]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2757 do not delete events on profile changes
authorSimon Brandhof <simon.brandhof@gmail.com>
Fri, 27 Jan 2012 09:40:00 +0000 (10:40 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Fri, 27 Jan 2012 09:40:00 +0000 (10:40 +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

index 7775c9bece96dbecbdab55963c335c1ae6f94a85..2ca34f0aeaaf6236d619046a88b21cd374df5397 100644 (file)
@@ -82,7 +82,7 @@ class KeepOneFilter extends Filter {
 
   @VisibleForTesting
   static boolean isDeletable(PurgeableSnapshotDto snapshot) {
-    return !snapshot.isLast() && !snapshot.hasVersionEvent();
+    return !snapshot.isLast() && !snapshot.hasReadOnlyEvents();
   }
 
 }
index 9e775a7fc61faa851a630c073bcb4138daeb1fa0..2229a39c0e8ce42f68a57a46a7554b60f40ebd74 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").setHasVersionEvent(true).setLast(false),
+      createSnapshotWithDate(3L, "2011-05-19").setHasReadOnlyEvents(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").setHasVersionEvent(true)), is(false));
+    assertThat(KeepOneFilter.isDeletable(createSnapshotWithDate(1L, "2011-05-01").setHasReadOnlyEvents(true)), is(false));
   }
 }
index e751cc32f2018bb8ed03166c6731df2c23afa4c1..32561f1c583ef24e0a93a13c3f42439463798309 100644 (file)
@@ -89,8 +89,8 @@ public class PurgeDao {
     try {
       PurgeMapper mapper = session.getMapper(PurgeMapper.class);
       List<PurgeableSnapshotDto> result = Lists.newArrayList();
-      result.addAll(mapper.selectPurgeableSnapshotsWithVersionEvent(resourceId));
-      result.addAll(mapper.selectPurgeableSnapshotsWithoutVersionEvent(resourceId));
+      result.addAll(mapper.selectPurgeableSnapshotsWithReadOnlyEvents(resourceId));
+      result.addAll(mapper.selectPurgeableSnapshotsWithoutReadOnlyEvents(resourceId));
       Collections.sort(result);// sort by date
       return result;
     } finally {
index d663cd44c536c824c9c2e760379f1bdab5b90d06..350c115bb7e48493af26560abb823db519f3e5c1 100644 (file)
@@ -73,7 +73,7 @@ public interface PurgeMapper {
 
   void closeResourceReviews(long resourceId);
 
-  List<PurgeableSnapshotDto> selectPurgeableSnapshotsWithVersionEvent(long resourceId);
+  List<PurgeableSnapshotDto> selectPurgeableSnapshotsWithReadOnlyEvents(long resourceId);
 
-  List<PurgeableSnapshotDto> selectPurgeableSnapshotsWithoutVersionEvent(long resourceId);
+  List<PurgeableSnapshotDto> selectPurgeableSnapshotsWithoutReadOnlyEvents(long resourceId);
 }
index 5579bfa7c06127b1e073c9779d7fed203e50fd37..20d4ab1f8296321cf41201c52c8df38a65976b9d 100644 (file)
@@ -27,7 +27,7 @@ import java.util.Date;
 public class PurgeableSnapshotDto implements Comparable<PurgeableSnapshotDto> {
   private Date date;
   private long snapshotId;
-  private boolean hasVersionEvent;
+  private boolean hasReadOnlyEvents;
   private boolean isLast;
 
   public Date getDate() {
@@ -38,8 +38,8 @@ public class PurgeableSnapshotDto implements Comparable<PurgeableSnapshotDto> {
     return snapshotId;
   }
 
-  public boolean hasVersionEvent() {
-    return hasVersionEvent;
+  public boolean hasReadOnlyEvents() {
+    return hasReadOnlyEvents;
   }
 
   public boolean isLast() {
@@ -55,8 +55,8 @@ public class PurgeableSnapshotDto implements Comparable<PurgeableSnapshotDto> {
     return this;
   }
 
-  public PurgeableSnapshotDto setHasVersionEvent(boolean hasVersionEvent) {
-    this.hasVersionEvent = hasVersionEvent;
+  public PurgeableSnapshotDto setHasReadOnlyEvents(boolean b) {
+    this.hasReadOnlyEvents = b;
     return this;
   }
 
index 34c85d4f7e21b758e2c54cf4ea523feda1c53b49..002a448873aa4008adfdd13d2062eb9410bfa75b 100644 (file)
     </where>
   </select>
 
-  <select id="selectPurgeableSnapshotsWithVersionEvent" parameterType="long" resultType="PurgeableSnapshot">
-    select s.id as "snapshotId", s.created_at as "date", ${_true} as "hasVersionEvent", islast as "isLast" from
+  <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='Version')
+    e.snapshot_id=s.id and e.category in ('Version', 'Profile'))
   </select>
 
-  <select id="selectPurgeableSnapshotsWithoutVersionEvent" parameterType="long" resultType="PurgeableSnapshot">
-    select s.id as "snapshotId", s.created_at as "date", ${_false} as "hasVersionEvent", islast as "isLast" from
+  <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='Version')
+    where e.snapshot_id=s.id and e.category in ('Version', 'Profile'))
   </select>
 
   <select id="selectResourceIdsToDisable" resultType="long" parameterType="long">
index c1a3541aeb0f2875c523c678b064e653e3f5806b..af30c7bbf70e80bf4fcd2532df1264ba5e1a5294 100644 (file)
@@ -180,24 +180,24 @@ public class PurgeDaoTest extends DaoTestCase {
   static final class SnapshotMatcher extends BaseMatcher<PurgeableSnapshotDto> {
     long snapshotId;
     boolean isLast;
-    boolean hasVersionEvent;
+    boolean hasReadOnlyEvents;
 
-    SnapshotMatcher(long snapshotId, boolean last, boolean hasVersionEvent) {
+    SnapshotMatcher(long snapshotId, boolean last, boolean hasReadOnlyEvents) {
       this.snapshotId = snapshotId;
       this.isLast = last;
-      this.hasVersionEvent = hasVersionEvent;
+      this.hasReadOnlyEvents = hasReadOnlyEvents;
     }
 
     public boolean matches(Object o) {
       PurgeableSnapshotDto obj = (PurgeableSnapshotDto) o;
-      return obj.getSnapshotId() == snapshotId && obj.isLast() == isLast && obj.hasVersionEvent() == hasVersionEvent;
+      return obj.getSnapshotId() == snapshotId && obj.isLast() == isLast && obj.hasReadOnlyEvents() == hasReadOnlyEvents;
     }
 
     public void describeTo(Description description) {
       description
         .appendText("snapshotId").appendValue(snapshotId)
         .appendText("isLast").appendValue(isLast)
-        .appendText("hasVersionEvent").appendValue(hasVersionEvent);
+        .appendText("hasReadOnlyEvents").appendValue(hasReadOnlyEvents);
     }
   }
 }