From 854390d0e6207adc3546d5d11b04b60915ea7bb9 Mon Sep 17 00:00:00 2001 From: Jerry Fan Date: Sun, 2 Jul 2023 20:49:07 +0800 Subject: [PATCH 01/13] fix: modify release CI/CD config --- .github/workflows/release.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cc35413dd..2c6c04a7a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -104,7 +104,7 @@ jobs: uses: actions/setup-node@main with: node-version: 16 - cache: 'yarn' + cache: "yarn" cache-dependency-path: chat2db-client/yarn.lock # 安装java @@ -120,7 +120,7 @@ jobs: run: | cd chat2db-client yarn install - yarn run build:web:desktop --appVersion=${{ steps.chat2db_version.outputs.substring }} + yarn run build:web:prod --appVersion=${{ steps.chat2db_version.outputs.substring }} cp -r dist ../chat2db-server/chat2db-server-start/src/main/resources/static/front # 编译服务端java版本 @@ -163,7 +163,6 @@ jobs: args: "-c.extraMetadata.version=${{ steps.chat2db_version.outputs.substring }} --mac --x64" release: true - # amd64 notarization - name: Notarization amd64 App if: ${{ runner.os == 'macOS' && matrix.arch == 'amd64' }} @@ -218,7 +217,7 @@ jobs: endpoint: "oss-accelerate.aliyuncs.com" access-key-id: ${{ secrets.OSS_ACCESS_KEY_ID }} access-key-secret: ${{ secrets.OSS_ACCESS_KEY_SECRET }} - ossutil-version: 'latest' + ossutil-version: "latest" - name: Upload to oss run: | ossutil cp -rf --acl=public-read ./oss_temp_file/ oss://chat2db/release/${{ steps.chat2db_version.outputs.substring }}/ From 2ed9c2f6944556d40a35785057f41df6e2327c85 Mon Sep 17 00:00:00 2001 From: jipengfei-jpf <1558143046@qq.com> Date: Sun, 2 Jul 2023 21:09:26 +0800 Subject: [PATCH 02/13] update README.md --- .../server/domain/support/util/JdbcUtils.java | 31 ++++++++++++------- .../java/ai/chat2db/spi/model/SSHInfo.java | 20 ++++++++++++ .../java/ai/chat2db/spi/util/JdbcUtils.java | 3 +- 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/JdbcUtils.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/JdbcUtils.java index 23b9277a5..2d3e278b9 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/JdbcUtils.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/JdbcUtils.java @@ -1,6 +1,22 @@ package ai.chat2db.server.domain.support.util; -import cn.hutool.core.date.DateUtil; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Connection; +import java.sql.Date; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Timestamp; +import java.sql.Types; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.Locale; +import java.util.Map; + +import com.alibaba.druid.DbType; + import ai.chat2db.server.domain.support.enums.DataTypeEnum; import ai.chat2db.server.domain.support.enums.DbTypeEnum; import ai.chat2db.server.domain.support.enums.DriverTypeEnum; @@ -8,19 +24,11 @@ import ai.chat2db.server.domain.support.model.SSHInfo; import ai.chat2db.server.domain.support.sql.IDriverManager; import ai.chat2db.server.domain.support.sql.SSHManager; -import com.alibaba.druid.DbType; +import cn.hutool.core.date.DateUtil; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; import lombok.extern.slf4j.Slf4j; -import java.sql.*; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.time.format.DateTimeFormatter; -import java.util.Locale; -import java.util.Map; - /** * jdbc工具类 * @@ -242,9 +250,10 @@ public static DataSourceConnect testConnect(String url, String host, String port if (session != null) { try { session.delPortForwardingL(Integer.parseInt(ssh.getLocalPort())); + session.disconnect(); + } catch (JSchException e) { } - session.disconnect(); } } dataSourceConnect.setDescription("成功"); diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/SSHInfo.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/SSHInfo.java index 31352549a..9af1c56b7 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/SSHInfo.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/SSHInfo.java @@ -4,6 +4,8 @@ */ package ai.chat2db.spi.model; +import java.util.Objects; + import lombok.Data; /** @@ -68,4 +70,22 @@ public class SSHInfo { */ private String rPort; + @Override + public boolean equals(Object o) { + if (this == o) {return true;} + if (o == null || getClass() != o.getClass()) {return false;} + SSHInfo sshInfo = (SSHInfo)o; + return use == sshInfo.use && Objects.equals(hostName, sshInfo.hostName) && Objects.equals(port, + sshInfo.port) && Objects.equals(userName, sshInfo.userName) && Objects.equals(localPort, + sshInfo.localPort) && Objects.equals(authenticationType, sshInfo.authenticationType) + && Objects.equals(password, sshInfo.password) && Objects.equals(keyFile, sshInfo.keyFile) + && Objects.equals(passphrase, sshInfo.passphrase) && Objects.equals(rHost, sshInfo.rHost) + && Objects.equals(rPort, sshInfo.rPort); + } + + @Override + public int hashCode() { + return Objects.hash(use, hostName, port, userName, localPort, authenticationType, password, keyFile, passphrase, + rHost, rPort); + } } \ No newline at end of file diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/JdbcUtils.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/JdbcUtils.java index 5716dfb58..e64180af5 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/JdbcUtils.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/JdbcUtils.java @@ -235,9 +235,10 @@ public static DataSourceConnect testConnect(String url, String host, String port if (session != null) { try { session.delPortForwardingL(Integer.parseInt(ssh.getLocalPort())); + session.disconnect(); + } catch (JSchException e) { } - session.disconnect(); } } dataSourceConnect.setDescription("成功"); From b6fb5870865e7132c2cb3cfdeb0d131dfd9c48a8 Mon Sep 17 00:00:00 2001 From: jipengfei-jpf <1558143046@qq.com> Date: Sun, 2 Jul 2023 21:15:41 +0800 Subject: [PATCH 03/13] update README.md --- .../src/main/java/ai/chat2db/spi/sql/Chat2DBContext.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 b44344f6f..6bd1464a9 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 @@ -126,9 +126,13 @@ private static void setConnectInfoThreadLocal(ConnectInfo connectInfo) { if (session != null) { try { session.delPortForwardingL(Integer.parseInt(ssh.getLocalPort())); - session.disconnect(); } catch (JSchException e) { - log.error("session close error", e); + log.error("session delPortForwardingL error", e); + } + try { + session.disconnect(); + } catch (Exception e) { + log.error("session disconnect error", e); } } throw new RuntimeException("getConnect error", e1); From 3ca9b55b8cc8535c484d6bf7c31615d2668716f9 Mon Sep 17 00:00:00 2001 From: jipengfei-jpf <1558143046@qq.com> Date: Sun, 2 Jul 2023 21:24:34 +0800 Subject: [PATCH 04/13] update README.md --- .../ai/chat2db/spi/sql/Chat2DBContext.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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 6bd1464a9..a12a60206 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 @@ -180,15 +180,15 @@ public static void removeContext() { } catch (SQLException e) { log.error("close connection error", e); } - Session session = connectInfo.getSession(); - if (session != null) { - try { - session.delPortForwardingL(Integer.parseInt(connectInfo.getSsh().getLocalPort())); - session.disconnect(); - } catch (JSchException e) { - log.error("close session error", e); - } - } + //Session session = connectInfo.getSession(); + //if (session != null) { + // try { + // session.delPortForwardingL(Integer.parseInt(connectInfo.getSsh().getLocalPort())); + // session.disconnect(); + // } catch (JSchException e) { + // log.error("close session error", e); + // } + //} CONNECT_INFO_THREAD_LOCAL.remove(); } } From d0bfd70ef599ae81f115beae162bce204da06ff4 Mon Sep 17 00:00:00 2001 From: JiaJu Zhuang <5152853@qq.com> Date: Sun, 2 Jul 2023 21:34:08 +0800 Subject: [PATCH 05/13] release docker --- .github/workflows/pushdocker.yml | 13 +++++++------ docker/Dockerfile | 4 ++-- docker/docker-build.sh | 1 - 3 files changed, 9 insertions(+), 9 deletions(-) delete mode 100644 docker/docker-build.sh diff --git a/.github/workflows/pushdocker.yml b/.github/workflows/pushdocker.yml index ed7fe70c9..eeb57ee83 100644 --- a/.github/workflows/pushdocker.yml +++ b/.github/workflows/pushdocker.yml @@ -3,9 +3,10 @@ name: Push To Docker # Workflow's trigger -on: - release: - types: [ published ] +#on: +# release: +# types: [ published ] +on: [ push, pull_request ] # Workflow's jobs jobs: @@ -44,10 +45,10 @@ jobs: # 构建静态文件信息 - name: Npm install & build & copy run: | - cd ali-dbhub-client + cd chat2db-client npm install npm run build:desktop - mv dist ../ali-dbhub-server/ali-dbhub-server-start/src/main/resources/static/front + mv dist ../chat2db-server/chat2db-server-start/src/main/resources/static/front # 安装java - name: Install Java and Maven @@ -59,7 +60,7 @@ jobs: # 编译服务端java版本 - name: Build Java - run: mvn clean package -B '-Dmaven.test.skip=true' -f ali-dbhub-server/pom.xml + run: mvn clean package -B '-Dmaven.test.skip=true' -f chat2db-server/pom.xml - name: Set up QEMU diff --git a/docker/Dockerfile b/docker/Dockerfile index 153b3c2ec..8d4fcdbff 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -3,8 +3,8 @@ FROM openjdk:17 # 定义进入容器时默认位置,接下来后续操作的工作位置 WORKDIR /app # 将当前目录下的jar包复制到docker容器的/app 目录下 -ADD ali-dbhub-server/ali-dbhub-server-start/target/ali-dbhub-server-start.jar ali-dbhub-server-start.jar +ADD chat2db-server/chat2db-server-start/target/chat2db-server-start.jar chat2db-server-start.jar # 让当前容器暴露10824 EXPOSE 10824 # 运行jar包 -ENTRYPOINT ["java","-Dspring.profiles.active=release","-jar","ali-dbhub-server-start.jar"] \ No newline at end of file +ENTRYPOINT ["java","-Dspring.profiles.active=release","-jar","chat2db-server-start.jar"] \ No newline at end of file diff --git a/docker/docker-build.sh b/docker/docker-build.sh deleted file mode 100644 index 38dc3d717..000000000 --- a/docker/docker-build.sh +++ /dev/null @@ -1 +0,0 @@ -docker build --no-cache -f docker/Dockerfile -t chat2db/chat2db:v1.0.111-dev . \ No newline at end of file From 624c9fa737686963fd10fc08a5678f61b3a217ce Mon Sep 17 00:00:00 2001 From: JiaJu Zhuang <5152853@qq.com> Date: Sun, 2 Jul 2023 21:35:01 +0800 Subject: [PATCH 06/13] release docker --- .github/workflows/pushdocker.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pushdocker.yml b/.github/workflows/pushdocker.yml index eeb57ee83..9e51cdfb6 100644 --- a/.github/workflows/pushdocker.yml +++ b/.github/workflows/pushdocker.yml @@ -3,10 +3,9 @@ name: Push To Docker # Workflow's trigger -#on: -# release: -# types: [ published ] -on: [ push, pull_request ] +on: + release: + types: [ published ] # Workflow's jobs jobs: From c14d91568ad83745e8a4d5d2fbb3a2a355ebda1b Mon Sep 17 00:00:00 2001 From: JiaJu Zhuang <5152853@qq.com> Date: Sun, 2 Jul 2023 21:36:35 +0800 Subject: [PATCH 07/13] release docker --- .github/workflows/pushdocker.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pushdocker.yml b/.github/workflows/pushdocker.yml index 9e51cdfb6..f4d371b8e 100644 --- a/.github/workflows/pushdocker.yml +++ b/.github/workflows/pushdocker.yml @@ -3,9 +3,10 @@ name: Push To Docker # Workflow's trigger -on: - release: - types: [ published ] +#on: +# release: +# types: [ published ] +on: [ push, pull_request ] # Workflow's jobs jobs: @@ -26,8 +27,7 @@ jobs: id: chat2db_version uses: bhowell2/github-substring-action@1.0.1 with: - value: ${{ github.ref }} - index_of_str: "refs/tags/v" + value: 2.0.0 # 输出基础信息 From ed5b717acd7d23b0b96e420dfd87a3b0bfbe8b0a Mon Sep 17 00:00:00 2001 From: jipengfei-jpf <1558143046@qq.com> Date: Sun, 2 Jul 2023 21:37:20 +0800 Subject: [PATCH 08/13] Remove useless code --- .../chat2db-server-domain-support/pom.xml | 62 -- .../support/datasource/DataSourceManger.java | 115 ---- .../support/datasource/IDataSource.java | 57 -- .../support/datasource/MyDataSource.java | 34 - .../domain/support/dialect/BaseMapper.java | 77 --- .../support/dialect/BaseMetaSchema.java | 145 ----- .../domain/support/dialect/MetaSchema.java | 183 ------ .../ClickhouseMetaSchemaSupport.java | 20 - .../support/dialect/common/SQLKeyConst.java | 41 -- .../support/dialect/common/SQLParam.java | 26 - .../support/dialect/common/SQLType.java | 32 - .../common/enums/BaseCollationEnum.java | 19 - .../common/enums/BaseColumnTypeEnum.java | 19 - .../common/enums/BaseIndexTypeEnum.java | 19 - .../common/handler/BooleanTypeHandler.java | 50 -- .../dialect/common/model/SpiExample.java | 28 - .../dialect/db2/DB2MetaSchemaSupport.java | 75 --- .../dialect/dm/DMMetaSchemaSupport.java | 43 -- .../support/dialect/h2/H2CollationEnum.java | 38 -- .../support/dialect/h2/H2ColumnTypeEnum.java | 46 -- .../support/dialect/h2/H2IndexTypeEnum.java | 42 -- .../dialect/h2/H2MetaSchemaSupport.java | 109 ---- .../h2/handler/H2IndexTypeHandler.java | 53 -- .../dialect/hive/HiveMetaSchemaSupport.java | 20 - .../kingbase/KingBaseSchemaSupport.java | 20 - .../mariadb/MariaDBMetaSchemaSupport.java | 21 - .../mongodb/MongodbMetaSchemaSupport.java | 20 - .../dialect/mysql/MysqlCollationEnum.java | 38 -- .../dialect/mysql/MysqlMetaSchemaSupport.java | 46 -- .../handler/MysqlCollationTypeHandler.java | 54 -- .../mysql/handler/MysqlColumnKeyHandler.java | 49 -- .../mysql/handler/MysqlExtraTypeHandler.java | 49 -- .../mysql/handler/MysqlIndexTypeHandler.java | 52 -- .../oceanbase/OceanBaseMetaSchemaSupport.java | 20 - .../oracle/OracleMetaSchemaSupport.java | 52 -- .../PostgresqlMetaSchemaSupport.java | 201 ------ .../postgresql/model/PostgresqlBaseModel.java | 20 - .../postgresql/model/PostgresqlColumn.java | 34 - .../model/PostgresqlConstraintCheck.java | 19 - .../model/PostgresqlConstraintExclusive.java | 19 - .../PostgresqlConstraintExclusiveField.java | 19 - .../model/PostgresqlConstraintForeign.java | 22 - .../PostgresqlConstraintForeignReference.java | 20 - .../model/PostgresqlConstraintUnique.java | 22 - .../PostgresqlConstraintUniqueField.java | 21 - .../model/PostgresqlForeignServer.java | 23 - .../model/PostgresqlForeignTable.java | 26 - .../postgresql/model/PostgresqlInherit.java | 24 - .../postgresql/model/PostgresqlPartition.java | 23 - .../model/PostgresqlPartitionColumn.java | 18 - .../postgresql/model/PostgresqlResemble.java | 20 - .../postgresql/model/PostgresqlTable.java | 26 - .../model/PostgresqlTableIndex.java | 36 -- .../model/PostgresqlTableIndexField.java | 20 - .../presto/PrestoMetaSchemaSupport.java | 27 - .../dialect/redis/RedisMetaSchemaSupport.java | 75 --- .../sqlite/SQLiteMetaSchemaSupport.java | 53 -- .../sqlserver/SqlServerMetaSchemaSupport.java | 78 --- .../domain/support/enums/CellTypeEnum.java | 50 -- .../domain/support/enums/CollationEnum.java | 55 -- .../domain/support/enums/ColumnTypeEnum.java | 50 -- .../domain/support/enums/DataTypeEnum.java | 99 --- .../domain/support/enums/DbTypeEnum.java | 239 ------- .../domain/support/enums/DriverTypeEnum.java | 163 ----- .../domain/support/enums/IndexTypeEnum.java | 40 -- .../domain/support/enums/SqlTypeEnum.java | 36 -- .../server/domain/support/model/Cell.java | 49 -- .../domain/support/model/CreateTableSql.java | 25 - .../support/model/DataSourceConnect.java | 34 - .../server/domain/support/model/Database.java | 22 - .../domain/support/model/DriverEntry.java | 31 - .../domain/support/model/ExecuteResult.java | 88 --- .../server/domain/support/model/Function.java | 43 -- .../server/domain/support/model/Header.java | 30 - .../server/domain/support/model/KeyValue.java | 39 -- .../domain/support/model/Procedure.java | 43 -- .../server/domain/support/model/SSHInfo.java | 71 --- .../server/domain/support/model/SSLInfo.java | 12 - .../server/domain/support/model/Schema.java | 25 - .../support/model/ShowDatabaseResult.java | 22 - .../server/domain/support/model/Sql.java | 24 - .../server/domain/support/model/Table.java | 65 -- .../domain/support/model/TableColumn.java | 145 ----- .../domain/support/model/TableIndex.java | 64 -- .../support/model/TableIndexColumn.java | 102 --- .../server/domain/support/model/Trigger.java | 12 - .../domain/support/sql/ConnectInfo.java | 598 ------------------ .../domain/support/sql/DbhubContext.java | 157 ----- .../domain/support/sql/IDriverManager.java | 201 ------ .../domain/support/sql/SQLExecutor.java | 407 ------------ .../server/domain/support/sql/SSHManager.java | 84 --- .../server/domain/support/util/JSchUtils.java | 40 -- .../domain/support/util/JdbcJarUtils.java | 152 ----- .../server/domain/support/util/JdbcUtils.java | 263 -------- .../domain/support/util/ResultSetUtils.java | 101 --- .../server/domain/support/util/SqlUtils.java | 436 ------------- .../druid/sql/parser/DbhubSQLParserUtils.java | 49 -- chat2db-server/chat2db-server-domain/pom.xml | 1 - 98 files changed, 6787 deletions(-) delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/pom.xml delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/datasource/DataSourceManger.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/datasource/IDataSource.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/datasource/MyDataSource.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/BaseMapper.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/BaseMetaSchema.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/MetaSchema.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/clickhouse/ClickhouseMetaSchemaSupport.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/SQLKeyConst.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/SQLParam.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/SQLType.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/enums/BaseCollationEnum.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/enums/BaseColumnTypeEnum.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/enums/BaseIndexTypeEnum.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/handler/BooleanTypeHandler.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/model/SpiExample.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/db2/DB2MetaSchemaSupport.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/dm/DMMetaSchemaSupport.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/h2/H2CollationEnum.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/h2/H2ColumnTypeEnum.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/h2/H2IndexTypeEnum.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/h2/H2MetaSchemaSupport.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/h2/handler/H2IndexTypeHandler.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/hive/HiveMetaSchemaSupport.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/kingbase/KingBaseSchemaSupport.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mariadb/MariaDBMetaSchemaSupport.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mongodb/MongodbMetaSchemaSupport.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/MysqlCollationEnum.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/MysqlMetaSchemaSupport.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/handler/MysqlCollationTypeHandler.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/handler/MysqlColumnKeyHandler.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/handler/MysqlExtraTypeHandler.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/handler/MysqlIndexTypeHandler.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/oceanbase/OceanBaseMetaSchemaSupport.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/oracle/OracleMetaSchemaSupport.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/PostgresqlMetaSchemaSupport.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlBaseModel.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlColumn.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintCheck.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintExclusive.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintExclusiveField.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintForeign.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintForeignReference.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintUnique.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintUniqueField.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlForeignServer.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlForeignTable.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlInherit.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlPartition.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlPartitionColumn.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlResemble.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlTable.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlTableIndex.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlTableIndexField.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/presto/PrestoMetaSchemaSupport.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/redis/RedisMetaSchemaSupport.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/sqlite/SQLiteMetaSchemaSupport.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/sqlserver/SqlServerMetaSchemaSupport.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/CellTypeEnum.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/CollationEnum.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/ColumnTypeEnum.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/DataTypeEnum.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/DbTypeEnum.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/DriverTypeEnum.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/IndexTypeEnum.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/SqlTypeEnum.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Cell.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/CreateTableSql.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/DataSourceConnect.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Database.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/DriverEntry.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/ExecuteResult.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Function.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Header.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/KeyValue.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Procedure.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/SSHInfo.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/SSLInfo.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Schema.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/ShowDatabaseResult.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Sql.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Table.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/TableColumn.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/TableIndex.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/TableIndexColumn.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Trigger.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/sql/ConnectInfo.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/sql/DbhubContext.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/sql/IDriverManager.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/sql/SQLExecutor.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/sql/SSHManager.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/JSchUtils.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/JdbcJarUtils.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/JdbcUtils.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/ResultSetUtils.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/SqlUtils.java delete mode 100644 chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/com/alibaba/druid/sql/parser/DbhubSQLParserUtils.java diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/pom.xml b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/pom.xml deleted file mode 100644 index 6eef10687..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/pom.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - ai.chat2db - chat2db-server-domain - ${revision} - ../pom.xml - - 4.0.0 - chat2db-server-domain-support - - - ai.chat2db - chat2db-server-tools-common - - - com.alibaba - druid - - - - - com.h2database - h2 - - - org.springframework - spring-jdbc - - - com.jcraft - jsch - 0.1.53 - - - com.oracle.ojdbc - orai18n - 19.3.0.0 - test - - - mysql - mysql-connector-java - 8.0.30 - test - - - com.squareup.okhttp3 - okhttp - - - com.zaxxer - HikariCP - - - com.baomidou - mybatis-plus-boot-starter - - - diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/datasource/DataSourceManger.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/datasource/DataSourceManger.java deleted file mode 100644 index 2e5aaf73e..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/datasource/DataSourceManger.java +++ /dev/null @@ -1,115 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.datasource; - -import java.net.URLClassLoader; -import java.sql.Connection; -import java.util.Properties; -import java.util.concurrent.ConcurrentHashMap; - -import javax.sql.DataSource; - -import ai.chat2db.server.domain.support.enums.DriverTypeEnum; -import ai.chat2db.server.domain.support.sql.ConnectInfo; -import ai.chat2db.server.domain.support.sql.IDriverManager; -import com.alibaba.fastjson2.JSON; - -import com.zaxxer.hikari.HikariDataSource; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.ObjectUtils; - -/** - * @author jipengfei - * @version : DataSourceManger.java - */ -@Slf4j -public class DataSourceManger { - - protected static final ConcurrentHashMap DATA_SOURCE_MAP = new ConcurrentHashMap(); - - public static DataSource getDataSource(ConnectInfo connectInfo) { - String key = connectInfo.getDataSourceId().toString(); - MyDataSource dataSource = DATA_SOURCE_MAP.get(key); - if (dataSource != null) { - if (!connectInfo.equals(dataSource.getConnectInfo())) { - try { - dataSource.getHikariDataSource().close(); - DATA_SOURCE_MAP.remove(key); - } catch (Exception e) { - } - } else { - return dataSource.getHikariDataSource(); - } - } - synchronized (key) { - dataSource = DATA_SOURCE_MAP.get(key); - if (dataSource != null) { - return dataSource.getHikariDataSource(); - } else { - try { - dataSource = createDataSource(connectInfo); - DATA_SOURCE_MAP.put(key, dataSource); - return dataSource.getHikariDataSource(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } - } - - private static MyDataSource createDataSource(ConnectInfo connectInfo) throws Exception { - DriverTypeEnum driverTypeEnum = DriverTypeEnum.getDriver(connectInfo.getDbType(), connectInfo.getJdbc()); - ClassLoader classLoader = IDriverManager.getClassLoader(driverTypeEnum); - //IDataSource dataSource = new IDataSource(connectInfo, driverTypeEnum, classLoader); - //dataSource.setName(connectInfo.getAlias()); - //dataSource.setDriverClassLoader(classLoader); - //dataSource.setDriverClassName(driverTypeEnum.getDriverClass()); - //dataSource.setUrl(connectInfo.getUrl()); - //dataSource.setInitialSize(2); - //dataSource.setMinIdle(0); - //dataSource.setMaxActive(5); - //dataSource.setMaxWait(3000L); - //dataSource.setMinEvictableIdleTimeMillis(300000L); - //dataSource.setUsername(connectInfo.getUser()); - //dataSource.setPassword(connectInfo.getPassword()); - //dataSource.setConnectionErrorRetryAttempts(2); - //dataSource.setBreakAfterAcquireFailure(true); - //dataSource.setRemoveAbandoned(true); - //dataSource.setRemoveAbandonedTimeout(1800); - //dataSource.setTestOnBorrow(true); - //dataSource.setValidationQuery("select 1"); - //if (!ObjectUtils.isEmpty(connectInfo.getExtendMap())) { - // Properties properties = new Properties(); - // properties.putAll(connectInfo.getExtendMap()); - // dataSource.setConnectProperties(properties); - //} - //return dataSource; - Thread.currentThread().setContextClassLoader(classLoader); - log.info("createDataSource classLoader hashCode:{}"+ classLoader.hashCode()); - log.info("createDataSource classLoader url :{}"+ JSON.toJSONString (((URLClassLoader)classLoader).getURLs())); - HikariDataSource myDataSource = (HikariDataSource)classLoader.loadClass("com.zaxxer.hikari.HikariDataSource") - .newInstance(); - myDataSource.setDriverClassName(driverTypeEnum.getDriverClass()); - myDataSource.setJdbcUrl(connectInfo.getUrl()); - myDataSource.setUsername(connectInfo.getUser()); - myDataSource.setPassword(connectInfo.getPassword()); - myDataSource.setAutoCommit(true); - myDataSource.setConnectionTimeout(30000); - myDataSource.setIdleTimeout(600000); - myDataSource.setMaximumPoolSize(5); - myDataSource.setMinimumIdle(1); - myDataSource.setPoolName(connectInfo.getAlias()); - myDataSource.setConnectionTestQuery("select 1"); - if (!ObjectUtils.isEmpty(connectInfo.getExtendMap())) { - Properties properties = new Properties(); - properties.putAll(connectInfo.getExtendMap()); - myDataSource.setDataSourceProperties(properties); - } - Connection connection = myDataSource.getConnection(); - if (connection != null) {connection.close();} - return new MyDataSource(connectInfo, myDataSource); - } - -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/datasource/IDataSource.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/datasource/IDataSource.java deleted file mode 100644 index 07804ec35..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/datasource/IDataSource.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.datasource; - -import java.io.Serial; -import java.sql.SQLException; - -import ai.chat2db.server.domain.support.enums.DriverTypeEnum; -import ai.chat2db.server.domain.support.model.SSHInfo; -import ai.chat2db.server.domain.support.sql.ConnectInfo; -import ai.chat2db.server.domain.support.sql.SSHManager; -import com.alibaba.druid.pool.DruidDataSource; - -import com.jcraft.jsch.Session; - -/** - * @author jipengfei - * @version : DbhubDataSource.java - */ -public class IDataSource extends DruidDataSource { - @Serial - private static final long serialVersionUID = -232274227856574115L; - - public ConnectInfo getConnectInfo() { - return connectInfo; - } - - private ConnectInfo connectInfo; - - public IDataSource(ConnectInfo connectInfo, DriverTypeEnum driverTypeEnum, ClassLoader classLoader) { - this.connectInfo = connectInfo; - - } - - @Override - public void init() throws SQLException { - if (inited) { - return; - } - connectSession(); - super.init(); - inited = true; - } - - private void connectSession() { - SSHInfo ssh = connectInfo.getSsh(); - if (ssh != null && ssh.isUse()) { - Session session = SSHManager.getSSHSession(ssh); - String url = connectInfo.getUrl(); - url = url.replace(connectInfo.getHost(), "127.0.0.1").replace(connectInfo.getPort() + "", - ssh.getLocalPort()); - setUrl(url); - } - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/datasource/MyDataSource.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/datasource/MyDataSource.java deleted file mode 100644 index ea317e678..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/datasource/MyDataSource.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.datasource; - -import ai.chat2db.server.domain.support.enums.DriverTypeEnum; -import ai.chat2db.server.domain.support.sql.ConnectInfo; - -import com.zaxxer.hikari.HikariDataSource; - -/** - * @author jipengfei - * @version : MyDataSource.java - */ -public class MyDataSource { - - public ConnectInfo getConnectInfo() { - return connectInfo; - } - - private ConnectInfo connectInfo; - - public HikariDataSource getHikariDataSource() { - return hikariDataSource; - } - - private HikariDataSource hikariDataSource; - - public MyDataSource(ConnectInfo connectInfo, HikariDataSource hikariDataSource) { - this.connectInfo = connectInfo; - this.hikariDataSource = hikariDataSource; - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/BaseMapper.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/BaseMapper.java deleted file mode 100644 index 4105bc176..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/BaseMapper.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect; - -import java.util.List; - -import ai.chat2db.server.domain.support.model.Table; -import ai.chat2db.server.domain.support.model.TableColumn; -import ai.chat2db.server.domain.support.model.TableIndexColumn; -import org.apache.ibatis.annotations.Param; - -/** - * @author jipengfei - * @version : BaseMapper.java - */ -public interface BaseMapper { - /** - * 查询Database - * - * @return - */ - List showDatabases(); - - /** - * 查询所有表中所有列信息 - * - * @param databaseName - * @param tableName - * @return - */ - List selectColumns(@Param("databaseName") String databaseName,@Param("tableSchema") String tableSchema, @Param("tableName") String tableName); - - /** - * 删除表 - * - * @param databaseName - * @param tableName - */ - void dropTable(@Param("databaseName") String databaseName, @Param("tableName") String tableName); - - /** - * 查询所有的表 - * - * @param databaseName - * @param tableSchema - * @return - */ - List selectTables(@Param("databaseName") String databaseName, @Param("tableSchema") String tableSchema,@Param("tableName") String tableName); - - /** - * @param databaseName - * @return - */ - Long selectTableCount(@Param("databaseName") String databaseName); - - /** - * 查询建表语句 - * - * @param databaseName - * @param tableName - * @return - */ - String showCreateTable(@Param("databaseName") String databaseName,@Param("tableSchema") String tableSchema, - @Param("tableName") String tableName); - - /** - * 查询表索引信息 - * - * @param databaseName - * @param tableName - * @return - */ - List selectTableIndexes(@Param("databaseName") String databaseName,@Param("tableSchema") String tableSchema, - @Param("tableName") String tableName); -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/BaseMetaSchema.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/BaseMetaSchema.java deleted file mode 100644 index da1b731d5..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/BaseMetaSchema.java +++ /dev/null @@ -1,145 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect; - -import java.util.List; - -import ai.chat2db.server.domain.support.dialect.common.SQLParam; -import ai.chat2db.server.domain.support.dialect.common.SQLType; -import ai.chat2db.server.domain.support.model.Function; -import ai.chat2db.server.domain.support.model.Procedure; -import ai.chat2db.server.domain.support.model.Table; -import ai.chat2db.server.domain.support.model.TableColumn; -import ai.chat2db.server.domain.support.model.TableIndex; -import ai.chat2db.server.domain.support.model.Trigger; -import ai.chat2db.server.domain.support.sql.SQLExecutor; -import com.alibaba.druid.sql.parser.DbhubSQLParserUtils; - -/** - * @author jipengfei - * @version : BaseMetaSchema.java - */ -public abstract class BaseMetaSchema implements MetaSchema { - - @Override - public List databases() { - return SQLExecutor.getInstance().databases(); - } - - public String getSQL(SQLType sqlType, SQLParam params) { - switch (sqlType) { - case CREATE_DATABASE: - return "CREATE DATABASE " + params.getDatabaseName(); - case DROP_DATABASE: - return "DROP DATABASE " + params.getDatabaseName(); - case MODIFY_DATABASE: - return "ALTER DATABASE " + params.getDatabaseName() + " RENAME TO " + params.getNewDatabaseName(); - case CREATE_SCHEMA: - return "CREATE SCHEMA " + params.getSchemaName(); - case DROP_SCHEMA: - return "DROP SCHEMA " + params.getSchemaName(); - case MODIFY_SCHEMA: - return "ALTER SCHEMA " + params.getSchemaName() + " RENAME TO " + params.getNewSchemaName(); - } - return null; - } - - @Override - public void modifyDatabase(String databaseName, String newDatabaseName) { - String sql = getSQL(SQLType.MODIFY_DATABASE, SQLParam.builder().databaseName(databaseName) - .newDatabaseName(newDatabaseName).build()); - SQLExecutor.getInstance().executeSql(sql, resultSet -> null); - } - - @Override - public void createDatabase(String databaseName) { - String sql = getSQL(SQLType.CREATE_DATABASE, SQLParam.builder().databaseName(databaseName).build()); - SQLExecutor.getInstance().executeSql(sql, resultSet -> null); - } - - @Override - public void dropDatabase(String databaseName) { - String sql = getSQL(SQLType.DROP_DATABASE, SQLParam.builder().databaseName(databaseName).build()); - SQLExecutor.getInstance().executeSql(sql, resultSet -> null); - } - - @Override - public void createSchema(String databaseName, String schemaName) { - String sql = getSQL(SQLType.CREATE_SCHEMA, SQLParam.builder().databaseName(databaseName).schemaName(schemaName) - .build()); - SQLExecutor.getInstance().executeSql(sql, resultSet -> null); - } - - @Override - public void dropSchema(String databaseName, String schemaName) { - String sql = getSQL(SQLType.DROP_SCHEMA, SQLParam.builder().databaseName(databaseName).schemaName(schemaName) - .build()); - SQLExecutor.getInstance().executeSql(sql, resultSet -> null); - } - - @Override - public void modifySchema(String databaseName, String schemaName, String newSchemaName) { - String sql = getSQL(SQLType.MODIFY_SCHEMA, SQLParam.builder().databaseName(databaseName).schemaName(schemaName) - .newSchemaName(newSchemaName).build()); - SQLExecutor.getInstance().executeSql(sql, resultSet -> null); - } - - @Override - public List schemas(String databaseName) { - return SQLExecutor.getInstance().schemas(databaseName, null); - } - - @Override - public String tableDDL(String databaseName, String schemaName, String tableName) { - return null; - } - - @Override - public void dropTable(String databaseName, String schemaName, String tableName) { - String sql = "drop table " + DbhubSQLParserUtils.format(dbType(),tableName); - SQLExecutor.getInstance().executeSql(sql, resultSet -> null); - } - - @Override - public List
tables(String databaseName, String schemaName, String tableName) { - return SQLExecutor.getInstance().tables(databaseName, schemaName, tableName, new String[] {"TABLE"}); - } - - @Override - public List views(String databaseName, String schemaName) { - return SQLExecutor.getInstance().tables(databaseName, schemaName, null, new String[] {"VIEW"}); - } - - @Override - public List functions(String databaseName, String schemaName) { - return SQLExecutor.getInstance().functions(databaseName, schemaName); - } - - @Override - public List triggers(String databaseName, String schemaName) { - return null; - } - - @Override - public List procedures(String databaseName, String schemaName) { - return SQLExecutor.getInstance().procedures(databaseName, schemaName); - } - - @Override - public List columns(String databaseName, String schemaName, String tableName) { - return SQLExecutor.getInstance().columns(databaseName, schemaName, tableName, null); - } - - @Override - public List columns(String databaseName, String schemaName, String tableName, - String columnName) { - return SQLExecutor.getInstance().columns(databaseName, schemaName, tableName, columnName); - } - - @Override - public List indexes(String databaseName, String schemaName, String tableName) { - return SQLExecutor.getInstance().indexes(databaseName, schemaName, tableName); - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/MetaSchema.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/MetaSchema.java deleted file mode 100644 index f8f60e0e0..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/MetaSchema.java +++ /dev/null @@ -1,183 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect; - -import java.util.List; - -import ai.chat2db.server.domain.support.enums.DbTypeEnum; -import ai.chat2db.server.domain.support.model.Function; -import ai.chat2db.server.domain.support.model.Procedure; -import ai.chat2db.server.domain.support.model.Table; -import ai.chat2db.server.domain.support.model.TableColumn; -import ai.chat2db.server.domain.support.model.TableIndex; -import ai.chat2db.server.domain.support.model.Trigger; -import jakarta.validation.constraints.NotEmpty; - -/** - * @author jipengfei - * @version : MetaSchemaManager.java, v 0.1 2022年12月14日 16:26 jipengfei Exp $ - */ -public interface MetaSchema { - /** - * 支持的数据库类型 - * - * @return - */ - DbTypeEnum dbType(); - - /** - * 查询所有的DATABASE - * - * @return - */ - List databases(); - - /** - * 修改数据库名称 - * @param databaseName - * @param newDatabaseName - */ - void modifyDatabase(String databaseName, String newDatabaseName); - - - /** - * 创建数据库 - * @param databaseName - */ - void createDatabase(String databaseName); - - - /** - * 删除数据库 - * @param databaseName - */ - void dropDatabase(String databaseName); - - /** - * 查询 DB 下schemas - * @param databaseName - * @return - */ - List schemas(String databaseName); - - /** - * 创建schema - * @param databaseName - * @param schemaName - */ - void createSchema(String databaseName, String schemaName); - - /** - * 删除schema - * @param databaseName - * @param schemaName - */ - void dropSchema(String databaseName, String schemaName); - - /** - * 修改schema - * @param databaseName - * @param schemaName - * @param newSchemaName - */ - void modifySchema(String databaseName, String schemaName, String newSchemaName); - - /** - * 展示建表语句 - * - * @param databaseName - * @param tableName - * @return - */ - String tableDDL(@NotEmpty String databaseName, String schemaName, @NotEmpty String tableName); - - /** - * 删除表结构 - * - * @param databaseName - * @param tableName - * @return - */ - void dropTable(@NotEmpty String databaseName, String schemaName, @NotEmpty String tableName); - - /** - * 分页查询表信息 - * - * @param databaseName - * @return - */ - List
tables(@NotEmpty String databaseName, String schemaName,String tableName); - - /** - * 查询所有视图 - * - * @param databaseName - * @param schemaName - * @return - */ - List views(@NotEmpty String databaseName, String schemaName); - - /** - * 查询所有的函数 - * - * @param databaseName - * @param schemaName - * @return - */ - List functions(@NotEmpty String databaseName, String schemaName); - - /** - * 查询所有触发器 - * - * @param databaseName - * @param schemaName - * @return - */ - List triggers(@NotEmpty String databaseName, String schemaName); - - /** - * 查询所有存储过程 - * - * @param databaseName - * @param schemaName - * @return - */ - List procedures(@NotEmpty String databaseName, String schemaName); - - /** - * 查询列的信息 - * - * @param databaseName - * @param tableName - * @return - */ - List columns(@NotEmpty String databaseName, String schemaName, - @NotEmpty String tableName); - - - /** - * 查询database下所有的列信息 - * - * @param databaseName - * @param schemaName - * @param tableName - * @param columnName - * @return - */ - List columns(@NotEmpty String databaseName, String schemaName,String tableName, String columnName); - - /** - * 查询列的信息 - * - * @param databaseName - * @param tableName * @return - */ - List indexes(@NotEmpty String databaseName, String schemaName, @NotEmpty String tableName); - - - - //T getMapper(); - -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/clickhouse/ClickhouseMetaSchemaSupport.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/clickhouse/ClickhouseMetaSchemaSupport.java deleted file mode 100644 index 3eef146bf..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/clickhouse/ClickhouseMetaSchemaSupport.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.clickhouse; - -import ai.chat2db.server.domain.support.dialect.BaseMetaSchema; -import ai.chat2db.server.domain.support.dialect.MetaSchema; -import ai.chat2db.server.domain.support.enums.DbTypeEnum; - -/** - * @author jipengfei - * @version : ClickhouseMetaSchemaSupport.java - */ -public class ClickhouseMetaSchemaSupport extends BaseMetaSchema implements MetaSchema { - @Override - public DbTypeEnum dbType() { - return DbTypeEnum.CLICKHOUSE; - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/SQLKeyConst.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/SQLKeyConst.java deleted file mode 100644 index e6f75613b..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/SQLKeyConst.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.common; - -/** - * @author jipengfei - * @version : SQLConst.java, v 0.1 2022年12月08日 15:08 jipengfei Exp $ - */ -public class SQLKeyConst { - public static final String PG_CREATE_TABLE_SIMPLE = "create table if not exists main.test_table( column_1 serial, column_2 varchar default 'dd'::character varying, column_3 bigserial, column_4 integer default 100, column_5 varchar not null constraint test_table_pk primary key, column_6 varchar, column_7 integer); comment on table main.test_table is '测试表'; comment on column main.test_table.column_6 is '设置备注'; alter table main.test_table owner to ali_dbhub_test; create index if not exists test_table_column_2_index on main.test_table (column_2); create unique index if not exists test_table_column_2_uindex on main.test_table (column_2); comment on index main.test_table_column_2_uindex is 'add'; "; - public static final String PG_ALTER_TABLE_SIMPLE = "alter table main.test_table rename column column_1 to column_001; alter table main.test_table add column_8 integer not null; create index test_table_column_8_index on main.test_table(column_8); "; - - public static final String MYSQL_CREATE_TABLE_SIMPLE = "CREATE TABLE `test`( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `gmt_modified` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', `date` datetime NULL COMMENT '日期', `string` varchar(128) NOT NULL DEFAULT 'Test' COMMENT '字符串', PRIMARY KEY (`id`), KEY `idx_string` (`string`)) DEFAULT CHARACTER SET=utf8mb4 COMMENT='测试表'; "; - public static final String MYSQL_ALTER_TABLE_SIMPLE = "ALTER TABLE `test` ADD COLUMN `number` bigint unsigned NULL COMMENT '数字'; ALTER TABLE `test` ADD UNIQUE INDEX uk_number(number); ALTER TABLE `test` DROP COLUMN `number`; "; - - - public static final String H2_CREATE_TABLE_SIMPLE = "CREATE TABLE `test`( `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `gmt_modified` datetime NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP COMMENT '修改时间', `date` datetime NULL COMMENT '日期', `string` varchar(128) NOT NULL DEFAULT 'Test' COMMENT '字符串', PRIMARY KEY (`id`));"; - - public static final String H2_ALTER_TABLE_SIMPLE = "ALTER TABLE `test` ADD COLUMN `number` bigint NULL COMMENT '数字'; CREATE UNIQUE INDEX uk_number ON `test`(`number`); ALTER TABLE `test` DROP COLUMN `number`;"; - - - public static final String ORACLE_CREATE_TABLE_SIMPLE = "create table if not exists main.test_table( column_1 serial, column_2 varchar default 'dd'::character varying, column_3 bigserial, column_4 integer default 100, column_5 varchar not null constraint test_table_pk primary key, column_6 varchar, column_7 integer); comment on table main.test_table is '测试表'; comment on column main.test_table.column_6 is '设置备注'; alter table main.test_table owner to ali_dbhub_test; create index if not exists test_table_column_2_index on main.test_table (column_2); create unique index if not exists test_table_column_2_uindex on main.test_table (column_2); comment on index main.test_table_column_2_uindex is 'add'; "; - public static final String ORACLE_ALTER_TABLE_SIMPLE = "alter table main.test_table rename column column_1 to column_001; alter table main.test_table add column_8 integer not null; create index test_table_column_8_index on main.test_table(column_8); "; - - - public static final String SQLSERVER_CREATE_TABLE_SIMPLE = "CREATE TABLE [dbo].[table_name] ( [id] bigint NOT NULL, [date] datetime NOT NULL, [String] varchar(1) NOT NULL, [number] bigint NULL);CREATE UNIQUE CLUSTERED INDEX [id] ON [dbo].[table_name] ( [id] ASC);CREATE NONCLUSTERED INDEX [table_name_date_index] ON [dbo].[table_name] ( [date] ASC);CREATE NONCLUSTERED INDEX [table_name_String_index] ON [dbo].[table_name] ( [String] ASC);CREATE UNIQUE NONCLUSTERED INDEX [table_name_pk] ON [dbo].[table_name] ( [number] ASC);EXEC sp_addextendedproperty @name=N'MS_Description', @value=N'mmm', @level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'table_name', @level2type=N'COLUMN', @level2name=N'id';EXEC sp_addextendedproperty @name=N'MS_Description', @value=N'mmm', @level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'table_name', @level2type=N'COLUMN', @level2name=N'date';EXEC sp_addextendedproperty @name=N'MS_Description', @value=N'mmm', @level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'table_name', @level2type=N'COLUMN', @level2name=N'String';EXEC sp_addextendedproperty @name=N'MS_Description', @value=N'mmm', @level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'table_name', @level2type=N'COLUMN', @level2name=N'number';"; - - public static final String SQLSERVER_ALTER_TABLE_SIMPLE = "exec sp_addextendedproperty 'MS_Description', 'mm', 'SCHEMA', 'dbo', 'TABLE', 'table_name', 'COLUMN', 'id' go"; - - - public static final String SQLITE_CREATE_TABLE_SIMPLE = "CREATE TABLE person (\n" - + " id INTEGER PRIMARY KEY AUTOINCREMENT,\n" - + " name TEXT NOT NULL,\n" - + " age INTEGER\n" - + ");"; - public static final String SQLITE_ALTER_TABLE_SIMPLE = "ALTER TABLE person ADD COLUMN address TEXT;"; - - -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/SQLParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/SQLParam.java deleted file mode 100644 index c60cc2b94..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/SQLParam.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.common; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : SQLParam.java - */ -@Data -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class SQLParam { - private String databaseName; - private String newDatabaseName; - private String schemaName; - private String newSchemaName; - -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/SQLType.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/SQLType.java deleted file mode 100644 index 7a00ae5b9..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/SQLType.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.common; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * 需要执行的sql类型 - * - * @author jipengfei - * @version : SQLType.java - */ -public enum SQLType { - - MODIFY_DATABASE, - - CREATE_DATABASE, - - DROP_DATABASE, - - CREATE_SCHEMA, - DROP_SCHEMA, - MODIFY_SCHEMA; - - -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/enums/BaseCollationEnum.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/enums/BaseCollationEnum.java deleted file mode 100644 index 6f40ae456..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/enums/BaseCollationEnum.java +++ /dev/null @@ -1,19 +0,0 @@ -package ai.chat2db.server.domain.support.dialect.common.enums; - -import ai.chat2db.server.domain.support.enums.CollationEnum; -import ai.chat2db.server.tools.base.enums.BaseEnum; - -/** - * 排序类型 - * - * @author Jiaju Zhuang - */ -public interface BaseCollationEnum extends BaseEnum { - - /** - * 返回排序类型 - * - * @return - */ - CollationEnum getCollation(); -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/enums/BaseColumnTypeEnum.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/enums/BaseColumnTypeEnum.java deleted file mode 100644 index 03e16a885..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/enums/BaseColumnTypeEnum.java +++ /dev/null @@ -1,19 +0,0 @@ -package ai.chat2db.server.domain.support.dialect.common.enums; - -import ai.chat2db.server.domain.support.enums.ColumnTypeEnum; -import ai.chat2db.server.tools.base.enums.BaseEnum; - -/** - * 列的类型 - * - * @author Jiaju Zhuang - */ -public interface BaseColumnTypeEnum extends BaseEnum { - - /** - * 返回列的类型 - * - * @return - */ - ColumnTypeEnum getColumnType(); -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/enums/BaseIndexTypeEnum.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/enums/BaseIndexTypeEnum.java deleted file mode 100644 index 805401c59..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/enums/BaseIndexTypeEnum.java +++ /dev/null @@ -1,19 +0,0 @@ -package ai.chat2db.server.domain.support.dialect.common.enums; - -import ai.chat2db.server.domain.support.enums.IndexTypeEnum; -import ai.chat2db.server.tools.base.enums.BaseEnum; - -/** - * 索引的类型 - * - * @author Jiaju Zhuang - */ -public interface BaseIndexTypeEnum extends BaseEnum { - - /** - * 返回索引的类型 - * - * @return - */ - IndexTypeEnum getIndexType(); -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/handler/BooleanTypeHandler.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/handler/BooleanTypeHandler.java deleted file mode 100644 index a991ae299..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/handler/BooleanTypeHandler.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.common.handler; - -import java.sql.CallableStatement; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - -import ai.chat2db.server.tools.base.enums.YesOrNoEnum; - -import org.apache.ibatis.type.JdbcType; -import org.apache.ibatis.type.TypeHandler; - -/** - * @author jipengfei - * @version : NullableTypeHandler.java - */ -public class BooleanTypeHandler implements TypeHandler { - - @Override - public void setParameter(PreparedStatement ps, int i, Boolean parameter, JdbcType jdbcType) throws SQLException { - } - - @Override - public Boolean getResult(ResultSet rs, String columnName) throws SQLException { - return parse(rs.getString(columnName)); - } - - @Override - public Boolean getResult(ResultSet rs, int columnIndex) throws SQLException { - return parse(rs.getString(columnIndex)); - - } - - @Override - public Boolean getResult(CallableStatement cs, int columnIndex) throws SQLException { - return parse(cs.getString(columnIndex)); - } - - private Boolean parse(String result) { - if (YesOrNoEnum.YES.getCode().equalsIgnoreCase(result)) { - return Boolean.TRUE; - } - return Boolean.FALSE; - } - -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/model/SpiExample.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/model/SpiExample.java deleted file mode 100644 index 54370fa6c..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/common/model/SpiExample.java +++ /dev/null @@ -1,28 +0,0 @@ -package ai.chat2db.server.domain.support.dialect.common.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * 表信息 - * - * @author Jiaju Zhuang - */ -@Data -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class SpiExample { - /** - * 建表语句 - */ - private String createTable; - - /** - * 修改表结构 - */ - private String alterTable; -} - diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/db2/DB2MetaSchemaSupport.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/db2/DB2MetaSchemaSupport.java deleted file mode 100644 index a2673cf7e..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/db2/DB2MetaSchemaSupport.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.db2; - -import java.sql.SQLException; - -import ai.chat2db.server.domain.support.dialect.BaseMetaSchema; -import ai.chat2db.server.domain.support.dialect.MetaSchema; -import ai.chat2db.server.domain.support.enums.DbTypeEnum; -import ai.chat2db.server.domain.support.sql.SQLExecutor; - -/** - * @author jipengfei - * @version : DB2MetaSchemaSupport.java - */ -public class DB2MetaSchemaSupport extends BaseMetaSchema implements MetaSchema { - - private String functionSQL - = "CREATE FUNCTION tableSchema.ufn_GetCreateTableScript( @schema_name NVARCHAR(128), @table_name NVARCHAR" - + "(128)) RETURNS NVARCHAR(MAX) AS BEGIN DECLARE @CreateTableScript NVARCHAR(MAX); DECLARE @IndexScripts " - + "NVARCHAR(MAX) = ''; DECLARE @ColumnDescriptions NVARCHAR(MAX) = N''; SELECT @CreateTableScript = CONCAT( " - + "'CREATE TABLE [', s.name, '].[' , t.name, '] (', STUFF( ( SELECT ', [' + c.name + '] ' + tp.name + CASE " - + "WHEN tp.name IN ('varchar', 'nvarchar', 'char', 'nchar') THEN '(' + IIF(c.max_length = -1, 'MAX', CAST(c" - + ".max_length AS NVARCHAR(10))) + ')' WHEN tp.name IN ('decimal', 'numeric') THEN '(' + CAST(c.precision AS " - + "NVARCHAR(10)) + ', ' + CAST(c.scale AS NVARCHAR(10)) + ')' ELSE '' END + ' ' + CASE WHEN c.is_nullable = 1" - + " THEN 'NULL' ELSE 'NOT NULL' END FROM sys.columns c JOIN sys.types tp ON c.user_type_id = tp.user_type_id " - + "WHERE c.object_id = t.object_id FOR XML PATH(''), TYPE ).value('/', 'nvarchar(max)'), 1, 1, ''), ');' ) " - + "FROM sys.tables t JOIN sys.schemas s ON t.schema_id = s.schema_id WHERE t.name = @table_name AND s.name = " - + "@schema_name; SELECT @IndexScripts = @IndexScripts + 'CREATE ' + CASE WHEN i.is_unique = 1 THEN 'UNIQUE ' " - + "ELSE '' END + i.type_desc + ' INDEX [' + i.name + '] ON [' + s.name + '].[' + t.name + '] (' + STUFF( ( " - + "SELECT ', [' + c.name + ']' + CASE WHEN ic.is_descending_key = 1 THEN ' DESC' ELSE ' ASC' END FROM sys" - + ".index_columns ic JOIN sys.columns c ON ic.object_id = c.object_id AND ic.column_id = c.column_id WHERE ic" - + ".object_id = i.object_id AND ic.index_id = i.index_id ORDER BY ic.key_ordinal FOR XML PATH('') ), 1, 1, " - + "'') + ')' + CASE WHEN i.has_filter = 1 THEN ' WHERE ' + i.filter_definition ELSE '' END + ';' + CHAR(13) +" - + " CHAR(10) FROM sys.indexes i JOIN sys.tables t ON i.object_id = t.object_id JOIN sys.schemas s ON t" - + ".schema_id = s.schema_id WHERE i.type > 0 AND t.name = @table_name AND s.name " - + "= @schema_name; SELECT @ColumnDescriptions += 'EXEC sp_addextendedproperty @name=N''MS_Description'', " - + "@value=N''' + CAST(p.value AS NVARCHAR(MAX)) + ''', @level0type=N''SCHEMA'', @level0name=N''' + " - + "@schema_name + ''', @level1type=N''TABLE'', @level1name=N''' + @table_name + ''', @level2type=N''COLUMN''," - + " @level2name=N''' + c.name + ''';' + CHAR(13) + CHAR(10) FROM sys.extended_properties p JOIN sys.columns c" - + " ON p.major_id = c.object_id AND p.minor_id = c.column_id JOIN sys.tables t ON c.object_id = t.object_id " - + "JOIN sys.schemas s ON t.schema_id = s.schema_id WHERE p.class = 1 AND t.name = @table_name AND s.name = " - + "@schema_name; SET @CreateTableScript = @CreateTableScript + CHAR(13) + CHAR(10) + @IndexScripts + CHAR(13)" - + " + CHAR(10)+ @ColumnDescriptions+ CHAR(10); RETURN @CreateTableScript; END"; - - @Override - public DbTypeEnum dbType() { - return DbTypeEnum.SQLSERVER; - } - - @Override - public String tableDDL(String databaseName, String schemaName, String tableName) { - try { - System.out.println(functionSQL); - SQLExecutor.getInstance().executeSql(functionSQL.replace("tableSchema", schemaName), resultSet -> null); - } catch (Exception e) { - //log.error("创建函数失败", e); - } - - String ddlSql = "SELECT " + schemaName + ".ufn_GetCreateTableScript('" + schemaName + "', '" + tableName - + "') AS sql"; - return SQLExecutor.getInstance().executeSql(ddlSql, resultSet -> { - try { - if (resultSet.next()) { - return resultSet.getString("sql"); - } - } catch (SQLException e) { - throw new RuntimeException(e); - } - return null; - }); - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/dm/DMMetaSchemaSupport.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/dm/DMMetaSchemaSupport.java deleted file mode 100644 index cdd1825d6..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/dm/DMMetaSchemaSupport.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.dm; - -import java.sql.SQLException; - -import ai.chat2db.server.domain.support.dialect.BaseMetaSchema; -import ai.chat2db.server.domain.support.dialect.MetaSchema; -import ai.chat2db.server.domain.support.enums.DbTypeEnum; -import ai.chat2db.server.domain.support.sql.SQLExecutor; -import ai.chat2db.server.domain.support.util.SqlUtils; - -/** - * @author jipengfei - * @version : DMMetaSchemaSupport.java - */ -public class DMMetaSchemaSupport extends BaseMetaSchema implements MetaSchema { - - @Override - public DbTypeEnum dbType() { - return DbTypeEnum.DM; - } - - @Override - public String tableDDL(String databaseName, String schemaName, String tableName) { - String selectObjectDDLSQL = String.format( - "select dbms_metadata.get_ddl(%s, %s, %s) AS \"sql\" from dual", - SqlUtils.formatSQLString("TABLE"), SqlUtils.formatSQLString(tableName), - SqlUtils.formatSQLString(schemaName)); - return SQLExecutor.getInstance().executeSql(selectObjectDDLSQL, resultSet -> { - try { - if (resultSet.next()) { - return resultSet.getString("sql"); - } - } catch (SQLException e) { - throw new RuntimeException(e); - } - return null; - }); - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/h2/H2CollationEnum.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/h2/H2CollationEnum.java deleted file mode 100644 index a72055d19..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/h2/H2CollationEnum.java +++ /dev/null @@ -1,38 +0,0 @@ -package ai.chat2db.server.domain.support.dialect.h2; - -import ai.chat2db.server.domain.support.enums.CollationEnum; -import ai.chat2db.server.domain.support.dialect.common.enums.BaseCollationEnum; - -import lombok.Getter; - -/** - * 排序枚举 - * - * @author Jiaju Zhuang - */ -@Getter -public enum H2CollationEnum implements BaseCollationEnum { - /** - * ASC - */ - ASC("ASC", CollationEnum.ASC), - /** - * DESC - */ - DESC("DESC", CollationEnum.DESC), - ; - - final String code; - final CollationEnum collation; - - H2CollationEnum(String code, CollationEnum collation) { - this.code = code; - this.collation = collation; - } - - @Override - public String getDescription() { - return getCode(); - } - -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/h2/H2ColumnTypeEnum.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/h2/H2ColumnTypeEnum.java deleted file mode 100644 index 78e5a990f..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/h2/H2ColumnTypeEnum.java +++ /dev/null @@ -1,46 +0,0 @@ -package ai.chat2db.server.domain.support.dialect.h2; - -import ai.chat2db.server.domain.support.dialect.common.enums.BaseColumnTypeEnum; -import ai.chat2db.server.domain.support.enums.ColumnTypeEnum; - -import lombok.Getter; - -/** - * 列的类型 - * - * @author Jiaju Zhuang - */ -@Getter -public enum H2ColumnTypeEnum implements BaseColumnTypeEnum { - /** - * BIGINT - */ - BIGINT("BIGINT", ColumnTypeEnum.BIGINT), - /** - * BIGINT - */ - CHARACTER_VARYING("CHARACTER VARYING", ColumnTypeEnum.VARCHAR), - /** - * TIMESTAMP - */ - TIMESTAMP("TIMESTAMP", ColumnTypeEnum.TIMESTAMP), - /** - * INTEGER - */ - INTEGER("INTEGER", ColumnTypeEnum.INTEGER), - ; - - final String code; - final ColumnTypeEnum columnType; - - H2ColumnTypeEnum(String code, ColumnTypeEnum columnType) { - this.code = code; - this.columnType = columnType; - } - - @Override - public String getDescription() { - return getCode(); - } - -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/h2/H2IndexTypeEnum.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/h2/H2IndexTypeEnum.java deleted file mode 100644 index 0611edaa6..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/h2/H2IndexTypeEnum.java +++ /dev/null @@ -1,42 +0,0 @@ -package ai.chat2db.server.domain.support.dialect.h2; - -import ai.chat2db.server.domain.support.enums.IndexTypeEnum; -import ai.chat2db.server.domain.support.dialect.common.enums.BaseIndexTypeEnum; - -import lombok.Getter; - -/** - * 列的类型 - * - * @author Jiaju Zhuang - */ -@Getter -public enum H2IndexTypeEnum implements BaseIndexTypeEnum { - /** - * PRIMARY_KEY - */ - PRIMARY_KEY("PRIMARY KEY", IndexTypeEnum.PRIMARY_KEY), - /** - * UNIQUE INDEX - */ - UNIQUE("UNIQUE INDEX", IndexTypeEnum.UNIQUE), - /** - * NORMAL - */ - NORMAL("INDEX", IndexTypeEnum.NORMAL), - ; - - final String code; - final IndexTypeEnum indexType; - - H2IndexTypeEnum(String code, IndexTypeEnum indexType) { - this.code = code; - this.indexType = indexType; - } - - @Override - public String getDescription() { - return getCode(); - } - -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/h2/H2MetaSchemaSupport.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/h2/H2MetaSchemaSupport.java deleted file mode 100644 index c191c9b97..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/h2/H2MetaSchemaSupport.java +++ /dev/null @@ -1,109 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.h2; - -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import ai.chat2db.server.domain.support.dialect.BaseMetaSchema; -import ai.chat2db.server.domain.support.dialect.MetaSchema; -import ai.chat2db.server.domain.support.enums.DbTypeEnum; -import ai.chat2db.server.domain.support.sql.SQLExecutor; -import jakarta.validation.constraints.NotEmpty; -import lombok.extern.slf4j.Slf4j; - -/** - * @author jipengfei - * @version : H2MetaSchemaSupport.java - */ -@Slf4j -public class H2MetaSchemaSupport extends BaseMetaSchema implements MetaSchema { - - @Override - public DbTypeEnum dbType() { - return DbTypeEnum.H2; - - } - - @Override - public String tableDDL(@NotEmpty String databaseName, String schemaName, @NotEmpty String tableName) { - return getDDL(databaseName, schemaName, tableName); - } - - - private String getDDL(String databaseName, String schemaName, String tableName) { - try { - Connection connection = SQLExecutor.getInstance().getConnection(); - // 查询表结构信息 - ResultSet columns = connection.getMetaData().getColumns(databaseName, schemaName, tableName, null); - List columnDefinitions = new ArrayList<>(); - while (columns.next()) { - String columnName = columns.getString("COLUMN_NAME"); - String columnType = columns.getString("TYPE_NAME"); - int columnSize = columns.getInt("COLUMN_SIZE"); - String remarks = columns.getString("REMARKS"); - String defaultValue = columns.getString("COLUMN_DEF"); - String nullable = columns.getInt("NULLABLE") == ResultSetMetaData.columnNullable ? "NULL" : "NOT NULL"; - StringBuilder columnDefinition = new StringBuilder(); - columnDefinition.append(columnName).append(" ").append(columnType); - if (columnSize != 0) { - columnDefinition.append("(").append(columnSize).append(")"); - } - columnDefinition.append(" ").append(nullable); - if (defaultValue != null) { - columnDefinition.append(" DEFAULT ").append(defaultValue); - } - if (remarks != null) { - columnDefinition.append(" COMMENT '").append(remarks).append("'"); - } - columnDefinitions.add(columnDefinition.toString()); - } - - // 查询表索引信息 - ResultSet indexes = connection.getMetaData().getIndexInfo(databaseName, schemaName, tableName, false, - false); - Map> indexMap = new HashMap<>(); - while (indexes.next()) { - String indexName = indexes.getString("INDEX_NAME"); - String columnName = indexes.getString("COLUMN_NAME"); - if (indexName != null) { - if (!indexMap.containsKey(indexName)) { - indexMap.put(indexName, new ArrayList<>()); - } - indexMap.get(indexName).add(columnName); - } - } - StringBuilder createTableDDL = new StringBuilder("CREATE TABLE "); - createTableDDL.append(tableName).append(" (\n"); - createTableDDL.append(String.join(",\n", columnDefinitions)); - createTableDDL.append("\n);\n"); - - System.out.println("DDL建表语句:"); - System.out.println(createTableDDL.toString()); - - // 输出索引信息 - System.out.println("\nDDL索引语句:"); - for (Map.Entry> entry : indexMap.entrySet()) { - String indexName = entry.getKey(); - List columnList = entry.getValue(); - String indexColumns = String.join(", ", columnList); - String createIndexDDL = String.format("CREATE INDEX %s ON %s (%s);", indexName, tableName, - indexColumns); - System.out.println(createIndexDDL); - createTableDDL.append(createIndexDDL); - } - return createTableDDL.toString(); - - } catch (Exception e) { - e.printStackTrace(); - } - return ""; - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/h2/handler/H2IndexTypeHandler.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/h2/handler/H2IndexTypeHandler.java deleted file mode 100644 index 64be534ef..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/h2/handler/H2IndexTypeHandler.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.h2.handler; - -import java.sql.CallableStatement; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - -import ai.chat2db.server.domain.support.dialect.h2.H2IndexTypeEnum; - -import org.apache.ibatis.type.JdbcType; -import org.apache.ibatis.type.TypeHandler; - -/** - * @author jipengfei - * @version : IndexTypeHandler.java, v 0.1 2022年12月15日 10:36 jipengfei Exp $ - */ -public class H2IndexTypeHandler implements TypeHandler { - @Override - public void setParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException { - } - - @Override - public String getResult(ResultSet rs, String columnName) throws SQLException { - return parse(rs.getString(columnName)); - } - - @Override - public String getResult(ResultSet rs, int columnIndex) throws SQLException { - return parse(rs.getString(columnIndex)); - - } - - @Override - public String getResult(CallableStatement cs, int columnIndex) throws SQLException { - return parse(cs.getString(columnIndex)); - } - - - private String parse(String result) { - - if (H2IndexTypeEnum.PRIMARY_KEY.getCode().equalsIgnoreCase(result)) { - return H2IndexTypeEnum.PRIMARY_KEY.getIndexType().getCode(); - } else if (H2IndexTypeEnum.UNIQUE.getCode().equalsIgnoreCase(result)) { - return H2IndexTypeEnum.UNIQUE.getIndexType().getCode(); - } else { - return H2IndexTypeEnum.NORMAL.getIndexType().getCode(); - } - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/hive/HiveMetaSchemaSupport.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/hive/HiveMetaSchemaSupport.java deleted file mode 100644 index 46bf19856..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/hive/HiveMetaSchemaSupport.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.hive; - -import ai.chat2db.server.domain.support.dialect.BaseMetaSchema; -import ai.chat2db.server.domain.support.dialect.MetaSchema; -import ai.chat2db.server.domain.support.enums.DbTypeEnum; - -/** - * @author jipengfei - * @version : HiveMetaSchemaSupport.java - */ -public class HiveMetaSchemaSupport extends BaseMetaSchema implements MetaSchema { - @Override - public DbTypeEnum dbType() { - return DbTypeEnum.HIVE; - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/kingbase/KingBaseSchemaSupport.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/kingbase/KingBaseSchemaSupport.java deleted file mode 100644 index c0cc57f5b..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/kingbase/KingBaseSchemaSupport.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.kingbase; - -import ai.chat2db.server.domain.support.dialect.BaseMetaSchema; -import ai.chat2db.server.domain.support.dialect.MetaSchema; -import ai.chat2db.server.domain.support.enums.DbTypeEnum; - -/** - * @author jipengfei - * @version : H2MetaSchemaSupport.java - */ -public class KingBaseSchemaSupport extends BaseMetaSchema implements MetaSchema { - @Override - public DbTypeEnum dbType() { - return DbTypeEnum.KINGBASE; - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mariadb/MariaDBMetaSchemaSupport.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mariadb/MariaDBMetaSchemaSupport.java deleted file mode 100644 index ea708b91e..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mariadb/MariaDBMetaSchemaSupport.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.mariadb; - -import ai.chat2db.server.domain.support.dialect.BaseMetaSchema; -import ai.chat2db.server.domain.support.dialect.MetaSchema; -import ai.chat2db.server.domain.support.dialect.mysql.MysqlMetaSchemaSupport; -import ai.chat2db.server.domain.support.enums.DbTypeEnum; - -/** - * @author jipengfei - * @version : MariaDBMetaSchemaSupport.java - */ -public class MariaDBMetaSchemaSupport extends MysqlMetaSchemaSupport implements MetaSchema { - @Override - public DbTypeEnum dbType() { - return DbTypeEnum.MARIADB; - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mongodb/MongodbMetaSchemaSupport.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mongodb/MongodbMetaSchemaSupport.java deleted file mode 100644 index 8f9c5ad14..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mongodb/MongodbMetaSchemaSupport.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.mongodb; - -import ai.chat2db.server.domain.support.dialect.BaseMetaSchema; -import ai.chat2db.server.domain.support.dialect.MetaSchema; -import ai.chat2db.server.domain.support.enums.DbTypeEnum; - -/** - * @author jipengfei - * @version : MongodbMetaSchemaSupport.java - */ -public class MongodbMetaSchemaSupport extends BaseMetaSchema implements MetaSchema { - @Override - public DbTypeEnum dbType() { - return DbTypeEnum.MONGODB; - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/MysqlCollationEnum.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/MysqlCollationEnum.java deleted file mode 100644 index 2d276f926..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/MysqlCollationEnum.java +++ /dev/null @@ -1,38 +0,0 @@ -package ai.chat2db.server.domain.support.dialect.mysql; - -import ai.chat2db.server.domain.support.enums.CollationEnum; -import ai.chat2db.server.domain.support.dialect.common.enums.BaseCollationEnum; - -import lombok.Getter; - -/** - * 排序枚举 - * - * @author Jiaju Zhuang - */ -@Getter -public enum MysqlCollationEnum implements BaseCollationEnum { - /** - * ASC - */ - ASC("A", CollationEnum.ASC), - /** - * DESC - */ - DESC("D", CollationEnum.DESC), - ; - - final String code; - final CollationEnum collation; - - MysqlCollationEnum(String code, CollationEnum collation) { - this.code = code; - this.collation = collation; - } - - @Override - public String getDescription() { - return getCode(); - } - -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/MysqlMetaSchemaSupport.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/MysqlMetaSchemaSupport.java deleted file mode 100644 index 0d22ccc39..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/MysqlMetaSchemaSupport.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.mysql; - -import java.sql.SQLException; - -import ai.chat2db.server.domain.support.dialect.BaseMetaSchema; -import ai.chat2db.server.domain.support.dialect.MetaSchema; -import ai.chat2db.server.domain.support.enums.DbTypeEnum; -import ai.chat2db.server.domain.support.sql.SQLExecutor; -import jakarta.validation.constraints.NotEmpty; -import lombok.extern.slf4j.Slf4j; - -import static com.alibaba.druid.sql.parser.DbhubSQLParserUtils.format; - -/** - * @author jipengfei - * @version : MysqlMetaSchemaSupport.java, v 0.1 2022年12月14日 22:44 jipengfei Exp $ - */ -@Slf4j -public class MysqlMetaSchemaSupport extends BaseMetaSchema implements MetaSchema { - - @Override - public DbTypeEnum dbType() { - return DbTypeEnum.MYSQL; - } - - @Override - public String tableDDL(@NotEmpty String databaseName, String schemaName, @NotEmpty String tableName) { - String sql = "SHOW CREATE TABLE " + format(dbType(), databaseName) + "." - + format(dbType(), tableName); - return SQLExecutor.getInstance().executeSql(sql, resultSet -> { - try { - if (resultSet.next()) { - return resultSet.getString("Create Table"); - } - } catch (SQLException e) { - throw new RuntimeException(e); - } - return null; - }); - } - -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/handler/MysqlCollationTypeHandler.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/handler/MysqlCollationTypeHandler.java deleted file mode 100644 index 925c380b5..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/handler/MysqlCollationTypeHandler.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.mysql.handler; - -import java.sql.CallableStatement; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - -import ai.chat2db.server.domain.support.dialect.mysql.MysqlCollationEnum; - -import org.apache.ibatis.type.JdbcType; -import org.apache.ibatis.type.TypeHandler; - -/** - * - * @author jipengfei - * @version : MysqlCollationTypeHandler.java - */ -public class MysqlCollationTypeHandler implements TypeHandler { - @Override - public void setParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException { - - } - - @Override - public String getResult(ResultSet rs, String columnName) throws SQLException { - if (MysqlCollationEnum.DESC.getCode().equalsIgnoreCase(rs.getString(columnName))) { - return MysqlCollationEnum.DESC.getCollation().getCode(); - } else { - return MysqlCollationEnum.ASC.getCollation().getCode(); - } - } - - @Override - public String getResult(ResultSet rs, int columnIndex) throws SQLException { - if (MysqlCollationEnum.DESC.getCode().equalsIgnoreCase(rs.getString(columnIndex))) { - return MysqlCollationEnum.DESC.getCollation().getCode(); - } else { - return MysqlCollationEnum.ASC.getCollation().getCode(); - } - } - - @Override - public String getResult(CallableStatement cs, int columnIndex) throws SQLException { - if (MysqlCollationEnum.DESC.getCode().equalsIgnoreCase(cs.getString(columnIndex))) { - return MysqlCollationEnum.DESC.getCollation().getCode(); - } else { - return MysqlCollationEnum.ASC.getCollation().getCode(); - } - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/handler/MysqlColumnKeyHandler.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/handler/MysqlColumnKeyHandler.java deleted file mode 100644 index 15b0e7bfe..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/handler/MysqlColumnKeyHandler.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.mysql.handler; - -import java.sql.CallableStatement; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - -import org.apache.ibatis.type.JdbcType; -import org.apache.ibatis.type.TypeHandler; - -/** - * ColumnKey专用的转换器 - * - * @author 是仪 - */ -public class MysqlColumnKeyHandler implements TypeHandler { - - @Override - public void setParameter(PreparedStatement ps, int i, Boolean parameter, JdbcType jdbcType) throws SQLException { - } - - @Override - public Boolean getResult(ResultSet rs, String columnName) throws SQLException { - return parse(rs.getString(columnName)); - } - - @Override - public Boolean getResult(ResultSet rs, int columnIndex) throws SQLException { - return parse(rs.getString(columnIndex)); - - } - - @Override - public Boolean getResult(CallableStatement cs, int columnIndex) throws SQLException { - return parse(cs.getString(columnIndex)); - } - - private Boolean parse(String result) { - if ("PRI".equalsIgnoreCase(result)) { - return Boolean.TRUE; - } - return Boolean.FALSE; - } - -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/handler/MysqlExtraTypeHandler.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/handler/MysqlExtraTypeHandler.java deleted file mode 100644 index c54ff408d..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/handler/MysqlExtraTypeHandler.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.mysql.handler; - -import java.sql.CallableStatement; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - -import org.apache.ibatis.type.JdbcType; -import org.apache.ibatis.type.TypeHandler; - -/** - * extra专用的转换器 - * - * @author 是仪 - */ -public class MysqlExtraTypeHandler implements TypeHandler { - - @Override - public void setParameter(PreparedStatement ps, int i, Boolean parameter, JdbcType jdbcType) throws SQLException { - } - - @Override - public Boolean getResult(ResultSet rs, String columnName) throws SQLException { - return parse(rs.getString(columnName)); - } - - @Override - public Boolean getResult(ResultSet rs, int columnIndex) throws SQLException { - return parse(rs.getString(columnIndex)); - - } - - @Override - public Boolean getResult(CallableStatement cs, int columnIndex) throws SQLException { - return parse(cs.getString(columnIndex)); - } - - private Boolean parse(String result) { - if ("auto_increment".equalsIgnoreCase(result)) { - return Boolean.TRUE; - } - return Boolean.FALSE; - } - -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/handler/MysqlIndexTypeHandler.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/handler/MysqlIndexTypeHandler.java deleted file mode 100644 index d5c31b945..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/mysql/handler/MysqlIndexTypeHandler.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.mysql.handler; - -import java.sql.CallableStatement; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - -import ai.chat2db.server.domain.support.enums.IndexTypeEnum; - -import org.apache.ibatis.type.JdbcType; -import org.apache.ibatis.type.TypeHandler; - -/** - * @author jipengfei - * @version : IndexTypeHandler.java, v 0.1 2022年12月15日 10:36 jipengfei Exp $ - */ -public class MysqlIndexTypeHandler implements TypeHandler { - @Override - public void setParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException { - } - - @Override - public String getResult(ResultSet rs, String columnName) throws SQLException { - return parse(rs.getString(columnName), rs.getString("INDEX_NAME")); - } - - @Override - public String getResult(ResultSet rs, int columnIndex) throws SQLException { - return parse(rs.getString(columnIndex), rs.getString("INDEX_NAME")); - } - - @Override - public String getResult(CallableStatement cs, int columnIndex) throws SQLException { - return parse(cs.getString(columnIndex), cs.getString("INDEX_NAME")); - } - - private String parse(String result, String indexName) { - if ("PRIMARY".equalsIgnoreCase(indexName)) { - return IndexTypeEnum.PRIMARY_KEY.getCode(); - } else { - if ("1".equalsIgnoreCase(result)) { - return IndexTypeEnum.NORMAL.getCode(); - } else { - return IndexTypeEnum.UNIQUE.getCode(); - } - } - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/oceanbase/OceanBaseMetaSchemaSupport.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/oceanbase/OceanBaseMetaSchemaSupport.java deleted file mode 100644 index 4285de265..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/oceanbase/OceanBaseMetaSchemaSupport.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.oceanbase; - -import ai.chat2db.server.domain.support.dialect.MetaSchema; -import ai.chat2db.server.domain.support.dialect.mysql.MysqlMetaSchemaSupport; -import ai.chat2db.server.domain.support.enums.DbTypeEnum; - -/** - * @author jipengfei - * @version : OceanBaseMetaSchemaSupport.java - */ -public class OceanBaseMetaSchemaSupport extends MysqlMetaSchemaSupport implements MetaSchema { - @Override - public DbTypeEnum dbType() { - return DbTypeEnum.OCEANBASE; - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/oracle/OracleMetaSchemaSupport.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/oracle/OracleMetaSchemaSupport.java deleted file mode 100644 index 88f6c1b6a..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/oracle/OracleMetaSchemaSupport.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.oracle; - -import java.sql.SQLException; - -import ai.chat2db.server.domain.support.dialect.BaseMetaSchema; -import ai.chat2db.server.domain.support.dialect.MetaSchema; -import ai.chat2db.server.domain.support.enums.DbTypeEnum; -import ai.chat2db.server.domain.support.sql.SQLExecutor; - -/** - * @author jipengfei - * @version : OracleMetaSchemaSupport.java - */ -public class OracleMetaSchemaSupport extends BaseMetaSchema implements MetaSchema { - - - @Override - public DbTypeEnum dbType() { - return DbTypeEnum.ORACLE; - } - -// @Override -// public List databases() { -// return super.schemas(null); -// } -// -// @Override -// public List schemas(String databaseName) { -// return Lists.newArrayList(); -// } - - @Override - public String tableDDL(String databaseName, String schemaName, String tableName) { - String sql = "select dbms_metadata.get_ddl('TABLE','"+tableName+"') as sql from dual," - + "user_tables where table_name = '" + tableName + "'"; - return SQLExecutor.getInstance().executeSql(sql, resultSet -> { - try { - if (resultSet.next()) { - return resultSet.getString("sql"); - } - } catch (SQLException e) { - throw new RuntimeException(e); - } - - return null; - }); - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/PostgresqlMetaSchemaSupport.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/PostgresqlMetaSchemaSupport.java deleted file mode 100644 index a7d03eb4f..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/PostgresqlMetaSchemaSupport.java +++ /dev/null @@ -1,201 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.postgresql; - -import java.sql.SQLException; - -import ai.chat2db.server.domain.support.dialect.BaseMetaSchema; -import ai.chat2db.server.domain.support.dialect.MetaSchema; -import ai.chat2db.server.domain.support.enums.DbTypeEnum; -import ai.chat2db.server.domain.support.sql.SQLExecutor; - -import lombok.extern.slf4j.Slf4j; - -import static ai.chat2db.server.domain.support.enums.DbTypeEnum.POSTGRESQL; - -/** - * @author jipengfei - * @version : PostgresqlDataBase.java, v 0.1 2022年12月08日 14:48 jipengfei Exp $ - */ -@Slf4j -public class PostgresqlMetaSchemaSupport extends BaseMetaSchema implements MetaSchema { - - @Override - public DbTypeEnum dbType() { - return POSTGRESQL; - } - - private String functionSQL = - " CREATE OR REPLACE FUNCTION showcreatetable(namespace character varying, tablename character " - + "varying)\n" - + " RETURNS character varying AS\n" - + "\n" - + " $BODY$\n" - + " declare\n" - + " tableScript character varying default '';\n" - + "\n" - + " begin\n" - + " -- columns\n" - + " tableScript:=tableScript || ' CREATE TABLE '|| tablename|| ' ( '|| chr(13)||chr(10) || " - + "array_to_string" - + "(\n" - + " array(\n" - + " select ' ' || concat_ws(' ',fieldName, fieldType, fieldLen, indexType, isNullStr, fieldComment" - + " ) as " - + "column_line\n" - + " from (\n" - + " select a.attname as fieldName,format_type(a.atttypid,a.atttypmod) as fieldType,(case when " - + "atttypmod-4>0 then\n" - + " atttypmod-4 else 0 end) as fieldLen,\n" - + " (case when (select count(*) from pg_constraint where conrelid = a.attrelid and conkey[1]=attnum " - + "and\n" - + " contype='p')>0 then 'PRI'\n" - + " when (select count(*) from pg_constraint where conrelid = a.attrelid and conkey[1]=attnum and " - + "contype='u')>0\n" - + " then 'UNI'\n" - + " when (select count(*) from pg_constraint where conrelid = a.attrelid and conkey[1]=attnum and " - + "contype='f')>0\n" - + " then 'FRI'\n" - + " else '' end) as indexType,\n" - + " (case when a.attnotnull=true then 'not null' else 'null' end) as isNullStr,\n" - + " ' comment ' || col_description(a.attrelid,a.attnum) as fieldComment\n" - + " from pg_attribute a where attstattarget=-1 and attrelid = (select c.oid from pg_class c," - + "pg_namespace n" - + " where\n" - + " c.relnamespace=n.oid and n.nspname =namespace and relname =tablename)\n" - + "\n" - + " ) as string_columns\n" - + " ),','||chr(13)||chr(10)) || ',';\n" - + "\n" - + "\n" - + " -- 约束\n" - + " tableScript:= tableScript || chr(13)||chr(10) || array_to_string(\n" - + " array(\n" - + " select concat(' CONSTRAINT ',conname ,c ,u,p,f) from (\n" - + " select conname,\n" - + " case when contype='c' then ' CHECK('|| ( select findattname(namespace,tablename,'c') ) ||')' " - + "end " - + "as c " - + ",\n" - + " case when contype='u' then ' UNIQUE('|| ( select findattname(namespace,tablename,'u') ) ||')' " - + "end " - + "as u" - + " ,\n" - + " case when contype='p' then ' PRIMARY KEY ('|| ( select findattname(namespace,tablename,'p') ) " - + "||')' " - + "end as p ,\n" - + " case when contype='f' then ' FOREIGN KEY('|| ( select findattname(namespace,tablename,'u') ) " - + "||') " - + "REFERENCES '||\n" - + " (select p.relname from pg_class p where p.oid=c.confrelid ) || '('|| ( select\n" - + " findattname(namespace,tablename,'u') ) ||')' end as f\n" - + " from pg_constraint c\n" - + " where contype in('u','c','f','p') and conrelid=(\n" - + " select oid from pg_class where relname=tablename and relnamespace =(\n" - + " select oid from pg_namespace where nspname = namespace\n" - + " )\n" - + " )\n" - + " ) as t\n" - + " ) ,',' || chr(13)||chr(10) ) || chr(13)||chr(10) ||' ); ';\n" - + "\n" - + " -- indexs\n" - + " -- CREATE UNIQUE INDEX pg_language_oid_index ON pg_language USING btree (oid); -- table " - + "pg_language\n" - + "\n" - + "\n" - + " --\n" - + " /** **/\n" - + " --- 获取非约束索引 column\n" - + " -- CREATE UNIQUE INDEX pg_language_oid_index ON pg_language USING btree (oid); -- table " - + "pg_language\n" - + " tableScript:= tableScript || chr(13)||chr(10) || chr(13)||chr(10) || array_to_string(\n" - + " array(\n" - + " select 'CREATE INDEX ' || indexrelname || ' ON ' || tablename || ' USING btree '|| '(' || " - + "attname " - + "|| " - + "');' from (\n" - + " SELECT\n" - + " i.relname AS indexrelname , x.indkey,\n" - + "\n" - + " ( select array_to_string (\n" - + " array(\n" - + " select a.attname from pg_attribute a where attrelid=c.oid and a.attnum in ( select unnest(x" - + ".indkey) )\n" - + "\n" - + " )\n" - + " ,',' ) )as attname\n" - + "\n" - + " FROM pg_class c\n" - + " JOIN pg_index x ON c.oid = x.indrelid\n" - + " JOIN pg_class i ON i.oid = x.indexrelid\n" - + " LEFT JOIN pg_namespace n ON n.oid = c.relnamespace\n" - + " WHERE c.relname=tablename and i.relname not in\n" - + " ( select constraint_name from information_schema.key_column_usage where table_name=tablename )\n" - + " )as t\n" - + " ) ,','|| chr(13)||chr(10));\n" - + "\n" - + "\n" - + " -- COMMENT COMMENT ON COLUMN sys_activity.id IS '主键';\n" - + " tableScript:= tableScript || chr(13)||chr(10) || chr(13)||chr(10) || array_to_string(\n" - + " array(\n" - + " SELECT 'COMMENT ON COLUMN' || tablename || '.' || a.attname ||' IS '|| ''''|| d.description " - + "||''''\n" - + " FROM pg_class c\n" - + " JOIN pg_description d ON c.oid=d.objoid\n" - + " JOIN pg_attribute a ON c.oid = a.attrelid\n" - + " WHERE c.relname=tablename\n" - + " AND a.attnum = d.objsubid),','|| chr(13)||chr(10)) ;\n" - + "\n" - + " return tableScript;\n" - + "\n" - + " end\n" - + " $BODY$ LANGUAGE plpgsql;\n" - + "\n" - + " CREATE OR REPLACE FUNCTION findattname(namespace character varying, tablename character " - + "varying, " - + "ctype" - + " character\n" - + " varying)\n" - + " RETURNS character varying as $BODY$\n" - + "\n" - + " declare\n" - + " tt oid ;\n" - + " aname character varying default '';\n" - + "\n" - + " begin\n" - + " tt := oid from pg_class where relname= tablename and relnamespace =(select oid from " - + "pg_namespace " - + "where\n" - + " nspname=namespace) ;\n" - + " aname:= array_to_string(\n" - + " array(\n" - + " select a.attname from pg_attribute a\n" - + " where a.attrelid=tt and a.attnum in (\n" - + " select unnest(conkey) from pg_constraint c where contype=ctype\n" - + " and conrelid=tt and array_to_string(conkey,',') is not null\n" - + " )\n" - + " ),',');\n" - + "\n" - + " return aname;\n" - + " end\n" - + " $BODY$ LANGUAGE plpgsql"; - - @Override - public String tableDDL(String databaseName, String schemaName, String tableName) { - SQLExecutor.getInstance().executeSql(functionSQL.replaceFirst("tableSchema", schemaName), resultSet -> null); - String ddlSql = "select showcreatetable('" + schemaName + "','" + tableName + "') as sql"; - return SQLExecutor.getInstance().executeSql(ddlSql, resultSet -> { - try { - if (resultSet.next()) { - return resultSet.getString("sql"); - } - } catch (SQLException e) { - throw new RuntimeException(e); - } - return null; - }); - } - -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlBaseModel.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlBaseModel.java deleted file mode 100644 index d48bdd485..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlBaseModel.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.postgresql.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : PostgresqlBaseModel.java, v 0.1 2022年12月11日 15:07 jipengfei Exp $ - */ -@Data -@SuperBuilder -@NoArgsConstructor -public class PostgresqlBaseModel { -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlColumn.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlColumn.java deleted file mode 100644 index 55f841be0..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlColumn.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.postgresql.model; - -import java.io.Serial; -import java.io.Serializable; - -import ai.chat2db.server.domain.support.model.TableColumn; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : PostgresqlColumn.java, v 0.1 2022年12月11日 14:38 jipengfei Exp $ - */ -@Data -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class PostgresqlColumn extends TableColumn implements Serializable { - @Serial - private static final long serialVersionUID = 6895029737377229332L; - private Integer ordinalPosition; - private boolean isArray; - private Integer precision; - private Integer scale; - private String sortRule; - private Integer attinhcount; -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintCheck.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintCheck.java deleted file mode 100644 index 36327a885..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintCheck.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.postgresql.model; - -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : PostgresqlConstraintCheck.java, v 0.1 2022年12月11日 15:24 jipengfei Exp $ - */ -@Data -@SuperBuilder -@NoArgsConstructor -public class PostgresqlConstraintCheck { -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintExclusive.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintExclusive.java deleted file mode 100644 index 8981acbcd..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintExclusive.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.postgresql.model; - -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : dd.java, v 0.1 2022年12月11日 15:19 jipengfei Exp $ - */ -@Data -@SuperBuilder -@NoArgsConstructor -public class PostgresqlConstraintExclusive { -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintExclusiveField.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintExclusiveField.java deleted file mode 100644 index 6ae9b1987..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintExclusiveField.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.postgresql.model; - -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : PostgresqlConstraintExclusiveField.java, v 0.1 2022年12月11日 15:19 jipengfei Exp $ - */ -@Data -@SuperBuilder -@NoArgsConstructor -public class PostgresqlConstraintExclusiveField { -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintForeign.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintForeign.java deleted file mode 100644 index 794ded1fd..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintForeign.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.postgresql.model; - -import java.util.List; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : PostgresqlConstraintForeign.java, v 0.1 2022年12月11日 15:14 jipengfei Exp $ - */ -@Data -@SuperBuilder -@NoArgsConstructor -public class PostgresqlConstraintForeign { -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintForeignReference.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintForeignReference.java deleted file mode 100644 index 5552669e7..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintForeignReference.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.postgresql.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : kk.java, v 0.1 2022年12月11日 15:16 jipengfei Exp $ - */ -@Data -@SuperBuilder -@NoArgsConstructor -public class PostgresqlConstraintForeignReference { -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintUnique.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintUnique.java deleted file mode 100644 index 862d2f0f4..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintUnique.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.postgresql.model; - -import java.util.List; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : PostgresqlConstraintUnique.java, v 0.1 2022年12月11日 15:21 jipengfei Exp $ - */ -@Data -@SuperBuilder -@NoArgsConstructor -public class PostgresqlConstraintUnique { -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintUniqueField.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintUniqueField.java deleted file mode 100644 index 2b401faa7..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlConstraintUniqueField.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.postgresql.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : PostgresqlConstraintUniqueField.java, v 0.1 2022年12月11日 15:22 jipengfei Exp $ - */ -@Data -@SuperBuilder -@NoArgsConstructor -public class PostgresqlConstraintUniqueField { - private String fieldName; -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlForeignServer.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlForeignServer.java deleted file mode 100644 index 2fbbb37ec..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlForeignServer.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.postgresql.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : PostgresqlForeignServer.java, v 0.1 2022年12月11日 16:23 jipengfei Exp $ - */ -@Data -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class PostgresqlForeignServer { - private String serverName; - private String serverCatalog; -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlForeignTable.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlForeignTable.java deleted file mode 100644 index 563bab610..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlForeignTable.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.postgresql.model; - -import java.util.LinkedHashMap; -import java.util.Map; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : PostgresqlForeignTable.java, v 0.1 2022年12月11日 16:19 jipengfei Exp $ - */ -@Data -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class PostgresqlForeignTable extends PostgresqlTable{ - private PostgresqlForeignServer server; - private Map foreignTableOptions = new LinkedHashMap(); -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlInherit.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlInherit.java deleted file mode 100644 index cd912b472..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlInherit.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.postgresql.model; - -import java.util.List; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : ll.java, v 0.1 2022年12月11日 15:26 jipengfei Exp $ - */ -@Data -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class PostgresqlInherit { - private List fullTableNames; -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlPartition.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlPartition.java deleted file mode 100644 index 04cf6817d..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlPartition.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.postgresql.model; - -import java.util.ArrayList; -import java.util.List; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : PostgresqlPartition.java, v 0.1 2022年12月11日 15:31 jipengfei Exp $ - */ -@Data -@SuperBuilder -@NoArgsConstructor -public class PostgresqlPartition { -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlPartitionColumn.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlPartitionColumn.java deleted file mode 100644 index 6db2344c9..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlPartitionColumn.java +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.postgresql.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : PostgresqlPartitionColumn.java, v 0.1 2022年12月11日 17:09 jipengfei Exp $ - */ -@Data -public class PostgresqlPartitionColumn { -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlResemble.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlResemble.java deleted file mode 100644 index 360578c48..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlResemble.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.postgresql.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : PostgresqlResemble.java, v 0.1 2022年12月11日 15:09 jipengfei Exp $ - */ -@Data -@SuperBuilder -@NoArgsConstructor -public class PostgresqlResemble { -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlTable.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlTable.java deleted file mode 100644 index a14563e92..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlTable.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.postgresql.model; - -import ai.chat2db.server.domain.support.model.Table; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : TableVO.java, v 0.1 2022年12月11日 14:34 jipengfei Exp $ - */ -@Data -@SuperBuilder -@NoArgsConstructor -public class PostgresqlTable extends Table { - - public boolean isForeignTable(){ - return false; - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlTableIndex.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlTableIndex.java deleted file mode 100644 index 5783e7a6a..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlTableIndex.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.postgresql.model; - -import java.util.List; - -import ai.chat2db.server.domain.support.model.TableIndex; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : PostgresqlTableIndex.java, v 0.1 2022年12月11日 15:27 jipengfei Exp $ - */ -@Data -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class PostgresqlTableIndex extends TableIndex { - private String tableSchemaName; - private long oid; - private String accessMethod; - private String tableSpace; - private int fillRate; - private boolean unique; - private boolean cluster; - private boolean parallelBuild; - private String constraint; - private int fieldCount; - private List fields; -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlTableIndexField.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlTableIndexField.java deleted file mode 100644 index a33dfc84b..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/postgresql/model/PostgresqlTableIndexField.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Alipay.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.postgresql.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : PostgresqlTableIndexField.java, v 0.1 2022年12月11日 15:37 jipengfei Exp $ - */ -@Data -@SuperBuilder -@NoArgsConstructor -public class PostgresqlTableIndexField { -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/presto/PrestoMetaSchemaSupport.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/presto/PrestoMetaSchemaSupport.java deleted file mode 100644 index 45a716dda..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/presto/PrestoMetaSchemaSupport.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.presto; - - -import ai.chat2db.server.domain.support.dialect.BaseMetaSchema; -import ai.chat2db.server.domain.support.dialect.MetaSchema; -import ai.chat2db.server.domain.support.enums.DbTypeEnum; -import jakarta.validation.constraints.NotEmpty; - -/** - * @author jipengfei - * @version : PrestoMetaSchemaSupport.java - */ -public class PrestoMetaSchemaSupport extends BaseMetaSchema implements MetaSchema { - - @Override - public DbTypeEnum dbType() { - return DbTypeEnum.PRESTO; - } - @Override - public String tableDDL(@NotEmpty String databaseName, String schemaName, @NotEmpty String tableName) { - return ""; - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/redis/RedisMetaSchemaSupport.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/redis/RedisMetaSchemaSupport.java deleted file mode 100644 index a2276e58d..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/redis/RedisMetaSchemaSupport.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.redis; - -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -import ai.chat2db.server.domain.support.dialect.BaseMetaSchema; -import ai.chat2db.server.domain.support.dialect.MetaSchema; -import ai.chat2db.server.domain.support.enums.DbTypeEnum; -import ai.chat2db.server.domain.support.model.Table; -import ai.chat2db.server.domain.support.sql.SQLExecutor; - -import jakarta.validation.constraints.NotEmpty; -import org.apache.commons.lang3.StringUtils; - -/** - * @author jipengfei - * @version : RedisMetaSchemaSupport.java - */ -public class RedisMetaSchemaSupport extends BaseMetaSchema implements MetaSchema { - - @Override - public DbTypeEnum dbType() { - return DbTypeEnum.REDIS; - } - @Override - public String tableDDL(@NotEmpty String databaseName, String schemaName, @NotEmpty String tableName) { - return ""; - } - - - @Override - public List databases() { - List databases = new ArrayList<>(); - return SQLExecutor.getInstance().executeSql("config get databases", resultSet -> { - try { - if (resultSet.next()) { - Object count = resultSet.getObject(2); - if(StringUtils.isNotBlank(count.toString())) { - for (int i = 0; i < Integer.parseInt(count.toString()); i++) { - databases.add(String.valueOf(i)); - } - } - } - } catch (SQLException e) { - throw new RuntimeException(e); - } - return databases; - }); - } - - @Override - public List
tables(String databaseName, String schemaName, String tableName) { - return SQLExecutor.getInstance().executeSql("scan 0 MATCH * COUNT 1000", resultSet -> { - List
tables = new ArrayList<>(); - try { - while (resultSet.next()) { - ArrayList list = (ArrayList)resultSet.getObject(2); - for (Object object : list) { - Table table = new Table(); - table.setName(object.toString()); - tables.add(table); - } - } - } catch (SQLException e) { - throw new RuntimeException(e); - } - return tables; - }); - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/sqlite/SQLiteMetaSchemaSupport.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/sqlite/SQLiteMetaSchemaSupport.java deleted file mode 100644 index ea50b0b36..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/sqlite/SQLiteMetaSchemaSupport.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.sqlite; - -import java.sql.SQLException; -import java.util.List; - -import ai.chat2db.server.domain.support.dialect.BaseMetaSchema; -import ai.chat2db.server.domain.support.dialect.MetaSchema; -import ai.chat2db.server.domain.support.enums.DbTypeEnum; -import ai.chat2db.server.domain.support.sql.SQLExecutor; - -import com.google.common.collect.Lists; -import lombok.extern.slf4j.Slf4j; - -/** - * @author jipengfei - * @version : SqlserverMetaSchemaSupport.java - */ -@Slf4j -public class SQLiteMetaSchemaSupport extends BaseMetaSchema implements MetaSchema { - - @Override - public DbTypeEnum dbType() { - return DbTypeEnum.SQLITE; - } - - @Override - public String tableDDL(String databaseName, String schemaName, String tableName) { - String sql = "SELECT sql FROM sqlite_master WHERE type='table' AND name='" + tableName + "'"; - return SQLExecutor.getInstance().executeSql(sql, resultSet -> { - try { - if (resultSet.next()) { - return resultSet.getString("sql"); - } - } catch (SQLException e) { - throw new RuntimeException(e); - } - return null; - }); - } - @Override - public List databases() { - return Lists.newArrayList("main"); - } - - @Override - public List schemas(String databaseName) { - return Lists.newArrayList(); - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/sqlserver/SqlServerMetaSchemaSupport.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/sqlserver/SqlServerMetaSchemaSupport.java deleted file mode 100644 index 1f3f99d20..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/dialect/sqlserver/SqlServerMetaSchemaSupport.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.dialect.sqlserver; - -import java.sql.SQLException; - -import ai.chat2db.server.domain.support.dialect.BaseMetaSchema; -import ai.chat2db.server.domain.support.dialect.MetaSchema; -import ai.chat2db.server.domain.support.enums.DbTypeEnum; -import ai.chat2db.server.domain.support.sql.SQLExecutor; - -import lombok.extern.slf4j.Slf4j; - -/** - * @author jipengfei - * @version : SqlserverMetaSchemaSupport.java - */ -@Slf4j -public class SqlServerMetaSchemaSupport extends BaseMetaSchema implements MetaSchema { - - private String functionSQL - = "CREATE FUNCTION tableSchema.ufn_GetCreateTableScript( @schema_name NVARCHAR(128), @table_name NVARCHAR" - + "(128)) RETURNS NVARCHAR(MAX) AS BEGIN DECLARE @CreateTableScript NVARCHAR(MAX); DECLARE @IndexScripts " - + "NVARCHAR(MAX) = ''; DECLARE @ColumnDescriptions NVARCHAR(MAX) = N''; SELECT @CreateTableScript = CONCAT( " - + "'CREATE TABLE [', s.name, '].[' , t.name, '] (', STUFF( ( SELECT ', [' + c.name + '] ' + tp.name + CASE " - + "WHEN tp.name IN ('varchar', 'nvarchar', 'char', 'nchar') THEN '(' + IIF(c.max_length = -1, 'MAX', CAST(c" - + ".max_length AS NVARCHAR(10))) + ')' WHEN tp.name IN ('decimal', 'numeric') THEN '(' + CAST(c.precision AS " - + "NVARCHAR(10)) + ', ' + CAST(c.scale AS NVARCHAR(10)) + ')' ELSE '' END + ' ' + CASE WHEN c.is_nullable = 1" - + " THEN 'NULL' ELSE 'NOT NULL' END FROM sys.columns c JOIN sys.types tp ON c.user_type_id = tp.user_type_id " - + "WHERE c.object_id = t.object_id FOR XML PATH(''), TYPE ).value('/', 'nvarchar(max)'), 1, 1, ''), ');' ) " - + "FROM sys.tables t JOIN sys.schemas s ON t.schema_id = s.schema_id WHERE t.name = @table_name AND s.name = " - + "@schema_name; SELECT @IndexScripts = @IndexScripts + 'CREATE ' + CASE WHEN i.is_unique = 1 THEN 'UNIQUE ' " - + "ELSE '' END + i.type_desc + ' INDEX [' + i.name + '] ON [' + s.name + '].[' + t.name + '] (' + STUFF( ( " - + "SELECT ', [' + c.name + ']' + CASE WHEN ic.is_descending_key = 1 THEN ' DESC' ELSE ' ASC' END FROM sys" - + ".index_columns ic JOIN sys.columns c ON ic.object_id = c.object_id AND ic.column_id = c.column_id WHERE ic" - + ".object_id = i.object_id AND ic.index_id = i.index_id ORDER BY ic.key_ordinal FOR XML PATH('') ), 1, 1, " - + "'') + ')' + CASE WHEN i.has_filter = 1 THEN ' WHERE ' + i.filter_definition ELSE '' END + ';' + CHAR(13) +" - + " CHAR(10) FROM sys.indexes i JOIN sys.tables t ON i.object_id = t.object_id JOIN sys.schemas s ON t" - + ".schema_id = s.schema_id WHERE i.type > 0 AND t.name = @table_name AND s.name " - + "= @schema_name; SELECT @ColumnDescriptions += 'EXEC sp_addextendedproperty @name=N''MS_Description'', " - + "@value=N''' + CAST(p.value AS NVARCHAR(MAX)) + ''', @level0type=N''SCHEMA'', @level0name=N''' + " - + "@schema_name + ''', @level1type=N''TABLE'', @level1name=N''' + @table_name + ''', @level2type=N''COLUMN''," - + " @level2name=N''' + c.name + ''';' + CHAR(13) + CHAR(10) FROM sys.extended_properties p JOIN sys.columns c" - + " ON p.major_id = c.object_id AND p.minor_id = c.column_id JOIN sys.tables t ON c.object_id = t.object_id " - + "JOIN sys.schemas s ON t.schema_id = s.schema_id WHERE p.class = 1 AND t.name = @table_name AND s.name = " - + "@schema_name; SET @CreateTableScript = @CreateTableScript + CHAR(13) + CHAR(10) + @IndexScripts + CHAR(13)" - + " + CHAR(10)+ @ColumnDescriptions+ CHAR(10); RETURN @CreateTableScript; END"; - - @Override - public DbTypeEnum dbType() { - return DbTypeEnum.SQLSERVER; - } - - @Override - public String tableDDL(String databaseName, String schemaName, String tableName) { - try { - System.out.println(functionSQL); - SQLExecutor.getInstance().executeSql(functionSQL.replace("tableSchema", schemaName), resultSet -> null); - } catch (Exception e) { - //log.error("创建函数失败", e); - } - - String ddlSql = "SELECT " + schemaName + ".ufn_GetCreateTableScript('" + schemaName + "', '" + tableName - + "') AS sql"; - return SQLExecutor.getInstance().executeSql(ddlSql, resultSet -> { - try { - if (resultSet.next()) { - return resultSet.getString("sql"); - } - } catch (SQLException e) { - throw new RuntimeException(e); - } - return null; - }); - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/CellTypeEnum.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/CellTypeEnum.java deleted file mode 100644 index 50b1ed684..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/CellTypeEnum.java +++ /dev/null @@ -1,50 +0,0 @@ -package ai.chat2db.server.domain.support.enums; - -import ai.chat2db.server.tools.base.enums.BaseEnum; - -import lombok.Getter; - -/** - * 驱动类枚举 - * - * @author Jiaju Zhuang - */ -@Getter -public enum CellTypeEnum implements BaseEnum { - /** - * 字符串 - */ - STRING("字符串"), - - /** - * 数字 - */ - BIG_DECIMAL("数字"), - - /** - * 日期 - */ - DATE("日期"), - - /** - * 二进制流 - */ - BYTE("二进制流"), - - /** - * 空数据 - */ - EMPTY("空数据"), - ; - - final String description; - - CellTypeEnum(String description) { - this.description = description; - } - - @Override - public String getCode() { - return this.name(); - } -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/CollationEnum.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/CollationEnum.java deleted file mode 100644 index 422797e9f..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/CollationEnum.java +++ /dev/null @@ -1,55 +0,0 @@ -package ai.chat2db.server.domain.support.enums; - -import ai.chat2db.server.tools.base.enums.BaseEnum; -import ai.chat2db.server.tools.common.util.EasyEnumUtils; -import com.alibaba.druid.sql.ast.SQLOrderingSpecification; - -import lombok.Getter; - -/** - * 排序枚举 - * - * @author Jiaju Zhuang - */ -@Getter -public enum CollationEnum implements BaseEnum { - /** - * ASC - */ - ASC("asc", SQLOrderingSpecification.ASC), - - /** - * DESC - */ - DESC("desc", SQLOrderingSpecification.DESC), - - ; - - final String description; - - final SQLOrderingSpecification sqlOrderingSpecification; - - CollationEnum(String description, SQLOrderingSpecification sqlOrderingSpecification) { - this.description = description; - this.sqlOrderingSpecification = sqlOrderingSpecification; - } - - @Override - public String getCode() { - return this.name(); - } - - public static boolean equals(String collation1, String collation2) { - return equals(EasyEnumUtils.getEnum(CollationEnum.class, collation1), - EasyEnumUtils.getEnum(CollationEnum.class, collation2)); - } - - public static boolean equals(CollationEnum collation1, CollationEnum collation2) { - // 想同直接返回 - if (collation1 == collation2) { - return true; - } - // 有一个是倒序 就是不相同 ,其他都是相同 - return !(collation1 == CollationEnum.DESC || collation2 == CollationEnum.DESC); - } -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/ColumnTypeEnum.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/ColumnTypeEnum.java deleted file mode 100644 index 0b442b2df..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/ColumnTypeEnum.java +++ /dev/null @@ -1,50 +0,0 @@ -package ai.chat2db.server.domain.support.enums; - -import ai.chat2db.server.tools.base.enums.BaseEnum; - -import lombok.Getter; - -/** - * 列的类型 - * - * @author Jiaju Zhuang - */ -@Getter -public enum ColumnTypeEnum implements BaseEnum { - /** - * BIGINT - */ - BIGINT, - - /** - * VARCHAR - */ - VARCHAR, - - /** - * TIMESTAMP - */ - TIMESTAMP, - - /** - * DATETIME - */ - DATETIME, - - /** - * INTEGER - */ - INTEGER, - - ; - - @Override - public String getCode() { - return this.name(); - } - - @Override - public String getDescription() { - return this.name(); - } -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/DataTypeEnum.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/DataTypeEnum.java deleted file mode 100644 index cb487c777..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/DataTypeEnum.java +++ /dev/null @@ -1,99 +0,0 @@ -package ai.chat2db.server.domain.support.enums; - -import ai.chat2db.server.tools.base.enums.BaseEnum; -import lombok.Getter; - -/** - * 驱动类枚举 - * - * @author Jiaju Zhuang - */ -@Getter -public enum DataTypeEnum implements BaseEnum { - /** - * 布尔值 - */ - BOOLEAN("布尔值"), - - /** - * 数字 - */ - NUMERIC("数字"), - - /** - * 字符串 - */ - STRING("字符串"), - - /** - * 日期 - */ - DATETIME("日期"), - - /** - * 二进制 - */ - BINARY("空数据"), - - /** - * 内容 - */ - CONTENT("内容"), - - /** - * 结构 - */ - STRUCT("结构"), - - /** - * 文档 - */ - DOCUMENT("文档"), - - /** - * 数组 - */ - ARRAY("数组"), - - - /** - * 对象 - */ - OBJECT("对象"), - - - /** - * 引用 - */ - REFERENCE("引用"), - - - /** - * 行号 - */ - ROWID("行号"), - - - /** - * 任何 - */ - ANY("任何"), - - - /** - * 未知 - */ - UNKNOWN("未知"), - ; - - final String description; - - DataTypeEnum(String description) { - this.description = description; - } - - @Override - public String getCode() { - return this.name(); - } -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/DbTypeEnum.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/DbTypeEnum.java deleted file mode 100644 index 58fa40869..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/DbTypeEnum.java +++ /dev/null @@ -1,239 +0,0 @@ -package ai.chat2db.server.domain.support.enums; - -import java.util.HashMap; -import java.util.Map; - -import ai.chat2db.server.domain.support.dialect.MetaSchema; -import ai.chat2db.server.domain.support.dialect.clickhouse.ClickhouseMetaSchemaSupport; -import ai.chat2db.server.domain.support.dialect.common.model.SpiExample; -import ai.chat2db.server.domain.support.dialect.db2.DB2MetaSchemaSupport; -import ai.chat2db.server.domain.support.dialect.dm.DMMetaSchemaSupport; -import ai.chat2db.server.domain.support.dialect.h2.H2MetaSchemaSupport; -import ai.chat2db.server.domain.support.dialect.hive.HiveMetaSchemaSupport; -import ai.chat2db.server.domain.support.dialect.kingbase.KingBaseSchemaSupport; -import ai.chat2db.server.domain.support.dialect.mariadb.MariaDBMetaSchemaSupport; -import ai.chat2db.server.domain.support.dialect.mongodb.MongodbMetaSchemaSupport; -import ai.chat2db.server.domain.support.dialect.mysql.MysqlMetaSchemaSupport; -import ai.chat2db.server.domain.support.dialect.oceanbase.OceanBaseMetaSchemaSupport; -import ai.chat2db.server.domain.support.dialect.oracle.OracleMetaSchemaSupport; -import ai.chat2db.server.domain.support.dialect.postgresql.PostgresqlMetaSchemaSupport; -import ai.chat2db.server.domain.support.dialect.presto.PrestoMetaSchemaSupport; -import ai.chat2db.server.domain.support.dialect.redis.RedisMetaSchemaSupport; -import ai.chat2db.server.domain.support.dialect.sqlite.SQLiteMetaSchemaSupport; -import ai.chat2db.server.domain.support.dialect.sqlserver.SqlServerMetaSchemaSupport; -import ai.chat2db.server.tools.base.enums.BaseEnum; - -import lombok.Getter; - -import static ai.chat2db.server.domain.support.dialect.common.SQLKeyConst.H2_ALTER_TABLE_SIMPLE; -import static ai.chat2db.server.domain.support.dialect.common.SQLKeyConst.H2_CREATE_TABLE_SIMPLE; -import static ai.chat2db.server.domain.support.dialect.common.SQLKeyConst.MYSQL_ALTER_TABLE_SIMPLE; -import static ai.chat2db.server.domain.support.dialect.common.SQLKeyConst.MYSQL_CREATE_TABLE_SIMPLE; -import static ai.chat2db.server.domain.support.dialect.common.SQLKeyConst.ORACLE_ALTER_TABLE_SIMPLE; -import static ai.chat2db.server.domain.support.dialect.common.SQLKeyConst.ORACLE_CREATE_TABLE_SIMPLE; -import static ai.chat2db.server.domain.support.dialect.common.SQLKeyConst.PG_ALTER_TABLE_SIMPLE; -import static ai.chat2db.server.domain.support.dialect.common.SQLKeyConst.PG_CREATE_TABLE_SIMPLE; -import static ai.chat2db.server.domain.support.dialect.common.SQLKeyConst.SQLITE_ALTER_TABLE_SIMPLE; -import static ai.chat2db.server.domain.support.dialect.common.SQLKeyConst.SQLITE_CREATE_TABLE_SIMPLE; - -/** - * 数据类型 - * - * @author Jiaju Zhuang - */ -@Getter -public enum DbTypeEnum implements BaseEnum { - /** - * MySQL - */ - MYSQL("MySQL"), - - /** - * PostgreSQL - */ - POSTGRESQL("PostgreSQL"), - - /** - * Oracle - */ - ORACLE("Oracle"), - - /** - * SQLServer - */ - SQLSERVER("SQLServer"), - - /** - * SQLite - */ - SQLITE("SQLite"), - - /** - * H2 - */ - H2("H2"), - - /** - * ADB MySQL - */ - ADB_POSTGRESQL("PostgreSQL"), - - /** - * ClickHouse - */ - CLICKHOUSE("ClickHouse"), - - /** - * OceanBase - */ - OCEANBASE("OceanBase"), - - /** - * DB2 - */ - DB2("DB2"), - - /** - * MMARIADB - */ - MARIADB("MariaDB"), - - /** - * DM 达梦 - */ - DM("DM"), - - - /** - * MONGODB - */ - MONGODB("Mongodb"), - - /** - * PRESTO - */ - PRESTO("Presto"), - - /** - * HIVE - */ - HIVE("Hive"), - - - /** - * REDIS - */ - REDIS("Redis"), - - /** - * KingBase - */ - KINGBASE("KingBase"); - - final String description; - - private static Map META_SCHEMA_MAP = new HashMap<>(); - - static { - META_SCHEMA_MAP.put(H2, new H2MetaSchemaSupport()); - META_SCHEMA_MAP.put(MYSQL, new MysqlMetaSchemaSupport()); - META_SCHEMA_MAP.put(POSTGRESQL, new PostgresqlMetaSchemaSupport()); - META_SCHEMA_MAP.put(ORACLE, new OracleMetaSchemaSupport()); - META_SCHEMA_MAP.put(SQLSERVER, new SqlServerMetaSchemaSupport()); - META_SCHEMA_MAP.put(SQLITE, new SQLiteMetaSchemaSupport()); - META_SCHEMA_MAP.put(OCEANBASE, new OceanBaseMetaSchemaSupport()); - META_SCHEMA_MAP.put(MARIADB, new MariaDBMetaSchemaSupport()); - META_SCHEMA_MAP.put(CLICKHOUSE, new ClickhouseMetaSchemaSupport()); - META_SCHEMA_MAP.put(DB2, new DB2MetaSchemaSupport()); - META_SCHEMA_MAP.put(DM, new DMMetaSchemaSupport()); - META_SCHEMA_MAP.put(MONGODB, new MongodbMetaSchemaSupport()); - META_SCHEMA_MAP.put(PRESTO, new PrestoMetaSchemaSupport()); - META_SCHEMA_MAP.put(REDIS, new RedisMetaSchemaSupport()); - META_SCHEMA_MAP.put(KINGBASE, new KingBaseSchemaSupport()); - META_SCHEMA_MAP.put(HIVE, new HiveMetaSchemaSupport()); - } - - DbTypeEnum(String description) { - this.description = description; - } - - /** - * 通过名称获取枚举 - * - * @param name - * @return - */ - public static DbTypeEnum getByName(String name) { - for (DbTypeEnum dbTypeEnum : DbTypeEnum.values()) { - if (dbTypeEnum.name().equals(name)) { - return dbTypeEnum; - } - } - return null; - } - - @Override - public String getCode() { - return this.name(); - } - - public MetaSchema metaSchema() { - return META_SCHEMA_MAP.get(this); - } - - public SpiExample example() { - SpiExample SpiExample = null; - switch (this) { - case H2: - SpiExample = SpiExample.builder().createTable(H2_CREATE_TABLE_SIMPLE).alterTable(H2_ALTER_TABLE_SIMPLE) - .build(); - break; - case MYSQL: - SpiExample = SpiExample.builder().createTable(MYSQL_CREATE_TABLE_SIMPLE).alterTable( - MYSQL_ALTER_TABLE_SIMPLE).build(); - break; - case POSTGRESQL: - SpiExample = SpiExample.builder().createTable(PG_CREATE_TABLE_SIMPLE).alterTable(PG_ALTER_TABLE_SIMPLE) - .build(); - break; - case ORACLE: - SpiExample = SpiExample.builder().createTable(ORACLE_CREATE_TABLE_SIMPLE).alterTable( - ORACLE_ALTER_TABLE_SIMPLE).build(); - break; - case SQLSERVER: - SpiExample = SpiExample.builder().createTable(ORACLE_CREATE_TABLE_SIMPLE).alterTable( - ORACLE_ALTER_TABLE_SIMPLE).build(); - break; - case SQLITE: - SpiExample = SpiExample.builder().createTable(SQLITE_CREATE_TABLE_SIMPLE).alterTable( - SQLITE_ALTER_TABLE_SIMPLE).build(); - break; - case OCEANBASE: - SpiExample = SpiExample.builder().createTable(MYSQL_CREATE_TABLE_SIMPLE).alterTable( - MYSQL_ALTER_TABLE_SIMPLE).build(); - break; - case CLICKHOUSE: - SpiExample = SpiExample.builder().createTable(MYSQL_CREATE_TABLE_SIMPLE).alterTable( - MYSQL_ALTER_TABLE_SIMPLE).build(); - break; - case MARIADB: - SpiExample = SpiExample.builder().createTable(MYSQL_CREATE_TABLE_SIMPLE).alterTable( - MYSQL_ALTER_TABLE_SIMPLE).build(); - break; - case DB2: - SpiExample = SpiExample.builder().createTable(MYSQL_CREATE_TABLE_SIMPLE).alterTable( - MYSQL_ALTER_TABLE_SIMPLE).build(); - break; - case DM: - SpiExample = SpiExample.builder().createTable(MYSQL_CREATE_TABLE_SIMPLE).alterTable( - MYSQL_ALTER_TABLE_SIMPLE).build(); - break; - case PRESTO: - SpiExample = SpiExample.builder().createTable("").alterTable("").build(); - break; - default: - } - return SpiExample; - } - -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/DriverTypeEnum.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/DriverTypeEnum.java deleted file mode 100644 index 26d14e12a..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/DriverTypeEnum.java +++ /dev/null @@ -1,163 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.enums; - -import org.apache.commons.lang3.StringUtils; - -/** - * @author jipengfei - * @version : DriverTypeEnum.java - */ -public enum DriverTypeEnum { - /** - * MySQL - */ - MYSQL_DRIVER(DbTypeEnum.MYSQL, "com.mysql.cj.jdbc.Driver", "mysql-connector-java-8.0.30.jar","8.0"), - - /** - * MySQL 5.1版本 - */ - MYSQL_DRIVER_5_1(DbTypeEnum.MYSQL, "com.mysql.jdbc.Driver", "mysql-connector-java-5.1.47.jar","5.0"), - - /** - * PostgreSQL - */ - POSTGRESQL_DRIVER(DbTypeEnum.POSTGRESQL, "org.postgresql.Driver", "postgresql-42.5.1.jar",""), - - /** - * Oracle - */ - ORACLE_DRIVER(DbTypeEnum.ORACLE, "oracle.jdbc.driver.OracleDriver", "ojdbc8-19.3.0.0.jar,orai18n-19.3.0.0.jar",""), - - /** - * SQLServer - */ - SQLSERVER_DRIVER(DbTypeEnum.SQLSERVER, "com.microsoft.sqlserver.jdbc.SQLServerDriver", - "mssql-jdbc-11.2.1.jre17.jar",""), - - /** - * SQLite - */ - SQLITE_DRIVER(DbTypeEnum.SQLITE, "org.sqlite.JDBC", "sqlite-jdbc-3.39.3.0.jar",""), - - /** - * H2 - */ - H2_DRIVER(DbTypeEnum.H2, "org.h2.Driver", "h2-2.1.214.jar",""), - - /** - * ADB MySQL - */ - ADB_POSTGRESQL_DRIVER(DbTypeEnum.ADB_POSTGRESQL, "org.postgresql.Driver", "",""), - - /** - * ClickHouse - */ - CLICKHOUSE_DRIVER(DbTypeEnum.CLICKHOUSE, "com.clickhouse.jdbc.ClickHouseDriver", "clickhouse-jdbc-0.3.2-patch8-http.jar",""), - - /** - * OceanBase - */ - OCEANBASE_DRIVER(DbTypeEnum.OCEANBASE, "com.oceanbase.jdbc.Driver", "oceanbase-client-2.4.2.jar",""), - - /** - * DB2 - */ - DB2_DRIVER(DbTypeEnum.DB2, "com.ibm.db2.jcc.DB2Driver", "db2jcc4_4.26.14.jar",""), - - /** - * MMARIADB - */ - MARIADB_DRIVER(DbTypeEnum.MARIADB, "org.mariadb.jdbc.Driver", "mariadb-java-client-3.0.8.jar",""), - - - - /** - * DM_DRIVER - */ - DM_DRIVER(DbTypeEnum.DM, "dm.jdbc.driver.DmDriver", "DmJdbcDriver18-8.1.2.141.jar",""), - - - /** - * PRESTO_DRIVER - */ - PRESTO_DRIVER(DbTypeEnum.PRESTO, "com.facebook.presto.jdbc.PrestoDriver", "presto-jdbc-0.245.1.jar",""), - - /** - * KINGBASE_DRIVER - * com.kingbase8.Driver - */ - KINGBASE_DRIVER(DbTypeEnum.KINGBASE, "com.kingbase8.Driver", "kingbase8-8.6.0.jar",""), - - /** - * HIVE_DRIVER - * org.apache.hive.jdbc.HiveDriver - */ - HIVE_DRIVER(DbTypeEnum.HIVE, "org.apache.hive.jdbc.HiveDriver", "hive-jdbc-3.1.2-standalone.jar",""), - - /** - * REDIS_DRIVER - */ - REDIS_DRIVER(DbTypeEnum.REDIS, "jdbc.RedisDriver", "redis-jdbc-driver-1.3.jar",""), - /** - * MONGODB_DRIVER - * com.dbschema.MongoJdbcDriver - */ - MONGODB_DRIVER(DbTypeEnum.MONGODB, "com.dbschema.MongoJdbcDriver", "mongo-jdbc-standalone-1.18.jar",""); - - final DbTypeEnum dbTypeEnum; - - final String driverClass; - - final String jar; - - final String jdbc; - - DriverTypeEnum(DbTypeEnum dbTypeEnum, String driverClass, String jar, String jdbc) { - this.dbTypeEnum = dbTypeEnum; - this.driverClass = driverClass; - this.jar = jar; - this.jdbc = jdbc; - } - - public static DriverTypeEnum getDriver(DbTypeEnum dbTypeEnum, String jdbc) { - for (DriverTypeEnum driverTypeEnum : DriverTypeEnum.values()) { - if (driverTypeEnum.dbTypeEnum.equals(dbTypeEnum)) { - if (StringUtils.isBlank(jdbc) || driverTypeEnum.jdbc.equals(jdbc)) { - return driverTypeEnum; - } - } - } - return null; - } - - /** - * Getter method for property dbTypeEnum. - * - * @return property value of dbTypeEnum - */ - public DbTypeEnum getDbTypeEnum() { - return dbTypeEnum; - } - - /** - * Getter method for property jar. - * - * @return property value of jar - */ - public String getJar() { - return jar; - } - - /** - * Getter method for property driverClass. - * - * @return property value of driverClass - */ - public String getDriverClass() { - return driverClass; - } - -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/IndexTypeEnum.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/IndexTypeEnum.java deleted file mode 100644 index 2bef949d2..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/IndexTypeEnum.java +++ /dev/null @@ -1,40 +0,0 @@ -package ai.chat2db.server.domain.support.enums; - -import ai.chat2db.server.tools.base.enums.BaseEnum; - -import lombok.Getter; - -/** - * 索引类型 - * - * @author Jiaju Zhuang - */ -@Getter -public enum IndexTypeEnum implements BaseEnum { - /** - * 主键 - */ - PRIMARY_KEY("主键"), - - /** - * 普通索引 - */ - NORMAL("普通索引"), - - /** - * 唯一索引 - */ - UNIQUE("唯一索引"), - ; - - final String description; - - IndexTypeEnum(String description) { - this.description = description; - } - - @Override - public String getCode() { - return this.name(); - } -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/SqlTypeEnum.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/SqlTypeEnum.java deleted file mode 100644 index 0b3022bb5..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/enums/SqlTypeEnum.java +++ /dev/null @@ -1,36 +0,0 @@ -package ai.chat2db.server.domain.support.enums; - -import ai.chat2db.server.tools.base.enums.BaseEnum; - -import lombok.Getter; - -/** - * sq类型 - * - * @author Jiaju Zhuang - */ -@Getter -public enum SqlTypeEnum implements BaseEnum { - /** - * 查询语句 - */ - SELECT("查询语句"), - - /** - * 未知 - */ - UNKNOWN("未知"), - - ; - - final String description; - - SqlTypeEnum(String description) { - this.description = description; - } - - @Override - public String getCode() { - return this.name(); - } -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Cell.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Cell.java deleted file mode 100644 index 58b7ac650..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Cell.java +++ /dev/null @@ -1,49 +0,0 @@ -package ai.chat2db.server.domain.support.model; - -import java.math.BigDecimal; - -import ai.chat2db.server.domain.support.enums.CellTypeEnum; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * 单元格类型 - * - * @author Jiaju Zhuang - */ -@Data -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class Cell { - - /** - * 单元格类型 - * - * @see CellTypeEnum - */ - private String type; - - /** - * 字符串数据 - */ - private String stringValue; - - /** - * 数字 - */ - private BigDecimal bigDecimalValue; - - /** - * 日期数据 - */ - private Long dateValue; - - /** - * 二进制流 - */ - private byte[] byteValue; -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/CreateTableSql.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/CreateTableSql.java deleted file mode 100644 index 842da93e6..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/CreateTableSql.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : CreateTableSql.java - */ -@Data -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class CreateTableSql { - - public String tableName; - - public String sql; -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/DataSourceConnect.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/DataSourceConnect.java deleted file mode 100644 index 5e320f481..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/DataSourceConnect.java +++ /dev/null @@ -1,34 +0,0 @@ -package ai.chat2db.server.domain.support.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * 数据库连接对象 - * - * @author Jiaju Zhuang - */ -@Data -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class DataSourceConnect { - - /** - * 是否成功标志位 - */ - private Boolean success; - - /** - * 失败消息提示 - * 只有失败的情况下会有 - */ - private String message; - - /** - * 描述 - */ - private String description; -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Database.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Database.java deleted file mode 100644 index 9c8778dcc..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Database.java +++ /dev/null @@ -1,22 +0,0 @@ -package ai.chat2db.server.domain.support.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * 数据库 - * - * @author Jiaju Zhuang - */ -@Data -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class Database { - /** - * 数据名字 - */ - private String name; -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/DriverEntry.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/DriverEntry.java deleted file mode 100644 index 3ba6cfcf5..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/DriverEntry.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.model; - -import java.sql.Driver; - -import ai.chat2db.server.domain.support.enums.DbTypeEnum; -import ai.chat2db.server.domain.support.enums.DriverTypeEnum; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : DriverEntry.java - */ -@Data -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class DriverEntry { - - private DriverTypeEnum driverTypeEnum; - - private Driver driver; - -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/ExecuteResult.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/ExecuteResult.java deleted file mode 100644 index 8181c487b..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/ExecuteResult.java +++ /dev/null @@ -1,88 +0,0 @@ -package ai.chat2db.server.domain.support.model; - -import java.util.List; - -import ai.chat2db.server.domain.support.enums.SqlTypeEnum; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * 执行结果 - * - * @author Jiaju Zhuang - */ -@Data -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class ExecuteResult { - - /** - * 是否成功标志位 - */ - private Boolean success; - - /** - * 失败消息提示 - * 只有失败的情况下会有 - */ - private String message; - - /** - * 执行的sql - */ - private String sql; - - /** - * 描述 - */ - private String description; - - /** - * 修改行数 查询sql不会返回 - */ - private Integer updateCount; - - /** - * 展示头的列表 - */ - private List
headerList; - - /** - * 数据的列表 - */ - private List> dataList; - - /** - * sql 类型 - * - * @see SqlTypeEnum - */ - private String sqlType; - - /** - * 是否存在下一页 - * 只有select语句才有 - */ - private Boolean hasNextPage; - - /** - * 分页编码 - * 只有select语句才有 - */ - private Integer pageNo; - - /** - * 分页大小 - * 只有select语句才有 - */ - private Integer pageSize; - - /** - * 执行持续时间 - */ - private Long duration; -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Function.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Function.java deleted file mode 100644 index f6537d1b2..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Function.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : Function.java - */ -@Data -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class Function { - //FUNCTION_CAT String => function catalog (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: - //functionResultUnknown - Cannot determine if a return value or table will be returned - //functionNoTable- Does not return a table - //functionReturnsTable - Returns a table - //SPECIFIC_NAME String => the name which uniquely identifies this function within its schema. This is a user specified, or DBMS generated, name that may be different then the FUNCTION_NAME for example with overload functions - // - - private String databaseName; - - private String schemaName; - - private String functionName; - - private String remarks; - - private Short functionType; - - private String specificName; -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Header.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Header.java deleted file mode 100644 index 07ba7a74e..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Header.java +++ /dev/null @@ -1,30 +0,0 @@ -package ai.chat2db.server.domain.support.model; - -import ai.chat2db.server.domain.support.enums.DataTypeEnum; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * 单元格头 - * - * @author Jiaju Zhuang - */ -@Data -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class Header { - /** - * 单元格类型 - * - * @see DataTypeEnum - */ - private String dataType; - - /** - * 展示的名字 - */ - private String name; -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/KeyValue.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/KeyValue.java deleted file mode 100644 index fba54da70..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/KeyValue.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.model; - -import java.util.List; -import java.util.Map; - -import com.google.common.collect.Maps; -import lombok.Data; -import org.apache.commons.collections4.CollectionUtils; - -/** - * @author jipengfei - * @version : KeyValue.java - */ -@Data -public class KeyValue { - /** - * 属性名 - */ - private String key; - - /** - * 属性值 - */ - private Object value; - - public static Map toMap(List keyValues) { - if (CollectionUtils.isEmpty(keyValues)) { - return Maps.newHashMap(); - } else { - Map map = Maps.newHashMap(); - keyValues.forEach(keyValue -> map.put(keyValue.getKey(), String.valueOf(keyValue.getValue()))); - return map; - } - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Procedure.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Procedure.java deleted file mode 100644 index f676d6d29..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Procedure.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : Procedure.java - */ -@Data -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class Procedure { - //PROCEDURE_CAT String => procedure catalog (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: - //procedureResultUnknown - Cannot determine if a return value will be returned - //procedureNoResult - Does not return a return value - //procedureReturnsResult - Returns a return value - //SPECIFIC_NAME String => the name which uniquely identifies this procedure within its schema. This is a user specified, or DBMS generated, name that may be different then the PROCEDURE_NAME for example with overload procedures - // - - private String databaseName; - - private String schemaName; - - private String procedureName; - - private String remarks; - - private Short procedureType; - - private String specificName; -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/SSHInfo.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/SSHInfo.java deleted file mode 100644 index 6750c8abe..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/SSHInfo.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.model; - -import lombok.Data; - -/** - * @author jipengfei - * @version : SSHInfo.java - */ -@Data -public class SSHInfo { - - /** - * 是否使用ssh - */ - private boolean use; - - /** - * ssh主机名 - */ - private String hostName; - - /** - * ssh端口 - */ - private String port; - - /** - * ssh用户名 - */ - private String userName; - - /** - * ssh本地端口 - */ - private String localPort; - - /** - * ssh认证类型 - */ - private String authenticationType; - - /** - * ssh密码 - */ - private String password; - - /** - * ssh密钥文件 - */ - private String keyFile; - - /** - * ssh密钥文件密码 - */ - private String passphrase; - - /** - * ssh跳板机目标主机 - */ - private String rHost; - - /** - * ssh跳板目标端口 - */ - private String rPort; - -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/SSLInfo.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/SSLInfo.java deleted file mode 100644 index 0a2f88029..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/SSLInfo.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.model; - -/** - * @author jipengfei - * @version : SSLInfo.java - */ -public class SSLInfo { -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Schema.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Schema.java deleted file mode 100644 index eadccf52e..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Schema.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : TableSchema.java - */ -@Data -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class Schema { - /** - * 数据名字 - */ - private String name; -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/ShowDatabaseResult.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/ShowDatabaseResult.java deleted file mode 100644 index e4687c112..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/ShowDatabaseResult.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * @author jipengfei - * @version : ShowDatabaseResult.java - */ -@Data -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class ShowDatabaseResult { - String database; -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Sql.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Sql.java deleted file mode 100644 index 668d9d22a..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Sql.java +++ /dev/null @@ -1,24 +0,0 @@ -package ai.chat2db.server.domain.support.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * sql对象 - * - * @author Jiaju Zhuang - */ -@Data -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class Sql { - - /** - * sql - */ - private String sql; - -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Table.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Table.java deleted file mode 100644 index f2891225c..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Table.java +++ /dev/null @@ -1,65 +0,0 @@ -package ai.chat2db.server.domain.support.model; - -import java.util.List; - -import ai.chat2db.server.domain.support.enums.DbTypeEnum; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * 表信息 - * - * @author Jiaju Zhuang - */ -@Data -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class Table { - - /** - * 表名 - */ - private String name; - - /** - * 描述 - */ - private String comment; - - /** - * DB 名 - */ - private String schemaName; - - /** - * 列列表 - */ - private List columnList; - - /** - * 索引列表 - */ - private List indexList; - - /** - * DB类型 - */ - private DbTypeEnum dbType; - - /** - * 数据库名 - */ - private String databaseName; - - /** - * 表类型 - */ - private String type; - - -} - diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/TableColumn.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/TableColumn.java deleted file mode 100644 index a306ea662..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/TableColumn.java +++ /dev/null @@ -1,145 +0,0 @@ -package ai.chat2db.server.domain.support.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * 列信息 - * - * @author Jiaju Zhuang - */ -@Data -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class TableColumn { - /** - * 旧的列名,在修改列的时候需要这个参数 - * 在返回的时候oldName=name - */ - private String oldName; - - /** - * 列名 - */ - private String name; - - /** - * 表名 - */ - private String tableName; - - /** - * 列的类型 - * 比如 varchar(100) ,double(10,6) - */ - private String columnType; - - /** - * 列的数据类型 - * 比如 varchar ,double - */ - private Integer dataType; - - - /** - * 默认值 - */ - private String defaultValue; - - /** - * 是否自增 - * 为空 代表没有值 数据库的实际语义是 false - */ - private Boolean autoIncrement; - - /** - * 注释 - */ - private String comment; - - /** - * 是否主键 - */ - private Boolean primaryKey; - - /** - * 空间名 - */ - private String schemaName; - - /** - * 数据库名 - */ - private String databaseName; - - /** - * Data source dependent type name, for a UDT the type name is fully qualified - */ - private String typeName; - - /** - * column size. - */ - private Integer columnSize; - - /** - * is not used. - */ - private Integer bufferLength; - - /** - * the number of fractional digits. Null is returned for data types where DECIMAL_DIGITS is not applicable. - */ - private Integer decimalDigits; - - /** - * Radix (typically either 10 or 2) - */ - private Integer numPrecRadix; - - /** - * is NULL allowed. - * columnNoNulls - might not allow NULL values - * columnNullable - definitely allows NULL values - * columnNullableUnknown - nullability unknown - */ - private Integer nullableInt; - - /** - * unused - */ - private Integer sqlDataType; - - - /** - * unused - */ - private Integer sqlDatetimeSub; - - /** - * for char types the maximum number of bytes in the column - */ - private Integer charOctetLength; - - /** - * index of column in table (starting at 1) - */ - private Integer ordinalPosition; - - /** - * ISO rules are used to determine the nullability for a column. - */ - private Boolean nullable; - - /** - * String => Indicates whether this is a generated column - * * YES --- if this a generated column - * * NO --- if this not a generated column - */ - private Boolean generatedColumn; - - -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/TableIndex.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/TableIndex.java deleted file mode 100644 index a0e69ad51..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/TableIndex.java +++ /dev/null @@ -1,64 +0,0 @@ -package ai.chat2db.server.domain.support.model; - -import java.util.List; - -import ai.chat2db.server.domain.support.enums.IndexTypeEnum; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * 索引信息 - * - * @author Jiaju Zhuang - */ -@Data -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class TableIndex { - - /** - * 索引名称 - */ - private String name; - - /** - * 表名 - */ - private String tableName; - - /** - * 索引类型 - * - * @see IndexTypeEnum - */ - private String type; - - /** - * 是否唯一 - */ - private Boolean unique; - - /** - * 注释 - */ - private String comment; - - /** - * 索引所属schema - */ - private String schemaName; - - /** - * 数据库名 - */ - private String databaseName; - - /** - * 索引包含的列 - */ - private List columnList; -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/TableIndexColumn.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/TableIndexColumn.java deleted file mode 100644 index 8ec9261b2..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/TableIndexColumn.java +++ /dev/null @@ -1,102 +0,0 @@ -package ai.chat2db.server.domain.support.model; - -import ai.chat2db.server.domain.support.enums.CollationEnum; -import ai.chat2db.server.domain.support.enums.IndexTypeEnum; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; - -/** - * 列信息 - * - * @author Jiaju Zhuang - */ -@Data -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class TableIndexColumn { - - /** - * 索引名称 - */ - private String indexName; - - /** - * 表名 - */ - private String tableName; - - /** - * 索引类型 - * - * @see IndexTypeEnum - */ - private String type; - - /** - * 注释 - */ - private String comment; - - /** - * 列名 - */ - private String columnName; - - /** - * 顺序 - */ - private Short ordinalPosition; - - /** - * 排序 - * - * @see CollationEnum - */ - private String collation; - - - /** - * 索引所属schema - */ - private String schemaName; - - /** - * 数据库名 - */ - private String databaseName; - - /** - * 是否唯一 - */ - private Boolean nonUnique; - - /** - * index catalog (may be null); null when TYPE is tableIndexStatistic - */ - private String indexQualifier; - - /** - * ASC_OR_DESC String => column sort sequence, "A" => ascending, "D" => descending, may be null if sort sequence is not supported; null when TYPE is tableIndexStatistic - */ - private String ascOrDesc; - - /** - * CARDINALITY long => When TYPE is tableIndexStatistic, then this is the number of rows in the table; otherwise, it is the number of unique values in the index. - */ - private Long cardinality; - - /** - * When TYPE is tableIndexStatistic then this is the number of pages used for the table, otherwise it is the number of pages used for the current index. - */ - private Long pages; - - /** - * Filter condition, if any. (may be null) - */ - private String filterCondition; -} - diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Trigger.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Trigger.java deleted file mode 100644 index e3a21ef0b..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/model/Trigger.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.model; - -/** - * @author jipengfei - * @version : Trigger.java - */ -public class Trigger { -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/sql/ConnectInfo.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/sql/ConnectInfo.java deleted file mode 100644 index ff07cb976..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/sql/ConnectInfo.java +++ /dev/null @@ -1,598 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.sql; - -import java.sql.Connection; -import java.time.LocalDateTime; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Objects; - -import ai.chat2db.server.domain.support.enums.DbTypeEnum; -import ai.chat2db.server.domain.support.model.KeyValue; -import ai.chat2db.server.domain.support.model.SSHInfo; -import ai.chat2db.server.domain.support.model.SSLInfo; - -import com.jcraft.jsch.Session; -import org.springframework.util.ObjectUtils; - -/** - * @author jipengfei - * @version : ConnectInfo.java - */ -public class ConnectInfo { - /** - * 别名 - */ - private String alias; - /** - * 数据连接ID - */ - private Long dataSourceId; - - - /** - * 创建时间 - */ - private LocalDateTime gmtCreate; - - /** - * 修改时间 - */ - private LocalDateTime gmtModified; - /** - * database - */ - private String databaseName; - - /** - * 控制台ID - */ - private Long consoleId; - - /** - * 数据库URL - */ - private String url; - - /** - * 用户名 - */ - private String user; - - /** - * 密码 - */ - private String password; - - /** - * console独立占有连接 - */ - private Boolean consoleOwn = Boolean.FALSE; - - /** - * 数据库类型 - */ - private DbTypeEnum dbType; - - private Integer port; - - /** - * - */ - private String urlWithOutDatabase; - - /** - * host - */ - private String host; - - /** - * ssh - */ - private SSHInfo ssh; - - /** - * ssh - */ - private SSLInfo ssl; - - /** - * sid - */ - private String sid; - - /** - * driver - */ - private String driver; - - /** - * jdbc版本 - */ - private String jdbc; - - /** - * 扩展信息 - */ - private List extendInfo; - - - - public Connection connection; - - /** - * Getter method for property session. - * - * @return property value of session - */ - public Session getSession() { - return session; - } - - /** - * Setter method for property session. - * - * @param session value to be assigned to property session - */ - public void setSession(Session session) { - this.session = session; - } - - public Session session; - - - /** - * Getter method for property extendInfo. - * - * @return property value of extendInfo - */ - public LinkedHashMap getExtendMap() { - if (ObjectUtils.isEmpty(extendInfo)) { - return new LinkedHashMap<>(); - } - LinkedHashMap map = new LinkedHashMap<>(); - for (KeyValue keyValue : extendInfo) { - map.put(keyValue.getKey(),keyValue.getValue()); - } - return map; - } - - - public void setDatabase(String database) { - this.databaseName = database; - //if (!ObjectUtils.isEmpty(this.urlWithOutDatabase) && !ObjectUtils.isEmpty(this.databaseName)) { - // this.url = this.urlWithOutDatabase + "/" + database; - //} - } - - public String key() { - return this.dataSourceId + "_" + this.databaseName; - } - - public void setUrl(String url) { - this.url = url; - //if (this.dbType != DbTypeEnum.MYSQL && this.dbType != DbTypeEnum.POSTGRESQL) { - // return; - //} - //if (!ObjectUtils.isEmpty(url)) { - // //jdbc:postgresql://localhost:5432/postgres - // String[] array = getUrl().split(":"); - // if (array.length == 4) { - // String str = array[3]; - // boolean isDigit = true; - // StringBuffer sb = new StringBuffer(); - // StringBuffer sb1 = new StringBuffer(); - // for (int i = 0; i < str.length(); i++) { - // char c = str.charAt(i); - // if (isDigit == true) { - // if (!Character.isDigit(c)) { - // isDigit = false; - // } else { - // sb1.append(c); - // } - // } else { - // sb.append(c); - // } - // } - // String s = sb.toString(); - // if (!ObjectUtils.isEmpty(s)) { - // this.databaseName = s; - // } - // this.port = Integer.parseInt(sb1.toString()); - // this.urlWithOutDatabase = array[0] + ":" + array[1] + ":" + array[2] + ":" + port; - // } - //} - } - - @Override - public boolean equals(Object o) { - if (this == o) {return true;} - if (!(o instanceof ConnectInfo)) {return false;} - ConnectInfo that = (ConnectInfo)o; - return Objects.equals(dataSourceId, that.dataSourceId) - && Objects.equals(gmtModified, that.gmtModified) - ; - } - - @Override - public int hashCode() { - return Objects.hash(dataSourceId, consoleId, databaseName); - } - - /** - * Getter method for property dataSourceId. - * - * @return property value of dataSourceId - */ - public Long getDataSourceId() { - return dataSourceId; - } - - /** - * Setter method for property dataSourceId. - * - * @param dataSourceId value to be assigned to property dataSourceId - */ - public void setDataSourceId(Long dataSourceId) { - this.dataSourceId = dataSourceId; - } - - /** - * Getter method for property databaseName. - * - * @return property value of databaseName - */ - public String getDatabaseName() { - return databaseName; - } - - /** - * Setter method for property databaseName. - * - * @param databaseName value to be assigned to property databaseName - */ - public void setDatabaseName(String databaseName) { - this.databaseName = databaseName; - } - - /** - * Getter method for property consoleId. - * - * @return property value of consoleId - */ - public Long getConsoleId() { - return consoleId; - } - - /** - * Setter method for property consoleId. - * - * @param consoleId value to be assigned to property consoleId - */ - public void setConsoleId(Long consoleId) { - this.consoleId = consoleId; - } - - /** - * Getter method for property url. - * - * @return property value of url - */ - public String getUrl() { - return url; - } - - /** - * Getter method for property user. - * - * @return property value of user - */ - public String getUser() { - return user; - } - - /** - * Setter method for property user. - * - * @param user value to be assigned to property user - */ - public void setUser(String user) { - this.user = user; - } - - /** - * Getter method for property password. - * - * @return property value of password - */ - public String getPassword() { - return password; - } - - /** - * Setter method for property password. - * - * @param password value to be assigned to property password - */ - public void setPassword(String password) { - this.password = password; - } - - /** - * Getter method for property consoleOwn. - * - * @return property value of consoleOwn - */ - public Boolean getConsoleOwn() { - return consoleOwn; - } - - /** - * Setter method for property consoleOwn. - * - * @param consoleOwn value to be assigned to property consoleOwn - */ - public void setConsoleOwn(Boolean consoleOwn) { - this.consoleOwn = consoleOwn; - } - - /** - * Getter method for property dbType. - * - * @return property value of dbType - */ - public DbTypeEnum getDbType() { - return dbType; - } - - /** - * Setter method for property dbType. - * - * @param dbType value to be assigned to property dbType - */ - public void setDbType(DbTypeEnum dbType) { - this.dbType = dbType; - } - - /** - * Getter method for property port. - * - * @return property value of port - */ - public Integer getPort() { - return port; - } - - /** - * Setter method for property port. - * - * @param port value to be assigned to property port - */ - public void setPort(Integer port) { - this.port = port; - } - - /** - * Getter method for property urlWithOutDatabase. - * - * @return property value of urlWithOutDatabase - */ - public String getUrlWithOutDatabase() { - return urlWithOutDatabase; - } - - /** - * Setter method for property urlWithOutDatabase. - * - * @param urlWithOutDatabase value to be assigned to property urlWithOutDatabase - */ - public void setUrlWithOutDatabase(String urlWithOutDatabase) { - this.urlWithOutDatabase = urlWithOutDatabase; - } - - /** - * Getter method for property host. - * - * @return property value of host - */ - public String getHost() { - return host; - } - - /** - * Setter method for property host. - * - * @param host value to be assigned to property host - */ - public void setHost(String host) { - this.host = host; - } - - /** - * Getter method for property ssh. - * - * @return property value of ssh - */ - public SSHInfo getSsh() { - return ssh; - } - - /** - * Setter method for property ssh. - * - * @param ssh value to be assigned to property ssh - */ - public void setSsh(SSHInfo ssh) { - this.ssh = ssh; - } - - /** - * Getter method for property ssl. - * - * @return property value of ssl - */ - public SSLInfo getSsl() { - return ssl; - } - - /** - * Setter method for property ssl. - * - * @param ssl value to be assigned to property ssl - */ - public void setSsl(SSLInfo ssl) { - this.ssl = ssl; - } - - /** - * Getter method for property sid. - * - * @return property value of sid - */ - public String getSid() { - return sid; - } - - /** - * Setter method for property sid. - * - * @param sid value to be assigned to property sid - */ - public void setSid(String sid) { - this.sid = sid; - } - - /** - * Getter method for property driver. - * - * @return property value of driver - */ - public String getDriver() { - return driver; - } - - /** - * Setter method for property driver. - * - * @param driver value to be assigned to property driver - */ - public void setDriver(String driver) { - this.driver = driver; - } - - /** - * Getter method for property jdbc. - * - * @return property value of jdbc - */ - public String getJdbc() { - return jdbc; - } - - /** - * Setter method for property jdbc. - * - * @param jdbc value to be assigned to property jdbc - */ - public void setJdbc(String jdbc) { - this.jdbc = jdbc; - } - - /** - * Getter method for property extendInfo. - * - * @return property value of extendInfo - */ - public List getExtendInfo() { - return extendInfo; - } - - - - /** - * Setter method for property extendInfo. - * - * @param extendInfo value to be assigned to property extendInfo - */ - public void setExtendInfo(List extendInfo) { - this.extendInfo = extendInfo; - } - - /** - * Getter method for property connection. - * - * @return property value of connection - */ - public Connection getConnection() { - return connection; - } - - /** - * Setter method for property connection. - * - * @param connection value to be assigned to property connection - */ - public void setConnection(Connection connection) { - this.connection = connection; - } - - - /** - * Getter method for property alias. - * - * @return property value of alias - */ - public String getAlias() { - return alias; - } - - /** - * Setter method for property alias. - * - * @param alias value to be assigned to property alias - */ - public void setAlias(String alias) { - this.alias = alias; - } - - /** - * Getter method for property gmtCreate. - * - * @return property value of gmtCreate - */ - public LocalDateTime getGmtCreate() { - return gmtCreate; - } - - /** - * Setter method for property gmtCreate. - * - * @param gmtCreate value to be assigned to property gmtCreate - */ - public void setGmtCreate(LocalDateTime gmtCreate) { - this.gmtCreate = gmtCreate; - } - - - /** - * Getter method for property gmtModified. - * - * @return property value of gmtModified - */ - public LocalDateTime getGmtModified() { - return gmtModified; - } - - /** - * Setter method for property gmtModified. - * - * @param gmtModified value to be assigned to property gmtModified - */ - public void setGmtModified(LocalDateTime gmtModified) { - this.gmtModified = gmtModified; - } - -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/sql/DbhubContext.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/sql/DbhubContext.java deleted file mode 100644 index 3afde0cd1..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/sql/DbhubContext.java +++ /dev/null @@ -1,157 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.sql; - -import java.sql.Connection; -import java.sql.SQLException; -import java.util.List; -import java.util.Map; - -import ai.chat2db.server.domain.support.dialect.MetaSchema; -import ai.chat2db.server.domain.support.enums.DbTypeEnum; -import ai.chat2db.server.domain.support.enums.DriverTypeEnum; -import ai.chat2db.server.domain.support.model.SSHInfo; - -import com.jcraft.jsch.JSchException; -import com.jcraft.jsch.Session; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; - -/** - * @author jipengfei - * @version : DbhubContext.java - */ -@Slf4j -public class DbhubContext { - - private static final ThreadLocal CONNECT_INFO_THREAD_LOCAL = new ThreadLocal<>(); - - public static List JDBC_JAR_DOWNLOAD_URL_LIST; - - /** - * 获取当前线程的ContentContext - * - * @return - */ - public static ConnectInfo getConnectInfo() { - return CONNECT_INFO_THREAD_LOCAL.get(); - } - - public static MetaSchema getMetaSchema() { - return getConnectInfo().getDbType().metaSchema(); - } - - public static Connection getConnection() { - return getConnectInfo().getConnection(); - } - - /** - * 设置context - * - * @param info - */ - public static void putContext(ConnectInfo info) { - ConnectInfo connectInfo = CONNECT_INFO_THREAD_LOCAL.get(); - CONNECT_INFO_THREAD_LOCAL.set(info); - if (connectInfo == null) { - setConnectInfoThreadLocal(info); - if (StringUtils.isNotBlank(info.getDatabaseName())) { - SQLExecutor.getInstance().connectDatabase(info.getDatabaseName()); - } - } - } - - private static void setConnectInfoThreadLocal(ConnectInfo connectInfo) { - Session session = null; - Connection connection = null; - SSHInfo ssh = connectInfo.getSsh(); - String url = connectInfo.getUrl(); - String host = connectInfo.getHost(); - String port = connectInfo.getPort() + ""; - try { - session = getSession(ssh); - if (session != null) { - url = url.replace(host, "127.0.0.1").replace(port, ssh.getLocalPort()); - } - connection = getConnect(url, host, port, connectInfo.getUser(), - connectInfo.getPassword(), connectInfo.getDbType(), - connectInfo.getJdbc(), ssh, connectInfo.getExtendMap()); - } catch (Exception e1) { - log.error("getConnect error", e1); - if (connection != null) { - try { - connection.close(); - } catch (SQLException e) { - log.error("session close error", e); - } - } - if (session != null) { - try { - session.delPortForwardingL(Integer.parseInt(ssh.getLocalPort())); - session.disconnect(); - } catch (JSchException e) { - log.error("session close error", e); - } - } - throw new RuntimeException("getConnect error", e1); - } - connectInfo.setSession(session); - connectInfo.setConnection(connection); - } - - /** - * 测试数据库连接 - * - * @param url 数据库连接 - * @param userName 用户名 - * @param password 密码 - * @param dbType 数据库类型 - * @return - */ - private static Connection getConnect(String url, String host, String port, - String userName, String password, DbTypeEnum dbType, - String jdbc, SSHInfo ssh, Map properties) throws SQLException { - // 创建连接 - return IDriverManager.getConnection(url, userName, password, - DriverTypeEnum.getDriver(dbType, jdbc), properties); - - } - - private static Session getSession(SSHInfo ssh) { - Session session = null; - if (ssh!=null && ssh.isUse()) { - session = SSHManager.getSSHSession(ssh); - } - return session; - } - - /** - * 设置context - */ - public static void removeContext() { - ConnectInfo connectInfo = CONNECT_INFO_THREAD_LOCAL.get(); - if (connectInfo != null) { - Connection connection = connectInfo.getConnection(); - try { - if (connection != null && !connection.isClosed()) { - connection.close(); - } - } catch (SQLException e) { - log.error("close connection error", e); - } - Session session = connectInfo.getSession(); - if (session != null) { - try { - session.delPortForwardingL(Integer.parseInt(connectInfo.getSsh().getLocalPort())); - session.disconnect(); - } catch (JSchException e) { - log.error("close session error", e); - } - } - CONNECT_INFO_THREAD_LOCAL.remove(); - } - } - -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/sql/IDriverManager.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/sql/IDriverManager.java deleted file mode 100644 index 423fdfba9..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/sql/IDriverManager.java +++ /dev/null @@ -1,201 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.sql; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.sql.Connection; -import java.sql.Driver; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.Map; -import java.util.Properties; -import java.util.concurrent.ConcurrentHashMap; - -import ai.chat2db.server.domain.support.enums.DbTypeEnum; -import ai.chat2db.server.domain.support.enums.DriverTypeEnum; -import ai.chat2db.server.domain.support.model.DriverEntry; -import ai.chat2db.server.domain.support.util.JdbcJarUtils; -import com.alibaba.fastjson2.JSON; - -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static ai.chat2db.server.domain.support.util.JdbcJarUtils.getFullPath; - -/** - * @author jipengfei - * @version : IsolationDriverManager.java - */ -public class IDriverManager { - private static final Logger log = LoggerFactory.getLogger(IDriverManager.class); - private static final Map CLASS_LOADER_MAP = new ConcurrentHashMap(); - private static final Map DRIVER_ENTRY_MAP = new ConcurrentHashMap(); - - public static Connection getConnection(String url, DriverTypeEnum driver) throws SQLException { - Properties info = new Properties(); - return getConnection(url, info, driver); - } - - public static Connection getConnection(String url, String user, String password, DriverTypeEnum driverTypeEnum) - throws SQLException { - Properties info = new Properties(); - if (user != null) { - info.put("user", user); - } - - if (password != null) { - info.put("password", password); - } - - return getConnection(url, info, driverTypeEnum); - } - - public static Connection getConnection(String url, String user, String password, DriverTypeEnum driverTypeEnum, - Map properties) - throws SQLException { - Properties info = new Properties(); - if (StringUtils.isNotEmpty(user)) { - info.put("user", user); - } - - if (StringUtils.isNotEmpty(password)) { - info.put("password", password); - } - info.putAll(properties); - return getConnection(url, info, driverTypeEnum); - } - - public static Connection getConnection(String url, Properties info, DriverTypeEnum driverTypeEnum) - throws SQLException { - if (url == null) { - throw new SQLException("The url cannot be null", "08001"); - } - DriverManager.println("DriverManager.getConnection(\"" + url + "\")"); - SQLException reason = null; - DriverEntry driverEntry = DRIVER_ENTRY_MAP.get(driverTypeEnum); - if (driverEntry == null) { - driverEntry = getJDBCDriver(driverTypeEnum); - } - try { - Connection con = driverEntry.getDriver().connect(url, info); - if (con != null) { - DriverManager.println("getConnection returning " + driverEntry.getDriver().getClass().getName()); - return con; - } - } catch (SQLException var7) { - Connection con = tryConnectionAgain(driverTypeEnum.getDbTypeEnum() ,driverEntry, url, info); - if (con != null) { - return con; - } else { - throw var7; - } - } - - if (reason != null) { - DriverManager.println("getConnection failed: " + reason); - throw reason; - } else { - DriverManager.println("getConnection: no suitable driver found for " + url); - throw new SQLException("No suitable driver found for " + url, "08001"); - } - } - - private static Connection tryConnectionAgain(DbTypeEnum dbTypeEnum, DriverEntry driverEntry, String url, - Properties info) throws SQLException { - if (DbTypeEnum.MYSQL.equals(dbTypeEnum)) { - if (!info.containsKey("useSSL")) { - info.put("useSSL", "false"); - } - return driverEntry.getDriver().connect(url, info); - } - return null; - } - - private static DriverEntry getJDBCDriver(DriverTypeEnum driverTypeEnum) - throws SQLException { - synchronized (driverTypeEnum) { - try { - if (DRIVER_ENTRY_MAP.containsKey(driverTypeEnum)) { - return DRIVER_ENTRY_MAP.get(driverTypeEnum); - } - ClassLoader cl = getClassLoader(driverTypeEnum); - Driver driver = (Driver)cl.loadClass(driverTypeEnum.getDriverClass()).newInstance(); - DriverEntry driverEntry = DriverEntry.builder().driverTypeEnum(driverTypeEnum).driver(driver).build(); - DRIVER_ENTRY_MAP.put(driverTypeEnum, driverEntry); - return driverEntry; - } catch (Exception e) { - log.error("getJDBCDriver error", e); - throw new SQLException("getJDBCDriver error", "08001"); - } - } - - } - - public static ClassLoader getClassLoader(DriverTypeEnum driverTypeEnum) throws MalformedURLException { - String jarPath = driverTypeEnum.getJar(); - if (CLASS_LOADER_MAP.containsKey(jarPath)) { - return CLASS_LOADER_MAP.get(jarPath); - } else { - synchronized (jarPath) { - if (CLASS_LOADER_MAP.containsKey(jarPath)) { - return CLASS_LOADER_MAP.get(jarPath); - } - String[] jarPaths = jarPath.split(","); - URL[] urls = new URL[jarPaths.length]; - for (int i = 0; i < jarPaths.length; i++) { - File driverFile = new File(getFullPath(jarPaths[i])); - urls[i] = driverFile.toURI().toURL(); - } - //urls[jarPaths.length] = new File(JdbcJarUtils.getFullPath("HikariCP-4.0.3.jar")).toURI().toURL(); - - URLClassLoader cl = new URLClassLoader(urls, ClassLoader.getSystemClassLoader()); - log.info("ClassLoader class:{}", cl.hashCode()); - log.info("ClassLoader URLs:{}", JSON.toJSONString(cl.getURLs())); - - try { - cl.loadClass(driverTypeEnum.getDriverClass()); - } catch (Exception e) { - //如果报错删除目录重试一次 - for (int i = 0; i < jarPaths.length; i++) { - File driverFile = new File(JdbcJarUtils.getNewFullPath(jarPaths[i])); - urls[i] = driverFile.toURI().toURL(); - } - //urls[jarPaths.length] = new File(JdbcJarUtils.getFullPath("HikariCP-4.0.3.jar")).toURI().toURL(); - cl = new URLClassLoader(urls, ClassLoader.getSystemClassLoader()); - - } - CLASS_LOADER_MAP.put(jarPath, cl); - return cl; - } - } - } - - //private static List loadClass(String jarPath, ClassLoader classLoader) throws IOException { - // Long s1 = System.currentTimeMillis(); - // JarFile jarFile = new JarFile(getFullPath(jarPath)); - // Enumeration entries = jarFile.entries(); - // List classes = new ArrayList(); - // while (entries.hasMoreElements()) { - // JarEntry jarEntry = entries.nextElement(); - // if (jarEntry.getName().endsWith(".class") && !jarEntry.getName().contains("$")) { - // String className = jarEntry.getName().substring(0, jarEntry.getName().length() - 6).replaceAll("/", - // "."); - // try { - // classes.add(classLoader.loadClass(className)); - // // log.info("loadClass:{}", className); - // } catch (Throwable var7) { - // //log.error("getClasses error "+className, var7); - // } - // } - // } - // log.info("loadClass cost:{}", System.currentTimeMillis() - s1); - // return classes; - //} - -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/sql/SQLExecutor.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/sql/SQLExecutor.java deleted file mode 100644 index 73247e857..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/sql/SQLExecutor.java +++ /dev/null @@ -1,407 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2022 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.sql; - -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.List; -import java.util.function.Function; -import java.util.stream.Collectors; - -import ai.chat2db.server.domain.support.model.ExecuteResult; -import ai.chat2db.server.domain.support.model.Header; -import ai.chat2db.server.domain.support.model.Procedure; -import ai.chat2db.server.domain.support.model.Table; -import ai.chat2db.server.domain.support.model.TableColumn; -import ai.chat2db.server.domain.support.model.TableIndex; -import ai.chat2db.server.domain.support.model.TableIndexColumn; - -import cn.hutool.core.date.TimeInterval; -import com.google.common.collect.Lists; -import lombok.extern.slf4j.Slf4j; -import org.springframework.jdbc.support.JdbcUtils; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - -import static ai.chat2db.server.domain.support.util.ResultSetUtils.buildColumn; -import static ai.chat2db.server.domain.support.util.ResultSetUtils.buildFunction; -import static ai.chat2db.server.domain.support.util.ResultSetUtils.buildProcedure; -import static ai.chat2db.server.domain.support.util.ResultSetUtils.buildTable; -import static ai.chat2db.server.domain.support.util.ResultSetUtils.buildTableIndexColumn; - -/** - * Dbhub 统一数据库连接管理 - * TODO 长时间不用连接可以关闭,待优化 - * - * @author jipengfei - * @version : DbhubDataSource.java - */ -@Slf4j -public class SQLExecutor { - /** - * 全局单例 - */ - private static final SQLExecutor INSTANCE = new SQLExecutor(); - - private SQLExecutor() { - } - - public static SQLExecutor getInstance() { - return INSTANCE; - } - - public Connection getConnection() throws SQLException { - return DbhubContext.getConnection(); - } - - public void close() { - } - - /** - * 执行sql - * - * @param sql - * @param function - * @return - */ - - public R executeSql(String sql, Function function) { - if (StringUtils.isEmpty(sql)) { - return null; - } - log.info("execute:{}", sql); - Statement stmt = null; - try { - stmt = getConnection().createStatement(); - boolean query = stmt.execute(sql); - // 代表是查询 - if (query) { - ResultSet rs = null; - try { - rs = stmt.getResultSet(); - return function.apply(rs); - } finally { - if (rs != null) { - rs.close(); - } - } - } - } catch (SQLException e) { - throw new RuntimeException(e); - } finally { - if (stmt != null) { - try { - stmt.close(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - } - return null; - } - - /** - * 执行sql - * - * @param sql - * @return - * @throws SQLException - */ - public ExecuteResult execute(final String sql, Connection connection) throws SQLException { - Assert.notNull(sql, "SQL must not be null"); - log.info("execute:{}", sql); - - ExecuteResult executeResult = ExecuteResult.builder().sql(sql).success(Boolean.TRUE).build(); - Statement stmt = null; - try { - TimeInterval timeInterval=new TimeInterval(); - stmt = connection.createStatement(); - boolean query = stmt.execute(sql.replaceFirst(";", "")); - executeResult.setDescription("执行成功"); - // 代表是查询 - if (query) { - ResultSet rs = null; - try { - rs = stmt.getResultSet(); - // 获取有几列 - ResultSetMetaData resultSetMetaData = rs.getMetaData(); - int col = resultSetMetaData.getColumnCount(); - - // 获取header信息 - List
headerList = Lists.newArrayListWithExpectedSize(col); - executeResult.setHeaderList(headerList); - for (int i = 1; i <= col; i++) { - headerList.add(Header.builder() - .dataType(ai.chat2db.server.domain.support.util.JdbcUtils.resolveDataType( - resultSetMetaData.getColumnTypeName(i), resultSetMetaData.getColumnType(i)).getCode()) - .name(resultSetMetaData.getColumnName(i)) - .build()); - } - - // 获取数据信息 - List> dataList = Lists.newArrayList(); - executeResult.setDataList(dataList); - - while (rs.next()) { - List row = Lists.newArrayListWithExpectedSize(col); - dataList.add(row); - for (int i = 1; i <= col; i++) { - row.add(ai.chat2db.server.domain.support.util.JdbcUtils.getResultSetValue(rs, i)); - } - } - executeResult.setDuration(timeInterval.interval()); - return executeResult; - } finally { - JdbcUtils.closeResultSet(rs); - } - } else { - // 修改或者其他 - executeResult.setUpdateCount(stmt.getUpdateCount()); - } - } finally { - JdbcUtils.closeStatement(stmt); - } - return executeResult; - } - - /** - * 执行sql - * - * @param sql - * @return - * @throws SQLException - */ - public ExecuteResult execute(String sql) throws SQLException { - return execute(sql, getConnection()); - } - - public void connectDatabase(String database) { - if (StringUtils.isEmpty(database)) { - return; - } - ConnectInfo info = DbhubContext.getConnectInfo(); - switch (info.getDbType()) { - case MYSQL -> { - try { - execute("use `" + database + "`;"); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - case SQLSERVER -> { - try { - execute("use " + database + ";"); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - case ORACLE, H2, SQLITE -> { - - } - case POSTGRESQL -> { - //close(); - info.setDatabase(database); - try { - getConnection(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - - } - case REDIS -> { - try { - execute("select " + database); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - default -> { - - } - } - } - - /** - * 获取所有的数据库 - * - * @return - */ - public List databases() { - List tables = Lists.newArrayList(); - try { - ResultSet resultSet = getConnection().getMetaData().getCatalogs(); - if (resultSet != null) { - while (resultSet.next()) { - tables.add(resultSet.getString("TABLE_CAT")); - } - } - } catch (SQLException e) { - close(); - throw new RuntimeException(e); - } - return tables; - } - - /** - * 获取所有的schema - * - * @param databaseName - * @param schemaName - * @return - */ - public List schemas(String databaseName, String schemaName) { - List schemaList = Lists.newArrayList(); - try { - ResultSet resultSet = getConnection().getMetaData().getSchemas(databaseName, schemaName); - if (resultSet != null) { - while (resultSet.next()) { - schemaList.add(resultSet.getString("TABLE_SCHEM")); - } - } - } catch (SQLException e) { - close(); - throw new RuntimeException(e); - } - return schemaList; - } - - /** - * 获取所有的数据库表 - * - * @param databaseName - * @param schemaName - * @param tableName - * @param types - * @return - */ - public List
tables(String databaseName, String schemaName, String tableName, String types[]) { - List
tables = Lists.newArrayList(); - try { - ResultSet resultSet = getConnection().getMetaData().getTables(databaseName, schemaName, tableName, - types); - if (resultSet != null) { - while (resultSet.next()) { - tables.add(buildTable(resultSet)); - } - } - } catch (SQLException e) { - close(); - throw new RuntimeException(e); - } - return tables; - } - - /** - * 获取所有的数据库表列 - * - * @param databaseName - * @param schemaName - * @param tableName - * @param columnName - * @return - */ - public List columns(String databaseName, String schemaName, String tableName, String columnName) { - List tableColumns = Lists.newArrayList(); - try { - ResultSet resultSet = getConnection().getMetaData().getColumns(databaseName, schemaName, tableName, - columnName); - if (resultSet != null) { - while (resultSet.next()) { - tableColumns.add(buildColumn(resultSet)); - } - } - } catch (Exception e) { - close(); - throw new RuntimeException(e); - } - return tableColumns; - } - - /** - * 获取所有的数据库表索引 - * - * @param databaseName - * @param schemaName - * @param tableName - * @return - */ - public List indexes(String databaseName, String schemaName, String tableName) { - List tableIndices = Lists.newArrayList(); - try { - List tableIndexColumns = Lists.newArrayList(); - ResultSet resultSet = getConnection().getMetaData().getIndexInfo(databaseName, schemaName, tableName, false, - false); - - while (resultSet != null && resultSet.next()) { - tableIndexColumns.add(buildTableIndexColumn(resultSet)); - } - - tableIndexColumns.stream().filter(c -> c.getIndexName() != null).collect( - Collectors.groupingBy(TableIndexColumn::getIndexName)).entrySet() - .stream().forEach(entry -> { - TableIndex tableIndex = new TableIndex(); - TableIndexColumn column = entry.getValue().get(0); - tableIndex.setName(entry.getKey()); - tableIndex.setTableName(column.getTableName()); - tableIndex.setSchemaName(column.getSchemaName()); - tableIndex.setDatabaseName(column.getDatabaseName()); - tableIndex.setUnique(!column.getNonUnique()); - tableIndex.setColumnList(entry.getValue()); - tableIndices.add(tableIndex); - }); - } catch (SQLException e) { - close(); - throw new RuntimeException(e); - } - return tableIndices; - } - - /** - * 获取所有的函数 - * - * @param databaseName - * @param schemaName - * @return - */ - public List functions(String databaseName, - String schemaName) { - List functions = Lists.newArrayList(); - try { - ResultSet resultSet = getConnection().getMetaData().getFunctions(databaseName, schemaName, null); - while (resultSet != null && resultSet.next()) { - functions.add(buildFunction(resultSet)); - } - } catch (Exception e) { - close(); - throw new RuntimeException(e); - } - return functions; - } - - /** - * 获取所有的存储过程 - * - * @param databaseName - * @param schemaName - * @return - */ - public List procedures(String databaseName, String schemaName) { - List procedures = Lists.newArrayList(); - try { - ResultSet resultSet = getConnection().getMetaData().getProcedures(databaseName, schemaName, null); - while (resultSet != null && resultSet.next()) { - procedures.add(buildProcedure(resultSet)); - } - } catch (Exception e) { - close(); - throw new RuntimeException(e); - } - return procedures; - } - -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/sql/SSHManager.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/sql/SSHManager.java deleted file mode 100644 index 0a1c3b4b8..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/sql/SSHManager.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.sql; - -import java.util.concurrent.ConcurrentHashMap; - -import ai.chat2db.server.domain.support.model.SSHInfo; - -import com.jcraft.jsch.JSch; -import com.jcraft.jsch.Session; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; - -/** - * @author jipengfei - * @version : SSHSessionManager.java - */ -@Slf4j -public class SSHManager { - - private static final ConcurrentHashMap SSH_SESSION_MAP = new ConcurrentHashMap(); - - public static Session getSSHSession(SSHInfo sshInfo) { - Session session = SSH_SESSION_MAP.get(sshInfo); - if (session != null && session.isConnected()) { - return session; - } else { - return createSession(sshInfo); - } - } - - private static Session createSession(SSHInfo ssh) { - synchronized (ssh) { - Session session = SSH_SESSION_MAP.get(ssh); - if (session != null && session.isConnected()) { - return session; - } - try { - JSch jSch = new JSch(); - session = jSch.getSession(ssh.getUserName(), ssh.getHostName(), Integer.parseInt(ssh.getPort())); - session.setPassword(ssh.getPassword()); - session.setConfig("StrictHostKeyChecking", "no"); - session.connect(); - SSH_SESSION_MAP.put(ssh, session); - } catch (Exception e) { - throw new RuntimeException("create ssh session error", e); - } - - if (StringUtils.isNotBlank(ssh.getLocalPort()) && StringUtils.isNotBlank(ssh.getRHost()) - && StringUtils.isNotBlank(ssh.getRPort())) { - try { - int port1 = session.setPortForwardingL(Integer.parseInt(ssh.getLocalPort()), ssh.getRHost(), - Integer.parseInt(ssh.getRPort())); - } catch (Exception e) { - if (session != null && session.isConnected()) { - session.disconnect(); - SSH_SESSION_MAP.remove(ssh); - } - throw new RuntimeException(ssh.getLocalPort() + " port is used,please change to another port ", e); - } - } - return session; - } - } - - public static void close() { - SSH_SESSION_MAP.forEach((k, v) -> { - if (v != null && v.isConnected()) { - try { - v.delPortForwardingL(Integer.parseInt(k.getLocalPort())); - } catch (Exception e) { - log.error("delPortForwardingL error", e); - } - try { - v.disconnect(); - } catch (Exception e) { - log.error("disconnect error", e); - } - } - }); - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/JSchUtils.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/JSchUtils.java deleted file mode 100644 index 27ae4c96a..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/JSchUtils.java +++ /dev/null @@ -1,40 +0,0 @@ -///** -// * alibaba.com Inc. -// * Copyright (c) 2004-2023 All Rights Reserved. -// */ -//package ai.chat2db.server.domain.support.util; -// -//import ai.chat2db.server.domain.support.model.SSHInfo; -// -//import com.jcraft.jsch.JSch; -//import com.jcraft.jsch.JSchException; -//import com.jcraft.jsch.Session; -// -///** -// * @author jipengfei -// * @version : JSchUtil.java -// */ -//public class JSchUtils { -// -// public static Session getSession(SSHInfo ssh, String host, String port) throws JSchException { -// JSch jSch = new JSch(); -// Session session = jSch.getSession(ssh.getUserName(), ssh.getHostName(), -// Integer.parseInt(ssh.getPort())); -// session.setPassword(ssh.getPassword()); -// session.setConfig("StrictHostKeyChecking", "no"); -// session.connect(); -// int port1 = session.setPortForwardingL(Integer.parseInt(ssh.getLocalPort()), host, -// Integer.parseInt(port)); -// return session; -// } -// -// public static Session getSession(SSHInfo ssh) throws JSchException { -// JSch jSch = new JSch(); -// Session session = jSch.getSession(ssh.getUserName(), ssh.getHostName(), -// Integer.parseInt(ssh.getPort())); -// session.setPassword(ssh.getPassword()); -// session.setConfig("StrictHostKeyChecking", "no"); -// session.connect(); -// return session; -// } -//} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/JdbcJarUtils.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/JdbcJarUtils.java deleted file mode 100644 index 22dde2794..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/JdbcJarUtils.java +++ /dev/null @@ -1,152 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.util; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; -import java.util.concurrent.Executors; - -import ai.chat2db.server.domain.support.sql.DbhubContext; - -import okhttp3.Call; -import okhttp3.Callback; -import okhttp3.Dispatcher; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; - -/** - * @author jipengfei - * @version : JdbcJarUtils.java - */ -public class JdbcJarUtils { - - private static final OkHttpClient async_client = new OkHttpClient.Builder() - .dispatcher(new Dispatcher(Executors.newFixedThreadPool(20))) // 设定线程池大小 - .build(); - - private static final OkHttpClient client = new OkHttpClient(); - - private static final String PATH = System.getProperty("user.home") + File.separator + ".chat2db" + File.separator - + "jdbc-lib" + File.separator; - - static { - File file = new File(PATH); - if (!file.exists()) { - file.mkdirs(); - } - } - - public static void asyncDownload(List urls) throws Exception { - for (String url : urls) { - String outputPath = PATH + url.substring(url.lastIndexOf("/") + 1); - File file = new File(outputPath); - if (file.exists()) { - System.out.println("File already exists: " + outputPath); - continue; - } - asyncDownload(url); - } - } - - public static void asyncDownload(String url) throws Exception { - String outputPath = PATH + url.substring(url.lastIndexOf("/") + 1); - File file = new File(outputPath); - if (file.exists()) { - file.delete(); - } - Request request = new Request.Builder() - .url(url) - .build(); - async_client.newCall(request).enqueue(new Callback() { - @Override - public void onFailure(Call call, IOException e) { - } - - @Override - public void onResponse(Call call, Response response) throws IOException { - if (!response.isSuccessful()) { - throw new IOException("Unexpected code " + response); - } - try (InputStream is = response.body().byteStream(); - FileOutputStream fos = new FileOutputStream(outputPath)) { - byte[] buffer = new byte[2048]; - int length; - while ((length = is.read(buffer)) != -1) { - fos.write(buffer, 0, length); - } - fos.flush(); - } - System.out.println("File downloaded: " + outputPath); - } - }); - } - - public static void download(String url) throws IOException { - String outputPath = PATH + url.substring(url.lastIndexOf("/") + 1); - File file = new File(outputPath); - if (file.exists()) { - file.delete(); - } - Request request = new Request.Builder() - .url(url) - .build(); - try (Response response = client.newCall(request).execute()) { - if (!response.isSuccessful()) { - throw new IOException("Unexpected code " + response); - } - try (InputStream is = response.body().byteStream(); - FileOutputStream fos = new FileOutputStream(outputPath)) { - - byte[] buffer = new byte[2048]; - int length; - while ((length = is.read(buffer)) != -1) { - fos.write(buffer, 0, length); - } - fos.flush(); - } - System.out.println("File downloaded: " + outputPath); - } - } - - public static String getNewFullPath(String jarPath) { - String path = PATH + jarPath; - File file = new File(path); - if (file.exists()) { - file.delete(); - } - return getFullPath(jarPath); - } - - public static String getFullPath(String jarPath) { - String path = PATH + jarPath; - File file = new File(path); - if (!file.exists()) { - String url = getDownloadUrl(jarPath); - try { - download(url); - } catch (IOException e) { - try { - download(url); - } catch (IOException ex) { - throw new RuntimeException(ex); - } - } - } - return path; - } - - private static String getDownloadUrl(String jarPath) { - for (String path : DbhubContext.JDBC_JAR_DOWNLOAD_URL_LIST) { - if (path.contains(jarPath)) { - return path.trim(); - } - } - return null; - } -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/JdbcUtils.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/JdbcUtils.java deleted file mode 100644 index 2d3e278b9..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/JdbcUtils.java +++ /dev/null @@ -1,263 +0,0 @@ -package ai.chat2db.server.domain.support.util; - -import java.sql.Blob; -import java.sql.Clob; -import java.sql.Connection; -import java.sql.Date; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.sql.Types; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.time.format.DateTimeFormatter; -import java.util.Locale; -import java.util.Map; - -import com.alibaba.druid.DbType; - -import ai.chat2db.server.domain.support.enums.DataTypeEnum; -import ai.chat2db.server.domain.support.enums.DbTypeEnum; -import ai.chat2db.server.domain.support.enums.DriverTypeEnum; -import ai.chat2db.server.domain.support.model.DataSourceConnect; -import ai.chat2db.server.domain.support.model.SSHInfo; -import ai.chat2db.server.domain.support.sql.IDriverManager; -import ai.chat2db.server.domain.support.sql.SSHManager; -import cn.hutool.core.date.DateUtil; -import com.jcraft.jsch.JSchException; -import com.jcraft.jsch.Session; -import lombok.extern.slf4j.Slf4j; - -/** - * jdbc工具类 - * - * @author Jiaju Zhuang - */ -@Slf4j -public class JdbcUtils { - - private static final String DEFAULT_DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss.SSS"; - private static final DateTimeFormatter DEFAULT_DATETIME_FORMAT = DateTimeFormatter - .ofPattern(DEFAULT_DATETIME_PATTERN, Locale.getDefault()) - .withZone(ZoneId.systemDefault()); - - private static final DateTimeFormatter DEFAULT_DATE_FORMAT = DateTimeFormatter - .ofPattern("yyyy-MM-dd", Locale.getDefault()) - .withZone(ZoneId.systemDefault()); - private static final DateTimeFormatter DEFAULT_DATETIME_TZ_FORMAT = DateTimeFormatter - .ofPattern("yyyy-MM-dd HH:mm:ss.SSS Z", Locale.getDefault()) - .withZone(ZoneId.systemDefault()); - - /** - * 获取德鲁伊的的数据库类型 - * - * @param dbType - * @return - */ - public static DbType parse2DruidDbType(DbTypeEnum dbType) { - if (dbType == null) { - return null; - } - try { - return DbType.valueOf(dbType.getCode().toLowerCase()); - } catch (Exception e) { - return null; - } - } - - /** - * 解析字段的类型 - * - * @param typeName - * @param type - * @return - */ - public static DataTypeEnum resolveDataType(String typeName, int type) { - switch (getTypeByTypeName(typeName, type)) { - case Types.BOOLEAN: - return DataTypeEnum.BOOLEAN; - case Types.CHAR: - case Types.VARCHAR: - case Types.NVARCHAR: - case Types.LONGVARCHAR: - case Types.LONGNVARCHAR: - return DataTypeEnum.STRING; - case Types.BIGINT: - case Types.DECIMAL: - case Types.DOUBLE: - case Types.FLOAT: - case Types.INTEGER: - case Types.NUMERIC: - case Types.REAL: - case Types.SMALLINT: - return DataTypeEnum.NUMERIC; - case Types.BIT: - case Types.TINYINT: - if (typeName.toLowerCase().contains("bool")) { - // Declared as numeric but actually it's a boolean - return DataTypeEnum.BOOLEAN; - } - return DataTypeEnum.NUMERIC; - case Types.DATE: - case Types.TIME: - case Types.TIME_WITH_TIMEZONE: - case Types.TIMESTAMP: - case Types.TIMESTAMP_WITH_TIMEZONE: - return DataTypeEnum.DATETIME; - case Types.BINARY: - case Types.VARBINARY: - case Types.LONGVARBINARY: - return DataTypeEnum.BINARY; - case Types.BLOB: - case Types.CLOB: - case Types.NCLOB: - case Types.SQLXML: - return DataTypeEnum.CONTENT; - case Types.STRUCT: - return DataTypeEnum.STRUCT; - case Types.ARRAY: - return DataTypeEnum.ARRAY; - case Types.ROWID: - return DataTypeEnum.ROWID; - case Types.REF: - return DataTypeEnum.REFERENCE; - case Types.OTHER: - return DataTypeEnum.OBJECT; - default: - return DataTypeEnum.UNKNOWN; - } - } - - private static int getTypeByTypeName(String typeName, int type) { - // [JDBC: SQLite driver uses VARCHAR value type for all LOBs] - if (type == Types.OTHER || type == Types.VARCHAR) { - if ("BLOB".equalsIgnoreCase(typeName)) { - return Types.BLOB; - } else if ("CLOB".equalsIgnoreCase(typeName)) { - return Types.CLOB; - } else if ("NCLOB".equalsIgnoreCase(typeName)) { - return Types.NCLOB; - } - } else if (type == Types.BIT) { - // Workaround for MySQL (and maybe others) when TINYINT(1) == BOOLEAN - if ("TINYINT".equalsIgnoreCase(typeName)) { - return Types.TINYINT; - } - } - return type; - } - - /** - * 获取一个返回值 - * - * @param rs - * @param index - * @return - * @throws SQLException - */ - public static String getResultSetValue(ResultSet rs, int index) throws SQLException { - Object obj = rs.getObject(index); - if (obj == null) { - return null; - } - - if (obj instanceof Blob blob) { - return "(BLOB " + blob.length() + ")"; - } - if (obj instanceof Clob clob) { - return "(CLOB " + clob.length() + ")"; - } - if (obj instanceof Timestamp timestamp) { - return DateUtil.format(timestamp, DEFAULT_DATETIME_FORMAT); - } - - String className = obj.getClass().getName(); - if ("oracle.sql.TIMESTAMP".equals(className) || "oracle.sql.TIMESTAMPTZ".equals(className)) { - return DateUtil.format(rs.getTimestamp(index), DEFAULT_DATETIME_TZ_FORMAT); - } - if (className.startsWith("oracle.sql.DATE")) { - String metaDataClassName = rs.getMetaData().getColumnClassName(index); - if ("java.sql.Timestamp".equals(metaDataClassName) || "oracle.sql.TIMESTAMP".equals(metaDataClassName)) { - return DateUtil.format(rs.getTimestamp(index), DEFAULT_DATETIME_FORMAT); - } else { - return DateUtil.format(rs.getDate(index), DEFAULT_DATETIME_FORMAT); - } - } - if (obj instanceof Date date) { - if ("java.sql.Timestamp".equals(rs.getMetaData().getColumnClassName(index))) { - return DateUtil.format(rs.getDate(index), DEFAULT_DATETIME_FORMAT); - } -// return DateUtil.format(date, DEFAULT_DATETIME_FORMAT); - return null; - } - if (obj instanceof LocalDateTime localDateTime) { - return localDateTime.toString(); - } - if (obj instanceof LocalDate localDate) { - return localDate.toString(); - } - if (obj instanceof Number) { - return obj.toString(); - } - return obj.toString(); - } - - /** - * 测试数据库连接 - * - * @param url 数据库连接 - * @param userName 用户名 - * @param password 密码 - * @param dbType 数据库类型 - * @return - */ - public static DataSourceConnect testConnect(String url, String host, String port, - String userName, String password, DbTypeEnum dbType, - String jdbc, SSHInfo ssh, Map properties) { - DataSourceConnect dataSourceConnect = DataSourceConnect.builder() - .success(Boolean.TRUE) - .build(); - Session session = null; - Connection connection = null; - // 加载驱动 - try { - if (ssh.isUse()) { - session = SSHManager.getSSHSession(ssh); - url = url.replace(host, "127.0.0.1").replace(port, ssh.getLocalPort()); - } - // 创建连接 - connection = IDriverManager.getConnection(url, userName, password, - DriverTypeEnum.getDriver(dbType, jdbc), properties); - } catch (Exception e) { - log.error("connection fail:", e); - dataSourceConnect.setSuccess(Boolean.FALSE); - // 获取最后一个异常的信息给前端 - Throwable t = e; - while (t.getCause() != null) { - t = t.getCause(); - } - dataSourceConnect.setMessage(t.getMessage()); - return dataSourceConnect; - } finally { - if (connection != null) { - try { - connection.close(); - } catch (SQLException e) { - // ignore - } - } - if (session != null) { - try { - session.delPortForwardingL(Integer.parseInt(ssh.getLocalPort())); - session.disconnect(); - - } catch (JSchException e) { - } - } - } - dataSourceConnect.setDescription("成功"); - return dataSourceConnect; - } - -} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/ResultSetUtils.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/ResultSetUtils.java deleted file mode 100644 index 4607674a4..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/ResultSetUtils.java +++ /dev/null @@ -1,101 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.util; - -import java.sql.ResultSet; -import java.sql.SQLException; - -import ai.chat2db.server.domain.support.model.Procedure; -import ai.chat2db.server.domain.support.model.Table; -import ai.chat2db.server.domain.support.model.TableColumn; -import ai.chat2db.server.domain.support.model.TableIndexColumn; - -/** - * @author jipengfei - * @version : ResultSetUtils.java - */ -public class ResultSetUtils { - - public static ai.chat2db.server.domain.support.model.Function buildFunction(ResultSet resultSet) { - ai.chat2db.server.domain.support.model.Function function - = new ai.chat2db.server.domain.support.model.Function(); - try { - function.setDatabaseName(resultSet.getString("FUNCTION_CAT")); - function.setSchemaName(resultSet.getString("FUNCTION_SCHEM")); - function.setFunctionName(resultSet.getString("FUNCTION_NAME")); - function.setRemarks(resultSet.getString("REMARKS")); - function.setFunctionType(resultSet.getShort("FUNCTION_TYPE")); - function.setSpecificName(resultSet.getString("SPECIFIC_NAME")); - } catch (SQLException e) { - throw new RuntimeException(e); - } - return function; - } - - public static Procedure buildProcedure(ResultSet resultSet) { - Procedure procedure = new Procedure(); - try { - procedure.setDatabaseName(resultSet.getString("PROCEDURE_CAT")); - procedure.setSchemaName(resultSet.getString("PROCEDURE_SCHEM")); - procedure.setProcedureName(resultSet.getString("PROCEDURE_NAME")); - procedure.setRemarks(resultSet.getString("REMARKS")); - procedure.setProcedureType(resultSet.getShort("PROCEDURE_TYPE")); - procedure.setSpecificName(resultSet.getString("SPECIFIC_NAME")); - } catch (SQLException e) { - throw new RuntimeException(e); - } - return procedure; - } - - public static TableIndexColumn buildTableIndexColumn(ResultSet resultSet) throws SQLException { - TableIndexColumn tableIndexColumn = new TableIndexColumn(); - tableIndexColumn.setColumnName(resultSet.getString("COLUMN_NAME")); - tableIndexColumn.setIndexName(resultSet.getString("INDEX_NAME")); - tableIndexColumn.setAscOrDesc(resultSet.getString("ASC_OR_DESC")); - tableIndexColumn.setCardinality(resultSet.getLong("CARDINALITY")); - tableIndexColumn.setPages(resultSet.getLong("PAGES")); - tableIndexColumn.setFilterCondition(resultSet.getString("FILTER_CONDITION")); - tableIndexColumn.setIndexQualifier(resultSet.getString("INDEX_QUALIFIER")); - // tableIndexColumn.setIndexType(resultSet.getShort("TYPE")); - tableIndexColumn.setNonUnique(resultSet.getBoolean("NON_UNIQUE")); - tableIndexColumn.setOrdinalPosition(resultSet.getShort("ORDINAL_POSITION")); - tableIndexColumn.setDatabaseName(resultSet.getString("TABLE_CAT")); - tableIndexColumn.setSchemaName(resultSet.getString("TABLE_SCHEM")); - tableIndexColumn.setTableName(resultSet.getString("TABLE_NAME")); - return tableIndexColumn; - } - - public static TableColumn buildColumn(ResultSet resultSet) throws SQLException { - TableColumn tableColumn = new TableColumn(); - tableColumn.setDatabaseName(resultSet.getString("TABLE_CAT")); - tableColumn.setSchemaName(resultSet.getString("TABLE_SCHEM")); - tableColumn.setTableName(resultSet.getString("TABLE_NAME")); - tableColumn.setName(resultSet.getString("COLUMN_NAME")); - tableColumn.setComment(resultSet.getString("REMARKS")); - tableColumn.setDefaultValue(resultSet.getString("COLUMN_DEF")); - tableColumn.setTypeName(resultSet.getString("TYPE_NAME")); - tableColumn.setColumnSize(resultSet.getInt("COLUMN_SIZE")); - tableColumn.setDataType(resultSet.getInt("DATA_TYPE")); - tableColumn.setNullable(resultSet.getInt("NULLABLE") == 1); - tableColumn.setOrdinalPosition(resultSet.getInt("ORDINAL_POSITION")); - tableColumn.setAutoIncrement("YES".equals(resultSet.getString("IS_AUTOINCREMENT"))); - //tableColumn.setGeneratedColumn("YES".equals(resultSet.getString("IS_GENERATEDCOLUMN"))); - tableColumn.setOrdinalPosition(resultSet.getInt("ORDINAL_POSITION")); - tableColumn.setDecimalDigits(resultSet.getInt("DECIMAL_DIGITS")); - tableColumn.setNumPrecRadix(resultSet.getInt("NUM_PREC_RADIX")); - tableColumn.setCharOctetLength(resultSet.getInt("CHAR_OCTET_LENGTH")); - return tableColumn; - } - - public static Table buildTable(ResultSet resultSet) throws SQLException { - Table table = new Table(); - table.setName(resultSet.getString("TABLE_NAME")); - table.setComment(resultSet.getString("REMARKS")); - table.setDatabaseName(resultSet.getString("TABLE_CAT")); - table.setSchemaName(resultSet.getString("TABLE_SCHEM")); - table.setType(resultSet.getString("TABLE_TYPE")); - return table; - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/SqlUtils.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/SqlUtils.java deleted file mode 100644 index 742d2b352..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/ai/chat2db/server/domain/support/util/SqlUtils.java +++ /dev/null @@ -1,436 +0,0 @@ -/** - * alibaba.com Inc. - * Copyright (c) 2004-2023 All Rights Reserved. - */ -package ai.chat2db.server.domain.support.util; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.stream.Collectors; - -import ai.chat2db.server.domain.support.enums.CollationEnum; -import ai.chat2db.server.domain.support.enums.IndexTypeEnum; -import ai.chat2db.server.domain.support.model.Sql; -import ai.chat2db.server.domain.support.model.Table; -import ai.chat2db.server.domain.support.model.TableColumn; -import ai.chat2db.server.domain.support.model.TableIndex; -import ai.chat2db.server.domain.support.model.TableIndexColumn; -import ai.chat2db.server.tools.common.util.EasyBooleanUtils; -import ai.chat2db.server.tools.common.util.EasyCollectionUtils; -import ai.chat2db.server.tools.common.util.EasyEnumUtils; -import com.alibaba.druid.DbType; -import com.alibaba.druid.sql.ast.SQLDataTypeImpl; -import com.alibaba.druid.sql.ast.expr.SQLCharExpr; -import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; -import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddColumn; -import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddConstraint; -import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropColumnItem; -import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropPrimaryKey; -import com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement; -import com.alibaba.druid.sql.ast.statement.SQLAssignItem; -import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition; -import com.alibaba.druid.sql.ast.statement.SQLColumnPrimaryKey; -import com.alibaba.druid.sql.ast.statement.SQLCreateIndexStatement; -import com.alibaba.druid.sql.ast.statement.SQLDropIndexStatement; -import com.alibaba.druid.sql.ast.statement.SQLExprTableSource; -import com.alibaba.druid.sql.ast.statement.SQLNotNullConstraint; -import com.alibaba.druid.sql.ast.statement.SQLNullConstraint; -import com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem; -import com.alibaba.druid.sql.dialect.mysql.ast.MySqlPrimaryKey; -import com.alibaba.druid.sql.dialect.mysql.ast.MySqlUnique; -import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlCharExpr; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableChangeColumn; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableModifyColumn; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlRenameTableStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlRenameTableStatement.Item; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlTableIndex; - -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.BooleanUtils; -import org.apache.commons.lang3.StringUtils; - -/** - * @author jipengfei - * @version : SqlUtils.java - */ -public class SqlUtils { - - public static List buildSql(Table oldTable, Table newTable) { - List sqlList = new ArrayList<>(); - // 创建表 - if (oldTable == null) { - MySqlCreateTableStatement mySqlCreateTableStatement = new MySqlCreateTableStatement(); - mySqlCreateTableStatement.setDbType(DbType.mysql); - mySqlCreateTableStatement.setTableName(newTable.getName()); - if (!Objects.isNull(newTable.getComment())) { - mySqlCreateTableStatement.setComment(new MySqlCharExpr(newTable.getComment())); - } - List columnList = newTable.getColumnList(); - if (!CollectionUtils.isEmpty(columnList)) { - for (TableColumn tableColumn : columnList) { - SQLColumnDefinition sqlColumnDefinition = new SQLColumnDefinition(); - mySqlCreateTableStatement.addColumn(sqlColumnDefinition); - sqlColumnDefinition.setName(tableColumn.getName()); - sqlColumnDefinition.setDataType(new SQLDataTypeImpl(tableColumn.getColumnType())); - if (BooleanUtils.isNotFalse(tableColumn.getNullable())) { - sqlColumnDefinition.addConstraint(new SQLNullConstraint()); - } else { - sqlColumnDefinition.addConstraint(new SQLNotNullConstraint()); - } - if (!Objects.isNull(tableColumn.getDefaultValue())) { - sqlColumnDefinition.setDefaultExpr(new MySqlCharExpr(tableColumn.getDefaultValue())); - } - sqlColumnDefinition.setAutoIncrement(BooleanUtils.isTrue(tableColumn.getAutoIncrement())); - if (!Objects.isNull(tableColumn.getComment())) { - sqlColumnDefinition.setComment(tableColumn.getComment()); - } - if (BooleanUtils.isTrue(tableColumn.getPrimaryKey())) { - sqlColumnDefinition.addConstraint(new SQLColumnPrimaryKey()); - } - } - //// 主键 - //List primaryKeyColumnList = EasyCollectionUtils.stream(columnList) - // .filter(tableColumn -> BooleanUtils.isTrue(tableColumn.getPrimaryKey())) - // .collect(Collectors.toList()); - //if (!CollectionUtils.isEmpty(primaryKeyColumnList)) { - // MySqlPrimaryKey mySqlPrimaryKey = new MySqlPrimaryKey(); - // mySqlCreateTableStatement.getTableElementList().add(mySqlPrimaryKey); - // for (TableColumn tableColumn : primaryKeyColumnList) { - // mySqlPrimaryKey.addColumn(new SQLIdentifierExpr(tableColumn.getName())); - // } - //} - } - - // 索引 - List indexList = newTable.getIndexList(); - if (!CollectionUtils.isEmpty(indexList)) { - for (TableIndex tableIndex : indexList) { - if (IndexTypeEnum.UNIQUE.getCode().equals(tableIndex.getType())) { - MySqlUnique mySqlUnique = new MySqlUnique(); - mySqlCreateTableStatement.getTableElementList().add(mySqlUnique); - mySqlUnique.setName(tableIndex.getName()); - mySqlUnique.setComment(new SQLCharExpr(tableIndex.getComment())); - mySqlUnique.getIndexDefinition().setType("unique"); - if (!CollectionUtils.isEmpty(tableIndex.getColumnList())) { - for (TableIndexColumn tableIndexColumn : tableIndex.getColumnList()) { - SQLSelectOrderByItem sqlSelectOrderByItem = new SQLSelectOrderByItem(); - sqlSelectOrderByItem.setExpr(new SQLIdentifierExpr(tableIndexColumn.getColumnName())); - CollationEnum collation = EasyEnumUtils.getEnum(CollationEnum.class, - tableIndexColumn.getCollation()); - if (collation != null) { - sqlSelectOrderByItem.setType(collation.getSqlOrderingSpecification()); - } - mySqlUnique.addColumn(sqlSelectOrderByItem); - } - } - } else { - MySqlTableIndex mySqlTableIndex = new MySqlTableIndex(); - mySqlCreateTableStatement.getTableElementList().add(mySqlTableIndex); - mySqlTableIndex.setName(tableIndex.getName()); - mySqlTableIndex.setComment(new SQLCharExpr(tableIndex.getComment())); - if (!CollectionUtils.isEmpty(tableIndex.getColumnList())) { - for (TableIndexColumn tableIndexColumn : tableIndex.getColumnList()) { - SQLSelectOrderByItem sqlSelectOrderByItem = new SQLSelectOrderByItem(); - sqlSelectOrderByItem.setExpr(new SQLIdentifierExpr(tableIndexColumn.getColumnName())); - CollationEnum collation = EasyEnumUtils.getEnum(CollationEnum.class, - tableIndexColumn.getCollation()); - if (collation != null) { - sqlSelectOrderByItem.setType(collation.getSqlOrderingSpecification()); - } - mySqlTableIndex.addColumn(sqlSelectOrderByItem); - } - } - } - } - } - - sqlList.add(Sql.builder().sql(mySqlCreateTableStatement + ";").build()); - return sqlList; - } - - // 修改表结构 - // 修改表名字 - if (!StringUtils.equals(oldTable.getName(), newTable.getName())) { - MySqlRenameTableStatement mySqlRenameTableStatement = new MySqlRenameTableStatement(); - mySqlRenameTableStatement.setDbType(DbType.mysql); - Item item = new Item(); - item.setName(new SQLIdentifierExpr(oldTable.getName())); - item.setTo(new SQLIdentifierExpr(newTable.getName())); - mySqlRenameTableStatement.addItem(item); - sqlList.add(Sql.builder().sql(mySqlRenameTableStatement + ";").build()); - } - // 修改注释 - if (!StringUtils.equals(oldTable.getComment(), newTable.getComment())) { - SQLAlterTableStatement sqlAlterTableStatement = new SQLAlterTableStatement(); - sqlAlterTableStatement.setDbType(DbType.mysql); - SQLAssignItem sqlAssignItem = new SQLAssignItem(); - sqlAssignItem.setTarget(new SQLIdentifierExpr("COMMENT")); - sqlAssignItem.setValue(new MySqlCharExpr(newTable.getComment())); - sqlAlterTableStatement.getTableOptions().add(sqlAssignItem); - sqlList.add(Sql.builder().sql(sqlAlterTableStatement + ";").build()); - } - // 修改字段 - modifyColumn(sqlList, oldTable, newTable); - - // 修改索引 - modifyIndex(sqlList, oldTable, newTable); - return sqlList; - } - - private static void modifyColumn(List sqlList, Table oldTable, Table newTable) { - Map oldColumnMap = EasyCollectionUtils.toIdentityMap(oldTable.getColumnList(), - tableColumn -> { - if (tableColumn.getOldName() != null) { - return tableColumn.getOldName(); - } - return tableColumn.getName(); - }); - Map newColumnMap = EasyCollectionUtils.toIdentityMap(newTable.getColumnList(), - tableColumn -> { - if (tableColumn.getOldName() != null) { - return tableColumn.getOldName(); - } - return tableColumn.getName(); - }); - - SQLAlterTableStatement sqlAlterTableStatement = new SQLAlterTableStatement(); - sqlAlterTableStatement.setDbType(DbType.mysql); - sqlAlterTableStatement.setTableSource(new SQLIdentifierExpr(newTable.getName())); - - newColumnMap.forEach((newTableColumnName, newTableColumn) -> { - TableColumn oldTableColumn = oldColumnMap.get(newTableColumnName); - // 代表新增字段 - if (oldTableColumn == null) { - - SQLAlterTableAddColumn sqlAlterTableAddColumn = new SQLAlterTableAddColumn(); - sqlAlterTableStatement.addItem(sqlAlterTableAddColumn); - SQLColumnDefinition sqlColumnDefinition = new SQLColumnDefinition(); - sqlAlterTableAddColumn.addColumn(sqlColumnDefinition); - sqlColumnDefinition.setName(newTableColumn.getName()); - sqlColumnDefinition.setDataType(new SQLDataTypeImpl(newTableColumn.getColumnType())); - if (BooleanUtils.isNotTrue(newTableColumn.getNullable())) { - sqlColumnDefinition.addConstraint(new SQLNotNullConstraint()); - } - if (!Objects.isNull(newTableColumn.getDefaultValue())) { - sqlColumnDefinition.setDefaultExpr(new MySqlCharExpr(newTableColumn.getDefaultValue())); - } - sqlColumnDefinition.setAutoIncrement(BooleanUtils.isTrue(newTableColumn.getAutoIncrement())); - if (!Objects.isNull(newTableColumn.getComment())) { - sqlColumnDefinition.setComment(newTableColumn.getComment()); - } - return; - } - // 代表可能修改字段 或者没变 - boolean hasChange = !StringUtils.equals(oldTableColumn.getName(), newTableColumn.getName()) - || !StringUtils.equals(oldTableColumn.getColumnType(), newTableColumn.getColumnType()) - || !EasyBooleanUtils.equals(oldTableColumn.getNullable(), newTableColumn.getNullable(), Boolean.TRUE) - || !StringUtils.equals(oldTableColumn.getDefaultValue(), newTableColumn.getDefaultValue()) - || !EasyBooleanUtils.equals(oldTableColumn.getAutoIncrement(), newTableColumn.getAutoIncrement(), - Boolean.FALSE) - || !StringUtils.equals(oldTableColumn.getComment(), newTableColumn.getComment()); - - // 没有修改字段 - if (!hasChange) { - return; - } - - // 修改字段包含字段名 - if (!StringUtils.equals(oldTableColumn.getName(), newTableColumn.getName())) { - MySqlAlterTableChangeColumn mySqlAlterTableChangeColumn = new MySqlAlterTableChangeColumn(); - sqlAlterTableStatement.addItem(mySqlAlterTableChangeColumn); - mySqlAlterTableChangeColumn.setColumnName(new SQLIdentifierExpr(newTableColumn.getOldName())); - SQLColumnDefinition sqlColumnDefinition = new SQLColumnDefinition(); - mySqlAlterTableChangeColumn.setNewColumnDefinition(sqlColumnDefinition); - sqlColumnDefinition.setName(newTableColumn.getName()); - sqlColumnDefinition.setDataType(new SQLDataTypeImpl(newTableColumn.getColumnType())); - if (BooleanUtils.isNotTrue(newTableColumn.getNullable())) { - sqlColumnDefinition.addConstraint(new SQLNotNullConstraint()); - } - if (!Objects.isNull(newTableColumn.getDefaultValue())) { - sqlColumnDefinition.setDefaultExpr(new MySqlCharExpr(newTableColumn.getDefaultValue())); - } - sqlColumnDefinition.setAutoIncrement(BooleanUtils.isTrue(newTableColumn.getAutoIncrement())); - if (!Objects.isNull(newTableColumn.getComment())) { - sqlColumnDefinition.setComment(newTableColumn.getComment()); - } - } else { - // 修改字段不包括字段名 - MySqlAlterTableModifyColumn mySqlAlterTableModifyColumn = new MySqlAlterTableModifyColumn(); - sqlAlterTableStatement.addItem(mySqlAlterTableModifyColumn); - SQLColumnDefinition sqlColumnDefinition = new SQLColumnDefinition(); - mySqlAlterTableModifyColumn.setNewColumnDefinition(sqlColumnDefinition); - sqlColumnDefinition.setName(newTableColumn.getName()); - sqlColumnDefinition.setDataType(new SQLDataTypeImpl(newTableColumn.getColumnType())); - if (BooleanUtils.isNotTrue(newTableColumn.getNullable())) { - sqlColumnDefinition.addConstraint(new SQLNotNullConstraint()); - } - if (!Objects.isNull(newTableColumn.getDefaultValue())) { - sqlColumnDefinition.setDefaultExpr(new MySqlCharExpr(newTableColumn.getDefaultValue())); - } - sqlColumnDefinition.setAutoIncrement(BooleanUtils.isTrue(newTableColumn.getAutoIncrement())); - if (!Objects.isNull(newTableColumn.getComment())) { - sqlColumnDefinition.setComment(newTableColumn.getComment()); - } - } - }); - - oldColumnMap.forEach((oldTableColumnName, oldTableColumn) -> { - TableColumn newTableColumn = newColumnMap.get(oldTableColumnName); - // 代表删除字段 - if (newTableColumn == null) { - SQLAlterTableDropColumnItem sqlAlterTableDropColumnItem = new SQLAlterTableDropColumnItem(); - sqlAlterTableStatement.addItem(sqlAlterTableDropColumnItem); - sqlAlterTableDropColumnItem.addColumn(new SQLIdentifierExpr(oldTableColumn.getName())); - } - }); - - // 比较主键是否有修改 - // 主键 - Set oldPrimaryKeySet = EasyCollectionUtils.stream(oldTable.getColumnList()) - .filter(tableColumn -> BooleanUtils.isTrue(tableColumn.getPrimaryKey())) - .map(TableColumn::getName) - .collect(Collectors.toSet()); - Set newPrimaryKeySet = EasyCollectionUtils.stream(newTable.getColumnList()) - .filter(tableColumn -> BooleanUtils.isTrue(tableColumn.getPrimaryKey())) - .map(TableColumn::getName) - .collect(Collectors.toSet()); - boolean primaryKeyChange = oldPrimaryKeySet.stream() - .anyMatch(oldPrimaryKey -> !newPrimaryKeySet.contains(oldPrimaryKey)) - || newPrimaryKeySet.stream() - .anyMatch(newPrimaryKey -> !oldPrimaryKeySet.contains(newPrimaryKey)); - if (primaryKeyChange) { - sqlAlterTableStatement.addItem(new SQLAlterTableDropPrimaryKey()); - SQLAlterTableAddConstraint sqlAlterTableAddConstraint = new SQLAlterTableAddConstraint(); - sqlAlterTableStatement.addItem(sqlAlterTableAddConstraint); - MySqlPrimaryKey mySqlPrimaryKey = new MySqlPrimaryKey(); - sqlAlterTableAddConstraint.setConstraint(mySqlPrimaryKey); - mySqlPrimaryKey.setIndexType("PRIMARY"); - // 排序 - EasyCollectionUtils.stream(newTable.getColumnList()) - .filter(tableColumn -> BooleanUtils.isTrue(tableColumn.getPrimaryKey())) - .map(TableColumn::getName) - .forEach(tableColumnName -> mySqlPrimaryKey.addColumn( - new SQLSelectOrderByItem(new SQLIdentifierExpr(tableColumnName)))); - } - - if (CollectionUtils.isNotEmpty(sqlAlterTableStatement.getItems())) { - sqlList.add(Sql.builder().sql(sqlAlterTableStatement + ";").build()); - } - } - - private static void modifyIndex(List sqlList, Table oldTable, Table newTable) { - Map oldIndexMap = EasyCollectionUtils.toIdentityMap(oldTable.getIndexList(), - TableIndex::getName); - Map newIndexMap = EasyCollectionUtils.toIdentityMap(newTable.getIndexList(), - TableIndex::getName); - newIndexMap.forEach((newTableIndexName, newTableIndex) -> { - TableIndex oldTableIndex = oldIndexMap.get(newTableIndexName); - // 代表新增索引 - if (oldTableIndex == null) { - SQLCreateIndexStatement sqlCreateIndexStatement = new SQLCreateIndexStatement(); - sqlCreateIndexStatement.setTable(new SQLExprTableSource(newTable.getName())); - sqlCreateIndexStatement.setName(new SQLIdentifierExpr(newTableIndex.getName())); - if (!Objects.isNull(newTableIndex.getComment())) { - sqlCreateIndexStatement.setComment(new SQLCharExpr(newTableIndex.getComment())); - } - if (!CollectionUtils.isEmpty(newTableIndex.getColumnList())) { - for (TableIndexColumn tableIndexColumn : newTableIndex.getColumnList()) { - SQLSelectOrderByItem sqlSelectOrderByItem = new SQLSelectOrderByItem(); - sqlSelectOrderByItem.setExpr(new SQLIdentifierExpr(tableIndexColumn.getColumnName())); - CollationEnum collation = EasyEnumUtils.getEnum(CollationEnum.class, - tableIndexColumn.getCollation()); - if (collation != null) { - sqlSelectOrderByItem.setType(collation.getSqlOrderingSpecification()); - } - sqlCreateIndexStatement.getColumns().add(sqlSelectOrderByItem); - } - } - sqlList.add(Sql.builder().sql(sqlCreateIndexStatement + ";").build()); - return; - } - // 代表可能修改索引 或者没变 - boolean hasChange = !StringUtils.equals(oldTableIndex.getName(), newTableIndex.getName()) - || !StringUtils.equals(oldTableIndex.getComment(), newTableIndex.getComment()) - || !Objects.equals(oldTableIndex.getUnique(), newTableIndex.getUnique()); - if (!hasChange) { - Map oldTableIndexColumnMap = EasyCollectionUtils.toIdentityMap( - oldTableIndex.getColumnList(), TableIndexColumn::getColumnName); - Map newTableIndexColumnMap = EasyCollectionUtils.toIdentityMap( - newTableIndex.getColumnList(), TableIndexColumn::getColumnName); - hasChange = oldTableIndexColumnMap.entrySet() - .stream() - .anyMatch(oldTableIndexColumnEntry -> { - TableIndexColumn newTableIndexColumn = newTableIndexColumnMap.get( - oldTableIndexColumnEntry.getKey()); - if (newTableIndexColumn == null) { - return true; - } - TableIndexColumn oldTableIndexColumn = oldTableIndexColumnEntry.getValue(); - return !StringUtils.equals(oldTableIndexColumn.getColumnName(), - newTableIndexColumn.getColumnName()) - || !CollationEnum.equals(oldTableIndexColumn.getCollation(), - newTableIndexColumn.getCollation()); - }) - || newTableIndexColumnMap.entrySet() - .stream() - .anyMatch(newTableIndexColumnEntry -> { - TableIndexColumn oldTableIndexColumn = oldTableIndexColumnMap.get( - newTableIndexColumnEntry.getKey()); - return oldTableIndexColumn == null; - }); - } - - // 没有修改索引 - if (!hasChange) { - return; - } - // 先删除 - SQLDropIndexStatement sqlDropIndexStatement = new SQLDropIndexStatement(); - sqlDropIndexStatement.setDbType(DbType.mysql); - sqlDropIndexStatement.setTableName(new SQLExprTableSource(newTable.getName())); - sqlDropIndexStatement.setIndexName(new SQLIdentifierExpr(newTableIndex.getName())); - sqlList.add(Sql.builder().sql(sqlDropIndexStatement + ";").build()); - - // 再新增 - SQLCreateIndexStatement sqlCreateIndexStatement = new SQLCreateIndexStatement(); - sqlCreateIndexStatement.setTable(new SQLExprTableSource(newTable.getName())); - sqlCreateIndexStatement.setName(new SQLIdentifierExpr(newTableIndex.getName())); - if (!Objects.isNull(newTableIndex.getComment())) { - sqlCreateIndexStatement.setComment(new SQLCharExpr(newTableIndex.getComment())); - } - if (!CollectionUtils.isEmpty(newTableIndex.getColumnList())) { - for (TableIndexColumn tableIndexColumn : newTableIndex.getColumnList()) { - SQLSelectOrderByItem sqlSelectOrderByItem = new SQLSelectOrderByItem(); - sqlSelectOrderByItem.setExpr(new SQLIdentifierExpr(tableIndexColumn.getColumnName())); - CollationEnum collation = EasyEnumUtils.getEnum(CollationEnum.class, - tableIndexColumn.getCollation()); - if (collation != null) { - sqlSelectOrderByItem.setType(collation.getSqlOrderingSpecification()); - } - sqlCreateIndexStatement.getColumns().add(sqlSelectOrderByItem); - } - } - sqlList.add(Sql.builder().sql(sqlCreateIndexStatement + ";").build()); - }); - - oldIndexMap.forEach((oldTableIndexName, oldTableIndex) -> { - TableIndex newTableIndex = newIndexMap.get(oldTableIndexName); - // 代表删除索引 - if (newTableIndex == null) { - SQLDropIndexStatement sqlDropIndexStatement = new SQLDropIndexStatement(); - sqlDropIndexStatement.setDbType(DbType.mysql); - sqlDropIndexStatement.setTableName(new SQLExprTableSource(newTable.getName())); - sqlDropIndexStatement.setIndexName(new SQLIdentifierExpr(oldTableIndex.getName())); - sqlList.add(Sql.builder().sql(sqlDropIndexStatement + ";").build()); - } - }); - } - - public static String formatSQLString(Object para) { - return para != null ? " '" + para + "' " : null; - } -} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/com/alibaba/druid/sql/parser/DbhubSQLParserUtils.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/com/alibaba/druid/sql/parser/DbhubSQLParserUtils.java deleted file mode 100644 index 1729df124..000000000 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-support/src/main/java/com/alibaba/druid/sql/parser/DbhubSQLParserUtils.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.alibaba.druid.sql.parser; - -import ai.chat2db.server.domain.support.enums.DbTypeEnum; - -/** - * 临时的sql 解析工具类 - * 已经让druid改了 但是没上线 - * - * @author 是仪 - */ -public class DbhubSQLParserUtils extends SQLParserUtils { - - - public static String format(DbTypeEnum dbType, String tableName) { - if (DbTypeEnum.MYSQL.equals(dbType)) { - return "`" + tableName + "`"; - } else if (DbTypeEnum.ORACLE.equals(dbType)) { - return "\"" + tableName + "\""; - } else if (DbTypeEnum.POSTGRESQL.equals(dbType)) { - return "\"" + tableName + "\""; - } else if (DbTypeEnum.SQLITE.equals(dbType)) { - return "\"" + tableName + "\""; - } else if (DbTypeEnum.SQLSERVER.equals(dbType)) { - return "[" + tableName + "]"; - } else if (DbTypeEnum.H2.equals(dbType)) { - return "\"" + tableName + "\""; - } else { - return "\"" + tableName + "\""; - } - } - - public static String format(String dbType, String tableName) { - if (DbTypeEnum.MYSQL.getCode().equalsIgnoreCase(dbType)) { - return "`" + tableName + "`"; - } else if (DbTypeEnum.ORACLE.getCode().equalsIgnoreCase(dbType)) { - return "\"" + tableName + "\""; - } else if (DbTypeEnum.POSTGRESQL.getCode().equalsIgnoreCase(dbType)) { - return "\"" + tableName + "\""; - } else if (DbTypeEnum.SQLITE.getCode().equalsIgnoreCase(dbType)) { - return "\"" + tableName + "\""; - } else if (DbTypeEnum.SQLSERVER.getCode().equalsIgnoreCase(dbType)) { - return "[" + tableName + "]"; - } else if (DbTypeEnum.H2.getCode().equalsIgnoreCase(dbType)) { - return "\"" + tableName + "\""; - } else { - return "\"" + tableName + "\""; - } - } -} diff --git a/chat2db-server/chat2db-server-domain/pom.xml b/chat2db-server/chat2db-server-domain/pom.xml index fd4be348a..87702c06d 100644 --- a/chat2db-server/chat2db-server-domain/pom.xml +++ b/chat2db-server/chat2db-server-domain/pom.xml @@ -16,7 +16,6 @@ chat2db-server-domain-api chat2db-server-domain-core chat2db-server-domain-repository - chat2db-server-domain-support \ No newline at end of file From efbc31430df5c395b396ffa39170ca1359525cfe Mon Sep 17 00:00:00 2001 From: JiaJu Zhuang <5152853@qq.com> Date: Sun, 2 Jul 2023 21:38:41 +0800 Subject: [PATCH 09/13] release docker --- .github/workflows/pushdocker.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pushdocker.yml b/.github/workflows/pushdocker.yml index f4d371b8e..d5fbdc42a 100644 --- a/.github/workflows/pushdocker.yml +++ b/.github/workflows/pushdocker.yml @@ -35,19 +35,21 @@ jobs: run: | echo "current version: ${{ steps.chat2db_version.outputs.substring }}" - # 安装nodejs + # 安装node - name: Install Node.js uses: actions/setup-node@main with: node-version: 16 + cache: "yarn" + cache-dependency-path: chat2db-client/yarn.lock # 构建静态文件信息 - - name: Npm install & build & copy + - name: Yarn install & build & copy run: | cd chat2db-client - npm install - npm run build:desktop - mv dist ../chat2db-server/chat2db-server-start/src/main/resources/static/front + yarn install + yarn run build:web:prod --appVersion=${{ steps.chat2db_version.outputs.substring }} + cp -r dist ../chat2db-server/chat2db-server-start/src/main/resources/static/front # 安装java - name: Install Java and Maven From b755e2351040759d63d314ae0b4bb0061f8e65c1 Mon Sep 17 00:00:00 2001 From: JiaJu Zhuang <5152853@qq.com> Date: Sun, 2 Jul 2023 21:45:14 +0800 Subject: [PATCH 10/13] release docker --- .github/workflows/pushdocker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pushdocker.yml b/.github/workflows/pushdocker.yml index d5fbdc42a..4b1efa267 100644 --- a/.github/workflows/pushdocker.yml +++ b/.github/workflows/pushdocker.yml @@ -6,7 +6,6 @@ name: Push To Docker #on: # release: # types: [ published ] -on: [ push, pull_request ] # Workflow's jobs jobs: @@ -27,7 +26,8 @@ jobs: id: chat2db_version uses: bhowell2/github-substring-action@1.0.1 with: - value: 2.0.0 + value: ${{ github.ref }} + index_of_str: "refs/tags/v" # 输出基础信息 From 551c6e1dfded3392a3b0f09cadf24841153d6043 Mon Sep 17 00:00:00 2001 From: JiaJu Zhuang <5152853@qq.com> Date: Sun, 2 Jul 2023 21:50:29 +0800 Subject: [PATCH 11/13] release 2.0.0 --- README.md | 8 ++++---- README_CN.md | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 79f4e6372..18c4a34d2 100644 --- a/README.md +++ b/README.md @@ -47,10 +47,10 @@ https://github.com/chat2db/Chat2DB/assets/22975773/b58db908-5768-4a71-aa30-135d2 | Description | Download | |-----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------| -| Windows | [https://oss-chat2db.alibaba.com/release/1.0.11/Chat2DB%20Setup%201.0.11.exe](https://oss-chat2db.alibaba.com/release/1.0.11/Chat2DB%20Setup%201.0.11.exe) | -| MacOS ARM64 | [https://oss-chat2db.alibaba.com/release/1.0.11/Chat2DB-1.0.11-arm64.dmg](https://oss-chat2db.alibaba.com/release/1.0.11/Chat2DB-1.0.11-arm64.dmg) | -| MacOS X64 | [https://oss-chat2db.alibaba.com/release/1.0.11/Chat2DB-1.0.11.dmg](https://oss-chat2db.alibaba.com/release/1.0.11/Chat2DB-1.0.11.dmg) | -| Jar包 | [https://oss-chat2db.alibaba.com/release/1.0.11/chat2db-server-start.jar](https://oss-chat2db.alibaba.com/release/1.0.11/chat2db-server-start.jar) | +| Windows | [https://oss-chat2db.alibaba.com/release/2.0.0/Chat2DB%20Setup%202.0.0.exe](https://oss-chat2db.alibaba.com/release/2.0.0/Chat2DB%20Setup%202.0.0.exe) | +| MacOS ARM64 | [https://oss-chat2db.alibaba.com/release/2.0.0/Chat2DB-2.0.0-arm64.dmg](https://oss-chat2db.alibaba.com/release/2.0.0/Chat2DB-2.0.0-arm64.dmg) | +| MacOS X64 | [https://oss-chat2db.alibaba.com/release/2.0.0/Chat2DB-2.0.0.dmg](https://oss-chat2db.alibaba.com/release/2.0.0/Chat2DB-2.0.0.dmg) | +| Jar包 | [https://oss-chat2db.alibaba.com/release/2.0.0/chat2db-server-start.jar](https://oss-chat2db.alibaba.com/release/2.0.0/chat2db-server-start.jar) | ## 🚀 Supported databases | Databases | Status | diff --git a/README_CN.md b/README_CN.md index f3d09b131..cef529360 100644 --- a/README_CN.md +++ b/README_CN.md @@ -50,10 +50,10 @@ https://github.com/chat2db/Chat2DB/assets/22975773/b58db908-5768-4a71-aa30-135d2 ## ⏬ 下载安装 | 描述 | 下载地址 | |-----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------| -| Windows | [https://oss-chat2db.alibaba.com/release/1.0.11/Chat2DB%20Setup%201.0.11.exe](https://oss-chat2db.alibaba.com/release/1.0.10/Chat2DB%20Setup%201.0.10.exe) | -| MacOS ARM64 (Apple芯片) | [https://oss-chat2db.alibaba.com/release/1.0.11/Chat2DB-1.0.11-arm64.dmg](https://oss-chat2db.alibaba.com/release/1.0.10/Chat2DB-1.0.10-arm64.dmg) | -| MacOS X64 (Intel芯片) | [https://oss-chat2db.alibaba.com/release/1.0.11/Chat2DB-1.0.11.dmg](https://oss-chat2db.alibaba.com/release/1.0.10/Chat2DB-1.0.10.dmg) | -| Jar包 | [https://oss-chat2db.alibaba.com/release/1.0.11/chat2db-server-start.jar](https://oss-chat2db.alibaba.com/release/1.0.10/chat2db-server-start.jar) | +| Windows | [https://oss-chat2db.alibaba.com/release/2.0.0/Chat2DB%20Setup%202.0.0.exe](https://oss-chat2db.alibaba.com/release/2.0.0/Chat2DB%20Setup%202.0.0.exe) | +| MacOS ARM64 (Apple芯片) | [https://oss-chat2db.alibaba.com/release/2.0.0/Chat2DB-2.0.0-arm64.dmg](https://oss-chat2db.alibaba.com/release/2.0.0/Chat2DB-2.0.0-arm64.dmg) | +| MacOS X64 (Intel芯片) | [https://oss-chat2db.alibaba.com/release/2.0.0/Chat2DB-2.0.0.dmg](https://oss-chat2db.alibaba.com/release/2.0.0/Chat2DB-2.0.0.dmg) | +| Jar包 | [https://oss-chat2db.alibaba.com/release/2.0.0/chat2db-server-start.jar](https://oss-chat2db.alibaba.com/release/2.0.0/chat2db-server-start.jar) | ## 🚀 支持的数据库 | 数据库 | 支持计划 | From 4ff242169be53e56883a60c82157f490b42fa6f7 Mon Sep 17 00:00:00 2001 From: JiaJu Zhuang <5152853@qq.com> Date: Sun, 2 Jul 2023 22:03:09 +0800 Subject: [PATCH 12/13] release 2.0.0 --- .github/workflows/pushdocker.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pushdocker.yml b/.github/workflows/pushdocker.yml index 4b1efa267..aa092c2b9 100644 --- a/.github/workflows/pushdocker.yml +++ b/.github/workflows/pushdocker.yml @@ -3,9 +3,9 @@ name: Push To Docker # Workflow's trigger -#on: -# release: -# types: [ published ] +on: + release: + types: [ published ] # Workflow's jobs jobs: From 3607f91ae38d226887f44b16e198c10c592963ab Mon Sep 17 00:00:00 2001 From: jipengfei-jpf <1558143046@qq.com> Date: Sun, 2 Jul 2023 22:08:38 +0800 Subject: [PATCH 13/13] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 18c4a34d2..8b01c804d 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,10 @@ Languages: English | [中文](README_CN.md) + ## DEMO -https://github.com/chat2db/Chat2DB/assets/22975773/b58db908-5768-4a71-aa30-135d202e505f +https://github.com/chat2db/Chat2DB/assets/22975773/79e9dded-375b-44cf-9979-bb7572465a2e ## 📖 Introduction