summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-06-18 08:21:22 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-06-18 08:21:22 +0200
commite53dcbdec744318ebf20918b35c6b27b072903a2 (patch)
tree6ed3107985f2b6e7847f1c68e432cfccf92b61a2
parent1dea058da99fa2c8e33c5ace9778536d9dac39c7 (diff)
downloadsonarqube-e53dcbdec744318ebf20918b35c6b27b072903a2.tar.gz
sonarqube-e53dcbdec744318ebf20918b35c6b27b072903a2.zip
Fix quality flaws
-rw-r--r--sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java43
1 files changed, 22 insertions, 21 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java b/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java
index a43f2a04a6e..494c5e7a4fa 100644
--- a/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java
+++ b/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java
@@ -31,11 +31,7 @@ import org.sonar.core.persistence.dialect.MySql;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
+import java.sql.*;
/**
* Update a table by iterating a sub-set of rows. For each row a SQL UPDATE request
@@ -100,12 +96,7 @@ public class MassUpdater {
readConnection = db.getDataSource().getConnection();
readConnection.setAutoCommit(false);
- stmt = readConnection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
- if (db.getDialect().getId().equals(MySql.ID)) {
- stmt.setFetchSize(Integer.MIN_VALUE);
- } else {
- stmt.setFetchSize(groupSize);
- }
+ stmt = initStatement(readConnection);
rs = stmt.executeQuery(convertSelectSql(inputLoader.selectSql(), db));
int cursor = 0;
@@ -122,20 +113,12 @@ public class MassUpdater {
}
if (cursor == groupSize) {
- writeStatement.executeBatch();
- if (periodicUpdater != null) {
- periodicUpdater.update(writeConnection);
- }
- writeConnection.commit();
+ commit(writeConnection, writeStatement, periodicUpdater);
cursor = 0;
}
}
if (cursor > 0) {
- writeStatement.executeBatch();
- if (periodicUpdater != null) {
- periodicUpdater.update(writeConnection);
- }
- writeConnection.commit();
+ commit(writeConnection, writeStatement, periodicUpdater);
}
} catch (SQLException e) {
@@ -152,6 +135,24 @@ public class MassUpdater {
}
}
+ private Statement initStatement(Connection readConnection) throws SQLException {
+ Statement stmt = readConnection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
+ if (db.getDialect().getId().equals(MySql.ID)) {
+ stmt.setFetchSize(Integer.MIN_VALUE);
+ } else {
+ stmt.setFetchSize(groupSize);
+ }
+ return stmt;
+ }
+
+ private void commit(Connection writeConnection, PreparedStatement writeStatement, @Nullable PeriodicUpdater periodicUpdater) throws SQLException {
+ writeStatement.executeBatch();
+ if (periodicUpdater != null) {
+ periodicUpdater.update(writeConnection);
+ }
+ writeConnection.commit();
+ }
+
private static MessageException processError(Exception e) {
String message = String.format("Fail to migrate data, error is : %s", e.getMessage());
LOGGER.error(message, e);