You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "TyrantLucifer (via GitHub)" <gi...@apache.org> on 2023/03/29 06:31:40 UTC

[GitHub] [incubator-seatunnel] TyrantLucifer commented on a diff in pull request #4444: [Feature][Connector v2] Supported preSQL execution for JDBC Sink

TyrantLucifer commented on code in PR #4444:
URL: https://github.com/apache/incubator-seatunnel/pull/4444#discussion_r1151451086


##########
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/sink/JdbcSink.java:
##########
@@ -140,4 +147,23 @@ public Optional<Serializer<XidInfo>> getCommitInfoSerializer() {
         }
         return Optional.empty();
     }
+
+    private void preSqlExecution() {
+        if (this.jdbcSinkConfig.getPreSql() != null) {
+            for (String preSql : this.jdbcSinkConfig.getPreSql()) {
+                try {
+                    JdbcConnectionProvider jdbcConnectionProvider =
+                            new SimpleJdbcConnectionProvider(
+                                    jdbcSinkConfig.getJdbcConnectionConfig());
+                    try (Connection conn = jdbcConnectionProvider.getOrEstablishConnection();
+                            PreparedStatement pStmt = conn.prepareStatement(preSql)) {
+                        pStmt.execute();
+                    }
+                } catch (Exception e) {
+                    throw new PrepareFailException(

Review Comment:
   ```suggestion
                       throw new JdbcConnectorException(
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org