diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/StdinReader.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/StdinReader.java new file mode 100644 index 000000000..3505849c5 --- /dev/null +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/StdinReader.java @@ -0,0 +1,30 @@ +//package ai.chat2db.server.start.config; +// +//import jakarta.annotation.PostConstruct; +//import org.springframework.boot.context.event.ApplicationReadyEvent; +//import org.springframework.context.ApplicationListener; +//import org.springframework.stereotype.Component; +// +//import java.util.Scanner; +// +//@Component +//public class StdinReader implements ApplicationListener { +// +// +// @Override +// public void onApplicationEvent(ApplicationReadyEvent event) { +// // 启动读取 stdin 的线程 +// new Thread(() -> readStdin()).start(); +// } +// +// private void readStdin() { +// Scanner scanner = new Scanner(System.in); +// while (scanner.hasNextLine()) { +// String line = scanner.nextLine(); +// // 处理接收到的数据 +// System.out.println("接收到数据: " + line); +// // 在这里调用其他服务或逻辑 +// } +// } +// +//} diff --git a/chat2db-server/chat2db-server-start/src/main/resources/application-dev.yml b/chat2db-server/chat2db-server-start/src/main/resources/application-dev.yml index 029e91f58..62dbd0eb0 100644 --- a/chat2db-server/chat2db-server-start/src/main/resources/application-dev.yml +++ b/chat2db-server/chat2db-server-start/src/main/resources/application-dev.yml @@ -1,7 +1,7 @@ spring: datasource: # 配置自带数据库的相对路径 - url: jdbc:h2:~/.chat2db/db/chat2db_dev;MODE=MYSQL + url: jdbc:h2:~/.chat2db/db/chat2db_dev;MODE=MYSQL;FILE_LOCK=NO driver-class-name: org.h2.Driver h2: console: diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/RdbDdlController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/RdbDdlController.java index 3871a71ce..feb7f3f7b 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/RdbDdlController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/RdbDdlController.java @@ -73,19 +73,19 @@ public WebPageResult list(@Valid TableBriefQueryRequest request) { PageResult tableDTOPageResult = tableService.pageQuery(queryParam, tableSelector); List tableVOS = rdbWebConverter.tableDto2vo(tableDTOPageResult.getData()); - ConnectInfo connectInfo = Chat2DBContext.getConnectInfo(); - singleThreadExecutor.submit(() -> { - try { - Chat2DBContext.putContext(connectInfo); - syncTableVector(request); -// syncTableEs(request); - } catch (Exception e) { - log.error("sync table vector error", e); - } finally { - Chat2DBContext.removeContext(); - } - log.info("sync table vector finish"); - }); +// ConnectInfo connectInfo = Chat2DBContext.getConnectInfo(); +// singleThreadExecutor.submit(() -> { +// try { +// Chat2DBContext.putContext(connectInfo); +// syncTableVector(request); +//// syncTableEs(request); +// } catch (Exception e) { +// log.error("sync table vector error", e); +// } finally { +// Chat2DBContext.removeContext(); +// } +// log.info("sync table vector finish"); +// }); return WebPageResult.of(tableVOS, tableDTOPageResult.getTotal(), request.getPageNo(), request.getPageSize()); } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/TableController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/TableController.java index 3e90d62d8..131a6bf6c 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/TableController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/TableController.java @@ -64,19 +64,19 @@ public WebPageResult list(@Valid TableBriefQueryRequest request) { tableSelector.setIndexList(false); PageResult
tableDTOPageResult = tableService.pageQuery(queryParam, tableSelector); List tableVOS = rdbWebConverter.tableDto2vo(tableDTOPageResult.getData()); - ConnectInfo connectInfo = Chat2DBContext.getConnectInfo(); - singleThreadExecutor.submit(() -> { - try { - Chat2DBContext.putContext(connectInfo); - syncTableVector(request); -// syncTableEs(request); - } catch (Exception e) { - log.error("sync table vector error", e); - } finally { - Chat2DBContext.removeContext(); - } - log.info("sync table vector finish"); - }); +// ConnectInfo connectInfo = Chat2DBContext.getConnectInfo(); +// singleThreadExecutor.submit(() -> { +// try { +// Chat2DBContext.putContext(connectInfo); +// syncTableVector(request); +//// syncTableEs(request); +// } catch (Exception e) { +// log.error("sync table vector error", e); +// } finally { +// Chat2DBContext.removeContext(); +// } +// log.info("sync table vector finish"); +// }); return WebPageResult.of(tableVOS, tableDTOPageResult.getTotal(), request.getPageNo(), request.getPageSize()); } diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/Chat2DBContext.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/Chat2DBContext.java index abec6ee87..69021a621 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/Chat2DBContext.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/Chat2DBContext.java @@ -81,9 +81,13 @@ public static Connection getConnection() { if (connection == null) { synchronized (connectInfo) { connection = connectInfo.getConnection(); - if (connection != null) { - return connection; - } else { + try { + if (connection != null && !connection.isClosed()) { + return connection; + } else { + connection = getDBManage().getConnection(connectInfo); + } + } catch (SQLException e) { connection = getDBManage().getConnection(connectInfo); } }