this.periodCleaner = periodCleaner;
}
- public PurgeTask deleteProject(long projectId) {
- purgeDao.deleteProject(projectId);
+ public PurgeTask delete(long resourceId) {
+ purgeDao.deleteProject(resourceId);
return this;
}
- public PurgeTask purgeProject(long projectId) {
- cleanHistoricalData(projectId);
- doPurgeProject(projectId);
+ public PurgeTask purge(long resourceId) {
+ cleanHistoricalData(resourceId);
+ doPurge(resourceId);
return this;
}
- private void cleanHistoricalData(long projectId) {
+ private void cleanHistoricalData(long resourceId) {
try {
- LOG.debug("Clean project historical data [id=" + projectId + "]");
- periodCleaner.purge(projectId);
+ LOG.debug("Clean historical data [id=" + resourceId + "]");
+ periodCleaner.purge(resourceId);
} catch (Exception e) {
// purge errors must no fail the batch
- LOG.error("Fail to clean project historical data [id=" + projectId + "]", e);
+ LOG.error("Fail to clean historical data [id=" + resourceId + "]", e);
}
}
return new String[]{Scopes.FILE};
}
- private void doPurgeProject(long projectId) {
+ private void doPurge(long resourceId) {
try {
- LOG.debug("Purge project [id=" + projectId + "]");
- purgeDao.purgeProject(projectId, getScopesWithoutHistoricalData());
+ LOG.debug("Purge data [id=" + resourceId + "]");
+ purgeDao.purgeProject(resourceId, getScopesWithoutHistoricalData());
} catch (Exception e) {
// purge errors must no fail the batch
- LOG.error("Fail to purge project [id=" + projectId + "]", e);
+ LOG.error("Fail to purge data [id=" + resourceId + "]", e);
}
}
}
*/
package org.sonar.plugins.dbcleaner.api;
+import com.google.common.annotations.Beta;
import org.sonar.api.BatchExtension;
/**
* @since 2.14
*/
+@Beta
public interface PurgeTask extends BatchExtension {
- PurgeTask purgeProject(long projectId);
- PurgeTask deleteProject(long projectId);
+ /**
+ * Purges the data related to a tree of resources.
+ *
+ * Exceptions are logged and are not thrown again, so this method fails only on {@link Error}s.
+ *
+ * @param resourceId the root of the tree
+ * @return this
+ */
+ PurgeTask purge(long resourceId);
+
+ /**
+ * Completely deletes a tree of resources.
+ *
+ * @param resourceId the root of the tree
+ * @return this
+ */
+ PurgeTask delete(long resourceId);
}
settings.setProperty(DbCleanerConstants.PROPERTY_CLEAN_DIRECTORY, "false");
DefaultPurgeTask task = new DefaultPurgeTask(purgeDao, settings, mock(DefaultPeriodCleaner.class));
- task.purgeProject(1L);
+ task.purge(1L);
verify(purgeDao).purgeProject(1L, new String[]{Scopes.FILE});
}
Settings settings = new Settings(new PropertyDefinitions(DefaultPurgeTask.class));
DefaultPurgeTask task = new DefaultPurgeTask(purgeDao, settings, mock(DefaultPeriodCleaner.class));
- task.purgeProject(1L);
+ task.purge(1L);
verify(purgeDao).purgeProject(1L, new String[]{Scopes.DIRECTORY, Scopes.FILE});
}
when(purgeDao.purgeProject(anyLong(), (String[]) any())).thenThrow(new RuntimeException());
DefaultPurgeTask task = new DefaultPurgeTask(purgeDao, new Settings(), mock(DefaultPeriodCleaner.class));
- task.purgeProject(1L);
+ task.purge(1L);
verify(purgeDao).purgeProject(anyLong(), (String[]) any());
}