mirror of
https://gitee.com/dromara/dbswitch.git
synced 2025-10-18 15:43:53 +00:00
支持db2和MariaDB数据库
This commit is contained in:
@@ -16,6 +16,7 @@ import javax.sql.DataSource;
|
||||
import org.springframework.boot.jdbc.DatabaseDriver;
|
||||
import org.springframework.jdbc.support.JdbcUtils;
|
||||
import org.springframework.jdbc.support.MetaDataAccessException;
|
||||
import com.weishao.dbswitch.dbcommon.database.impl.DB2DatabaseOperator;
|
||||
import com.weishao.dbswitch.dbcommon.database.impl.GreenplumDatabaseOperator;
|
||||
import com.weishao.dbswitch.dbcommon.database.impl.MysqlDatabaseOperator;
|
||||
import com.weishao.dbswitch.dbcommon.database.impl.OracleDatabaseOperator;
|
||||
@@ -40,6 +41,7 @@ public final class DatabaseOperatorFactory {
|
||||
put("SQLSERVER", SqlServerDatabaseOperator.class.getName());
|
||||
put("POSTGRESQL", PostgreSqlDatabaseOperator.class.getName());
|
||||
put("GREENPLUM", GreenplumDatabaseOperator.class.getName());
|
||||
put("DB2", DB2DatabaseOperator.class.getName());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -71,7 +73,7 @@ public final class DatabaseOperatorFactory {
|
||||
* 根据DataSource获取数据库的类型
|
||||
*
|
||||
* @param dataSource 数据库源
|
||||
* @return 数据库的类型:mysql/oracle/postgresql/sqlserver/greenplum
|
||||
* @return 数据库的类型:mysql/oracle/postgresql/sqlserver/greenplum/db2
|
||||
*/
|
||||
public static String getDatabaseNameByDataSource(DataSource dataSource) {
|
||||
try {
|
||||
|
@@ -0,0 +1,64 @@
|
||||
// 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.weishao.dbswitch.dbcommon.database.impl;
|
||||
|
||||
import java.util.List;
|
||||
import javax.sql.DataSource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.weishao.dbswitch.dbcommon.database.AbstractDatabaseOperator;
|
||||
import com.weishao.dbswitch.dbcommon.database.IDatabaseOperator;
|
||||
import com.weishao.dbswitch.dbcommon.pojo.StatementResultSet;
|
||||
|
||||
/**
|
||||
* DB2数据库实现类
|
||||
*
|
||||
* @author tang
|
||||
*
|
||||
*/
|
||||
public class DB2DatabaseOperator extends AbstractDatabaseOperator implements IDatabaseOperator {
|
||||
|
||||
public DB2DatabaseOperator(DataSource dataSource) {
|
||||
super(dataSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSelectTableSql(String schemaName, String tableName, List<String> fields) {
|
||||
return String.format("select \"%s\" from \"%s\".\"%s\" ", StringUtils.join(fields, "\",\""), schemaName,
|
||||
tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatementResultSet queryTableData(String schemaName, String tableName, List<String> fields,
|
||||
List<String> orders) {
|
||||
String sql = String.format("select \"%s\" from \"%s\".\"%s\" order by \"%s\" asc ",
|
||||
StringUtils.join(fields, "\",\""), schemaName, tableName, StringUtils.join(orders, "\",\""));
|
||||
return this.selectTableData(sql, this.fetchSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatementResultSet queryTableData(String schemaName, String tableName, List<String> fields) {
|
||||
String sql = String.format("select \"%s\" from \"%s\".\"%s\" ", StringUtils.join(fields, "\",\""), schemaName,
|
||||
tableName);
|
||||
return this.selectTableData(sql, this.fetchSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void truncateTableData(String schemaName, String tableName) {
|
||||
String sql = String.format("TRUNCATE TABLE \"%s\".\"%s\" immediate ", schemaName, tableName);
|
||||
this.executeSql(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropTable(String schemaName, String tableName) {
|
||||
String sql = String.format("DROP TABLE \"%s\".\"%s\" ", schemaName, tableName);
|
||||
this.executeSql(sql);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user