Skip to content

Commit 09ce7ec

Browse files
committed
新增 APIJSON 8.3 UPSERT 配置示例,新增 APIJSON-8.3.0-preview.jar,升级 apijson-fastjson2-1.2.1.jar
1 parent 50c8bae commit 09ce7ec

3 files changed

Lines changed: 51 additions & 10 deletions

File tree

Binary file not shown.

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/libs/apijson-fastjson2-1.2.0.jar renamed to APIJSON-Java-Server/APIJSONBoot-MultiDataSource/libs/apijson-fastjson2-1.2.1.jar

37 KB
Binary file not shown.

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

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,23 @@
1414

1515
package apijson.demo;
1616

17-
import static apijson.framework.APIJSONConstant.ID;
18-
import static apijson.framework.APIJSONConstant.PRIVACY_;
19-
import static apijson.framework.APIJSONConstant.USER_;
20-
import static apijson.framework.APIJSONConstant.USER_ID;
21-
2217
import java.text.SimpleDateFormat;
2318
import java.util.*;
2419

2520
//import apijson.influxdb.InfluxDBUtil;
2621
//import apijson.iotdb.IoTDBUtil;
2722
import apijson.RequestMethod;
2823
import apijson.StringUtil;
29-
import apijson.orm.AbstractParser;
30-
import apijson.orm.AbstractSQLConfig;
31-
import apijson.orm.Parser;
24+
import apijson.orm.*;
3225
//import apijson.surrealdb.SurrealDBUtil;
3326
import com.alibaba.fastjson2.JSONArray;
3427
import com.alibaba.fastjson2.JSONObject;
3528

3629
import apijson.framework.ColumnUtil;
3730
import apijson.fastjson2.APIJSONSQLConfig;
38-
import apijson.orm.Join;
3931
import apijson.orm.Join.On;
32+
33+
import static apijson.framework.APIJSONConstant.*;
4034
//import org.influxdb.InfluxDB;
4135

4236

