diff --git a/dbswitch-common/src/main/java/com/gitee/dbswitch/common/type/ProductTypeEnum.java b/dbswitch-common/src/main/java/com/gitee/dbswitch/common/type/ProductTypeEnum.java index 77da917e..94281e64 100644 --- a/dbswitch-common/src/main/java/com/gitee/dbswitch/common/type/ProductTypeEnum.java +++ b/dbswitch-common/src/main/java/com/gitee/dbswitch/common/type/ProductTypeEnum.java @@ -128,6 +128,14 @@ public enum ProductTypeEnum { "SELECT 1", "jdbc:sqlite:", new String[]{"jdbc:sqlite:{file}", "jdbc:sqlite::resource:{file}"}), + + /** + * OpenGauss数据库类型 + */ + OPENGAUSS(14, "\"", "opengauss", "org.opengauss.Driver", 15432, + "SELECT 1", + "jdbc:opengauss://", + new String[]{"jdbc:opengauss://{host}[:{port}]/[{database}][\\?{params}]"}), ; private int id; @@ -176,7 +184,7 @@ public enum ProductTypeEnum { * @return boolean */ public boolean isLikePostgres() { - return this == POSTGRESQL || this == KINGBASE; + return this == POSTGRESQL || this == KINGBASE || this == OPENGAUSS; } /** diff --git a/dbswitch-common/src/main/java/com/gitee/dbswitch/common/util/DatabaseAwareUtils.java b/dbswitch-common/src/main/java/com/gitee/dbswitch/common/util/DatabaseAwareUtils.java index 5ffc9078..8bae2370 100644 --- a/dbswitch-common/src/main/java/com/gitee/dbswitch/common/util/DatabaseAwareUtils.java +++ b/dbswitch-common/src/main/java/com/gitee/dbswitch/common/util/DatabaseAwareUtils.java @@ -75,7 +75,14 @@ public final class DatabaseAwareUtils { String productName = connection.getMetaData().getDatabaseProductName(); String driverName = connection.getMetaData().getDriverName(); if (driverNameMap.containsKey(driverName)) { - return driverNameMap.get(driverName); + ProductTypeEnum productType = driverNameMap.get(driverName); + if (productType == ProductTypeEnum.POSTGRESQL) { + String url = connection.getMetaData().getURL(); + if (null != url && url.contains("opengauss")) { + return ProductTypeEnum.OPENGAUSS; + } + } + return productType; } ProductTypeEnum type = productNameMap.get(productName); diff --git a/dbswitch-product/dbswitch-product-opengauss/pom.xml b/dbswitch-product/dbswitch-product-opengauss/pom.xml new file mode 100644 index 00000000..34566687 --- /dev/null +++ b/dbswitch-product/dbswitch-product-opengauss/pom.xml @@ -0,0 +1,34 @@ + + + + dbswitch-product + com.gitee.dbswitch + 1.8.0 + + 4.0.0 + + dbswitch-product-openguass + + + + com.gitee.dbswitch + dbswitch-common + ${project.version} + + + + com.gitee.dbswitch + dbswitch-core + ${project.version} + + + + com.gitee.dbswitch + dbswitch-product-postgresql + ${project.version} + + + + \ No newline at end of file diff --git a/dbswitch-product/dbswitch-product-opengauss/src/main/java/com/gitee/dbswitch/product/openguass/OpenGaussFactoryProvider.java b/dbswitch-product/dbswitch-product-opengauss/src/main/java/com/gitee/dbswitch/product/openguass/OpenGaussFactoryProvider.java new file mode 100644 index 00000000..54e00576 --- /dev/null +++ b/dbswitch-product/dbswitch-product-opengauss/src/main/java/com/gitee/dbswitch/product/openguass/OpenGaussFactoryProvider.java @@ -0,0 +1,54 @@ +// Copyright tang. All rights reserved. +// https://gitee.com/inrgihc/dbswitch +// +// Use of this source code is governed by a BSD-style license +// +// Author: tang (inrgihc@126.com) +// Date : 2020/1/2 +// Location: beijing , china +///////////////////////////////////////////////////////////// +package com.gitee.dbswitch.product.openguass; + +import com.gitee.dbswitch.annotation.Product; +import com.gitee.dbswitch.common.type.ProductTypeEnum; +import com.gitee.dbswitch.features.ProductFeatures; +import com.gitee.dbswitch.product.postgresql.PostgresTableInsertWriterProvider; +import com.gitee.dbswitch.product.postgresql.PostgresTableSynchronizer; +import com.gitee.dbswitch.provider.AbstractFactoryProvider; +import com.gitee.dbswitch.provider.meta.MetadataProvider; +import com.gitee.dbswitch.provider.operate.TableOperateProvider; +import com.gitee.dbswitch.provider.sync.TableDataSynchronizer; +import com.gitee.dbswitch.provider.write.TableDataWriteProvider; +import javax.sql.DataSource; + +@Product(ProductTypeEnum.OPENGAUSS) +public class OpenGaussFactoryProvider extends AbstractFactoryProvider { + + public OpenGaussFactoryProvider(DataSource dataSource) { + super(dataSource); + } + + public ProductFeatures getProductFeatures() { + return new OpenGaussFeatures(); + } + + @Override + public MetadataProvider createMetadataQueryProvider() { + return new OpenGaussMetadataQueryProvider(this); + } + + @Override + public TableOperateProvider createTableOperateProvider() { + return new OpenGaussTableOperateProvider(this); + } + + @Override + public TableDataWriteProvider createTableDataWriteProvider(boolean useInsert) { + return new PostgresTableInsertWriterProvider(this); + } + + @Override + public TableDataSynchronizer createTableDataSynchronizer() { + return new PostgresTableSynchronizer(this); + } +} diff --git a/dbswitch-product/dbswitch-product-opengauss/src/main/java/com/gitee/dbswitch/product/openguass/OpenGaussFeatures.java b/dbswitch-product/dbswitch-product-opengauss/src/main/java/com/gitee/dbswitch/product/openguass/OpenGaussFeatures.java new file mode 100644 index 00000000..015c49c3 --- /dev/null +++ b/dbswitch-product/dbswitch-product-opengauss/src/main/java/com/gitee/dbswitch/product/openguass/OpenGaussFeatures.java @@ -0,0 +1,16 @@ +// Copyright tang. All rights reserved. +// https://gitee.com/inrgihc/dbswitch +// +// Use of this source code is governed by a BSD-style license +// +// Author: tang (inrgihc@126.com) +// Date : 2020/1/2 +// Location: beijing , china +///////////////////////////////////////////////////////////// +package com.gitee.dbswitch.product.openguass; + +import com.gitee.dbswitch.features.ProductFeatures; + +public class OpenGaussFeatures implements ProductFeatures { + +} diff --git a/dbswitch-product/dbswitch-product-opengauss/src/main/java/com/gitee/dbswitch/product/openguass/OpenGaussMetadataQueryProvider.java b/dbswitch-product/dbswitch-product-opengauss/src/main/java/com/gitee/dbswitch/product/openguass/OpenGaussMetadataQueryProvider.java new file mode 100644 index 00000000..bf2f3aed --- /dev/null +++ b/dbswitch-product/dbswitch-product-opengauss/src/main/java/com/gitee/dbswitch/product/openguass/OpenGaussMetadataQueryProvider.java @@ -0,0 +1,51 @@ +// Copyright tang. All rights reserved. +// https://gitee.com/inrgihc/dbswitch +// +// Use of this source code is governed by a BSD-style license +// +// Author: tang (inrgihc@126.com) +// Date : 2020/1/2 +// Location: beijing , china +///////////////////////////////////////////////////////////// +package com.gitee.dbswitch.product.openguass; + +import com.gitee.dbswitch.product.postgresql.PostgresMetadataQueryProvider; +import com.gitee.dbswitch.provider.ProductFactoryProvider; +import java.sql.Connection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +public class OpenGaussMetadataQueryProvider extends PostgresMetadataQueryProvider { + + private static Set systemSchemas = new HashSet<>(); + + static { + systemSchemas.add("blockchain"); + systemSchemas.add("cstore"); + systemSchemas.add("db4ai"); + systemSchemas.add("dbe_perf"); + systemSchemas.add("dbe_pldebugger"); + systemSchemas.add("dbe_pldeveloper"); + systemSchemas.add("dbe_sql_util"); + systemSchemas.add("information_schema"); + systemSchemas.add("pg_catalog"); + systemSchemas.add("pkg_service"); + systemSchemas.add("snapshot"); + systemSchemas.add("sqladvisor"); + } + + public OpenGaussMetadataQueryProvider(ProductFactoryProvider factoryProvider) { + super(factoryProvider); + } + + @Override + public List querySchemaList(Connection connection) { + List schemas = super.querySchemaList(connection); + return schemas.stream() + .filter(s -> !systemSchemas.contains(s)) + .collect(Collectors.toList()); + } + +} diff --git a/dbswitch-product/dbswitch-product-opengauss/src/main/java/com/gitee/dbswitch/product/openguass/OpenGaussTableOperateProvider.java b/dbswitch-product/dbswitch-product-opengauss/src/main/java/com/gitee/dbswitch/product/openguass/OpenGaussTableOperateProvider.java new file mode 100644 index 00000000..a7ecb898 --- /dev/null +++ b/dbswitch-product/dbswitch-product-opengauss/src/main/java/com/gitee/dbswitch/product/openguass/OpenGaussTableOperateProvider.java @@ -0,0 +1,28 @@ +// Copyright tang. All rights reserved. +// https://gitee.com/inrgihc/dbswitch +// +// Use of this source code is governed by a BSD-style license +// +// Author: tang (inrgihc@126.com) +// Date : 2020/1/2 +// Location: beijing , china +///////////////////////////////////////////////////////////// +package com.gitee.dbswitch.product.openguass; + +import com.gitee.dbswitch.provider.ProductFactoryProvider; +import com.gitee.dbswitch.provider.operate.DefaultTableOperateProvider; + +public class OpenGaussTableOperateProvider extends DefaultTableOperateProvider { + + public OpenGaussTableOperateProvider(ProductFactoryProvider factoryProvider) { + super(factoryProvider); + } + + @Override + public void dropTable(String schemaName, String tableName) { + String sql = String.format("DROP TABLE \"%s\".\"%s\" CASCADE ", + schemaName, tableName); + this.executeSql(sql); + } + +} diff --git a/dbswitch-product/dbswitch-product-opengauss/src/main/resources/META-INF/services/dbswitch.providers b/dbswitch-product/dbswitch-product-opengauss/src/main/resources/META-INF/services/dbswitch.providers new file mode 100644 index 00000000..606e1b1e --- /dev/null +++ b/dbswitch-product/dbswitch-product-opengauss/src/main/resources/META-INF/services/dbswitch.providers @@ -0,0 +1 @@ +com.gitee.dbswitch.product.openguass.OpenGaussFactoryProvider \ No newline at end of file diff --git a/dbswitch-product/dbswitch-register-product/pom.xml b/dbswitch-product/dbswitch-register-product/pom.xml index 47349bcf..bb34c79e 100644 --- a/dbswitch-product/dbswitch-register-product/pom.xml +++ b/dbswitch-product/dbswitch-register-product/pom.xml @@ -78,6 +78,11 @@ ${project.version} + + com.gitee.dbswitch + dbswitch-product-openguass + ${project.version} + \ No newline at end of file diff --git a/dbswitch-product/pom.xml b/dbswitch-product/pom.xml index 388a6ae7..306e2899 100644 --- a/dbswitch-product/pom.xml +++ b/dbswitch-product/pom.xml @@ -25,6 +25,7 @@ dbswitch-product-mariadb dbswitch-product-hive dbswitch-product-gbase + dbswitch-product-opengauss dbswitch-register-product diff --git a/drivers/opengauss/opengauss-3.0.0/opengauss-jdbc-3.0.0.jar b/drivers/opengauss/opengauss-3.0.0/opengauss-jdbc-3.0.0.jar new file mode 100644 index 00000000..8e731e5b Binary files /dev/null and b/drivers/opengauss/opengauss-3.0.0/opengauss-jdbc-3.0.0.jar differ