sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jar...@apache.org
Subject sqoop git commit: SQOOP-2521: Sqoop2: Findbugs: Fix warning in repository-mysql module
Date Mon, 24 Aug 2015 17:45:26 GMT
Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 b7ddddbe1 -> 709dd3671


SQOOP-2521: Sqoop2: Findbugs: Fix warning in repository-mysql module

(Colin Ma via Jarek Jarcec Cecho)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/709dd367
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/709dd367
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/709dd367

Branch: refs/heads/sqoop2
Commit: 709dd3671bc19239bf7b4ada62f247e4cc2769a6
Parents: b7ddddb
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Mon Aug 24 10:45:06 2015 -0700
Committer: Jarek Jarcec Cecho <jarcec@apache.org>
Committed: Mon Aug 24 10:45:06 2015 -0700

----------------------------------------------------------------------
 .../mysql/MySqlRepositoryHandler.java           | 31 ++++++++------------
 1 file changed, 12 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/709dd367/repository/repository-mysql/src/main/java/org/apache/sqoop/repository/mysql/MySqlRepositoryHandler.java
----------------------------------------------------------------------
diff --git a/repository/repository-mysql/src/main/java/org/apache/sqoop/repository/mysql/MySqlRepositoryHandler.java
b/repository/repository-mysql/src/main/java/org/apache/sqoop/repository/mysql/MySqlRepositoryHandler.java
index 61b058a..4917ffe 100644
--- a/repository/repository-mysql/src/main/java/org/apache/sqoop/repository/mysql/MySqlRepositoryHandler.java
+++ b/repository/repository-mysql/src/main/java/org/apache/sqoop/repository/mysql/MySqlRepositoryHandler.java
@@ -82,8 +82,7 @@ public class MySqlRepositoryHandler extends CommonRepositoryHandler {
    * @return
    */
   public int detectRepositoryVersion(Connection conn) {
-    ResultSet rs = null, metadataResultSet = null;
-    PreparedStatement stmt = null;
+    ResultSet metadataResultSet = null;
 
     // Select and return the version
     try {
@@ -93,22 +92,21 @@ public class MySqlRepositoryHandler extends CommonRepositoryHandler {
           CommonRepositorySchemaConstants.TABLE_SQ_SYSTEM_NAME, null);
 
       if (metadataResultSet.next()) {
-        stmt = conn.prepareStatement(MySqlSchemaQuery.STMT_SELECT_SYSTEM);
-        stmt.setString(1, CommonRepoConstants.SYSKEY_VERSION);
-        rs = stmt.executeQuery();
+        try (PreparedStatement stmt = conn.prepareStatement(MySqlSchemaQuery.STMT_SELECT_SYSTEM)){
+          stmt.setString(1, CommonRepoConstants.SYSKEY_VERSION);
+          try (ResultSet rs = stmt.executeQuery()){
 
-        if (!rs.next()) {
-          return 0;
-        }
+            if (!rs.next()) {
+              return 0;
+            }
 
-        return rs.getInt(1);
+            return rs.getInt(1);
+          }
+        }
       }
     } catch (SQLException e) {
       LOG.info("Can't fetch repository structure version.", e);
       return 0;
-    } finally {
-      closeResultSets(rs);
-      closeStatements(stmt);
     }
 
     return 0;
@@ -154,10 +152,8 @@ public class MySqlRepositoryHandler extends CommonRepositoryHandler {
     }
 
     ResultSet rs = null;
-    PreparedStatement stmt = null;
-    try {
-      stmt = conn
-          .prepareStatement(MySqlSchemaQuery.STMT_INSERT_ON_DUPLICATE_KEY_SYSTEM);
+    try (PreparedStatement stmt = conn
+            .prepareStatement(MySqlSchemaQuery.STMT_INSERT_ON_DUPLICATE_KEY_SYSTEM);) {
       stmt.setString(1, CommonRepoConstants.SYSKEY_VERSION);
       stmt.setString(2,
           Integer.toString(MySqlRepoConstants.LATEST_MYSQL_REPOSITORY_VERSION));
@@ -166,9 +162,6 @@ public class MySqlRepositoryHandler extends CommonRepositoryHandler {
       stmt.executeUpdate();
     } catch (SQLException e) {
       LOG.error("Can't persist the repository version", e);
-    } finally {
-      closeResultSets(rs);
-      closeStatements(stmt);
     }
   }
 


Mime
View raw message