From 1e207b3b6de3382938c710a7c6135be4ce849219 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Mon, 9 Jul 2012 11:36:01 +0200 Subject: SONAR-3437 Use MyBatis instead of Hibernate to improve batch insert --- .../org/sonar/api/database/model/MeasureDto.java | 156 +++++++++++++++++++++ .../api/database/model/MeasureModelMapper.java | 26 ++++ .../database/model/MeasureModelMapper-oracle.xml | 46 ++++++ .../api/database/model/MeasureModelMapper.xml | 43 ++++++ 4 files changed, 271 insertions(+) create mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureDto.java create mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModelMapper.java create mode 100644 sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureModelMapper-oracle.xml create mode 100644 sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureModelMapper.xml (limited to 'sonar-plugin-api') 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 = new ArrayList(); + + 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 @@ + + + + + + + + select project_measures_seq.NEXTVAL from DUAL + + 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} + ) + + + + + 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} + + + 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 @@ + + + + + + + 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} + ) + + + + + 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} + + + -- cgit v1.2.3