aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-01-30 17:39:03 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2012-01-30 17:39:13 +0100
commit0ed45530370c950a14069a97194c7d5a0b57220d (patch)
tree266f4f4640d49a64fc29b6b5c9af2cbc8e8c5e2b /sonar-core
parentaece758f85682f49dfc02ef5cae2729c680dcc57 (diff)
downloadsonarqube-0ed45530370c950a14069a97194c7d5a0b57220d.tar.gz
sonarqube-0ed45530370c950a14069a97194c7d5a0b57220d.zip
Do not delete snapshots with events
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/purge/PurgeableSnapshotDto.java10
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml20
-rw-r--r--sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java10
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldSelectPurgeableSnapshots.xml11
6 files changed, 28 insertions, 31 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java
index 32561f1c583..de93c7b503b 100644
--- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java
@@ -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 {
diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java
index 350c115bb7e..4aa251a7437 100644
--- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java
@@ -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);
}
diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeableSnapshotDto.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeableSnapshotDto.java
index 20d4ab1f829..a9aceeacbdf 100644
--- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeableSnapshotDto.java
+++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeableSnapshotDto.java
@@ -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;
}
diff --git a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml
index 002a448873a..28745b85272 100644
--- a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml
@@ -48,18 +48,18 @@
</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">
diff --git a/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java b/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java
index af30c7bbf70..5d4e07a847a 100644
--- a/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java
@@ -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);
}
}
}
diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldSelectPurgeableSnapshots.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldSelectPurgeableSnapshots.xml
index a9024ccfbdb..9628af3f9bc 100644
--- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldSelectPurgeableSnapshots.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldSelectPurgeableSnapshots.xml
@@ -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]"
@@ -44,10 +44,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]"/>
- <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]"