Skip to content

Commit

Permalink
Merge pull request #2074 from xieruiming/fix_conn
Browse files Browse the repository at this point in the history
 postSql use DriverManager to get connection
  • Loading branch information
xieruiming authored Mar 18, 2024
2 parents e71a315 + ae3c3a7 commit 072b24f
Showing 1 changed file with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,32 +191,34 @@ public List<Configuration> split(Configuration originalConfig,
// 一般来说,是需要推迟到 task 中进行post 的执行(单表情况例外)
public void post(Configuration originalConfig) {

String username = originalConfig.getString(Key.USERNAME);
String password = originalConfig.getString(Key.PASSWORD);

String jdbcUrl = originalConfig.getString(Key.JDBC_URL);
try {
String username = originalConfig.getString(Key.USERNAME);
String password = originalConfig.getString(Key.PASSWORD);

String table = originalConfig.getString(Key.TABLE);
String jdbcUrl = originalConfig.getString(Key.JDBC_URL);

List<String> postSqls = originalConfig.getList(Key.POST_SQL,
String.class);
List<String> renderedPostSqls = WriterUtil.renderPreOrPostSqls(
postSqls, table);
String table = originalConfig.getString(Key.TABLE);

if (null != renderedPostSqls && !renderedPostSqls.isEmpty()) {
// 说明有 postSql 配置,则此处删除掉
originalConfig.remove(Key.POST_SQL);
String tempJdbcUrl = jdbcUrl.replace("postgresql", "hologres");
Connection conn = DBUtil.getConnection(this.dataBaseType,
tempJdbcUrl, username, password);
List<String> postSqls = originalConfig.getList(Key.POST_SQL,
String.class);
List<String> renderedPostSqls = WriterUtil.renderPreOrPostSqls(
postSqls, table);

LOG.info(
"Begin to execute postSqls:[{}]. context info:{}.",
StringUtils.join(renderedPostSqls, ";"), tempJdbcUrl);
WriterUtil.executeSqls(conn, renderedPostSqls, tempJdbcUrl, dataBaseType);
DBUtil.closeDBResources(null, null, conn);
if (null != renderedPostSqls && !renderedPostSqls.isEmpty()) {
// 说明有 postSql 配置,则此处删除掉
originalConfig.remove(Key.POST_SQL);
String tempJdbcUrl = jdbcUrl.replace("postgresql", "hologres");
try (Connection conn = DriverManager.getConnection(
tempJdbcUrl, username, password)) {
LOG.info(
"Begin to execute postSqls:[{}]. context info:{}.",
StringUtils.join(renderedPostSqls, ";"), tempJdbcUrl);
WriterUtil.executeSqls(conn, renderedPostSqls, tempJdbcUrl, dataBaseType);
}
}
} catch (SQLException e) {
throw DataXException.asDataXException(DBUtilErrorCode.SQL_EXECUTE_FAIL, e);
}

}

public void destroy(Configuration originalConfig) {
Expand Down

0 comments on commit 072b24f

Please sign in to comment.