summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java8
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java14
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/data.xml4
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java1
-rw-r--r--sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureMapper-oracle.xml53
-rw-r--r--sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureMapper.xml23
7 files changed, 38 insertions, 69 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
index 0c0cf825354..4ccc106b70a 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
@@ -85,11 +85,12 @@ public final class MeasurePersister {
}
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;
}
@@ -218,9 +219,10 @@ public final class MeasurePersister {
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 {
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java
index 4e7f37add5d..26615c99a82 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java
@@ -122,7 +122,7 @@ public class MeasurePersisterTest extends AbstractDaoTestCase {
measurePersister.saveMeasure(aFile, new Measure(coverage()).setValue(100.0));
- assertEmptyTables("project_measures");
+ assertEmptyTables("project_measures", "measure_data");
}
@Test
@@ -131,7 +131,7 @@ public class MeasurePersisterTest extends AbstractDaoTestCase {
measurePersister.saveMeasure(aFile, new Measure("ncloc").setPersistenceMode(PersistenceMode.MEMORY));
- assertEmptyTables("project_measures");
+ assertEmptyTables("project_measures", "measure_data");
}
@Test
@@ -150,9 +150,9 @@ public class MeasurePersisterTest extends AbstractDaoTestCase {
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
@@ -180,7 +180,7 @@ public class MeasurePersisterTest extends AbstractDaoTestCase {
assertEmptyTables("project_measures");
measurePersister.dump();
- checkTables("shouldDelaySaving", "project_measures");
+ checkTables("shouldDelaySaving", "project_measures", "measure_data");
}
@Test
@@ -201,11 +201,11 @@ public class MeasurePersisterTest extends AbstractDaoTestCase {
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
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/data.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/data.xml
index 2db0aca4e4d..b64b9b2d480 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/data.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/data.xml
@@ -12,12 +12,10 @@
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>
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml
index e1db7336b32..22201f588e4 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml
@@ -12,12 +12,12 @@
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>
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
index d5c23809301..65c2d425ba3 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
@@ -83,6 +83,7 @@ public class MyBatis implements BatchComponent, ServerComponent {
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);
diff --git a/sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureMapper-oracle.xml b/sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureMapper-oracle.xml
deleted file mode 100644
index 380e14ffb08..00000000000
--- a/sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureMapper-oracle.xml
+++ /dev/null
@@ -1,53 +0,0 @@
-<?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>
diff --git a/sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureMapper.xml b/sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureMapper.xml
index 6823b141497..cb892f7009a 100644
--- a/sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureMapper.xml
+++ b/sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureMapper.xml
@@ -22,7 +22,7 @@
</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">
@@ -48,4 +48,25 @@
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>