aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-07-12 10:05:02 +0200
committerDavid Gageot <david@gageot.net>2012-07-12 10:05:11 +0200
commit7e59c12b5c8b65e0c44e3f70b38f01eae5cade15 (patch)
tree042ab592091527df2497ea63a18f943d06d1502c /sonar-core
parenta8b40677a72848ce94d437d4943674ad99f8b065 (diff)
downloadsonarqube-7e59c12b5c8b65e0c44e3f70b38f01eae5cade15.tar.gz
sonarqube-7e59c12b5c8b65e0c44e3f70b38f01eae5cade15.zip
Merge PurgeMapper and PurgeVendorMapper with new MyBatis mechanism
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java3
-rw-r--r--sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java10
-rw-r--r--sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/purge/PurgeVendorMapper.java32
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml33
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/purge/PurgeVendorMapper-mssql.xml19
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/purge/PurgeVendorMapper-mysql.xml15
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/purge/PurgeVendorMapper.xml17
9 files changed, 43 insertions, 92 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
index 4b0e85edf99..543f8f0f31a 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
@@ -61,7 +61,6 @@ import org.sonar.core.filter.FilterMapper;
import org.sonar.core.properties.PropertiesMapper;
import org.sonar.core.properties.PropertyDto;
import org.sonar.core.purge.PurgeMapper;
-import org.sonar.core.purge.PurgeVendorMapper;
import org.sonar.core.purge.PurgeableSnapshotDto;
import org.sonar.core.resource.ResourceDto;
import org.sonar.core.resource.ResourceIndexDto;
@@ -141,7 +140,7 @@ public class MyBatis implements BatchComponent, ServerComponent {
loadAlias(conf, "MeasureModel", MeasureModel.class);
Class<?>[] mappers = {ActiveDashboardMapper.class, AuthorMapper.class, FilterMapper.class, CriterionMapper.class, FilterColumnMapper.class, DashboardMapper.class,
- DependencyMapper.class, DuplicationMapper.class, LoadedTemplateMapper.class, PropertiesMapper.class, PurgeMapper.class, PurgeVendorMapper.class,
+ DependencyMapper.class, DuplicationMapper.class, LoadedTemplateMapper.class, PropertiesMapper.class, PurgeMapper.class,
ResourceKeyUpdaterMapper.class, ResourceIndexerMapper.class, ResourceMapper.class, ResourceSnapshotMapper.class, ReviewCommentMapper.class,
ReviewMapper.class, RoleMapper.class, RuleMapper.class, SchemaMigrationMapper.class, UserMapper.class, WidgetMapper.class, WidgetPropertyMapper.class,
MeasureMapper.class};
diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java
index 405770b658c..7e670362182 100644
--- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java
+++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java
@@ -27,17 +27,15 @@ import java.util.List;
class PurgeCommands {
private final SqlSession session;
private final PurgeMapper purgeMapper;
- private final PurgeVendorMapper purgeVendorMapper;
- PurgeCommands(SqlSession session, PurgeMapper purgeMapper, PurgeVendorMapper purgeVendorMapper) {
+ PurgeCommands(SqlSession session, PurgeMapper purgeMapper) {
this.session = session;
this.purgeMapper = purgeMapper;
- this.purgeVendorMapper = purgeVendorMapper;
}
@VisibleForTesting
PurgeCommands(SqlSession session) {
- this(session, session.getMapper(PurgeMapper.class), session.getMapper(PurgeVendorMapper.class));
+ this(session, session.getMapper(PurgeMapper.class));
}
List<Long> selectSnapshotIds(PurgeSnapshotQuery query) {
@@ -86,12 +84,12 @@ class PurgeCommands {
session.commit();
for (Long resourceId : resourceIds) {
- purgeVendorMapper.deleteResourceReviewComments(resourceId);
+ purgeMapper.deleteResourceReviewComments(resourceId);
}
session.commit();
for (Long resourceId : resourceIds) {
- purgeVendorMapper.deleteResourceActionPlansReviews(resourceId);
+ purgeMapper.deleteResourceActionPlansReviews(resourceId);
}
session.commit();
diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java
index 73b1487a330..56c09193bac 100644
--- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java
@@ -50,7 +50,7 @@ public class PurgeDao {
public PurgeDao purge(long rootResourceId, String[] scopesWithoutHistoricalData) {
SqlSession session = mybatis.openBatchSession();
PurgeMapper purgeMapper = session.getMapper(PurgeMapper.class);
- PurgeCommands commands = new PurgeCommands(session, purgeMapper, session.getMapper(PurgeVendorMapper.class));
+ PurgeCommands commands = new PurgeCommands(session, purgeMapper);
try {
List<ResourceDto> projects = getProjects(rootResourceId, session);
for (ResourceDto project : projects) {
diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java
index 451b45329f1..3dedc06b3f0 100644
--- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java
@@ -90,4 +90,8 @@ public interface PurgeMapper {
List<PurgeableSnapshotDto> selectPurgeableSnapshotsWithoutEvents(long resourceId);
List<Long> selectResourceIdsByRootId(long rootProjectId);
+
+ void deleteResourceReviewComments(long resourceId);
+
+ void deleteResourceActionPlansReviews(long resourceId);
}
diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeVendorMapper.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeVendorMapper.java
deleted file mode 100644
index 2187bb01eba..00000000000
--- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeVendorMapper.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.purge;
-
-/**
- * Purge requests that are specific to database vendors. They are extracted from PurgeMapper
- * as long as MyBatis does not support multiple databases in the same XML file.
- *
- * See code.google.com/p/mybatis/issues/detail?id=21
- */
-public interface PurgeVendorMapper {
- void deleteResourceReviewComments(long resourceId);
-
- void deleteResourceActionPlansReviews(long resourceId);
-}
diff --git a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml
index eae4bdc11b9..33975927cc1 100644
--- a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml
@@ -194,5 +194,38 @@
<update id="setSnapshotIsLastToFalse" parameterType="long">
update snapshots set islast=${_false} where project_id=#{id}
</update>
+
+ <delete id="deleteResourceReviewComments" parameterType="long">
+ delete from review_comments rc where exists (select * from reviews r where rc.review_id=r.id and
+ r.resource_id=#{id})
+ </delete>
+
+ <delete id="deleteResourceActionPlansReviews" parameterType="long">
+ delete from action_plans_reviews apr where exists (select * from action_plans ap where ap.id=apr.action_plan_id and
+ ap.project_id=#{id})
+ </delete>
+
+ <!-- Mssql -->
+ <delete id="deleteResourceReviewComments" databaseId="mssql" parameterType="long">
+ delete review_comments from review_comments
+ inner join reviews on review_comments.review_id=reviews.id
+ where reviews.resource_id=#{id}
+ </delete>
+
+ <delete id="deleteResourceActionPlansReviews" databaseId="mssql" parameterType="long">
+ delete action_plans_reviews from action_plans_reviews
+ inner join action_plans on action_plans.id=action_plans_reviews.action_plan_id
+ where action_plans.project_id=#{id}
+ </delete>
+
+ <!-- Mysql -->
+ <delete id="deleteResourceReviewComments" databaseId="mysql" parameterType="long">
+ delete rc from review_comments as rc, reviews as r where rc.review_id=r.id and r.resource_id=#{id}
+ </delete>
+
+ <delete id="deleteResourceActionPlansReviews" databaseId="mysql" parameterType="long">
+ delete apr from action_plans_reviews as apr, action_plans as ap where ap.id=apr.action_plan_id and ap.project_id=#{id}
+ </delete>
+
</mapper>
diff --git a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeVendorMapper-mssql.xml b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeVendorMapper-mssql.xml
deleted file mode 100644
index b47bf4f3213..00000000000
--- a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeVendorMapper-mssql.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.core.purge.PurgeVendorMapper">
-
- <delete id="deleteResourceReviewComments" parameterType="long">
- delete review_comments from review_comments
- inner join reviews on review_comments.review_id=reviews.id
- where reviews.resource_id=#{id}
- </delete>
-
- <delete id="deleteResourceActionPlansReviews" parameterType="long">
- delete action_plans_reviews from action_plans_reviews
- inner join action_plans on action_plans.id=action_plans_reviews.action_plan_id
- where action_plans.project_id=#{id}
- </delete>
-
-</mapper>
-
diff --git a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeVendorMapper-mysql.xml b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeVendorMapper-mysql.xml
deleted file mode 100644
index 69578003f58..00000000000
--- a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeVendorMapper-mysql.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.core.purge.PurgeVendorMapper">
-
- <delete id="deleteResourceReviewComments" parameterType="long">
- delete rc from review_comments as rc, reviews as r where rc.review_id=r.id and r.resource_id=#{id}
- </delete>
-
- <delete id="deleteResourceActionPlansReviews" parameterType="long">
- delete apr from action_plans_reviews as apr, action_plans as ap where ap.id=apr.action_plan_id and ap.project_id=#{id}
- </delete>
-
-</mapper>
-
diff --git a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeVendorMapper.xml b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeVendorMapper.xml
deleted file mode 100644
index 698f648150e..00000000000
--- a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeVendorMapper.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.core.purge.PurgeVendorMapper">
-
- <delete id="deleteResourceReviewComments" parameterType="long">
- delete from review_comments rc where exists (select * from reviews r where rc.review_id=r.id and
- r.resource_id=#{id})
- </delete>
-
- <delete id="deleteResourceActionPlansReviews" parameterType="long">
- delete from action_plans_reviews apr where exists (select * from action_plans ap where ap.id=apr.action_plan_id and
- ap.project_id=#{id})
- </delete>
-
-</mapper>
-