mirror of
https://gitee.com/dromara/dbswitch.git
synced 2025-09-09 21:49:08 +00:00
使用问题改进
This commit is contained in:
@@ -12,6 +12,7 @@ package com.gitee.dbswitch.product.gbase;
|
||||
import com.gitee.dbswitch.annotation.Product;
|
||||
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||
import com.gitee.dbswitch.features.ProductFeatures;
|
||||
import com.gitee.dbswitch.product.mysql.MysqlMetadataQueryProvider;
|
||||
import com.gitee.dbswitch.provider.AbstractFactoryProvider;
|
||||
import com.gitee.dbswitch.provider.meta.MetadataProvider;
|
||||
import com.gitee.dbswitch.provider.sync.AutoCastTableDataSynchronizer;
|
||||
@@ -33,7 +34,7 @@ public class GbaseFactoryProvider extends AbstractFactoryProvider {
|
||||
|
||||
@Override
|
||||
public MetadataProvider createMetadataQueryProvider() {
|
||||
return new GbaseMetadataQueryProvider(this);
|
||||
return new MysqlMetadataQueryProvider(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,35 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -10,7 +10,6 @@
|
||||
package com.gitee.dbswitch.product.mysql;
|
||||
|
||||
import com.gitee.dbswitch.common.consts.Constants;
|
||||
import com.gitee.dbswitch.common.util.JdbcUrlUtils;
|
||||
import com.gitee.dbswitch.provider.ProductFactoryProvider;
|
||||
import com.gitee.dbswitch.provider.meta.AbstractMetadataProvider;
|
||||
import com.gitee.dbswitch.schema.ColumnDescription;
|
||||
@@ -25,7 +24,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@@ -44,18 +43,14 @@ public class MysqlMetadataQueryProvider extends AbstractMetadataProvider {
|
||||
|
||||
@Override
|
||||
public List<String> querySchemaList(Connection connection) {
|
||||
try {
|
||||
final Matcher matcher = JdbcUrlUtils
|
||||
.getPattern("jdbc:mysql://{host}[:{port}]/[{database}][\\?{params}]")
|
||||
.matcher(connection.getMetaData().getURL());
|
||||
if (matcher.matches()) {
|
||||
return Collections.singletonList(matcher.group("database"));
|
||||
List<String> result = new ArrayList<>();
|
||||
try (ResultSet rs = connection.getMetaData().getCatalogs()) {
|
||||
while (rs.next()) {
|
||||
Optional.ofNullable(rs.getString(1)).ifPresent(result::add);
|
||||
}
|
||||
throw new RuntimeException("get database name from jdbc url failed!");
|
||||
return result.stream().distinct().collect(Collectors.toList());
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +82,27 @@ public class MysqlMetadataQueryProvider extends AbstractMetadataProvider {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized TableDescription queryTableMeta(Connection connection, String schemaName,
|
||||
String tableName) {
|
||||
setCatalogName(schemaName);
|
||||
return super.queryTableMeta(connection, schemaName, tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<String> queryTableColumnName(Connection connection, String schemaName,
|
||||
String tableName) {
|
||||
setCatalogName(schemaName);
|
||||
return super.queryTableColumnName(connection, schemaName, tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<String> queryTablePrimaryKeys(Connection connection, String schemaName,
|
||||
String tableName) {
|
||||
setCatalogName(schemaName);
|
||||
return super.queryTablePrimaryKeys(connection, schemaName, tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTableDDL(Connection connection, String schemaName, String tableName) {
|
||||
List<String> result = new ArrayList<>();
|
||||
|
Reference in New Issue
Block a user