Skip to content

Commit e61da33

Browse files
committed
Java:MultiDataSource 优化 Redis 缓存
1 parent 3c1a542 commit e61da33

File tree

3 files changed

+28
-49
lines changed

3 files changed

+28
-49
lines changed

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/pom.xml

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>apijson.boot</groupId>
77
<artifactId>apijson-boot-multi-datasource</artifactId>
8-
<version>5.4.0</version>
8+
<version>6.0.0</version>
99
<packaging>jar</packaging>
1010

1111
<name>APIJSONBoot-MultiDataSource</name>
@@ -19,13 +19,6 @@
1919
</properties>
2020

2121
<dependencies>
22-
<!-- JDK 11+ 需要,否则启动报错 NoClassDefFoundError: javax/activation/UnsupportedDataTypeException -->
23-
<dependency>
24-
<groupId>javax.activation</groupId>
25-
<artifactId>activation</artifactId>
26-
<version>1.1.1</version>
27-
</dependency>
28-
2922
<!-- APIJSON 需要用的依赖库,1.2.0 以上 -->
3023
<dependency>
3124
<groupId>com.alibaba</groupId>
@@ -60,26 +53,26 @@
6053

6154

6255
<!-- 可使用 libs 目录的 apijson-orm.jar, apijson-framework.jar, apijson-column.jar 来替代,两种方式二选一 <<<<<<<<<< -->
63-
<dependency>
64-
<groupId>com.github.Tencent</groupId>
65-
<artifactId>APIJSON</artifactId>
66-
<version>5.4.0</version>
67-
</dependency>
68-
<dependency>
69-
<groupId>com.github.APIJSON</groupId>
70-
<artifactId>apijson-framework</artifactId>
71-
<version>5.4.0</version>
72-
</dependency>
73-
<dependency>
74-
<groupId>com.github.APIJSON</groupId>
75-
<artifactId>apijson-column</artifactId>
76-
<version>1.2.9</version>
77-
</dependency>
78-
<dependency>
79-
<groupId>com.github.APIJSON</groupId>
80-
<artifactId>apijson-router</artifactId>
81-
<version>1.1.0</version>
82-
</dependency>
56+
<!-- <dependency>-->
57+
<!-- <groupId>com.github.Tencent</groupId>-->
58+
<!-- <artifactId>APIJSON</artifactId>-->
59+
<!-- <version>6.0.0</version>-->
60+
<!-- </dependency>-->
61+
<!-- <dependency>-->
62+
<!-- <groupId>com.github.APIJSON</groupId>-->
63+
<!-- <artifactId>apijson-framework</artifactId>-->
64+
<!-- <version>6.0.0</version>-->
65+
<!-- </dependency>-->
66+
<!-- <dependency>-->
67+
<!-- <groupId>com.github.APIJSON</groupId>-->
68+
<!-- <artifactId>apijson-column</artifactId>-->
69+
<!-- <version>1.3.0</version>-->
70+
<!-- </dependency>-->
71+
<!-- <dependency>-->
72+
<!-- <groupId>com.github.APIJSON</groupId>-->
73+
<!-- <artifactId>apijson-router</artifactId>-->
74+
<!-- <version>1.2.0</version>-->
75+
<!-- </dependency>-->
8376
<!-- 可使用 libs 目录的 apijson-orm.jar, apijson-framework.jar, apijson-column.jar 来替代,两种方式二选一 >>>>>>>>>> -->
8477

8578
<!-- 需要用的数据库 JDBC 驱动 -->

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ public static ApplicationContext getApplicationContext() {
8282
public static void main(String[] args) throws Exception {
8383
APPLICATION_CONTEXT = SpringApplication.run(DemoApplication.class, args);
8484

85+
try {
86+
DemoSQLExecutor.REDIS_TEMPLATE.discard();
87+
} catch (Throwable e) {
88+
e.printStackTrace();
89+
}
90+
8591
// FIXME 不要开放给项目组后端之外的任何人使用 UnitAuto(强制登录鉴权)!!!如果不需要单元测试则移除相关代码或 unitauto.Log.DEBUG = false;
8692
// 上线生产环境前改为 false,可不输出 APIJSONORM 的日志 以及 SQLException 的原始(敏感)信息
8793
unitauto.Log.DEBUG = Log.DEBUG = true;

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

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import apijson.RequestMethod;
1919
import com.alibaba.druid.pool.DruidDataSource;
2020
import com.alibaba.fastjson.JSONObject;
21-
import com.alibaba.fastjson.support.spring.FastJsonRedisSerializer;
2221
import com.vesoft.nebula.jdbc.impl.NebulaDriver;
2322
import com.zaxxer.hikari.HikariDataSource;
2423

@@ -100,28 +99,9 @@ public synchronized void removeCache(String sql, SQLConfig config) {
10099
}
101100
}
102101

103-
@Override
104-
public JSONObject execute(SQLConfig config, boolean unknownType) throws Exception {
105-
JSONObject result = super.execute(config, unknownType);
106-
RequestMethod method = config.getMethod();
107-
if (method == RequestMethod.POST) { // 没必要,直接查就行了
108-
// Object id = result.get(config.getIdKey());
109-
// Object idIn = result.get(config.getIdKey() + "[]");
110-
// SQLConfig cacheConfig = APIJSONRouterApplication.DEFAULT_APIJSON_CREATOR.createSQLConfig();
111-
// cacheConfig.setMethod(RequestMethod.GET);
112-
//
113-
} else if (method == RequestMethod.PUT || method == RequestMethod.DELETE) { // RequestMethod.isQueryMethod(method) == false) {
114-
config.setMethod(RequestMethod.GET);
115-
boolean isPrepared = config.isPrepared();
116-
removeCache(config.getSQL(false), config);
117-
config.setPrepared(isPrepared);
118-
config.setMethod(method);
119-
}
120-
return result;
121-
}
122-
123102
// Redis 缓存 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
124103

104+
125105
// 适配连接池,如果这里能拿到连接池的有效 Connection,则 SQLConfig 不需要配置 dbVersion, dbUri, dbAccount, dbPassword
126106
@Override
127107
public Connection getConnection(SQLConfig config) throws Exception {

0 commit comments

Comments
 (0)