diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2011-10-27 13:37:43 +0200 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-10-27 19:51:36 +0200 |
commit | 851fee23dbc02e601121f162ea73cd38fe01a213 (patch) | |
tree | 5cfffb6204e5caaa6be5f2bc610c0bd8756db320 /plugins | |
parent | c5ff5521a3c3b5775557745fda19db642d56772f (diff) | |
download | sonarqube-851fee23dbc02e601121f162ea73cd38fe01a213.tar.gz sonarqube-851fee23dbc02e601121f162ea73cd38fe01a213.zip |
Improve boolean parameters of Hibernate HQL queries
Diffstat (limited to 'plugins')
18 files changed, 30 insertions, 27 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ReferenceAnalysis.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ReferenceAnalysis.java index 4a04c1ec810..2f8b31baae5 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ReferenceAnalysis.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ReferenceAnalysis.java @@ -47,9 +47,10 @@ public class ReferenceAnalysis implements BatchExtension { } Snapshot getSnapshot(Resource resource) { - Query query = session.createQuery("from " + Snapshot.class.getSimpleName() + " s where s.last=true and s.resourceId=(select r.id from " + Query query = session.createQuery("from " + Snapshot.class.getSimpleName() + " s where s.last=:last and s.resourceId=(select r.id from " + ResourceModel.class.getSimpleName() + " r where r.key=:key)"); query.setParameter("key", resource.getEffectiveKey()); + query.setParameter("last", Boolean.TRUE); return session.getSingleResult(query, null); } } diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shared.xml b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shared.xml index 90a3f202297..db1849bc7a7 100644 --- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shared.xml +++ b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shared.xml @@ -1,7 +1,7 @@ <dataset> - <rules_categories id="1" name="Efficiency" description="[null]"/> - <rules_categories id="6" name="Usability" description="[null]"/> + <rules_categories id="1" name="Efficiency" description="Efficiency"/> + <rules_categories id="6" name="Usability" description="Usability"/> <rules id="30" name="Check Header" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck" plugin_config_key="Checker/Treewalker/HeaderCheck" plugin_name="checkstyle" description="[null]" priority="4" enabled="true" diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shouldCopyPermanentIdFromReferenceViolation-result.xml b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shouldCopyPermanentIdFromReferenceViolation-result.xml index fc52aa2bd62..1366055ebce 100644 --- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shouldCopyPermanentIdFromReferenceViolation-result.xml +++ b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shouldCopyPermanentIdFromReferenceViolation-result.xml @@ -1,7 +1,7 @@ <dataset> - <rules_categories id="1" name="Efficiency" description="[null]"/> - <rules_categories id="6" name="Usability" description="[null]"/> + <rules_categories id="1" name="Efficiency" description="Efficiency"/> + <rules_categories id="6" name="Usability" description="Usability"/> <rules id="30" name="Check Header" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck" plugin_config_key="Checker/Treewalker/HeaderCheck" plugin_name="checkstyle" description="[null]" priority="4" enabled="true" diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shouldSaveViolations-result.xml b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shouldSaveViolations-result.xml index 726b925bf12..cdb569bd223 100644 --- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shouldSaveViolations-result.xml +++ b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shouldSaveViolations-result.xml @@ -1,6 +1,6 @@ <dataset> - <rules_categories id="1" name="Efficiency" description="[null]"/> - <rules_categories id="6" name="Usability" description="[null]"/> + <rules_categories id="1" name="Efficiency" description="Efficiency"/> + <rules_categories id="6" name="Usability" description="Usability"/> <rules id="30" name="Check Header" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck" plugin_config_key="Checker/Treewalker/HeaderCheck" plugin_name="checkstyle" description="[null]" priority="4" enabled="true" 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); diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots-result.xml index 942c65bc81e..f3237cc3c84 100644 --- a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots-result.xml +++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots-result.xml @@ -1,5 +1,5 @@ <dataset> - <rules_categories id="1" name="category one" description="[null]"/> + <rules_categories id="1" name="category one" description="one"/> <rules id="1" name="foo" plugin_config_key="checker/foo" plugin_rule_key="checkstyle.rule1" plugin_name="maven-checkstyle-plugin" description="description" cardinality="SINGLE" parent_id="[null]" /> diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots.xml index 4f75f336d60..f8b8bdee5e2 100644 --- a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots.xml +++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots.xml @@ -1,5 +1,5 @@ <dataset> - <rules_categories id="1" name="category one" description="[null]"/> + <rules_categories id="1" name="category one" description="one"/> <rules id="1" name="foo" plugin_config_key="checker/foo" plugin_rule_key="checkstyle.rule1" plugin_name="maven-checkstyle-plugin" description="description" cardinality="SINGLE" parent_id="[null]"/> diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResourcesTest/sharedFixture.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResourcesTest/sharedFixture.xml index d11bd33fdd1..d2031ec398f 100644 --- a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResourcesTest/sharedFixture.xml +++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResourcesTest/sharedFixture.xml @@ -1,5 +1,5 @@ <dataset> - <rules_categories id="1" name="category one" description="[null]"/> + <rules_categories id="1" name="category one" description="one"/> <rules id="1" name="foo" plugin_config_key="checker/foo" plugin_rule_key="checkstyle.rule1" plugin_name="maven-checkstyle-plugin" description="description" cardinality="SINGLE" parent_id="[null]"/> diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLastTest/sharedFixture.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLastTest/sharedFixture.xml index d11bd33fdd1..d2031ec398f 100644 --- a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLastTest/sharedFixture.xml +++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLastTest/sharedFixture.xml @@ -1,5 +1,5 @@ <dataset> - <rules_categories id="1" name="category one" description="[null]"/> + <rules_categories id="1" name="category one" description="one"/> <rules id="1" name="foo" plugin_config_key="checker/foo" plugin_rule_key="checkstyle.rule1" plugin_name="maven-checkstyle-plugin" description="description" cardinality="SINGLE" parent_id="[null]"/> diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/sharedFixture.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/sharedFixture.xml index d79d906a17d..6ee23b42083 100644 --- a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/sharedFixture.xml +++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/sharedFixture.xml @@ -1,5 +1,5 @@ <dataset> - <rules_categories id="1" name="category one" description="[null]"/> + <rules_categories id="1" name="category one" description="one"/> <rules id="1" name="foo" plugin_config_key="checker/foo" plugin_rule_key="checkstyle.rule1" plugin_name="maven-checkstyle-plugin" description="description" cardinality="SINGLE" parent_id="[null]"/> diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEntitiesTest/sharedFixture.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEntitiesTest/sharedFixture.xml index d11bd33fdd1..d2031ec398f 100644 --- a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEntitiesTest/sharedFixture.xml +++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEntitiesTest/sharedFixture.xml @@ -1,5 +1,5 @@ <dataset> - <rules_categories id="1" name="category one" description="[null]"/> + <rules_categories id="1" name="category one" description="one"/> <rules id="1" name="foo" plugin_config_key="checker/foo" plugin_rule_key="checkstyle.rule1" plugin_name="maven-checkstyle-plugin" description="description" cardinality="SINGLE" parent_id="[null]"/> diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasuresTest/sharedFixture.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasuresTest/sharedFixture.xml index d65258e2be5..46b5a77133b 100644 --- a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasuresTest/sharedFixture.xml +++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasuresTest/sharedFixture.xml @@ -1,5 +1,5 @@ <dataset> - <rules_categories id="1" name="category one" description="[null]"/> + <rules_categories id="1" name="category one" description="one"/> <rules id="1" name="foo" plugin_config_key="checker/foo" plugin_rule_key="checkstyle.rule1" plugin_name="maven-checkstyle-plugin" description="description" cardinality="SINGLE" parent_id="[null]"/> diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessedTest/sharedFixture.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessedTest/sharedFixture.xml index d11bd33fdd1..d2031ec398f 100644 --- a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessedTest/sharedFixture.xml +++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessedTest/sharedFixture.xml @@ -1,5 +1,5 @@ <dataset> - <rules_categories id="1" name="category one" description="[null]"/> + <rules_categories id="1" name="category one" description="one"/> <rules id="1" name="foo" plugin_config_key="checker/foo" plugin_rule_key="checkstyle.rule1" plugin_name="maven-checkstyle-plugin" description="description" cardinality="SINGLE" parent_id="[null]"/> |