]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3437 Fix batch insert on mysql
authorDavid Gageot <david@gageot.net>
Tue, 10 Jul 2012 09:54:42 +0000 (11:54 +0200)
committerDavid Gageot <david@gageot.net>
Tue, 10 Jul 2012 09:54:42 +0000 (11:54 +0200)
sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureMapper.java
sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureMapper-oracle.xml
sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureMapper.xml

index e8ed644c2c8cfad9c621eea0e1cf7a822da6ca5e..34ae2758b413c1ae02d3f4702c058545be39168c 100644 (file)
@@ -189,7 +189,7 @@ public final class MeasurePersister {
       MeasureMapper mapper = session.getMapper(MeasureMapper.class);
 
       for (MeasureModel value : values) {
-        mapper.insert(value);
+        mapper.batchInsert(value);
       }
 
       session.commit();
@@ -204,7 +204,7 @@ public final class MeasurePersister {
       MeasureMapper mapper = session.getMapper(MeasureMapper.class);
 
       for (MeasureModel value : values) {
-        mapper.insert(value);
+        mapper.batchInsert(value);
         mapper.insertData(value);
       }
 
index 5995096374796e839714c2053cc3265fa3d600ac..bc73674425b640d21a9f6368868f73eb1333757d 100644 (file)
@@ -22,6 +22,8 @@ package org.sonar.api.database.model;
 public interface MeasureMapper {
   void insert(MeasureModel measure);
 
+  void batchInsert(MeasureModel measure);
+
   void insertData(MeasureModel data);
 
   void update(MeasureModel measure);
index 4213e3c9003ffb46e3a4e01bc94c7b5f622299cd..b64fb24264666f85264d8b36c1af5ca36e2fa8f4 100644 (file)
     )
   </insert>
 
-  <insert id="insertData" parameterType="MeasureModel" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+  <insert id="batchInsert" parameterType="MeasureModel" useGeneratedKeys="false">
+    <selectKey order="BEFORE" resultType="Long" keyProperty="id">
+      select project_measures_seq.NEXTVAL from DUAL
+    </selectKey>
+    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 (#{id},
+      #{value}, #{metricId}, #{snapshotId}, #{ruleId}, #{textValue, jdbcType=VARCHAR}, #{tendency},
+      #{measureDate, jdbcType=TIMESTAMP}, #{projectId}, #{alertStatus, jdbcType=VARCHAR}, #{alertText, jdbcType=VARCHAR},
+      #{url, jdbcType=VARCHAR}, #{description, jdbcType=VARCHAR}, #{rulePriority.ordinal}, #{characteristic.id}, #{variationValue1},
+      #{variationValue2}, #{variationValue3}, #{variationValue4}, #{variationValue5}, #{personId}
+    )
+  </insert>
+
+  <insert id="insertData" parameterType="MeasureModel" useGeneratedKeys="false">
     <selectKey order="BEFORE" resultType="Long" keyProperty="id">
       select measure_data_seq.NEXTVAL from DUAL
     </selectKey>
index b24af941d6a07eb7c7471a97617814fba7dccfa4..c6eee0d29f793c5a37417dccb824660806397c85 100644 (file)
     )
   </insert>
   
-  <insert id="insertData" parameterType="MeasureModel" useGeneratedKeys="true" keyProperty="id">
+  <insert id="batchInsert" parameterType="MeasureModel" useGeneratedKeys="false">
+    INSERT INTO project_measures (
+      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 (
+      #{value}, #{metricId}, #{snapshotId}, #{ruleId}, #{textValue, jdbcType=VARCHAR}, #{tendency},
+      #{measureDate, jdbcType=TIMESTAMP}, #{projectId}, #{alertStatus, jdbcType=VARCHAR}, #{alertText, jdbcType=VARCHAR},
+      #{url, jdbcType=VARCHAR}, #{description, jdbcType=VARCHAR}, #{rulePriority.ordinal}, #{characteristic.id}, #{variationValue1},
+      #{variationValue2}, #{variationValue3}, #{variationValue4}, #{variationValue5}, #{personId}
+    )
+  </insert>
+  
+  <insert id="insertData" parameterType="MeasureModel" useGeneratedKeys="false">
     INSERT INTO measure_data (measure_id, snapshot_id, data)
     VALUES (#{measureData.measure.id}, #{snapshotId}, #{measureData.data}) 
   </insert>