mirror of
https://gitee.com/dromara/dbswitch.git
synced 2025-09-10 14:09:06 +00:00
代码逻辑梳理调整
This commit is contained in:
@@ -170,10 +170,67 @@ public enum ProductTypeEnum {
|
|||||||
return String.format("%s%s%s.%s%s%s", quote, schema, quote, quote, table, quote);
|
return String.format("%s%s%s.%s%s%s", quote, schema, quote, quote, table, quote);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类似于PostgreSQL系列的数据库类型
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean isLikePostgres() {
|
||||||
|
return this == POSTGRESQL || this == KINGBASE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类似于MySQL系列的数据库类型
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean isLikeMysql() {
|
||||||
|
return this == MYSQL || this == MARIADB || this == GBASE8A;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类似于Oracle系列的数据库类型
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean isLikeOracle() {
|
||||||
|
return this == ORACLE || this == DM;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类似于SQL Server系列的数据库类型
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean isLikeSqlServer() {
|
||||||
|
return this == SQLSERVER || this == SYBASE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类似于Hive系列的数据库类型
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean isLikeHive() {
|
||||||
|
return this == HIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否存在指定字符串名称的数据库类型
|
||||||
|
*
|
||||||
|
* @param name 字符串名称
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
public static boolean exists(String name) {
|
public static boolean exists(String name) {
|
||||||
return Arrays.stream(values()).anyMatch(item -> item.name().equalsIgnoreCase(name));
|
return Arrays.stream(values()).anyMatch(item -> item.name().equalsIgnoreCase(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将字符串名称转换为枚举值
|
||||||
|
*
|
||||||
|
* @param name 字符串名称
|
||||||
|
* @return ProductTypeEnum
|
||||||
|
*/
|
||||||
public static ProductTypeEnum of(String name) {
|
public static ProductTypeEnum of(String name) {
|
||||||
if (!StringUtils.isEmpty(name)) {
|
if (!StringUtils.isEmpty(name)) {
|
||||||
for (ProductTypeEnum type : ProductTypeEnum.values()) {
|
for (ProductTypeEnum type : ProductTypeEnum.values()) {
|
||||||
@@ -186,6 +243,12 @@ public enum ProductTypeEnum {
|
|||||||
throw new IllegalArgumentException("cannot find enum name: " + name);
|
throw new IllegalArgumentException("cannot find enum name: " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 针对SQLite数据库的URL连接串判断
|
||||||
|
*
|
||||||
|
* @param url SQLite数据库的URL连接串
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
public static boolean isUnsupportedTargetSqlite(String url) {
|
public static boolean isUnsupportedTargetSqlite(String url) {
|
||||||
String prefix1 = "jdbc:sqlite::resource:";
|
String prefix1 = "jdbc:sqlite::resource:";
|
||||||
//String prefix2 = "jdbc:sqlite::memory:";
|
//String prefix2 = "jdbc:sqlite::memory:";
|
||||||
|
@@ -0,0 +1,14 @@
|
|||||||
|
package com.gitee.dbswitch.annotation;
|
||||||
|
|
||||||
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Target({ElementType.TYPE})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface Product {
|
||||||
|
|
||||||
|
ProductTypeEnum value();
|
||||||
|
}
|
@@ -9,7 +9,10 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.provider;
|
package com.gitee.dbswitch.provider;
|
||||||
|
|
||||||
|
import com.gitee.dbswitch.annotation.Product;
|
||||||
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.common.util.ExamineUtils;
|
import com.gitee.dbswitch.common.util.ExamineUtils;
|
||||||
|
import java.util.Objects;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
public abstract class AbstractFactoryProvider implements ProductFactoryProvider {
|
public abstract class AbstractFactoryProvider implements ProductFactoryProvider {
|
||||||
@@ -25,4 +28,13 @@ public abstract class AbstractFactoryProvider implements ProductFactoryProvider
|
|||||||
return this.dataSource;
|
return this.dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final ProductTypeEnum getProductType() {
|
||||||
|
Product annotation = getClass().getAnnotation(Product.class);
|
||||||
|
if (Objects.isNull(annotation)) {
|
||||||
|
throw new RuntimeException("Should use Product annotation for class :" + getClass().getName());
|
||||||
|
}
|
||||||
|
return annotation.value();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,6 @@
|
|||||||
package com.gitee.dbswitch.schema;
|
package com.gitee.dbswitch.schema;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.consts.Constants;
|
import com.gitee.dbswitch.common.consts.Constants;
|
||||||
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据库表列的元信息
|
* 数据库表列的元信息
|
||||||
@@ -349,8 +348,7 @@ public class ColumnMetaData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we're dealing with PostgreSQL and double precision types
|
// If we're dealing with PostgreSQL and double precision types
|
||||||
if ((desc.getProductType() == ProductTypeEnum.POSTGRESQL
|
if ((desc.getProductType().isLikePostgres())
|
||||||
|| desc.getProductType() == ProductTypeEnum.KINGBASE)
|
|
||||||
&& type == java.sql.Types.DOUBLE
|
&& type == java.sql.Types.DOUBLE
|
||||||
&& precision >= 16
|
&& precision >= 16
|
||||||
&& length >= 16) {
|
&& length >= 16) {
|
||||||
@@ -360,8 +358,7 @@ public class ColumnMetaData {
|
|||||||
|
|
||||||
// MySQL: max resolution is double precision floating point (double)
|
// MySQL: max resolution is double precision floating point (double)
|
||||||
// The (12,31) that is given back is not correct
|
// The (12,31) that is given back is not correct
|
||||||
if (desc.getProductType() == ProductTypeEnum.MYSQL
|
if (desc.getProductType().isLikeMysql()) {
|
||||||
|| desc.getProductType() == ProductTypeEnum.MARIADB) {
|
|
||||||
if (precision >= length) {
|
if (precision >= length) {
|
||||||
precision = -1;
|
precision = -1;
|
||||||
length = -1;
|
length = -1;
|
||||||
@@ -369,7 +366,7 @@ public class ColumnMetaData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we're dealing with Hive and double/float precision types
|
// If we're dealing with Hive and double/float precision types
|
||||||
if (desc.getProductType() == ProductTypeEnum.HIVE) {
|
if (desc.getProductType().isLikeHive()) {
|
||||||
if (type == java.sql.Types.DOUBLE
|
if (type == java.sql.Types.DOUBLE
|
||||||
&& precision >= 15
|
&& precision >= 15
|
||||||
&& length >= 15) {
|
&& length >= 15) {
|
||||||
@@ -400,8 +397,7 @@ public class ColumnMetaData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (desc.getProductType() == ProductTypeEnum.POSTGRESQL
|
if (desc.getProductType().isLikePostgres()) {
|
||||||
|| desc.getProductType() == ProductTypeEnum.KINGBASE) {
|
|
||||||
// undefined size => arbitrary precision
|
// undefined size => arbitrary precision
|
||||||
if (type == java.sql.Types.NUMERIC && length == 0 && precision == 0) {
|
if (type == java.sql.Types.NUMERIC && length == 0 && precision == 0) {
|
||||||
valtype = ColumnMetaData.TYPE_BIGNUMBER;
|
valtype = ColumnMetaData.TYPE_BIGNUMBER;
|
||||||
@@ -410,8 +406,7 @@ public class ColumnMetaData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (desc.getProductType() == ProductTypeEnum.ORACLE ||
|
if (desc.getProductType().isLikeOracle()) {
|
||||||
desc.getProductType() == ProductTypeEnum.DM) {
|
|
||||||
if (precision == 0 && length == 38) {
|
if (precision == 0 && length == 38) {
|
||||||
valtype = ColumnMetaData.TYPE_INTEGER;
|
valtype = ColumnMetaData.TYPE_INTEGER;
|
||||||
}
|
}
|
||||||
|
@@ -69,7 +69,7 @@
|
|||||||
</includes>
|
</includes>
|
||||||
</fileSet>
|
</fileSet>
|
||||||
|
|
||||||
<!-- 将模块dbswitch-core的jar文件放到打包目录/lib 下 -->
|
<!-- 将模块dbswitch-data的jar文件放到打包目录/lib 下 -->
|
||||||
<fileSet>
|
<fileSet>
|
||||||
<directory>${project.parent.basedir}/dbswitch-data/target</directory>
|
<directory>${project.parent.basedir}/dbswitch-data/target</directory>
|
||||||
<outputDirectory>lib</outputDirectory>
|
<outputDirectory>lib</outputDirectory>
|
||||||
@@ -88,9 +88,9 @@
|
|||||||
</includes>
|
</includes>
|
||||||
</fileSet>
|
</fileSet>
|
||||||
|
|
||||||
<!-- 将模块dbswitch-product-repository的jar文件放到打包目录/lib 下 -->
|
<!-- 将模块dbswitch-product下的jar文件放到打包目录/lib 下 -->
|
||||||
<fileSet>
|
<fileSet>
|
||||||
<directory>${project.parent.basedir}/dbswitch-product/dbswitch-product-repository/target
|
<directory>${project.parent.basedir}/dbswitch-product/dbswitch-register-product/target
|
||||||
</directory>
|
</directory>
|
||||||
<outputDirectory>lib</outputDirectory>
|
<outputDirectory>lib</outputDirectory>
|
||||||
<includes>
|
<includes>
|
||||||
@@ -98,7 +98,6 @@
|
|||||||
</includes>
|
</includes>
|
||||||
</fileSet>
|
</fileSet>
|
||||||
|
|
||||||
|
|
||||||
<!-- 将模块drivers驱动等打包目录/drivers 下 -->
|
<!-- 将模块drivers驱动等打包目录/drivers 下 -->
|
||||||
<fileSet>
|
<fileSet>
|
||||||
<directory>${project.parent.basedir}/drivers/
|
<directory>${project.parent.basedir}/drivers/
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.product.db2;
|
package com.gitee.dbswitch.product.db2;
|
||||||
|
|
||||||
|
import com.gitee.dbswitch.annotation.Product;
|
||||||
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.features.ProductFeatures;
|
import com.gitee.dbswitch.features.ProductFeatures;
|
||||||
import com.gitee.dbswitch.provider.AbstractFactoryProvider;
|
import com.gitee.dbswitch.provider.AbstractFactoryProvider;
|
||||||
@@ -18,17 +19,13 @@ import com.gitee.dbswitch.provider.sync.TableDataSynchronizer;
|
|||||||
import com.gitee.dbswitch.provider.write.TableDataWriteProvider;
|
import com.gitee.dbswitch.provider.write.TableDataWriteProvider;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
@Product(ProductTypeEnum.DB2)
|
||||||
public class DB2FactoryProvider extends AbstractFactoryProvider {
|
public class DB2FactoryProvider extends AbstractFactoryProvider {
|
||||||
|
|
||||||
public DB2FactoryProvider(DataSource dataSource) {
|
public DB2FactoryProvider(DataSource dataSource) {
|
||||||
super(dataSource);
|
super(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProductTypeEnum getProductType() {
|
|
||||||
return ProductTypeEnum.DB2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProductFeatures getProductFeatures() {
|
public ProductFeatures getProductFeatures() {
|
||||||
return new DB2Features();
|
return new DB2Features();
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1 @@
|
|||||||
|
com.gitee.dbswitch.product.db2.DB2FactoryProvider
|
@@ -9,6 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.product.dm;
|
package com.gitee.dbswitch.product.dm;
|
||||||
|
|
||||||
|
import com.gitee.dbswitch.annotation.Product;
|
||||||
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.features.ProductFeatures;
|
import com.gitee.dbswitch.features.ProductFeatures;
|
||||||
import com.gitee.dbswitch.provider.AbstractFactoryProvider;
|
import com.gitee.dbswitch.provider.AbstractFactoryProvider;
|
||||||
@@ -18,17 +19,13 @@ import com.gitee.dbswitch.provider.sync.TableDataSynchronizer;
|
|||||||
import com.gitee.dbswitch.provider.write.TableDataWriteProvider;
|
import com.gitee.dbswitch.provider.write.TableDataWriteProvider;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
@Product(ProductTypeEnum.DM)
|
||||||
public class DmFactoryProvider extends AbstractFactoryProvider {
|
public class DmFactoryProvider extends AbstractFactoryProvider {
|
||||||
|
|
||||||
public DmFactoryProvider(DataSource dataSource) {
|
public DmFactoryProvider(DataSource dataSource) {
|
||||||
super(dataSource);
|
super(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProductTypeEnum getProductType() {
|
|
||||||
return ProductTypeEnum.DM;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProductFeatures getProductFeatures() {
|
public ProductFeatures getProductFeatures() {
|
||||||
return new DmFeatures();
|
return new DmFeatures();
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1 @@
|
|||||||
|
com.gitee.dbswitch.product.dm.DmFactoryProvider
|
@@ -9,33 +9,29 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.product.gbase;
|
package com.gitee.dbswitch.product.gbase;
|
||||||
|
|
||||||
|
import com.gitee.dbswitch.annotation.Product;
|
||||||
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.features.ProductFeatures;
|
import com.gitee.dbswitch.features.ProductFeatures;
|
||||||
import com.gitee.dbswitch.product.mysql.MysqlMetadataQueryProvider;
|
|
||||||
import com.gitee.dbswitch.product.mysql.MysqlTableSynchronizer;
|
import com.gitee.dbswitch.product.mysql.MysqlTableSynchronizer;
|
||||||
import com.gitee.dbswitch.provider.AbstractFactoryProvider;
|
import com.gitee.dbswitch.provider.AbstractFactoryProvider;
|
||||||
import com.gitee.dbswitch.provider.meta.MetadataProvider;
|
import com.gitee.dbswitch.provider.meta.MetadataProvider;
|
||||||
import com.gitee.dbswitch.provider.sync.TableDataSynchronizer;
|
import com.gitee.dbswitch.provider.sync.TableDataSynchronizer;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
@Product(ProductTypeEnum.GBASE8A)
|
||||||
public class GbaseFactoryProvider extends AbstractFactoryProvider {
|
public class GbaseFactoryProvider extends AbstractFactoryProvider {
|
||||||
|
|
||||||
public GbaseFactoryProvider(DataSource dataSource) {
|
public GbaseFactoryProvider(DataSource dataSource) {
|
||||||
super(dataSource);
|
super(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProductTypeEnum getProductType() {
|
|
||||||
return ProductTypeEnum.GBASE8A;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProductFeatures getProductFeatures() {
|
public ProductFeatures getProductFeatures() {
|
||||||
return new GbaseFeatures();
|
return new GbaseFeatures();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MetadataProvider createMetadataQueryProvider() {
|
public MetadataProvider createMetadataQueryProvider() {
|
||||||
return new MysqlMetadataQueryProvider(this);
|
return new GbaseMetadataQueryProvider(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -0,0 +1,35 @@
|
|||||||
|
package com.gitee.dbswitch.product.gbase;
|
||||||
|
|
||||||
|
import com.gitee.dbswitch.common.util.JdbcUrlUtils;
|
||||||
|
import com.gitee.dbswitch.product.mysql.MysqlMetadataQueryProvider;
|
||||||
|
import com.gitee.dbswitch.provider.ProductFactoryProvider;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
|
||||||
|
public class GbaseMetadataQueryProvider extends MysqlMetadataQueryProvider {
|
||||||
|
|
||||||
|
public GbaseMetadataQueryProvider(ProductFactoryProvider factoryProvider) {
|
||||||
|
super(factoryProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> querySchemaList(Connection connection) {
|
||||||
|
try {
|
||||||
|
final Matcher matcher = JdbcUrlUtils
|
||||||
|
.getPattern("jdbc:gbase:://{host}[:{port}]/[{database}][\\?{params}]")
|
||||||
|
.matcher(connection.getMetaData().getURL());
|
||||||
|
if (matcher.matches()) {
|
||||||
|
return Collections.singletonList(matcher.group("database"));
|
||||||
|
}
|
||||||
|
throw new RuntimeException("get database name from jdbc url failed!");
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1 @@
|
|||||||
|
com.gitee.dbswitch.product.gbase.GbaseFactoryProvider
|
@@ -9,6 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.product.hive;
|
package com.gitee.dbswitch.product.hive;
|
||||||
|
|
||||||
|
import com.gitee.dbswitch.annotation.Product;
|
||||||
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.features.ProductFeatures;
|
import com.gitee.dbswitch.features.ProductFeatures;
|
||||||
import com.gitee.dbswitch.provider.AbstractFactoryProvider;
|
import com.gitee.dbswitch.provider.AbstractFactoryProvider;
|
||||||
@@ -16,17 +17,13 @@ import com.gitee.dbswitch.provider.meta.MetadataProvider;
|
|||||||
import com.gitee.dbswitch.provider.query.TableDataQueryProvider;
|
import com.gitee.dbswitch.provider.query.TableDataQueryProvider;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
@Product(ProductTypeEnum.HIVE)
|
||||||
public class HiveFactoryProvider extends AbstractFactoryProvider {
|
public class HiveFactoryProvider extends AbstractFactoryProvider {
|
||||||
|
|
||||||
public HiveFactoryProvider(DataSource dataSource) {
|
public HiveFactoryProvider(DataSource dataSource) {
|
||||||
super(dataSource);
|
super(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProductTypeEnum getProductType() {
|
|
||||||
return ProductTypeEnum.HIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProductFeatures getProductFeatures() {
|
public ProductFeatures getProductFeatures() {
|
||||||
return new HiveFeatures();
|
return new HiveFeatures();
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1 @@
|
|||||||
|
com.gitee.dbswitch.product.hive.HiveFactoryProvider
|
@@ -9,6 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.product.kingbase;
|
package com.gitee.dbswitch.product.kingbase;
|
||||||
|
|
||||||
|
import com.gitee.dbswitch.annotation.Product;
|
||||||
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.features.ProductFeatures;
|
import com.gitee.dbswitch.features.ProductFeatures;
|
||||||
import com.gitee.dbswitch.product.postgresql.PostgresTableOperateProvider;
|
import com.gitee.dbswitch.product.postgresql.PostgresTableOperateProvider;
|
||||||
@@ -20,17 +21,13 @@ import com.gitee.dbswitch.provider.sync.TableDataSynchronizer;
|
|||||||
import com.gitee.dbswitch.provider.write.TableDataWriteProvider;
|
import com.gitee.dbswitch.provider.write.TableDataWriteProvider;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
@Product(ProductTypeEnum.KINGBASE)
|
||||||
public class KingbaseFactoryProvider extends AbstractFactoryProvider {
|
public class KingbaseFactoryProvider extends AbstractFactoryProvider {
|
||||||
|
|
||||||
public KingbaseFactoryProvider(DataSource dataSource) {
|
public KingbaseFactoryProvider(DataSource dataSource) {
|
||||||
super(dataSource);
|
super(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProductTypeEnum getProductType() {
|
|
||||||
return ProductTypeEnum.KINGBASE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProductFeatures getProductFeatures() {
|
public ProductFeatures getProductFeatures() {
|
||||||
return new KingbaseFeatures();
|
return new KingbaseFeatures();
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1 @@
|
|||||||
|
com.gitee.dbswitch.product.kingbase.KingbaseFactoryProvider
|
@@ -9,6 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.product.mariadb;
|
package com.gitee.dbswitch.product.mariadb;
|
||||||
|
|
||||||
|
import com.gitee.dbswitch.annotation.Product;
|
||||||
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.features.ProductFeatures;
|
import com.gitee.dbswitch.features.ProductFeatures;
|
||||||
import com.gitee.dbswitch.product.mysql.MysqlMetadataQueryProvider;
|
import com.gitee.dbswitch.product.mysql.MysqlMetadataQueryProvider;
|
||||||
@@ -18,17 +19,13 @@ import com.gitee.dbswitch.provider.meta.MetadataProvider;
|
|||||||
import com.gitee.dbswitch.provider.sync.TableDataSynchronizer;
|
import com.gitee.dbswitch.provider.sync.TableDataSynchronizer;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
@Product(ProductTypeEnum.MARIADB)
|
||||||
public class MariadbFactoryProvider extends AbstractFactoryProvider {
|
public class MariadbFactoryProvider extends AbstractFactoryProvider {
|
||||||
|
|
||||||
public MariadbFactoryProvider(DataSource dataSource) {
|
public MariadbFactoryProvider(DataSource dataSource) {
|
||||||
super(dataSource);
|
super(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProductTypeEnum getProductType() {
|
|
||||||
return ProductTypeEnum.MARIADB;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProductFeatures getProductFeatures() {
|
public ProductFeatures getProductFeatures() {
|
||||||
return new MariadbFeatures();
|
return new MariadbFeatures();
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1 @@
|
|||||||
|
com.gitee.dbswitch.product.mariadb.MariadbFactoryProvider
|
@@ -9,6 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.product.mysql;
|
package com.gitee.dbswitch.product.mysql;
|
||||||
|
|
||||||
|
import com.gitee.dbswitch.annotation.Product;
|
||||||
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.features.ProductFeatures;
|
import com.gitee.dbswitch.features.ProductFeatures;
|
||||||
import com.gitee.dbswitch.provider.AbstractFactoryProvider;
|
import com.gitee.dbswitch.provider.AbstractFactoryProvider;
|
||||||
@@ -16,17 +17,13 @@ import com.gitee.dbswitch.provider.meta.MetadataProvider;
|
|||||||
import com.gitee.dbswitch.provider.sync.TableDataSynchronizer;
|
import com.gitee.dbswitch.provider.sync.TableDataSynchronizer;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
@Product(ProductTypeEnum.MYSQL)
|
||||||
public class MysqlFactoryProvider extends AbstractFactoryProvider {
|
public class MysqlFactoryProvider extends AbstractFactoryProvider {
|
||||||
|
|
||||||
public MysqlFactoryProvider(DataSource dataSource) {
|
public MysqlFactoryProvider(DataSource dataSource) {
|
||||||
super(dataSource);
|
super(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProductTypeEnum getProductType() {
|
|
||||||
return ProductTypeEnum.MYSQL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProductFeatures getProductFeatures() {
|
public ProductFeatures getProductFeatures() {
|
||||||
return new MysqlFeatures();
|
return new MysqlFeatures();
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1 @@
|
|||||||
|
com.gitee.dbswitch.product.mysql.MysqlFactoryProvider
|
@@ -9,6 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.product.oracle;
|
package com.gitee.dbswitch.product.oracle;
|
||||||
|
|
||||||
|
import com.gitee.dbswitch.annotation.Product;
|
||||||
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.features.ProductFeatures;
|
import com.gitee.dbswitch.features.ProductFeatures;
|
||||||
import com.gitee.dbswitch.provider.AbstractFactoryProvider;
|
import com.gitee.dbswitch.provider.AbstractFactoryProvider;
|
||||||
@@ -18,17 +19,13 @@ import com.gitee.dbswitch.provider.sync.TableDataSynchronizer;
|
|||||||
import com.gitee.dbswitch.provider.write.TableDataWriteProvider;
|
import com.gitee.dbswitch.provider.write.TableDataWriteProvider;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
@Product(ProductTypeEnum.ORACLE)
|
||||||
public class OracleFactoryProvider extends AbstractFactoryProvider {
|
public class OracleFactoryProvider extends AbstractFactoryProvider {
|
||||||
|
|
||||||
public OracleFactoryProvider(DataSource dataSource) {
|
public OracleFactoryProvider(DataSource dataSource) {
|
||||||
super(dataSource);
|
super(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProductTypeEnum getProductType() {
|
|
||||||
return ProductTypeEnum.ORACLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProductFeatures getProductFeatures() {
|
public ProductFeatures getProductFeatures() {
|
||||||
return new OracleFeatures();
|
return new OracleFeatures();
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1 @@
|
|||||||
|
com.gitee.dbswitch.product.oracle.OracleFactoryProvider
|
@@ -9,6 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.product.oscar;
|
package com.gitee.dbswitch.product.oscar;
|
||||||
|
|
||||||
|
import com.gitee.dbswitch.annotation.Product;
|
||||||
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.features.ProductFeatures;
|
import com.gitee.dbswitch.features.ProductFeatures;
|
||||||
import com.gitee.dbswitch.provider.AbstractFactoryProvider;
|
import com.gitee.dbswitch.provider.AbstractFactoryProvider;
|
||||||
@@ -18,17 +19,13 @@ import com.gitee.dbswitch.provider.sync.TableDataSynchronizer;
|
|||||||
import com.gitee.dbswitch.provider.write.TableDataWriteProvider;
|
import com.gitee.dbswitch.provider.write.TableDataWriteProvider;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
@Product(ProductTypeEnum.OSCAR)
|
||||||
public class OscarFactoryProvider extends AbstractFactoryProvider {
|
public class OscarFactoryProvider extends AbstractFactoryProvider {
|
||||||
|
|
||||||
public OscarFactoryProvider(DataSource dataSource) {
|
public OscarFactoryProvider(DataSource dataSource) {
|
||||||
super(dataSource);
|
super(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProductTypeEnum getProductType() {
|
|
||||||
return ProductTypeEnum.OSCAR;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProductFeatures getProductFeatures() {
|
public ProductFeatures getProductFeatures() {
|
||||||
return new OscarFeatures();
|
return new OscarFeatures();
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1 @@
|
|||||||
|
com.gitee.dbswitch.product.oscar.OscarFactoryProvider
|
@@ -9,6 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.product.postgresql;
|
package com.gitee.dbswitch.product.postgresql;
|
||||||
|
|
||||||
|
import com.gitee.dbswitch.annotation.Product;
|
||||||
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.features.ProductFeatures;
|
import com.gitee.dbswitch.features.ProductFeatures;
|
||||||
import com.gitee.dbswitch.provider.AbstractFactoryProvider;
|
import com.gitee.dbswitch.provider.AbstractFactoryProvider;
|
||||||
@@ -18,17 +19,13 @@ import com.gitee.dbswitch.provider.sync.TableDataSynchronizer;
|
|||||||
import com.gitee.dbswitch.provider.write.TableDataWriteProvider;
|
import com.gitee.dbswitch.provider.write.TableDataWriteProvider;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
@Product(ProductTypeEnum.POSTGRESQL)
|
||||||
public class PostgresFactoryProvider extends AbstractFactoryProvider {
|
public class PostgresFactoryProvider extends AbstractFactoryProvider {
|
||||||
|
|
||||||
public PostgresFactoryProvider(DataSource dataSource) {
|
public PostgresFactoryProvider(DataSource dataSource) {
|
||||||
super(dataSource);
|
super(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProductTypeEnum getProductType() {
|
|
||||||
return ProductTypeEnum.POSTGRESQL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProductFeatures getProductFeatures() {
|
public ProductFeatures getProductFeatures() {
|
||||||
return new PostgresFeatures();
|
return new PostgresFeatures();
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1 @@
|
|||||||
|
com.gitee.dbswitch.product.postgresql.PostgresFactoryProvider
|
@@ -1,55 +0,0 @@
|
|||||||
// 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.repository;
|
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
|
||||||
import com.gitee.dbswitch.product.db2.DB2FactoryProvider;
|
|
||||||
import com.gitee.dbswitch.product.dm.DmFactoryProvider;
|
|
||||||
import com.gitee.dbswitch.product.gbase.GbaseFactoryProvider;
|
|
||||||
import com.gitee.dbswitch.product.hive.HiveFactoryProvider;
|
|
||||||
import com.gitee.dbswitch.product.kingbase.KingbaseFactoryProvider;
|
|
||||||
import com.gitee.dbswitch.product.mariadb.MariadbFactoryProvider;
|
|
||||||
import com.gitee.dbswitch.product.mysql.MysqlFactoryProvider;
|
|
||||||
import com.gitee.dbswitch.product.oracle.OracleFactoryProvider;
|
|
||||||
import com.gitee.dbswitch.product.oscar.OscarFactoryProvider;
|
|
||||||
import com.gitee.dbswitch.product.postgresql.PostgresFactoryProvider;
|
|
||||||
import com.gitee.dbswitch.product.sqlite.SqliteFactoryProvider;
|
|
||||||
import com.gitee.dbswitch.product.sqlserver.SqlserverFactoryProvider;
|
|
||||||
import com.gitee.dbswitch.product.sybase.SybaseFactoryProvider;
|
|
||||||
import com.gitee.dbswitch.provider.ProductProviderFactory;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Configuration
|
|
||||||
@ConditionalOnClass(ProductProviderFactory.class)
|
|
||||||
public class ProductRegisterAutoConfiguration implements InitializingBean {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterPropertiesSet() throws Exception {
|
|
||||||
log.info("Register database product now ...");
|
|
||||||
ProductProviderFactory.register(ProductTypeEnum.MYSQL, MysqlFactoryProvider.class.getName());
|
|
||||||
ProductProviderFactory.register(ProductTypeEnum.ORACLE, OracleFactoryProvider.class.getName());
|
|
||||||
ProductProviderFactory.register(ProductTypeEnum.POSTGRESQL, PostgresFactoryProvider.class.getName());
|
|
||||||
ProductProviderFactory.register(ProductTypeEnum.SQLSERVER, SqlserverFactoryProvider.class.getName());
|
|
||||||
ProductProviderFactory.register(ProductTypeEnum.DB2, DB2FactoryProvider.class.getName());
|
|
||||||
ProductProviderFactory.register(ProductTypeEnum.DM, DmFactoryProvider.class.getName());
|
|
||||||
ProductProviderFactory.register(ProductTypeEnum.SYBASE, SybaseFactoryProvider.class.getName());
|
|
||||||
ProductProviderFactory.register(ProductTypeEnum.KINGBASE, KingbaseFactoryProvider.class.getName());
|
|
||||||
ProductProviderFactory.register(ProductTypeEnum.OSCAR, OscarFactoryProvider.class.getName());
|
|
||||||
ProductProviderFactory.register(ProductTypeEnum.SQLITE3, SqliteFactoryProvider.class.getName());
|
|
||||||
ProductProviderFactory.register(ProductTypeEnum.MARIADB, MariadbFactoryProvider.class.getName());
|
|
||||||
ProductProviderFactory.register(ProductTypeEnum.GBASE8A, GbaseFactoryProvider.class.getName());
|
|
||||||
ProductProviderFactory.register(ProductTypeEnum.HIVE, HiveFactoryProvider.class.getName());
|
|
||||||
log.info("Finish to register database product ");
|
|
||||||
}
|
|
||||||
}
|
|
@@ -9,6 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.product.sqlite;
|
package com.gitee.dbswitch.product.sqlite;
|
||||||
|
|
||||||
|
import com.gitee.dbswitch.annotation.Product;
|
||||||
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.features.ProductFeatures;
|
import com.gitee.dbswitch.features.ProductFeatures;
|
||||||
import com.gitee.dbswitch.provider.AbstractFactoryProvider;
|
import com.gitee.dbswitch.provider.AbstractFactoryProvider;
|
||||||
@@ -18,17 +19,13 @@ import com.gitee.dbswitch.provider.sync.TableDataSynchronizer;
|
|||||||
import com.gitee.dbswitch.provider.write.TableDataWriteProvider;
|
import com.gitee.dbswitch.provider.write.TableDataWriteProvider;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
@Product(ProductTypeEnum.SQLITE3)
|
||||||
public class SqliteFactoryProvider extends AbstractFactoryProvider {
|
public class SqliteFactoryProvider extends AbstractFactoryProvider {
|
||||||
|
|
||||||
public SqliteFactoryProvider(DataSource dataSource) {
|
public SqliteFactoryProvider(DataSource dataSource) {
|
||||||
super(dataSource);
|
super(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProductTypeEnum getProductType() {
|
|
||||||
return ProductTypeEnum.SQLITE3;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProductFeatures getProductFeatures() {
|
public ProductFeatures getProductFeatures() {
|
||||||
return new SqliteFeatures();
|
return new SqliteFeatures();
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1 @@
|
|||||||
|
com.gitee.dbswitch.product.sqlite.SqliteFactoryProvider
|
@@ -9,6 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.product.sqlserver;
|
package com.gitee.dbswitch.product.sqlserver;
|
||||||
|
|
||||||
|
import com.gitee.dbswitch.annotation.Product;
|
||||||
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.features.ProductFeatures;
|
import com.gitee.dbswitch.features.ProductFeatures;
|
||||||
import com.gitee.dbswitch.provider.AbstractFactoryProvider;
|
import com.gitee.dbswitch.provider.AbstractFactoryProvider;
|
||||||
@@ -17,17 +18,13 @@ import com.gitee.dbswitch.provider.operate.TableOperateProvider;
|
|||||||
import com.gitee.dbswitch.provider.sync.TableDataSynchronizer;
|
import com.gitee.dbswitch.provider.sync.TableDataSynchronizer;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
@Product(ProductTypeEnum.SQLSERVER)
|
||||||
public class SqlserverFactoryProvider extends AbstractFactoryProvider {
|
public class SqlserverFactoryProvider extends AbstractFactoryProvider {
|
||||||
|
|
||||||
public SqlserverFactoryProvider(DataSource dataSource) {
|
public SqlserverFactoryProvider(DataSource dataSource) {
|
||||||
super(dataSource);
|
super(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProductTypeEnum getProductType() {
|
|
||||||
return ProductTypeEnum.SQLSERVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProductFeatures getProductFeatures() {
|
public ProductFeatures getProductFeatures() {
|
||||||
return new SqlserverFeatures();
|
return new SqlserverFeatures();
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1 @@
|
|||||||
|
com.gitee.dbswitch.product.sqlserver.SqlserverFactoryProvider
|
@@ -9,6 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.product.sybase;
|
package com.gitee.dbswitch.product.sybase;
|
||||||
|
|
||||||
|
import com.gitee.dbswitch.annotation.Product;
|
||||||
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.features.ProductFeatures;
|
import com.gitee.dbswitch.features.ProductFeatures;
|
||||||
import com.gitee.dbswitch.product.sqlserver.SqlserverTableOperateProvider;
|
import com.gitee.dbswitch.product.sqlserver.SqlserverTableOperateProvider;
|
||||||
@@ -19,17 +20,13 @@ import com.gitee.dbswitch.provider.operate.TableOperateProvider;
|
|||||||
import com.gitee.dbswitch.provider.sync.TableDataSynchronizer;
|
import com.gitee.dbswitch.provider.sync.TableDataSynchronizer;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
@Product(ProductTypeEnum.SYBASE)
|
||||||
public class SybaseFactoryProvider extends AbstractFactoryProvider {
|
public class SybaseFactoryProvider extends AbstractFactoryProvider {
|
||||||
|
|
||||||
public SybaseFactoryProvider(DataSource dataSource) {
|
public SybaseFactoryProvider(DataSource dataSource) {
|
||||||
super(dataSource);
|
super(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProductTypeEnum getProductType() {
|
|
||||||
return ProductTypeEnum.SYBASE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProductFeatures getProductFeatures() {
|
public ProductFeatures getProductFeatures() {
|
||||||
return new SybaseFeatures();
|
return new SybaseFeatures();
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1 @@
|
|||||||
|
com.gitee.dbswitch.product.sybase.SybaseFactoryProvider
|
@@ -77,6 +77,7 @@
|
|||||||
<artifactId>dbswitch-product-gbase</artifactId>
|
<artifactId>dbswitch-product-gbase</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- 新增加的数据库产品需要在这里追加依赖-->
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
@@ -0,0 +1,135 @@
|
|||||||
|
// 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.repository;
|
||||||
|
|
||||||
|
import com.gitee.dbswitch.annotation.Product;
|
||||||
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
|
import com.gitee.dbswitch.provider.ProductFactoryProvider;
|
||||||
|
import com.gitee.dbswitch.provider.ProductProviderFactory;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ServiceConfigurationError;
|
||||||
|
import java.util.Set;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Configuration
|
||||||
|
@ConditionalOnClass(ProductProviderFactory.class)
|
||||||
|
public class ProductRegisterAutoConfiguration implements InitializingBean, BeanClassLoaderAware {
|
||||||
|
|
||||||
|
private static final String SPI_FILE = "META-INF/services/dbswitch.providers";
|
||||||
|
private static final Set<String> providers = new HashSet<>();
|
||||||
|
|
||||||
|
private ClassLoader classLoader;
|
||||||
|
|
||||||
|
private int parseLine(BufferedReader reader, int lc, List<String> names)
|
||||||
|
throws IOException, ServiceConfigurationError {
|
||||||
|
String ln = reader.readLine();
|
||||||
|
if (ln == null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int ci = ln.indexOf('#');
|
||||||
|
if (ci >= 0) {
|
||||||
|
ln = ln.substring(0, ci);
|
||||||
|
}
|
||||||
|
ln = ln.trim();
|
||||||
|
int n = ln.length();
|
||||||
|
if (n != 0) {
|
||||||
|
if ((ln.indexOf(' ') >= 0) || (ln.indexOf('\t') >= 0)) {
|
||||||
|
log.error("Illegal configuration-file syntax: {}", ln);
|
||||||
|
}
|
||||||
|
int cp = ln.codePointAt(0);
|
||||||
|
if (!Character.isJavaIdentifierStart(cp)) {
|
||||||
|
log.error("Illegal provider-class name: {}", ln);
|
||||||
|
}
|
||||||
|
for (int i = Character.charCount(cp); i < n; i += Character.charCount(cp)) {
|
||||||
|
cp = ln.codePointAt(i);
|
||||||
|
if (!Character.isJavaIdentifierPart(cp) && (cp != '.')) {
|
||||||
|
log.error("Illegal provider-class name: {}", ln);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!providers.contains(ln) && !names.contains(ln)) {
|
||||||
|
names.add(ln);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lc + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> parse(URL url) throws ServiceConfigurationError {
|
||||||
|
InputStream in = null;
|
||||||
|
BufferedReader reader = null;
|
||||||
|
ArrayList<String> names = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
in = url.openStream();
|
||||||
|
reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
||||||
|
int lc = 1;
|
||||||
|
while ((lc = parseLine(reader, lc, names)) >= 0) {
|
||||||
|
}
|
||||||
|
} catch (IOException x) {
|
||||||
|
log.error("Error reading configuration file", x);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (reader != null) {
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
if (in != null) {
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
} catch (IOException y) {
|
||||||
|
log.error("Error closing configuration file", y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||||
|
this.classLoader = classLoader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterPropertiesSet() throws Exception {
|
||||||
|
log.info("Register database product now ...");
|
||||||
|
ClassLoader loader = (null != classLoader)
|
||||||
|
? classLoader
|
||||||
|
: ProductProviderFactory.class.getClassLoader();
|
||||||
|
Enumeration<URL> resources = loader.getResources(SPI_FILE);
|
||||||
|
while (resources.hasMoreElements()) {
|
||||||
|
URL url = resources.nextElement();
|
||||||
|
providers.addAll(parse(url));
|
||||||
|
}
|
||||||
|
int totalCount = 0;
|
||||||
|
for (String className : providers) {
|
||||||
|
Class<?> aClass = classLoader.loadClass(className);
|
||||||
|
if (ProductFactoryProvider.class.isAssignableFrom(aClass)) {
|
||||||
|
if (aClass.isAnnotationPresent(Product.class)) {
|
||||||
|
Product annotation = aClass.getAnnotation(Product.class);
|
||||||
|
ProductTypeEnum productType = annotation.value();
|
||||||
|
if (null != productType) {
|
||||||
|
ProductProviderFactory.register(productType, className);
|
||||||
|
++totalCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.info("Finish to register total {} database product !", totalCount);
|
||||||
|
}
|
||||||
|
}
|
@@ -25,7 +25,7 @@
|
|||||||
<module>dbswitch-product-mariadb</module>
|
<module>dbswitch-product-mariadb</module>
|
||||||
<module>dbswitch-product-hive</module>
|
<module>dbswitch-product-hive</module>
|
||||||
<module>dbswitch-product-gbase</module>
|
<module>dbswitch-product-gbase</module>
|
||||||
<module>dbswitch-product-repository</module>
|
<module>dbswitch-register-product</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
</project>
|
</project>
|
Reference in New Issue
Block a user