From c91f7d7e66ba32e17be49706cac59847054b8718 Mon Sep 17 00:00:00 2001 From: kentoyoshida Date: Mon, 8 Jul 2024 12:37:01 +0700 Subject: [PATCH] Refactor to use try-with-resources for SnowflakeOutputConnection in CopyTask - Updated the `call` method in `CopyTask` to use try-with-resources for managing `SnowflakeOutputConnection`. - Ensured proper resource management and automatic closure of the connection. - Improved code readability and reliability by eliminating the need for explicit connection close in the finally block. --- .../embulk/output/snowflake/SnowflakeCopyBatchInsert.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/org/embulk/output/snowflake/SnowflakeCopyBatchInsert.java b/src/main/java/org/embulk/output/snowflake/SnowflakeCopyBatchInsert.java index 2b64839..abca3cc 100644 --- a/src/main/java/org/embulk/output/snowflake/SnowflakeCopyBatchInsert.java +++ b/src/main/java/org/embulk/output/snowflake/SnowflakeCopyBatchInsert.java @@ -427,8 +427,7 @@ public Void call() throws SQLException, InterruptedException, ExecutionException try { uploadFuture.get(); - SnowflakeOutputConnection con = (SnowflakeOutputConnection) connector.connect(true); - try { + try (SnowflakeOutputConnection con = (SnowflakeOutputConnection) connector.connect(true)) { logger.info("Running COPY from file {}", snowflakeStageFileName); long startTime = System.currentTimeMillis(); @@ -446,9 +445,6 @@ public Void call() throws SQLException, InterruptedException, ExecutionException logger.info( String.format( "Loaded file %s (%.2f seconds for COPY)", snowflakeStageFileName, seconds)); - - } finally { - con.close(); } } finally { if (deleteStageFile) {