]> source.dussan.org Git - sonarqube.git/commitdiff
Do not delete snapshots with events
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 30 Jan 2012 16:39:03 +0000 (17:39 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 30 Jan 2012 16:39:13 +0000 (17:39 +0100)
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/KeepOneFilter.java
plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/KeepOneFilterTest.java
sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java
sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java
sonar-core/src/main/java/org/sonar/core/purge/PurgeableSnapshotDto.java
sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml
sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java
sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldSelectPurgeableSnapshots.xml

index 2ca34f0aeaaf6236d619046a88b21cd374df5397..c667bd1be5933ccdbec43ed5860dc38110977a00 100644 (file)
@@ -82,7 +82,7 @@ class KeepOneFilter extends Filter {
 
   @VisibleForTesting
   static boolean isDeletable(PurgeableSnapshotDto snapshot) {
-    return !snapshot.isLast() && !snapshot.hasReadOnlyEvents();
+    return !snapshot.isLast() && !snapshot.hasEvents();
   }
 
 }
index 2229a39c0e8ce42f68a57a46a7554b60f40ebd74..b2f7d4831316539924430ab02cdeadb7f73199f1 100644 (file)
@@ -60,7 +60,7 @@ public class KeepOneFilterTest {
     List<PurgeableSnapshotDto> toDelete = filter.filter(Arrays.<PurgeableSnapshotDto>asList(
       createSnapshotWithDate(1L, "2011-05-01"), // to be deleted
       createSnapshotWithDate(2L, "2011-05-02").setLast(true),
-      createSnapshotWithDate(3L, "2011-05-19").setHasReadOnlyEvents(true).setLast(false),
+      createSnapshotWithDate(3L, "2011-05-19").setHasEvents(true).setLast(false),
       createSnapshotWithDate(4L, "2011-05-23") // to be deleted
     ));
 
@@ -73,6 +73,6 @@ public class KeepOneFilterTest {
   public void test_isDeletable() {
     assertThat(KeepOneFilter.isDeletable(createSnapshotWithDate(1L, "2011-05-01")), is(true));
     assertThat(KeepOneFilter.isDeletable(createSnapshotWithDate(1L, "2011-05-01").setLast(true)), is(false));
-    assertThat(KeepOneFilter.isDeletable(createSnapshotWithDate(1L, "2011-05-01").setHasReadOnlyEvents(true)), is(false));
+    assertThat(KeepOneFilter.isDeletable(createSnapshotWithDate(1L, "2011-05-01").setHasEvents(true)), is(false));
   }
 }
index 32561f1c583ef24e0a93a13c3f42439463798309..de93c7b503bad9c4df3a2eaad8c829065e9a42cd 100644 (file)
@@ -89,8 +89,8 @@ public class PurgeDao {
     try {
       PurgeMapper mapper = session.getMapper(PurgeMapper.class);
       List<PurgeableSnapshotDto> result = Lists.newArrayList();
-      result.addAll(mapper.selectPurgeableSnapshotsWithReadOnlyEvents(resourceId));
-      result.addAll(mapper.selectPurgeableSnapshotsWithoutReadOnlyEvents(resourceId));
+      result.addAll(mapper.selectPurgeableSnapshotsWithEvents(resourceId));
+      result.addAll(mapper.selectPurgeableSnapshotsWithoutEvents(resourceId));
       Collections.sort(result);// sort by date
       return result;
     } finally {
index 350c115bb7e48493af26560abb823db519f3e5c1..4aa251a7437ae420d241ab35f5b555205623f9a2 100644 (file)
@@ -73,7 +73,7 @@ public interface PurgeMapper {
 
   void closeResourceReviews(long resourceId);
 
-  List<PurgeableSnapshotDto> selectPurgeableSnapshotsWithReadOnlyEvents(long resourceId);
+  List<PurgeableSnapshotDto> selectPurgeableSnapshotsWithEvents(long resourceId);
 
-  List<PurgeableSnapshotDto> selectPurgeableSnapshotsWithoutReadOnlyEvents(long resourceId);
+  List<PurgeableSnapshotDto> selectPurgeableSnapshotsWithoutEvents(long resourceId);
 }
index 20d4ab1f8296321cf41201c52c8df38a65976b9d..a9aceeacbdf4d9a3137883906b13686248c923a5 100644 (file)
@@ -27,7 +27,7 @@ import java.util.Date;
 public class PurgeableSnapshotDto implements Comparable<PurgeableSnapshotDto> {
   private Date date;
   private long snapshotId;
-  private boolean hasReadOnlyEvents;
+  private boolean hasEvents;
   private boolean isLast;
 
   public Date getDate() {
@@ -38,8 +38,8 @@ public class PurgeableSnapshotDto implements Comparable<PurgeableSnapshotDto> {
     return snapshotId;
   }
 
-  public boolean hasReadOnlyEvents() {
-    return hasReadOnlyEvents;
+  public boolean hasEvents() {
+    return hasEvents;
   }
 
   public boolean isLast() {
@@ -55,8 +55,8 @@ public class PurgeableSnapshotDto implements Comparable<PurgeableSnapshotDto> {
     return this;
   }
 
-  public PurgeableSnapshotDto setHasReadOnlyEvents(boolean b) {
-    this.hasReadOnlyEvents = b;
+  public PurgeableSnapshotDto setHasEvents(boolean b) {
+    this.hasEvents = b;
     return this;
   }
 
index 002a448873aa4008adfdd13d2062eb9410bfa75b..28745b8527277e44e3adac116f39d033d8f8c84f 100644 (file)
     </where>
   </select>
 
-  <select id="selectPurgeableSnapshotsWithReadOnlyEvents" parameterType="long" resultType="PurgeableSnapshot">
-    select s.id as "snapshotId", s.created_at as "date", ${_true} as "hasReadOnlyEvents", islast as "isLast" from
-    snapshots s
-    where s.project_id=#{id} and s.status='P' and s.qualifier &lt;&gt; 'LIB' and exists(select e.id from events e where
-    e.snapshot_id=s.id and e.category in ('Version', 'Profile'))
+  <select id="selectPurgeableSnapshotsWithEvents" parameterType="long" resultType="PurgeableSnapshot">
+    select s.id as "snapshotId", s.created_at as "date", ${_true} as "hasEvents", islast as "isLast" from
+    snapshots s where
+    s.project_id=#{id} and s.status='P' and s.qualifier &lt;&gt; 'LIB' and
+    exists(select e.id from events e where e.snapshot_id=s.id)
   </select>
 
-  <select id="selectPurgeableSnapshotsWithoutReadOnlyEvents" parameterType="long" resultType="PurgeableSnapshot">
-    select s.id as "snapshotId", s.created_at as "date", ${_false} as "hasReadOnlyEvents", islast as "isLast" from
-    snapshots s
-    where s.project_id=#{id} and s.status='P' and s.qualifier &lt;&gt; 'LIB' and not exists(select e.id from events e
-    where e.snapshot_id=s.id and e.category in ('Version', 'Profile'))
+  <select id="selectPurgeableSnapshotsWithoutEvents" parameterType="long" resultType="PurgeableSnapshot">
+    select s.id as "snapshotId", s.created_at as "date", ${_false} as "hasEvents", islast as "isLast" from
+    snapshots s where
+    s.project_id=#{id} and s.status='P' and s.qualifier &lt;&gt; 'LIB' and
+    not exists(select e.id from events e where e.snapshot_id=s.id)
   </select>
 
   <select id="selectResourceIdsToDisable" resultType="long" parameterType="long">
index af30c7bbf70e80bf4fcd2532df1264ba5e1a5294..5d4e07a847afb44dfbe77693e354ce463b46e180 100644 (file)
@@ -180,24 +180,24 @@ public class PurgeDaoTest extends DaoTestCase {
   static final class SnapshotMatcher extends BaseMatcher<PurgeableSnapshotDto> {
     long snapshotId;
     boolean isLast;
-    boolean hasReadOnlyEvents;
+    boolean hasEvents;
 
-    SnapshotMatcher(long snapshotId, boolean last, boolean hasReadOnlyEvents) {
+    SnapshotMatcher(long snapshotId, boolean last, boolean hasEvents) {
       this.snapshotId = snapshotId;
       this.isLast = last;
-      this.hasReadOnlyEvents = hasReadOnlyEvents;
+      this.hasEvents = hasEvents;
     }
 
     public boolean matches(Object o) {
       PurgeableSnapshotDto obj = (PurgeableSnapshotDto) o;
-      return obj.getSnapshotId() == snapshotId && obj.isLast() == isLast && obj.hasReadOnlyEvents() == hasReadOnlyEvents;
+      return obj.getSnapshotId() == snapshotId && obj.isLast() == isLast && obj.hasEvents() == hasEvents;
     }
 
     public void describeTo(Description description) {
       description
         .appendText("snapshotId").appendValue(snapshotId)
         .appendText("isLast").appendValue(isLast)
-        .appendText("hasReadOnlyEvents").appendValue(hasReadOnlyEvents);
+        .appendText("hasEvents").appendValue(hasEvents);
     }
   }
 }
index a9024ccfbdb5469640f31ddf05d9378e67a70424..9628af3f9bc80b207aa24a493049c7846926e585 100644 (file)
@@ -1,6 +1,6 @@
 <dataset>
 
-  <!-- last -> keep -->
+  <!-- last -> select -->
   <snapshots id="1"
              project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
              status="P" islast="true" purge_status="[null]"
@@ -22,7 +22,7 @@
              period5_mode="[null]" period5_param="[null]" period5_date="[null]"
              depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/>
 
-  <!-- on other resource -->
+  <!-- on other resource -> exclude -->
   <snapshots id="3"
              project_id="222" parent_snapshot_id="[null]" root_project_id="222" root_snapshot_id="[null]"
              status="P" islast="true" purge_status="[null]"
@@ -33,7 +33,7 @@
              period5_mode="[null]" period5_param="[null]" period5_date="[null]"
              depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/>
 
-  <!-- without version -> keep -->
+  <!-- without event -> select -->
   <snapshots id="4"
              project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
              status="P" islast="false" purge_status="[null]"
              period5_mode="[null]" period5_param="[null]" period5_date="[null]"
              depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/>
 
-  <events id="1" resource_id="1" snapshot_id="4"
-            category="Quality profile change" description="[null]" name="xxx" event_date="2008-12-02 13:58:00.00" created_at="[null]"/>
-
-  <!-- with version -> keep -->
+  <!-- with event -> select -->
   <snapshots id="5"
              project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
              status="P" islast="false" purge_status="[null]"