funky-eyes commented on issue #7303: URL: https://github.com/apache/incubator-seata/issues/7303#issuecomment-2819822462
> 我们使用的是APIJSON进行的开发,本地扩展了AbstractSQLExecutor,代码段如下 `// 适配连接池,如果这里能拿到连接池的有效 Connection,则 SQLConfig 不需要配置 dbVersion, dbUri, dbAccount, dbPassword [@OverRide](https://github.com/OverRide) public Connection getConnection(SQLConfig config) throws Exception { > > ``` > if (StringUtils.isNotBlank(config.getDBUri())) { > ``` > > // Connection c = CACHED_CONNECTION.getIfPresent(config.getDBUri()); Connection c = connectionMap.get(config.getDBUri()); if (c == null || c.isClosed()) { DataSource dataSource; if (DATA_SOURCE_CACHE.containsKey(config.getDBUri())) { dataSource = DATA_SOURCE_CACHE.get(config.getDBUri()); } else { dataSource = createdDataSource(config.isMySQL() ? "com.mysql.cj.jdbc.Driver" : "dm.jdbc.driver.DmDriver", config.getDBUri(), config.getDBAccount(), config.getDBPassword(), "apijson"); DATA_SOURCE_CACHE.put(config.getDBUri(), dataSource); } if (GET == config.getMethod() || HEAD == config.getMethod()) { connection = (Connection) ((DruidDataSource) dataSource).getPooledConnection(); } else { connection = new DataSourceProxy(dataSource).getConnection(); } connectionMap.put(config.getDBUri(), connection); // //CACHED_CONNECTION.put(config.getDBUri(), connection); } return connection; } Connection c = connectionMap.get(config.getDatabase()); if (c == null || c.isClosed()) { try { DynamicRouti ngDataSource ds = (DynamicRoutingDataSource) LowCodeBusinessApplication.getApplicationContext().getBean(DataSource.class); connectionMap.put(config.getDatasource() + "-" + config.getDatabase(), ds.getConnection()); } catch (Exception e) { Log.e(TAG, "getConnection try { " + "DataSource ds = DemoApplication.getApplicationContext().getBean(DataSource.class); .." + "} catch (Exception e) = " + e.getMessage()); } } > > ``` > // 必须最后执行 super 方法,因为里面还有事务相关处理。 > // 如果这里是 return c,则会导致 增删改 多个对象时只有第一个会 commit,即只有第一个对象成功插入数据库表 > return super.getConnection(config); > }` > ``` 那就说明你代码有bug呀,把datasourceproxy缓存起来,不要每次去new -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org For additional commands, e-mail: notifications-h...@seata.apache.org