Skip to main content

6.3.1 Database provider

Dependency and schema​

implementation 'net.hasor:dataway-meta-jdbc:5.0.0'

The application supplies the JDBC driver and DataSource. This module uses dbVisitor to access the database.

Table creation scripts​

Select your database, then copy and run the script to create interface_info, interface_release and their indexes. Adjust names to match any table and field mappings.

CREATE TABLE interface_info (
api_id VARCHAR(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL PRIMARY KEY,
api_method VARCHAR(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
api_path VARCHAR(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
api_status VARCHAR(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
api_comment VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
api_type VARCHAR(24) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
api_script MEDIUMTEXT NOT NULL,
api_schema MEDIUMTEXT NOT NULL,
api_sample MEDIUMTEXT NOT NULL,
api_option MEDIUMTEXT NOT NULL,
api_create_time VARCHAR(32) NOT NULL,
api_gmt_time VARCHAR(32) NOT NULL,
api_revision BIGINT NOT NULL DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

CREATE TABLE interface_release (
pub_id VARCHAR(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL PRIMARY KEY,
pub_api_id VARCHAR(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
pub_method VARCHAR(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
pub_path VARCHAR(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
pub_status VARCHAR(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
pub_comment VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
pub_type VARCHAR(24) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
pub_script MEDIUMTEXT NOT NULL,
pub_schema MEDIUMTEXT NOT NULL,
pub_sample MEDIUMTEXT NOT NULL,
pub_option MEDIUMTEXT NOT NULL,
pub_release_time VARCHAR(32) NOT NULL,
pub_revision BIGINT NOT NULL DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

CREATE UNIQUE INDEX uk_interface_info ON interface_info (api_method, api_path);
CREATE INDEX idx_interface_release_api ON interface_release (pub_api_id);
CREATE INDEX idx_interface_release_path ON interface_release (pub_method, pub_path, pub_status);

The JAR also includes mysql.sql, postgresql.sql, oracle.sql, sqlserver.sql and h2.sql under META-INF/dataway/schema/.

Create the store​

import net.hasor.dataway.dal.ApiDataAccessLayer;
import net.hasor.dataway.dal.jdbc.JdbcDataAccessLayer;

ApiDataAccessLayer metadata = new JdbcDataAccessLayer(source);

Configure the store through DatawayConfig.dataAccessLayer(metadata). Single-argument constructors use interface_info and interface_release. To add a prefix, use new JdbcDataAccessLayer(source, "dw_"); create matching tables named dw_interface_info and dw_interface_release.

Use the primary or a dedicated database. Default construction uses local transactions; pass JdbcExecutor for host transactions.

Consistency​

Each batch runs on one connection. Updates and deletes compare revisions; stale versions and duplicate routes report conflicts. Method, path and identity columns must compare case-sensitively; follow the selected script and its connection requirements.

Use mappings for custom storage names.