diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2010-11-26 06:56:17 +0000 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2010-11-26 06:56:17 +0000 |
commit | 19f841e8c13c6dc8ef2f6a68a5751fa5fba26062 (patch) | |
tree | 9d49148613eb125d28d69984ee76331f867b18c5 /sonar-core/src | |
parent | 0b63c5a59ac2f160c5c7bc35d7f423f2a944e8ac (diff) | |
download | sonarqube-19f841e8c13c6dc8ef2f6a68a5751fa5fba26062.tar.gz sonarqube-19f841e8c13c6dc8ef2f6a68a5751fa5fba26062.zip |
SONAR-249: extract persistence layer from data index + dump measures at the end of the batch instead of persisting them on the fly
Diffstat (limited to 'sonar-core/src')
3 files changed, 10 insertions, 8 deletions
diff --git a/sonar-core/src/main/java/org/sonar/jpa/dao/AsyncMeasuresDao.java b/sonar-core/src/main/java/org/sonar/jpa/dao/AsyncMeasuresDao.java index 4e2ece885ab..4c8c71b0b72 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dao/AsyncMeasuresDao.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dao/AsyncMeasuresDao.java @@ -131,7 +131,7 @@ public class AsyncMeasuresDao extends BaseDao { "AND ams.snapshotDate>=:measureDate " +
"ORDER BY ams.snapshotDate ASC ")
.setParameter("projectId", asyncMeasure.getProjectId())
- .setParameter("metricId", asyncMeasure.getMetric().getId())
+ .setParameter("metricId", asyncMeasure.getMetricId())
.setParameter("measureDate", asyncMeasure.getMeasureDate());
if (endDate != null) {
query.setParameter("endDate", endDate);
diff --git a/sonar-core/src/main/java/org/sonar/jpa/dao/AsyncMeasuresService.java b/sonar-core/src/main/java/org/sonar/jpa/dao/AsyncMeasuresService.java index ae296d1e356..26b1926b901 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dao/AsyncMeasuresService.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dao/AsyncMeasuresService.java @@ -90,7 +90,7 @@ public class AsyncMeasuresService { AsyncMeasuresDao dao = new AsyncMeasuresDao(session); MeasureModel measure = dao.getAsyncMeasure(id); AsyncMeasureSnapshot pastAsyncMeasureSnapshot = dao.getLastAsyncMeasureSnapshot(measure.getProjectId(), - measure.getMetric().getId(), measure.getMeasureDate()); + measure.getMetricId(), measure.getMeasureDate()); dao.deleteAsyncMeasure(measure); if (pastAsyncMeasureSnapshot != null) { MeasureModel pastAsyncMeasure = dao.getAsyncMeasure(pastAsyncMeasureSnapshot.getMeasureId()); @@ -102,7 +102,7 @@ public class AsyncMeasuresService { private void registerMeasure(MeasureModel measure, AsyncMeasuresDao dao) { AsyncMeasureSnapshot nextAsyncMeasureSnapshot = dao.getNextAsyncMeasureSnapshot( - measure.getProjectId(), measure.getMetric().getId(), measure.getMeasureDate()); + measure.getProjectId(), measure.getMetricId(), measure.getMeasureDate()); Date dateNextAsyncMeasure = (nextAsyncMeasureSnapshot != null) ? nextAsyncMeasureSnapshot.getMeasureDate() : null; List<AsyncMeasureSnapshot> nextAsyncMeasureSnapshots = dao.getNextAsyncMeasureSnapshotsUntilDate( @@ -110,7 +110,7 @@ public class AsyncMeasuresService { if (!nextAsyncMeasureSnapshots.isEmpty()) { for (AsyncMeasureSnapshot asyncMeasureSnapshot : nextAsyncMeasureSnapshots) { dao.createAsyncMeasureSnapshot(measure.getId(), asyncMeasureSnapshot.getSnapshotId(), measure.getMeasureDate(), - asyncMeasureSnapshot.getSnapshotDate(), measure.getMetric().getId(), measure.getProjectId()); + asyncMeasureSnapshot.getSnapshotDate(), measure.getMetricId(), measure.getProjectId()); dao.removeSnapshotFromAsyncMeasureSnapshot(asyncMeasureSnapshot); } } else { @@ -118,11 +118,11 @@ public class AsyncMeasuresService { if (!nextSnapshotsUntilDate.isEmpty()) { for (Snapshot nextSnapshot : nextSnapshotsUntilDate) { dao.createAsyncMeasureSnapshot(measure.getId(), nextSnapshot.getId(), measure.getMeasureDate(), - nextSnapshot.getCreatedAt(), measure.getMetric().getId(), measure.getProjectId()); + nextSnapshot.getCreatedAt(), measure.getMetricId(), measure.getProjectId()); } } else { dao.createAsyncMeasureSnapshot(measure.getId(), null, measure.getMeasureDate(), - null, measure.getMetric().getId(), measure.getProjectId()); + null, measure.getMetricId(), measure.getProjectId()); } } } 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 6cc891f6cf8..4094cca55c2 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 @@ -26,6 +26,7 @@ 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;
@@ -53,11 +54,12 @@ public class DatabaseSessionTest extends AbstractDbUnitTestCase { Snapshot snapshot = new Snapshot(project1, true, "", new Date(1));
getSession().save(project1, snapshot);
+ getSession().save(CoreMetrics.CLASSES);
getSession().commit();
- Metric metric = new MeasuresDao(getSession()).getMetric("classes_count");
+ Metric metric = new MeasuresDao(getSession()).getMetric(CoreMetrics.CLASSES_KEY);
for (int i = 0; i < NB_INSERTS; i++) {
- MeasureModel pm = new MeasureModel(metric, 1.0).setSnapshotId(snapshot.getId());
+ MeasureModel pm = new MeasureModel(metric.getId(), 1.0).setSnapshotId(snapshot.getId());
getSession().save(pm);
}
|