This is an automated email from the ASF dual-hosted git repository.

mattyb149 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new a239eea  NIFI-8996: Close JDBC statements in PutHive*QL processors.
a239eea is described below

commit a239eea8ff07e836d391ff0c5e73503c28369d9b
Author: Peter Turcsanyi <[email protected]>
AuthorDate: Tue Aug 3 20:41:43 2021 +0200

    NIFI-8996: Close JDBC statements in PutHive*QL processors.
    
    Signed-off-by: Matthew Burgess <[email protected]>
    
    This closes #5280
---
 .../org/apache/nifi/processors/hive/PutHiveQL.java | 45 ++++++++++----------
 .../apache/nifi/processors/hive/PutHive3QL.java    | 49 +++++++++++-----------
 .../apache/nifi/processors/hive/PutHive_1_1QL.java | 45 ++++++++++----------
 3 files changed, 71 insertions(+), 68 deletions(-)

diff --git 
a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/processors/hive/PutHiveQL.java
 
b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/processors/hive/PutHiveQL.java
index e1aeade..57462c4 100644
--- 
a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/processors/hive/PutHiveQL.java
+++ 
b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/processors/hive/PutHiveQL.java
@@ -230,29 +230,30 @@ public class PutHiveQL extends AbstractHiveQLProcessor {
 
                 final String hiveQL = hiveQLStr.trim();
                 if (!StringUtils.isEmpty(hiveQL)) {
-                    final PreparedStatement stmt = 
conn.prepareStatement(hiveQL);
-
-                    // Get ParameterMetadata
-                    // Hive JDBC Doesn't support this yet:
-                    // ParameterMetaData pmd = stmt.getParameterMetaData();
-                    // int paramCount = pmd.getParameterCount();
-                    int paramCount = StringUtils.countMatches(hiveQL, "?");
-
-                    if (paramCount > 0) {
-                        loc = setParameters(loc, stmt, paramCount, 
flowFile.getAttributes());
+                    try (final PreparedStatement stmt = 
conn.prepareStatement(hiveQL)) {
+
+                        // Get ParameterMetadata
+                        // Hive JDBC Doesn't support this yet:
+                        // ParameterMetaData pmd = stmt.getParameterMetaData();
+                        // int paramCount = pmd.getParameterCount();
+                        int paramCount = StringUtils.countMatches(hiveQL, "?");
+
+                        if (paramCount > 0) {
+                            loc = setParameters(loc, stmt, paramCount, 
flowFile.getAttributes());
+                        }
+
+                        // Parse hiveQL and extract input/output tables
+                        try {
+                            tableNames.addAll(findTableNames(hiveQL));
+                        } catch (Exception e) {
+                            // If failed to parse the query, just log a 
warning message, but continue.
+                            getLogger().warn("Failed to parse hiveQL: {} due 
to {}", new Object[]{hiveQL, e}, e);
+                        }
+
+                        // Execute the statement
+                        stmt.execute();
+                        fc.proceed();
                     }
-
-                    // Parse hiveQL and extract input/output tables
-                    try {
-                        tableNames.addAll(findTableNames(hiveQL));
-                    } catch (Exception e) {
-                        // If failed to parse the query, just log a warning 
message, but continue.
-                        getLogger().warn("Failed to parse hiveQL: {} due to 
{}", new Object[]{hiveQL, e}, e);
-                    }
-
-                    // Execute the statement
-                    stmt.execute();
-                    fc.proceed();
                 }
             }
 
diff --git 
a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive3-processors/src/main/java/org/apache/nifi/processors/hive/PutHive3QL.java
 
b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive3-processors/src/main/java/org/apache/nifi/processors/hive/PutHive3QL.java
index 7d137e7..9f24248 100644
--- 
a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive3-processors/src/main/java/org/apache/nifi/processors/hive/PutHive3QL.java
+++ 
b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive3-processors/src/main/java/org/apache/nifi/processors/hive/PutHive3QL.java
@@ -231,31 +231,32 @@ public class PutHive3QL extends AbstractHive3QLProcessor {
 
                 final String hiveQL = hiveQLStr.trim();
                 if (!StringUtils.isEmpty(hiveQL)) {
-                    final PreparedStatement stmt = 
conn.prepareStatement(hiveQL);
-
-                    // Get ParameterMetadata
-                    // Hive JDBC Doesn't support this yet:
-                    // ParameterMetaData pmd = stmt.getParameterMetaData();
-                    // int paramCount = pmd.getParameterCount();
-                    int paramCount = StringUtils.countMatches(hiveQL, "?");
-
-                    if (paramCount > 0) {
-                        loc = setParameters(loc, stmt, paramCount, 
flowFile.getAttributes());
-                    }
-
-                    // Parse hiveQL and extract input/output tables
-                    try {
-                        tableNames.addAll(findTableNames(hiveQL));
-                    } catch (Exception e) {
-                        // If failed to parse the query, just log a warning 
message, but continue.
-                        getLogger().warn("Failed to parse hiveQL: {} due to 
{}", new Object[]{hiveQL, e}, e);
+                    try (final PreparedStatement stmt = 
conn.prepareStatement(hiveQL)) {
+
+                        // Get ParameterMetadata
+                        // Hive JDBC Doesn't support this yet:
+                        // ParameterMetaData pmd = stmt.getParameterMetaData();
+                        // int paramCount = pmd.getParameterCount();
+                        int paramCount = StringUtils.countMatches(hiveQL, "?");
+
+                        if (paramCount > 0) {
+                            loc = setParameters(loc, stmt, paramCount, 
flowFile.getAttributes());
+                        }
+
+                        // Parse hiveQL and extract input/output tables
+                        try {
+                            tableNames.addAll(findTableNames(hiveQL));
+                        } catch (Exception e) {
+                            // If failed to parse the query, just log a 
warning message, but continue.
+                            getLogger().warn("Failed to parse hiveQL: {} due 
to {}", new Object[]{hiveQL, e}, e);
+                        }
+
+                        
stmt.setQueryTimeout(context.getProperty(QUERY_TIMEOUT).evaluateAttributeExpressions(flowFile).asInteger());
+
+                        // Execute the statement
+                        stmt.execute();
+                        fc.proceed();
                     }
-
-                    
stmt.setQueryTimeout(context.getProperty(QUERY_TIMEOUT).evaluateAttributeExpressions(flowFile).asInteger());
-
-                    // Execute the statement
-                    stmt.execute();
-                    fc.proceed();
                 }
             }
 
diff --git 
a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive_1_1-processors/src/main/java/org/apache/nifi/processors/hive/PutHive_1_1QL.java
 
b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive_1_1-processors/src/main/java/org/apache/nifi/processors/hive/PutHive_1_1QL.java
index d337f0d..0b62038 100644
--- 
a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive_1_1-processors/src/main/java/org/apache/nifi/processors/hive/PutHive_1_1QL.java
+++ 
b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive_1_1-processors/src/main/java/org/apache/nifi/processors/hive/PutHive_1_1QL.java
@@ -230,29 +230,30 @@ public class PutHive_1_1QL extends 
AbstractHive_1_1QLProcessor {
 
                 final String hiveQL = hiveQLStr.trim();
                 if (!StringUtils.isEmpty(hiveQL)) {
-                    final PreparedStatement stmt = 
conn.prepareStatement(hiveQL);
-
-                    // Get ParameterMetadata
-                    // Hive JDBC Doesn't support this yet:
-                    // ParameterMetaData pmd = stmt.getParameterMetaData();
-                    // int paramCount = pmd.getParameterCount();
-                    int paramCount = StringUtils.countMatches(hiveQL, "?");
-
-                    if (paramCount > 0) {
-                        loc = setParameters(loc, stmt, paramCount, 
flowFile.getAttributes());
+                    try (final PreparedStatement stmt = 
conn.prepareStatement(hiveQL)) {
+
+                        // Get ParameterMetadata
+                        // Hive JDBC Doesn't support this yet:
+                        // ParameterMetaData pmd = stmt.getParameterMetaData();
+                        // int paramCount = pmd.getParameterCount();
+                        int paramCount = StringUtils.countMatches(hiveQL, "?");
+
+                        if (paramCount > 0) {
+                            loc = setParameters(loc, stmt, paramCount, 
flowFile.getAttributes());
+                        }
+
+                        // Parse hiveQL and extract input/output tables
+                        try {
+                            tableNames.addAll(findTableNames(hiveQL));
+                        } catch (Exception e) {
+                            // If failed to parse the query, just log a 
warning message, but continue.
+                            getLogger().warn("Failed to parse hiveQL: {} due 
to {}", new Object[]{hiveQL, e}, e);
+                        }
+
+                        // Execute the statement
+                        stmt.execute();
+                        fc.proceed();
                     }
-
-                    // Parse hiveQL and extract input/output tables
-                    try {
-                        tableNames.addAll(findTableNames(hiveQL));
-                    } catch (Exception e) {
-                        // If failed to parse the query, just log a warning 
message, but continue.
-                        getLogger().warn("Failed to parse hiveQL: {} due to 
{}", new Object[]{hiveQL, e}, e);
-                    }
-
-                    // Execute the statement
-                    stmt.execute();
-                    fc.proceed();
                 }
             }
 

Reply via email to