[refactor](jdbc catalog) split oceanbase jdbc executor (#34869) (#35175)

pick #34869
This commit is contained in:
zy-kkk
2024-05-22 19:09:35 +08:00
committed by GitHub
parent 24990383ff
commit 05a390e050
6 changed files with 27 additions and 10 deletions

View File

@ -74,7 +74,8 @@ public abstract class JdbcClient {
case JdbcResource.MYSQL:
return new JdbcMySQLClient(jdbcClientConfig);
case JdbcResource.OCEANBASE:
return new JdbcOceanBaseClient(jdbcClientConfig);
JdbcOceanBaseClient jdbcOceanBaseClient = new JdbcOceanBaseClient(jdbcClientConfig);
return jdbcOceanBaseClient.createClient(jdbcClientConfig);
case JdbcResource.POSTGRESQL:
return new JdbcPostgreSQLClient(jdbcClientConfig);
case JdbcResource.ORACLE:

View File

@ -65,6 +65,12 @@ public class JdbcMySQLClient extends JdbcClient {
}
}
protected JdbcMySQLClient(JdbcClientConfig jdbcClientConfig, String dbType) {
super(jdbcClientConfig);
convertDateToNull = isConvertDatetimeToNull(jdbcClientConfig);
this.dbType = dbType;
}
@Override
public List<String> getDatabaseNameList() {
Connection conn = getConnection();

View File

@ -27,15 +27,15 @@ import java.sql.SQLException;
import java.sql.Statement;
public class JdbcOceanBaseClient extends JdbcClient {
private JdbcClient currentClient;
public JdbcOceanBaseClient(JdbcClientConfig jdbcClientConfig) {
super(jdbcClientConfig);
}
public JdbcClient createClient(JdbcClientConfig jdbcClientConfig) throws JdbcClientException {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = super.getConnection();
stmt = conn.createStatement();
@ -43,16 +43,17 @@ public class JdbcOceanBaseClient extends JdbcClient {
if (rs.next()) {
String compatibilityMode = rs.getString(2);
if ("MYSQL".equalsIgnoreCase(compatibilityMode)) {
currentClient = new JdbcMySQLClient(jdbcClientConfig);
return new JdbcMySQLClient(jdbcClientConfig, JdbcResource.OCEANBASE);
} else if ("ORACLE".equalsIgnoreCase(compatibilityMode)) {
currentClient = new JdbcOracleClient(jdbcClientConfig);
setOracleMode();
return new JdbcOracleClient(jdbcClientConfig, JdbcResource.OCEANBASE_ORACLE);
} else {
throw new JdbcClientException("Unsupported OceanBase compatibility mode: " + compatibilityMode);
}
} else {
throw new JdbcClientException("Failed to determine OceanBase compatibility mode");
}
} catch (SQLException | JdbcClientException e) {
closeClient();
} catch (SQLException e) {
throw new JdbcClientException("Failed to initialize JdbcOceanBaseClient", e.getMessage());
} finally {
close(rs, stmt, conn);
@ -61,10 +62,11 @@ public class JdbcOceanBaseClient extends JdbcClient {
@Override
protected Type jdbcTypeToDoris(JdbcFieldSchema fieldSchema) {
return currentClient.jdbcTypeToDoris(fieldSchema);
throw new UnsupportedOperationException("JdbcOceanBaseClient does not support jdbcTypeToDoris");
}
public void setOracleMode() {
private void setOracleMode() {
this.dbType = JdbcResource.OCEANBASE_ORACLE;
}
}

View File

@ -38,6 +38,11 @@ public class JdbcOracleClient extends JdbcClient {
super(jdbcClientConfig);
}
protected JdbcOracleClient(JdbcClientConfig jdbcClientConfig, String dbType) {
super(jdbcClientConfig);
this.dbType = dbType;
}
@Override
public String getTestQuery() {
return "SELECT 1 FROM dual";