From 478383011bba15b19869380384aa569697706681 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Thu, 24 Apr 2014 18:05:36 +0200 Subject: Revert "SONAR-3437 Remove Measure from Hibernate model" This reverts commit cafd76d5317716817c0f15a402d820a6e80d19a9. --- .../src/main/resources/META-INF/persistence.xml | 2 ++ .../org/sonar/jpa/session/DatabaseSessionTest.java | 34 +++++++++++++++++----- 2 files changed, 28 insertions(+), 8 deletions(-) (limited to 'sonar-core/src') diff --git a/sonar-core/src/main/resources/META-INF/persistence.xml b/sonar-core/src/main/resources/META-INF/persistence.xml index 79a9ad22f6b..034e3dffd10 100644 --- a/sonar-core/src/main/resources/META-INF/persistence.xml +++ b/sonar-core/src/main/resources/META-INF/persistence.xml @@ -11,6 +11,8 @@ org.sonar.api.database.configuration.Property org.sonar.api.database.model.User org.sonar.api.database.model.Snapshot + org.sonar.api.database.model.MeasureModel + org.sonar.api.database.model.MeasureData org.sonar.api.design.DependencyDto org.sonar.api.measures.Metric org.sonar.api.database.model.ResourceModel diff --git a/sonar-core/src/test/java/org/sonar/jpa/session/DatabaseSessionTest.java b/sonar-core/src/test/java/org/sonar/jpa/session/DatabaseSessionTest.java index 54d57081e68..99bb844283e 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/session/DatabaseSessionTest.java +++ b/sonar-core/src/test/java/org/sonar/jpa/session/DatabaseSessionTest.java @@ -23,20 +23,19 @@ import org.hamcrest.Matchers; import org.junit.Before; import org.junit.Test; import org.junit.internal.matchers.IsCollectionContaining; +import org.sonar.api.database.model.MeasureModel; import org.sonar.api.database.model.ResourceModel; +import org.sonar.api.database.model.Snapshot; +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.Metric; +import org.sonar.jpa.dao.MeasuresDao; import org.sonar.jpa.test.AbstractDbUnitTestCase; import javax.persistence.NonUniqueResultException; - +import java.sql.Date; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; public class DatabaseSessionTest extends AbstractDbUnitTestCase { private static final Long NB_INSERTS = 20000l; @@ -50,6 +49,25 @@ public class DatabaseSessionTest extends AbstractDbUnitTestCase { project2 = new ResourceModel(ResourceModel.SCOPE_PROJECT, "mygroup:myartifact1", "JAV", null, "my name 2"); } + @Test + public void performanceTestOnBatchInserts() throws Exception { + getSession().save(project1); + Snapshot snapshot = new Snapshot(project1, true, "", new Date(1)); + getSession().save(snapshot); + getSession().save(CoreMetrics.CLASSES); + getSession().commit(); + + Metric metric = new MeasuresDao(getSession()).getMetric(CoreMetrics.CLASSES_KEY); + for (int i = 0; i < NB_INSERTS; i++) { + MeasureModel pm = new MeasureModel(metric.getId(), 1.0).setSnapshotId(snapshot.getId()); + getSession().save(pm); + } + + getSession().commit(); + assertEquals(NB_INSERTS, getHQLCount(MeasureModel.class)); + + } + @Test public void testGetSingleResultWithNoResults() { assertNull(getSession().getSingleResult(ResourceModel.class, "name", "test")); -- cgit v1.2.3