aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-06-28 14:34:33 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-07-04 15:20:29 +0200
commit1fee723699376696a3abdafc12c6edc25872dfd0 (patch)
treef3cc37c760c0c59f039b2f47f653517a6180f45c /sonar-db
parenta9a771177453eafa65bfa42b96872df287b8ec68 (diff)
downloadsonarqube-1fee723699376696a3abdafc12c6edc25872dfd0.tar.gz
sonarqube-1fee723699376696a3abdafc12c6edc25872dfd0.zip
SONAR-7705 remove work Resource from PurgeMapper and use uuids
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java18
-rw-r--r--sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java36
-rw-r--r--sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java22
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml156
-rw-r--r--sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java8
5 files changed, 135 insertions, 105 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 4e930ac5954..222fe42cf70 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
@@ -62,21 +62,21 @@ class PurgeCommands {
// Batch requests can only relate to the same PreparedStatement.
for (List<String> componentUuidPartition : componentUuidsPartitions) {
- deleteSnapshots(purgeMapper.selectSnapshotIdAndUuidsByResource(componentUuidPartition));
+ deleteSnapshots(purgeMapper.selectSnapshotIdAndUuidsByComponent(componentUuidPartition));
}
// possible missing optimization: filter requests according to resource scope
profiler.start("deleteResourceLinks (project_links)");
for (List<String> componentUuidPartition : componentUuidsPartitions) {
- purgeMapper.deleteResourceLinks(componentUuidPartition);
+ purgeMapper.deleteComponentLinks(componentUuidPartition);
}
session.commit();
profiler.stop();
profiler.start("deleteResourceProperties (properties)");
for (List<Long> partResourceIds : componentIdPartitions) {
- purgeMapper.deleteResourceProperties(partResourceIds);
+ purgeMapper.deleteComponentProperties(partResourceIds);
}
session.commit();
profiler.stop();
@@ -90,21 +90,21 @@ class PurgeCommands {
profiler.start("deleteResourceGroupRoles (group_roles)");
for (List<Long> partResourceIds : componentIdPartitions) {
- purgeMapper.deleteResourceGroupRoles(partResourceIds);
+ purgeMapper.deleteComponentGroupRoles(partResourceIds);
}
session.commit();
profiler.stop();
profiler.start("deleteResourceUserRoles (user_roles)");
for (List<Long> partResourceIds : componentIdPartitions) {
- purgeMapper.deleteResourceUserRoles(partResourceIds);
+ purgeMapper.deleteComponentUserRoles(partResourceIds);
}
session.commit();
profiler.stop();
profiler.start("deleteResourceManualMeasures (manual_measures)");
for (List<String> componentUuidPartition : componentUuidsPartitions) {
- purgeMapper.deleteResourceManualMeasures(componentUuidPartition);
+ purgeMapper.deleteComponentManualMeasures(componentUuidPartition);
}
session.commit();
profiler.stop();
@@ -131,8 +131,8 @@ class PurgeCommands {
profiler.stop();
profiler.start("deleteResource (projects)");
- for (List<Long> partResourceIds : componentIdPartitions) {
- purgeMapper.deleteResource(partResourceIds);
+ for (List<String> componentUuidPartition : componentUuidsPartitions) {
+ purgeMapper.deleteComponents(componentUuidPartition);
}
session.commit();
profiler.stop();
@@ -205,7 +205,7 @@ class PurgeCommands {
profiler.stop();
profiler.start("updatePurgeStatusToOne (snapshots)");
- snapshotIdUuidPairs.iterator().forEachRemaining(idUuidPair -> purgeMapper.updatePurgeStatusToOne(idUuidPair.getId()));
+ snapshotIdUuidPairs.iterator().forEachRemaining(idUuidPair -> purgeMapper.updatePurgeStatusToOne(idUuidPair.getUuid()));
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 c4b789746a5..489017dd01a 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
@@ -21,7 +21,6 @@ package org.sonar.db.purge;
import com.google.common.collect.Lists;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
@@ -33,7 +32,6 @@ import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
import org.sonar.db.component.ResourceDao;
import org.sonar.db.component.ResourceDto;
@@ -48,12 +46,10 @@ public class PurgeDao implements Dao {
private static final Logger LOG = Loggers.get(PurgeDao.class);
private static final String[] UNPROCESSED_STATUS = new String[] {"U"};
- private final MyBatis mybatis;
private final ResourceDao resourceDao;
private final System2 system2;
- public PurgeDao(MyBatis mybatis, ResourceDao resourceDao, System2 system2) {
- this.mybatis = mybatis;
+ public PurgeDao(ResourceDao resourceDao, System2 system2) {
this.resourceDao = resourceDao;
this.system2 = system2;
}
@@ -119,19 +115,19 @@ public class PurgeDao implements Dao {
}
}
- private void disableOrphanResources(final ResourceDto project, final SqlSession session, final PurgeMapper purgeMapper, final PurgeListener purgeListener) {
- final List<IdUuidPair> componentIdUuids = new ArrayList<>();
- session.select("org.sonar.db.purge.PurgeMapper.selectComponentIdUuidsToDisable", project.getUuid(),
+ private void disableOrphanResources(ResourceDto project, SqlSession session, PurgeMapper purgeMapper, PurgeListener purgeListener) {
+ List<String> componentUuids = new ArrayList<>();
+ session.select("org.sonar.db.purge.PurgeMapper.selectComponentUuidsToDisable", project.getUuid(),
resultContext -> {
- IdUuidPair componentIdUuid = (IdUuidPair) resultContext.getResultObject();
- if (componentIdUuid.getId() != null) {
- componentIdUuids.add(componentIdUuid);
+ String componentUuid = (String) resultContext.getResultObject();
+ if (componentUuid != null) {
+ componentUuids.add(componentUuid);
}
});
- for (IdUuidPair componentIdUuid : componentIdUuids) {
- disableResource(componentIdUuid, purgeMapper);
- purgeListener.onComponentDisabling(componentIdUuid.getUuid());
+ for (String componentUuid : componentUuids) {
+ disableComponent(componentUuid, purgeMapper);
+ purgeListener.onComponentDisabling(componentUuid);
}
session.commit();
@@ -160,12 +156,12 @@ public class PurgeDao implements Dao {
commands.deleteCeActivity(rootUuid);
}
- private void disableResource(IdUuidPair componentIdUuid, PurgeMapper mapper) {
- mapper.deleteResourceIndex(Arrays.asList(componentIdUuid.getUuid()));
- mapper.setSnapshotIsLastToFalse(componentIdUuid.getUuid());
- mapper.deleteFileSourcesByUuid(componentIdUuid.getUuid());
- mapper.disableResource(componentIdUuid.getId());
- mapper.resolveResourceIssuesNotAlreadyResolved(componentIdUuid.getUuid(), system2.now());
+ 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) {
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 d0888709c08..2c2b5298739 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
@@ -27,7 +27,7 @@ public interface PurgeMapper {
List<IdUuidPair> selectSnapshotIdsAndUuids(PurgeSnapshotQuery query);
- List<IdUuidPair> selectSnapshotIdAndUuidsByResource(@Param("componentUuids") List<String> componentUuids);
+ List<IdUuidPair> selectSnapshotIdAndUuidsByComponent(@Param("componentUuids") List<String> componentUuids);
/**
* Returns the list of components of a project from a project_uuid. The project itself is also returned.
@@ -46,29 +46,27 @@ public interface PurgeMapper {
void deleteSnapshotWastedMeasures(@Param("snapshotIds") List<Long> snapshotIds, @Param("mids") List<Long> metricIds);
- void updatePurgeStatusToOne(long snapshotId);
+ void updatePurgeStatusToOne(String snapshotUuid);
- void disableResource(long resourceId);
+ void disableComponent(String componentUuid);
- void resolveResourceIssuesNotAlreadyResolved(@Param("componentUuid") String componentUuid, @Param("dateAsLong") Long dateAsLong);
+ void resolveComponentIssuesNotAlreadyResolved(@Param("componentUuid") String componentUuid, @Param("dateAsLong") Long dateAsLong);
void deleteResourceIndex(@Param("componentUuids") List<String> componentUuids);
- void deleteEvent(long eventId);
-
void setSnapshotIsLastToFalse(@Param("componentUuid") String componentUuid);
- void deleteResourceLinks(@Param("componentUuids") List<String> componentUuids);
+ void deleteComponentLinks(@Param("componentUuids") List<String> componentUuids);
- void deleteResourceProperties(@Param("resourceIds") List<Long> resourceIds);
+ void deleteComponentProperties(@Param("componentIds") List<Long> componentIds);
- void deleteResource(@Param("resourceIds") List<Long> resourceIds);
+ void deleteComponents(@Param("componentUuids") List<String> componentUuids);
- void deleteResourceGroupRoles(@Param("resourceIds") List<Long> resourceIds);
+ void deleteComponentGroupRoles(@Param("componentIds") List<Long> componentIds);
- void deleteResourceUserRoles(@Param("resourceIds") List<Long> resourceIds);
+ void deleteComponentUserRoles(@Param("componentIds") List<Long> componentIds);
- void deleteResourceManualMeasures(@Param("componentUuids") List<String> componentUuids);
+ void deleteComponentManualMeasures(@Param("componentUuids") List<String> componentUuids);
void deleteComponentEvents(@Param("componentUuids") List<String> componentUuids);
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 7cdb910c694..ecbbda75bbc 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
@@ -46,14 +46,16 @@
</where>
</select>
- <select id="selectSnapshotIdAndUuidsByResource" parameterType="map" resultType="IdUuidPair">
- select s.id as id, s.uuid as uuid from snapshots s
- <where>
+ <select id="selectSnapshotIdAndUuidsByComponent" parameterType="map" resultType="IdUuidPair">
+ select
+ s.id as id, s.uuid as uuid
+ from
+ snapshots s
+ where
s.component_uuid in
<foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
#{componentUuid}
</foreach>
- </where>
</select>
<select id="selectPurgeableAnalysesWithEvents" parameterType="String" resultType="PurgeableAnalysis">
@@ -82,10 +84,15 @@
and parent_snapshot_id is null
</select>
- <select id="selectComponentIdUuidsToDisable" resultType="org.sonar.db.purge.IdUuidPair" parameterType="String">
- select p.id, p.uuid from projects p
- where p.root_uuid=#{uuid} 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 id="selectComponentUuidsToDisable" resultType="String" parameterType="String">
+ select
+ p.uuid
+ from
+ projects p
+ where
+ p.root_uuid=#{uuid}
+ 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>
<select id="selectMetricIdsWithoutHistoricalData" resultType="long">
@@ -140,70 +147,93 @@
</where>
</delete>
- <update id="updatePurgeStatusToOne" parameterType="long">
- update snapshots set purge_status = 1 where id = #{id}
+ <update id="updatePurgeStatusToOne" parameterType="string">
+ update
+ snapshots
+ set
+ purge_status = 1
+ where
+ uuid = #{snapshotUuid}
</update>
- <update id="disableResource" parameterType="long">
- update projects set enabled=${_false} where id=#{id}
+ <update id="disableComponent" parameterType="string">
+ update
+ projects
+ set
+ enabled=${_false}
+ where
+ uuid=#{componentUuid}
</update>
- <update id="resolveResourceIssuesNotAlreadyResolved" parameterType="map">
- UPDATE issues SET status='CLOSED',resolution='REMOVED',updated_at=#{dateAsLong},issue_close_date=#{dateAsLong},
- issue_update_date=#{dateAsLong}
- WHERE component_uuid=#{componentUuid} AND resolution IS NULL
+ <update id="resolveComponentIssuesNotAlreadyResolved" parameterType="map">
+ update
+ issues
+ set
+ status='CLOSED',
+ resolution='REMOVED',
+ updated_at=#{dateAsLong},
+ issue_close_date=#{dateAsLong},
+ issue_update_date=#{dateAsLong}
+ where
+ component_uuid=#{componentUuid}
+ and resolution is null
</update>
<delete id="deleteResourceIndex" parameterType="map">
- delete from resource_index where component_uuid in
- <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
- #{componentUuid}
- </foreach>
- </delete>
-
- <delete id="deleteEvent" parameterType="map">
- delete from events where id in
- <foreach collection="resourceIds" open="(" close=")" item="resourceId" separator=",">
- #{resourceId}
- </foreach>
+ delete from resource_index
+ where
+ component_uuid in
+ <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
+ #{componentUuid}
+ </foreach>
</delete>
- <delete id="deleteResourceLinks" parameterType="map">
- delete from project_links where component_uuid in
- <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
- #{componentUuid}
- </foreach>
+ <delete id="deleteComponentLinks" parameterType="map">
+ delete from project_links
+ where
+ component_uuid in
+ <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
+ #{componentUuid}
+ </foreach>
</delete>
- <delete id="deleteResourceProperties" parameterType="map">
- delete from properties where resource_id in
- <foreach collection="resourceIds" open="(" close=")" item="resourceId" separator=",">
- #{resourceId}
- </foreach>
+ <delete id="deleteComponentProperties" parameterType="map">
+ delete from properties
+ where
+ resource_id in
+ <foreach collection="componentIds" open="(" close=")" item="componentId" separator=",">
+ #{componentId}
+ </foreach>
</delete>
- <delete id="deleteResource" parameterType="map">
- delete from projects where id in
- <foreach collection="resourceIds" open="(" close=")" item="resourceId" separator=",">
- #{resourceId}
- </foreach>
+ <delete id="deleteComponents" parameterType="map">
+ delete from projects
+ where
+ uuid in
+ <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
+ #{componentUuid}
+ </foreach>
</delete>
- <delete id="deleteResourceGroupRoles" parameterType="map">
- delete from group_roles where resource_id in
- <foreach collection="resourceIds" open="(" close=")" item="resourceId" separator=",">
- #{resourceId}
- </foreach>
+ <delete id="deleteComponentGroupRoles" parameterType="map">
+ delete from group_roles
+ where
+ resource_id in
+ <foreach collection="componentIds" open="(" close=")" item="componentId" separator=",">
+ #{componentId}
+ </foreach>
</delete>
- <delete id="deleteResourceUserRoles" parameterType="map">
- delete from user_roles where resource_id in
- <foreach collection="resourceIds" open="(" close=")" item="resourceId" separator=",">
- #{resourceId}
- </foreach>
+ <delete id="deleteComponentUserRoles" parameterType="map">
+ delete from user_roles
+ where
+ resource_id in
+ <foreach collection="componentIds" open="(" close=")" item="componentId" separator=",">
+ #{componentId}
+ </foreach>
</delete>
- <delete id="deleteResourceManualMeasures" parameterType="map">
+ <delete id="deleteComponentManualMeasures" parameterType="map">
delete from manual_measures where component_uuid in
<foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
#{componentUuid}
@@ -211,17 +241,21 @@
</delete>
<delete id="deleteComponentEvents" parameterType="map">
- delete from events where component_uuid in
- <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
- #{componentUuid}
- </foreach>
+ delete from events
+ where
+ component_uuid in
+ <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
+ #{componentUuid}
+ </foreach>
</delete>
<delete id="deleteAuthors" parameterType="map">
- delete from authors where person_id in
- <foreach collection="resourceIds" open="(" close=")" item="resourceId" separator=",">
- #{resourceId}
- </foreach>
+ delete from authors
+ where
+ person_id in
+ <foreach collection="resourceIds" open="(" close=")" item="resourceId" separator=",">
+ #{resourceId}
+ </foreach>
</delete>
<update id="setSnapshotIsLastToFalse" parameterType="String">
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 afb7d30e8cf..154dda8bc0a 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
@@ -84,7 +84,8 @@ public class PurgeDaoTest {
@Test
public void shouldDeleteHistoricalDataOfDirectoriesAndFiles() {
dbTester.prepareDbUnit(getClass(), "shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml");
- underTest.purge(dbSession, new PurgeConfiguration(new IdUuidPair(THE_PROJECT_ID, "1"), new String[] {Scopes.DIRECTORY, Scopes.FILE}, 30), PurgeListener.EMPTY, new PurgeProfiler());
+ underTest.purge(dbSession, new PurgeConfiguration(new IdUuidPair(THE_PROJECT_ID, "1"), new String[] {Scopes.DIRECTORY, Scopes.FILE}, 30), PurgeListener.EMPTY,
+ new PurgeProfiler());
dbSession.commit();
dbTester.assertDbUnit(getClass(), "shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml", "projects", "snapshots");
}
@@ -95,8 +96,9 @@ public class PurgeDaoTest {
when(system2.now()).thenReturn(1450000000000L);
underTest.purge(dbSession, newConfigurationWith30Days(system2), PurgeListener.EMPTY, new PurgeProfiler());
dbSession.commit();
- dbTester.assertDbUnit(getClass(), "disable_resources_without_last_snapshot-result.xml", new String[] {"issue_close_date", "issue_update_date"}, "projects", "snapshots",
- "issues");
+ dbTester.assertDbUnit(getClass(), "disable_resources_without_last_snapshot-result.xml",
+ new String[] {"issue_close_date", "issue_update_date"},
+ "projects", "snapshots", "issues");
}
@Test