aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-07-09 11:36:01 +0200
committerDavid Gageot <david@gageot.net>2012-07-09 13:48:07 +0200
commit1e207b3b6de3382938c710a7c6135be4ce849219 (patch)
tree3fa34dde986f316760dc630ee1d8fb12503ec006 /sonar-plugin-api
parent111cf7219f5a4439687f2cd836fb8e498e545773 (diff)
downloadsonarqube-1e207b3b6de3382938c710a7c6135be4ce849219.tar.gz
sonarqube-1e207b3b6de3382938c710a7c6135be4ce849219.zip
SONAR-3437 Use MyBatis instead of Hibernate to improve batch insert
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureDto.java156
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModelMapper.java26
-rw-r--r--sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureModelMapper-oracle.xml46
-rw-r--r--sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureModelMapper.xml43
4 files changed, 271 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureDto.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureDto.java
new file mode 100644
index 00000000000..a0cb386407d
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureDto.java
@@ -0,0 +1,156 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.database.model;
+
+import java.util.Date;
+
+public class MeasureDto {
+ private final Long id;
+ private final Double value;
+ private final String textValue;
+ private final Integer tendency;
+ private final Integer metricId;
+ private final Integer snapshotId;
+ private final Integer projectId;
+ private final String description;
+ private final Date measureDate;
+ private final Integer ruleId;
+ private final Integer rulePriority;
+ private final String alertStatus;
+ private final String alertText;
+ private final Double variationValue1;
+ private final Double variationValue2;
+ private final Double variationValue3;
+ private final Double variationValue4;
+ private final Double variationValue5;
+ private final String url;
+ private final Integer characteristicId;
+ private final Integer personId;
+
+ // private List<MeasureData> measureData = new ArrayList<MeasureData>();
+
+ public MeasureDto(MeasureModel model) {
+ id = model.getId();
+ value = model.getValue();
+ textValue = model.getTextValue();
+ tendency = model.getTendency();
+ metricId = model.getMetricId();
+ snapshotId = model.getSnapshotId();
+ projectId = model.getProjectId();
+ description = model.getDescription();
+ measureDate = model.getMeasureDate();
+ ruleId = model.getRuleId();
+ rulePriority = (null == model.getRulePriority()) ? null : model.getRulePriority().ordinal();
+ alertStatus = (null == model.getAlertStatus()) ? null : model.getAlertStatus().name();
+ alertText = model.getAlertText();
+ variationValue1 = model.getVariationValue1();
+ variationValue2 = model.getVariationValue2();
+ variationValue3 = model.getVariationValue3();
+ variationValue4 = model.getVariationValue4();
+ variationValue5 = model.getVariationValue5();
+ url = model.getUrl();
+ characteristicId = (null == model.getCharacteristic()) ? null : model.getCharacteristic().getId();
+ personId = model.getPersonId();
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public Double getValue() {
+ return value;
+ }
+
+ public String getTextValue() {
+ return textValue;
+ }
+
+ public Integer getTendency() {
+ return tendency;
+ }
+
+ public Integer getMetricId() {
+ return metricId;
+ }
+
+ public Integer getSnapshotId() {
+ return snapshotId;
+ }
+
+ public Integer getProjectId() {
+ return projectId;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public Date getMeasureDate() {
+ return measureDate;
+ }
+
+ public Integer getRuleId() {
+ return ruleId;
+ }
+
+ public Integer getRulePriority() {
+ return rulePriority;
+ }
+
+ public String getAlertStatus() {
+ return alertStatus;
+ }
+
+ public String getAlertText() {
+ return alertText;
+ }
+
+ public Double getVariationValue1() {
+ return variationValue1;
+ }
+
+ public Double getVariationValue2() {
+ return variationValue2;
+ }
+
+ public Double getVariationValue3() {
+ return variationValue3;
+ }
+
+ public Double getVariationValue4() {
+ return variationValue4;
+ }
+
+ public Double getVariationValue5() {
+ return variationValue5;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public Integer getCharacteristicId() {
+ return characteristicId;
+ }
+
+ public Integer getPersonId() {
+ return personId;
+ }
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModelMapper.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModelMapper.java
new file mode 100644
index 00000000000..615971f3ffe
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModelMapper.java
@@ -0,0 +1,26 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.database.model;
+
+public interface MeasureModelMapper {
+ void insert(MeasureDto measure);
+
+ void update(MeasureDto measure);
+}
diff --git a/sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureModelMapper-oracle.xml b/sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureModelMapper-oracle.xml
new file mode 100644
index 00000000000..655f4cecc7a
--- /dev/null
+++ b/sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureModelMapper-oracle.xml
@@ -0,0 +1,46 @@
+<?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.MeasureModelMapper">
+
+ <insert id="insert" parameterType="MeasureDto" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+ <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}, #{characteristicId}, #{variationValue1},
+ #{variationValue2}, #{variationValue3}, #{variationValue4}, #{variationValue5}, #{personId}
+ )
+ </insert>
+
+
+ <update id="update" parameterType="MeasureDto">
+ UPDATE project_measures
+ SET
+ value = #{value},
+ metric_id = #{metricId},
+ rule_id = #{ruleId},
+ text_value = #{textValue, jdbcType=VARCHAR},
+ tendency = #{tendency},
+ alert_status = #{alertStatus, jdbcType=VARCHAR},
+ alert_text = #{alertText, jdbcType=VARCHAR},
+ url = #{url, jdbcType=VARCHAR},
+ description = #{description, jdbcType=VARCHAR},
+ rule_priority = #{rulePriority},
+ characteristic_id = #{characteristicId},
+ 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/MeasureModelMapper.xml b/sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureModelMapper.xml
new file mode 100644
index 00000000000..594674a1b3c
--- /dev/null
+++ b/sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureModelMapper.xml
@@ -0,0 +1,43 @@
+<?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.MeasureModelMapper">
+
+ <insert id="insert" parameterType="MeasureDto" useGeneratedKeys="true" keyProperty="id">
+ 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}, #{characteristicId}, #{variationValue1},
+ #{variationValue2}, #{variationValue3}, #{variationValue4}, #{variationValue5}, #{personId}
+ )
+ </insert>
+
+
+ <update id="update" parameterType="MeasureDto">
+ UPDATE project_measures
+ SET
+ value = #{value},
+ metric_id = #{metricId},
+ rule_id = #{ruleId},
+ text_value = #{textValue, jdbcType=VARCHAR},
+ tendency = #{tendency},
+ alert_status = #{alertStatus, jdbcType=VARCHAR},
+ alert_text = #{alertText, jdbcType=VARCHAR},
+ url = #{url, jdbcType=VARCHAR},
+ description = #{description, jdbcType=VARCHAR},
+ rule_priority = #{rulePriority},
+ characteristic_id = #{characteristicId},
+ 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>