Skip to content

Commit 6738c6e

Browse files
committed
Server:优化存储过程的性能
1 parent efb1dd6 commit 6738c6e

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

APIJSON-Java-Server/APIJSONBoot/src/main/java/apijson/demo/server/DemoObjectParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public DemoObjectParser setParser(Parser<?> parser) {
6262
}
6363

6464
@Override
65-
public SQLConfig newSQLConfig() throws Exception {
66-
return DemoSQLConfig.newSQLConfig(method, table, sqlRequest, joinList);
65+
public SQLConfig newSQLConfig(boolean isProcedure) throws Exception {
66+
return DemoSQLConfig.newSQLConfig(method, table, sqlRequest, joinList, isProcedure);
6767
}
6868

6969

APIJSON-Java-Server/APIJSONBoot/src/main/java/apijson/demo/server/DemoSQLConfig.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,12 @@ public DemoSQLConfig(RequestMethod method, int count, int page) {
122122
/**获取SQL配置
123123
* @param table
124124
* @param request
125+
* @param isProcedure
125126
* @return
126127
* @throws Exception
127128
*/
128-
public static SQLConfig newSQLConfig(RequestMethod method, String table, JSONObject request, List<Join> joinList) throws Exception {
129-
return newSQLConfig(method, table, request, joinList, SIMPLE_CALLBACK);
129+
public static SQLConfig newSQLConfig(RequestMethod method, String table, JSONObject request, List<Join> joinList, boolean isProcedure) throws Exception {
130+
return newSQLConfig(method, table, request, joinList, isProcedure, SIMPLE_CALLBACK);
130131
}
131132

132133

APIJSON-Java-Server/APIJSONORM/src/main/java/zuo/biao/apijson/server/AbstractObjectParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ public AbstractObjectParser setSQLConfig(int count, int page, int position) thro
611611
}
612612

613613
if (sqlConfig == null) {
614-
sqlConfig = newSQLConfig();
614+
sqlConfig = newSQLConfig(false);
615615
}
616616
sqlConfig.setCount(count).setPage(page).setPosition(position);
617617

@@ -719,7 +719,7 @@ public void onFunctionResponse(String type) throws Exception {
719719
public void parseFunction(JSONObject json, String key, String value) throws Exception {
720720
Object result;
721721
if (key.startsWith("@")) {
722-
SQLConfig config = newSQLConfig();
722+
SQLConfig config = newSQLConfig(true);
723723
config.setProcedure(value);
724724

725725
SQLExecutor executor = null;

APIJSON-Java-Server/APIJSONORM/src/main/java/zuo/biao/apijson/server/AbstractSQLConfig.java

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public String getUserIdKey() {
128128
//array item >>>>>>>>>>
129129
private boolean test; //测试
130130
private boolean cacheStatic; //静态缓存
131-
131+
132132
private String procedure;
133133
public SQLConfig setProcedure(String procedure) {
134134
this.procedure = procedure;
@@ -340,8 +340,8 @@ public String getGroupString(boolean hasPrefix) {
340340

341341
}
342342
}
343-
344-
343+
344+
345345
group = StringUtil.getTrimedString(group);
346346
String[] keys = StringUtil.split(group);
347347
if (keys == null || keys.length <= 0) {
@@ -400,7 +400,7 @@ public String getHavingString(boolean hasPrefix) {
400400

401401
}
402402
}
403-
403+
404404
having = StringUtil.getTrimedString(having);
405405
String[] keys = StringUtil.split(having, ";");
406406
if (keys == null || keys.length <= 0) {
@@ -1885,17 +1885,17 @@ public static String getSQL(AbstractSQLConfig config) throws Exception {
18851885
Log.i(TAG, "getSQL config == null >> return null;");
18861886
return null;
18871887
}
1888-
1888+
18891889
//TODO procedure 改为 List<Procedure> procedureList; behind : true; function: callFunction(); String key; ...
18901890
// for (...) { Call procedure1();\n SQL \n; Call procedure2(); ... }
18911891
// 貌似不需要,因为 ObjecParser 里就已经处理的顺序等,只是这里要解决下 Schema 问题。
1892-
1892+
18931893
String sch = config.getSQLSchema(config.getSQLTable());
18941894
if (StringUtil.isNotEmpty(config.getProcedure(), true)) {
18951895
String q = config.getQuote();
18961896
return "CALL " + q + sch + q + "."+ config.getProcedure();
18971897
}
1898-
1898+
18991899
String tablePath = config.getTablePath();
19001900
if (StringUtil.isNotEmpty(tablePath, true) == false) {
19011901
Log.i(TAG, "getSQL StringUtil.isNotEmpty(tablePath, true) == false >> return null;");
@@ -2069,20 +2069,29 @@ public String getJoinString() throws Exception {
20692069
* @return
20702070
* @throws Exception
20712071
*/
2072-
public static AbstractSQLConfig newSQLConfig(RequestMethod method, String table, JSONObject request, List<Join> joinList, Callback callback) throws Exception {
2072+
public static AbstractSQLConfig newSQLConfig(RequestMethod method, String table, JSONObject request, List<Join> joinList, boolean isProcedure, Callback callback) throws Exception {
20732073
if (request == null) { // User:{} 这种空内容在查询时也有效
20742074
throw new NullPointerException(TAG + ": newSQLConfig request == null!");
20752075
}
20762076
AbstractSQLConfig config = callback.getSQLConfig(method, table);
20772077

20782078
//放后面会导致主表是空对象时 joinList 未解析
2079-
config = parseJoin(method, config, joinList, callback);
2079+
if (isProcedure == false) {
2080+
config = parseJoin(method, config, joinList, callback);
2081+
}
20802082

20812083
if (request.isEmpty()) { // User:{} 这种空内容在查询时也有效
20822084
return config; //request.remove(key); 前都可以直接return,之后必须保证 put 回去
20832085
}
20842086

2087+
String database = request.getString(KEY_DATABASE);
20852088
String schema = request.getString(KEY_SCHEMA);
2089+
config.setDatabase(database); //不删,后面表对象还要用的
2090+
config.setSchema(schema); //不删,后面表对象还要用的
2091+
2092+
if (isProcedure) {
2093+
return config;
2094+
}
20862095

20872096
String idKey = callback.getIdKey(schema, table);
20882097
String idInKey = idKey + "{}";
@@ -2128,7 +2137,6 @@ else if (id instanceof Subquery) {}
21282137

21292138

21302139
String role = request.getString(KEY_ROLE);
2131-
String database = request.getString(KEY_DATABASE);
21322140
String combine = request.getString(KEY_COMBINE);
21332141
Subquery from = (Subquery) request.get(KEY_FROM);
21342142
String column = request.getString(KEY_COLUMN);
@@ -2329,8 +2337,6 @@ else if (whereList != null && whereList.contains(key)) {
23292337
//在 tableWhere 第0个 config.setIdIn(idIn);
23302338

23312339
config.setRole(role);
2332-
config.setDatabase(database);
2333-
config.setSchema(schema);
23342340
config.setGroup(group);
23352341
config.setHaving(having);
23362342
config.setOrder(order);
@@ -2378,8 +2384,8 @@ public static AbstractSQLConfig parseJoin(RequestMethod method, AbstractSQLConfi
23782384
for (Join j : joinList) {
23792385
name = j.getName();
23802386
//JOIN子查询不能设置LIMIT,因为ON关系是在子查询后处理的,会导致结果会错误
2381-
SQLConfig joinConfig = newSQLConfig(method, name, j.getTable(), null, callback);
2382-
SQLConfig cacheConfig = newSQLConfig(method, name, j.getTable(), null, callback).setCount(1);
2387+
SQLConfig joinConfig = newSQLConfig(method, name, j.getTable(), null, false, callback);
2388+
SQLConfig cacheConfig = newSQLConfig(method, name, j.getTable(), null, false, callback).setCount(1);
23832389

23842390
if (j.isAppJoin() == false) { //除了 @ APP JOIN,其它都是 SQL JOIN,则副表要这样配置
23852391
if (isQuery) {
@@ -2389,7 +2395,7 @@ public static AbstractSQLConfig parseJoin(RequestMethod method, AbstractSQLConfi
23892395
joinConfig.setMain(false).setKeyPrefix(true);
23902396

23912397
if (j.isLeftOrRightJoin()) {
2392-
SQLConfig outterConfig = newSQLConfig(method, name, j.getOutter(), null, callback);
2398+
SQLConfig outterConfig = newSQLConfig(method, name, j.getOutter(), null, false, callback);
23932399
outterConfig.setMain(false).setKeyPrefix(true);
23942400
j.setOutterConfig(outterConfig);
23952401
}

APIJSON-Java-Server/APIJSONORM/src/main/java/zuo/biao/apijson/server/ObjectParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public interface ObjectParser {
119119
void onChildResponse() throws Exception;
120120

121121

122-
SQLConfig newSQLConfig() throws Exception;
122+
SQLConfig newSQLConfig(boolean isProcedure) throws Exception;
123123

124124
/**
125125
* response has the final value after parse (and query if isTableKey)

0 commit comments

Comments
 (0)