]> source.dussan.org Git - sonarqube.git/commitdiff
Merge PurgeMapper and PurgeVendorMapper with new MyBatis mechanism
authorDavid Gageot <david@gageot.net>
Thu, 12 Jul 2012 08:05:02 +0000 (10:05 +0200)
committerDavid Gageot <david@gageot.net>
Thu, 12 Jul 2012 08:05:11 +0000 (10:05 +0200)
sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java
sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java
sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java
sonar-core/src/main/java/org/sonar/core/purge/PurgeVendorMapper.java [deleted file]
sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml
sonar-core/src/main/resources/org/sonar/core/purge/PurgeVendorMapper-mssql.xml [deleted file]
sonar-core/src/main/resources/org/sonar/core/purge/PurgeVendorMapper-mysql.xml [deleted file]
sonar-core/src/main/resources/org/sonar/core/purge/PurgeVendorMapper.xml [deleted file]

index 4b0e85edf99c6ff71ce2b38fbe13def7fd526d42..543f8f0f31a32d2698e3271c6e557d921c724176 100644 (file)
@@ -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};
index 405770b658c79cc9f54b9f0760b97344287bff98..7e670362182923a72bf0721a5fad02c6d315010f 100644 (file)
@@ -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();
 
index 73b1487a330130eb8e11917619b8bb783110e4d1..56c09193bac304225f6d83d7edd752d88e832ad1 100644 (file)
@@ -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) {
index 451b45329f1e64b545e7712937164b159bd76f3a..3dedc06b3f08aee0d8345fc71763791bc2e63ae6 100644 (file)
@@ -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 (file)
index 2187bb0..0000000
+++ /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);
-}
index eae4bdc11b9125d6e6de205ad444f4ceffbf323c..33975927cc12e171a7ce1bc78c680b4f09b221ea 100644 (file)
   <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 (file)
index b47bf4f..0000000
+++ /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 (file)
index 6957800..0000000
+++ /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 (file)
index 698f648..0000000
+++ /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>
-