代码接口调整

This commit is contained in:
inrgihc
2024-07-24 21:45:20 +08:00
parent 5ec8f5c48a
commit 815528b817
25 changed files with 179 additions and 160 deletions

View File

@@ -46,8 +46,8 @@ public abstract class AbstractCommonProvider {
return dataSource;
}
public ProductFeatures getProductFeatures() {
return productFeatures;
public <T extends ProductFeatures> T getProductFeatures() {
return (T) productFeatures;
}
protected String getTableFieldsQuerySQL(String schemaName, String tableName) {

View File

@@ -19,6 +19,7 @@ import com.gitee.dbswitch.schema.ColumnMetaData;
import com.gitee.dbswitch.schema.IndexDescription;
import com.gitee.dbswitch.schema.IndexFieldMeta;
import com.gitee.dbswitch.schema.TableDescription;
import com.gitee.dbswitch.schema.SourceProperties;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
@@ -247,7 +248,7 @@ public abstract class AbstractMetadataProvider
@Override
public void postAppendCreateTableSql(StringBuilder builder, String tblComment, List<String> primaryKeys,
Map<String, String> tblProperties) {
SourceProperties tblProperties) {
// Nothing, please override by subclass!
}

View File

@@ -14,9 +14,9 @@ import com.gitee.dbswitch.schema.ColumnDescription;
import com.gitee.dbswitch.schema.ColumnMetaData;
import com.gitee.dbswitch.schema.IndexDescription;
import com.gitee.dbswitch.schema.TableDescription;
import com.gitee.dbswitch.schema.SourceProperties;
import java.sql.Connection;
import java.util.List;
import java.util.Map;
/**
* 元数据查询
@@ -183,7 +183,7 @@ public interface MetadataProvider {
* @param tblProperties 表的属性
*/
void postAppendCreateTableSql(StringBuilder builder, String tblComment, List<String> primaryKeys,
Map<String, String> tblProperties);
SourceProperties tblProperties);
/**
* 主键列转换为逗号分隔的字符串
@@ -203,7 +203,7 @@ public interface MetadataProvider {
List<String> getTableColumnCommentDefinition(TableDescription td, List<ColumnDescription> cds);
/**
* 为hive定制的获取联邦建表导数SQL列表
* 为hive定制的获取联邦建表导数SQL列表
*
* @param fieldNames 字段结构信息
* @param primaryKeys 主键字段信息
@@ -214,7 +214,7 @@ public interface MetadataProvider {
* @return 建表导数SQL列表
*/
default List<String> getCreateTableSqlList(List<ColumnDescription> fieldNames, List<String> primaryKeys,
String schemaName, String tableName, String tableRemarks, boolean autoIncr, Map<String, String> tblProperties) {
String schemaName, String tableName, String tableRemarks, boolean autoIncr, SourceProperties tblProperties) {
throw new UnsupportedOperationException("Unsupported function!");
}
}

View File