@@ -51,6 +45,7 @@ public class DemoSQLConfig extends APIJSONSQLConfig<Long> {
5145
public DemoSQLConfig() {
5246
super();
5347
}
48+
5449
public DemoSQLConfig(RequestMethod method, String table) {
5550
super(method, table);
5651
}
@@ -107,6 +102,42 @@ public String getUserIdKey(String database, String datasource, String namespace,
107102
// }
108103
};
109104

105+
// 需依赖 APIJSON 8.3.0+
106+
//// INSERT INTO `sys`.`Method`(`package`,`method`,`detail`,`userId`) VALUES('unitauto.test','test','测试 UPSERT',82001) ON DUPLICATE KEY UPDATE version = version + 1
107+
//UPSERT_TABLE_MAP.put("Method", "version = version + 1"); // 最简单的配置,一般适用于 MySQL, PostgreSQL 及兼容它们语法的数据库
108+
//// Oracle/PostgreSQL/SQL Server 配置
109+
////{
110+
//// Map<String, Object> pgMap = new LinkedHashMap<>();
111+
//// pgMap.put("package,method", "version = excluded.version + 1");
112+
//// Map<String, Object> dbMap = new LinkedHashMap<>();
113+
//// dbMap.put(SQLConfig.DATABASE_POSTGRESQL, pgMap);
114+
////
115+
//// Map<String, Object> db2Map = new LinkedHashMap<>();
116+
//// pgMap.put("package,method", "Method.version = excluded.version + 1");
117+
//// dbMap.put(SQLConfig.DATABASE_DB2, db2Map); // 针对 DB2 的配置
118+
////
119+
//// dbMap.put("package,method", "version = version + 1"); // 除了明确的按数据库配置外的默认配置
120+
//// UPSERT_TABLE_MAP.put("Method", dbMap);
121+
////}
122+
//
123+
//// POST /post {"Request":{"method":"GETS","tag":"Test","structure":"{}","tag":"Request"}}
124+
//// UPSERT_TABLE_MAP.put(REQUEST_, "version = version + 1"); // 最简单的配置,一般适用于 MySQL, PostgreSQL 及兼容它们语法的数据库
125+
//// Oracle/PostgreSQL/SQL Server 配置
126+
//{
127+
// Map<String, Object> map = new LinkedHashMap<>();
128+
// map.put("", "version = excluded.version + 1");
129+
// Map<String, Object> dbMap = new LinkedHashMap<>();
130+
// dbMap.put(SQLConfig.DATABASE_POSTGRESQL, map); // 针对 PostgreSQL 的配置
131+
//
132+
// Map<String, Object> oracleMap = new LinkedHashMap<>();
133+
// oracleMap.put("package,method", "Method.version = excluded.version + 1");
134+
// dbMap.put(SQLConfig.DATABASE_ORACLE, oracleMap); // 针对 Oracle 的配置
135+
//
136+
// dbMap.put("", "version = version + 1"); // 除了明确的按数据库配置外的默认配置
137+
// UPSERT_TABLE_MAP.put(REQUEST_, dbMap);
138+
//}
139+
140+
110141
// 自定义原始 SQL 片段,其它功能满足不了时才用它,只有 RAW_MAP 配置了的 key 才允许前端传
111142
RAW_MAP.put("`to`.`id`", ""); // 空字符串 "" 表示用 key 的值 `to`.`id`
112143
RAW_MAP.put("toDate", ""); // "@column": "date;date_format('2020-01-01','%Y-%m-%d'):toDate", "@having": "(date > toDate)", "@raw": "@column,@having"
@@ -229,10 +260,12 @@ public String gainDBVersion() {
229260
}
230261

231262
private String dbUri;
263+
232264
public DemoSQLConfig setDBUri(String dbUri) {
233265
this.dbUri = dbUri;
234266
return this;
235267
}
268+
236269
@Override
237270
public String gainDBUri() {
238271
if (StringUtil.isNotEmpty(dbUri)) {
@@ -273,7 +306,7 @@ public String gainDBUri() {
273306
return "jdbc:TAOS-RS://localhost:6041"; //TODO 改成你自己的
274307
}
275308
if (isTimescaleDB()) { // PG JDBC 必须在 URI 传 catalog
276-
return "jdbc:postgresql://localhost:5432/postgres?stringtype=unspecified"; //TODO 改成你自己的
309+
return "jdbc:postgresql://localhost:5432/postgres?stringtype=unspecified"; //TODO 改成你自己的
277310
}
278311
if (isQuestDB()) { // PG JDBC 必须在 URI 传 catalog
279312
return "jdbc:postgresql://localhost:8812/qdb"; //TODO 改成你自己的
@@ -321,10 +354,12 @@ public String gainDBUri() {
321354
}
322355

323356
private String dbAccount;
357+
324358
public DemoSQLConfig setDBAccount(String dbAccount) {
325359
this.dbAccount = dbAccount;
326360
return this;
327361
}
362+
328363
@Override
329364
public String gainDBAccount() {
330365
if (StringUtil.isNotEmpty(dbAccount)) {
@@ -408,10 +443,12 @@ public String gainDBAccount() {
408443
}
409444

410445
private String dbPassword;
446+
411447
public DemoSQLConfig setDBPassword(String dbPassword) {
412448
this.dbPassword = dbPassword;
413449
return this;
414450
}
451+
415452
@Override
416453
public String gainDBPassword() {
417454
if (StringUtil.isNotEmpty(dbPassword)) {
@@ -493,9 +530,11 @@ public String gainDBPassword() {
493530
}
494531

495532
private String sql;
533+
496534
public String gainSQL() throws Exception {
497535
return gainSQL(isPrepared());
498536
}
537+
499538
@Override
500539
public String gainSQL(boolean prepared) throws Exception {
501540
if (StringUtil.isNotEmpty(sql)) {
@@ -576,10 +615,12 @@ public void setSql(String sql) {
576615
protected void onGainCrossJoinString(Join<Long, JSONObject, JSONArray> join) throws UnsupportedOperationException {
577616
// 开启 CROSS JOIN 笛卡尔积联表 super.onGetCrossJoinString(join);
578617
}
618+
579619
@Override
580620
protected void onJoinNotRelation(String sql, String quote, Join<Long, JSONObject, JSONArray> join, String table, List<On> onList, On on) {
581621
// 开启 JOIN ON t1.c1 != t2.c2 等不等式关联 super.onJoinNotRelation(sql, quote, join, table, onList, on);
582622
}
623+
583624
@Override
584625
protected void onJoinComplexRelation(String sql, String quote, Join<Long, JSONObject, JSONArray> join, String table, List<On> onList, On on) {
585626
// 开启 JOIN ON t1.c1 LIKE concat('%', t2.c2, '%') 等复杂关联 super.onJoinComplexRelation(sql, quote, join, table, onList, on);

0 commit comments

Comments
 (0)