mirror of
https://gitee.com/dromara/dbswitch.git
synced 2025-09-11 14:39:05 +00:00
支持dm和kingbase8数据库
This commit is contained in:
27
README.md
27
README.md
@@ -22,16 +22,19 @@
|
||||
|
||||
### 3、详细功能
|
||||
|
||||
- 源端oracle/SqlServer/MySQL/MariaDB/PostgreSQL/DB2向目的端为Greenplum/PostgreSQL的迁移(**支持绝大多数常规类型字段**)
|
||||
- 源端oracle/SqlServer/MySQL/MariaDB/PostgreSQL/DB2/DM/Kingbase向目的端为Greenplum/PostgreSQL的迁移(**支持绝大多数常规类型字段**)
|
||||
|
||||
- 源端oracle/SqlServer/MySQL/MariaDB/PostgreSQL/DB2向目的端为Oralce的迁移(**支持绝大多数常规类型字段**)
|
||||
- 源端oracle/SqlServer/MySQL/MariaDB/PostgreSQL/DB2DM/Kingbase向目的端为Oralce的迁移(**支持绝大多数常规类型字段**)
|
||||
|
||||
- 源端oracle/SqlServer/MySQL/MariaDB/PostgreSQL/DB2向目的端为SQLServer的迁移(**字段类型兼容测试中...**)
|
||||
- 源端oracle/SqlServer/MySQL/MariaDB/PostgreSQL/DB2DM/Kingbase向目的端为SQLServer的迁移(**字段类型兼容测试中...**)
|
||||
|
||||
- 源端oracle/SqlServer/MySQL/MariaDB/PostgreSQL/DB2向目的端为MySQL/MariaDB的迁移(**字段类型兼容测试中...**)
|
||||
- 源端oracle/SqlServer/MySQL/MariaDB/PostgreSQL/DB2DM/Kingbase向目的端为MySQL/MariaDB的迁移(**字段类型兼容测试中...**)
|
||||
|
||||
- 源端oracle/SqlServer/MySQL/MariaDB/PostgreSQL/DB2向目的端为DB2的迁移(**字段类型兼容测试中...**)
|
||||
- 源端oracle/SqlServer/MySQL/MariaDB/PostgreSQL/DB2DM/Kingbase向目的端为DB2的迁移(**字段类型兼容测试中...**)
|
||||
|
||||
- 源端oracle/SqlServer/MySQL/MariaDB/PostgreSQL/DB2DM/Kingbase向目的端为DM的迁移(**字段类型兼容测试中...**)
|
||||
|
||||
- 源端oracle/SqlServer/MySQL/MariaDB/PostgreSQL/DB2DM/Kingbase向目的端为Kingbase的迁移(**字段类型兼容测试中...**)
|
||||
|
||||
### 4、结构设计
|
||||
|
||||
@@ -171,6 +174,20 @@ jdbc连接地址:jdbc:db2://172.17.20.91:50000/testdb:driverType=4;fullyMateri
|
||||
jdbc驱动名称:com.ibm.db2.jcc.DB2Driver
|
||||
```
|
||||
|
||||
- DM的驱动配置样例
|
||||
|
||||
```
|
||||
jdbc连接地址:jdbc:dm://172.17.20.91:5236
|
||||
jdbc驱动名称:dm.jdbc.driver.DmDriver
|
||||
```
|
||||
|
||||
- Kingbase的驱动配置样例
|
||||
|
||||
```
|
||||
jdbc连接地址:jdbc:kingbase8://172.17.20.91:54321/TEMPLATE2
|
||||
jdbc驱动名称:com.kingbase8.Driver
|
||||
```
|
||||
|
||||
启动执行命令如下:
|
||||
|
||||
linux系统下:
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.gitee</groupId>
|
||||
<artifactId>dbswitch</artifactId>
|
||||
<version>1.5.2</version>
|
||||
<version>1.5.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dbswitch-common</artifactId>
|
||||
|
@@ -59,7 +59,17 @@ public enum DatabaseTypeEnum {
|
||||
/**
|
||||
* DB2数据库类型
|
||||
*/
|
||||
DB2(8);
|
||||
DB2(8),
|
||||
|
||||
/**
|
||||
* DM数据库类型
|
||||
*/
|
||||
DM(9),
|
||||
|
||||
/**
|
||||
* Kingbase数据库类型
|
||||
*/
|
||||
KINGBASE(10);
|
||||
|
||||
private int index;
|
||||
|
||||
|
BIN
dbswitch-core/lib/DmJdbcDriver18.jar
Normal file
BIN
dbswitch-core/lib/DmJdbcDriver18.jar
Normal file
Binary file not shown.
BIN
dbswitch-core/lib/kingbase8-8.2.0.jar
Normal file
BIN
dbswitch-core/lib/kingbase8-8.2.0.jar
Normal file
Binary file not shown.
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.gitee</groupId>
|
||||
<artifactId>dbswitch</artifactId>
|
||||
<version>1.5.2</version>
|
||||
<version>1.5.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dbswitch-core</artifactId>
|
||||
@@ -78,6 +78,22 @@
|
||||
<systemPath>${project.basedir}/lib/greenplum-jdbc-5.1.4.jar</systemPath>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.dameng</groupId>
|
||||
<artifactId>dm-jdbc</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/DmJdbcDriver18.jar</systemPath>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.kingbase</groupId>
|
||||
<artifactId>kingbase-jdbc</artifactId>
|
||||
<version>8.2.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/kingbase8-8.2.0.jar</systemPath>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mariadb.jdbc</groupId>
|
||||
<artifactId>mariadb-java-client</artifactId>
|
||||
|
@@ -13,7 +13,9 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import com.gitee.dbswitch.common.constant.DatabaseTypeEnum;
|
||||
import com.gitee.dbswitch.core.database.impl.DatabaseDB2Impl;
|
||||
import com.gitee.dbswitch.core.database.impl.DatabaseDmImpl;
|
||||
import com.gitee.dbswitch.core.database.impl.DatabaseGreenplumImpl;
|
||||
import com.gitee.dbswitch.core.database.impl.DatabaseKingbaseImpl;
|
||||
import com.gitee.dbswitch.core.database.impl.DatabaseMariaDBImpl;
|
||||
import com.gitee.dbswitch.core.database.impl.DatabaseMysqlImpl;
|
||||
import com.gitee.dbswitch.core.database.impl.DatabaseOracleImpl;
|
||||
@@ -41,6 +43,8 @@ public final class DatabaseFactory {
|
||||
put(DatabaseTypeEnum.GREENPLUM,DatabaseGreenplumImpl.class.getName());
|
||||
put(DatabaseTypeEnum.MARIADB,DatabaseMariaDBImpl.class.getName());
|
||||
put(DatabaseTypeEnum.DB2,DatabaseDB2Impl.class.getName());
|
||||
put(DatabaseTypeEnum.DM,DatabaseDmImpl.class.getName());
|
||||
put(DatabaseTypeEnum.KINGBASE,DatabaseKingbaseImpl.class.getName());
|
||||
}};
|
||||
|
||||
public static AbstractDatabase getDatabaseInstance(DatabaseTypeEnum type) {
|
||||
|
@@ -0,0 +1,121 @@
|
||||
// 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)
|
||||
// Data : 2020/1/2
|
||||
// Location: beijing , china
|
||||
/////////////////////////////////////////////////////////////
|
||||
package com.gitee.dbswitch.core.database.impl;
|
||||
|
||||
import java.util.List;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.gitee.dbswitch.common.constant.DatabaseTypeEnum;
|
||||
import com.gitee.dbswitch.core.constant.Const;
|
||||
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
||||
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
||||
import com.gitee.dbswitch.core.model.ColumnDescription;
|
||||
import com.gitee.dbswitch.core.model.ColumnMetaData;
|
||||
|
||||
/**
|
||||
* 支持DM数据库的元信息实现
|
||||
*
|
||||
* @author tang
|
||||
*
|
||||
*/
|
||||
public class DatabaseDmImpl extends AbstractDatabase implements IDatabaseInterface {
|
||||
|
||||
public DatabaseDmImpl() {
|
||||
super("dm.jdbc.driver.DmDriver");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ColumnDescription> querySelectSqlColumnMeta(String sql) {
|
||||
String querySQL = String.format("SELECT * from (%s) tmp where ROWNUM<=1 ", sql.replace(";", ""));
|
||||
return this.getSelectSqlColumnMeta(querySQL, DatabaseTypeEnum.DM);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTableFieldsQuerySQL(String schemaName, String tableName) {
|
||||
return String.format("SELECT * FROM \"%s\".\"%s\" ", schemaName, tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestQuerySQL(String sql) {
|
||||
return String.format("explain %s", sql.replace(";", ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatSQL(String sql) {
|
||||
return SQLUtils.formatOracle(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFieldDefinition(ColumnMetaData v, List<String> pks, boolean useAutoInc, boolean addCr) {
|
||||
String fieldname = v.getName();
|
||||
int length = v.getLength();
|
||||
int precision = v.getPrecision();
|
||||
|
||||
StringBuilder retval = new StringBuilder(128);
|
||||
retval.append(" \"").append(fieldname).append("\" ");
|
||||
|
||||
int type = v.getType();
|
||||
switch (type) {
|
||||
case ColumnMetaData.TYPE_TIMESTAMP:
|
||||
case ColumnMetaData.TYPE_TIME:
|
||||
retval.append("TIMESTAMP");
|
||||
break;
|
||||
case ColumnMetaData.TYPE_DATE:
|
||||
retval.append("DATE");
|
||||
break;
|
||||
case ColumnMetaData.TYPE_BOOLEAN:
|
||||
retval.append("VARCHAR(32)");
|
||||
break;
|
||||
case ColumnMetaData.TYPE_NUMBER:
|
||||
case ColumnMetaData.TYPE_BIGNUMBER:
|
||||
retval.append("NUMBER");
|
||||
if (length > 0) {
|
||||
if (length > 38) {
|
||||
length = 38;
|
||||
}
|
||||
|
||||
retval.append('(').append(length);
|
||||
if (precision > 0) {
|
||||
retval.append(", ").append(precision);
|
||||
}
|
||||
retval.append(')');
|
||||
}
|
||||
break;
|
||||
case ColumnMetaData.TYPE_INTEGER:
|
||||
retval.append("INTEGER");
|
||||
break;
|
||||
case ColumnMetaData.TYPE_STRING:
|
||||
if (2*length >= AbstractDatabase.CLOB_LENGTH) {
|
||||
retval.append("CLOB");
|
||||
} else {
|
||||
if (length == 1) {
|
||||
retval.append("NVARCHAR2(2)");
|
||||
} else if (length > 0 && length < 2048) {
|
||||
retval.append("NVARCHAR2(").append(2*length).append(')');
|
||||
} else {
|
||||
retval.append("CLOB");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ColumnMetaData.TYPE_BINARY:
|
||||
retval.append("BLOB");
|
||||
break;
|
||||
default:
|
||||
retval.append("CLOB");
|
||||
break;
|
||||
}
|
||||
|
||||
if (addCr) {
|
||||
retval.append(Const.CR);
|
||||
}
|
||||
|
||||
return retval.toString();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,136 @@
|
||||
// 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)
|
||||
// Data : 2020/1/2
|
||||
// Location: beijing , china
|
||||
/////////////////////////////////////////////////////////////
|
||||
package com.gitee.dbswitch.core.database.impl;
|
||||
|
||||
import java.util.List;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.gitee.dbswitch.common.constant.DatabaseTypeEnum;
|
||||
import com.gitee.dbswitch.core.constant.Const;
|
||||
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
||||
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
||||
import com.gitee.dbswitch.core.model.ColumnDescription;
|
||||
import com.gitee.dbswitch.core.model.ColumnMetaData;
|
||||
|
||||
/**
|
||||
* 支持Kingbase数据库的元信息实现
|
||||
*
|
||||
* @author tang
|
||||
*
|
||||
*/
|
||||
public class DatabaseKingbaseImpl extends AbstractDatabase implements IDatabaseInterface {
|
||||
|
||||
public DatabaseKingbaseImpl() {
|
||||
super("com.kingbase8.Driver");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ColumnDescription> querySelectSqlColumnMeta(String sql) {
|
||||
String querySQL = String.format(" %s LIMIT 0 ", sql.replace(";", ""));
|
||||
return this.getSelectSqlColumnMeta(querySQL, DatabaseTypeEnum.KINGBASE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTableFieldsQuerySQL(String schemaName, String tableName) {
|
||||
return String.format("SELECT * FROM \"%s\".\"%s\" ", schemaName, tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestQuerySQL(String sql) {
|
||||
return String.format("explain %s", sql.replace(";", ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatSQL(String sql) {
|
||||
return SQLUtils.formatPGSql(sql, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFieldDefinition(ColumnMetaData v, List<String> pks, boolean useAutoInc, boolean addCr) {
|
||||
String fieldname = v.getName();
|
||||
int length = v.getLength();
|
||||
int precision = v.getPrecision();
|
||||
int type = v.getType();
|
||||
|
||||
String retval = " \"" + fieldname + "\" ";
|
||||
|
||||
switch (type) {
|
||||
case ColumnMetaData.TYPE_TIMESTAMP:
|
||||
retval += "TIMESTAMP";
|
||||
break;
|
||||
case ColumnMetaData.TYPE_TIME:
|
||||
retval += "TIME";
|
||||
break;
|
||||
case ColumnMetaData.TYPE_DATE:
|
||||
retval += "DATE";
|
||||
break;
|
||||
case ColumnMetaData.TYPE_BOOLEAN:
|
||||
retval += "VARCHAR(32)";
|
||||
break;
|
||||
case ColumnMetaData.TYPE_NUMBER:
|
||||
case ColumnMetaData.TYPE_INTEGER:
|
||||
case ColumnMetaData.TYPE_BIGNUMBER:
|
||||
if (null != pks && pks.contains(fieldname)) {
|
||||
if (useAutoInc) {
|
||||
retval += "BIGSERIAL";
|
||||
} else {
|
||||
retval += "BIGINT";
|
||||
}
|
||||
} else {
|
||||
if (length > 0) {
|
||||
if (precision > 0 || length > 18) {
|
||||
if ((length + precision) > 0 && precision > 0) {
|
||||
// Numeric(Precision, Scale): Precision = total length; Scale = decimal places
|
||||
retval += "NUMERIC(" + (length + precision) + ", " + precision + ")";
|
||||
} else {
|
||||
retval += "DOUBLE PRECISION";
|
||||
}
|
||||
} else {
|
||||
if (length > 9) {
|
||||
retval += "BIGINT";
|
||||
} else {
|
||||
if (length < 5) {
|
||||
retval += "SMALLINT";
|
||||
} else {
|
||||
retval += "INTEGER";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
retval += "DOUBLE PRECISION";
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ColumnMetaData.TYPE_STRING:
|
||||
if (length < 1 || length >= AbstractDatabase.CLOB_LENGTH) {
|
||||
retval += "TEXT";
|
||||
} else {
|
||||
if (null != pks && pks.contains(fieldname)) {
|
||||
retval += "VARCHAR(" + length + ")";
|
||||
} else {
|
||||
retval += "TEXT";
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ColumnMetaData.TYPE_BINARY:
|
||||
retval += "BYTEA";
|
||||
break;
|
||||
default:
|
||||
retval += "TEXT";
|
||||
break;
|
||||
}
|
||||
|
||||
if (addCr) {
|
||||
retval += Const.CR;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
}
|
@@ -110,7 +110,7 @@ public class DatabaseOracleImpl extends AbstractDatabase implements IDatabaseInt
|
||||
@Override
|
||||
public List<ColumnDescription> querySelectSqlColumnMeta(String sql) {
|
||||
String querySQL = String.format("SELECT * from (%s) tmp where ROWNUM<=1 ", sql.replace(";", ""));
|
||||
return this.getSelectSqlColumnMeta(querySQL, DatabaseTypeEnum.MYSQL);
|
||||
return this.getSelectSqlColumnMeta(querySQL, DatabaseTypeEnum.ORACLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.gitee</groupId>
|
||||
<artifactId>dbswitch</artifactId>
|
||||
<version>1.5.2</version>
|
||||
<version>1.5.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dbswitch-data</artifactId>
|
||||
|
@@ -15,7 +15,7 @@ import com.gitee.dbswitch.core.service.IMetaDataService;
|
||||
import com.gitee.dbswitch.core.service.impl.MigrationMetaDataServiceImpl;
|
||||
|
||||
/**
|
||||
* 注册所有映射属性类 { }中用逗号分隔即可注册多个属性类
|
||||
* 配置类
|
||||
*
|
||||
* @author tang
|
||||
*
|
||||
|
@@ -22,8 +22,8 @@ import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.ConnectionCallback;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.support.JdbcUtils;
|
||||
import org.springframework.jdbc.support.MetaDataAccessException;
|
||||
import com.gitee.dbswitch.common.constant.DatabaseTypeEnum;
|
||||
import com.gitee.dbswitch.dbcommon.util.DatabaseAwareUtils;
|
||||
|
||||
/**
|
||||
* JdbcTemplate包制使用工具类型
|
||||
@@ -44,15 +44,16 @@ public final class JdbcTemplateUtils {
|
||||
* @return DatabaseType 数据库类型
|
||||
*/
|
||||
public static DatabaseTypeEnum getDatabaseProduceName(DataSource dataSource) {
|
||||
try {
|
||||
String productName = JdbcUtils.commonDatabaseName(
|
||||
JdbcUtils.extractDatabaseMetaData(dataSource, "getDatabaseProductName").toString());
|
||||
if (productName.equalsIgnoreCase("Greenplum")) {
|
||||
return DatabaseTypeEnum.GREENPLUM;
|
||||
} else if (productName.equalsIgnoreCase("Microsoft SQL Server")) {
|
||||
return DatabaseTypeEnum.SQLSERVER;
|
||||
}
|
||||
|
||||
String productName = DatabaseAwareUtils.getDatabaseNameByDataSource(dataSource);
|
||||
if (productName.equalsIgnoreCase("Greenplum")) {
|
||||
return DatabaseTypeEnum.GREENPLUM;
|
||||
} else if (productName.equalsIgnoreCase("SQLServer")) {
|
||||
return DatabaseTypeEnum.SQLSERVER;
|
||||
} else if (productName.equalsIgnoreCase("DM")) {
|
||||
return DatabaseTypeEnum.DM;
|
||||
} else if (productName.equalsIgnoreCase("Kingbase")) {
|
||||
return DatabaseTypeEnum.KINGBASE;
|
||||
} else {
|
||||
DatabaseDriver databaseDriver = DatabaseDriver.fromProductName(productName);
|
||||
if (DatabaseDriver.MARIADB == databaseDriver) {
|
||||
return DatabaseTypeEnum.MARIADB;
|
||||
@@ -67,8 +68,6 @@ public final class JdbcTemplateUtils {
|
||||
} else {
|
||||
throw new RuntimeException(String.format("Unsupport database type by product name [%s]", productName));
|
||||
}
|
||||
} catch (MetaDataAccessException ex) {
|
||||
throw new IllegalStateException("Unable to detect database type", ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
# source database connection information
|
||||
## support MySQL/MariaDB/DB2/Oracle/SQLServer/PostgreSQL/Greenplum
|
||||
## support MySQL/MariaDB/DB2/DM/Kingbase/Oracle/SQLServer/PostgreSQL/Greenplum
|
||||
dbswitch.source[0].url= jdbc:oracle:thin:@172.17.20.58:1521:ORCL
|
||||
dbswitch.source[0].driver-class-name= oracle.jdbc.driver.OracleDriver
|
||||
dbswitch.source[0].username= tang
|
||||
@@ -15,7 +15,7 @@ dbswitch.source[0].source-includes=
|
||||
dbswitch.source[0].source-excludes=
|
||||
|
||||
# target database connection information
|
||||
## support Oracle/PostgreSQL/Greenplum
|
||||
## support Oracle/PostgreSQL/Greenplum/DM/Kingbase
|
||||
dbswitch.target.url= jdbc:postgresql://172.17.20.44:5432/study
|
||||
dbswitch.target.driver-class-name= org.postgresql.Driver
|
||||
dbswitch.target.username= tang
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.gitee</groupId>
|
||||
<artifactId>dbswitch</artifactId>
|
||||
<version>1.5.2</version>
|
||||
<version>1.5.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dbswitch-dbchange</artifactId>
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.gitee</groupId>
|
||||
<artifactId>dbswitch</artifactId>
|
||||
<version>1.5.2</version>
|
||||
<version>1.5.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dbswitch-dbcommon</artifactId>
|
||||
|
@@ -13,15 +13,15 @@ import java.util.Map;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.HashMap;
|
||||
import javax.sql.DataSource;
|
||||
import org.springframework.boot.jdbc.DatabaseDriver;
|
||||
import org.springframework.jdbc.support.JdbcUtils;
|
||||
import org.springframework.jdbc.support.MetaDataAccessException;
|
||||
import com.gitee.dbswitch.dbcommon.database.impl.DB2DatabaseOperator;
|
||||
import com.gitee.dbswitch.dbcommon.database.impl.DmDatabaseOperator;
|
||||
import com.gitee.dbswitch.dbcommon.database.impl.GreenplumDatabaseOperator;
|
||||
import com.gitee.dbswitch.dbcommon.database.impl.KingbaseDatabaseOperator;
|
||||
import com.gitee.dbswitch.dbcommon.database.impl.MysqlDatabaseOperator;
|
||||
import com.gitee.dbswitch.dbcommon.database.impl.OracleDatabaseOperator;
|
||||
import com.gitee.dbswitch.dbcommon.database.impl.PostgreSqlDatabaseOperator;
|
||||
import com.gitee.dbswitch.dbcommon.database.impl.SqlServerDatabaseOperator;
|
||||
import com.gitee.dbswitch.dbcommon.util.DatabaseAwareUtils;
|
||||
|
||||
/**
|
||||
* 数据库操作器构造工厂类
|
||||
@@ -42,6 +42,8 @@ public final class DatabaseOperatorFactory {
|
||||
put("POSTGRESQL", PostgreSqlDatabaseOperator.class.getName());
|
||||
put("GREENPLUM", GreenplumDatabaseOperator.class.getName());
|
||||
put("DB2", DB2DatabaseOperator.class.getName());
|
||||
put("DM", DmDatabaseOperator.class.getName());
|
||||
put("KINGBASE", KingbaseDatabaseOperator.class.getName());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -52,7 +54,7 @@ public final class DatabaseOperatorFactory {
|
||||
* @return 指定类型的数据库读取器
|
||||
*/
|
||||
public static IDatabaseOperator createDatabaseOperator(DataSource dataSource) {
|
||||
String type = getDatabaseNameByDataSource(dataSource).toUpperCase();
|
||||
String type = DatabaseAwareUtils.getDatabaseNameByDataSource(dataSource).toUpperCase();
|
||||
if (DATABASE_OPERATOR_MAPPER.containsKey(type)) {
|
||||
String className = DATABASE_OPERATOR_MAPPER.get(type);
|
||||
try {
|
||||
@@ -69,29 +71,4 @@ public final class DatabaseOperatorFactory {
|
||||
throw new RuntimeException(String.format("[dbcommon] Unkown Supported database type (%s)", type));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据DataSource获取数据库的类型
|
||||
*
|
||||
* @param dataSource 数据库源
|
||||
* @return 数据库的类型:mysql/oracle/postgresql/sqlserver/greenplum/db2
|
||||
*/
|
||||
public static String getDatabaseNameByDataSource(DataSource dataSource) {
|
||||
try {
|
||||
String productName = JdbcUtils.commonDatabaseName(
|
||||
JdbcUtils.extractDatabaseMetaData(dataSource, "getDatabaseProductName").toString());
|
||||
if (productName.equalsIgnoreCase("Greenplum")) {
|
||||
return "greenplum";
|
||||
} else if (productName.equalsIgnoreCase("Microsoft SQL Server")) {
|
||||
return "sqlserver";
|
||||
} else {
|
||||
DatabaseDriver databaseDriver = DatabaseDriver.fromProductName(productName);
|
||||
if (databaseDriver == DatabaseDriver.UNKNOWN) {
|
||||
throw new IllegalStateException("Unable to detect database type from data source instance");
|
||||
}
|
||||
return databaseDriver.getId();
|
||||
}
|
||||
} catch (MetaDataAccessException ex) {
|
||||
throw new IllegalStateException("Unable to detect database type", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,12 @@
|
||||
package com.gitee.dbswitch.dbcommon.database.impl;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import com.gitee.dbswitch.dbcommon.database.IDatabaseOperator;
|
||||
|
||||
public class DmDatabaseOperator extends OracleDatabaseOperator implements IDatabaseOperator {
|
||||
|
||||
public DmDatabaseOperator(DataSource dataSource) {
|
||||
super(dataSource);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
package com.gitee.dbswitch.dbcommon.database.impl;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import com.gitee.dbswitch.dbcommon.database.IDatabaseOperator;
|
||||
|
||||
public class KingbaseDatabaseOperator extends PostgreSqlDatabaseOperator implements IDatabaseOperator {
|
||||
|
||||
public KingbaseDatabaseOperator(DataSource dataSource) {
|
||||
super(dataSource);
|
||||
}
|
||||
|
||||
}
|
@@ -42,8 +42,12 @@ public final class DatabaseAwareUtils {
|
||||
return "greenplum";
|
||||
} else if (productName.equalsIgnoreCase("Microsoft SQL Server")) {
|
||||
return "sqlserver";
|
||||
} else if (productName.equalsIgnoreCase("KingbaseES")) {
|
||||
return "kingbase";
|
||||
} else if (productName.equalsIgnoreCase("DM DBMS")) {
|
||||
return "dm";
|
||||
}
|
||||
|
||||
|
||||
DatabaseDriver databaseDriver = DatabaseDriver.fromProductName(productName);
|
||||
if (databaseDriver == DatabaseDriver.UNKNOWN) {
|
||||
throw new IllegalStateException("Unable to detect database type from data source instance");
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.gitee</groupId>
|
||||
<artifactId>dbswitch</artifactId>
|
||||
<version>1.5.2</version>
|
||||
<version>1.5.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dbswitch-dbsynch</artifactId>
|
||||
|
@@ -14,12 +14,13 @@ import java.util.HashMap;
|
||||
import javax.sql.DataSource;
|
||||
import com.gitee.dbswitch.dbcommon.util.DatabaseAwareUtils;
|
||||
import com.gitee.dbswitch.dbsynch.db2.DB2DatabaseSynchImpl;
|
||||
import com.gitee.dbswitch.dbsynch.dm.DmDatabaseSynchImpl;
|
||||
import com.gitee.dbswitch.dbsynch.kingbase.KingbaseDatabaseSynchImpl;
|
||||
import com.gitee.dbswitch.dbsynch.mssql.SqlServerDatabaseSynchImpl;
|
||||
import com.gitee.dbswitch.dbsynch.mysql.MySqlDatabaseSynchImpl;
|
||||
import com.gitee.dbswitch.dbsynch.oracle.OracleDatabaseSynchImpl;
|
||||
import com.gitee.dbswitch.dbsynch.pgsql.GreenplumDatabaseSynchImpl;
|
||||
import com.gitee.dbswitch.dbsynch.pgsql.PostgresqlDatabaseSynchImpl;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
/**
|
||||
@@ -41,6 +42,8 @@ public final class DatabaseSynchronizeFactory {
|
||||
put("POSTGRESQL", PostgresqlDatabaseSynchImpl.class.getName());
|
||||
put("GREENPLUM", GreenplumDatabaseSynchImpl.class.getName());
|
||||
put("DB2",DB2DatabaseSynchImpl.class.getName());
|
||||
put("DM",DmDatabaseSynchImpl.class.getName());
|
||||
put("KINGBASE",KingbaseDatabaseSynchImpl.class.getName());
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -0,0 +1,22 @@
|
||||
// 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)
|
||||
// Data : 2020/1/2
|
||||
// Location: beijing , china
|
||||
/////////////////////////////////////////////////////////////
|
||||
package com.gitee.dbswitch.dbsynch.dm;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.gitee.dbswitch.dbsynch.oracle.OracleDatabaseSynchImpl;
|
||||
|
||||
public class DmDatabaseSynchImpl extends OracleDatabaseSynchImpl {
|
||||
|
||||
public DmDatabaseSynchImpl(DataSource ds) {
|
||||
super(ds);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
// 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)
|
||||
// Data : 2020/1/2
|
||||
// Location: beijing , china
|
||||
/////////////////////////////////////////////////////////////
|
||||
package com.gitee.dbswitch.dbsynch.kingbase;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.gitee.dbswitch.dbsynch.pgsql.PostgresqlDatabaseSynchImpl;
|
||||
|
||||
public class KingbaseDatabaseSynchImpl extends PostgresqlDatabaseSynchImpl {
|
||||
|
||||
public KingbaseDatabaseSynchImpl(DataSource ds) {
|
||||
super(ds);
|
||||
}
|
||||
|
||||
}
|
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.gitee</groupId>
|
||||
<artifactId>dbswitch</artifactId>
|
||||
<version>1.5.2</version>
|
||||
<version>1.5.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dbswitch-dbwriter</artifactId>
|
||||
@@ -18,6 +18,11 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.gitee</groupId>
|
||||
<artifactId>dbswitch-dbcommon</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.gitee</groupId>
|
||||
|
@@ -12,9 +12,7 @@ package com.gitee.dbswitch.dbwriter;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import javax.sql.DataSource;
|
||||
import org.springframework.boot.jdbc.DatabaseDriver;
|
||||
import org.springframework.jdbc.support.JdbcUtils;
|
||||
import org.springframework.jdbc.support.MetaDataAccessException;
|
||||
import com.gitee.dbswitch.dbcommon.util.DatabaseAwareUtils;
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
/**
|
||||
@@ -36,6 +34,9 @@ public class DatabaseWriterFactory {
|
||||
put("POSTGRESQL", "com.gitee.dbswitch.dbwriter.gpdb.GreenplumCopyWriterImpl");
|
||||
put("GREENPLUM", "com.gitee.dbswitch.dbwriter.gpdb.GreenplumCopyWriterImpl");
|
||||
put("DB2", "com.gitee.dbswitch.dbwriter.db2.DB2WriterImpl");
|
||||
put("DM", "com.gitee.dbswitch.dbwriter.dm.DmWriterImpl");
|
||||
//对于kingbase当前只能使用insert模式
|
||||
put("KINGBASE", "com.gitee.dbswitch.dbwriter.kingbase.KingbaseInsertWriterImpl");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -57,11 +58,15 @@ public class DatabaseWriterFactory {
|
||||
* @return 写入器对象
|
||||
*/
|
||||
public static AbstractDatabaseWriter createDatabaseWriter(DataSource dataSource, boolean insert) {
|
||||
String type = DatabaseWriterFactory.getDatabaseNameByDataSource(dataSource).toUpperCase();
|
||||
String type = DatabaseAwareUtils.getDatabaseNameByDataSource(dataSource).toUpperCase();
|
||||
if (insert) {
|
||||
if ("POSTGRESQL".equalsIgnoreCase(type) || "GREENPLUM".equalsIgnoreCase(type)) {
|
||||
return new com.gitee.dbswitch.dbwriter.gpdb.GreenplumInsertWriterImpl(dataSource);
|
||||
}
|
||||
|
||||
if ("KINGBASE".equalsIgnoreCase(type)) {
|
||||
return new com.gitee.dbswitch.dbwriter.kingbase.KingbaseInsertWriterImpl(dataSource);
|
||||
}
|
||||
}
|
||||
|
||||
if (DATABASE_WRITER_MAPPER.containsKey(type.trim())) {
|
||||
@@ -81,29 +86,4 @@ public class DatabaseWriterFactory {
|
||||
throw new RuntimeException(String.format("[dbwrite] Unkown Supported database type (%s)", type));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据DataSource获取数据库的类型
|
||||
*
|
||||
* @param dataSource 数据库源
|
||||
* @return 数据库的类型:mysql/oracle/postgresql/greenplum
|
||||
*/
|
||||
private static String getDatabaseNameByDataSource(DataSource dataSource) {
|
||||
try {
|
||||
String productName = JdbcUtils.commonDatabaseName(
|
||||
JdbcUtils.extractDatabaseMetaData(dataSource, "getDatabaseProductName").toString());
|
||||
if (productName.equalsIgnoreCase("Greenplum")) {
|
||||
return "greenplum";
|
||||
} else if (productName.equalsIgnoreCase("Microsoft SQL Server")) {
|
||||
return "sqlserver";
|
||||
}
|
||||
|
||||
DatabaseDriver databaseDriver = DatabaseDriver.fromProductName(productName);
|
||||
if (databaseDriver == DatabaseDriver.UNKNOWN) {
|
||||
throw new IllegalStateException("[dbwrite] Unable to detect database type from data source instance");
|
||||
}
|
||||
return databaseDriver.getId();
|
||||
} catch (MetaDataAccessException ex) {
|
||||
throw new IllegalStateException("[dbwrite] Unable to detect database type", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,22 @@
|
||||
// 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)
|
||||
// Data : 2020/1/2
|
||||
// Location: beijing , china
|
||||
/////////////////////////////////////////////////////////////
|
||||
package com.gitee.dbswitch.dbwriter.dm;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import com.gitee.dbswitch.dbwriter.oracle.OracleWriterImpl;
|
||||
import com.gitee.dbswitch.dbwriter.IDatabaseWriter;
|
||||
|
||||
public class DmWriterImpl extends OracleWriterImpl implements IDatabaseWriter {
|
||||
|
||||
public DmWriterImpl(DataSource dataSource) {
|
||||
super(dataSource);
|
||||
}
|
||||
|
||||
}
|
@@ -473,9 +473,7 @@ public class GreenplumCopyWriterImpl extends AbstractDatabaseWriter implements I
|
||||
}
|
||||
});
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Greenplum copy write data affect count:{}", count);
|
||||
}
|
||||
|
||||
return count;
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
@@ -71,9 +71,6 @@ public class GreenplumInsertWriterImpl extends AbstractDatabaseWriter implements
|
||||
|
||||
recordValues.clear();
|
||||
transactionManager.commit(status);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Greenplum insert data affect count:{}", affectCount);
|
||||
}
|
||||
return affectCount;
|
||||
} catch (TransactionException e) {
|
||||
transactionManager.rollback(status);
|
||||
|
@@ -0,0 +1,22 @@
|
||||
// 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)
|
||||
// Data : 2020/1/2
|
||||
// Location: beijing , china
|
||||
/////////////////////////////////////////////////////////////
|
||||
package com.gitee.dbswitch.dbwriter.kingbase;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import com.gitee.dbswitch.dbwriter.IDatabaseWriter;
|
||||
import com.gitee.dbswitch.dbwriter.gpdb.GreenplumCopyWriterImpl;
|
||||
|
||||
public class KingbaseCopyWriterImpl extends GreenplumCopyWriterImpl implements IDatabaseWriter {
|
||||
|
||||
public KingbaseCopyWriterImpl(DataSource dataSource) {
|
||||
super(dataSource);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
// 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)
|
||||
// Data : 2020/1/2
|
||||
// Location: beijing , china
|
||||
/////////////////////////////////////////////////////////////
|
||||
package com.gitee.dbswitch.dbwriter.kingbase;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import com.gitee.dbswitch.dbwriter.IDatabaseWriter;
|
||||
import com.gitee.dbswitch.dbwriter.gpdb.GreenplumInsertWriterImpl;
|
||||
|
||||
public class KingbaseInsertWriterImpl extends GreenplumInsertWriterImpl implements IDatabaseWriter {
|
||||
|
||||
public KingbaseInsertWriterImpl(DataSource dataSource) {
|
||||
super(dataSource);
|
||||
}
|
||||
}
|
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.gitee</groupId>
|
||||
<artifactId>dbswitch</artifactId>
|
||||
<version>1.5.2</version>
|
||||
<version>1.5.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dbswitch-pgwriter</artifactId>
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.gitee</groupId>
|
||||
<artifactId>dbswitch</artifactId>
|
||||
<version>1.5.2</version>
|
||||
<version>1.5.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dbswitch-sql</artifactId>
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.gitee</groupId>
|
||||
<artifactId>dbswitch</artifactId>
|
||||
<version>1.5.2</version>
|
||||
<version>1.5.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dbswitch-webapi</artifactId>
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.gitee</groupId>
|
||||
<artifactId>dbswitch</artifactId>
|
||||
<version>1.5.2</version>
|
||||
<version>1.5.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>package-tool</artifactId>
|
||||
|
2
pom.xml
2
pom.xml
@@ -21,7 +21,7 @@
|
||||
|
||||
<groupId>com.gitee</groupId>
|
||||
<artifactId>dbswitch</artifactId>
|
||||
<version>1.5.2</version>
|
||||
<version>1.5.3</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>dbswitch</name>
|
||||
<description>database switch project</description>
|
||||
|
@@ -1,6 +1,6 @@
|
||||
@echo off
|
||||
|
||||
set APP_VERSION=1.5.2
|
||||
set APP_VERSION=1.5.3
|
||||
|
||||
echo "Clean Project ..."
|
||||
call mvn clean -f pom.xml
|
||||
|
Reference in New Issue
Block a user