having);
+
+ String getHavingCombine();
+ SQLConfig setHavingCombine(String havingCombine);
String getOrder();
SQLConfig setOrder(String order);
From 12738bfb6bafb4bdcd91afd58016119f37bd5598 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Mon, 21 Mar 2022 00:46:20 +0800
Subject: [PATCH 033/619] =?UTF-8?q?=E8=A7=A3=E5=86=B3=20JOIN=20ON=20?=
=?UTF-8?q?=E4=B8=AD=E7=94=A8=20@combine=20=E7=AD=89=E6=83=85=E5=86=B5?=
=?UTF-8?q?=E4=B8=8B=E9=A2=84=E7=BC=96=E8=AF=91=E5=80=BC=E4=B8=8E=20SQL=20?=
=?UTF-8?q?=E4=B8=AD=20=3F=20=E5=8D=A0=E4=BD=8D=E7=AC=A6=E9=A1=BA=E5=BA=8F?=
=?UTF-8?q?=E5=AF=B9=E4=B8=8D=E4=B8=8A=E5=AF=BC=E8=87=B4=E7=9A=84=E5=BC=82?=
=?UTF-8?q?=E5=B8=B8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/apijson/orm/AbstractSQLConfig.java | 24 ++++++++++++-------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java
index c9c64b61e..fd9631c2e 100755
--- a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java
+++ b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java
@@ -2463,8 +2463,10 @@ protected String parseCombineExpression(RequestMethod method, String quote, Stri
int n = s.length();
if (n > 0) {
- setPreparedValueList(new ArrayList<>());
-
+ if (isHaving == false) {
+ setPreparedValueList(new ArrayList<>()); // 必须反过来,否则 JOIN ON 内部 @combine 拼接后顺序错误
+ }
+
int maxDepth = getMaxCombineDepth();
int maxCombineCount = getMaxCombineCount();
int maxCombineKeyCount = getMaxCombineKeyCount();
@@ -2675,13 +2677,17 @@ else if (c == ')') {
if (StringUtil.isEmpty(result, true)) {
result = andCond;
}
- else if (StringUtil.isNotEmpty(andCond, true)) { // andWhere 必须放后面,否则 prepared 值顺序错误
- // result = "( " + result + " )" + AND + andCond;
- result = andCond + AND + "( " + result + " )"; // 先暂存之前的 prepared 值,然后反向整合
- if (n > 0) {
- prepreadValues.addAll(getPreparedValueList());
- setPreparedValueList(prepreadValues);
- }
+ else if (StringUtil.isNotEmpty(andCond, true)) { // andCond 必须放后面,否则 prepared 值顺序错误
+ if (isHaving) { // HAVING 前 WHERE 已经有条件 ? 占位,不能反过来,想优化 AND 连接在最前,需要多遍历一次内部的 key,也可以 newSQLConfig 时存到 andList
+ result = "( " + result + " )" + AND + andCond;
+ }
+ else {
+ result = andCond + AND + "( " + result + " )"; // 先暂存之前的 prepared 值,然后反向整合
+ if (n > 0) {
+ prepreadValues.addAll(getPreparedValueList());
+ setPreparedValueList(prepreadValues);
+ }
+ }
}
return result;
From be92b894b5beb6f2b1cdd8ffe71f9fbef11ae79a Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sat, 26 Mar 2022 16:26:27 +0800
Subject: [PATCH 034/619] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index e0d4110cf..1aca30303 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@ This source code is licensed under the Apache License Version 2.0
APIJSON
-零代码、热更新、全自动 ORM 库
🚀 后端接口和文档零代码,前端(客户端) 定制返回 JSON 的数据和结构
+零代码、全自动、强安全 ORM 库
🚀 后端接口和文档零代码,前端(客户端) 定制返回 JSON 的数据和结构
From b248c698887728bd826febd77c4404dd1faecf06 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sat, 26 Mar 2022 23:56:23 +0800
Subject: [PATCH 035/619] =?UTF-8?q?=E4=BC=98=E5=8C=96=20@combine=20?=
=?UTF-8?q?=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3=E7=A0=81=EF=BC=8C=E9=BB=98?=
=?UTF-8?q?=E8=AE=A4=20combine=20=E4=B8=BA=E9=80=BB=E8=BE=91=E8=BF=90?=
=?UTF-8?q?=E7=AE=97=E6=A8=A1=E6=9D=BF=EF=BC=8C=E5=8E=9F=E6=9D=A5=E7=9A=84?=
=?UTF-8?q?=20combine=20=E9=87=8D=E5=91=BD=E5=90=8D=E4=B8=BA=20combineMap?=
=?UTF-8?q?=EF=BC=8CcombineExpression=20=E9=87=8D=E5=91=BD=E5=90=8D?=
=?UTF-8?q?=E4=B8=BA=20combine?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/apijson/orm/AbstractSQLConfig.java | 83 ++++++++++++-------
.../java/apijson/orm/AbstractSQLExecutor.java | 2 +-
.../src/main/java/apijson/orm/SQLConfig.java | 32 +++----
3 files changed, 70 insertions(+), 47 deletions(-)
diff --git a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java
index fd9631c2e..17aebb59a 100755
--- a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java
+++ b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java
@@ -775,8 +775,8 @@ public String getUserIdKey() {
private Map cast;
private Map content; //Request内容,key:value形式,column = content.keySet(),values = content.values()
private Map where; //筛选条件,key:value形式
- private Map> combine; //条件组合,{ "&":[key], "|":[key], "!":[key] }
- private String combineExpression;
+ private String combine; //条件组合, a | (b & c & !(d | !e))
+ private Map> combineMap; //条件组合,{ "&":[key], "|":[key], "!":[key] }
//array item <<<<<<<<<<
private int count; //Table数量
@@ -2238,31 +2238,31 @@ protected float getMaxCombineRatio() {
@Override
- public String getCombineExpression() {
- return combineExpression;
+ public String getCombine() {
+ return combine;
}
@Override
- public AbstractSQLConfig setCombineExpression(String combineExpression) {
- this.combineExpression = combineExpression;
+ public AbstractSQLConfig setCombine(String combine) {
+ this.combine = combine;
return this;
}
@NotNull
@Override
- public Map> getCombine() {
- List andList = combine == null ? null : combine.get("&");
+ public Map> getCombineMap() {
+ List andList = combineMap == null ? null : combineMap.get("&");
if (andList == null) {
andList = where == null ? new ArrayList() : new ArrayList(where.keySet());
- if (combine == null) {
- combine = new HashMap<>();
+ if (combineMap == null) {
+ combineMap = new HashMap<>();
}
- combine.put("&", andList);
+ combineMap.put("&", andList);
}
- return combine;
+ return combineMap;
}
@Override
- public AbstractSQLConfig setCombine(Map> combine) {
- this.combine = combine;
+ public AbstractSQLConfig setCombineMap(Map> combineMap) {
+ this.combineMap = combineMap;
return this;
}
@@ -2329,8 +2329,8 @@ public AbstractSQLConfig putWhere(String key, Object value, boolean prior) {
where.put(key, value);
}
- combine = getCombine();
- List andList = combine.get("&");
+ Map> combineMap = getCombineMap();
+ List andList = combineMap.get("&");
if (value == null) {
if (andList != null) {
andList.remove(key);
@@ -2392,7 +2392,7 @@ else if (key.equals(userIdInKey)) {
andList.add(key); //AbstractSQLExecutor.onPutColumn里getSQL,要保证缓存的SQL和查询的SQL里 where 的 key:value 顺序一致
}
}
- combine.put("&", andList);
+ combineMap.put("&", andList);
}
return this;
@@ -2405,11 +2405,11 @@ else if (key.equals(userIdInKey)) {
@JSONField(serialize = false)
@Override
public String getWhereString(boolean hasPrefix) throws Exception {
- String ce = getCombineExpression();
- if (StringUtil.isEmpty(ce, true)) {
- return getWhereString(hasPrefix, getMethod(), getWhere(), getCombine(), getJoinList(), ! isTest());
+ String combineExpr = getCombine();
+ if (StringUtil.isEmpty(combineExpr, true)) {
+ return getWhereString(hasPrefix, getMethod(), getWhere(), getCombineMap(), getJoinList(), ! isTest());
}
- return getWhereString(hasPrefix, getMethod(), getWhere(), ce, getJoinList(), ! isTest());
+ return getWhereString(hasPrefix, getMethod(), getWhere(), combineExpr, getJoinList(), ! isTest());
}
/**获取WHERE
* @param method
@@ -2432,7 +2432,19 @@ public String getWhereString(boolean hasPrefix, RequestMethod method, Map conditioinMap, String combine, boolean verifyName, boolean containRaw, boolean isHaving) throws Exception {
@@ -2693,6 +2705,17 @@ else if (StringUtil.isNotEmpty(andCond, true)) { // andCond 必须放后面,
return result;
}
+ /**已废弃,最快 6.0 删除,请尽快把前端/客户端 @combine:"a,b" 这种旧方式改为 @combine:"a | b" 这种新方式
+ * @param hasPrefix
+ * @param method
+ * @param where
+ * @param combine
+ * @param joinList
+ * @param verifyName
+ * @return
+ * @throws Exception
+ */
+ @Deprecated
public String getWhereString(boolean hasPrefix, RequestMethod method, Map where, Map> combine, List joinList, boolean verifyName) throws Exception {
Set>> combineSet = combine == null ? null : combine.entrySet();
if (combineSet == null || combineSet.isEmpty()) {
@@ -4437,9 +4460,9 @@ else if (id instanceof Subquery) {}
List whereList = null;
String[] ws = StringUtil.split(combine);
- String combineExpression = ws == null || ws.length != 1 ? null : ws[0];
+ String combineExpr = ws == null || ws.length != 1 ? null : ws[0];
- Map> combineMap = StringUtil.isNotEmpty(combineExpression, true) ? null : new LinkedHashMap<>();
+ Map> combineMap = StringUtil.isNotEmpty(combineExpr, true) ? null : new LinkedHashMap<>();
List andList = combineMap == null ? null : new ArrayList<>();
List orList = combineMap == null ? null : new ArrayList<>();
List notList = combineMap == null ? null : new ArrayList<>();
@@ -4459,14 +4482,14 @@ else if (id instanceof Subquery) {}
}
if (combineMap == null) {
- if (StringUtil.isNotEmpty(combineExpression, true)) {
+ if (StringUtil.isNotEmpty(combineExpr, true)) {
List banKeyList = Arrays.asList(idKey, idInKey, userIdKey, userIdInKey);
for (String key : banKeyList) {
- int index = combineExpression.indexOf(key);
+ int index = combineExpr.indexOf(key);
if (index >= 0) {
- char left = index <= 0 ? ' ' : combineExpression.charAt(index - 1);
- char right = index >= combineExpression.length() - key.length() ? ' ' : combineExpression.charAt(index + key.length());
+ char left = index <= 0 ? ' ' : combineExpr.charAt(index - 1);
+ char right = index >= combineExpr.length() - key.length() ? ' ' : combineExpr.charAt(index + key.length());
if ((left == ' ' || left == '(' || left == '&' || left == '|' || left == '!') && (right == ' ' || right == ')')) {
throw new UnsupportedOperationException(table + ":{} 里的 @combine:value 中的 value 里 " + key + " 不合法!"
+ "不允许传 [" + idKey + ", " + idInKey + ", " + userIdKey + ", " + userIdInKey + "] 其中任何一个!");
@@ -4567,8 +4590,8 @@ else if (whereList != null && whereList.contains(key)) {
combineMap.put("|", orList);
combineMap.put("!", notList);
}
- config.setCombine(combineMap);
- config.setCombineExpression(combineExpression);
+ config.setCombineMap(combineMap);
+ config.setCombine(combineExpr);
config.setContent(tableContent);
}
diff --git a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLExecutor.java b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLExecutor.java
index bd5c0cf00..c99f1e5eb 100755
--- a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLExecutor.java
+++ b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLExecutor.java
@@ -335,7 +335,7 @@ public JSONObject execute(@NotNull SQLConfig config, boolean unknowType) throws
capacity = config.getCount() <= 0 ? Parser.MAX_QUERY_COUNT : config.getCount();
if (capacity > 100) {
// 有条件,条件越多过滤数据越多
- Map> combine = config.getCombine();
+ Map> combine = config.getCombineMap();
List andList = combine == null ? null : combine.get("&");
int andCondCount = andList == null ? (config.getWhere() == null ? 0 : config.getWhere().size()) : andList.size();
diff --git a/APIJSONORM/src/main/java/apijson/orm/SQLConfig.java b/APIJSONORM/src/main/java/apijson/orm/SQLConfig.java
index 22acf1461..43561fdd8 100755
--- a/APIJSONORM/src/main/java/apijson/orm/SQLConfig.java
+++ b/APIJSONORM/src/main/java/apijson/orm/SQLConfig.java
@@ -156,18 +156,6 @@ public interface SQLConfig {
List getRaw();
SQLConfig setRaw(List raw);
- String getGroup();
- SQLConfig setGroup(String group);
-
- Map getHaving();
- SQLConfig setHaving(Map having);
-
- String getHavingCombine();
- SQLConfig setHavingCombine(String havingCombine);
-
- String getOrder();
- SQLConfig setOrder(String order);
-
Subquery getFrom();
SQLConfig setFrom(Subquery from);
@@ -180,11 +168,11 @@ public interface SQLConfig {
Map getContent();
SQLConfig setContent(Map content);
- Map> getCombine();
- SQLConfig setCombine(Map> combine);
+ Map> getCombineMap();
+ SQLConfig setCombineMap(Map> combineMap);
- String getCombineExpression();
- SQLConfig setCombineExpression(String combineExpression);
+ String getCombine();
+ SQLConfig setCombine(String combine);
Map getCast();
SQLConfig setCast(Map