diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2013-01-29 10:40:17 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2013-01-29 12:28:32 +0100 |
commit | afa0528377e18a5d40f8771f5093729d81e80e6e (patch) | |
tree | 525e192139018640a983a9a2af2a58550a8bcd8e /sonar-core | |
parent | a98f8dfab784f9e0e6e1fa8d0b7c9608db5814fd (diff) | |
download | sonarqube-afa0528377e18a5d40f8771f5093729d81e80e6e.tar.gz sonarqube-afa0528377e18a5d40f8771f5093729d81e80e6e.zip |
SONAR-2501 purge project graphs
Diffstat (limited to 'sonar-core')
12 files changed, 63 insertions, 12 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/component/ComponentVertex.java b/sonar-core/src/main/java/org/sonar/core/component/ComponentVertex.java index e4fc8b75b16..8d139007b36 100644 --- a/sonar-core/src/main/java/org/sonar/core/component/ComponentVertex.java +++ b/sonar-core/src/main/java/org/sonar/core/component/ComponentVertex.java @@ -42,6 +42,7 @@ public class ComponentVertex extends BeanVertex implements Component { setProperty("qualifier", component.qualifier()); if (component instanceof ResourceComponent) { setProperty("sid", ((ResourceComponent) component).snapshotId()); + setProperty("rid", ((ResourceComponent) component).resourceId()); } } } diff --git a/sonar-core/src/main/java/org/sonar/core/component/ResourceComponent.java b/sonar-core/src/main/java/org/sonar/core/component/ResourceComponent.java index c200a5bf4a4..b519d7a922d 100644 --- a/sonar-core/src/main/java/org/sonar/core/component/ResourceComponent.java +++ b/sonar-core/src/main/java/org/sonar/core/component/ResourceComponent.java @@ -30,6 +30,7 @@ class ResourceComponent implements Component { private String name; private String qualifier; private Long snapshotId; + private Long resourceId; ResourceComponent(Resource resource, @Nullable Snapshot snapshot) { this.key = resource.getEffectiveKey(); @@ -37,6 +38,7 @@ class ResourceComponent implements Component { this.qualifier = resource.getQualifier(); if (snapshot != null && snapshot.getId() != null) { this.snapshotId = snapshot.getId().longValue(); + this.resourceId = snapshot.getResourceId().longValue(); } } @@ -59,4 +61,8 @@ class ResourceComponent implements Component { public Long snapshotId() { return snapshotId; } + + public Long resourceId() { + return resourceId; + } }
\ No newline at end of file diff --git a/sonar-core/src/main/java/org/sonar/core/component/ScanGraphStore.java b/sonar-core/src/main/java/org/sonar/core/component/ScanGraphStore.java index 0af38668cab..2baaddc271c 100644 --- a/sonar-core/src/main/java/org/sonar/core/component/ScanGraphStore.java +++ b/sonar-core/src/main/java/org/sonar/core/component/ScanGraphStore.java @@ -58,6 +58,7 @@ public class ScanGraphStore { .setFormat("graphson") .setPerspective(builder.getPerspectiveKey()) .setVersion(1) + .setResourceId((Long) component.element().getProperty("rid")) .setSnapshotId(snapshotId) .setRootVertexId(component.element().getId().toString()) ); diff --git a/sonar-core/src/main/java/org/sonar/core/graph/jdbc/GraphDto.java b/sonar-core/src/main/java/org/sonar/core/graph/jdbc/GraphDto.java index 64ae196f765..d081cfe8d61 100644 --- a/sonar-core/src/main/java/org/sonar/core/graph/jdbc/GraphDto.java +++ b/sonar-core/src/main/java/org/sonar/core/graph/jdbc/GraphDto.java @@ -21,6 +21,7 @@ package org.sonar.core.graph.jdbc; public class GraphDto { private long id; + private long resourceId; private long snapshotId; private String format; private String perspective; @@ -37,6 +38,15 @@ public class GraphDto { return this; } + public long getResourceId() { + return resourceId; + } + + public GraphDto setResourceId(long resourceId) { + this.resourceId = resourceId; + return this; + } + public long getSnapshotId() { return snapshotId; } diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java index 9d3b77a486a..13f5b9bea23 100644 --- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java +++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java @@ -112,6 +112,11 @@ class PurgeCommands { session.commit(); for (Long resourceId : resourceIds) { + purgeMapper.deleteResourceGraphs(resourceId); + } + session.commit(); + + for (Long resourceId : resourceIds) { purgeMapper.deleteResource(resourceId); } session.commit(); @@ -163,6 +168,11 @@ class PurgeCommands { session.commit(); for (Long snapshotId : snapshotIds) { + purgeMapper.deleteSnapshotGraphs(snapshotId); + } + session.commit(); + + for (Long snapshotId : snapshotIds) { purgeMapper.deleteSnapshot(snapshotId); } @@ -195,6 +205,11 @@ class PurgeCommands { } session.commit(); + for (Long snapshotId : snapshotIds) { + purgeMapper.deleteSnapshotGraphs(snapshotId); + } + session.commit(); + List<Long> metricIdsWithoutHistoricalData = purgeMapper.selectMetricIdsWithoutHistoricalData(); if (!metricIdsWithoutHistoricalData.isEmpty()) { for (Long snapshotId : snapshotIds) { diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java index 3dedc06b3f0..84234fa1cac 100644 --- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java @@ -45,6 +45,8 @@ public interface PurgeMapper { void deleteSnapshotViolations(long snapshotId); + void deleteSnapshotGraphs(long snapshotId); + List<Long> selectMetricIdsWithoutHistoricalData(); List<Long> selectCharacteristicIdsToPurge(); @@ -81,6 +83,8 @@ public interface PurgeMapper { void deleteResourceActionPlans(long resourceId); + void deleteResourceGraphs(long resourceId); + void deleteAuthors(long developerId); void closeResourceReviews(long resourceId); diff --git a/sonar-core/src/main/resources/org/sonar/core/graph/jdbc/GraphDtoMapper.xml b/sonar-core/src/main/resources/org/sonar/core/graph/jdbc/GraphDtoMapper.xml index 81d9dec7327..ee684f90ddf 100644 --- a/sonar-core/src/main/resources/org/sonar/core/graph/jdbc/GraphDtoMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/graph/jdbc/GraphDtoMapper.xml @@ -4,13 +4,13 @@ <mapper namespace="org.sonar.core.graph.jdbc.GraphDtoMapper"> <select id="selectBySnapshot" parameterType="map" resultType="Graph"> - SELECT id, snapshot_id as snapshotId, format, version, perspective, root_vertex_id as rootVertexId, data + SELECT id, resource_id as resourceId, snapshot_id as snapshotId, format, version, perspective, root_vertex_id as rootVertexId, data FROM graphs WHERE snapshot_id = #{sid} AND perspective = #{perspective} </select> <select id="selectByComponent" parameterType="map" resultType="Graph"> - SELECT g.id, g.snapshot_id as snapshotId, g.format, g.version, g.perspective, g.root_vertex_id as rootVertexId, g.data + SELECT g.id, g.resource_id as resourceId, g.snapshot_id as snapshotId, g.format, g.version, g.perspective, g.root_vertex_id as rootVertexId, g.data FROM graphs g, snapshots s WHERE g.perspective = #{perspective} AND g.snapshot_id=s.id AND s.islast=${_true} and s.project_id=( select id from projects where enabled=${_true} and kee=#{key} and person_id is null and copy_resource_id is null @@ -19,9 +19,9 @@ <insert id="insert" parameterType="Graph" useGeneratedKeys="false"> insert into graphs - (snapshot_id, format, version, perspective, root_vertex_id, data, created_at, updated_at) + (resource_id, snapshot_id, format, version, perspective, root_vertex_id, data, created_at, updated_at) values ( - #{snapshotId}, #{format}, #{version}, #{perspective}, #{rootVertexId}, + #{resourceId}, #{snapshotId}, #{format}, #{version}, #{perspective}, #{rootVertexId}, #{data}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) </insert> @@ -31,9 +31,9 @@ select graphs_seq.NEXTVAL from DUAL </selectKey> insert into graphs - (id, snapshot_id, format, version, perspective, root_vertex_id, data, created_at, updated_at) + (id, resource_id, snapshot_id, format, version, perspective, root_vertex_id, data, created_at, updated_at) values ( - #{id}, #{snapshotId}, #{format}, #{version}, #{perspective}, #{rootVertexId}, + #{id}, #{resourceId}, #{snapshotId}, #{format}, #{version}, #{perspective}, #{rootVertexId}, #{data}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) </insert> </mapper> diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl index 413c2f65832..aea283eb183 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl @@ -501,6 +501,7 @@ CREATE TABLE "MEASURE_FILTER_FAVOURITES" ( CREATE TABLE "GRAPHS" ( "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "RESOURCE_ID" INTEGER NOT NULL, "SNAPSHOT_ID" INTEGER NOT NULL, "FORMAT" VARCHAR(20), "PERSPECTIVE" VARCHAR(30), diff --git a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml index 33975927cc1..affa97b86b1 100644 --- a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml @@ -100,6 +100,10 @@ delete from rule_failures where snapshot_id=#{id} </delete> + <delete id="deleteSnapshotGraphs" parameterType="long"> + delete from graphs where snapshot_id=#{id} + </delete> + <delete id="deleteSnapshotDependencies" parameterType="long"> delete from dependencies where from_snapshot_id=#{id} or to_snapshot_id=#{id} or project_snapshot_id=#{id} </delete> @@ -119,14 +123,14 @@ <delete id="deleteSnapshotWastedMeasures" parameterType="map"> delete from project_measures where snapshot_id=#{sid} and (rule_id is not null or person_id is not null or metric_id in - <foreach item="mid" index="index" collection="mids" open="(" separator="," close=")">#{mid}</foreach> + <foreach item="mid" index="index" collection="mids" open="(" separator="," close=")">#{mid}</foreach> ) </delete> <delete id="deleteSnapshotMeasuresOnCharacteristics" parameterType="map"> delete from project_measures where snapshot_id=#{sid} and ( - <foreach item="cid" index="index" collection="cids" open="" separator=" OR " close="">characteristic_id=#{cid}</foreach> + <foreach item="cid" index="index" collection="cids" open="" separator=" OR " close="">characteristic_id=#{cid}</foreach> ) </delete> @@ -187,6 +191,10 @@ delete from action_plans where project_id=#{id} </delete> + <delete id="deleteResourceGraphs" parameterType="long"> + delete from graphs where resource_id=#{id} + </delete> + <delete id="deleteAuthors" parameterType="long"> delete from authors where person_id=#{id} </delete> diff --git a/sonar-core/src/test/java/org/sonar/core/component/ResourceComponentTest.java b/sonar-core/src/test/java/org/sonar/core/component/ResourceComponentTest.java index efdf18a307d..61c55b931c9 100644 --- a/sonar-core/src/test/java/org/sonar/core/component/ResourceComponentTest.java +++ b/sonar-core/src/test/java/org/sonar/core/component/ResourceComponentTest.java @@ -27,19 +27,22 @@ import static org.fest.assertions.Assertions.assertThat; public class ResourceComponentTest { @Test - public void snapshot_id_should_be_optional() { + public void db_ids_should_be_optional() { ResourceComponent component = new ResourceComponent(new File("foo.c"), new Snapshot()); assertThat(component.snapshotId()).isNull(); + assertThat(component.resourceId()).isNull(); } @Test - public void snapshot_id_should_be_set() { + public void db_ids_should_be_set() { Snapshot snapshot = new Snapshot(); snapshot.setId(123); + snapshot.setResourceId(456); ResourceComponent component = new ResourceComponent(new File("foo.c"), snapshot); assertThat(component.snapshotId()).isEqualTo(123); + assertThat(component.resourceId()).isEqualTo(456); } @Test diff --git a/sonar-core/src/test/java/org/sonar/core/graph/jdbc/GraphDaoTest.java b/sonar-core/src/test/java/org/sonar/core/graph/jdbc/GraphDaoTest.java index 38d6cc8dfc3..09f46951ae2 100644 --- a/sonar-core/src/test/java/org/sonar/core/graph/jdbc/GraphDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/graph/jdbc/GraphDaoTest.java @@ -39,6 +39,7 @@ public class GraphDaoTest extends AbstractDaoTestCase { GraphDto testPlan = dao.selectBySnapshot("testplan", 11L); assertThat(testPlan.getId()).isEqualTo(101L); + assertThat(testPlan.getResourceId()).isEqualTo(1L); assertThat(testPlan.getSnapshotId()).isEqualTo(11L); assertThat(testPlan.getFormat()).isEqualTo("graphson"); assertThat(testPlan.getVersion()).isEqualTo(1); @@ -62,6 +63,7 @@ public class GraphDaoTest extends AbstractDaoTestCase { GraphDto testPlan = dao.selectByComponent("testplan", "org.apache.struts:struts"); assertThat(testPlan.getId()).isEqualTo(101L); + assertThat(testPlan.getResourceId()).isEqualTo(1L); assertThat(testPlan.getSnapshotId()).isEqualTo(11L); assertThat(testPlan.getFormat()).isEqualTo("graphson"); assertThat(testPlan.getVersion()).isEqualTo(1); diff --git a/sonar-core/src/test/resources/org/sonar/core/graph/jdbc/GraphDaoTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/graph/jdbc/GraphDaoTest/shared.xml index 6df3aaca20c..9345cfcf402 100644 --- a/sonar-core/src/test/resources/org/sonar/core/graph/jdbc/GraphDaoTest/shared.xml +++ b/sonar-core/src/test/resources/org/sonar/core/graph/jdbc/GraphDaoTest/shared.xml @@ -4,6 +4,6 @@ <snapshots id="10" project_id="1" islast="[false]" /> <snapshots id="11" project_id="1" islast="[true]" /> - <graphs id="100" snapshot_id="11" format="graphson" version="1" perspective="testable" root_vertex_id="7890" data="{testable of snapshot 123}"/> - <graphs id="101" snapshot_id="11" format="graphson" version="1" perspective="testplan" root_vertex_id="3456" data="{testplan of snapshot 123}"/> + <graphs id="100" resource_id="1" snapshot_id="11" format="graphson" version="1" perspective="testable" root_vertex_id="7890" data="{testable of snapshot 123}"/> + <graphs id="101" resource_id="1" snapshot_id="11" format="graphson" version="1" perspective="testplan" root_vertex_id="3456" data="{testplan of snapshot 123}"/> </dataset>
\ No newline at end of file |