修正OceanBase测试连接

This commit is contained in:
inrgihc
2024-11-18 21:25:32 +08:00
parent 1bf6fe61c1
commit 46d3dff7a1
3 changed files with 19 additions and 3 deletions

View File

@@ -10,7 +10,6 @@
package com.gitee.dbswitch.provider.meta;
import cn.hutool.core.text.StrPool;
import com.gitee.dbswitch.common.type.ProductTypeEnum;
import com.gitee.dbswitch.common.type.TableIndexEnum;
import com.gitee.dbswitch.provider.AbstractCommonProvider;
import com.gitee.dbswitch.provider.ProductFactoryProvider;
@@ -60,6 +59,15 @@ public abstract class AbstractMetadataProvider
this.catalogName = catalogName;
}
@Override
public void testConnection(Connection connection, String pingSql) {
try (Statement st = connection.createStatement()) {
st.execute(pingSql);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
@Override
public List<String> querySchemaList(Connection connection) {
Set<String> ret = new LinkedHashSet<>();

View File

@@ -30,6 +30,14 @@ public interface MetadataProvider {
*/
ProductTypeEnum getProductType();
/**
* 测试连接原始SQL语句
*
* @param connection JDBC连接
* @param pingSql 测试连接的SQL语句
*/
void testConnection(Connection connection, String pingSql);
/**
* 获取数据库的模式schema列表
*

View File

@@ -103,9 +103,9 @@ public class OceanbaseMetadataQueryProvider extends AbstractMetadataProvider {
@Override
public void testQuerySQL(Connection connection, String sql) {
if (StringUtils.equals(ProductTypeEnum.OCEANBASE.getSql(), sql)) {
this.delegate.testQuerySQL(connection, this.dialect.getSql());
this.delegate.testConnection(connection, this.dialect.getSql());
} else {
this.delegate.testQuerySQL(connection, sql);
this.delegate.testConnection(connection, sql);
}
}