From 59f39abc1858dfc238f0dc3d59bc02fe7df68350 Mon Sep 17 00:00:00 2001 From: tmlx1990 Date: Tue, 21 Nov 2023 18:14:55 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8B=BC=E5=86=99?= =?UTF-8?q?=E9=94=99=E8=AF=AF=20=E6=95=B0=E6=8D=AE=E5=BA=93=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E4=BD=BF=E7=94=A8=E6=9E=9A=E4=B8=BE=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/ai/chat2db/spi/sql/SQLExecutor.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java index f3706538f..9ed899c5e 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java @@ -1,6 +1,7 @@ package ai.chat2db.spi.sql; import ai.chat2db.server.tools.base.constant.EasyToolsConstant; +import ai.chat2db.server.tools.base.enums.DataSourceTypeEnum; import ai.chat2db.server.tools.common.util.I18nUtils; import ai.chat2db.spi.ValueHandler; import ai.chat2db.spi.jdbc.DefaultValueHandler; @@ -203,11 +204,12 @@ public ExecuteResult execute(final String sql, Connection connection, boolean li // 获取header信息 List
headerList = Lists.newArrayListWithExpectedSize(col); executeResult.setHeaderList(headerList); - int chat2dbAutoRowIdIndex = -1;// chat2db自动生成的行分页ID + // chat2db自动生成的行分页ID + int chat2dbAutoRowIdIndex = -1; for (int i = 1; i <= col; i++) { String name = ResultSetUtils.getColumnName(resultSetMetaData, i); - if ("CAHT2DB_AUTO_ROW_ID".equals(name)) { + if ("CHAT2DB_AUTO_ROW_ID".equals(name)) { chat2dbAutoRowIdIndex = i; continue; } @@ -293,9 +295,9 @@ public List databases(Connection connection) { } /** - * Retrieves the schema names available in this database. The results are ordered by TABLE_CATALOG and TABLE_SCHEM. + * Retrieves the schema names available in this database. The results are ordered by TABLE_CATALOG and TABLE_SCHEMA. * The schema columns are: - * TABLE_SCHEM String => schema name + * TABLE_SCHEMA String => schema name * TABLE_CATALOG String => catalog name (may be null) * Params: * catalog – a catalog name; must match the catalog name as it is stored in the database;"" retrieves those without @@ -344,7 +346,7 @@ public List tables(Connection connection, String databaseName, String sch ResultSet resultSet = metadata.getTables(databaseName, schemaName, tableName, types); // 如果connection为mysql - if ("MySQL".equalsIgnoreCase(metadata.getDatabaseProductName())) { + if (DataSourceTypeEnum.MYSQL.getCode().equalsIgnoreCase(metadata.getDatabaseProductName())) { // 获取mysql表的comment List
tables = ResultSetUtils.toObjectList(resultSet, Table.class); if (CollectionUtils.isNotEmpty(tables)) { From 37306c5bf01b49d5a269ea6f0a575c6de29c9f2f Mon Sep 17 00:00:00 2001 From: tmlx1990 Date: Tue, 21 Nov 2023 18:22:02 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9SCHEMA=E6=8B=BC=E5=86=99?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/ai/chat2db/spi/model/Function.java | 4 ++-- .../src/main/java/ai/chat2db/spi/model/Procedure.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Function.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Function.java index b111ed8f1..9d86ba907 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Function.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Function.java @@ -17,7 +17,7 @@ @AllArgsConstructor public class Function { //FUNCTION_CAT String => function catalog (may be null) - //FUNCTION_SCHEM String => function schema (may be null) + //FUNCTION_SCHEMA String => function schema (may be null) //FUNCTION_NAME String => function name. This is the name used to invoke the function //REMARKS String => explanatory comment on the function //FUNCTION_TYPE short => kind of function: @@ -30,7 +30,7 @@ public class Function { @JsonAlias({"FUNCTION_CAT"}) private String databaseName; - @JsonAlias({"FUNCTION_SCHEM"}) + @JsonAlias({"FUNCTION_SCHEMA"}) private String schemaName; @JsonAlias({"FUNCTION_NAME"}) diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Procedure.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Procedure.java index 3c48489d7..14958dd91 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Procedure.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Procedure.java @@ -17,7 +17,7 @@ @AllArgsConstructor public class Procedure { //PROCEDURE_CAT String => procedure catalog (may be null) - //PROCEDURE_SCHEM String => procedure schema (may be null) + //PROCEDURE_SCHEMA String => procedure schema (may be null) //PROCEDURE_NAME String => procedure name //REMARKS String => explanatory comment on the procedure //PROCEDURE_TYPE short => kind of procedure: @@ -30,7 +30,7 @@ public class Procedure { @JsonAlias({"PROCEDURE_CAT"}) private String databaseName; - @JsonAlias({"PROCEDURE_SCHEM"}) + @JsonAlias({"PROCEDURE_SCHEMA"}) private String schemaName; From c674d25d0e7089dcd50affe92ae3759b443c180c Mon Sep 17 00:00:00 2001 From: Xin Yan Date: Wed, 22 Nov 2023 00:06:57 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E4=BD=BF=E7=94=A8=E6=9E=9A=E4=B8=BE=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/ai/chat2db/spi/sql/SQLExecutor.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java index f3706538f..fce7db266 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java @@ -1,6 +1,7 @@ package ai.chat2db.spi.sql; import ai.chat2db.server.tools.base.constant.EasyToolsConstant; +import ai.chat2db.server.tools.base.enums.DataSourceTypeEnum; import ai.chat2db.server.tools.common.util.I18nUtils; import ai.chat2db.spi.ValueHandler; import ai.chat2db.spi.jdbc.DefaultValueHandler; @@ -203,7 +204,8 @@ public ExecuteResult execute(final String sql, Connection connection, boolean li // 获取header信息 List
headerList = Lists.newArrayListWithExpectedSize(col); executeResult.setHeaderList(headerList); - int chat2dbAutoRowIdIndex = -1;// chat2db自动生成的行分页ID + // chat2db自动生成的行分页ID + int chat2dbAutoRowIdIndex = -1; for (int i = 1; i <= col; i++) { String name = ResultSetUtils.getColumnName(resultSetMetaData, i); @@ -344,7 +346,7 @@ public List
tables(Connection connection, String databaseName, String sch ResultSet resultSet = metadata.getTables(databaseName, schemaName, tableName, types); // 如果connection为mysql - if ("MySQL".equalsIgnoreCase(metadata.getDatabaseProductName())) { + if (DataSourceTypeEnum.MYSQL.getCode().equalsIgnoreCase(metadata.getDatabaseProductName())) { // 获取mysql表的comment List
tables = ResultSetUtils.toObjectList(resultSet, Table.class); if (CollectionUtils.isNotEmpty(tables)) { From 218662a2ccbb89a14c66779c743a3a2200eec40b Mon Sep 17 00:00:00 2001 From: tmlx1990 Date: Wed, 22 Nov 2023 00:11:23 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E6=81=A2=E5=A4=8D=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/ai/chat2db/spi/model/Function.java | 4 ++-- .../src/main/java/ai/chat2db/spi/model/Procedure.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Function.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Function.java index 9d86ba907..b111ed8f1 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Function.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Function.java @@ -17,7 +17,7 @@ @AllArgsConstructor public class Function { //FUNCTION_CAT String => function catalog (may be null) - //FUNCTION_SCHEMA String => function schema (may be null) + //FUNCTION_SCHEM String => function schema (may be null) //FUNCTION_NAME String => function name. This is the name used to invoke the function //REMARKS String => explanatory comment on the function //FUNCTION_TYPE short => kind of function: @@ -30,7 +30,7 @@ public class Function { @JsonAlias({"FUNCTION_CAT"}) private String databaseName; - @JsonAlias({"FUNCTION_SCHEMA"}) + @JsonAlias({"FUNCTION_SCHEM"}) private String schemaName; @JsonAlias({"FUNCTION_NAME"}) diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Procedure.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Procedure.java index 14958dd91..3c48489d7 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Procedure.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Procedure.java @@ -17,7 +17,7 @@ @AllArgsConstructor public class Procedure { //PROCEDURE_CAT String => procedure catalog (may be null) - //PROCEDURE_SCHEMA String => procedure schema (may be null) + //PROCEDURE_SCHEM String => procedure schema (may be null) //PROCEDURE_NAME String => procedure name //REMARKS String => explanatory comment on the procedure //PROCEDURE_TYPE short => kind of procedure: @@ -30,7 +30,7 @@ public class Procedure { @JsonAlias({"PROCEDURE_CAT"}) private String databaseName; - @JsonAlias({"PROCEDURE_SCHEMA"}) + @JsonAlias({"PROCEDURE_SCHEM"}) private String schemaName; From 4a5185235e01e782586db3014b7b5feadf5c0641 Mon Sep 17 00:00:00 2001 From: tmlx1990 Date: Wed, 22 Nov 2023 00:13:26 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E6=81=A2=E5=A4=8D=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/ai/chat2db/spi/sql/SQLExecutor.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java index 9ed899c5e..f3706538f 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java @@ -1,7 +1,6 @@ package ai.chat2db.spi.sql; import ai.chat2db.server.tools.base.constant.EasyToolsConstant; -import ai.chat2db.server.tools.base.enums.DataSourceTypeEnum; import ai.chat2db.server.tools.common.util.I18nUtils; import ai.chat2db.spi.ValueHandler; import ai.chat2db.spi.jdbc.DefaultValueHandler; @@ -204,12 +203,11 @@ public ExecuteResult execute(final String sql, Connection connection, boolean li // 获取header信息 List
headerList = Lists.newArrayListWithExpectedSize(col); executeResult.setHeaderList(headerList); - // chat2db自动生成的行分页ID - int chat2dbAutoRowIdIndex = -1; + int chat2dbAutoRowIdIndex = -1;// chat2db自动生成的行分页ID for (int i = 1; i <= col; i++) { String name = ResultSetUtils.getColumnName(resultSetMetaData, i); - if ("CHAT2DB_AUTO_ROW_ID".equals(name)) { + if ("CAHT2DB_AUTO_ROW_ID".equals(name)) { chat2dbAutoRowIdIndex = i; continue; } @@ -295,9 +293,9 @@ public List databases(Connection connection) { } /** - * Retrieves the schema names available in this database. The results are ordered by TABLE_CATALOG and TABLE_SCHEMA. + * Retrieves the schema names available in this database. The results are ordered by TABLE_CATALOG and TABLE_SCHEM. * The schema columns are: - * TABLE_SCHEMA String => schema name + * TABLE_SCHEM String => schema name * TABLE_CATALOG String => catalog name (may be null) * Params: * catalog – a catalog name; must match the catalog name as it is stored in the database;"" retrieves those without @@ -346,7 +344,7 @@ public List
tables(Connection connection, String databaseName, String sch ResultSet resultSet = metadata.getTables(databaseName, schemaName, tableName, types); // 如果connection为mysql - if (DataSourceTypeEnum.MYSQL.getCode().equalsIgnoreCase(metadata.getDatabaseProductName())) { + if ("MySQL".equalsIgnoreCase(metadata.getDatabaseProductName())) { // 获取mysql表的comment List
tables = ResultSetUtils.toObjectList(resultSet, Table.class); if (CollectionUtils.isNotEmpty(tables)) { From df0b417eb5c26ef05ee509e41ec05970724ac540 Mon Sep 17 00:00:00 2001 From: tmlx1990 Date: Wed, 22 Nov 2023 00:13:26 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E4=BD=BF=E7=94=A8=E6=9E=9A=E4=B8=BE=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/ai/chat2db/spi/sql/SQLExecutor.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java index 9ed899c5e..fce7db266 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java @@ -209,7 +209,7 @@ public ExecuteResult execute(final String sql, Connection connection, boolean li for (int i = 1; i <= col; i++) { String name = ResultSetUtils.getColumnName(resultSetMetaData, i); - if ("CHAT2DB_AUTO_ROW_ID".equals(name)) { + if ("CAHT2DB_AUTO_ROW_ID".equals(name)) { chat2dbAutoRowIdIndex = i; continue; } @@ -295,9 +295,9 @@ public List databases(Connection connection) { } /** - * Retrieves the schema names available in this database. The results are ordered by TABLE_CATALOG and TABLE_SCHEMA. + * Retrieves the schema names available in this database. The results are ordered by TABLE_CATALOG and TABLE_SCHEM. * The schema columns are: - * TABLE_SCHEMA String => schema name + * TABLE_SCHEM String => schema name * TABLE_CATALOG String => catalog name (may be null) * Params: * catalog – a catalog name; must match the catalog name as it is stored in the database;"" retrieves those without From add658c7b53376e106e5bdf3547813d58d13a30b Mon Sep 17 00:00:00 2001 From: tmlx1990 Date: Wed, 6 Dec 2023 18:13:48 +0800 Subject: [PATCH 7/8] =?UTF-8?q?hutool=E7=9A=84SQL=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96=EF=BC=8C=E4=B8=8D=E8=83=BD=E5=A4=84=E7=90=86=E5=B8=A6?= =?UTF-8?q?=E6=B3=A8=E9=87=8A=E7=9A=84=E5=86=85=E5=AE=B9=E3=80=82=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=BA=E4=BD=BF=E7=94=A8JSQLFormatter?= =?UTF-8?q?=E5=BC=80=E6=BA=90=E9=A1=B9=E7=9B=AE=E6=9D=A5=E5=A4=84=E7=90=86?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat2db-server-web/chat2db-server-web-api/pom.xml | 5 +++++ .../server/web/api/controller/sql/SqlController.java | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/pom.xml b/chat2db-server/chat2db-server-web/chat2db-server-web-api/pom.xml index 590b8421e..9d80aad7a 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/pom.xml +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/pom.xml @@ -89,6 +89,11 @@ java-jwt + + com.manticore-projects.jsqlformatter + jsqlformatter + 1.0.0 + diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/sql/SqlController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/sql/SqlController.java index 17bcfa614..d7b8e0b29 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/sql/SqlController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/sql/SqlController.java @@ -3,7 +3,7 @@ import ai.chat2db.server.tools.base.wrapper.result.DataResult; import ai.chat2db.server.web.api.aspect.ConnectionInfoAspect; import ai.chat2db.server.web.api.controller.sql.request.SqlFormatRequest; -import cn.hutool.db.sql.SqlFormatter; +import com.manticore.jsqlformatter.JSQLFormatter; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -19,18 +19,19 @@ public class SqlController { /** * SQL Format + * * @param sqlFormatRequest * @return */ @GetMapping("/format") public DataResult list(@Valid SqlFormatRequest sqlFormatRequest) { - String sql = sqlFormatRequest.getSql(); try { - sql = SqlFormatter.format(sql); + sql = JSQLFormatter.format(sql); } catch (Exception e) { // ignore } return DataResult.of(sql); } + } From 2c162f2f519253241a6efe72f5dc7c8af8945bf7 Mon Sep 17 00:00:00 2001 From: SwallowGG <1558143046@qq.com> Date: Thu, 7 Dec 2023 23:12:18 +0800 Subject: [PATCH 8/8] Improve startup speed --- .../main/java/ai/chat2db/server/domain/repository/Dbutils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/Dbutils.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/Dbutils.java index 348919b37..9d6d0e460 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/Dbutils.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/Dbutils.java @@ -199,7 +199,7 @@ private static void registryMapperXml(MybatisConfiguration configuration, String Enumeration entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); - if (jarEntry.getName().endsWith(".xml")) { + if (jarEntry.getName().endsWith("Mapper.xml")) { InputStream in = jarFile.getInputStream(jarEntry); XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(in, configuration, jarEntry.getName(), configuration.getSqlFragments()); xmlMapperBuilder.parse();