From b900c5819c3bc641845fffce3e205da6b64bccda Mon Sep 17 00:00:00 2001 From: TommyLemon <1184482681@qq.com> Date: Sun, 18 Apr 2021 01:38:29 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=20>=20RIGHT=20JOIN,=20^=20SI?= =?UTF-8?q?DE=20JOIN,=20!=20ANTI=20JOIN,=20)=20FOREIGN=20JOIN=20=E7=AD=89?= =?UTF-8?q?=E4=B8=8D=E8=BF=94=E5=9B=9E=E5=89=AF=E8=A1=A8=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=EF=BC=9B=E8=A7=A3=E5=86=B3=20|=20FULL=20JOIN=20=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E7=9A=84=E5=89=AF=E8=A1=A8=E6=95=B0=E6=8D=AE=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=98=AF=E9=94=99=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/apijson/orm/AbstractSQLConfig.java | 17 +++--- .../java/apijson/orm/AbstractSQLExecutor.java | 18 +++++-- .../src/main/java/apijson/orm/Join.java | 52 +++++++++++++++---- 3 files changed, 67 insertions(+), 20 deletions(-) diff --git a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java index 4ed74b0f5..d4ac822f8 100755 --- a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java +++ b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java @@ -1769,8 +1769,8 @@ else if ("!".equals(ce.getKey())) { if (isAntiJoin) { // ( ANTI JOIN: A & ! B newWs += " ( " + ( isWsEmpty ? "" : ws + AND ) + NOT + " ( " + js + " ) " + " ) "; } - else if (isForeignJoin) { // ) FOREIGN JOIN: B & ! A - newWs += " ( " + " ( " + js + " ) " + ( isWsEmpty ? "" : AND + NOT + ws ) + " ) "; + else if (isForeignJoin) { // ) FOREIGN JOIN: (! A) & B // preparedValueList.add 不好反过来 B & ! A + newWs += " ( " + NOT + " ( " + ws + " ) ) " + AND + " ( " + js + " ) "; } else if (isSideJoin) { // ^ SIDE JOIN: ! (A & B) //MySQL 因为 NULL 值处理问题,(A & ! B) | (B & ! A) 与 ! (A & B) 返回结果不一样,后者往往更多 @@ -3203,7 +3203,7 @@ public static SQLConfig parseJoin(RequestMethod method, SQLConfig config, List resultList, Map continue; } - jc = j.getJoinConfig(); cc = j.getCacheConfig(); //这里用config改了getSQL后再还原很麻烦,所以提前给一个config2更好 + if (cc == null) { + if (Log.DEBUG) { + throw new NullPointerException("服务器内部错误, executeAppJoin cc == null ! 导致不能缓存 @ APP JOIN 的副表数据!"); + } + continue; + } + + jc = j.getJoinConfig(); //取出 "id@": "@/User/userId" 中所有 userId 的值 List targetValueList = new ArrayList<>(); @@ -543,15 +550,18 @@ protected JSONObject onPutColumn(@NotNull SQLConfig config, @NotNull ResultSet r } } } + + } + Object value = getValue(config, rs, rsmd, tablePosition, table, columnIndex, lable, childMap); + if (value != null) { if (finalTable == null) { finalTable = new JSONObject(true); childMap.put(childSql, finalTable); } + finalTable.put(lable, value); } - - finalTable.put(lable, getValue(config, rs, rsmd, tablePosition, table, columnIndex, lable, childMap)); - + return table; } diff --git a/APIJSONORM/src/main/java/apijson/orm/Join.java b/APIJSONORM/src/main/java/apijson/orm/Join.java index 01761037a..70c4401b9 100644 --- a/APIJSONORM/src/main/java/apijson/orm/Join.java +++ b/APIJSONORM/src/main/java/apijson/orm/Join.java @@ -162,7 +162,48 @@ else if (originKey.endsWith("<>")) { } + public boolean isAppJoin() { + return "@".equals(getJoinType()); + } + public boolean isLeftJoin() { + return "<".equals(getJoinType()); + } + public boolean isRightJoin() { + return ">".equals(getJoinType()); + } + public boolean isCrossJoin() { + return "*".equals(getJoinType()); + } + public boolean isInnerJoin() { + return "&".equals(getJoinType()); + } + public boolean isFullJoin() { + String jt = getJoinType(); + return "".equals(jt) || "|".equals(jt); + } + public boolean isOuterJoin() { + return "!".equals(getJoinType()); + } + public boolean isSideJoin() { + return "^".equals(getJoinType()); + } + public boolean isAntiJoin() { + return "(".equals(getJoinType()); + } + public boolean isForeignJoin() { + return ")".equals(getJoinType()); + } + public boolean isLeftOrRightJoin() { + String jt = getJoinType(); + return "<".equals(jt) || ">".equals(jt); + } + + public boolean canCacheViceTable() { + String jt = getJoinType(); + return "@".equals(jt) || "<".equals(jt) || ">".equals(jt) || "&".equals(jt) || "*".equals(jt) || ")".equals(jt); + } + public boolean isSQLJoin() { return ! isAppJoin(); } @@ -171,22 +212,13 @@ public static boolean isSQLJoin(Join j) { return j != null && j.isSQLJoin(); } - public boolean isAppJoin() { - return "@".equals(getJoinType()); - } - public static boolean isAppJoin(Join j) { return j != null && j.isAppJoin(); } - - public boolean isLeftOrRightJoin() { - return "<".equals(getJoinType()) || ">".equals(getJoinType()); - } - + public static boolean isLeftOrRightJoin(Join j) { return j != null && j.isLeftOrRightJoin(); } - }