aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-dbcleaner-plugin/src/main
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2011-10-27 13:37:43 +0200
committersimonbrandhof <simon.brandhof@gmail.com>2011-10-27 19:51:36 +0200
commit851fee23dbc02e601121f162ea73cd38fe01a213 (patch)
tree5cfffb6204e5caaa6be5f2bc610c0bd8756db320 /plugins/sonar-dbcleaner-plugin/src/main
parentc5ff5521a3c3b5775557745fda19db642d56772f (diff)
downloadsonarqube-851fee23dbc02e601121f162ea73cd38fe01a213.tar.gz
sonarqube-851fee23dbc02e601121f162ea73cd38fe01a213.zip
Improve boolean parameters of Hibernate HQL queries
Diffstat (limited to 'plugins/sonar-dbcleaner-plugin/src/main')
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDependencies.java2
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLast.java3
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResources.java6
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEntities.java7
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphans.java5
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessed.java3
6 files changed, 14 insertions, 12 deletions
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDependencies.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDependencies.java
index 65792f152aa..430e4c6ffd2 100644
--- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDependencies.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDependencies.java
@@ -38,7 +38,7 @@ public final class PurgeDependencies extends Purge {
public void purge(PurgeContext context) {
Query query = getSession().createQuery("SELECT d.projectSnapshotId FROM " + DependencyDto.class.getSimpleName() +
" d WHERE EXISTS(FROM " + Snapshot.class.getSimpleName() + " s WHERE s.id=d.projectSnapshotId AND s.last=:last and s.status=:status)");
- query.setParameter("last", false);
+ query.setParameter("last", Boolean.FALSE);
query.setParameter("status", Snapshot.STATUS_PROCESSED);
final List<Integer> projectSnapshotIds = query.getResultList();
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLast.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLast.java
index fc84d52a2de..6246551cca4 100644
--- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLast.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLast.java
@@ -40,7 +40,8 @@ public final class PurgeDeprecatedLast extends Purge {
public void purge(PurgeContext context) {
Query query = getSession().createQuery("SELECT s.id FROM " + Snapshot.class.getSimpleName() +
- " s WHERE s.last=true AND s.rootId IS NOT NULL AND NOT EXISTS(FROM " + Snapshot.class.getSimpleName() + " s2 WHERE s2.id=s.rootId AND s2.last=true)");
+ " s WHERE s.last=last AND s.rootId IS NOT NULL AND NOT EXISTS(FROM " + Snapshot.class.getSimpleName() + " s2 WHERE s2.id=s.rootId AND s2.last=true)");
+ query.setParameter("last", Boolean.TRUE);
List<Integer> snapshotIds = query.getResultList();
PurgeUtils.deleteSnapshotsData(getSession(), snapshotIds);
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResources.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResources.java
index 4a0895fea0c..267876d0928 100644
--- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResources.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResources.java
@@ -53,13 +53,15 @@ public final class PurgeDisabledResources extends Purge {
}
private List<Integer> getResourceIds() {
- Query query = getSession().createQuery("SELECT r.id FROM " + ResourceModel.class.getSimpleName() + " r WHERE r.enabled=false");
+ Query query = getSession().createQuery("SELECT r.id FROM " + ResourceModel.class.getSimpleName() + " r WHERE r.enabled=:enabled");
+ query.setParameter("enabled", Boolean.FALSE);
return query.getResultList();
}
private List<Integer> getSnapshotIds() {
Query query = getSession().createQuery("SELECT s.id FROM " + Snapshot.class.getSimpleName() + " s WHERE " +
- " EXISTS (FROM " + ResourceModel.class.getSimpleName() + " r WHERE r.id=s.resourceId AND r.enabled=false)");
+ " EXISTS (FROM " + ResourceModel.class.getSimpleName() + " r WHERE r.id=s.resourceId AND r.enabled=:enabled)");
+ query.setParameter("enabled", Boolean.FALSE);
return query.getResultList();
}
}
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEntities.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEntities.java
index a074cb9a6bb..ac33e6f6e0f 100644
--- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEntities.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEntities.java
@@ -23,7 +23,7 @@ import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.time.DateUtils;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.Resource;
+import org.sonar.api.resources.Scopes;
import org.sonar.api.utils.Logs;
import org.sonar.plugins.dbcleaner.api.Purge;
import org.sonar.plugins.dbcleaner.api.PurgeContext;
@@ -50,9 +50,10 @@ public final class PurgeEntities extends Purge {
final Date beforeDate = DateUtils.addHours(new Date(), -minimumPeriodInHours);
Logs.INFO.info("Deleting files data before " + beforeDate);
- Query query = getSession().createQuery("SELECT s.id FROM " + Snapshot.class.getSimpleName() + " s WHERE s.last=false AND scope=:scope AND s.createdAt<:date");
- query.setParameter("scope", Resource.SCOPE_ENTITY);
+ Query query = getSession().createQuery("SELECT s.id FROM " + Snapshot.class.getSimpleName() + " s WHERE s.last=:last AND scope=:scope AND s.createdAt<:date");
+ query.setParameter("scope", Scopes.FILE);
query.setParameter("date", beforeDate);
+ query.setParameter("last", Boolean.FALSE);
List<Integer> snapshotIds = query.getResultList();
PurgeUtils.deleteSnapshotsData(getSession(), snapshotIds);
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphans.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphans.java
index 1b55504f1c6..5a5ebf4c259 100644
--- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphans.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphans.java
@@ -22,15 +22,12 @@ package org.sonar.plugins.dbcleaner.purges;
import org.sonar.api.batch.Event;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.database.model.SnapshotSource;
import org.sonar.plugins.dbcleaner.api.Purge;
import org.sonar.plugins.dbcleaner.api.PurgeContext;
import org.sonar.plugins.dbcleaner.api.PurgeUtils;
-import java.util.List;
-
import javax.persistence.Query;
+import java.util.List;
public final class PurgeEventOrphans extends Purge {
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessed.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessed.java
index 21b7b67bb26..9e7ffe2aa3a 100644
--- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessed.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessed.java
@@ -49,9 +49,10 @@ public final class PurgeUnprocessed extends Purge {
final Date beforeDate = DateUtils.addHours(new Date(), -minimumPeriodInHours);
Logs.INFO.info("Deleting unprocessed data before " + beforeDate);
- Query query = getSession().createQuery("SELECT s.id FROM " + Snapshot.class.getSimpleName() + " s WHERE s.last=false AND status=:status AND s.createdAt<:date");
+ Query query = getSession().createQuery("SELECT s.id FROM " + Snapshot.class.getSimpleName() + " s WHERE s.last=:last AND status=:status AND s.createdAt<:date");
query.setParameter("status", Snapshot.STATUS_UNPROCESSED);
query.setParameter("date", beforeDate);
+ query.setParameter("last", Boolean.FALSE);
List<Integer> snapshotIds = query.getResultList();
PurgeUtils.deleteSnapshotsData(getSession(), snapshotIds);