25
25
import apijson .Log ;
26
26
import apijson .boot .DemoApplication ;
27
27
import apijson .framework .APIJSONSQLExecutor ;
28
- import apijson .orm .SQLConfig ;
28
+ import apijson .orm .SQLConfig ;
29
29
30
30
31
- /**SQL 执行
31
+ /**SQL 执行
32
32
* @author Lemon
33
33
*/
34
34
public class DemoSQLExecutor extends APIJSONSQLExecutor {
@@ -48,15 +48,16 @@ public class DemoSQLExecutor extends APIJSONSQLExecutor {
48
48
// super.removeCache(sql, type);
49
49
// }
50
50
51
- // 适配连接池,如果这里能拿到连接池的有效 Connection,则 SQLConfig 不需要配置 dbVersion, dbUri, dbAccount, dbPassword
52
- @ Override
51
+ // 适配连接池,如果这里能拿到连接池的有效 Connection,则 SQLConfig 不需要配置 dbVersion, dbUri, dbAccount, dbPassword
52
+ @ Override
53
53
public Connection getConnection (SQLConfig config ) throws Exception {
54
54
String datasource = config .getDatasource ();
55
55
Log .d (TAG , "getConnection config.getDatasource() = " + datasource );
56
-
57
- Connection c = connectionMap .get (datasource );
58
- if (datasource != null && (c == null || c .isClosed ())) {
59
- try {
56
+
57
+ String key = datasource + "-" + config .getDatabase ();
58
+ Connection c = connectionMap .get (key );
59
+ if (datasource != null && (c == null || c .isClosed ())) {
60
+ try {
60
61
DataSource ds ;
61
62
switch (datasource ) {
62
63
case "HIKARICP" :
@@ -80,18 +81,18 @@ public Connection getConnection(SQLConfig config) throws Exception {
80
81
}
81
82
break ;
82
83
}
83
-
84
- connectionMap .put (datasource , ds == null ? null : ds .getConnection ());
85
- } catch (Exception e ) {
86
- Log .e (TAG , "getConnection try { "
87
- + "DataSource ds = DemoApplication.getApplicationContext().getBean(DataSource.class); .."
88
- + "} catch (Exception e) = " + e .getMessage ());
89
- }
90
- }
91
-
92
- // 必须最后执行 super 方法,因为里面还有事务相关处理。
93
- // 如果这里是 return c,则会导致 增删改 多个对象时只有第一个会 commit,即只有第一个对象成功插入数据库表
94
- return super .getConnection (config );
84
+
85
+ connectionMap .put (key , ds == null ? null : ds .getConnection ());
86
+ } catch (Exception e ) {
87
+ Log .e (TAG , "getConnection try { "
88
+ + "DataSource ds = DemoApplication.getApplicationContext().getBean(DataSource.class); .."
89
+ + "} catch (Exception e) = " + e .getMessage ());
90
+ }
91
+ }
92
+
93
+ // 必须最后执行 super 方法,因为里面还有事务相关处理。
94
+ // 如果这里是 return c,则会导致 增删改 多个对象时只有第一个会 commit,即只有第一个对象成功插入数据库表
95
+ return super .getConnection (config );
95
96
}
96
97
97
98
@@ -100,6 +101,6 @@ public Connection getConnection(SQLConfig config) throws Exception {
100
101
// protected String getKey(SQLConfig config, ResultSet rs, ResultSetMetaData rsmd, int tablePosition, JSONObject table,
101
102
// int columnIndex, Map<String, JSONObject> childMap) throws Exception {
102
103
// return ColumnUtil.compatOutputKey(super.getKey(config, rs, rsmd, tablePosition, table, columnIndex, childMap), config.getTable(), config.getMethod());
103
- // }
104
-
104
+ // }
105
+
105
106
}
0 commit comments