diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-03-05 16:04:44 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-03-05 16:04:44 +0100 |
commit | 5209fac8c90c46ba4dd6d9ce73eae7f2dc428a9b (patch) | |
tree | b12cea78009c77471fea3c873afa92ad093ce167 /plugins/sonar-dbcleaner-plugin | |
parent | 15efef19303c240d12ec345e774987ba8a075d8d (diff) | |
download | sonarqube-5209fac8c90c46ba4dd6d9ce73eae7f2dc428a9b.tar.gz sonarqube-5209fac8c90c46ba4dd6d9ce73eae7f2dc428a9b.zip |
Improve batch execution of DELETE statements in PurgeDao
Diffstat (limited to 'plugins/sonar-dbcleaner-plugin')
3 files changed, 18 insertions, 3 deletions
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DefaultPurgeTask.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DefaultPurgeTask.java index cdb55dd86ad..10f75cc1ef7 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DefaultPurgeTask.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DefaultPurgeTask.java @@ -58,7 +58,6 @@ public class DefaultPurgeTask implements PurgeTask { } public PurgeTask purge(long resourceId) { - LOG.info("Clean historical data [id=" + resourceId + "]"); cleanHistoricalData(resourceId); doPurge(resourceId); return this; diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleaner.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleaner.java index 9b9bc9e1dc6..e81e3cd30ea 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleaner.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleaner.java @@ -64,6 +64,7 @@ public class DefaultPeriodCleaner implements PeriodCleaner { for (PurgeableSnapshotDto snapshot : snapshots) { LOG.info("<- Delete snapshot: " + DateUtils.formatDateTime(snapshot.getDate()) + " [" + snapshot.getSnapshotId() + "]"); purgeDao.deleteSnapshots(PurgeSnapshotQuery.create().setRootSnapshotId(snapshot.getSnapshotId())); + purgeDao.deleteSnapshots(PurgeSnapshotQuery.create().setId(snapshot.getSnapshotId())); } } diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleanerTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleanerTest.java index 0d4ba72ebd9..c9f27bc979e 100644 --- a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleanerTest.java +++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleanerTest.java @@ -19,6 +19,7 @@ */ package org.sonar.plugins.dbcleaner.period; +import org.apache.commons.lang.ObjectUtils; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.junit.Test; @@ -42,7 +43,7 @@ public class DefaultPeriodCleanerTest { public void doClean() { PurgeDao dao = mock(PurgeDao.class); when(dao.selectPurgeableSnapshots(123L)).thenReturn(Arrays.asList( - new PurgeableSnapshotDto().setSnapshotId(999L).setDate(new Date()))); + new PurgeableSnapshotDto().setSnapshotId(999L).setDate(new Date()))); Filter filter1 = newLazyFilter(); Filter filter2 = newLazyFilter(); @@ -52,12 +53,26 @@ public class DefaultPeriodCleanerTest { verify(filter1).log(); verify(filter2).log(); verify(dao, times(2)).deleteSnapshots(argThat(newRootSnapshotQuery())); + verify(dao, times(2)).deleteSnapshots(argThat(newSnapshotIdQuery())); } private BaseMatcher<PurgeSnapshotQuery> newRootSnapshotQuery() { return new BaseMatcher<PurgeSnapshotQuery>() { public boolean matches(Object o) { - return ((PurgeSnapshotQuery) o).getRootSnapshotId() == 999L; + PurgeSnapshotQuery query = (PurgeSnapshotQuery) o; + return ObjectUtils.equals(query.getRootSnapshotId(), 999L); + } + + public void describeTo(Description description) { + } + }; + } + + private BaseMatcher<PurgeSnapshotQuery> newSnapshotIdQuery() { + return new BaseMatcher<PurgeSnapshotQuery>() { + public boolean matches(Object o) { + PurgeSnapshotQuery query = (PurgeSnapshotQuery) o; + return ObjectUtils.equals(query.getId(), 999L); } public void describeTo(Description description) { |