@VisibleForTesting
static boolean isDeletable(PurgeableSnapshotDto snapshot) {
- return !snapshot.isLast() && !snapshot.hasVersionEvent();
+ return !snapshot.isLast() && !snapshot.hasReadOnlyEvents();
}
}
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
));
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));
}
}
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 {
void closeResourceReviews(long resourceId);
- List<PurgeableSnapshotDto> selectPurgeableSnapshotsWithVersionEvent(long resourceId);
+ List<PurgeableSnapshotDto> selectPurgeableSnapshotsWithReadOnlyEvents(long resourceId);
- List<PurgeableSnapshotDto> selectPurgeableSnapshotsWithoutVersionEvent(long resourceId);
+ List<PurgeableSnapshotDto> selectPurgeableSnapshotsWithoutReadOnlyEvents(long resourceId);
}
public class PurgeableSnapshotDto implements Comparable<PurgeableSnapshotDto> {
private Date date;
private long snapshotId;
- private boolean hasVersionEvent;
+ private boolean hasReadOnlyEvents;
private boolean isLast;
public Date getDate() {
return snapshotId;
}
- public boolean hasVersionEvent() {
- return hasVersionEvent;
+ public boolean hasReadOnlyEvents() {
+ return hasReadOnlyEvents;
}
public boolean isLast() {
return this;
}
- public PurgeableSnapshotDto setHasVersionEvent(boolean hasVersionEvent) {
- this.hasVersionEvent = hasVersionEvent;
+ public PurgeableSnapshotDto setHasReadOnlyEvents(boolean b) {
+ this.hasReadOnlyEvents = b;
return this;
}
</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 <> '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 <> '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">
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);
}
}
}