Skip to content

Commit 9f64b61

Browse files
committed
AbstractSQLConfig 新增 UPSERT_TABLE_MAP:INSERT INTO ... ON DUPLICATE KEY UPDATE column = column + 1,升级版本为 8.3.0
1 parent 8a8d33e commit 9f64b61

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

APIJSONORM/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.github.Tencent</groupId>
77
<artifactId>APIJSON</artifactId>
8-
<version>8.2.0</version>
8+
<version>8.3.0</version>
99
<packaging>jar</packaging>
1010

1111
<name>APIJSONORM</name>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
public class Log {
1414
public static boolean DEBUG = false;
15-
public static final String VERSION = "8.2.0";
15+
public static final String VERSION = "8.3.0";
1616

1717
public static final String LEVEL_VERBOSE = "VERBOSE";
1818
public static final String LEVEL_INFO = "INFO";

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public abstract class AbstractSQLConfig<T, M extends Map<String, Object>, L exte
8686
* 表名映射,隐藏真实表名,对安全要求很高的表可以这么做
8787
*/
8888
public static Map<String, String> TABLE_KEY_MAP;
89+
public static Map<String, String> UPSERT_TABLE_MAP;
8990
/**
9091
* 字段名映射,隐藏真实字段名,对安全要求很高的表可以这么做,另外可以配置 name_tag:(name,tag) 来实现多字段 IN,length_tag:length(tag) 来实现 SQL 函数复杂条件
9192
*/
@@ -135,6 +136,8 @@ public abstract class AbstractSQLConfig<T, M extends Map<String, Object>, L exte
135136
TABLE_KEY_MAP.put(AllTableComment.class.getSimpleName(), AllTableComment.TABLE_NAME);
136137
TABLE_KEY_MAP.put(AllColumnComment.class.getSimpleName(), AllColumnComment.TABLE_NAME);
137138

139+
UPSERT_TABLE_MAP = new HashMap<>();
140+
138141
ALLOW_PARTIAL_UPDATE_FAIL_TABLE_MAP = new HashMap<>();
139142

140143
CONFIG_TABLE_LIST = new ArrayList<>(); // Table, Column 等是系统表 AbstractVerifier.SYSTEM_ACCESS_MAP.keySet());
@@ -5004,13 +5007,13 @@ public static <T, M extends Map<String, Object>, L extends List<Object>> String
50045007
// TODO procedure 改为 List<Procedure> procedureList; behind : true; function: callFunction(); String key; ...
50055008
// for (...) { Call procedure1();\n SQL \n; Call procedure2(); ... }
50065009
// 貌似不需要,因为 ObjectParser<T, M, L> 里就已经处理的顺序等,只是这里要解决下 Schema 问题。
5007-
5010+
String table = config.getTable();
50085011
String procedure = config.getProcedure();
50095012
if (StringUtil.isNotEmpty(procedure, true)) {
50105013
int ind = procedure.indexOf(".");
50115014
boolean hasPrefix = ind >= 0 && ind < procedure.indexOf("(");
50125015
String sch = hasPrefix ? AbstractFunctionParser.extractSchema(
5013-
procedure.substring(0, ind), config.getTable()
5016+
procedure.substring(0, ind), table
50145017
) : config.gainSQLSchema();
50155018

50165019
String q = config.getQuote();
@@ -5030,10 +5033,22 @@ public static <T, M extends Map<String, Object>, L extends List<Object>> String
50305033
method = GET;
50315034
}
50325035

5033-
String cSql = null;
5036+
String cSql;
50345037
switch (method) {
50355038
case POST:
5036-
return "INSERT INTO " + tablePath + config.gainColumnString() + " VALUES" + config.getValuesString();
5039+
String s = UPSERT_TABLE_MAP.get(table);
5040+
// 暂不支持,UNIQUE KEY 应该比较固定不会频繁改动,而且改了也是同步改后端配置,和前端传参关系不大
5041+
// Object obj = UPSERT_TABLE_MAP.get(table);
5042+
// if (obj instanceof String) {
5043+
// s += obj;
5044+
// } else if (obj instanceof Map<?, ?>) { // { "a+": 1, "b-": 1 }
5045+
// Map<String, Object> setObj = (Map<String, Object>) obj;
5046+
// AbstractSQLConfig<T, M, L> cfg = gainParser().createSQLConfig();
5047+
// s = cfg.gainSetString();
5048+
// }
5049+
5050+
return "INSERT INTO " + tablePath + config.gainColumnString() + " VALUES" + config.getValuesString()
5051+
+ (StringUtil.isEmpty(s) ? "" : " ON DUPLICATE KEY UPDATE " + s);
50375052
case PUT:
50385053
if(config.isClickHouse()){
50395054
return "ALTER TABLE " + tablePath + " UPDATE" + config.gainSetString() + config.gainWhereString(true);

0 commit comments

Comments
 (0)