setProperty("qualifier", component.qualifier());
if (component instanceof ResourceComponent) {
setProperty("sid", ((ResourceComponent) component).snapshotId());
+ setProperty("rid", ((ResourceComponent) component).resourceId());
}
}
}
private String name;
private String qualifier;
private Long snapshotId;
+ private Long resourceId;
ResourceComponent(Resource resource, @Nullable Snapshot snapshot) {
this.key = resource.getEffectiveKey();
this.qualifier = resource.getQualifier();
if (snapshot != null && snapshot.getId() != null) {
this.snapshotId = snapshot.getId().longValue();
+ this.resourceId = snapshot.getResourceId().longValue();
}
}
public Long snapshotId() {
return snapshotId;
}
+
+ public Long resourceId() {
+ return resourceId;
+ }
}
\ No newline at end of file
.setFormat("graphson")
.setPerspective(builder.getPerspectiveKey())
.setVersion(1)
+ .setResourceId((Long) component.element().getProperty("rid"))
.setSnapshotId(snapshotId)
.setRootVertexId(component.element().getId().toString())
);
public class GraphDto {
private long id;
+ private long resourceId;
private long snapshotId;
private String format;
private String perspective;
return this;
}
+ public long getResourceId() {
+ return resourceId;
+ }
+
+ public GraphDto setResourceId(long resourceId) {
+ this.resourceId = resourceId;
+ return this;
+ }
+
public long getSnapshotId() {
return snapshotId;
}
}
session.commit();
+ for (Long resourceId : resourceIds) {
+ purgeMapper.deleteResourceGraphs(resourceId);
+ }
+ session.commit();
+
for (Long resourceId : resourceIds) {
purgeMapper.deleteResource(resourceId);
}
}
session.commit();
+ for (Long snapshotId : snapshotIds) {
+ purgeMapper.deleteSnapshotGraphs(snapshotId);
+ }
+ session.commit();
+
for (Long snapshotId : snapshotIds) {
purgeMapper.deleteSnapshot(snapshotId);
}
}
session.commit();
+ for (Long snapshotId : snapshotIds) {
+ purgeMapper.deleteSnapshotGraphs(snapshotId);
+ }
+ session.commit();
+
List<Long> metricIdsWithoutHistoricalData = purgeMapper.selectMetricIdsWithoutHistoricalData();
if (!metricIdsWithoutHistoricalData.isEmpty()) {
for (Long snapshotId : snapshotIds) {
void deleteSnapshotViolations(long snapshotId);
+ void deleteSnapshotGraphs(long snapshotId);
+
List<Long> selectMetricIdsWithoutHistoricalData();
List<Long> selectCharacteristicIdsToPurge();
void deleteResourceActionPlans(long resourceId);
+ void deleteResourceGraphs(long resourceId);
+
void deleteAuthors(long developerId);
void closeResourceReviews(long resourceId);
<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
<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>
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>
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),
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>
<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>
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>
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
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);
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);
<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
def self.up
create_table 'graphs' do |t|
t.column 'snapshot_id', :integer, :null => false
+ t.column 'resource_id', :integer, :null => false
t.column 'format', :string, :null => true, :limit => 20
t.column 'perspective', :string, :null => true, :limit => 30
t.column 'version', :string, :null => true, :limit => 20