Skip to content

Commit 5c7566f

Browse files
authored
merge master to springboot3 #667
#667
2 parents 604c677 + fec206c commit 5c7566f

10 files changed

+149
-53
lines changed

APIJSONORM/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.github.Tencent</groupId>
77
<artifactId>APIJSON-spring-boot3</artifactId>
8-
<version>6.2.0</version>
8+
<version>6.4.0</version>
99
<packaging>jar</packaging>
1010

1111
<name>APIJSONORM</name>

APIJSONORM/src/main/java/apijson/Log.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class Log {
1414

1515
public static boolean DEBUG = true;
1616

17-
public static final String VERSION = "6.2.1";
17+
public static final String VERSION = "6.4.0";
1818
public static final String KEY_SYSTEM_INFO_DIVIDER = "\n---|-----APIJSON SYSTEM INFO-----|---\n";
1919

2020
public static final String OS_NAME;

APIJSONORM/src/main/java/apijson/RequestMethod.java

+16
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ public static boolean isHeadMethod(RequestMethod method, boolean containPrivate)
8383
public static boolean isQueryMethod(RequestMethod method) {
8484
return isGetMethod(method, true) || isHeadMethod(method, true);
8585
}
86+
87+
/**是否为更新(增删改)的请求方法
88+
* @param method
89+
* @return 读操作(GET型或HEAD型) - false, 写操作(POST,PUT,DELETE) - true
90+
*/
91+
public static boolean isUpdateMethod(RequestMethod method) {
92+
return ! isQueryMethod(method);
93+
}
8694

8795
/**是否为开放(不限制请求的结构或内容;明文,浏览器能直接访问及查看)的请求方法
8896
* @param method
@@ -92,6 +100,14 @@ public static boolean isPublicMethod(RequestMethod method) {
92100
return method == null || method == GET || method == HEAD;
93101
}
94102

103+
/**是否为私有(限制请求的结构或内容)的请求方法
104+
* @param method
105+
* @return
106+
*/
107+
public static boolean isPrivateMethod(RequestMethod method) {
108+
return ! isPublicMethod(method);
109+
}
110+
95111
public static String getName(RequestMethod method) {
96112
return method == null ? GET.name() : method.name();
97113
}

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

+70-16
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public abstract class AbstractSQLConfig<T extends Object> implements SQLConfig<T
157157
// TODO 改成更好的正则,校验前面为单词,中间为操作符,后面为值
158158
PATTERN_FUNCTION = Pattern.compile("^[A-Za-z0-9%,:_@&~`!=\\<\\>\\|\\[\\]\\{\\} /\\.\\+\\-\\*\\^\\?\\(\\)\\$]+$");
159159

160-
TABLE_KEY_MAP = new HashMap<String, String>();
160+
TABLE_KEY_MAP = new HashMap<>();
161161
TABLE_KEY_MAP.put(Table.class.getSimpleName(), Table.TABLE_NAME);
162162
TABLE_KEY_MAP.put(Column.class.getSimpleName(), Column.TABLE_NAME);
163163
TABLE_KEY_MAP.put(PgClass.class.getSimpleName(), PgClass.TABLE_NAME);
@@ -195,9 +195,15 @@ public abstract class AbstractSQLConfig<T extends Object> implements SQLConfig<T
195195
DATABASE_LIST.add(DATABASE_HIVE);
196196
DATABASE_LIST.add(DATABASE_PRESTO);
197197
DATABASE_LIST.add(DATABASE_TRINO);
198+
DATABASE_LIST.add(DATABASE_MILVUS);
198199
DATABASE_LIST.add(DATABASE_INFLUXDB);
199200
DATABASE_LIST.add(DATABASE_TDENGINE);
201+
DATABASE_LIST.add(DATABASE_SNOWFLAKE);
202+
DATABASE_LIST.add(DATABASE_DATABRICKS);
200203
DATABASE_LIST.add(DATABASE_REDIS);
204+
DATABASE_LIST.add(DATABASE_MONGODB);
205+
DATABASE_LIST.add(DATABASE_CASSANDRA);
206+
DATABASE_LIST.add(DATABASE_KAFKA);
201207
DATABASE_LIST.add(DATABASE_MQ);
202208

203209
RAW_MAP = new LinkedHashMap<>(); // 保证顺序,避免配置冲突等意外情况
@@ -1189,6 +1195,14 @@ public static boolean isPresto(String db) {
11891195
return DATABASE_PRESTO.equals(db);
11901196
}
11911197

1198+
@Override
1199+
public boolean isTrino() {
1200+
return isTrino(getSQLDatabase());
1201+
}
1202+
public static boolean isTrino(String db) {
1203+
return DATABASE_TRINO.equals(db);
1204+
}
1205+
11921206
@Override
11931207
public boolean isSnowflake() {
11941208
return isSnowflake(getSQLDatabase());
@@ -1214,11 +1228,11 @@ public static boolean isCassandra(String db) {
12141228
}
12151229

12161230
@Override
1217-
public boolean isTrino() {
1218-
return isTrino(getSQLDatabase());
1231+
public boolean isMilvus() {
1232+
return isMilvus(getSQLDatabase());
12191233
}
1220-
public static boolean isTrino(String db) {
1221-
return DATABASE_TRINO.equals(db);
1234+
public static boolean isMilvus(String db) {
1235+
return DATABASE_MILVUS.equals(db);
12221236
}
12231237

12241238
@Override
@@ -1245,20 +1259,36 @@ public static boolean isRedis(String db) {
12451259
return DATABASE_REDIS.equals(db);
12461260
}
12471261

1262+
@Override
1263+
public boolean isMongoDB() {
1264+
return isMongoDB(getSQLDatabase());
1265+
}
1266+
public static boolean isMongoDB(String db) {
1267+
return DATABASE_MONGODB.equals(db);
1268+
}
1269+
1270+
@Override
1271+
public boolean isKafka() {
1272+
return isKafka(getSQLDatabase());
1273+
}
1274+
public static boolean isKafka(String db) {
1275+
return DATABASE_KAFKA.equals(db);
1276+
}
1277+
12481278
@Override
12491279
public boolean isMQ() {
12501280
return isMQ(getSQLDatabase());
12511281
}
12521282
public static boolean isMQ(String db) {
1253-
return DATABASE_MQ.equals(db);
1283+
return DATABASE_MQ.equals(db) || isKafka(db);
12541284
}
12551285

12561286
@Override
12571287
public String getQuote() {
12581288
if(isElasticsearch()) {
12591289
return "";
12601290
}
1261-
return isMySQL() || isMariaDB() || isTiDB() || isClickHouse() || isTDengine() ? "`" : "\"";
1291+
return isMySQL() || isMariaDB() || isTiDB() || isClickHouse() || isTDengine() || isMilvus() ? "`" : "\"";
12621292
}
12631293

12641294
public String quote(String s) {
@@ -1272,6 +1302,7 @@ public String getSchema() {
12721302
}
12731303

12741304
@NotNull
1305+
@Override
12751306
public String getSQLSchema() {
12761307
String table = getTable();
12771308
//强制,避免因为全局默认的 @schema 自动填充进来,导致这几个类的 schema 为 sys 等其它值
@@ -1953,14 +1984,14 @@ public String getColumnString(boolean inSQLJoin) throws Exception {
19531984
}
19541985

19551986
// 简单点, 后台配置就带上 AS
1956-
// int index = expression.lastIndexOf(":");
1957-
// String alias = expression.substring(index+1);
1958-
// boolean hasAlias = StringUtil.isName(alias);
1959-
// String pre = index > 0 && hasAlias ? expression.substring(0, index) : expression;
1960-
// if (RAW_MAP.containsValue(pre) || "".equals(RAW_MAP.get(pre))) { // newSQLConfig 提前处理好的
1961-
// expression = pre + (hasAlias ? " AS " + alias : "");
1962-
// continue;
1963-
// }
1987+
int index = expression.lastIndexOf(":");
1988+
String alias = expression.substring(index+1);
1989+
boolean hasAlias = StringUtil.isName(alias);
1990+
String pre = index > 0 && hasAlias ? expression.substring(0, index) : expression;
1991+
if (RAW_MAP.containsValue(pre) || "".equals(RAW_MAP.get(pre))) { // newSQLConfig 提前处理好的
1992+
keys[i] = pre + (hasAlias ? " AS " + alias : "");
1993+
continue;
1994+
}
19641995
}
19651996

19661997
if (expression.length() > 100) {
@@ -2001,6 +2032,16 @@ public String parseSQLExpression(String key, String expression, boolean containR
20012032
* @return
20022033
*/
20032034
public String parseSQLExpression(String key, String expression, boolean containRaw, boolean allowAlias, String example) {
2035+
if (containRaw) {
2036+
String s = RAW_MAP.get(expression);
2037+
if ("".equals(s)) {
2038+
return expression;
2039+
}
2040+
if (s != null) {
2041+
return s;
2042+
}
2043+
}
2044+
20042045
String quote = getQuote();
20052046
int start = expression.indexOf('(');
20062047
if (start < 0) {
@@ -2578,9 +2619,22 @@ public static int getOffset(int page, int count) {
25782619
*/
25792620
@JSONField(serialize = false)
25802621
public String getLimitString() {
2581-
if (count <= 0 || RequestMethod.isHeadMethod(getMethod(), true)) {
2622+
int count = getCount();
2623+
2624+
if (isMilvus()) {
2625+
if (count == 0) {
2626+
Parser<T> parser = getParser();
2627+
count = parser == null ? AbstractParser.MAX_QUERY_COUNT : parser.getMaxQueryCount();
2628+
}
2629+
2630+
int offset = getOffset(getPage(), count);
2631+
return " LIMIT " + offset + ", " + count; // 目前 moql-transx 的限制
2632+
}
2633+
2634+
if (count <= 0 || RequestMethod.isHeadMethod(getMethod(), true)) { // TODO HEAD 真的不需要 LIMIT ?
25822635
return "";
25832636
}
2637+
25842638
return getLimitString(
25852639
getPage()
25862640
, getCount()

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
public abstract class AbstractVerifier<T extends Object> implements Verifier<T>, IdCallback<T> {
8181
private static final String TAG = "AbstractVerifier";
8282

83-
/**为 PUT, DELETE 强制要求必须有 id/id{} 条件
83+
/**为 PUT, DELETE 强制要求必须有 id/id{}/id{}@ 条件
8484
*/
8585
public static boolean IS_UPDATE_MUST_HAVE_ID_CONDITION = true;
8686
/**开启校验请求角色权限
@@ -700,8 +700,9 @@ public JSONObject onParseJSONObject(String key, JSONObject tobj, JSONObject robj
700700
throw new IllegalArgumentException(method + "请求," + name + "/" + key + " 不能传 " + finalIdKey + " !");
701701
}
702702
} else {
703-
if (RequestMethod.isQueryMethod(method) == false) {
704-
verifyId(method.name(), name, key, robj, finalIdKey, maxUpdateCount, IS_UPDATE_MUST_HAVE_ID_CONDITION);
703+
Boolean atLeastOne = tobj == null ? null : tobj.getBoolean(Operation.IS_ID_CONDITION_MUST.name());
704+
if (Boolean.TRUE.equals(atLeastOne) || RequestMethod.isUpdateMethod(method)) {
705+
verifyId(method.name(), name, key, robj, finalIdKey, maxUpdateCount, atLeastOne != null ? atLeastOne : IS_UPDATE_MUST_HAVE_ID_CONDITION);
705706

706707
String userIdKey = idCallback == null ? null : idCallback.getUserIdKey(db, sh, ds, key);
707708
String finalUserIdKey = StringUtil.isEmpty(userIdKey, false) ? apijson.JSONObject.KEY_USER_ID : userIdKey;
@@ -746,7 +747,7 @@ private static void verifyId(@NotNull String method, @NotNull String name, @NotN
746747
Object id = robj.get(idKey); //如果必须传 id ,可在Request表中配置NECESSARY
747748
if (id != null && id instanceof Number == false && id instanceof String == false) {
748749
throw new IllegalArgumentException(method + "请求," + name + "/" + key
749-
+ " 里面的 " + idKey + ":value 中value的类型只能是 Long 或 String !");
750+
+ " 里面的 " + idKey + ":value 中value的类型只能是 Long 或 String !");
750751
}
751752

752753

@@ -795,7 +796,7 @@ else if (o instanceof String) {
795796
}
796797
else {
797798
throw new IllegalArgumentException(method + "请求," + name + "/" + key
798-
+ " 里面的 " + idInKey + ":[] 中所有项的类型都只能是 Long 或 String !");
799+
+ " 里面的 " + idInKey + ":[] 中所有项的类型都只能是 Long 或 String !");
799800
}
800801
}
801802
}

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,13 @@ public enum Operation {
145145
/**
146146
* 允许批量增删改部分失败,结构是
147147
* "Table[],key[],key:alias[]"
148-
* 自动 ALLOW_PARTIAL_UPDATE_FAILED_TABLE_MAP.put
148+
* 自动 ALLOW_PARTIAL_UPDATE_FAILED_TABLE_MAP.put,结构是 Boolean,例如 true
149149
*/
150-
ALLOW_PARTIAL_UPDATE_FAIL;
150+
ALLOW_PARTIAL_UPDATE_FAIL,
151+
152+
/**
153+
* 强制要求必须有 id/id{}/id{}@ 条件,结构是 Boolean,例如 true
154+
*/
155+
IS_ID_CONDITION_MUST;
151156

152157
}

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

+16-9
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ public interface SQLConfig<T extends Object> {
3434
String DATABASE_SNOWFLAKE = "SNOWFLAKE"; // https://www.snowflake.com
3535
String DATABASE_DATABRICKS = "DATABRICKS"; // https://www.databricks.com
3636
String DATABASE_CASSANDRA = "CASSANDRA"; // https://cassandra.apache.org
37+
String DATABASE_MILVUS = "MILVUS"; // https://milvus.io
3738
String DATABASE_INFLUXDB = "INFLUXDB"; // https://www.influxdata.com/products/influxdb-overview
3839
String DATABASE_TDENGINE = "TDENGINE"; // https://tdengine.com
39-
String DATABASE_REDIS = "REDIS";
40-
String DATABASE_MQ = "MQ";
40+
String DATABASE_REDIS = "REDIS"; // https://redisql.com
41+
String DATABASE_MONGODB = "MONGODB"; // https://www.mongodb.com/docs/atlas/data-federation/query/query-with-sql
42+
String DATABASE_KAFKA = "KAFKA"; // https://github.com/APIJSON/APIJSON-Demo/tree/master/APIJSON-Java-Server/APIJSONDemo-MultiDataSource-Kafka
43+
String DATABASE_MQ = "MQ"; //
4144

4245
String SCHEMA_INFORMATION = "information_schema"; //MySQL, PostgreSQL, SQL Server 都有的系统模式
4346
String SCHEMA_SYS = "sys"; //SQL Server 系统模式
@@ -50,19 +53,19 @@ public interface SQLConfig<T extends Object> {
5053

5154
Parser<T> getParser();
5255

53-
AbstractSQLConfig setParser(Parser<T> parser);
56+
SQLConfig setParser(Parser<T> parser);
5457

5558
ObjectParser getObjectParser();
5659

57-
AbstractSQLConfig setObjectParser(ObjectParser objectParser);
60+
SQLConfig setObjectParser(ObjectParser objectParser);
5861

5962
int getVersion();
6063

61-
AbstractSQLConfig setVersion(int version);
64+
SQLConfig setVersion(int version);
6265

6366
String getTag();
6467

65-
AbstractSQLConfig setTag(String tag);
68+
SQLConfig setTag(String tag);
6669

6770
boolean isMySQL();
6871
boolean isPostgreSQL();
@@ -77,17 +80,20 @@ public interface SQLConfig<T extends Object> {
7780
boolean isClickHouse();
7881
boolean isHive();
7982
boolean isPresto();
83+
boolean isTrino();
8084
boolean isSnowflake();
8185
boolean isDatabricks();
8286
boolean isCassandra();
83-
boolean isTrino();
87+
boolean isMilvus();
8488
boolean isInfluxDB();
8589
boolean isTDengine();
8690
boolean isRedis();
91+
boolean isMongoDB();
92+
boolean isKafka();
8793
boolean isMQ();
8894

8995

90-
//暂时只兼容以上几种
96+
// 暂时只兼容以上几种
9197
// boolean isSQL();
9298
// boolean isTSQL();
9399
// boolean isPLSQL();
@@ -215,6 +221,7 @@ default int[] getDBVersionNums() {
215221
String getDatabase();
216222
SQLConfig setDatabase(String database);
217223

224+
String getSQLSchema();
218225
String getSchema();
219226
SQLConfig setSchema(String schema);
220227

@@ -243,7 +250,7 @@ default int[] getDBVersionNums() {
243250
String getTablePath();
244251

245252
Map<String, String> getKeyMap();
246-
AbstractSQLConfig setKeyMap(Map<String, String> keyMap);
253+
SQLConfig setKeyMap(Map<String, String> keyMap);
247254

248255
List<String> getRaw();
249256
SQLConfig setRaw(List<String> raw);

0 commit comments

Comments
 (0)