Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Document-Chinese.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,14 @@ DELETE: <br > 删除数据 | base_url/delete/ | {<br > &nbsp;&nbsp; TableName:{<
<br >

### <h3 id="3.2">3.2 功能符<h3/>

#### KingbaseES 接入与迁移

- 使用 MySQL、Oracle 或 SQL Server 兼容模式时,将 `@database` 或后端 `DEFAULT_DATABASE` 配置为 `KINGBASE_AUTO`,并由应用提供运行时 Kingbase JDBC 驱动。APIJSON 使用 `SHOW database_mode` 识别模式,并缓存数据源的识别结果。
- 从 `KINGBASE_MYSQL`、`KINGBASE_ORACLE` 或 `KINGBASE_SQLSERVER` 直接配置迁移时,请改为 `KINGBASE_AUTO`。这三个标识仍可用于后端 `gainKingbaseExpectedDatabase()` 的期望模式校验,但不再作为直接配置值。原有 `KINGBASE` 入口保留旧行为,不自动探测模式。
- 自管数据源可覆盖 `openKingbaseModeConnection()`,返回可由探测器关闭的连接。探测连接和缓存键不能依赖已解析的 SQL 方言;如果同一数据源切换目标实例,请使用 `KINGBASE_MODE_RESOLVER.invalidate(config)` 清除旧的模式缓存。

默认 Maven 测试不需要 Kingbase 驱动。要单独验证 JDBC 驱动合约,可运行 `mvn -Pkingbase-driver-tests -Dtest=KingbaseTypeMappingTest test`,按需要通过 `-Dkingbase.jdbc.version` 指定可从 Maven 仓库获取的驱动版本。这不等同于实库测试。

功能 | 键值对格式 | 使用示例
------------ | ------------ | ------------
Expand Down
16 changes: 16 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<kingbase.jdbc.version>9.0.0</kingbase.jdbc.version>
</properties>

<dependencies>
Expand All @@ -29,6 +30,21 @@
</dependency>
</dependencies>

<!-- Optional real-driver contract tests; the ORM has no production driver dependency. -->
<profiles>
<profile>
<id>kingbase-driver-tests</id>
<dependencies>
<dependency>
<groupId>cn.com.kingbase</groupId>
<artifactId>kingbase8</artifactId>
<version>${kingbase.jdbc.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>

<build>
<plugins>
<plugin>
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/apijson/orm/AbstractFunctionParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,21 @@ public String toFunctionCallString(boolean useValue, String quote) {
return s + ")";
}

/** Encode the arguments of a text CALL before Kingbase Oracle prepares it. */
String toKingbaseOracleCallString() {
StringBuilder call = new StringBuilder(getMethod()).append('(');
Object[] args = getValues();
if (args != null) {
for (int i = 0; i < args.length; i++) {
if (i > 0) call.append(',');
Object arg = args[i];
if (arg instanceof Boolean || arg instanceof Number) call.append(arg);
else call.append("E'").append(String.valueOf(arg).replace("\\", "\\\\").replace("'", "''")).append('\'');
}
}
return call.append(')').toString();
}

}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/apijson/orm/AbstractObjectParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ public void parseFunction(String rawKey, String key, String value, String parent
if (StringUtil.isNotEmpty(sch, true)) {
config.setSchema(sch);
}
config.setProcedure(fb.toFunctionCallString(true));
config.setProcedure(config.isKingBaseOracle() ? fb.toKingbaseOracleCallString() : fb.toFunctionCallString(true));
result = parseResponse(config, true);

key = key.substring(1);
Expand Down
48 changes: 40 additions & 8 deletions src/main/java/apijson/orm/AbstractParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -683,18 +683,33 @@ public void onVerifyRole(@NotNull SQLConfig<T, M, L> config) throws Exception {
}

if (isNeedVerifyRole()) {
if (config.getRole() == null) {
if (globalRole != null) {
config.setRole(globalRole);
} else {
config.setRole(getVisitor().getId() == null ? AbstractVerifier.UNKNOWN : AbstractVerifier.LOGIN);
verifyConfigRole(config);
List<Join> jl = config.getJoinList();
if (jl != null) {
// Verify the joined rows before SQL generation and before caching any child results.
for (Join<T, M, L> join : jl) {
SQLConfig<T, M, L> child = join.getJoinConfig();
if (child != null) { // && child.isKingBaseSQLServer() {
verifyConfigRole(child);
}

SQLConfig<T, M, L> cache = join.getCacheConfig();
if (cache != null && cache != child) { // && cache.isKingBaseSQLServer() {
verifyConfigRole(cache);
}
}
}
getVerifier().verifyAccess(config);
}

}

private void verifyConfigRole(SQLConfig<T, M, L> config) throws Exception {
if (config.getRole() == null) {
config.setRole(globalRole != null ? globalRole : (getVisitor().getId() == null ? AbstractVerifier.UNKNOWN : AbstractVerifier.LOGIN));
}
getVerifier().verifyAccess(config);
}


@Override
public M parseCorrectRequest(RequestMethod method, String tag, int version, String name, @NotNull M request
Expand Down Expand Up @@ -1106,6 +1121,8 @@ public M getStructure(@NotNull String table, String method, String tag, int vers
config.setParser(this);
config.setPrepared(false);
config.setColumn(Arrays.asList("structure"));
// Only the three compatibility modes opt into TEXT/CLOB-backed rules.
config.setJson(Arrays.asList("structure"));

Map<String, Object> where = new HashMap<String, Object>();
where.put("method", method);
Expand All @@ -1126,7 +1143,9 @@ public M getStructure(@NotNull String table, String method, String tag, int vers
// AbstractVerifier.REQUEST_MAP.put(cacheKey, versionedMap);
}

return JSON.get(result, "structure"); //解决返回值套了一层 "structure":{}
// Legacy KINGBASE and native databases keep the original cached-rule contract.
Object structure = result == null ? null : result.get("structure");
return structure instanceof String ? JSON.parseObject(structure) : (M) structure;
}


Expand Down Expand Up @@ -1534,6 +1553,7 @@ else if (childKeys.length == 1 && isTableKey(childKeys[0])) { // 可能无需
JOIN_COPY_KEY_LIST.add(KEY_ORDER);
JOIN_COPY_KEY_LIST.add(KEY_KEY);
JOIN_COPY_KEY_LIST.add(KEY_RAW);
JOIN_COPY_KEY_LIST.add(KEY_JSON);
}

/**JOIN 多表同时筛选
Expand Down Expand Up @@ -1677,6 +1697,18 @@ else if (join != null){
}

boolean isAppJoin = "@".equals(joinType);
// String joinDatabase = getString(tableObj, KEY_DATABASE);
// if (joinDatabase == null) {
// joinDatabase = getString(request, KEY_DATABASE);
// if (joinDatabase == null) {
// joinDatabase = getGlobalDatabase();
// if (joinDatabase == null) {
// joinDatabase = AbstractSQLConfig.DEFAULT_DATABASE;
// }
// }
// }

// boolean copyJoinJson = SQLConfig.DATABASE_KINGBASE_AUTO.equals(joinDatabase);

M refObj = JSON.createJSONObject();

Expand Down Expand Up @@ -1758,7 +1790,7 @@ else if (join != null){
}

if (k.startsWith("@")) {
if (JOIN_COPY_KEY_LIST.contains(k)) {
if (JOIN_COPY_KEY_LIST.contains(k)) { // 直接 JOIN_COPY_KEY_LIST.add(KEY_JSON) || (copyJoinJson && KEY_JSON.equals(k))) {
requestObj.put(k, v); // 保留
}
}
Expand Down
Loading
Loading