Skip to content

Commit 78a7964

Browse files
committed
SQLAuto: support CRUD cache
1 parent 78152cb commit 78a7964

5 files changed

Lines changed: 305 additions & 117 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*Copyright ©2025 APIJSON(https://github.com/APIJSON)
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.*/
14+
15+
package apijson;
16+
17+
public class SQLUtil {
18+
public static boolean isRead(String sql) {
19+
return isRead(sql, false);
20+
}
21+
public static boolean isRead(String sql, boolean isRedis) {
22+
return ! isWrite(sql, isRedis);
23+
}
24+
25+
public static boolean isWrite(String sql) {
26+
return isWrite(sql, false);
27+
}
28+
public static boolean isWrite(String sql, boolean isRedis) {
29+
return isInsert(sql, isRedis) || isUpdate(sql, isRedis) || isDelete(sql, isRedis);
30+
}
31+
32+
public static boolean isSelect(String sql) {
33+
return isSelect(sql, false);
34+
}
35+
public static boolean isSelect(String sql, boolean isRedis) {
36+
return sql != null && ! (isInsert(sql, isRedis) || isUpdate(sql, isRedis) || isDelete(sql, isRedis));
37+
}
38+
39+
public static boolean isInsert(String sql) {
40+
return isInsert(sql, false);
41+
}
42+
public static boolean isInsert(String sql, boolean isRedis) {
43+
return sql != null && ((sql.startsWith("INSERT ") && ! isRedis) || (isRedis && (
44+
sql.startsWith("SADD ") || sql.startsWith("ZADD ")
45+
|| sql.startsWith("LPUSH ") || sql.startsWith("RPUSH ")
46+
)));
47+
}
48+
49+
public static boolean isUpdate(String sql) {
50+
return isUpdate(sql, false);
51+
}
52+
public static boolean isUpdate(String sql, boolean isRedis) {
53+
return sql != null && ((sql.startsWith("UPDATE ") && ! isRedis) || (isRedis && (sql.startsWith("SET ")
54+
|| sql.startsWith("HSET ") || sql.startsWith("MSET ")
55+
)));
56+
}
57+
58+
public static boolean isDelete(String sql) {
59+
return isDelete(sql, false);
60+
}
61+
public static boolean isDelete(String sql, boolean isRedis) {
62+
return sql != null && ((sql.startsWith("DELETE ") && ! isRedis)
63+
|| (isRedis && (sql.startsWith("DEL ") || sql.startsWith("HDEL ") || sql.startsWith("MDEL ")
64+
|| sql.startsWith("SREM ") || sql.startsWith("ZREM ")
65+
|| sql.startsWith("LPOP ") || sql.startsWith("RPOP ")
66+
|| sql.startsWith("FLUSHDB ") || sql.startsWith("FLUSHALL ")
67+
)));
68+
}
69+
70+
}

‎APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/java/apijson/boot/AutoTestNodeProcessSupervisor.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/*Copyright ©2025 APIJSON(https://github.com/APIJSON)
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.*/
14+
115
package apijson.boot;
216

317
import apijson.Log;

‎APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/java/apijson/boot/AutoTestRegressionScheduler.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/*Copyright ©2025 APIJSON(https://github.com/APIJSON)
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.*/
14+
115
package apijson.boot;
216

317
import apijson.Log;

0 commit comments

Comments
 (0)