import org.sonar.core.resource.ResourceDao;
import org.sonar.core.resource.ResourceDto;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
/**
* @since 2.14
}
private void disableOrphanResources(final ResourceDto project, final SqlSession session, final PurgeMapper purgeMapper, final PurgeListener purgeListener) {
+ final List<IdUuidPair> componentIdUuids = new ArrayList<IdUuidPair>();
session.select("org.sonar.core.purge.PurgeMapper.selectResourceIdsToDisable", project.getId(), new ResultHandler() {
@Override
public void handleResult(ResultContext resultContext) {
- IdUuidPair resourceIdUuid = (IdUuidPair) resultContext.getResultObject();
- if (resourceIdUuid.getId() != null) {
- disableResource(resourceIdUuid, purgeMapper);
- purgeListener.onComponentDisabling(resourceIdUuid.getUuid());
+ IdUuidPair componentIdUuid = (IdUuidPair) resultContext.getResultObject();
+ if (componentIdUuid.getId() != null) {
+ componentIdUuids.add(componentIdUuid);
}
}
});
+
+ for (IdUuidPair componentIdUuid : componentIdUuids) {
+ disableResource(componentIdUuid, purgeMapper);
+ purgeListener.onComponentDisabling(componentIdUuid.getUuid());
+ }
+
session.commit();
}
sut = new PurgeDao(getMyBatis(), new ResourceDao(getMyBatis(), system2), new PurgeProfiler(), system2);
}
+
@After
public void after() {
MyBatis.closeQuietly(dbSession);
public void disable_resources_without_last_snapshot() {
setupData("disable_resources_without_last_snapshot");
sut.purge(new PurgeConfiguration(1L, new String[0], 30, system2), PurgeListener.EMPTY);
- checkTables("disable_resources_without_last_snapshot", new String[]{"issue_close_date", "issue_update_date"}, "projects", "snapshots", "issues");
+ checkTables("disable_resources_without_last_snapshot", new String[] {"issue_close_date", "issue_update_date"}, "projects", "snapshots", "issues");
}
@Test