aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db/src
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-06-30 14:59:13 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-07-04 15:20:30 +0200
commit59735ceddd04e235ed58050e93f6a7f7ad919d54 (patch)
tree666501239397eb6f235f4bc2a3e51cf8852981c0 /sonar-db/src
parenta8377cdc47390e932da20c2f644206a7adba3070 (diff)
downloadsonarqube-59735ceddd04e235ed58050e93f6a7f7ad919d54.tar.gz
sonarqube-59735ceddd04e235ed58050e93f6a7f7ad919d54.zip
SONAR-7705 remove Orphan components directly from the root
Diffstat (limited to 'sonar-db/src')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java75
-rw-r--r--sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java71
-rw-r--r--sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java11
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml29
-rw-r--r--sonar-db/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java21
-rw-r--r--sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java7
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingAnalysis-result.xml (renamed from sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot-result.xml)0
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingAnalysis.xml (renamed from sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot.xml)0
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis-result.xml (renamed from sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeSnapshot-result.xml)0
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis.xml (renamed from sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeSnapshot.xml)0
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/delete_file_sources_of_disabled_resources-result.xml28
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/delete_file_sources_of_disabled_resources.xml54
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAnalyses-result.xml69
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAnalyses.xml101
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteSnapshots-result.xml29
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteSnapshots.xml41
16 files changed, 307 insertions, 229 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java
index 7e728f84ca0..03d53ea9d30 100644
--- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java
+++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java
@@ -21,8 +21,6 @@ package org.sonar.db.purge;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-import java.util.LinkedHashSet;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.ibatis.session.SqlSession;
@@ -72,79 +70,57 @@ class PurgeCommands {
// possible missing optimization: filter requests according to resource scope
profiler.start("deleteResourceLinks (project_links)");
- for (List<String> componentUuidPartition : componentUuidsPartitions) {
- purgeMapper.deleteComponentLinks(componentUuidPartition);
- }
+ componentUuidsPartitions.forEach(purgeMapper::deleteComponentLinks);
session.commit();
profiler.stop();
profiler.start("deleteResourceProperties (properties)");
- for (List<Long> partResourceIds : componentIdPartitions) {
- purgeMapper.deleteComponentProperties(partResourceIds);
- }
+ componentIdPartitions.forEach(purgeMapper::deleteComponentProperties);
session.commit();
profiler.stop();
profiler.start("deleteResourceIndex (resource_index)");
- for (List<String> componentUuidPartition : componentUuidsPartitions) {
- purgeMapper.deleteResourceIndex(componentUuidPartition);
- }
+ componentUuidsPartitions.forEach(purgeMapper::deleteResourceIndex);
session.commit();
profiler.stop();
profiler.start("deleteResourceGroupRoles (group_roles)");
- for (List<Long> partResourceIds : componentIdPartitions) {
- purgeMapper.deleteComponentGroupRoles(partResourceIds);
- }
+ componentIdPartitions.forEach(purgeMapper::deleteComponentGroupRoles);
session.commit();
profiler.stop();
profiler.start("deleteResourceUserRoles (user_roles)");
- for (List<Long> partResourceIds : componentIdPartitions) {
- purgeMapper.deleteComponentUserRoles(partResourceIds);
- }
+ componentIdPartitions.forEach(purgeMapper::deleteComponentUserRoles);
session.commit();
profiler.stop();
profiler.start("deleteResourceManualMeasures (manual_measures)");
- for (List<String> componentUuidPartition : componentUuidsPartitions) {
- purgeMapper.deleteComponentManualMeasures(componentUuidPartition);
- }
+ componentUuidsPartitions.forEach(purgeMapper::deleteComponentManualMeasures);
session.commit();
profiler.stop();
profiler.start("deleteComponentIssueChanges (issue_changes)");
- for (List<String> componentUuidPartition : componentUuidsPartitions) {
- purgeMapper.deleteComponentIssueChanges(componentUuidPartition);
- }
+ componentUuidsPartitions.forEach(purgeMapper::deleteComponentIssueChanges);
session.commit();
profiler.stop();
profiler.start("deleteComponentIssues (issues)");
- for (List<String> componentUuidPartition : componentUuidsPartitions) {
- purgeMapper.deleteComponentIssues(componentUuidPartition);
- }
+ componentUuidsPartitions.forEach(purgeMapper::deleteComponentIssues);
session.commit();
profiler.stop();
profiler.start("deleteComponentEvents (events)");
- for (List<String> componentUuidPartition : componentUuidsPartitions) {
- purgeMapper.deleteComponentEvents(componentUuidPartition);
- }
+ componentUuidsPartitions.forEach(purgeMapper::deleteComponentEvents);
session.commit();
profiler.stop();
profiler.start("deleteResource (projects)");
- for (List<String> componentUuidPartition : componentUuidsPartitions) {
- purgeMapper.deleteComponents(componentUuidPartition);
- }
+ componentUuidsPartitions.forEach(purgeMapper::deleteComponents);
session.commit();
profiler.stop();
profiler.start("deleteAuthors (authors)");
- for (List<Long> partResourceIds : componentIdPartitions) {
- purgeMapper.deleteAuthors(partResourceIds);
- }
+ componentIdPartitions.forEach(purgeMapper::deleteAuthors);
session.commit();
profiler.stop();
}
@@ -223,38 +199,12 @@ class PurgeCommands {
profiler.start("deleteAnalyses (snapshots)");
analysisUuidsPartitions.forEach(purgeMapper::deleteAnalyses);
+ // FIXME remove this when cardinality of snapshots has been changed
analysisIdsPartitions.forEach(purgeMapper::deleteDescendantSnapshots);
session.commit();
profiler.stop();
}
- void purgeSnapshots(PurgeSnapshotQuery... queries) {
- // use LinkedHashSet to keep order by remove duplicated ids
- LinkedHashSet<IdUuidPair> snapshotIds = Sets.newLinkedHashSet(from(asList(queries))
- .transformAndConcat(purgeMapper::selectSnapshotIdsAndUuids));
- purgeSnapshots(snapshotIds);
- }
-
- @VisibleForTesting
- protected void purgeSnapshots(Iterable<IdUuidPair> snapshotIdUuidPairs) {
- List<List<Long>> snapshotIdsPartitions = Lists.partition(IdUuidPairs.ids(snapshotIdUuidPairs), MAX_SNAPSHOTS_PER_QUERY);
- List<List<String>> snapshotUuidsPartitions = Lists.partition(IdUuidPairs.uuids(snapshotIdUuidPairs), MAX_SNAPSHOTS_PER_QUERY);
-
- deleteSnapshotDuplications(snapshotUuidsPartitions);
-
- profiler.start("deleteSnapshotWastedMeasures (project_measures)");
- List<Long> metricIdsWithoutHistoricalData = purgeMapper.selectMetricIdsWithoutHistoricalData();
- snapshotIdsPartitions.stream()
- .forEach(snapshotIdsPartition -> purgeMapper.deleteSnapshotWastedMeasures(snapshotIdsPartition, metricIdsWithoutHistoricalData));
- session.commit();
- profiler.stop();
-
- profiler.start("updatePurgeStatusToOne (snapshots)");
- snapshotUuidsPartitions.forEach(snapshotUuidsPartition -> purgeMapper.updatePurgeStatusToOne(snapshotUuidsPartition));
- session.commit();
- profiler.stop();
- }
-
public void purgeAnalyses(List<IdUuidPair> analysisUuids) {
List<List<Long>> analysisIdsPartitions = Lists.partition(IdUuidPairs.ids(analysisUuids), MAX_SNAPSHOTS_PER_QUERY);
List<List<String>> analysisUuidsPartitions = Lists.partition(IdUuidPairs.uuids(analysisUuids), MAX_SNAPSHOTS_PER_QUERY);
@@ -270,6 +220,7 @@ class PurgeCommands {
profiler.start("updatePurgeStatusToOne (snapshots)");
analysisUuidsPartitions.forEach(purgeMapper::updatePurgeStatusToOne);
+ // FIXME remove this when cardinality of snapshots has been changed
analysisIdsPartitions.forEach(purgeMapper::updateDescendantPurgeStatusToOne);
session.commit();
profiler.stop();
diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java
index b15c88048bd..a470b4d2dfd 100644
--- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java
@@ -26,7 +26,6 @@ import java.util.Collections;
import java.util.Date;
import java.util.List;
import org.apache.ibatis.session.SqlSession;
-import org.sonar.api.resources.Scopes;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
@@ -36,8 +35,6 @@ import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDao;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTreeQuery;
-import org.sonar.db.component.ResourceDao;
-import org.sonar.db.component.ResourceDto;
import static java.util.Collections.emptyList;
import static org.sonar.api.utils.DateUtils.dateToLong;
@@ -51,12 +48,10 @@ public class PurgeDao implements Dao {
private static final String[] UNPROCESSED_STATUS = new String[] {"U"};
private static final List<String> UUID_FIELD_SORT = Collections.singletonList("uuid");
- private final ResourceDao resourceDao;
private final ComponentDao componentDao;
private final System2 system2;
- public PurgeDao(ResourceDao resourceDao, ComponentDao componentDao, System2 system2) {
- this.resourceDao = resourceDao;
+ public PurgeDao(ComponentDao componentDao, System2 system2) {
this.componentDao = componentDao;
this.system2 = system2;
}
@@ -66,26 +61,25 @@ public class PurgeDao implements Dao {
PurgeCommands commands = new PurgeCommands(session, mapper, profiler);
String rootUuid = conf.rootProjectIdUuid().getUuid();
deleteAbortedAnalyses(rootUuid, commands);
- deleteDataOfComponentsWithoutHistoricalData(session, conf.rootProjectIdUuid().getUuid(), conf.scopesWithoutHistoricalData(), commands);
+ deleteDataOfComponentsWithoutHistoricalData(session, rootUuid, conf.scopesWithoutHistoricalData(), commands);
+ purgeAnalyses(commands, rootUuid);
+ disableOrphanResources(rootUuid, session, mapper, listener);
+ deleteOldClosedIssues(conf, mapper, listener);
+ }
+ private static void purgeAnalyses(PurgeCommands commands, String rootUuid) {
List<IdUuidPair> analysisUuids = commands.selectSnapshotIdUuids(
- PurgeSnapshotQuery.create()
- .setComponentUuid(rootUuid)
- .setIslast(false)
- .setNotPurged(true));
+ PurgeSnapshotQuery.create()
+ .setComponentUuid(rootUuid)
+ .setIslast(false)
+ .setNotPurged(true));
commands.purgeAnalyses(analysisUuids);
-
- // retrieve all nodes in the tree (including root) with scope=PROJECT
- List<ResourceDto> projects = getProjects(conf.rootProjectIdUuid().getId(), session);
- for (ResourceDto project : projects) {
- disableOrphanResources(project, session, mapper, listener);
- }
- deleteOldClosedIssues(conf, mapper, listener);
}
private static void deleteOldClosedIssues(PurgeConfiguration conf, PurgeMapper mapper, PurgeListener listener) {
Date toDate = conf.maxLiveDateOfClosedIssues();
- List<String> issueKeys = mapper.selectOldClosedIssueKeys(conf.rootProjectIdUuid().getUuid(), dateToLong(toDate));
+ String rootUuid = conf.rootProjectIdUuid().getUuid();
+ List<String> issueKeys = mapper.selectOldClosedIssueKeys(rootUuid, dateToLong(toDate));
executeLargeInputs(issueKeys, input -> {
mapper.deleteIssueChangesFromIssueKeys(input);
return emptyList();
@@ -94,7 +88,7 @@ public class PurgeDao implements Dao {
mapper.deleteIssuesFromKeys(input);
return emptyList();
});
- listener.onIssuesRemoval(conf.rootProjectIdUuid().getUuid(), issueKeys);
+ listener.onIssuesRemoval(rootUuid, issueKeys);
}
private static void deleteAbortedAnalyses(String rootUuid, PurgeCommands commands) {
@@ -145,9 +139,10 @@ public class PurgeDao implements Dao {
.setSortFields(UUID_FIELD_SORT);
}
- private void disableOrphanResources(ResourceDto project, SqlSession session, PurgeMapper purgeMapper, PurgeListener purgeListener) {
+ private void disableOrphanResources(String rootUuid, SqlSession session, PurgeMapper mapper, PurgeListener listener) {
List<String> componentUuids = new ArrayList<>();
- session.select("org.sonar.db.purge.PurgeMapper.selectComponentUuidsToDisable", project.getUuid(),
+ mapper.selectComponentUuidsToDisable(
+ rootUuid,
resultContext -> {
String componentUuid = (String) resultContext.getResultObject();
if (componentUuid != null) {
@@ -155,9 +150,9 @@ public class PurgeDao implements Dao {
}
});
+ disableComponents(componentUuids, mapper);
for (String componentUuid : componentUuids) {
- disableComponent(componentUuid, purgeMapper);
- purgeListener.onComponentDisabling(componentUuid);
+ listener.onComponentDisabling(componentUuid);
}
session.commit();
@@ -187,30 +182,22 @@ public class PurgeDao implements Dao {
commands.deleteCeActivity(rootUuid);
}
- private void disableComponent(String uuid, PurgeMapper mapper) {
- mapper.deleteResourceIndex(Collections.singletonList(uuid));
- mapper.setSnapshotIsLastToFalse(uuid);
- mapper.deleteFileSourcesByUuid(uuid);
- mapper.disableComponent(uuid);
- mapper.resolveComponentIssuesNotAlreadyResolved(uuid, system2.now());
- }
-
- public PurgeDao deleteSnapshots(DbSession session, PurgeProfiler profiler, PurgeSnapshotQuery... queries) {
- new PurgeCommands(session, profiler).deleteSnapshots(queries);
- return this;
+ private void disableComponents(List<String> uuids, PurgeMapper mapper) {
+ executeLargeInputs(uuids,
+ input -> {
+ mapper.deleteResourceIndex(input);
+ mapper.setSnapshotIsLastToFalse(input);
+ mapper.deleteFileSourcesByUuid(input);
+ mapper.disableComponent(input);
+ mapper.resolveComponentIssuesNotAlreadyResolved(input, system2.now());
+ return emptyList();
+ });
}
public void deleteAnalyses(DbSession session, PurgeProfiler profiler, List<IdUuidPair> analysisIdUuids) {
new PurgeCommands(session, profiler).deleteAnalyses(analysisIdUuids);
}
- /**
- * Load the whole tree of projects, including the project given in parameter.
- */
- private List<ResourceDto> getProjects(long rootId, SqlSession session) {
- return resourceDao.selectWholeTreeForRootId(session, rootId, Scopes.PROJECT);
- }
-
private static PurgeMapper mapper(DbSession session) {
return session.getMapper(PurgeMapper.class);
}
diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java
index 82215fdfa21..c58961f872e 100644
--- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java
+++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java
@@ -22,6 +22,7 @@ package org.sonar.db.purge;
import java.util.List;
import javax.annotation.Nullable;
import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.session.ResultHandler;
public interface PurgeMapper {
@@ -32,6 +33,8 @@ public interface PurgeMapper {
*/
List<IdUuidPair> selectComponentsByProjectUuid(String projectUuid);
+ void selectComponentUuidsToDisable(@Param("rootUuid") String rootUuid, ResultHandler resultHandler);
+
void deleteAnalyses(@Param("analysisUuids") List<String> analysisUuids);
void deleteDescendantSnapshots(@Param("snapshotIds") List<Long> snapshotIds);
@@ -58,13 +61,13 @@ public interface PurgeMapper {
void updateDescendantPurgeStatusToOne(@Param("analysisIds") List<Long> analysisIds);
- void disableComponent(String componentUuid);
+ void disableComponent(@Param("componentUuids") List<String> componentUuids);
- void resolveComponentIssuesNotAlreadyResolved(@Param("componentUuid") String componentUuid, @Param("dateAsLong") Long dateAsLong);
+ void resolveComponentIssuesNotAlreadyResolved(@Param("componentUuids") List<String> componentUuids, @Param("dateAsLong") Long dateAsLong);
void deleteResourceIndex(@Param("componentUuids") List<String> componentUuids);
- void setSnapshotIsLastToFalse(@Param("componentUuid") String componentUuid);
+ void setSnapshotIsLastToFalse(@Param("componentUuids") List<String> componentUuids);
void deleteComponentLinks(@Param("componentUuids") List<String> componentUuids);
@@ -98,7 +101,7 @@ public interface PurgeMapper {
void deleteFileSourcesByProjectUuid(String rootProjectUuid);
- void deleteFileSourcesByUuid(String fileUuid);
+ void deleteFileSourcesByUuid(@Param("fileUuids") List<String> fileUuids);
void deleteCeActivityByProjectUuid(String projectUuid);
}
diff --git a/sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml b/sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
index ebd055cde76..8bd48191a83 100644
--- a/sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
+++ b/sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
@@ -78,7 +78,7 @@
from
projects p
where
- p.root_uuid=#{uuid}
+ p.project_uuid=#{rootUuid}
and p.enabled=${_true}
and not exists(select s.component_uuid from snapshots s where s.islast=${_true} and s.component_uuid=p.uuid)
</select>
@@ -227,7 +227,10 @@
set
enabled=${_false}
where
- uuid=#{componentUuid}
+ uuid in
+ <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
+ #{componentUuid}
+ </foreach>
</update>
<update id="resolveComponentIssuesNotAlreadyResolved" parameterType="map">
@@ -240,7 +243,10 @@
issue_close_date=#{dateAsLong},
issue_update_date=#{dateAsLong}
where
- component_uuid=#{componentUuid}
+ component_uuid in
+ <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
+ #{componentUuid}
+ </foreach>
and resolution is null
</update>
@@ -324,7 +330,15 @@
</delete>
<update id="setSnapshotIsLastToFalse" parameterType="String">
- update snapshots set islast=${_false} where component_uuid=#{componentUuid}
+ update
+ snapshots
+ set
+ islast=${_false}
+ where
+ component_uuid in
+ <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
+ #{componentUuid}
+ </foreach>
</update>
<delete id="deleteComponentIssueChanges" parameterType="map">
@@ -366,7 +380,12 @@
</delete>
<delete id="deleteFileSourcesByUuid">
- delete from file_sources where file_uuid=#{fileUuid}
+ delete from file_sources
+ where
+ file_uuid in
+ <foreach collection="fileUuids" open="(" close=")" item="fileUuid" separator=",">
+ #{fileUuid}
+ </foreach>
</delete>
<select id="selectOldClosedIssueKeys" parameterType="map" resultType="String">
diff --git a/sonar-db/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java b/sonar-db/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java
index 7507d1db680..d6df3980c36 100644
--- a/sonar-db/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java
@@ -26,6 +26,7 @@ import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import static com.google.common.collect.Lists.newArrayList;
+import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
@@ -70,29 +71,29 @@ public class PurgeCommandsTest {
* Test that all related data is purged.
*/
@Test
- public void shouldPurgeSnapshot() {
- dbTester.prepareDbUnit(getClass(), "shouldPurgeSnapshot.xml");
+ public void shouldPurgeAnalysis() {
+ dbTester.prepareDbUnit(getClass(), "shouldPurgeAnalysis.xml");
- new PurgeCommands(dbTester.getSession(), profiler).purgeSnapshots(PurgeSnapshotQuery.create().setSnapshotUuid("u1"));
+ new PurgeCommands(dbTester.getSession(), profiler).purgeAnalyses(singletonList(new IdUuidPair(1, "u1")));
- dbTester.assertDbUnit(getClass(), "shouldPurgeSnapshot-result.xml", "snapshots", "project_measures", "duplications_index", "events");
+ dbTester.assertDbUnit(getClass(), "shouldPurgeAnalysis-result.xml", "snapshots", "project_measures", "duplications_index", "events");
}
@Test
- public void delete_wasted_measures_when_purging_snapshot() {
- dbTester.prepareDbUnit(getClass(), "shouldDeleteWastedMeasuresWhenPurgingSnapshot.xml");
+ public void delete_wasted_measures_when_purging_analysis() {
+ dbTester.prepareDbUnit(getClass(), "shouldDeleteWastedMeasuresWhenPurgingAnalysis.xml");
- new PurgeCommands(dbTester.getSession(), profiler).purgeSnapshots(PurgeSnapshotQuery.create().setSnapshotUuid("u1"));
+ new PurgeCommands(dbTester.getSession(), profiler).purgeAnalyses(singletonList(new IdUuidPair(1, "u1")));
- dbTester.assertDbUnit(getClass(), "shouldDeleteWastedMeasuresWhenPurgingSnapshot-result.xml", "project_measures");
+ dbTester.assertDbUnit(getClass(), "shouldDeleteWastedMeasuresWhenPurgingAnalysis-result.xml", "project_measures");
}
/**
* Test that SQL queries execution do not fail with a huge number of parameter
*/
@Test
- public void should_not_fail_when_purging_huge_number_of_snapshots() {
- new PurgeCommands(dbTester.getSession(), profiler).purgeSnapshots(getHugeNumberOfIdUuidPairs());
+ public void should_not_fail_when_purging_huge_number_of_analyses() {
+ new PurgeCommands(dbTester.getSession(), profiler).purgeAnalyses(getHugeNumberOfIdUuidPairs());
// The goal of this test is only to check that the query do no fail, not to check result
}
diff --git a/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java b/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
index 05aa18219a0..30e66d1f880 100644
--- a/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.db.purge;
+import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
import org.junit.Rule;
@@ -103,9 +104,9 @@ public class PurgeDaoTest {
@Test
public void shouldDeleteSnapshots() {
- dbTester.prepareDbUnit(getClass(), "shouldDeleteSnapshots.xml");
- underTest.deleteSnapshots(dbSession, new PurgeProfiler(), PurgeSnapshotQuery.create().setIslast(false).setComponentUuid(THE_PROJECT_UUID));
- dbTester.assertDbUnit(getClass(), "shouldDeleteSnapshots-result.xml", "snapshots");
+ dbTester.prepareDbUnit(getClass(), "shouldDeleteAnalyses.xml");
+ underTest.deleteAnalyses(dbSession, new PurgeProfiler(), ImmutableList.of(new IdUuidPair(3, "u3")));
+ dbTester.assertDbUnit(getClass(), "shouldDeleteAnalyses-result.xml", "snapshots");
}
@Test
diff --git a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot-result.xml b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingAnalysis-result.xml
index e3297878a6e..e3297878a6e 100644
--- a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot-result.xml
+++ b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingAnalysis-result.xml
diff --git a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot.xml b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingAnalysis.xml
index 9e9b5547c89..9e9b5547c89 100644
--- a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot.xml
+++ b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingAnalysis.xml
diff --git a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeSnapshot-result.xml b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis-result.xml
index 4963f5ed5c4..4963f5ed5c4 100644
--- a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeSnapshot-result.xml
+++ b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis-result.xml
diff --git a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeSnapshot.xml b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis.xml
index d42dbd85c8b..d42dbd85c8b 100644
--- a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeSnapshot.xml
+++ b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis.xml
diff --git a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/delete_file_sources_of_disabled_resources-result.xml b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/delete_file_sources_of_disabled_resources-result.xml
index 919e713b25b..2deaffedd12 100644
--- a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/delete_file_sources_of_disabled_resources-result.xml
+++ b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/delete_file_sources_of_disabled_resources-result.xml
@@ -1,9 +1,25 @@
<dataset>
- <file_sources id="2" project_uuid="ABCD" file_uuid="KLMN" binary_data="[null]" line_hashes="[null]"
- data_hash="321654988" revision="123456789"
- created_at="123456789" updated_at="123456789" src_hash="123456" data_type="SOURCE"/>
- <file_sources id="4" project_uuid="ABCD" file_uuid="KLMN" binary_data="[null]" line_hashes="[null]"
- data_hash="321654988" revision="123456789"
- created_at="123456789" updated_at="123456789" src_hash="123456" data_type="TEST"/>
+ <file_sources id="2"
+ project_uuid="P1"
+ file_uuid="KLMN"
+ binary_data="[null]"
+ line_hashes="[null]"
+ data_hash="321654988"
+ revision="123456789"
+ created_at="123456789"
+ updated_at="123456789"
+ src_hash="123456"
+ data_type="SOURCE"/>
+ <file_sources id="4"
+ project_uuid="P1"
+ file_uuid="KLMN"
+ binary_data="[null]"
+ line_hashes="[null]"
+ data_hash="321654988"
+ revision="123456789"
+ created_at="123456789"
+ updated_at="123456789"
+ src_hash="123456"
+ data_type="TEST"/>
</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/delete_file_sources_of_disabled_resources.xml b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/delete_file_sources_of_disabled_resources.xml
index 86697f8b4dc..c5e8631ac64 100644
--- a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/delete_file_sources_of_disabled_resources.xml
+++ b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/delete_file_sources_of_disabled_resources.xml
@@ -1,9 +1,9 @@
<dataset>
<!-- the project -->
- <projects uuid="ABCD"
- uuid_path="NOT_USED"
- project_uuid="ABCD"
+ <projects uuid="P1"
+ uuid_path="."
+ project_uuid="P1"
module_uuid="[null]"
module_uuid_path="."
created_at="[null]"
@@ -21,13 +21,13 @@
authorization_updated_at="[null]"
id="1"
enabled="[true]"
- root_uuid="ABCD"/>
+ root_uuid="P1"/>
<!-- the directory -->
<projects uuid="EFGH"
- uuid_path="NOT_USED"
- project_uuid="ABCD"
- module_uuid="ABCD"
+ uuid_path=".P1."
+ project_uuid="P1"
+ module_uuid="P1"
module_uuid_path="."
created_at="[null]"
long_name="[null]"
@@ -44,14 +44,14 @@
authorization_updated_at="[null]"
id="2"
enabled="[true]"
- root_uuid="ABCD"/>
+ root_uuid="P1"/>
<!-- the files -->
<projects uuid="GHIJ"
- uuid_path="NOT_USED"
- project_uuid="ABCD"
- module_uuid="ABCD"
- module_uuid_path=".ABCD."
+ uuid_path=".P1.EFGH."
+ project_uuid="P1"
+ module_uuid="P1"
+ module_uuid_path=".P1."
created_at="[null]"
long_name="[null]"
scope="FIL"
@@ -67,12 +67,12 @@
authorization_updated_at="[null]"
id="3"
enabled="[true]"
- root_uuid="ABCD"/>
+ root_uuid="P1"/>
<projects uuid="KLMN"
- uuid_path="NOT_USED"
- project_uuid="ABCD"
- module_uuid="ABCD"
- module_uuid_path=".ABCD."
+ uuid_path=".P1.EFGH."
+ project_uuid="P1"
+ module_uuid="P1"
+ module_uuid_path=".P1."
created_at="[null]"
long_name="[null]"
scope="FIL"
@@ -88,13 +88,13 @@
authorization_updated_at="[null]"
id="4"
enabled="[true]"
- root_uuid="ABCD"/>
+ root_uuid="P1"/>
<snapshots id="1"
uuid="u1"
- component_uuid="ABCD"
+ component_uuid="P1"
parent_snapshot_id="[null]"
- root_component_uuid="ABCD"
+ root_component_uuid="P1"
root_snapshot_id="[null]"
status="P"
islast="[false]"
@@ -126,7 +126,7 @@
uuid="u2"
component_uuid="EFGH"
parent_snapshot_id="1"
- root_component_uuid="ABCD"
+ root_component_uuid="P1"
root_snapshot_id="1"
status="P"
islast="[false]"
@@ -158,7 +158,7 @@
uuid="u3"
component_uuid="GHIJ"
parent_snapshot_id="2"
- root_component_uuid="ABCD"
+ root_component_uuid="P1"
root_snapshot_id="1"
status="P"
islast="[false]"
@@ -191,7 +191,7 @@
uuid="u4"
component_uuid="KLMN"
parent_snapshot_id="2"
- root_component_uuid="ABCD"
+ root_component_uuid="P1"
root_snapshot_id="1"
status="P"
islast="[true]"
@@ -220,7 +220,7 @@
path="[null]"/>
<file_sources id="1"
- project_uuid="ABCD"
+ project_uuid="P1"
file_uuid="GHIJ"
binary_data="[null]"
line_hashes="[null]"
@@ -231,7 +231,7 @@
src_hash="12345"
data_type="SOURCE"/>
<file_sources id="2"
- project_uuid="ABCD"
+ project_uuid="P1"
file_uuid="KLMN"
binary_data="[null]"
line_hashes="[null]"
@@ -242,7 +242,7 @@
src_hash="123456"
data_type="SOURCE"/>
<file_sources id="3"
- project_uuid="ABCD"
+ project_uuid="P1"
file_uuid="GHIJ"
binary_data="[null]"
line_hashes="[null]"
@@ -253,7 +253,7 @@
src_hash="12345"
data_type="TEST"/>
<file_sources id="4"
- project_uuid="ABCD"
+ project_uuid="P1"
file_uuid="KLMN"
binary_data="[null]"
line_hashes="[null]"
diff --git a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAnalyses-result.xml b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAnalyses-result.xml
new file mode 100644
index 00000000000..8806a1de991
--- /dev/null
+++ b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAnalyses-result.xml
@@ -0,0 +1,69 @@
+<dataset>
+
+ <!-- do not delete if islast=true -->
+ <snapshots id="1"
+ uuid="u1"
+ component_uuid="P1"
+ parent_snapshot_id="[null]"
+ root_component_uuid="P1"
+ root_snapshot_id="[null]"
+ status="P"
+ islast="[true]"
+ purge_status="[null]"
+ period1_mode="[null]"
+ period1_param="[null]"
+ period1_date="[null]"
+ period2_mode="[null]"
+ period2_param="[null]"
+ period2_date="[null]"
+ period3_mode="[null]"
+ period3_param="[null]"
+ period3_date="[null]"
+ period4_mode="[null]"
+ period4_param="[null]"
+ period4_date="[null]"
+ period5_mode="[null]"
+ period5_param="[null]"
+ period5_date="[null]"
+ depth="[null]"
+ scope="PRJ"
+ qualifier="TRK"
+ created_at="1228222680000"
+ build_date="1228222680000"
+ version="[null]"
+ path="[null]"/>
+
+ <!-- delete only resource 1 -->
+ <snapshots id="2"
+ uuid="u2"
+ component_uuid="uuid_2"
+ parent_snapshot_id="1"
+ root_component_uuid="P1"
+ root_snapshot_id="1"
+ status="P"
+ islast="[false]"
+ purge_status="[null]"
+ period1_mode="[null]"
+ period1_param="[null]"
+ period1_date="[null]"
+ period2_mode="[null]"
+ period2_param="[null]"
+ period2_date="[null]"
+ period3_mode="[null]"
+ period3_param="[null]"
+ period3_date="[null]"
+ period4_mode="[null]"
+ period4_param="[null]"
+ period4_date="[null]"
+ period5_mode="[null]"
+ period5_param="[null]"
+ period5_date="[null]"
+ depth="[null]"
+ scope="PRJ"
+ qualifier="TRK"
+ created_at="1228222680000"
+ build_date="1228222680000"
+ version="[null]"
+ path="[null]"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAnalyses.xml b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAnalyses.xml
new file mode 100644
index 00000000000..0bab7830171
--- /dev/null
+++ b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAnalyses.xml
@@ -0,0 +1,101 @@
+<dataset>
+
+ <!-- do not delete if islast=true -->
+ <snapshots id="1"
+ uuid="u1"
+ component_uuid="P1"
+ parent_snapshot_id="[null]"
+ root_component_uuid="P1"
+ root_snapshot_id="[null]"
+ status="P"
+ islast="[true]"
+ purge_status="[null]"
+ period1_mode="[null]"
+ period1_param="[null]"
+ period1_date="[null]"
+ period2_mode="[null]"
+ period2_param="[null]"
+ period2_date="[null]"
+ period3_mode="[null]"
+ period3_param="[null]"
+ period3_date="[null]"
+ period4_mode="[null]"
+ period4_param="[null]"
+ period4_date="[null]"
+ period5_mode="[null]"
+ period5_param="[null]"
+ period5_date="[null]"
+ depth="[null]"
+ scope="PRJ"
+ qualifier="TRK"
+ created_at="1228222680000"
+ build_date="1228222680000"
+ version="[null]"
+ path="[null]"/>
+
+ <!-- delete only resource 1 -->
+ <snapshots id="2"
+ uuid="u2"
+ component_uuid="uuid_2"
+ parent_snapshot_id="1"
+ root_component_uuid="P1"
+ root_snapshot_id="1"
+ status="P"
+ islast="[false]"
+ purge_status="[null]"
+ period1_mode="[null]"
+ period1_param="[null]"
+ period1_date="[null]"
+ period2_mode="[null]"
+ period2_param="[null]"
+ period2_date="[null]"
+ period3_mode="[null]"
+ period3_param="[null]"
+ period3_date="[null]"
+ period4_mode="[null]"
+ period4_param="[null]"
+ period4_date="[null]"
+ period5_mode="[null]"
+ period5_param="[null]"
+ period5_date="[null]"
+ depth="[null]"
+ scope="PRJ"
+ qualifier="TRK"
+ created_at="1228222680000"
+ build_date="1228222680000"
+ version="[null]"
+ path="[null]"/>
+
+ <!-- to be deleted -->
+ <snapshots id="3"
+ uuid="u3"
+ component_uuid="P1"
+ parent_snapshot_id="[null]"
+ root_component_uuid="P1"
+ root_snapshot_id="[null]"
+ status="P"
+ islast="[false]"
+ purge_status="[null]"
+ period1_mode="[null]"
+ period1_param="[null]"
+ period1_date="[null]"
+ period2_mode="[null]"
+ period2_param="[null]"
+ period2_date="[null]"
+ period3_mode="[null]"
+ period3_param="[null]"
+ period3_date="[null]"
+ period4_mode="[null]"
+ period4_param="[null]"
+ period4_date="[null]"
+ period5_mode="[null]"
+ period5_param="[null]"
+ period5_date="[null]"
+ depth="[null]"
+ scope="PRJ"
+ qualifier="TRK"
+ created_at="1228222680000"
+ build_date="1228222680000"
+ version="[null]"
+ path="[null]"/>
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteSnapshots-result.xml b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteSnapshots-result.xml
deleted file mode 100644
index 0a3624676c9..00000000000
--- a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteSnapshots-result.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<dataset>
-
- <!-- do not delete if islast=true -->
- <snapshots id="1"
- uuid="u1"
- component_uuid="P1" parent_snapshot_id="[null]" root_component_uuid="P1" root_snapshot_id="[null]"
- status="P" islast="[true]" purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000"
- version="[null]" path="[null]"/>
-
- <!-- delete only resource 1 -->
- <snapshots id="2"
- uuid="u2"
- component_uuid="uuid_2" parent_snapshot_id="1" root_component_uuid="P1" root_snapshot_id="1"
- status="P" islast="[false]" purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000"
- version="[null]" path="[null]"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteSnapshots.xml b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteSnapshots.xml
deleted file mode 100644
index ff7ab3066f4..00000000000
--- a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteSnapshots.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-<dataset>
-
- <!-- do not delete if islast=true -->
- <snapshots id="1"
- uuid="u1"
- component_uuid="P1" parent_snapshot_id="[null]" root_component_uuid="P1" root_snapshot_id="[null]"
- status="P" islast="[true]" purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000"
- version="[null]" path="[null]"/>
-
- <!-- delete only resource 1 -->
- <snapshots id="2"
- uuid="u2"
- component_uuid="uuid_2" parent_snapshot_id="1" root_component_uuid="P1" root_snapshot_id="1"
- status="P" islast="[false]" purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000"
- version="[null]" path="[null]"/>
-
- <!-- to be deleted -->
- <snapshots id="3"
- uuid="u3"
- component_uuid="P1" parent_snapshot_id="[null]" root_component_uuid="P1" root_snapshot_id="[null]"
- status="P" islast="[false]" purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000"
- version="[null]" path="[null]"/>
-</dataset>