]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3120 Resources associated to a module which has been removed from a multi-modul...
authorSimon Brandhof <simon.brandhof@gmail.com>
Tue, 14 Feb 2012 06:30:34 +0000 (07:30 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Tue, 14 Feb 2012 06:30:46 +0000 (07:30 +0100)
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DefaultPurgeTask.java
plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DefaultPurgeTaskTest.java
sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.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 [new file with mode: 0644]
sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml
sonar-core/src/main/resources/org/sonar/core/purge/PurgeVendorMapper.xml [new file with mode: 0644]
sonar-core/src/main/resources/org/sonar/core/purge/PurgeVendorMapper_mysql.xml [new file with mode: 0644]
sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java

index 08a3c64ddec1e737dd5375b43568bec20c4c783a..8ccad6d0c5dade63fbf2fb4360c3ed926b1fa8fb 100644 (file)
@@ -26,7 +26,6 @@ import org.sonar.api.Property;
 import org.sonar.api.config.Settings;
 import org.sonar.api.resources.Scopes;
 import org.sonar.core.purge.PurgeDao;
-import org.sonar.core.purge.PurgeSnapshotQuery;
 import org.sonar.plugins.dbcleaner.api.DbCleanerConstants;
 import org.sonar.plugins.dbcleaner.api.PurgeTask;
 import org.sonar.plugins.dbcleaner.period.DefaultPeriodCleaner;
@@ -53,19 +52,14 @@ public class DefaultPurgeTask implements PurgeTask {
     this.periodCleaner = periodCleaner;
   }
 
-  public PurgeTask purgeProject(long projectId) {
-    cleanHistoricalData(projectId);
-    deleteAbortedBuilds(projectId);
-    deleteFileHistory(projectId);
-    if (settings.getBoolean(DbCleanerConstants.PROPERTY_CLEAN_DIRECTORY)) {
-      deleteDirectoryHistory(projectId);
-    }
-    purgeProjectResources(projectId);
+  public PurgeTask deleteProject(long projectId) {
+    purgeDao.deleteProject(projectId);
     return this;
   }
 
-  public PurgeTask deleteProject(long projectId) {
-    purgeDao.deleteProject(projectId);
+  public PurgeTask purgeProject(long projectId) {
+    cleanHistoricalData(projectId);
+    doPurgeProject(projectId);
     return this;
   }
 
@@ -79,55 +73,20 @@ public class DefaultPurgeTask implements PurgeTask {
     }
   }
 
-  private void purgeProjectResources(long projectId) {
-    try {
-      LOG.debug("Purge project [id=" + projectId + "]");
-      purgeDao.purgeProject(projectId);
-    } catch (Exception e) {
-      // purge errors must no fail the batch
-      LOG.error("Fail to purge project [id=" + projectId + "]", e);
-    }
-  }
-
-  private void deleteDirectoryHistory(long projectId) {
-    try {
-      LOG.debug("Delete historical data of directories [id=" + projectId + "]");
-      PurgeSnapshotQuery query = PurgeSnapshotQuery.create()
-        .setRootProjectId(projectId)
-        .setIslast(false)
-        .setScopes(new String[]{Scopes.DIRECTORY});
-      purgeDao.deleteSnapshots(query);
-    } catch (Exception e) {
-      // purge errors must no fail the batch
-      LOG.error("Fail to delete historical data of directories [id=" + projectId + "]", e);
-    }
-  }
-
-  private void deleteFileHistory(long projectId) {
-    try {
-      LOG.debug("Delete historical data of files [id=" + projectId + "]");
-      PurgeSnapshotQuery query = PurgeSnapshotQuery.create()
-        .setRootProjectId(projectId)
-        .setIslast(false)
-        .setScopes(new String[]{Scopes.FILE});
-      purgeDao.deleteSnapshots(query);
-    } catch (Exception e) {
-      // purge errors must no fail the batch
-      LOG.error("Fail to delete historical data of files [id=" + projectId + "]", e);
+  private String[] getScopesWithoutHistoricalData() {
+    if (settings.getBoolean(DbCleanerConstants.PROPERTY_CLEAN_DIRECTORY)) {
+      return new String[]{Scopes.DIRECTORY, Scopes.FILE};
     }
+    return new String[]{Scopes.FILE};
   }
 
-  private void deleteAbortedBuilds(long projectId) {
+  private void doPurgeProject(long projectId) {
     try {
-      LOG.debug("Delete aborted builds [id=" + projectId + "]");
-      PurgeSnapshotQuery query = PurgeSnapshotQuery.create()
-        .setRootProjectId(projectId)
-        .setIslast(false)
-        .setStatus(new String[]{"U"});
-      purgeDao.deleteSnapshots(query);
+      LOG.debug("Purge project [id=" + projectId + "]");
+      purgeDao.purgeProject(projectId, getScopesWithoutHistoricalData());
     } catch (Exception e) {
       // purge errors must no fail the batch
-      LOG.error("Fail to delete historical aborted builds [id=" + projectId + "]", e);
+      LOG.error("Fail to purge project [id=" + projectId + "]", e);
     }
   }
 }
index 51dee76ba54395cc02e76dbe5f2700fdb33028ba..4aa4fa4dd9f3b453e74b19fd862abccc66fff7bc 100644 (file)
  */
 package org.sonar.plugins.dbcleaner;
 
-import org.apache.commons.lang.ArrayUtils;
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
 import org.junit.Test;
 import org.sonar.api.config.PropertyDefinitions;
 import org.sonar.api.config.Settings;
+import org.sonar.api.resources.Scopes;
 import org.sonar.core.purge.PurgeDao;
-import org.sonar.core.purge.PurgeSnapshotQuery;
 import org.sonar.plugins.dbcleaner.api.DbCleanerConstants;
 import org.sonar.plugins.dbcleaner.period.DefaultPeriodCleaner;
 
@@ -42,7 +39,7 @@ public class DefaultPurgeTaskTest {
 
     task.purgeProject(1L);
 
-    verify(purgeDao, never()).deleteSnapshots(argThat(newDirectoryQueryMatcher()));
+    verify(purgeDao).purgeProject(1L, new String[]{Scopes.FILE});
   }
 
   @Test
@@ -53,29 +50,17 @@ public class DefaultPurgeTaskTest {
 
     task.purgeProject(1L);
 
-    verify(purgeDao, times(1)).deleteSnapshots(argThat(newDirectoryQueryMatcher()));
+    verify(purgeDao).purgeProject(1L, new String[]{Scopes.DIRECTORY, Scopes.FILE});
   }
 
   @Test
   public void shouldNotFailOnErrors() {
     PurgeDao purgeDao = mock(PurgeDao.class);
-    when(purgeDao.purgeProject(anyLong())).thenThrow(new RuntimeException());
+    when(purgeDao.purgeProject(anyLong(), (String[]) any())).thenThrow(new RuntimeException());
     DefaultPurgeTask task = new DefaultPurgeTask(purgeDao, new Settings(), mock(DefaultPeriodCleaner.class));
 
     task.purgeProject(1L);
 
-    verify(purgeDao).purgeProject(anyLong());
-  }
-
-  private BaseMatcher<PurgeSnapshotQuery> newDirectoryQueryMatcher() {
-    return new BaseMatcher<PurgeSnapshotQuery>() {
-      public boolean matches(Object o) {
-        return ArrayUtils.contains(((PurgeSnapshotQuery) o).getScopes(), "DIR");
-      }
-
-      public void describeTo(Description description) {
-        description.appendText("Query on scope DIR");
-      }
-    };
+    verify(purgeDao).purgeProject(anyLong(), (String[]) any());
   }
 }
index 3629a399df32ea7d5ba886f7fe4a93fe7eba47c5..073fda4048e09b63eb9b8ccaec7cbe6ba8dec38c 100644 (file)
  */
 package org.sonar.core.persistence;
 
-import java.io.IOException;
-import java.io.InputStream;
-
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.ibatis.builder.xml.XMLMapperBuilder;
 import org.apache.ibatis.logging.LogFactory;
 import org.apache.ibatis.mapping.Environment;
-import org.apache.ibatis.session.Configuration;
-import org.apache.ibatis.session.ExecutorType;
-import org.apache.ibatis.session.SqlSession;
-import org.apache.ibatis.session.SqlSessionFactory;
-import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+import org.apache.ibatis.session.*;
 import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.BatchComponent;
 import org.sonar.api.ServerComponent;
-import org.sonar.core.dashboard.ActiveDashboardDto;
-import org.sonar.core.dashboard.ActiveDashboardMapper;
-import org.sonar.core.dashboard.DashboardDto;
-import org.sonar.core.dashboard.DashboardMapper;
-import org.sonar.core.dashboard.WidgetDto;
-import org.sonar.core.dashboard.WidgetMapper;
-import org.sonar.core.dashboard.WidgetPropertyDto;
-import org.sonar.core.dashboard.WidgetPropertyMapper;
+import org.sonar.core.dashboard.*;
 import org.sonar.core.duplication.DuplicationMapper;
 import org.sonar.core.duplication.DuplicationUnitDto;
 import org.sonar.core.properties.PropertiesMapper;
 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;
-import org.sonar.core.resource.ResourceIndexerMapper;
-import org.sonar.core.resource.ResourceMapper;
-import org.sonar.core.resource.SnapshotDto;
+import org.sonar.core.resource.*;
 import org.sonar.core.review.ReviewDto;
 import org.sonar.core.review.ReviewMapper;
 import org.sonar.core.rule.RuleDto;
@@ -61,6 +44,9 @@ import org.sonar.core.rule.RuleMapper;
 import org.sonar.core.template.LoadedTemplateDto;
 import org.sonar.core.template.LoadedTemplateMapper;
 
+import java.io.IOException;
+import java.io.InputStream;
+
 public class MyBatis implements BatchComponent, ServerComponent {
 
   private Database database;
@@ -98,6 +84,7 @@ public class MyBatis implements BatchComponent, ServerComponent {
     loadMapper(conf, LoadedTemplateMapper.class);
     loadMapper(conf, PropertiesMapper.class);
     loadMapper(conf, PurgeMapper.class);
+    loadMapper(conf, PurgeVendorMapper.class);
     loadMapper(conf, ResourceMapper.class);
     loadMapper(conf, ReviewMapper.class);
     loadMapper(conf, ResourceIndexerMapper.class);
@@ -148,7 +135,7 @@ public class MyBatis implements BatchComponent, ServerComponent {
 
   private InputStream getPathToMapper(Class mapperClass) {
     InputStream input = getClass().getResourceAsStream(
-        "/" + StringUtils.replace(mapperClass.getName(), ".", "/") + "-" + database.getDialect().getId() + ".xml");
+      "/" + StringUtils.replace(mapperClass.getName(), ".", "/") + "-" + database.getDialect().getId() + ".xml");
     if (input == null) {
       input = getClass().getResourceAsStream("/" + StringUtils.replace(mapperClass.getName(), ".", "/") + ".xml");
     }
index 8a7bbf5f9a554b29121758a5453caba0bae43a35..11933ec79fe5ae9d1998652658ecabfed4a0ba14 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.core.purge;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.Lists;
+import org.apache.commons.lang.ArrayUtils;
 import org.apache.ibatis.session.ResultContext;
 import org.apache.ibatis.session.ResultHandler;
 import org.apache.ibatis.session.SqlSession;
@@ -39,13 +40,14 @@ public class PurgeDao {
     this.resourceDao = resourceDao;
   }
 
-  public PurgeDao purgeProject(long rootProjectId) {
+  public PurgeDao purgeProject(long rootProjectId, String[] scopesWithoutHistoricalData) {
     SqlSession session = mybatis.openBatchSession();
     PurgeMapper purgeMapper = session.getMapper(PurgeMapper.class);
     try {
-      List<Long> projectIds = Lists.newArrayList(rootProjectId);
-      projectIds.addAll(resourceDao.getDescendantProjectIds(rootProjectId, session));
+      List<Long> projectIds = getProjectIds(rootProjectId, session);
       for (Long projectId : projectIds) {
+        deleteAbortedBuilds(projectId, session, purgeMapper);
+        deleteHistoricalData(projectId, scopesWithoutHistoricalData, session, purgeMapper);
         purgeProject(projectId, session, purgeMapper);
       }
 
@@ -58,6 +60,24 @@ public class PurgeDao {
     return this;
   }
 
+  private void deleteAbortedBuilds(Long projectId, SqlSession session, PurgeMapper purgeMapper) {
+    PurgeSnapshotQuery query = PurgeSnapshotQuery.create()
+      .setIslast(false)
+      .setStatus(new String[]{"U"})
+      .setRootProjectId(projectId);
+    deleteSnapshots(query, session, purgeMapper);
+  }
+
+  private void deleteHistoricalData(Long projectId, String[] scopesWithoutHistoricalData, SqlSession session, PurgeMapper purgeMapper) {
+    if (!ArrayUtils.isEmpty(scopesWithoutHistoricalData)) {
+      PurgeSnapshotQuery query = PurgeSnapshotQuery.create()
+        .setIslast(false)
+        .setScopes(scopesWithoutHistoricalData)
+        .setRootProjectId(projectId);
+      deleteSnapshots(query, session, purgeMapper);
+    }
+  }
+
   private void purgeProject(final Long projectId, final SqlSession session, final PurgeMapper purgeMapper) {
     List<Long> projectSnapshotIds = purgeMapper.selectSnapshotIds(PurgeSnapshotQuery.create().setResourceId(projectId).setIslast(false).setNotPurged(true));
     for (final Long projectSnapshotId : projectSnapshotIds) {
@@ -102,37 +122,38 @@ public class PurgeDao {
   public PurgeDao deleteProject(long rootProjectId) {
     final SqlSession session = mybatis.openBatchSession();
     final PurgeMapper mapper = session.getMapper(PurgeMapper.class);
+    final PurgeVendorMapper vendorMapper = session.getMapper(PurgeVendorMapper.class);
     try {
-      deleteProject(rootProjectId, session, mapper);
+      deleteProject(rootProjectId, session, mapper, vendorMapper);
       return this;
     } finally {
       MyBatis.closeQuietly(session);
     }
   }
 
-  private void deleteProject(final long rootProjectId, final SqlSession session, final PurgeMapper mapper) {
+  private void deleteProject(final long rootProjectId, final SqlSession session, final PurgeMapper mapper, final PurgeVendorMapper vendorMapper) {
     List<Long> childrenIds = mapper.selectProjectIdsByRootId(rootProjectId);
     for (Long childId : childrenIds) {
-      deleteProject(childId, session, mapper);
+      deleteProject(childId, session, mapper, vendorMapper);
     }
 
     session.select("org.sonar.core.purge.PurgeMapper.selectResourceTreeIdsByRootId", rootProjectId, new ResultHandler() {
       public void handleResult(ResultContext context) {
         Long resourceId = (Long) context.getResultObject();
-        deleteResource(resourceId, session, mapper);
+        deleteResource(resourceId, session, mapper, vendorMapper);
       }
     });
     session.commit();
   }
 
-  void deleteResource(final long resourceId, final SqlSession session, final PurgeMapper mapper) {
+  void deleteResource(final long resourceId, final SqlSession session, final PurgeMapper mapper, final PurgeVendorMapper vendorMapper) {
     session.select("org.sonar.core.purge.PurgeMapper.selectSnapshotIdsByResource", resourceId, new ResultHandler() {
       public void handleResult(ResultContext context) {
         Long snapshotId = (Long) context.getResultObject();
         deleteSnapshot(snapshotId, mapper);
       }
     });
-    // TODO optimization: filter requests according to resource scope
+    // possible optimization: filter requests according to resource scope
     mapper.deleteResourceLinks(resourceId);
     mapper.deleteResourceProperties(resourceId);
     mapper.deleteResourceIndex(resourceId);
@@ -140,8 +161,8 @@ public class PurgeDao {
     mapper.deleteResourceUserRoles(resourceId);
     mapper.deleteResourceManualMeasures(resourceId);
     mapper.deleteResourceReviews(resourceId);
-    mapper.deleteResourceReviewComments(resourceId);
-    mapper.deleteResourceActionPlansReviews(resourceId);
+    vendorMapper.deleteResourceReviewComments(resourceId);
+    vendorMapper.deleteResourceActionPlansReviews(resourceId);
     mapper.deleteResourceActionPlans(resourceId);
     mapper.deleteResourceEvents(resourceId);
     mapper.deleteResource(resourceId);
@@ -155,17 +176,11 @@ public class PurgeDao {
     mapper.closeResourceReviews(resourceId);
   }
 
-
   public PurgeDao deleteSnapshots(PurgeSnapshotQuery query) {
     final SqlSession session = mybatis.openBatchSession();
     try {
       final PurgeMapper mapper = session.getMapper(PurgeMapper.class);
-      session.select("org.sonar.core.purge.PurgeMapper.selectSnapshotIds", query, new ResultHandler() {
-        public void handleResult(ResultContext context) {
-          Long snapshotId = (Long) context.getResultObject();
-          deleteSnapshot(snapshotId, mapper);
-        }
-      });
+      deleteSnapshots(query, session, mapper);
       session.commit();
       return this;
 
@@ -174,6 +189,24 @@ public class PurgeDao {
     }
   }
 
+  private void deleteSnapshots(PurgeSnapshotQuery query, SqlSession session, final PurgeMapper mapper) {
+    session.select("org.sonar.core.purge.PurgeMapper.selectSnapshotIds", query, new ResultHandler() {
+      public void handleResult(ResultContext context) {
+        Long snapshotId = (Long) context.getResultObject();
+        deleteSnapshot(snapshotId, mapper);
+      }
+    });
+  }
+
+  /**
+   * Load the whole tree of projects, including the project given in parameter.
+   */
+  private List<Long> getProjectIds(long rootProjectId, SqlSession session) {
+    List<Long> projectIds = Lists.newArrayList(rootProjectId);
+    projectIds.addAll(resourceDao.getDescendantProjectIds(rootProjectId, session));
+    return projectIds;
+  }
+
   @VisibleForTesting
   void purgeSnapshot(long snapshotId, PurgeMapper mapper) {
     // note that events are not deleted
index 964b734aac6c1640c83c75966ce6bcc0215a511e..3231b9c225e69e77a912a0929f7fc69237eb36ac 100644 (file)
@@ -71,14 +71,10 @@ public interface PurgeMapper {
 
   void deleteResourceReviews(long resourceId);
 
-  void deleteResourceReviewComments(long resourceId);
-
   void deleteResourceEvents(long resourceId);
 
   void deleteResourceActionPlans(long resourceId);
 
-  void deleteResourceActionPlansReviews(long resourceId);
-
   void closeResourceReviews(long resourceId);
 
   List<PurgeableSnapshotDto> selectPurgeableSnapshotsWithEvents(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
new file mode 100644 (file)
index 0000000..2187bb0
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * 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 e62a75ad90b23952dfcbc959158edc7d8f91bc51..aad082e351616c46884fc6a41f21f8fb10df4186 100644 (file)
     delete from reviews where resource_id=#{id}
   </delete>
 
-  <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="deleteResourceEvents" parameterType="long">
     delete from events where resource_id=#{id}
   </delete>
     delete from action_plans where project_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>
-
   <update id="setSnapshotIsLastToFalse" parameterType="long">
     update snapshots set islast=${_false} where project_id=#{id}
   </update>
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
new file mode 100644 (file)
index 0000000..698f648
--- /dev/null
@@ -0,0 +1,17 @@
+<?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>
+
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
new file mode 100644 (file)
index 0000000..f1d2cd8
--- /dev/null
@@ -0,0 +1,15 @@
+<?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 using reviews where review_comments.review_id=reviews.id and reviews.resource_id=#{id}
+  </delete>
+
+  <delete id="deleteResourceActionPlansReviews" parameterType="long">
+    delete from action_plans_reviews using action_plans where action_plans.id=action_plans_reviews.action_plan_id and action_plans.project_id=#{id}
+  </delete>
+
+</mapper>
+
index df17a128b8f92fb23732fa8cdbd062216825b1bd..2c9dd6299a8e187247eec657ca76196212f9e5a1 100644 (file)
@@ -24,6 +24,7 @@ import org.hamcrest.BaseMatcher;
 import org.hamcrest.Description;
 import org.junit.Before;
 import org.junit.Test;
+import org.sonar.api.resources.Scopes;
 import org.sonar.core.persistence.DaoTestCase;
 import org.sonar.core.persistence.MyBatis;
 import org.sonar.core.resource.ResourceDao;
@@ -119,21 +120,21 @@ public class PurgeDaoTest extends DaoTestCase {
   @Test
   public void shouldPurgeProject() {
     setupData("shouldPurgeProject");
-    dao.purgeProject(1);
+    dao.purgeProject(1, new String[0]);
     checkTables("shouldPurgeProject", "projects", "snapshots");
   }
 
   @Test
   public void shouldPurgeDirectoriesAndFiles() {
     setupData("shouldPurgeDirectoriesAndFiles");
-    dao.purgeProject(1);
+    dao.purgeProject(1, new String[]{Scopes.DIRECTORY, Scopes.FILE});
     checkTables("shouldPurgeDirectoriesAndFiles", "projects", "snapshots");
   }
 
   @Test
   public void shouldDisableResourcesWithoutLastSnapshot() {
     setupData("shouldDisableResourcesWithoutLastSnapshot");
-    dao.purgeProject(1);
+    dao.purgeProject(1, new String[0]);
     checkTables("shouldDisableResourcesWithoutLastSnapshot", "projects", "snapshots");
   }
 
@@ -161,7 +162,7 @@ public class PurgeDaoTest extends DaoTestCase {
     SqlSession session = getMyBatis().openSession();
     try {
       // this method does not commit and close the session
-      dao.deleteResource(1L, session, session.getMapper(PurgeMapper.class));
+      dao.deleteResource(1L, session, session.getMapper(PurgeMapper.class), session.getMapper(PurgeVendorMapper.class));
       session.commit();
 
     } finally {