20260822:数据库桥接资源泄露bug修复
This commit is contained in:
parent
725df3aa29
commit
1e15ae7400
@ -92,6 +92,7 @@ public class DataSourceService {
|
||||
Bridge bridge = bridgeService.queryByIdWithCache(id);
|
||||
if (bridge == null || bridge.getType() != 5) {
|
||||
log.error("数据源不存在或者当前配置类型不是数据库存储,id={}", id);
|
||||
return null;
|
||||
}
|
||||
return JSON.parseObject(bridge.getConfigJson(), MultipleDataSource.class);
|
||||
}
|
||||
|
||||
@ -21,27 +21,33 @@ public class DatabaseBridge extends NodeComponent {
|
||||
@Override
|
||||
public void process() throws Exception {
|
||||
MsgContext cxt = this.getContextBean(MsgContext.class);
|
||||
Long id = cxt.getData("databaseBridgeID");
|
||||
MultipleDataSource multipleDataSource = dataSourceService.getDataSource(id);
|
||||
Integer id = cxt.getData("databaseBridgeID");
|
||||
if (id == null) {
|
||||
log.error("databaseBridgeID未设置,跳过数据库桥接");
|
||||
return;
|
||||
}
|
||||
MultipleDataSource multipleDataSource = dataSourceService.getDataSource(Long.valueOf(id));
|
||||
if (multipleDataSource == null) {
|
||||
log.error("multipleDataSource为空,请检查桥接配置");
|
||||
return;
|
||||
}
|
||||
DruidDataSource dataSource = dataSourceService.createDataSource(multipleDataSource);
|
||||
DruidPooledConnection connection = null;
|
||||
Statement statement = null;
|
||||
String sql = cxt.placeholders(multipleDataSource.getSql());
|
||||
log.info("执行sql:{}", sql);
|
||||
try {
|
||||
connection = dataSource.getConnection();
|
||||
statement = connection.createStatement();
|
||||
statement.execute(sql);
|
||||
} catch (SQLException e) {
|
||||
log.error("sql执行失败---------,原因:{ }", e);
|
||||
if ("SELECT 1;".equalsIgnoreCase(sql)) {
|
||||
// 不要浪费资源直接返回
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
connection.close();
|
||||
if (statement != null) {
|
||||
statement.close();
|
||||
try (DruidPooledConnection connection = dataSource.getConnection();
|
||||
Statement statement = connection.createStatement()) {
|
||||
statement.execute(sql);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.error("关闭数据库连接失败,原因:{ }", e);
|
||||
log.error("sql执行失败---------,原因:", e);
|
||||
} finally {
|
||||
dataSource.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user