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-2518: Sqoop2: Findbugs: Fix warning in repository-derby module
Date Mon, 24 Aug 2015 16:38:41 GMT
Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 d26c5031b -> c4b2ac61f


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

Branch: refs/heads/sqoop2
Commit: c4b2ac61f24d576d2ac1e8ac286883617ca17551
Parents: d26c503
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Mon Aug 24 09:38:03 2015 -0700
Committer: Jarek Jarcec Cecho <jarcec@apache.org>
Committed: Mon Aug 24 09:38:03 2015 -0700

----------------------------------------------------------------------
 .../derby/DerbyRepositoryHandler.java           | 158 +++++++------------
 .../repository/derby/DerbySchemaConstants.java  |  26 +--
 ...GenericJdbcConnectorConfigAndInputNames.java |  37 ++---
 .../derby/upgrade/UniqueJobRename.java          |  27 +---
 4 files changed, 95 insertions(+), 153 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/c4b2ac61/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java
b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java
index 2408558..0b68058 100644
--- a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java
+++ b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java
@@ -93,7 +93,6 @@ public class DerbyRepositoryHandler extends CommonRepositoryHandler {
   @Override
   public synchronized void initialize(JdbcRepositoryContext ctx) {
     repoContext = ctx;
-    repoContext.getDataSource();
     LOG.info("DerbyRepositoryHandler initialized.");
   }
 
@@ -119,8 +118,7 @@ public class DerbyRepositoryHandler extends CommonRepositoryHandler {
         LOG.debug("Attempting to shutdown embedded Derby using URL: "
             + shutDownUrl);
 
-        try {
-          DriverManager.getConnection(shutDownUrl);
+        try (Connection tempConnection = DriverManager.getConnection(shutDownUrl)) {
         } catch (SQLException ex) {
           // Shutdown for one db instance is expected to raise SQL STATE 45000
           if (ex.getErrorCode() != 45000) {
@@ -145,19 +143,14 @@ public class DerbyRepositoryHandler extends CommonRepositoryHandler
{
    * @return
    */
   public int detectRepositoryVersion(Connection conn) {
-    ResultSet rs = null;
-    PreparedStatement stmt = null;
-
     // First release went out without system table, so we have to detect
     // this version differently.
-    try {
-      rs = conn.getMetaData().getTables(null, null, null, null);
+    try (ResultSet rs = conn.getMetaData().getTables(null, null, null, null)) {
 
       Set<String> tableNames = new HashSet<String>();
       while(rs.next()) {
         tableNames.add(rs.getString("TABLE_NAME"));
       }
-      closeResultSets(rs);
 
       LOG.debug("Detecting existing version of repository");
       boolean foundAll = true;
@@ -175,30 +168,25 @@ public class DerbyRepositoryHandler extends CommonRepositoryHandler
{
 
     } catch (SQLException e) {
       throw new SqoopException(DerbyRepoError.DERBYREPO_0006, e);
-    } finally {
-      closeResultSets(rs);
     }
 
     // Normal version detection, select and return the version
-    try {
+    try (PreparedStatement stmt = conn.prepareStatement(STMT_SELECT_DEPRECATED_OR_NEW_SYSTEM_VERSION))
{
       // NOTE: Since we can different types of version stored in system table, we renamed
the
       // key name for the repository version from "version" to "repository.version" for clarity
-      stmt = conn.prepareStatement(STMT_SELECT_DEPRECATED_OR_NEW_SYSTEM_VERSION);
       stmt.setString(1, CommonRepoConstants.SYSKEY_VERSION);
       stmt.setString(2, DerbyRepoConstants.SYSKEY_VERSION);
-      rs = stmt.executeQuery();
+      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);
     }
   }
 
@@ -337,12 +325,10 @@ public class DerbyRepositoryHandler extends CommonRepositoryHandler
{
    */
   private void migrateFromUnnamedConstraintsToNamedConstraints(Connection conn) {
     // Get unnamed constraints
-    PreparedStatement fetchUnnamedConstraintsStmt = null;
-    Statement dropUnnamedConstraintsStmt = null;
     Map<String, List<String>> autoConstraintNameMap = new TreeMap<String,
List<String>>();
 
-    try {
-      fetchUnnamedConstraintsStmt = conn.prepareStatement(STMT_FETCH_TABLE_FOREIGN_KEYS);
+    try (PreparedStatement fetchUnnamedConstraintsStmt = conn.prepareStatement(STMT_FETCH_TABLE_FOREIGN_KEYS))
{
+
       for (String tableName : new String[] {
           DerbySchemaConstants.TABLE_SQ_FORM_NAME,
           CommonRepositorySchemaConstants.TABLE_SQ_INPUT_NAME,
@@ -363,34 +349,30 @@ public class DerbyRepositoryHandler extends CommonRepositoryHandler
{
 
         if (fetchUnnamedConstraintsStmt.execute()) {
           LOG.info("QUERY(" + STMT_FETCH_TABLE_FOREIGN_KEYS + ") with args: [" + tableName
+ "]");
-          ResultSet rs = fetchUnnamedConstraintsStmt.getResultSet();
+          try (ResultSet rs = fetchUnnamedConstraintsStmt.getResultSet()) {
 
-          while (rs.next()) {
-            autoConstraintNames.add(rs.getString(1));
+            while (rs.next()) {
+              autoConstraintNames.add(rs.getString(1));
+            }
           }
-
-          rs.close();
         }
       }
     } catch (SQLException e) {
       throw new SqoopException(DerbyRepoError.DERBYREPO_0000, e);
-    } finally {
-      closeStatements(fetchUnnamedConstraintsStmt);
     }
 
     // Drop constraints
-    for (String tableName : autoConstraintNameMap.keySet()) {
-      for (String constraintName : autoConstraintNameMap.get(tableName)) {
+    for (Map.Entry<String, List<String>> entry : autoConstraintNameMap.entrySet())
{
+      for (String constraintName : entry.getValue()) {
         String query = DerbySchemaUpgradeQuery.getDropConstraintQuery(
-            SCHEMA_SQOOP, tableName, constraintName);
-        try {
-          dropUnnamedConstraintsStmt = conn.createStatement();
+            SCHEMA_SQOOP, entry.getKey(), constraintName);
+        try (Statement dropUnnamedConstraintsStmt = conn.createStatement()) {
+
           dropUnnamedConstraintsStmt.execute(query);
         } catch (SQLException e) {
           throw new SqoopException(DerbyRepoError.DERBYREPO_0000, e);
         } finally {
           LOG.info("QUERY(" + query + ")");
-          closeStatements(dropUnnamedConstraintsStmt);
         }
       }
     }
@@ -547,14 +529,12 @@ public class DerbyRepositoryHandler extends CommonRepositoryHandler
{
    */
   protected void updateDirections(Connection conn, Map<Direction, Long> directionMap)
{
     // Remember directions
-    Statement fetchFormsStmt = null,
-              fetchConnectorsStmt = null;
     List<Long> connectorIds = new LinkedList<Long>();
     List<Long> configIds = new LinkedList<Long>();
     List<String> directions = new LinkedList<String>();
-    try {
-      fetchFormsStmt = conn.createStatement();
-      ResultSet rs = fetchFormsStmt.executeQuery(STMT_FETCH_CONFIG_DIRECTIONS);
+    try (Statement fetchFormsStmt = conn.createStatement();
+         ResultSet rs = fetchFormsStmt.executeQuery(STMT_FETCH_CONFIG_DIRECTIONS);) {
+
       while (rs.next()) {
         configIds.add(rs.getLong(1));
         directions.add(rs.getString(2));
@@ -562,8 +542,6 @@ public class DerbyRepositoryHandler extends CommonRepositoryHandler {
       rs.close();
     } catch (SQLException e) {
       throw new SqoopException(DerbyRepoError.DERBYREPO_0000, e);
-    } finally {
-      closeStatements(fetchFormsStmt);
     }
 
     // Change Schema
@@ -582,17 +560,14 @@ public class DerbyRepositoryHandler extends CommonRepositoryHandler
{
     }
 
     // Add connector directions
-    try {
-      fetchConnectorsStmt = conn.createStatement();
-      ResultSet rs = fetchConnectorsStmt.executeQuery(STMT_SELECT_CONNECTOR_ALL);
+    try (Statement fetchConnectorsStmt = conn.createStatement();
+         ResultSet rs = fetchConnectorsStmt.executeQuery(STMT_SELECT_CONNECTOR_ALL);) {
       while (rs.next()) {
         connectorIds.add(rs.getLong(1));
       }
       rs.close();
     } catch (SQLException e) {
       throw new SqoopException(DerbyRepoError.DERBYREPO_0000, e);
-    } finally {
-      closeStatements(fetchConnectorsStmt);
     }
 
     for (Long connectorId : connectorIds) {
@@ -652,7 +627,7 @@ public class DerbyRepositoryHandler extends CommonRepositoryHandler {
         "output");
 
     runQuery(QUERY_UPGRADE_TABLE_SQ_FORM_UPDATE_CONNECTOR, conn,
-        new Long(hdfsConnectorId), "input", "output");
+        Long.valueOf(hdfsConnectorId), "input", "output");
     //update the names of the configs
     // 1. input ==> fromJobConfig
     runQuery(QUERY_UPGRADE_TABLE_SQ_FORM_UPDATE_CONNECTOR_HDFS_FORM_NAME, conn,
@@ -677,15 +652,15 @@ public class DerbyRepositoryHandler extends CommonRepositoryHandler
{
     runQuery(QUERY_UPGRADE_TABLE_SQ_FORM_UPDATE_DIRECTION_TO_NULL, conn,
         "throttling");
     runQuery(QUERY_UPGRADE_TABLE_SQ_FORM_UPDATE_DRIVER_INDEX, conn,
-        new Long(0), "throttling");
+        Long.valueOf(0), "throttling");
 
     Long connectionId = createHdfsConnection(conn, hdfsConnectorId);
     runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_UPDATE_SQB_TO_CONNECTION_COPY_SQB_FROM_CONNECTION,
conn,
         "EXPORT");
     runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_UPDATE_SQB_FROM_CONNECTION, conn,
-        new Long(connectionId), "EXPORT");
+            connectionId, "EXPORT");
     runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_UPDATE_SQB_TO_CONNECTION, conn,
-        new Long(connectionId), "IMPORT");
+            connectionId, "IMPORT");
 
     runQuery(QUERY_UPGRADE_TABLE_SQ_FORM_UPDATE_TABLE_FROM_JOB_INPUT_NAMES, conn,
         "fromJobConfig", "fromJobConfig", Direction.FROM.toString());
@@ -735,10 +710,8 @@ public class DerbyRepositoryHandler extends CommonRepositoryHandler {
       LOG.trace("Begin Driver loading.");
     }
 
-    PreparedStatement baseDriverStmt = null;
-    try {
-      baseDriverStmt = conn.prepareStatement(crudQueries.getStmtInsertIntoConfigurable(),
-          Statement.RETURN_GENERATED_KEYS);
+    try (PreparedStatement baseDriverStmt = conn.prepareStatement(crudQueries.getStmtInsertIntoConfigurable(),
+          Statement.RETURN_GENERATED_KEYS);) {
       baseDriverStmt.setString(1, MDriver.DRIVER_NAME);
       baseDriverStmt.setString(2, Driver.getClassName());
       baseDriverStmt.setString(3, "1");
@@ -749,16 +722,15 @@ public class DerbyRepositoryHandler extends CommonRepositoryHandler
{
         throw new SqoopException(DerbyRepoError.DERBYREPO_0003, Integer.toString(baseDriverCount));
       }
 
-      ResultSet rsetDriverId = baseDriverStmt.getGeneratedKeys();
+      try (ResultSet rsetDriverId = baseDriverStmt.getGeneratedKeys()) {
 
-      if (!rsetDriverId.next()) {
-        throw new SqoopException(DerbyRepoError.DERBYREPO_0004);
+        if (!rsetDriverId.next()) {
+          throw new SqoopException(DerbyRepoError.DERBYREPO_0004);
+        }
+        return rsetDriverId.getLong(1);
       }
-      return rsetDriverId.getLong(1);
     } catch (SQLException ex) {
       throw new SqoopException(DerbyRepoError.DERBYREPO_0009, ex);
-    } finally {
-      closeStatements(baseDriverStmt);
     }
   }
 
@@ -785,12 +757,11 @@ public class DerbyRepositoryHandler extends CommonRepositoryHandler
{
       if (handler.getConnectorConfigurable().getPersistenceId() != -1) {
         return handler.getConnectorConfigurable().getPersistenceId();
       }
-      PreparedStatement baseConnectorStmt = null;
       if (handler.getUniqueName().equals(CONNECTOR_HDFS)) {
-        try {
-          baseConnectorStmt = conn.prepareStatement(
-              STMT_INSERT_INTO_CONNECTOR_WITHOUT_SUPPORTED_DIRECTIONS,
-              Statement.RETURN_GENERATED_KEYS);
+        try (PreparedStatement baseConnectorStmt = conn.prepareStatement(
+                STMT_INSERT_INTO_CONNECTOR_WITHOUT_SUPPORTED_DIRECTIONS,
+                Statement.RETURN_GENERATED_KEYS)) {
+
           baseConnectorStmt.setString(1, handler.getConnectorConfigurable().getUniqueName());
           baseConnectorStmt.setString(2, handler.getConnectorConfigurable().getClassName());
           baseConnectorStmt.setString(3, "0");
@@ -805,8 +776,6 @@ public class DerbyRepositoryHandler extends CommonRepositoryHandler {
           }
         } catch (SQLException e) {
           throw new SqoopException(DerbyRepoError.DERBYREPO_0004);
-        } finally {
-          closeStatements(baseConnectorStmt);
         }
 
         break;
@@ -829,11 +798,9 @@ public class DerbyRepositoryHandler extends CommonRepositoryHandler {
       LOG.trace("Creating HDFS link.");
     }
 
-    PreparedStatement stmt = null;
     int result;
-    try {
-      stmt = conn.prepareStatement(STMT_INSERT_CONNECTION,
-          Statement.RETURN_GENERATED_KEYS);
+    try (PreparedStatement stmt = conn.prepareStatement(STMT_INSERT_CONNECTION,
+            Statement.RETURN_GENERATED_KEYS)) {
       stmt.setString(1, CONNECTOR_HDFS);
       stmt.setLong(2, connectorId);
       stmt.setBoolean(3, true);
@@ -847,21 +814,20 @@ public class DerbyRepositoryHandler extends CommonRepositoryHandler
{
         throw new SqoopException(DerbyRepoError.DERBYREPO_0003,
             Integer.toString(result));
       }
-      ResultSet rsetConnectionId = stmt.getGeneratedKeys();
+      try (ResultSet rsetConnectionId = stmt.getGeneratedKeys()) {
 
-      if (!rsetConnectionId.next()) {
-        throw new SqoopException(DerbyRepoError.DERBYREPO_0004);
-      }
+        if (!rsetConnectionId.next()) {
+          throw new SqoopException(DerbyRepoError.DERBYREPO_0004);
+        }
 
-      if (LOG.isTraceEnabled()) {
-        LOG.trace("Created HDFS connection.");
-      }
+        if (LOG.isTraceEnabled()) {
+          LOG.trace("Created HDFS connection.");
+        }
 
-      return rsetConnectionId.getLong(1);
+        return rsetConnectionId.getLong(1);
+      }
     } catch (SQLException ex) {
       throw new SqoopException(DerbyRepoError.DERBYREPO_0005, ex);
-    } finally {
-      closeStatements(stmt);
     }
   }
 
@@ -876,11 +842,10 @@ public class DerbyRepositoryHandler extends CommonRepositoryHandler
{
       LOG.trace("Creating HDFS link.");
     }
 
-    PreparedStatement stmt = null;
     int result;
-    try {
+    try (PreparedStatement stmt = conn.prepareStatement(STMT_INSERT_INTO_FORM, Statement.RETURN_GENERATED_KEYS))
{
       short index = 0;
-      stmt = conn.prepareStatement(STMT_INSERT_INTO_FORM, Statement.RETURN_GENERATED_KEYS);
+
       stmt.setLong(1, connectorId);
       stmt.setString(2, "linkConfig");
       // it could also be set to the deprecated "CONNECTION"
@@ -890,20 +855,19 @@ public class DerbyRepositoryHandler extends CommonRepositoryHandler
{
       if (result != 1) {
         throw new SqoopException(DerbyRepoError.DERBYREPO_0003, Integer.toString(result));
       }
-      ResultSet rsetFormId = stmt.getGeneratedKeys();
+      try (ResultSet rsetFormId = stmt.getGeneratedKeys()) {
 
-      if (!rsetFormId.next()) {
-        throw new SqoopException(DerbyRepoError.DERBYREPO_0004);
-      }
+        if (!rsetFormId.next()) {
+          throw new SqoopException(DerbyRepoError.DERBYREPO_0004);
+        }
 
-      if (LOG.isTraceEnabled()) {
-        LOG.trace("Created HDFS connector link FORM.");
+        if (LOG.isTraceEnabled()) {
+          LOG.trace("Created HDFS connector link FORM.");
+        }
+        return rsetFormId.getLong(1);
       }
-      return rsetFormId.getLong(1);
     } catch (SQLException ex) {
       throw new SqoopException(DerbyRepoError.DERBYREPO_0005, ex);
-    } finally {
-      closeStatements(stmt);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/c4b2ac61/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaConstants.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaConstants.java
b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaConstants.java
index 7678d35..522d82a 100644
--- a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaConstants.java
+++ b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaConstants.java
@@ -19,6 +19,7 @@ package org.apache.sqoop.repository.derby;
 
 import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.*;
 
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -182,18 +183,19 @@ public final class DerbySchemaConstants {
    */
   public static final Set<String> tablesV1;
   static {
-    tablesV1 = new HashSet<String>();
-    tablesV1.add(TABLE_SQ_CONNECTOR_NAME);
-    tablesV1.add(TABLE_SQ_CONNECTION_NAME);
-    tablesV1.add(TABLE_SQ_CONNECTION_INPUT_NAME);
-    tablesV1.add(TABLE_SQ_COUNTER_NAME);
-    tablesV1.add(TABLE_SQ_COUNTER_GROUP_NAME);
-    tablesV1.add(TABLE_SQ_COUNTER_SUBMISSION_NAME);
-    tablesV1.add(TABLE_SQ_FORM_NAME);
-    tablesV1.add(TABLE_SQ_INPUT_NAME);
-    tablesV1.add(TABLE_SQ_JOB_NAME);
-    tablesV1.add(TABLE_SQ_JOB_INPUT_NAME);
-    tablesV1.add(TABLE_SQ_SUBMISSION_NAME);
+    Set<String> tempTablesV1 = new HashSet<String>();
+    tempTablesV1.add(TABLE_SQ_CONNECTOR_NAME);
+    tempTablesV1.add(TABLE_SQ_CONNECTION_NAME);
+    tempTablesV1.add(TABLE_SQ_CONNECTION_INPUT_NAME);
+    tempTablesV1.add(TABLE_SQ_COUNTER_NAME);
+    tempTablesV1.add(TABLE_SQ_COUNTER_GROUP_NAME);
+    tempTablesV1.add(TABLE_SQ_COUNTER_SUBMISSION_NAME);
+    tempTablesV1.add(TABLE_SQ_FORM_NAME);
+    tempTablesV1.add(TABLE_SQ_INPUT_NAME);
+    tempTablesV1.add(TABLE_SQ_JOB_NAME);
+    tempTablesV1.add(TABLE_SQ_JOB_INPUT_NAME);
+    tempTablesV1.add(TABLE_SQ_SUBMISSION_NAME);
+    tablesV1 = Collections.unmodifiableSet(tempTablesV1);
   }
 
   private DerbySchemaConstants() {

http://git-wip-us.apache.org/repos/asf/sqoop/blob/c4b2ac61/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyUpgradeGenericJdbcConnectorConfigAndInputNames.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyUpgradeGenericJdbcConnectorConfigAndInputNames.java
b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyUpgradeGenericJdbcConnectorConfigAndInputNames.java
index eb8a905..738e593 100644
--- a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyUpgradeGenericJdbcConnectorConfigAndInputNames.java
+++ b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyUpgradeGenericJdbcConnectorConfigAndInputNames.java
@@ -123,39 +123,32 @@ public class DerbyUpgradeGenericJdbcConnectorConfigAndInputNames {
   }
 
   private Long getConfigId(boolean direction, String ... args) {
-    PreparedStatement statement = null;
     String configIdQuery = (direction) ?
         DerbySchemaUpgradeQuery.QUERY_SELECT_CONFIG_ID_BY_NAME_AND_DIRECTION : DerbySchemaUpgradeQuery.QUERY_SELECT_CONFIG_ID_BY_NAME;
 
-    try {
-      statement = connection.prepareStatement(configIdQuery);
-
+    try (PreparedStatement statement = connection.prepareStatement(configIdQuery);) {
       for (int i = 0; i < args.length; ++i) {
         statement.setString(i + 1, args[i]);
       }
 
-      ResultSet configIdResultSet = statement.executeQuery();
+      try (ResultSet configIdResultSet = statement.executeQuery()) {
+        LOG.debug("QUERY(" + configIdQuery + ") with args [" + StringUtils.join(args, ",")
+ "] fetch size: " + configIdResultSet.getFetchSize());
 
-      LOG.debug("QUERY(" + configIdQuery + ") with args [" + StringUtils.join(args, ",")
+ "] fetch size: " + configIdResultSet.getFetchSize());
+        if (!configIdResultSet.next() || configIdResultSet.getFetchSize() != 1) {
+          return null;
+        }
 
-      if (!configIdResultSet.next() || configIdResultSet.getFetchSize() != 1) {
-        return null;
+        return configIdResultSet.getLong(1);
       }
-
-      return configIdResultSet.getLong(1);
     } catch (SQLException e) {
       throw new SqoopException(DerbyRepoError.DERBYREPO_0002, e);
-    } finally {
-      handler.closeStatements(statement);
     }
   }
 
   private void renameConfig(long configId, String configName) {
-    PreparedStatement statement = null;
     String query = DerbySchemaUpgradeQuery.QUERY_UPDATE_TABLE_SQ_CONFIG_NAME;
 
-    try {
-      statement = connection.prepareStatement(query);
+    try (PreparedStatement statement = connection.prepareStatement(query)) {
       statement.setString(1, configName);
       statement.setLong(2, configId);
 
@@ -163,19 +156,15 @@ public class DerbyUpgradeGenericJdbcConnectorConfigAndInputNames {
       LOG.debug("QUERY(" + query + ") with args [" + configName + ", " + configId + "] update
count: " + updateCount);
     } catch (SQLException e) {
       throw new SqoopException(DerbyRepoError.DERBYREPO_0002, e);
-    } finally {
-      handler.closeStatements(statement);
     }
   }
 
   private void renameConfigInputs(long configId, Map<String, String> inputNameMap)
{
-    PreparedStatement statement = null;
-
-    try {
-      statement = connection.prepareStatement(DerbySchemaUpgradeQuery.QUERY_UPDATE_TABLE_SQ_INPUT_SQI_NAME);
 
-      for (String inputName : inputNameMap.keySet()) {
-        statement.setString(1, inputNameMap.get(inputName));
+    try (PreparedStatement statement = connection.prepareStatement(DerbySchemaUpgradeQuery.QUERY_UPDATE_TABLE_SQ_INPUT_SQI_NAME))
{
+      for (Map.Entry<String, String> entry : inputNameMap.entrySet()) {
+        String inputName = entry.getKey();
+        statement.setString(1, entry.getValue());
         statement.setString(2, inputName);
         statement.setLong(3, configId);
         statement.addBatch();
@@ -189,8 +178,6 @@ public class DerbyUpgradeGenericJdbcConnectorConfigAndInputNames {
           + StringUtils.join(ArrayUtils.toObject(updateCounts), ","));
     } catch (SQLException e) {
       throw new SqoopException(DerbyRepoError.DERBYREPO_0002, e);
-    } finally {
-      handler.closeStatements(statement);
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/c4b2ac61/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/upgrade/UniqueJobRename.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/upgrade/UniqueJobRename.java
b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/upgrade/UniqueJobRename.java
index 2322553..19e5376 100644
--- a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/upgrade/UniqueJobRename.java
+++ b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/upgrade/UniqueJobRename.java
@@ -66,31 +66,23 @@ public class UniqueJobRename {
   public void execute() {
     Map<Long, String> idToNewNameMap = new TreeMap<Long, String>();
 
-    Statement fetchJobStmt = null;
-    PreparedStatement updateJobStmt = null;
-    ResultSet fetchJobResultSet = null;
-
     // Fetch all non-unique job IDs and Names.
     // Transform names.
-    try {
-      fetchJobStmt = conn.createStatement();
-      fetchJobResultSet = fetchJobStmt.executeQuery(QUERY_SELECT_JOBS_WITH_NON_UNIQUE_NAMES);
+    try (Statement fetchJobStmt = conn.createStatement();
+         ResultSet fetchJobResultSet = fetchJobStmt.executeQuery(QUERY_SELECT_JOBS_WITH_NON_UNIQUE_NAMES))
{
+
       while (fetchJobResultSet.next()) {
         idToNewNameMap.put(fetchJobResultSet.getLong(1), getNewName(fetchJobResultSet.getString(2)));
       }
     } catch (SQLException e) {
       throw new SqoopException(DerbyRepoError.DERBYREPO_0000, e);
-    } finally {
-      CommonRepoUtils.closeResultSets(fetchJobResultSet);
-      CommonRepoUtils.closeStatements(fetchJobStmt);
     }
 
+    try (PreparedStatement updateJobStmt = conn.prepareStatement(QUERY_UPDATE_JOB_NAME_BY_ID))
{
 
-    try {
-      updateJobStmt = conn.prepareStatement(QUERY_UPDATE_JOB_NAME_BY_ID);
-      for (Long jobId : idToNewNameMap.keySet()) {
-        updateJobStmt.setString(1, idToNewNameMap.get(jobId));
-        updateJobStmt.setLong(2, jobId);
+      for (Map.Entry<Long, String> entry : idToNewNameMap.entrySet()) {
+        updateJobStmt.setString(1, entry.getValue());
+        updateJobStmt.setLong(2, entry.getKey());
         updateJobStmt.addBatch();
       }
 
@@ -99,14 +91,11 @@ public class UniqueJobRename {
         if (count != 1) {
           throw new SqoopException(DerbyRepoError.DERBYREPO_0000,
               "Update count wrong when changing names for non-unique jobs. Update coutns
are: "
-                  + StringUtils.join(Arrays.asList(counts), ","));
+                  + Arrays.toString(counts));
         }
       }
     } catch (SQLException e) {
       throw new SqoopException(DerbyRepoError.DERBYREPO_0000, e);
-    } finally {
-      CommonRepoUtils.closeResultSets(fetchJobResultSet);
-      CommonRepoUtils.closeStatements(fetchJobStmt);
     }
   }
 


Mime
View raw message