Skip to content

[pull] master from Tencent:master #306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 21, 2025
Merged
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
2 changes: 1 addition & 1 deletion APIJSONORM/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.github.Tencent</groupId>
<artifactId>APIJSON</artifactId>
<version>7.5.5</version>
<version>7.5.6</version>
<packaging>jar</packaging>

<name>APIJSONORM</name>
Expand Down
13 changes: 11 additions & 2 deletions APIJSONORM/src/main/java/apijson/JSONObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ public JSONObject setUserIdIn(List<Object> list) {
public static final String KEY_ROLE = "@role"; //角色,拥有对某些数据的某些操作的权限
public static final String KEY_DATABASE = "@database"; //数据库类型,默认为MySQL
public static final String KEY_DATASOURCE = "@datasource"; //数据源
public static final String KEY_NAMESPACE = "@namespace"; //命名空间,Table在非默认namespace内时需要声明
public static final String KEY_SCHEMA = "@schema"; //数据库,Table在非默认schema内时需要声明
public static final String KEY_NAMESPACE = "@namespace"; //命名空间,Table 在非默认 namespace 内时需要声明
public static final String KEY_CATALOG = "@catalog"; //目录,Table 在非默认 catalog 内时需要声明
public static final String KEY_SCHEMA = "@schema"; //数据库,Table 在非默认 schema 内时需要声明
public static final String KEY_EXPLAIN = "@explain"; //分析 true/false
public static final String KEY_CACHE = "@cache"; //缓存 RAM/ROM/ALL
public static final String KEY_COLUMN = "@column"; //查询的Table字段或SQL函数
Expand Down Expand Up @@ -172,6 +173,7 @@ public JSONObject setUserIdIn(List<Object> list) {
TABLE_KEY_LIST.add(KEY_DATABASE);
TABLE_KEY_LIST.add(KEY_DATASOURCE);
TABLE_KEY_LIST.add(KEY_NAMESPACE);
TABLE_KEY_LIST.add(KEY_CATALOG);
TABLE_KEY_LIST.add(KEY_SCHEMA);
TABLE_KEY_LIST.add(KEY_EXPLAIN);
TABLE_KEY_LIST.add(KEY_CACHE);
Expand Down Expand Up @@ -269,6 +271,13 @@ public JSONObject setDatasource(String datasource) {
public JSONObject setNamespace(String namespace) {
return puts(KEY_NAMESPACE, namespace);
}
/**set catalog where table was puts
* @param catalog
* @return this
*/
public JSONObject setCatalog(String catalog) {
return puts(KEY_CATALOG, catalog);
}
/**set schema where table was puts
* @param schema
* @return this
Expand Down
40 changes: 30 additions & 10 deletions APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,22 +328,42 @@ else if (_method == PUT && value instanceof JSONArray && (whereList == null || w
}

if (isTable) {
if (parser.getGlobalDatabase() != null && sqlRequest.get(JSONRequest.KEY_DATABASE) == null) {
sqlRequest.put(JSONRequest.KEY_DATABASE, parser.getGlobalDatabase());
// parser.onVerifyRole 已处理 globalRole

String db = parser.getGlobalDatabase();
if (db != null) {
sqlRequest.putIfAbsent(JSONRequest.KEY_DATABASE, db);
}

String ds = parser.getGlobalDatasource();
if (ds != null) {
sqlRequest.putIfAbsent(JSONRequest.KEY_DATASOURCE, ds);
}

String ns = parser.getGlobalNamespace();
if (ns != null) {
sqlRequest.putIfAbsent(JSONRequest.KEY_NAMESPACE, ns);
}
if (parser.getGlobalSchema() != null && sqlRequest.get(JSONRequest.KEY_SCHEMA) == null) {
sqlRequest.put(JSONRequest.KEY_SCHEMA, parser.getGlobalSchema());

String cl = parser.getGlobalCatalog();
if (cl != null) {
sqlRequest.putIfAbsent(JSONRequest.KEY_CATALOG, cl);
}
if (parser.getGlobalDatasource() != null && sqlRequest.get(JSONRequest.KEY_DATASOURCE) == null) {
sqlRequest.put(JSONRequest.KEY_DATASOURCE, parser.getGlobalDatasource());

String sch = parser.getGlobalSchema();
if (sch != null) {
sqlRequest.putIfAbsent(JSONRequest.KEY_SCHEMA, sch);
}

if (isSubquery == false) { // 解决 SQL 语法报错,子查询不能 EXPLAIN
if (parser.getGlobalExplain() != null && sqlRequest.get(JSONRequest.KEY_EXPLAIN) == null) {
sqlRequest.put(JSONRequest.KEY_EXPLAIN, parser.getGlobalExplain());
Boolean exp = parser.getGlobalExplain();
if (sch != null) {
sqlRequest.putIfAbsent(JSONRequest.KEY_EXPLAIN, exp);
}
if (parser.getGlobalCache() != null && sqlRequest.get(JSONRequest.KEY_CACHE) == null) {
sqlRequest.put(JSONRequest.KEY_CACHE, parser.getGlobalCache());

String cache = parser.getGlobalCache();
if (cache != null) {
sqlRequest.putIfAbsent(JSONRequest.KEY_CACHE, cache);
}
}
}
Expand Down
56 changes: 43 additions & 13 deletions APIJSONORM/src/main/java/apijson/orm/AbstractParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,7 @@ public AbstractParser<T> setGlobalDatabase(String globalDatabase) {
public String getGlobalDatabase() {
return globalDatabase;
}
protected String globalSchema;
public AbstractParser<T> setGlobalSchema(String globalSchema) {
this.globalSchema = globalSchema;
return this;
}
@Override
public String getGlobalSchema() {
return globalSchema;
}

protected String globalDatasource;
@Override
public String getGlobalDatasource() {
Expand All @@ -339,6 +331,36 @@ public AbstractParser<T> setGlobalDatasource(String globalDatasource) {
return this;
}

protected String globalNamespace;
public AbstractParser<T> setGlobalNamespace(String globalNamespace) {
this.globalNamespace = globalNamespace;
return this;
}
@Override
public String getGlobalNamespace() {
return globalNamespace;
}

protected String globalCatalog;
public AbstractParser<T> setGlobalCatalog(String globalCatalog) {
this.globalCatalog = globalCatalog;
return this;
}
@Override
public String getGlobalCatalog() {
return globalCatalog;
}

protected String globalSchema;
public AbstractParser<T> setGlobalSchema(String globalSchema) {
this.globalSchema = globalSchema;
return this;
}
@Override
public String getGlobalSchema() {
return globalSchema;
}

protected Boolean globalExplain;
public AbstractParser<T> setGlobalExplain(Boolean globalExplain) {
this.globalExplain = globalExplain;
Expand Down Expand Up @@ -508,19 +530,25 @@ public JSONObject parseResponse(JSONObject request) {
}

try {
setGlobalFormat(requestObject.getBoolean(JSONRequest.KEY_FORMAT));
setGlobalDatabase(requestObject.getString(JSONRequest.KEY_DATABASE));
setGlobalSchema(requestObject.getString(JSONRequest.KEY_SCHEMA));
setGlobalDatasource(requestObject.getString(JSONRequest.KEY_DATASOURCE));
setGlobalNamespace(requestObject.getString(JSONRequest.KEY_NAMESPACE));
setGlobalCatalog(requestObject.getString(JSONRequest.KEY_CATALOG));
setGlobalSchema(requestObject.getString(JSONRequest.KEY_SCHEMA));

setGlobalExplain(requestObject.getBoolean(JSONRequest.KEY_EXPLAIN));
setGlobalCache(requestObject.getString(JSONRequest.KEY_CACHE));
setGlobalFormat(requestObject.getBoolean(JSONRequest.KEY_FORMAT));

requestObject.remove(JSONRequest.KEY_FORMAT);
requestObject.remove(JSONRequest.KEY_DATABASE);
requestObject.remove(JSONRequest.KEY_SCHEMA);
requestObject.remove(JSONRequest.KEY_DATASOURCE);
requestObject.remove(JSONRequest.KEY_NAMESPACE);
requestObject.remove(JSONRequest.KEY_CATALOG);
requestObject.remove(JSONRequest.KEY_SCHEMA);

requestObject.remove(JSONRequest.KEY_EXPLAIN);
requestObject.remove(JSONRequest.KEY_CACHE);
requestObject.remove(JSONRequest.KEY_FORMAT);
} catch (Exception e) {
return extendErrorResult(requestObject, e, requestMethod, getRequestURL(), isRoot);
}
Expand Down Expand Up @@ -1462,6 +1490,8 @@ else if (childKeys.length == 1 && JSONRequest.isTableKey(childKeys[0])) { //
JOIN_COPY_KEY_LIST = new ArrayList<String>();
JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_ROLE);
JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_DATABASE);
JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_NAMESPACE);
JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_CATALOG);
JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_SCHEMA);
JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_DATASOURCE);
JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_COLUMN);
Expand Down
Loading