summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-10-28 14:28:57 +0000
committerGodin <mandrikov@gmail.com>2010-10-28 14:28:57 +0000
commitd7869519b8a56a36617cdcdd4a057398750e1a38 (patch)
tree620f67dbf179737238bbe7080fc0b46f03010348 /plugins
parent8793034838a4c4e54652b5a48466212c02f016d4 (diff)
downloadsonarqube-d7869519b8a56a36617cdcdd4a057398750e1a38.tar.gz
sonarqube-d7869519b8a56a36617cdcdd4a057398750e1a38.zip
SONAR-1837:
* Add profiling logs to database optimization tasks * Extend TimeProfiler to produce logs using debug level
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDeletedResources.java5
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDeprecatedLast.java8
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDisabledResources.java9
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeEntities.java7
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeEventOrphans.java7
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeOrphanResources.java9
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgePropertyOrphans.java11
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeResourceRoles.java9
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeRuleMeasures.java9
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeUnprocessed.java7
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/UnflagLastDoublons.java6
11 files changed, 48 insertions, 39 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDeletedResources.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDeletedResources.java
index 63136a6086b..fff6b0101ac 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDeletedResources.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDeletedResources.java
@@ -19,13 +19,14 @@
*/
package org.sonar.plugins.core.purges;
-import org.sonar.core.purge.AbstractPurge;
import org.sonar.api.batch.PurgeContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.database.model.Snapshot;
+import org.sonar.core.purge.AbstractPurge;
import java.util.List;
+
import javax.persistence.Query;
/**
@@ -40,7 +41,7 @@ public class PurgeDeletedResources extends AbstractPurge {
public void purge(PurgeContext context) {
Query query = getSession().createQuery("SELECT s.id FROM " + Snapshot.class.getSimpleName() +
" s WHERE NOT EXISTS(FROM " + ResourceModel.class.getSimpleName() + " r WHERE r.id=s.resourceId)");
- final List<Integer> snapshotIds = query.getResultList();
+ final List<Integer> snapshotIds = selectIds(query);
deleteSnapshotData(snapshotIds);
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDeprecatedLast.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDeprecatedLast.java
index 4e8c6a64c16..bf8e44a7f02 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDeprecatedLast.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDeprecatedLast.java
@@ -19,14 +19,15 @@
*/
package org.sonar.plugins.core.purges;
-import org.sonar.core.purge.AbstractPurge;
import org.sonar.api.batch.PurgeContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
+import org.sonar.core.purge.AbstractPurge;
-import javax.persistence.Query;
import java.util.List;
+import javax.persistence.Query;
+
/**
* @since 1.11
*/
@@ -39,9 +40,8 @@ public class PurgeDeprecatedLast extends AbstractPurge {
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)");
- List<Integer> snapshotIds = query.getResultList();
+ List<Integer> snapshotIds = selectIds(query);
deleteSnapshotData(snapshotIds);
}
}
-
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDisabledResources.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDisabledResources.java
index bf1b571f469..f9cd5de642b 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDisabledResources.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDisabledResources.java
@@ -19,13 +19,14 @@
*/
package org.sonar.plugins.core.purges;
-import org.sonar.core.purge.AbstractPurge;
import org.sonar.api.batch.PurgeContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.database.model.Snapshot;
+import org.sonar.core.purge.AbstractPurge;
import java.util.List;
+
import javax.persistence.Query;
/**
@@ -44,19 +45,19 @@ public class PurgeDisabledResources extends AbstractPurge {
private void deleteResources() {
final List<Integer> resourceIds = getResourceIds();
- if (!resourceIds.isEmpty()) {
+ if ( !resourceIds.isEmpty()) {
executeQuery(resourceIds, "delete from " + ResourceModel.class.getSimpleName() + " r where r.id in (:ids)");
}
}
private List<Integer> getResourceIds() {
Query query = getSession().createQuery("SELECT r.id FROM " + ResourceModel.class.getSimpleName() + " r WHERE r.enabled=false");
- return (List<Integer>) query.getResultList();
+ return selectIds(query);
}
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)");
- return (List<Integer>) query.getResultList();
+ return selectIds(query);
}
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeEntities.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeEntities.java
index 88b13381903..ccd03543a33 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeEntities.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeEntities.java
@@ -20,16 +20,17 @@
package org.sonar.plugins.core.purges;
import org.apache.commons.lang.time.DateUtils;
-import org.sonar.core.purge.AbstractPurge;
import org.sonar.api.batch.PurgeContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Resource;
+import org.sonar.core.purge.AbstractPurge;
-import javax.persistence.Query;
import java.util.Date;
import java.util.List;
+import javax.persistence.Query;
+
/**
* @since 1.11
*/
@@ -46,7 +47,7 @@ public class PurgeEntities extends AbstractPurge {
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.setParameter("date", beforeDate);
- List<Integer> snapshotIds = query.getResultList();
+ List<Integer> snapshotIds = selectIds(query);
deleteSnapshotData(snapshotIds);
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeEventOrphans.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeEventOrphans.java
index d98c17effa9..8132b19af2f 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeEventOrphans.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeEventOrphans.java
@@ -19,15 +19,16 @@
*/
package org.sonar.plugins.core.purges;
-import org.sonar.core.purge.AbstractPurge;
import org.sonar.api.batch.Event;
import org.sonar.api.batch.PurgeContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
+import org.sonar.core.purge.AbstractPurge;
-import javax.persistence.Query;
import java.util.List;
+import javax.persistence.Query;
+
public class PurgeEventOrphans extends AbstractPurge {
public PurgeEventOrphans(DatabaseSession session) {
@@ -37,7 +38,7 @@ public class PurgeEventOrphans extends AbstractPurge {
public void purge(PurgeContext context) {
Query query = getSession().createQuery("SELECT e.id FROM " + Event.class.getSimpleName() +
" e WHERE e.resourceId IS NOT NULL AND NOT EXISTS(FROM " + ResourceModel.class.getSimpleName() + " r WHERE r.id=e.resourceId)");
- final List<Integer> eventIds = query.getResultList();
+ final List<Integer> eventIds = selectIds(query);
executeQuery(eventIds, "DELETE FROM " + Event.class.getSimpleName() + " WHERE id in (:ids)");
}
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeOrphanResources.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeOrphanResources.java
index bc720f8fcf0..3552bf9018a 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeOrphanResources.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeOrphanResources.java
@@ -19,14 +19,15 @@
*/
package org.sonar.plugins.core.purges;
-import org.sonar.core.purge.AbstractPurge;
import org.sonar.api.batch.PurgeContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
+import org.sonar.core.purge.AbstractPurge;
-import javax.persistence.Query;
import java.util.List;
+import javax.persistence.Query;
+
/**
* @since 2.1
*/
@@ -39,9 +40,9 @@ public class PurgeOrphanResources extends AbstractPurge {
public void purge(PurgeContext context) {
Query query = getSession().createQuery("SELECT r1.id FROM " + ResourceModel.class.getSimpleName() +
" r1 WHERE r1.rootId IS NOT NULL AND NOT EXISTS(FROM " + ResourceModel.class.getSimpleName() + " r2 WHERE r1.rootId=r2.id)");
- List<Integer> idsToDelete = query.getResultList();
+ List<Integer> idsToDelete = selectIds(query);
if (idsToDelete.size() > 0) {
executeQuery(idsToDelete, "DELETE FROM " + ResourceModel.class.getSimpleName() + " WHERE id in (:ids)");
}
}
-} \ No newline at end of file
+}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgePropertyOrphans.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgePropertyOrphans.java
index e809dc2670c..4cbd3e423b6 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgePropertyOrphans.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgePropertyOrphans.java
@@ -19,16 +19,17 @@
*/
package org.sonar.plugins.core.purges;
-import org.sonar.core.purge.AbstractPurge;
import org.sonar.api.batch.PurgeContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.configuration.Property;
import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.database.model.User;
+import org.sonar.core.purge.AbstractPurge;
-import javax.persistence.Query;
import java.util.List;
+import javax.persistence.Query;
+
/**
* @since 2.2
*/
@@ -46,7 +47,7 @@ public class PurgePropertyOrphans extends AbstractPurge {
void purgeResourceOrphans() {
Query query = getSession().createQuery("SELECT p.id FROM " + Property.class.getSimpleName() +
" p WHERE p.resourceId IS NOT NULL AND NOT EXISTS(FROM " + ResourceModel.class.getSimpleName() + " r WHERE r.id=p.resourceId)");
- List<Integer> idsToDelete = query.getResultList();
+ List<Integer> idsToDelete = selectIds(query);
if (idsToDelete.size() > 0) {
executeQuery(idsToDelete, "DELETE FROM " + Property.class.getSimpleName() + " WHERE id in (:ids)");
}
@@ -55,9 +56,9 @@ public class PurgePropertyOrphans extends AbstractPurge {
void purgeUserOrphans() {
Query query = getSession().createQuery("SELECT p.id FROM " + Property.class.getSimpleName() +
" p WHERE p.userId IS NOT NULL AND NOT EXISTS(FROM " + User.class.getSimpleName() + " u WHERE u.id=p.userId)");
- List<Integer> idsToDelete = query.getResultList();
+ List<Integer> idsToDelete = selectIds(query);
if (idsToDelete.size() > 0) {
executeQuery(idsToDelete, "DELETE FROM " + Property.class.getSimpleName() + " WHERE id in (:ids)");
}
}
-} \ No newline at end of file
+}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeResourceRoles.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeResourceRoles.java
index 909301cc992..b29d0d25fef 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeResourceRoles.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeResourceRoles.java
@@ -19,16 +19,17 @@
*/
package org.sonar.plugins.core.purges;
-import org.sonar.core.purge.AbstractPurge;
import org.sonar.api.batch.PurgeContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.security.GroupRole;
import org.sonar.api.security.UserRole;
+import org.sonar.core.purge.AbstractPurge;
-import javax.persistence.Query;
import java.util.List;
+import javax.persistence.Query;
+
/**
* @since 1.12
*/
@@ -46,8 +47,8 @@ public class PurgeResourceRoles extends AbstractPurge {
private void deleteRoles(String classname) {
Query query = getSession().createQuery("SELECT rol.id FROM " + classname + " rol "
+ " WHERE rol.resourceId IS NOT NULL AND NOT EXISTS(FROM " + ResourceModel.class.getSimpleName() + " r WHERE r.id=rol.resourceId)");
- List<Integer> roleIds = (List<Integer>) query.getResultList();
- if (!roleIds.isEmpty()) {
+ List<Integer> roleIds = selectIds(query);
+ if ( !roleIds.isEmpty()) {
executeQuery(roleIds, "delete from " + classname + " rol where rol.id in (:ids)");
}
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeRuleMeasures.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeRuleMeasures.java
index f2afd3b4b52..50c42189cda 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeRuleMeasures.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeRuleMeasures.java
@@ -19,18 +19,19 @@
*/
package org.sonar.plugins.core.purges;
-import org.sonar.core.purge.AbstractPurge;
import org.sonar.api.batch.PurgeContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.MeasureModel;
import org.sonar.api.database.model.Snapshot;
+import org.sonar.core.purge.AbstractPurge;
-import javax.persistence.Query;
import java.util.List;
+import javax.persistence.Query;
+
/**
* see SONAR-522
- *
+ *
* @since 1.11
*/
public class PurgeRuleMeasures extends AbstractPurge {
@@ -49,7 +50,7 @@ public class PurgeRuleMeasures extends AbstractPurge {
Query query = getSession().createQuery("SELECT m.id FROM " + MeasureModel.class.getSimpleName() + " m, " + Snapshot.class.getSimpleName() + " s WHERE s.id = m.snapshotId and " +
"(s.rootId=:rootSid OR s.id=:rootSid) and (m.rule is not null or m.rulesCategoryId is not null or m.rulePriority is not null)");
query.setParameter("rootSid", sid);
- List<Integer> measureIds = query.getResultList();
+ List<Integer> measureIds = selectIds(query);
deleteMeasuresById(measureIds);
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeUnprocessed.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeUnprocessed.java
index 4f4a492f561..08fc2ec5514 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeUnprocessed.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeUnprocessed.java
@@ -20,15 +20,16 @@
package org.sonar.plugins.core.purges;
import org.apache.commons.lang.time.DateUtils;
-import org.sonar.core.purge.AbstractPurge;
import org.sonar.api.batch.PurgeContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
+import org.sonar.core.purge.AbstractPurge;
-import javax.persistence.Query;
import java.util.Date;
import java.util.List;
+import javax.persistence.Query;
+
/**
* @since 1.11
*/
@@ -45,7 +46,7 @@ public class PurgeUnprocessed extends AbstractPurge {
Query query = getSession().createQuery("SELECT s.id FROM " + Snapshot.class.getSimpleName() + " s WHERE s.last=false AND status=:status AND s.createdAt<:date");
query.setParameter("status", Snapshot.STATUS_UNPROCESSED);
query.setParameter("date", beforeDate);
- List<Integer> snapshotIds = query.getResultList();
+ List<Integer> snapshotIds = selectIds(query);
deleteSnapshotData(snapshotIds);
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/UnflagLastDoublons.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/UnflagLastDoublons.java
index da3c7a61202..b72ffcb818c 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/UnflagLastDoublons.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/UnflagLastDoublons.java
@@ -24,9 +24,10 @@ import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
import org.sonar.core.purge.AbstractPurge;
-import javax.persistence.Query;
import java.util.List;
+import javax.persistence.Query;
+
/**
* @since 1.11
*/
@@ -40,9 +41,8 @@ public class UnflagLastDoublons extends AbstractPurge {
Query query = getSession().createQuery(
"SELECT olds.id FROM " + Snapshot.class.getSimpleName() + " olds " +
" where olds.last=true AND EXISTS (from " + Snapshot.class.getSimpleName() + " news WHERE news.last=true AND news.resourceId=olds.resourceId AND news.createdAt>olds.createdAt)");
- List<Integer> snapshotIds = query.getResultList();
+ List<Integer> snapshotIds = selectIds(query);
executeQuery(snapshotIds, "UPDATE " + Snapshot.class.getSimpleName() + " SET last=false WHERE id in (:ids)");
}
}
-