mirror of
https://gitee.com/dromara/dbswitch.git
synced 2025-09-25 21:28:01 +00:00
version for 1.6.9
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.gitee.dbswitch</groupId>
|
||||
<artifactId>dbswitch-parent</artifactId>
|
||||
<version>1.6.8</version>
|
||||
<version>1.6.9</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dbswitch-dbwriter</artifactId>
|
||||
|
@@ -28,6 +28,7 @@ import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionException;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* 数据库写入抽象基类
|
||||
@@ -57,8 +58,8 @@ public abstract class AbstractDatabaseWriter implements IDatabaseWriter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareWrite(String schemaName, String tableName) {
|
||||
String sql = this.selectTableMetaDataSqlString(schemaName, tableName);
|
||||
public void prepareWrite(String schemaName, String tableName, List<String> fieldNames) {
|
||||
String sql = this.selectTableMetaDataSqlString(schemaName, tableName, fieldNames);
|
||||
Map<String, Integer> columnMetaData = new HashMap<>();
|
||||
jdbcTemplate.execute((Connection conn) -> {
|
||||
try (Statement stmt = conn.createStatement();
|
||||
@@ -85,8 +86,14 @@ public abstract class AbstractDatabaseWriter implements IDatabaseWriter {
|
||||
|
||||
}
|
||||
|
||||
protected String selectTableMetaDataSqlString(String schemaName, String tableName) {
|
||||
return String.format("SELECT * FROM \"%s\".\"%s\" WHERE 1=2", schemaName, tableName);
|
||||
protected String selectTableMetaDataSqlString(String schemaName, String tableName,
|
||||
List<String> fieldNames) {
|
||||
if (CollectionUtils.isEmpty(fieldNames)) {
|
||||
return String.format("SELECT * FROM \"%s\".\"%s\" WHERE 1=2", schemaName, tableName);
|
||||
} else {
|
||||
return String.format("SELECT \"%s\" FROM \"%s\".\"%s\" WHERE 1=2",
|
||||
StringUtils.join(fieldNames, "\",\""), schemaName, tableName);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract String getDatabaseProductName();
|
||||
|
@@ -32,7 +32,7 @@ public interface IDatabaseWriter {
|
||||
* @param schemaName schema名称
|
||||
* @param tableName table名称
|
||||
*/
|
||||
void prepareWrite(String schemaName, String tableName);
|
||||
void prepareWrite(String schemaName, String tableName,List<String> fieldNames);
|
||||
|
||||
/**
|
||||
* 批量数据写入
|
||||
|
@@ -24,6 +24,7 @@ import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionException;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* SQLServer批量写入实现类
|
||||
@@ -43,8 +44,14 @@ public class SqlServerWriterImpl extends AbstractDatabaseWriter implements IData
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String selectTableMetaDataSqlString(String schemaName, String tableName) {
|
||||
return String.format("SELECT * FROM [%s].[%s] WHERE 1=2", schemaName, tableName);
|
||||
protected String selectTableMetaDataSqlString(String schemaName, String tableName,
|
||||
List<String> fieldNames) {
|
||||
if (CollectionUtils.isEmpty(fieldNames)) {
|
||||
return String.format("SELECT * FROM [%s].[%s] WHERE 1=2", schemaName, tableName);
|
||||
} else {
|
||||
return String.format("SELECT [%s] FROM [%s].[%s] WHERE 1=2",
|
||||
StringUtils.join(fieldNames, "],["), schemaName, tableName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -32,6 +32,7 @@ import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* MySQL数据库写入实现类
|
||||
@@ -58,8 +59,14 @@ public class MySqlWriterImpl extends AbstractDatabaseWriter implements IDatabase
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String selectTableMetaDataSqlString(String schemaName, String tableName) {
|
||||
return String.format("SELECT * FROM `%s`.`%s` WHERE 1=2", schemaName, tableName);
|
||||
protected String selectTableMetaDataSqlString(String schemaName, String tableName,
|
||||
List<String> fieldNames) {
|
||||
if (CollectionUtils.isEmpty(fieldNames)) {
|
||||
return String.format("SELECT * FROM `%s`.`%s` WHERE 1=2", schemaName, tableName);
|
||||
} else {
|
||||
return String.format("SELECT `%s` FROM `%s`.`%s` WHERE 1=2",
|
||||
StringUtils.join(fieldNames, "`,`"), schemaName, tableName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user