修改模型查询连接池代码逻辑

dev_xd
haha 2025-07-08 22:45:46 +08:00
parent fdafdcd16e
commit c2dafcc271
2 changed files with 35 additions and 23 deletions

View File

@ -30,8 +30,11 @@ public class BimDataSource {
HikariConfig config = new HikariConfig(); HikariConfig config = new HikariConfig();
config.setDriverClassName(driverName); config.setDriverClassName(driverName);
config.setJdbcUrl(url); config.setJdbcUrl(url);
config.setConnectionTimeout(120*1000L); config.setConnectionTimeout(60000L);
config.setIdleTimeout(60000L);
config.setMaxLifetime(600000L);
config.setMaximumPoolSize(100); config.setMaximumPoolSize(100);
config.setMinimumIdle(5);
config.setConnectionTestQuery("SELECT 1"); config.setConnectionTestQuery("SELECT 1");
DataSource ds= new HikariDataSource(config); DataSource ds= new HikariDataSource(config);
dataSourceMap.put(dbName, ds); dataSourceMap.put(dbName, ds);

View File

@ -13,8 +13,8 @@ import com.yanzhu.manage.domain.bim.ModelTypeVo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.sql.DataSource;
import java.io.File; import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.Statement; import java.sql.Statement;
@ -80,8 +80,8 @@ public class BimModelController {
return AjaxResult.error("file not found!"); return AjaxResult.error("file not found!");
} }
try { try {
DataSource ds = bimDataSource.getDataSource(name); Connection conn = bimDataSource.getDataSource(name).getConnection();
PreparedStatement pss= ds.getConnection().prepareStatement(sql); PreparedStatement pss= conn.prepareStatement(sql);
if(StringUtils.isNotEmpty(pid)) { if(StringUtils.isNotEmpty(pid)) {
pss.setString(1,pid); pss.setString(1,pid);
} }
@ -99,6 +99,7 @@ public class BimModelController {
list.add(modelTreeVo); list.add(modelTreeVo);
} }
redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS); redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS);
conn.close();
return AjaxResult.success(list); return AjaxResult.success(list);
} catch (Exception e) { } catch (Exception e) {
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());
@ -130,8 +131,8 @@ public class BimModelController {
return AjaxResult.error("file not found!"); return AjaxResult.error("file not found!");
} }
try { try {
DataSource ds = bimDataSource.getDataSource(name); Connection conn = bimDataSource.getDataSource(name).getConnection();
PreparedStatement pss= ds.getConnection().prepareStatement(sql); PreparedStatement pss= conn.prepareStatement(sql);
for (int i = 1; i <= glids.size(); i++) { for (int i = 1; i <= glids.size(); i++) {
pss.setLong(i, glids.get(i - 1)); pss.setLong(i, glids.get(i - 1));
} }
@ -149,6 +150,7 @@ public class BimModelController {
list.add(modelTreeVo); list.add(modelTreeVo);
} }
redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS); redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS);
conn.close();
return AjaxResult.success(list); return AjaxResult.success(list);
} catch (Exception e) { } catch (Exception e) {
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());
@ -167,8 +169,8 @@ public class BimModelController {
return AjaxResult.error("file not found!"); return AjaxResult.error("file not found!");
} }
try { try {
DataSource ds = bimDataSource.getDataSource(name); Connection conn = bimDataSource.getDataSource(name).getConnection();
PreparedStatement pss= ds.getConnection().prepareStatement(sql); PreparedStatement pss= conn.prepareStatement(sql);
pss.setString(1,externalId); pss.setString(1,externalId);
ResultSet rs = pss.executeQuery(); ResultSet rs = pss.executeQuery();
List<ModelTreeVo> list = new ArrayList<>(); List<ModelTreeVo> list = new ArrayList<>();
@ -184,6 +186,7 @@ public class BimModelController {
list.add(modelTreeVo); list.add(modelTreeVo);
} }
redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS); redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS);
conn.close();
return AjaxResult.success(list); return AjaxResult.success(list);
} catch (Exception e) { } catch (Exception e) {
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());
@ -222,8 +225,8 @@ public class BimModelController {
return AjaxResult.error("file not found!"); return AjaxResult.error("file not found!");
} }
try { try {
DataSource ds = bimDataSource.getDataSource(name); Connection conn = bimDataSource.getDataSource(name).getConnection();
PreparedStatement pss= ds.getConnection().prepareStatement(sql); PreparedStatement pss= conn.prepareStatement(sql);
if(StringUtils.isNotEmpty(pid)) { if(StringUtils.isNotEmpty(pid)) {
pss.setString(1,pid); pss.setString(1,pid);
} }
@ -241,6 +244,7 @@ public class BimModelController {
list.add(modelTreeVo); list.add(modelTreeVo);
} }
redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS); redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS);
conn.close();
return AjaxResult.success(list); return AjaxResult.success(list);
} catch (Exception e) { } catch (Exception e) {
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());
@ -250,7 +254,6 @@ public class BimModelController {
/** /**
* model_tree * model_tree
* @param name * @param name
* @param pid
* @return * @return
*/ */
@PostMapping("/modelTreeAllLeafChildByGlids/{name}") @PostMapping("/modelTreeAllLeafChildByGlids/{name}")
@ -288,8 +291,8 @@ public class BimModelController {
return AjaxResult.error("file not found!"); return AjaxResult.error("file not found!");
} }
try { try {
DataSource ds = bimDataSource.getDataSource(name); Connection conn = bimDataSource.getDataSource(name).getConnection();
PreparedStatement pss= ds.getConnection().prepareStatement(sql); PreparedStatement pss= conn.prepareStatement(sql);
for (int i = 1; i <= glids.size(); i++) { for (int i = 1; i <= glids.size(); i++) {
pss.setString(i, glids.get(i - 1)); pss.setString(i, glids.get(i - 1));
} }
@ -307,6 +310,7 @@ public class BimModelController {
list.add(modelTreeVo); list.add(modelTreeVo);
} }
redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS); redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS);
conn.close();
return AjaxResult.success(list); return AjaxResult.success(list);
} catch (Exception e) { } catch (Exception e) {
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());
@ -340,8 +344,8 @@ public class BimModelController {
return AjaxResult.error("file not found!"); return AjaxResult.error("file not found!");
} }
try { try {
DataSource ds = bimDataSource.getDataSource(name); Connection conn = bimDataSource.getDataSource(name).getConnection();
PreparedStatement pss= ds.getConnection().prepareStatement(sql); PreparedStatement pss= conn.prepareStatement(sql);
if(StringUtils.isNotEmpty(pid)) { if(StringUtils.isNotEmpty(pid)) {
pss.setString(1,pid); pss.setString(1,pid);
} }
@ -359,6 +363,7 @@ public class BimModelController {
list.add(modelTreeVo); list.add(modelTreeVo);
} }
redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS); redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS);
conn.close();
return AjaxResult.success(list); return AjaxResult.success(list);
} catch (Exception e) { } catch (Exception e) {
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());
@ -398,8 +403,8 @@ public class BimModelController {
return AjaxResult.error("file not found!"); return AjaxResult.error("file not found!");
} }
try { try {
DataSource ds = bimDataSource.getDataSource(name); Connection conn = bimDataSource.getDataSource(name).getConnection();
PreparedStatement pss= ds.getConnection().prepareStatement(sql); PreparedStatement pss= conn.prepareStatement(sql);
if(StringUtils.isNotEmpty(pid)) { if(StringUtils.isNotEmpty(pid)) {
pss.setString(1,pid); pss.setString(1,pid);
} }
@ -417,6 +422,7 @@ public class BimModelController {
list.add(vo); list.add(vo);
} }
redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS); redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS);
conn.close();
return AjaxResult.success(list); return AjaxResult.success(list);
} catch (Exception e) { } catch (Exception e) {
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());
@ -450,8 +456,8 @@ public class BimModelController {
return AjaxResult.error("file not found!"); return AjaxResult.error("file not found!");
} }
try { try {
DataSource ds = bimDataSource.getDataSource(name); Connection conn = bimDataSource.getDataSource(name).getConnection();
PreparedStatement pss= ds.getConnection().prepareStatement(sql); PreparedStatement pss= conn.prepareStatement(sql);
if(StringUtils.isNotEmpty(pid)) { if(StringUtils.isNotEmpty(pid)) {
pss.setString(1,pid); pss.setString(1,pid);
} }
@ -469,6 +475,7 @@ public class BimModelController {
list.add(vo); list.add(vo);
} }
redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS); redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS);
conn.close();
return AjaxResult.success(list); return AjaxResult.success(list);
} catch (Exception e) { } catch (Exception e) {
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());
@ -492,8 +499,8 @@ public class BimModelController {
return AjaxResult.error("file not found!"); return AjaxResult.error("file not found!");
} }
try { try {
DataSource ds = bimDataSource.getDataSource(name); Connection conn = bimDataSource.getDataSource(name).getConnection();
PreparedStatement pss = ds.getConnection().prepareStatement(sql); PreparedStatement pss= conn.prepareStatement(sql);
pss.setLong(1, externalId); pss.setLong(1, externalId);
ResultSet rs = pss.executeQuery(); ResultSet rs = pss.executeQuery();
@ -513,6 +520,7 @@ public class BimModelController {
list.add(vo); list.add(vo);
} }
redisService.setCacheObject(key, list, 60 * 60 * 24L, TimeUnit.SECONDS); redisService.setCacheObject(key, list, 60 * 60 * 24L, TimeUnit.SECONDS);
conn.close();
return AjaxResult.success(list); return AjaxResult.success(list);
} catch (Exception e) { } catch (Exception e) {
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());
@ -544,8 +552,8 @@ public class BimModelController {
return AjaxResult.error("file not found!"); return AjaxResult.error("file not found!");
} }
try { try {
DataSource ds = bimDataSource.getDataSource(name); Connection conn = bimDataSource.getDataSource(name).getConnection();
PreparedStatement pss= ds.getConnection().prepareStatement(sql); PreparedStatement pss= conn.prepareStatement(sql);
for (int i = 1; i <= glids.size(); i++) { for (int i = 1; i <= glids.size(); i++) {
pss.setLong(i, glids.get(i - 1)); pss.setLong(i, glids.get(i - 1));
} }
@ -566,6 +574,7 @@ public class BimModelController {
list.add(vo); list.add(vo);
} }
redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS); redisService.setCacheObject(key,list,60*60*24L, TimeUnit.SECONDS);
conn.close();
return AjaxResult.success(list); return AjaxResult.success(list);
} catch (Exception e) { } catch (Exception e) {
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());