Skip to content

Commit d959c6c

Browse files
committed
存储过程 @procedure():"fun(key0,key1..)" 返回格式中去掉 key 的 @ 前缀;取消支持 key? 这种正则匹配方式,全面用 key~ 替代;优化代码
1 parent 7958fd3 commit d959c6c

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ public void onPUTArrayParse(@NotNull String key, @NotNull JSONArray array) throw
513513
// throw new IllegalAccessException("PUT " + path + ", PUT Array不允许 " + key +
514514
// " 这种没有 + 或 - 结尾的key!不允许整个替换掉原来的Array!");
515515
}
516-
String realKey = AbstractSQLConfig.getRealKey(method, key, false, false, "`"); //FIXME PG 是 "
516+
String realKey = AbstractSQLConfig.getRealKey(method, key, false, false);
517517

518518
//GET > add all 或 remove all > PUT > remove key
519519

@@ -746,19 +746,21 @@ public void onFunctionResponse(String type) throws Exception {
746746

747747
public void parseFunction(String key, String value, String parentPath, String currentName, JSONObject currentObject) throws Exception {
748748
Object result;
749-
if (key.startsWith("@")) { //TODO 以后这种小众功能从 ORM 移出,作为一个 plugin/APIJSONProcedure
749+
if (key.startsWith("@")) {
750750
FunctionBean fb = AbstractFunctionParser.parseFunction(value, currentObject, true);
751751

752752
SQLConfig config = newSQLConfig(true);
753753
config.setProcedure(fb.toFunctionCallString(true));
754754
result = parseResponse(config, true);
755+
756+
key = key.substring(1);
755757
}
756758
else {
757759
result = parser.onFunctionParse(key, value, parentPath, currentName, currentObject);
758760
}
759761

760762
if (result != null) {
761-
String k = AbstractSQLConfig.getRealKey(method, key, false, false, "`"); //FIXME PG 是 "
763+
String k = AbstractSQLConfig.getRealKey(method, key, false, false);
762764

763765
response.put(k, result);
764766
parser.putQueryResult(AbstractParser.getAbsPath(path, k), result);

APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -882,14 +882,14 @@ public String getColumnString(boolean inSQLJoin) throws Exception {
882882
}
883883

884884
// 简单点, 后台配置就带上 AS
885-
// int index = expression.lastIndexOf(":");
886-
// String alias = expression.substring(index+1);
887-
// boolean hasAlias = StringUtil.isName(alias);
888-
// String pre = index > 0 && hasAlias ? expression.substring(0, index) : expression;
889-
// if (RAW_MAP.containsValue(pre) || "".equals(RAW_MAP.get(pre))) { // newSQLConfig 提前处理好的
890-
// expression = pre + (hasAlias ? " AS " + alias : "");
891-
// continue;
892-
// }
885+
// int index = expression.lastIndexOf(":");
886+
// String alias = expression.substring(index+1);
887+
// boolean hasAlias = StringUtil.isName(alias);
888+
// String pre = index > 0 && hasAlias ? expression.substring(0, index) : expression;
889+
// if (RAW_MAP.containsValue(pre) || "".equals(RAW_MAP.get(pre))) { // newSQLConfig 提前处理好的
890+
// expression = pre + (hasAlias ? " AS " + alias : "");
891+
// continue;
892+
// }
893893
}
894894

895895

@@ -1572,8 +1572,7 @@ else if (isSideJoin) { // ^ SIDE JOIN: ! (A & B)
15721572
* @return
15731573
* @throws Exception
15741574
*/
1575-
private String getWhereItem(String key, Object value
1576-
, RequestMethod method, boolean verifyName) throws Exception {
1575+
protected String getWhereItem(String key, Object value, RequestMethod method, boolean verifyName) throws Exception {
15771576
Log.d(TAG, "getWhereItem key = " + key);
15781577
//避免筛选到全部 value = key == null ? null : where.get(key);
15791578
if (key == null || value == null || key.endsWith("()") || key.startsWith("@")) { //关键字||方法, +或-直接报错
@@ -1593,7 +1592,7 @@ private String getWhereItem(String key, Object value
15931592
if (key.endsWith("$")) {
15941593
keyType = 1;
15951594
}
1596-
else if (key.endsWith("~") || key.endsWith("?")) { //TODO ?可能以后会被废弃,全用 ~ 和 *~ 替代,更接近 PostgreSQL 语法
1595+
else if (key.endsWith("~")) {
15971596
keyType = key.charAt(key.length() - 2) == '*' ? -2 : 2; //FIXME StringIndexOutOfBoundsException
15981597
}
15991598
else if (key.endsWith("%")) {
@@ -1623,7 +1622,7 @@ else if (key.endsWith("<")) {
16231622
keyType = 0;
16241623
}
16251624

1626-
key = getRealKey(method, key, false, true, verifyName, getQuote());
1625+
key = getRealKey(method, key, false, true, verifyName);
16271626

16281627
switch (keyType) {
16291628
case 1:
@@ -2223,8 +2222,6 @@ public String getSetString(RequestMethod method, Map<String, Object> content, bo
22232222
String setString = "";
22242223

22252224
if (set != null && set.size() > 0) {
2226-
String quote = getQuote();
2227-
22282225
boolean isFirst = true;
22292226
int keyType;// 0 - =; 1 - +, 2 - -
22302227
Object value;
@@ -2244,7 +2241,7 @@ public String getSetString(RequestMethod method, Map<String, Object> content, bo
22442241
keyType = 0; //注意重置类型,不然不该加减的字段会跟着加减
22452242
}
22462243
value = content.get(key);
2247-
key = getRealKey(method, key, false, true, verifyName, quote);
2244+
key = getRealKey(method, key, false, true, verifyName);
22482245

22492246
setString += (isFirst ? "" : ", ") + (getKey(key) + " = " + (keyType == 1 ? getAddString(key, value) : (keyType == 2
22502247
? getRemoveString(key, value) : getValue(value)) ) );
@@ -2967,8 +2964,8 @@ LEFT JOIN ( SELECT count(*) AS count FROM sys.Comment ) AS Comment ON Comment.m
29672964
* @return
29682965
*/
29692966
public static String getRealKey(RequestMethod method, String originKey
2970-
, boolean isTableKey, boolean saveLogic, String quote) throws Exception {
2971-
return getRealKey(method, originKey, isTableKey, saveLogic, true, quote);
2967+
, boolean isTableKey, boolean saveLogic) throws Exception {
2968+
return getRealKey(method, originKey, isTableKey, saveLogic, true);
29722969
}
29732970
/**获取客户端实际需要的key
29742971
* @param method
@@ -2979,19 +2976,18 @@ public static String getRealKey(RequestMethod method, String originKey
29792976
* @return
29802977
*/
29812978
public static String getRealKey(RequestMethod method, String originKey
2982-
, boolean isTableKey, boolean saveLogic, boolean verifyName, String quote) throws Exception {
2979+
, boolean isTableKey, boolean saveLogic, boolean verifyName) throws Exception {
29832980
Log.i(TAG, "getRealKey saveLogic = " + saveLogic + "; originKey = " + originKey);
2984-
if (originKey == null || originKey.startsWith(quote) || apijson.JSONObject.isArrayKey(originKey)) {
2985-
Log.w(TAG, "getRealKey originKey == null || originKey.startsWith(`)"
2986-
+ " || apijson.JSONObject.isArrayKey(originKey) >> return originKey;");
2981+
if (originKey == null || apijson.JSONObject.isArrayKey(originKey)) {
2982+
Log.w(TAG, "getRealKey originKey == null || apijson.JSONObject.isArrayKey(originKey) >> return originKey;");
29872983
return originKey;
29882984
}
29892985

29902986
String key = new String(originKey);
29912987
if (key.endsWith("$")) {//搜索 LIKE,查询时处理
29922988
key = key.substring(0, key.length() - 1);
29932989
}
2994-
else if (key.endsWith("~") || key.endsWith("?")) {//匹配正则表达式 REGEXP,查询时处理 TODO ?可能以后会被废弃,全用 ~ 和 *~ 替代,更接近 PostgreSQL 语法
2990+
else if (key.endsWith("~")) {//匹配正则表达式 REGEXP,查询时处理
29952991
key = key.substring(0, key.length() - 1);
29962992
if (key.endsWith("*")) {//忽略大小写
29972993
key = key.substring(0, key.length() - 1);

APIJSONORM/src/main/java/apijson/orm/AbstractVerifier.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
import apijson.StringUtil;
5757
import apijson.orm.AbstractSQLConfig.IdCallback;
5858
import apijson.orm.exception.ConflictException;
59-
import apijson.orm.exception.NotExistException;
6059
import apijson.orm.exception.NotLoggedInException;
6160
import apijson.orm.model.Access;
6261
import apijson.orm.model.Column;
@@ -1182,10 +1181,10 @@ private static void verifyValue(@NotNull String tk, @NotNull Object tv, @NotNull
11821181
String rk;
11831182
Object rv;
11841183
Logic logic;
1185-
if (tk.endsWith("$")) { //搜索
1184+
if (tk.endsWith("$")) { // 模糊搜索
11861185
verifyCondition("$", real, tk, tv, creator);
11871186
}
1188-
else if (tk.endsWith("~") || tk.endsWith("?")) { //TODO 正则表达式, 以后可能取消支持 ? 作为 正则匹配 的功能符
1187+
else if (tk.endsWith("~")) { // 正则匹配
11891188
logic = new Logic(tk.substring(0, tk.length() - 1));
11901189
rk = logic.getKey();
11911190
rv = real.get(rk);

0 commit comments

Comments
 (0)