@VisibleForTesting
static boolean isDeletable(PurgeableSnapshotDto snapshot) {
- return !snapshot.isLast() && !snapshot.hasReadOnlyEvents();
+ return !snapshot.isLast() && !snapshot.hasEvents();
}
}
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
));
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));
}
}
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 {
void closeResourceReviews(long resourceId);
- List<PurgeableSnapshotDto> selectPurgeableSnapshotsWithReadOnlyEvents(long resourceId);
+ List<PurgeableSnapshotDto> selectPurgeableSnapshotsWithEvents(long resourceId);
- List<PurgeableSnapshotDto> selectPurgeableSnapshotsWithoutReadOnlyEvents(long resourceId);
+ List<PurgeableSnapshotDto> selectPurgeableSnapshotsWithoutEvents(long resourceId);
}
public class PurgeableSnapshotDto implements Comparable<PurgeableSnapshotDto> {
private Date date;
private long snapshotId;
- private boolean hasReadOnlyEvents;
+ private boolean hasEvents;
private boolean isLast;
public Date getDate() {
return snapshotId;
}
- public boolean hasReadOnlyEvents() {
- return hasReadOnlyEvents;
+ public boolean hasEvents() {
+ return hasEvents;
}
public boolean isLast() {
return this;
}
- public PurgeableSnapshotDto setHasReadOnlyEvents(boolean b) {
- this.hasReadOnlyEvents = b;
+ public PurgeableSnapshotDto setHasEvents(boolean b) {
+ this.hasEvents = b;
return this;
}
</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 <> '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 <> '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 <> '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 <> 'LIB' and
+ not exists(select e.id from events e where e.snapshot_id=s.id)
</select>
<select id="selectResourceIdsToDisable" resultType="long" parameterType="long">
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);
}
}
}
<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]"
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]"
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]"