aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-07-25 23:53:25 +0400
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-07-26 00:00:59 +0400
commit6acbf886c2cc4b8f6998481e24236b1739ba079a (patch)
treef4cb4b93d8a5897a5a96ebbadce2b0b2b1c73dc6
parent3380cba1de57f48e535de91e0c98c16030a36fa8 (diff)
downloadsonarqube-6acbf886c2cc4b8f6998481e24236b1739ba079a.tar.gz
sonarqube-6acbf886c2cc4b8f6998481e24236b1739ba079a.zip
Fix CloseReviewsDecorator for Derby and move Review entity from sonar-plugin-api to sonar-core
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CloseReviewsDecorator.java12
-rw-r--r--sonar-core/src/main/java/org/sonar/jpa/entity/Review.java (renamed from sonar-plugin-api/src/main/java/org/sonar/api/database/model/Review.java)2
-rw-r--r--sonar-core/src/main/resources/META-INF/persistence.xml2
3 files changed, 10 insertions, 6 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CloseReviewsDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CloseReviewsDecorator.java
index 437db024b2a..6e17f67f66d 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CloseReviewsDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CloseReviewsDecorator.java
@@ -28,7 +28,6 @@ import org.sonar.api.batch.DecoratorBarriers;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.DependsUpon;
import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.Review;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.database.model.User;
import org.sonar.api.notifications.Notification;
@@ -39,6 +38,7 @@ import org.sonar.api.resources.ResourceUtils;
import org.sonar.api.security.UserFinder;
import org.sonar.batch.index.ResourcePersister;
import org.sonar.core.NotDryRun;
+import org.sonar.jpa.entity.Review;
/**
* Decorator that currently only closes a review when its corresponding violation has been fixed.
@@ -117,13 +117,17 @@ public class CloseReviewsDecorator implements Decorator {
protected int closeReviewsForDeletedResources(int projectId, int projectSnapshotId) {
String conditions = " WHERE status!='CLOSED' AND project_id=" + projectId
+ " AND resource_id IN ( SELECT prev.project_id FROM snapshots prev WHERE prev.root_project_id=" + projectId
- + " AND prev.islast=TRUE AND NOT EXISTS ( SELECT cur.id FROM snapshots cur WHERE cur.root_snapshot_id=" + projectSnapshotId
+ + " AND prev.islast=? AND NOT EXISTS ( SELECT cur.id FROM snapshots cur WHERE cur.root_snapshot_id=" + projectSnapshotId
+ " AND cur.created_at > prev.created_at AND cur.root_project_id=" + projectId + " AND cur.project_id=prev.project_id ) )";
- List<Review> reviews = databaseSession.getEntityManager().createNativeQuery("SELECT * FROM reviews " + conditions, Review.class).getResultList();
+ List<Review> reviews = databaseSession.getEntityManager().createNativeQuery("SELECT * FROM reviews " + conditions, Review.class)
+ .setParameter(1, Boolean.TRUE)
+ .getResultList();
for (Review review : reviews) {
notifyClosed(review);
}
- int rowUpdated = databaseSession.createNativeQuery("UPDATE reviews SET status='CLOSED', updated_at=CURRENT_TIMESTAMP" + conditions).executeUpdate();
+ int rowUpdated = databaseSession.createNativeQuery("UPDATE reviews SET status='CLOSED', updated_at=CURRENT_TIMESTAMP" + conditions)
+ .setParameter(1, Boolean.TRUE)
+ .executeUpdate();
LOG.debug("- {} reviews set to 'closed' on project #{}", rowUpdated, projectSnapshotId);
return rowUpdated;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Review.java b/sonar-core/src/main/java/org/sonar/jpa/entity/Review.java
index 927e96a4a8e..81f9f5e595f 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Review.java
+++ b/sonar-core/src/main/java/org/sonar/jpa/entity/Review.java
@@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.api.database.model;
+package org.sonar.jpa.entity;
import java.util.Date;
diff --git a/sonar-core/src/main/resources/META-INF/persistence.xml b/sonar-core/src/main/resources/META-INF/persistence.xml
index f3b022a96a3..4250a8c33a3 100644
--- a/sonar-core/src/main/resources/META-INF/persistence.xml
+++ b/sonar-core/src/main/resources/META-INF/persistence.xml
@@ -34,7 +34,7 @@
<class>org.sonar.api.profiles.Alert</class>
<class>org.sonar.api.rules.ActiveRuleChange</class>
<class>org.sonar.api.rules.ActiveRuleParamChange</class>
- <class>org.sonar.api.database.model.Review</class>
+ <class>org.sonar.jpa.entity.Review</class>
<class>org.sonar.jpa.entity.NotificationQueueElement</class>
<properties>