Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dailai committed Sep 13, 2024
1 parent 881ddbf commit f5ffed1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.seatunnel.common.exception.CommonErrorCode;
import org.apache.seatunnel.common.exception.SeaTunnelRuntimeException;
import org.apache.seatunnel.common.utils.JdbcUrlUtil;
import org.apache.seatunnel.common.utils.SeaTunnelException;
import org.apache.seatunnel.connectors.seatunnel.jdbc.catalog.utils.CatalogUtils;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -290,6 +291,8 @@ public boolean databaseExists(String databaseName) throws CatalogException {
return listDatabases().contains(databaseName);
}
throw e;
} catch (SQLException e) {
throw new SeaTunnelException("Failed to querySQLResult", e);
}
}

Expand Down Expand Up @@ -350,6 +353,8 @@ && listTables(tablePath.getDatabaseName())
}
}
throw e1;
} catch (SQLException e) {
throw new SeaTunnelException("Failed to querySQLResult", e);
}
}

Expand Down Expand Up @@ -566,13 +571,10 @@ protected List<String> queryString(String url, String sql, ResultSetConsumer<Str
}
}

protected boolean querySQLResultExists(String dbUrl, String sql) {
protected boolean querySQLResultExists(String dbUrl, String sql) throws SQLException {
try (PreparedStatement stmt = getConnection(dbUrl).prepareStatement(sql);
ResultSet rs = stmt.executeQuery()) {
return rs.next();
} catch (SQLException e) {
log.info("query exists error", e);
return false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,13 @@ public boolean databaseExists(String databaseName) throws CatalogException {

@Override
public boolean tableExists(TablePath tablePath) throws CatalogException {
return querySQLResultExists(
this.getUrlFromDatabaseName(tablePath.getDatabaseName()),
getTableWithConditionSql(tablePath));
try {
return querySQLResultExists(
this.getUrlFromDatabaseName(tablePath.getDatabaseName()),
getTableWithConditionSql(tablePath));
} catch (SQLException e) {
throw new SeaTunnelException("Failed to querySQLResult", e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
import org.apache.seatunnel.api.table.catalog.exception.DatabaseNotExistException;
import org.apache.seatunnel.api.table.catalog.exception.TableAlreadyExistException;
import org.apache.seatunnel.common.utils.JdbcUrlUtil;
import org.apache.seatunnel.common.utils.SeaTunnelException;
import org.apache.seatunnel.connectors.seatunnel.jdbc.catalog.oracle.OracleCatalog;

import java.sql.SQLException;
import java.util.List;

import static org.apache.seatunnel.shade.com.google.common.base.Preconditions.checkNotNull;
Expand Down Expand Up @@ -52,9 +54,13 @@ protected String getDatabaseWithConditionSql(String databaseName) {

@Override
public boolean tableExists(TablePath tablePath) throws CatalogException {
return querySQLResultExists(
this.getUrlFromDatabaseName(tablePath.getDatabaseName()),
getTableWithConditionSql(tablePath));
try {
return querySQLResultExists(
this.getUrlFromDatabaseName(tablePath.getDatabaseName()),
getTableWithConditionSql(tablePath));
} catch (SQLException e) {
throw new SeaTunnelException("Failed to querySQLResult", e);
}
}

@Override
Expand Down

0 comments on commit f5ffed1

Please sign in to comment.