diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-12-29 16:20:13 +0400 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-12-29 16:20:13 +0400 |
commit | a8910c851e616843d9489895755955bf06ea51fd (patch) | |
tree | 2c602061966ae6bb081fcdc161c073f503d1a3e1 /plugins/sonar-dbcleaner-plugin/src/main | |
parent | 217728d515945fa61565a297b5a09a761bff9e47 (diff) | |
download | sonarqube-a8910c851e616843d9489895755955bf06ea51fd.tar.gz sonarqube-a8910c851e616843d9489895755955bf06ea51fd.zip |
Fix PurgeUtils
createQuery() and createNativeQuery() should be invoked as many times as
commit(), because it starts new transaction
Diffstat (limited to 'plugins/sonar-dbcleaner-plugin/src/main')
-rw-r--r-- | plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeUtils.java | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeUtils.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeUtils.java index 390f4f0736f..37747560318 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeUtils.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeUtils.java @@ -26,6 +26,8 @@ import org.sonar.api.database.model.*; import org.sonar.api.design.DependencyDto; import org.sonar.api.utils.TimeProfiler; +import com.google.common.annotations.VisibleForTesting; + import javax.persistence.Query; import java.util.List; @@ -141,27 +143,32 @@ public final class PurgeUtils { if (ids == null || ids.isEmpty()) { return; } - executeQuery(session, description, ids, session.createQuery(hql)); + TimeProfiler profiler = new TimeProfiler().setLevelToDebug().start("Execute " + description); + int index = 0; + while (index < ids.size()) { + List<Integer> paginedSids = ids.subList(index, Math.min(ids.size(), index + MAX_IN_ELEMENTS)); + Query query = session.createQuery(hql); + query.setParameter("ids", paginedSids); + query.executeUpdate(); + index += MAX_IN_ELEMENTS; + session.commit(); + } + profiler.stop(); } /** * @since 2.13 */ - private static void executeNativeQuery(DatabaseSession session, String description, List<Integer> ids, String sql) { + @VisibleForTesting + static void executeNativeQuery(DatabaseSession session, String description, List<Integer> ids, String sql) { if (ids == null || ids.isEmpty()) { return; } - executeQuery(session, description, ids, session.createNativeQuery(sql)); - } - - /** - * @since 2.13 - */ - private static void executeQuery(DatabaseSession session, String description, List<Integer> ids, Query query) { TimeProfiler profiler = new TimeProfiler().setLevelToDebug().start("Execute " + description); int index = 0; while (index < ids.size()) { List<Integer> paginedSids = ids.subList(index, Math.min(ids.size(), index + MAX_IN_ELEMENTS)); + Query query = session.createNativeQuery(sql); query.setParameter("ids", paginedSids); query.executeUpdate(); index += MAX_IN_ELEMENTS; |