aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-11-05 17:40:34 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-11-05 17:40:34 +0000
commit7b76b83b4c2cc1e5621281185e35e7d75a9ac9f1 (patch)
tree961a97dccbf1520dd61b5a7ee462853b18ac90b4 /sonar-batch
parent3a1d139ba2b2f22e0d8e1cadc390959fa52a07d4 (diff)
downloadsonarqube-7b76b83b4c2cc1e5621281185e35e7d75a9ac9f1.tar.gz
sonarqube-7b76b83b4c2cc1e5621281185e35e7d75a9ac9f1.zip
fix issue in snapshot duplications
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/indexer/LibraryPersister.java37
1 files changed, 33 insertions, 4 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/indexer/LibraryPersister.java b/sonar-batch/src/main/java/org/sonar/batch/indexer/LibraryPersister.java
index 7d7fcfaf318..2aaa2f316ef 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/indexer/LibraryPersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/indexer/LibraryPersister.java
@@ -25,7 +25,9 @@ import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Library;
import org.sonar.api.resources.Resource;
+import javax.persistence.Query;
import java.util.Date;
+import java.util.List;
public class LibraryPersister extends ResourcePersister<Library> {
@@ -52,10 +54,11 @@ public class LibraryPersister extends ResourcePersister<Library> {
@Override
protected Snapshot createSnapshot(Bucket<Library> bucket, ResourceModel resourceModel) {
- Snapshot snapshot = getSession().getSingleResult(Snapshot.class,
- "resourceId", resourceModel.getId(),
- "version", bucket.getResource().getVersion(),
- "scope", Resource.SCOPE_SET);
+ Snapshot snapshot = findProject(resourceModel.getId(), bucket.getResource().getVersion());
+ if (snapshot == null) {
+ snapshot = findLibrary(resourceModel.getId(), bucket.getResource().getVersion());
+ }
+
if (snapshot == null) {
snapshot = new Snapshot(resourceModel, null);
snapshot.setCreatedAt(now);
@@ -68,4 +71,30 @@ public class LibraryPersister extends ResourcePersister<Library> {
}
return snapshot;
}
+
+ private Snapshot findLibrary(Integer resourceId, String version) {
+ List<Snapshot> snapshots = getSession().getResults(Snapshot.class,
+ "resourceId", resourceId,
+ "version", version,
+ "scope", Resource.SCOPE_SET,
+ "qualifier", Resource.QUALIFIER_LIB);
+ if (snapshots.isEmpty()) {
+ return null;
+ }
+ return snapshots.get(0);
+ }
+
+ private Snapshot findProject(Integer resourceId, String version) {
+ Query query = getSession().createQuery("from " + Snapshot.class.getSimpleName() + " s WHERE s.resourceId=:resourceId AND s.version=:version AND s.scope=:scope AND s.qualifier<>:qualifier AND s.last=:last");
+ query.setParameter("resourceId", resourceId);
+ query.setParameter("version", version);
+ query.setParameter("scope", Resource.SCOPE_SET);
+ query.setParameter("qualifier", Resource.QUALIFIER_LIB);
+ query.setParameter("last", Boolean.TRUE);
+ List<Snapshot> snapshots = query.getResultList();
+ if (snapshots.isEmpty()) {
+ return null;
+ }
+ return snapshots.get(0);
+ }
}