]> source.dussan.org Git - sonarqube.git/commitdiff
Remove useless double try/catch
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 17 Mar 2014 10:13:58 +0000 (11:13 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 17 Mar 2014 10:14:06 +0000 (11:14 +0100)
sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java

index d349ce6417f92cd7b80409f3c9e2de817f30cc6b..31f9e0224d08e5266400b792dffe4d655f130324 100644 (file)
@@ -61,50 +61,47 @@ public class MassUpdater {
 
   public <S> void execute(InputLoader<S> inputLoader, InputConverter<S> converter) {
     long count = 0;
+    Connection readConnection = null;
+    Statement stmt = null;
+    ResultSet rs = null;
+    Connection writeConnection = null;
+    PreparedStatement writeStatement = null;
     try {
-      Connection readConnection = db.getDataSource().getConnection();
-      Statement stmt = null;
-      ResultSet rs = null;
-      Connection writeConnection = db.getDataSource().getConnection();
-      PreparedStatement writeStatement = null;
-      try {
-        readConnection.setAutoCommit(false);
-        writeConnection.setAutoCommit(false);
-        writeStatement = writeConnection.prepareStatement(converter.updateSql());
-        stmt = readConnection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
+      writeConnection = db.getDataSource().getConnection();
+      writeConnection.setAutoCommit(false);
+      writeStatement = writeConnection.prepareStatement(converter.updateSql());
+
+      readConnection = db.getDataSource().getConnection();
+      readConnection.setAutoCommit(false);
+
+      stmt = readConnection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
+      stmt.setFetchSize(GROUP_SIZE);
+      if (db.getDialect().getId().equals(MySql.ID)) {
+        stmt.setFetchSize(Integer.MIN_VALUE);
+      } else {
         stmt.setFetchSize(GROUP_SIZE);
-        if (db.getDialect().getId().equals(MySql.ID)) {
-          stmt.setFetchSize(Integer.MIN_VALUE);
-        } else {
-          stmt.setFetchSize(GROUP_SIZE);
-        }
-        rs = stmt.executeQuery(inputLoader.selectSql());
-
-        int cursor = 0;
-        while (rs.next()) {
-          if (converter.convert(inputLoader.load(rs), writeStatement)) {
-            writeStatement.addBatch();
-            cursor++;
-            count++;
-          }
-
-          if (cursor == GROUP_SIZE) {
-            writeStatement.executeBatch();
-            writeConnection.commit();
-            cursor = 0;
-          }
+      }
+      rs = stmt.executeQuery(inputLoader.selectSql());
+
+      int cursor = 0;
+      while (rs.next()) {
+        if (converter.convert(inputLoader.load(rs), writeStatement)) {
+          writeStatement.addBatch();
+          cursor++;
+          count++;
         }
-        if (cursor > 0) {
+
+        if (cursor == GROUP_SIZE) {
           writeStatement.executeBatch();
           writeConnection.commit();
+          cursor = 0;
         }
-      } finally {
-        DbUtils.closeQuietly(writeStatement);
-        DbUtils.closeQuietly(writeConnection);
-        DbUtils.closeQuietly(readConnection, stmt, rs);
-
-        LOGGER.info("{} rows have been updated", count);
       }
+      if (cursor > 0) {
+        writeStatement.executeBatch();
+        writeConnection.commit();
+      }
+
     } catch (SQLException e) {
       LOGGER.error(FAILURE_MESSAGE, e);
       SqlUtil.log(LOGGER, e);
@@ -113,6 +110,13 @@ public class MassUpdater {
     } catch (Exception e) {
       LOGGER.error(FAILURE_MESSAGE, e);
       throw MessageException.of(FAILURE_MESSAGE);
+
+    } finally {
+      DbUtils.closeQuietly(writeStatement);
+      DbUtils.closeQuietly(writeConnection);
+      DbUtils.closeQuietly(readConnection, stmt, rs);
+
+      LOGGER.info("{} rows have been updated", count);
     }
   }