}
private MeasureModel insertOrUpdate(Resource resource, Measure measure) {
+ Snapshot snapshot = resourcePersister.getSnapshotOrFail(resource);
if (measure.getId() != null) {
- return update(measure);
+ return update(measure, snapshot);
}
if (shouldPersistMeasure(resource, measure)) {
- return insert(measure, resourcePersister.getSnapshotOrFail(resource));
+ return insert(measure, snapshot);
}
return null;
}
return value;
}
- private MeasureModel update(Measure measure) {
+ private MeasureModel update(Measure measure, Snapshot snapshot) {
MeasureModel value = model(measure);
value.setId(measure.getId());
+ value.setSnapshotId(snapshot.getId());
SqlSession session = mybatis.openSession();
try {
measurePersister.saveMeasure(aFile, new Measure(coverage()).setValue(100.0));
- assertEmptyTables("project_measures");
+ assertEmptyTables("project_measures", "measure_data");
}
@Test
measurePersister.saveMeasure(aFile, new Measure("ncloc").setPersistenceMode(PersistenceMode.MEMORY));
- assertEmptyTables("project_measures");
+ assertEmptyTables("project_measures", "measure_data");
}
@Test
measurePersister.saveMeasure(project, new Measure(coverage()).setValue(12.5).setId(1L));
measurePersister.saveMeasure(project, new Measure(coverage()).setData(SHORT).setId(2L));
- measurePersister.saveMeasure(project, new Measure(coverage()).setData(LONG).setId(3L));
+ measurePersister.saveMeasure(aPackage, new Measure(coverage()).setData(LONG).setId(3L));
- checkTables("shouldUpdateMeasure", "project_measures");
+ checkTables("shouldUpdateMeasure", "project_measures", "measure_data");
}
@Test
assertEmptyTables("project_measures");
measurePersister.dump();
- checkTables("shouldDelaySaving", "project_measures");
+ checkTables("shouldDelaySaving", "project_measures", "measure_data");
}
@Test
measurePersister.setDelayedMode(true);
measurePersister.saveMeasure(aFile, new Measure(coverage()).setValue(100.0));
- assertEmptyTables("project_measures");
+ assertEmptyTables("project_measures", "measure_data");
measurePersister.dump();
- assertEmptyTables("project_measures");
+ assertEmptyTables("project_measures", "measure_data");
}
@Test
person_id="[null]"
variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/>
- <project_measures id="3" VALUE="60" METRIC_ID="2" SNAPSHOT_ID="3001" alert_text="[null]" RULES_CATEGORY_ID="[null]"
+ <project_measures id="3" VALUE="60" METRIC_ID="2" SNAPSHOT_ID="3002" alert_text="[null]" RULES_CATEGORY_ID="[null]"
RULE_ID="[null]" text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]"
person_id="[null]"
variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/>
- <measure_data id="1" measure_id="2" snapshot_id="3001" data="MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OQ=="/>
-
</dataset>
person_id="[null]"
variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/>
- <project_measures id="3" VALUE="[null]" METRIC_ID="2" SNAPSHOT_ID="3001" alert_text="[null]" RULES_CATEGORY_ID="[null]"
+ <project_measures id="3" VALUE="[null]" METRIC_ID="2" SNAPSHOT_ID="3002" alert_text="[null]" RULES_CATEGORY_ID="[null]"
RULE_ID="[null]" text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]"
person_id="[null]"
variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/>
- <measure_data id="1" measure_id="3" snapshot_id="3001" data="MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OQ=="/>
+ <measure_data id="1" measure_id="3" snapshot_id="3002" data="MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OQ=="/>
</dataset>
conf.setJdbcTypeForNull(JdbcType.NULL);
conf.getVariables().setProperty("_true", database.getDialect().getTrueSqlValue());
conf.getVariables().setProperty("_false", database.getDialect().getFalseSqlValue());
+ conf.setDatabaseId(database.getDialect().getId());
loadAlias(conf, "ActiveDashboard", ActiveDashboardDto.class);
loadAlias(conf, "Author", AuthorDto.class);
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.api.database.model.MeasureMapper">
-
- <insert id="insert" parameterType="MeasureModel" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
- INSERT INTO project_measures (
- id,
- value, metric_id, snapshot_id, rule_id, text_value, tendency, measure_date,
- project_id, alert_status, alert_text, url, description, rule_priority, characteristic_id, variation_value_1,
- variation_value_2, variation_value_3, variation_value_4, variation_value_5, person_id)
- VALUES (
- project_measures_seq.NEXTVAL,
- #{value}, #{metricId}, #{snapshotId}, #{ruleId}, #{textValue}, #{tendency},
- #{measureDate}, #{projectId}, #{alertStatus}, #{alertText},
- #{url}, #{description}, #{rulePriority.ordinal}, #{characteristic.id}, #{variationValue1},
- #{variationValue2}, #{variationValue3}, #{variationValue4}, #{variationValue5}, #{personId}
- )
- </insert>
-
- <insert id="insertData" parameterType="MeasureModel" useGeneratedKeys="true">
- INSERT INTO measure_data (id, measure_id, snapshot_id, data)
- VALUES (measure_data_seq.NEXTVAL, #{id}, #{snapshotId}, #{measureData.data})
- </insert>
-
- <update id="deleteData" parameterType="MeasureModel">
- DELETE FROM measure_data WHERE measure_id = #{id} AND snapshot_id = #{snapshotId}
- </update>
-
- <update id="update" parameterType="MeasureModel">
- UPDATE project_measures
- SET
- value = #{value},
- metric_id = #{metricId},
- rule_id = #{ruleId},
- text_value = #{textValue},
- tendency = #{tendency},
- alert_status = #{alertStatus},
- alert_text = #{alertText},
- url = #{url},
- description = #{description},
- rule_priority = #{rulePriority.ordinal},
- characteristic_id = #{characteristic.id},
- variation_value_1 = #{variationValue1},
- variation_value_2 = #{variationValue2},
- variation_value_3 = #{variationValue3},
- variation_value_4 = #{variationValue4},
- variation_value_5 = #{variationValue5},
- person_id = #{personId}
- WHERE id = #{id}
- </update>
-
-</mapper>
</insert>
<update id="deleteData" parameterType="MeasureModel">
- DELETE FROM measure_data WHERE measure_id = #{id} AND snapshot_id = #{snapshotId}
+ DELETE FROM measure_data WHERE measure_id=#{id} AND snapshot_id=#{snapshotId}
</update>
<update id="update" parameterType="MeasureModel">
WHERE id = #{id}
</update>
+ <!-- ORACLE -->
+ <insert id="insert" databaseId="oracle" parameterType="MeasureModel" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+ INSERT INTO project_measures (
+ id,
+ value, metric_id, snapshot_id, rule_id, text_value, tendency, measure_date,
+ project_id, alert_status, alert_text, url, description, rule_priority, characteristic_id, variation_value_1,
+ variation_value_2, variation_value_3, variation_value_4, variation_value_5, person_id)
+ VALUES (
+ project_measures_seq.NEXTVAL,
+ #{value}, #{metricId}, #{snapshotId}, #{ruleId}, #{textValue}, #{tendency},
+ #{measureDate}, #{projectId}, #{alertStatus}, #{alertText},
+ #{url}, #{description}, #{rulePriority.ordinal}, #{characteristic.id}, #{variationValue1},
+ #{variationValue2}, #{variationValue3}, #{variationValue4}, #{variationValue5}, #{personId}
+ )
+ </insert>
+
+ <insert id="insertData" databaseId="oracle" parameterType="MeasureModel" useGeneratedKeys="true">
+ INSERT INTO measure_data (id, measure_id, snapshot_id, data)
+ VALUES (measure_data_seq.NEXTVAL, #{id}, #{snapshotId}, #{measureData.data})
+ </insert>
+
</mapper>