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-2519: Sqoop2: Findbugs: Fix warning in repository-postgresql module
Date Sat, 22 Aug 2015 00:41:24 GMT
Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 cd8621a20 -> 7aca9f4f6


SQOOP-2519: Sqoop2: Findbugs: Fix warning in repository-postgresql 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/7aca9f4f
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/7aca9f4f
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/7aca9f4f

Branch: refs/heads/sqoop2
Commit: 7aca9f4f6c81f421f1c74109d43bdac5d0f871b4
Parents: cd8621a
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Fri Aug 21 17:40:47 2015 -0700
Committer: Jarek Jarcec Cecho <jarcec@apache.org>
Committed: Fri Aug 21 17:40:47 2015 -0700

----------------------------------------------------------------------
 .../postgresql/PostgresqlRepositoryHandler.java | 52 ++++++++------------
 1 file changed, 20 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/7aca9f4f/repository/repository-postgresql/src/main/java/org/apache/sqoop/repository/postgresql/PostgresqlRepositoryHandler.java
----------------------------------------------------------------------
diff --git a/repository/repository-postgresql/src/main/java/org/apache/sqoop/repository/postgresql/PostgresqlRepositoryHandler.java
b/repository/repository-postgresql/src/main/java/org/apache/sqoop/repository/postgresql/PostgresqlRepositoryHandler.java
index 81bc000..0d0ea8c 100644
--- a/repository/repository-postgresql/src/main/java/org/apache/sqoop/repository/postgresql/PostgresqlRepositoryHandler.java
+++ b/repository/repository-postgresql/src/main/java/org/apache/sqoop/repository/postgresql/PostgresqlRepositoryHandler.java
@@ -55,7 +55,6 @@ public class PostgresqlRepositoryHandler extends CommonRepositoryHandler
{
   @Override
   public synchronized void initialize(JdbcRepositoryContext ctx) {
     repoContext = ctx;
-    repoContext.getDataSource();
     LOG.info("PostgresqlRepositoryHandler initialized.");
   }
 
@@ -72,33 +71,30 @@ public class PostgresqlRepositoryHandler extends CommonRepositoryHandler
{
    * @return
    */
   public int detectRepositoryVersion(Connection conn) {
-    ResultSet rs = null, metadataResultSet = null;
-    PreparedStatement stmt = null;
-
     // Select and return the version
     try {
       DatabaseMetaData md = conn.getMetaData();
-      metadataResultSet = md.getTables(null,
+      try (ResultSet metadataResultSet = md.getTables(null,
           CommonRepositorySchemaConstants.SCHEMA_SQOOP,
-          CommonRepositorySchemaConstants.TABLE_SQ_SYSTEM_NAME, null);
+          CommonRepositorySchemaConstants.TABLE_SQ_SYSTEM_NAME, null)){
 
-      if (metadataResultSet.next()) {
-        stmt = conn.prepareStatement(PostgresqlSchemaQuery.STMT_SELECT_SYSTEM);
-        stmt.setString(1, CommonRepoConstants.SYSKEY_VERSION);
-        rs = stmt.executeQuery();
+        if (metadataResultSet.next()) {
+          try (PreparedStatement stmt = conn.prepareStatement(PostgresqlSchemaQuery.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;
@@ -144,24 +140,16 @@ public class PostgresqlRepositoryHandler extends CommonRepositoryHandler
{
       runQuery(PostgresqlSchemaCreateQuery.QUERY_CREATE_TABLE_SQ_CONTEXT, conn);
     }
 
-    ResultSet rs = null;
-    PreparedStatement stmt = null;
-    try {
-      stmt = conn.prepareStatement(PostgresqlSchemaQuery.STMT_DELETE_SYSTEM);
-      stmt.setString(1, CommonRepoConstants.SYSKEY_VERSION);
-      stmt.executeUpdate();
-
-      closeStatements(stmt);
+    try (PreparedStatement stmtDel = conn.prepareStatement(PostgresqlSchemaQuery.STMT_DELETE_SYSTEM);
+         PreparedStatement stmtInsert = conn.prepareStatement(PostgresqlSchemaQuery.STMT_INSERT_SYSTEM);)
{
+      stmtDel.setString(1, CommonRepoConstants.SYSKEY_VERSION);
+      stmtDel.executeUpdate();
 
-      stmt = conn.prepareStatement(PostgresqlSchemaQuery.STMT_INSERT_SYSTEM);
-      stmt.setString(1, CommonRepoConstants.SYSKEY_VERSION);
-      stmt.setString(2, Integer.toString(PostgresqlRepoConstants.LATEST_POSTGRESQL_REPOSITORY_VERSION));
-      stmt.executeUpdate();
+      stmtInsert.setString(1, CommonRepoConstants.SYSKEY_VERSION);
+      stmtInsert.setString(2, Integer.toString(PostgresqlRepoConstants.LATEST_POSTGRESQL_REPOSITORY_VERSION));
+      stmtInsert.executeUpdate();
     } catch (SQLException e) {
       LOG.error("Can't persist the repository version", e);
-    } finally {
-      closeResultSets(rs);
-      closeStatements(stmt);
     }
   }
 


Mime
View raw message