]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3437 merge Mappers
authorDavid Gageot <david@gageot.net>
Wed, 11 Jul 2012 15:04:02 +0000 (17:04 +0200)
committerDavid Gageot <david@gageot.net>
Wed, 11 Jul 2012 15:38:40 +0000 (17:38 +0200)
sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java
sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/data.xml
sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml
sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureMapper-oracle.xml [deleted file]
sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureMapper.xml

index 0c0cf8253548454b68a2ede5670a856608e40164..4ccc106b70a0f196e4d4c16d9ca2f4b17b03fc36 100644 (file)
@@ -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 {
index 4e7f37add5d36ab5d816ead37c54aae1305e903b..26615c99a82a12261aca84c63702e0d72ae8e59c 100644 (file)
@@ -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
index 2db0aca4e4d4fb5269d78f5e720f8c6d0b3b8650..b64b9b2d480f60e462cea6d865241180d1987616 100644 (file)
                     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>
index e1db7336b32081d0c5914d907217cdba890548ae..22201f588e4d54f29ff50828dde5ef0f62a5e34a 100644 (file)
                     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>
index d5c238093010c68f8046d5d67a77d1088ddf28a5..65c2d425ba30d0cca89a34df3fc7e75571c63e7b 100644 (file)
@@ -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 (file)
index 380e14f..0000000
+++ /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>
index 6823b1414978491a086ee06de9147b1fdf870c24..cb892f7009a705a54edc64b2625873a2d2024d92 100644 (file)
@@ -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">
     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>