summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java6
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java10
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasureWithLargeData-result.xml8
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureMapper.java2
-rw-r--r--sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureMapper.xml8
6 files changed, 20 insertions, 17 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 4ccc106b70a..a03c6c90369 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
@@ -188,7 +188,7 @@ public final class MeasurePersister {
for (MeasureModel value : values) {
mapper.insert(value);
if (value.getMeasureData() != null) {
- mapper.insertData(value);
+ mapper.insertData(value.getMeasureData());
}
}
@@ -208,7 +208,7 @@ public final class MeasurePersister {
mapper.insert(value);
if (value.getMeasureData() != null) {
- mapper.insertData(value);
+ mapper.insertData(value.getMeasureData());
}
session.commit();
@@ -231,7 +231,7 @@ public final class MeasurePersister {
mapper.update(value);
mapper.deleteData(value);
if (value.getMeasureData() != null) {
- mapper.insertData(value);
+ mapper.insertData(value.getMeasureData());
}
session.commit();
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 26615c99a82..c59dc0e7613 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
@@ -19,6 +19,8 @@
*/
package org.sonar.batch.index;
+import org.mockito.ArgumentCaptor;
+
import org.apache.commons.lang.StringUtils;
import org.junit.Before;
import org.junit.Test;
@@ -110,10 +112,14 @@ public class MeasurePersisterTest extends AbstractDaoTestCase {
public void should_insert_measure_with_text_data() {
setupData("empty");
- measurePersister.saveMeasure(project, new Measure(ncloc()).setData(SHORT));
- measurePersister.saveMeasure(project, new Measure(ncloc()).setData(LONG));
+ Measure withLargeData = new Measure(ncloc()).setData(LONG);
+ measurePersister.saveMeasure(project, withLargeData);
checkTables("shouldInsertMeasureWithLargeData", "project_measures", "measure_data");
+
+ ArgumentCaptor<MeasureModel> validMeasureModel = ArgumentCaptor.forClass(MeasureModel.class);
+ verify(memoryOptimizer).evictDataMeasure(eq(withLargeData), validMeasureModel.capture());
+ assertThat(validMeasureModel.getValue().getMeasureData().getId()).isNotNull();
}
@Test
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasureWithLargeData-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasureWithLargeData-result.xml
index c90db3d3f14..77b6b6049a8 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasureWithLargeData-result.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasureWithLargeData-result.xml
@@ -1,18 +1,12 @@
<dataset>
<project_measures id="1" VALUE="[null]" METRIC_ID="1" SNAPSHOT_ID="3001" alert_text="[null]" RULES_CATEGORY_ID="[null]"
- RULE_ID="[null]" text_value="SHORT" 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]"/>
-
- <project_measures id="2" VALUE="[null]" METRIC_ID="1" SNAPSHOT_ID="3001" 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=="/>
+ <measure_data id="1" measure_id="1" snapshot_id="3001" 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 543f8f0f31a..e6a62e55356 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
@@ -19,6 +19,8 @@
*/
package org.sonar.core.persistence;
+import org.sonar.api.database.model.MeasureData;
+
import ch.qos.logback.classic.Level;
import com.google.common.io.Closeables;
import org.apache.ibatis.builder.xml.XMLMapperBuilder;
@@ -138,6 +140,7 @@ public class MyBatis implements BatchComponent, ServerComponent {
loadAlias(conf, "Widget", WidgetDto.class);
loadAlias(conf, "WidgetProperty", WidgetPropertyDto.class);
loadAlias(conf, "MeasureModel", MeasureModel.class);
+ loadAlias(conf, "MeasureData", MeasureData.class);
Class<?>[] mappers = {ActiveDashboardMapper.class, AuthorMapper.class, FilterMapper.class, CriterionMapper.class, FilterColumnMapper.class, DashboardMapper.class,
DependencyMapper.class, DuplicationMapper.class, LoadedTemplateMapper.class, PropertiesMapper.class, PurgeMapper.class,
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureMapper.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureMapper.java
index f9362533a76..e5ca6ecac0e 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureMapper.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureMapper.java
@@ -22,7 +22,7 @@ package org.sonar.api.database.model;
public interface MeasureMapper {
void insert(MeasureModel measure);
- void insertData(MeasureModel data);
+ void insertData(MeasureData data);
void deleteData(MeasureModel data);
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 cb892f7009a..bbc0ba808ea 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
@@ -16,9 +16,9 @@
)
</insert>
- <insert id="insertData" parameterType="MeasureModel" useGeneratedKeys="true">
+ <insert id="insertData" parameterType="MeasureData" useGeneratedKeys="true" keyProperty="id">
INSERT INTO measure_data (measure_id, snapshot_id, data)
- VALUES (#{id}, #{snapshotId}, #{measureData.data})
+ VALUES (#{measure.id}, #{measure.snapshotId}, #{data})
</insert>
<update id="deleteData" parameterType="MeasureModel">
@@ -64,9 +64,9 @@
)
</insert>
- <insert id="insertData" databaseId="oracle" parameterType="MeasureModel" useGeneratedKeys="true">
+ <insert id="insertData" databaseId="oracle" parameterType="MeasureData" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
INSERT INTO measure_data (id, measure_id, snapshot_id, data)
- VALUES (measure_data_seq.NEXTVAL, #{id}, #{snapshotId}, #{measureData.data})
+ VALUES (measure_data_seq.NEXTVAL, #{measure.id}, #{measure.snapshotId}, #{data})
</insert>
</mapper>