Skip to content

Commit ba95225

Browse files
committed
Java:APIJSONBoot 系列新增当前用户相关的远程函数,默认开启 * CROSS JOIN、非等价的复杂 JOIN ON 关联方式
1 parent be0601a commit ba95225

File tree

4 files changed

+76
-20
lines changed

4 files changed

+76
-20
lines changed

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/java/apijson/demo/DemoFunctionParser.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import java.util.ArrayList;
1818
import java.util.Arrays;
1919
import java.util.Collection;
20-
import java.util.Iterator;
2120
import java.util.List;
2221

2322
import javax.servlet.http.HttpSession;

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import apijson.column.ColumnUtil;
3232
import apijson.framework.APIJSONSQLConfig;
3333
import apijson.orm.AbstractSQLConfig;
34+
import apijson.orm.Join;
35+
import apijson.orm.Join.On;
3436

3537

3638
/**SQL配置
@@ -293,5 +295,19 @@ public String getDBPassword() {
293295
// }
294296
// return super.getValue(value);
295297
// }
298+
299+
300+
@Override
301+
protected void onGetCrossJoinString(Join j) throws UnsupportedOperationException {
302+
// 开启 CROSS JOIN 笛卡尔积联表 super.onGetCrossJoinString(j);
303+
}
304+
@Override
305+
protected void onJoinNotRelation(String sql, String quote, Join j, String jt, List<On> onList, On on) {
306+
// 开启 JOIN ON t1.c1 != t2.c2 等不等式关联 super.onJoinNotRelation(sql, quote, j, jt, onList, on);
307+
}
308+
@Override
309+
protected void onJoinComplextRelation(String sql, String quote, Join j, String jt, List<On> onList, On on) {
310+
// 开启 JOIN ON t1.c1 LIKE concat('%', t2.c2, '%') 等复杂关联 super.onJoinComplextRelation(sql, quote, j, jt, onList, on);
311+
}
296312

297313
}

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

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.ArrayList;
1818
import java.util.Arrays;
1919
import java.util.Collection;
20+
import java.util.List;
2021

2122
import javax.servlet.http.HttpSession;
2223

@@ -30,6 +31,7 @@
3031
import apijson.framework.APIJSONFunctionParser;
3132
import apijson.orm.AbstractVerifier;
3233
import apijson.orm.JSONRequest;
34+
import apijson.orm.Visitor;
3335

3436

3537
/**可远程调用的函数类,用于自定义业务逻辑处理
@@ -45,31 +47,51 @@ public DemoFunctionParser() {
4547
public DemoFunctionParser(RequestMethod method, String tag, int version, JSONObject request, HttpSession session) {
4648
super(method, tag, version, request, session);
4749
}
50+
51+
public Visitor<Long> getCurrentUser(@NotNull JSONObject current) {
52+
return DemoVerifier.getVisitor(getSession());
53+
}
54+
55+
public Long getCurrentUserId(@NotNull JSONObject current) {
56+
return DemoVerifier.getVisitorId(getSession());
57+
}
58+
59+
public List<Long> getCurrentUserIdAsList(@NotNull JSONObject current) {
60+
return Arrays.asList(DemoVerifier.getVisitorId(getSession()));
61+
}
62+
63+
public List<Long> getCurrentContactIdList(@NotNull JSONObject current) {
64+
Visitor<Long> user = getCurrentUser(current);
65+
return user == null ? null : user.getContactIdList();
66+
}
67+
4868

4969
/**
5070
* @param current
5171
* @param idList
5272
* @return
5373
* @throws Exception
5474
*/
55-
public Object verifyIdList(@NotNull JSONObject current, @NotNull String idList) throws Exception {
75+
public void verifyIdList(@NotNull JSONObject current, @NotNull String idList) throws Exception {
5676
Object obj = current.get(idList);
5777
if (obj == null) {
58-
return null;
78+
return;
5979
}
6080

6181
if (obj instanceof Collection == false) {
62-
throw new IllegalArgumentException(idList + " 不符合 Array 类型! 结构必须是 [] !");
82+
throw new IllegalArgumentException(idList + " 不符合 Array 数组类型! 结构必须是 [] !");
6383
}
64-
JSONArray array = (JSONArray) obj;
65-
if (array != null) {
66-
for (int i = 0; i < array.size(); i++) {
67-
if (array.get(i) instanceof Long == false && array.get(i) instanceof Integer == false) {
68-
throw new IllegalArgumentException(idList + " 内字符 " + array.getString(i) + " 不符合 Long 类型!");
84+
85+
Collection<?> collection = (Collection<?>) obj;
86+
if (collection != null) {
87+
int i = -1;
88+
for (Object item : collection) {
89+
i ++;
90+
if (item instanceof Long == false && item instanceof Integer == false) {
91+
throw new IllegalArgumentException(idList + "/" + i + ": " + item + " 不符合 Long 数字类型!");
6992
}
7093
}
7194
}
72-
return null;
7395
}
7496

7597

@@ -79,24 +101,26 @@ public Object verifyIdList(@NotNull JSONObject current, @NotNull String idList)
79101
* @return
80102
* @throws Exception
81103
*/
82-
public Object verifyURLList(@NotNull JSONObject current, @NotNull String urlList) throws Exception {
104+
public void verifyURLList(@NotNull JSONObject current, @NotNull String urlList) throws Exception {
83105
Object obj = current.get(urlList);
84106
if (obj == null) {
85-
return null;
107+
return;
86108
}
87109

88110
if (obj instanceof Collection == false) {
89-
throw new IllegalArgumentException(urlList + " 不符合 Array 类型! 结构必须是 [] !");
111+
throw new IllegalArgumentException(urlList + " 不符合 Array 数组类型! 结构必须是 [] !");
90112
}
91-
JSONArray array = (JSONArray) obj;
92-
if (array != null) {
93-
for (int i = 0; i < array.size(); i++) {
94-
if (StringUtil.isUrl(array.getString(i)) == false) {
95-
throw new IllegalArgumentException(urlList + " 内字符 " + array.getString(i) + " 不符合 URL 格式!");
113+
114+
Collection<?> collection = (Collection<?>) obj;
115+
if (collection != null) {
116+
int i = -1;
117+
for (Object item : collection) {
118+
i ++;
119+
if (item instanceof String == false || StringUtil.isUrl((String) item) == false) {
120+
throw new IllegalArgumentException(urlList + "/" + i + ": " + item + " 不符合 URL 字符串格式!");
96121
}
97122
}
98123
}
99-
return null;
100124
}
101125

102126

@@ -211,6 +235,7 @@ public JSONArray getIdList(@NotNull JSONObject current) {
211235
* @return
212236
* @throws Exception
213237
*/
238+
@Override
214239
public Object verifyAccess(@NotNull JSONObject current) throws Exception {
215240
long userId = current.getLongValue(JSONRequest.KEY_USER_ID);
216241
String role = current.getString(JSONRequest.KEY_ROLE);

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
import apijson.column.ColumnUtil;
3232
import apijson.framework.APIJSONSQLConfig;
3333
import apijson.orm.AbstractSQLConfig;
34+
import apijson.orm.Join;
35+
import apijson.orm.Join.On;
3436

3537

36-
/**SQL 配置
38+
/**SQL配置
3739
* TiDB 用法和 MySQL 一致
3840
* 具体见详细的说明文档 C.开发说明 C-1-1.修改数据库链接
3941
* https://github.com/Tencent/APIJSON/blob/master/%E8%AF%A6%E7%BB%86%E7%9A%84%E8%AF%B4%E6%98%8E%E6%96%87%E6%A1%A3.md#c-1-1%E4%BF%AE%E6%94%B9%E6%95%B0%E6%8D%AE%E5%BA%93%E9%93%BE%E6%8E%A5
@@ -293,5 +295,19 @@ public String getDBPassword() {
293295
// }
294296
// return super.getValue(value);
295297
// }
298+
299+
300+
@Override
301+
protected void onGetCrossJoinString(Join j) throws UnsupportedOperationException {
302+
// 开启 CROSS JOIN 笛卡尔积联表 super.onGetCrossJoinString(j);
303+
}
304+
@Override
305+
protected void onJoinNotRelation(String sql, String quote, Join j, String jt, List<On> onList, On on) {
306+
// 开启 JOIN ON t1.c1 != t2.c2 等不等式关联 super.onJoinNotRelation(sql, quote, j, jt, onList, on);
307+
}
308+
@Override
309+
protected void onJoinComplextRelation(String sql, String quote, Join j, String jt, List<On> onList, On on) {
310+
// 开启 JOIN ON t1.c1 LIKE concat('%', t2.c2, '%') 等复杂关联 super.onJoinComplextRelation(sql, quote, j, jt, onList, on);
311+
}
296312

297313
}

0 commit comments

Comments
 (0)