@@ -14,6 +14,7 @@ import com.gitee.dbswitch.common.consts.Constants;
import com.gitee.dbswitch.common.entity.ResultSetWrapper;
import com.gitee.dbswitch.common.type.ProductTypeEnum;
import com.gitee.dbswitch.common.util.ObjectCastUtils;
import com.gitee.dbswitch.features.ProductFeatures;
import com.gitee.dbswitch.provider.AbstractCommonProvider;
import com.gitee.dbswitch.provider.ProductFactoryProvider;
import com.gitee.dbswitch.schema.SchemaTableData;
@@ -68,7 +69,8 @@ public class DefaultTableDataQueryProvider
sb.append(" ORDER BY ");
sb.append(productType.quoteName(StringUtils.join(orders, productType.quoteName(","))));
}
return this.selectTableData(sb.toString(), getProductFeatures().convertFetchSize(this.fetchSize));
ProductFeatures features = getProductFeatures();
return this.selectTableData(sb.toString(), features.convertFetchSize(this.fetchSize));
}
protected ResultSetWrapper selectTableData(String sql, int fetchSize) {

View File

@@ -38,7 +38,7 @@ public class DefaultTableDataSynchronizeProvider
private JdbcTemplate jdbcTemplate;
private PlatformTransactionManager tx;
private Map<String, Integer> columnType;
protected Map<String, Integer> columnType;
protected List<String> fieldOrders;
protected List<String> pksOrders;
protected String insertStatementSql;

View File

@@ -0,0 +1,82 @@
package com.gitee.dbswitch.schema;
import com.gitee.dbswitch.common.type.ProductTypeEnum;
import java.util.List;
public class SourceProperties {
private ProductTypeEnum productType;
private String driverClass;
private String jdbcUrl;
private String username;
private String password;
private String schemaName;
private String tableName;
private List<String> columnNames;
public ProductTypeEnum getProductType() {
return productType;
}
public void setProductType(ProductTypeEnum productType) {
this.productType = productType;
}
public String getDriverClass() {
return driverClass;
}
public void setDriverClass(String driverClass) {
this.driverClass = driverClass;
}
public String getJdbcUrl() {
return jdbcUrl;
}
public void setJdbcUrl(String jdbcUrl) {
this.jdbcUrl = jdbcUrl;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getSchemaName() {
return schemaName;
}
public void setSchemaName(String schemaName) {
this.schemaName = schemaName;
}
public String getTableName() {
return tableName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
public List<String> getColumnNames() {
return columnNames;
}
public void setColumnNames(List<String> columnNames) {
this.columnNames = columnNames;
}
}

View File

@@ -19,12 +19,12 @@ import com.gitee.dbswitch.schema.IndexDescription;
import com.gitee.dbswitch.schema.SchemaTableData;
import com.gitee.dbswitch.schema.SchemaTableMeta;
import com.gitee.dbswitch.schema.TableDescription;
import com.gitee.dbswitch.schema.SourceProperties;
import com.gitee.dbswitch.util.GenerateSqlUtils;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
/**
@@ -224,7 +224,7 @@ public class DefaultMetadataService implements MetadataService {
@Override
public List<String> getDDLCreateTableSQL(MetadataProvider provider,
List<ColumnDescription> fieldNames, List<String> primaryKeys, String schemaName,
String tableName, String tableRemarks, boolean autoIncr, Map<String, String> tblProperties) {
String tableName, String tableRemarks, boolean autoIncr, SourceProperties tblProperties) {
return GenerateSqlUtils.getDDLCreateTableSQL(
provider, fieldNames, primaryKeys, schemaName, tableName, tableRemarks, autoIncr, tblProperties);
}

View File

@@ -11,12 +11,12 @@ package com.gitee.dbswitch.service;
import com.gitee.dbswitch.provider.meta.MetadataProvider;
import com.gitee.dbswitch.schema.ColumnDescription;
import com.gitee.dbswitch.schema.SourceProperties;
import com.gitee.dbswitch.schema.IndexDescription;
import com.gitee.dbswitch.schema.SchemaTableData;
import com.gitee.dbswitch.schema.SchemaTableMeta;
import com.gitee.dbswitch.schema.TableDescription;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
public interface MetadataService {
@@ -159,5 +159,5 @@ public interface MetadataService {
*/
List<String> getDDLCreateTableSQL(MetadataProvider provider, List<ColumnDescription> fieldNames,
List<String> primaryKeys, String schemaName, String tableName, String tableRemarks,
boolean autoIncr, Map<String, String> tblProperties);
boolean autoIncr, SourceProperties tblProperties);
}

View File

@@ -17,12 +17,11 @@ import com.gitee.dbswitch.provider.meta.MetadataProvider;
import com.gitee.dbswitch.schema.ColumnDescription;
import com.gitee.dbswitch.schema.ColumnMetaData;
import com.gitee.dbswitch.schema.TableDescription;
import com.gitee.dbswitch.schema.SourceProperties;
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.experimental.UtilityClass;
@@ -52,7 +51,7 @@ public final class GenerateSqlUtils {
false,
null,
autoIncr,
Collections.emptyMap());
null);
}
public static String getDDLCreateTableSQL(
@@ -64,7 +63,7 @@ public final class GenerateSqlUtils {
boolean withRemarks,
String tableRemarks,
boolean autoIncr,
Map<String, String> tblProperties) {
SourceProperties tblProperties) {
ProductTypeEnum type = provider.getProductType();
StringBuilder sb = new StringBuilder();
Set<String> fieldNameSets = fieldNames.stream()
@@ -120,7 +119,7 @@ public final class GenerateSqlUtils {
String tableName,
String tableRemarks,
boolean autoIncr,
Map<String, String> tblProperties) {
SourceProperties tblProperties) {
ProductTypeEnum productType = provider.getProductType();
if (productType.isLikeHive()) {
return provider.getCreateTableSqlList(