diff options
author | Eric Hartmann <hartmann.eric@gmail.com> | 2012-03-06 21:53:47 +0100 |
---|---|---|
committer | Eric Hartmann <hartmann.eric@gmail.com> | 2012-03-06 21:53:47 +0100 |
commit | 1b76c008dbe78276319320d241a412c84d922ea5 (patch) | |
tree | 0cd9aed7c5444c620ca25bb37bf5439e9212e3a4 /sonar-core | |
parent | 7c6222ae03569c5af98fdbe646edde3f52cd1674 (diff) | |
parent | 8b595a47c93e534a3b00a7439dfc98005a82a9b0 (diff) | |
download | sonarqube-1b76c008dbe78276319320d241a412c84d922ea5.tar.gz sonarqube-1b76c008dbe78276319320d241a412c84d922ea5.zip |
Merge branch 'release-2.14'
Diffstat (limited to 'sonar-core')
27 files changed, 563 insertions, 254 deletions
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 new file mode 100644 index 00000000000..22a841a2e3f --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java @@ -0,0 +1,195 @@ +/* + * 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; + +import com.google.common.annotations.VisibleForTesting; +import org.apache.ibatis.session.SqlSession; + +import java.util.List; + +final class PurgeCommands { + private PurgeCommands() { + } + + @VisibleForTesting + static void deleteResources(List<Long> resourceIds, SqlSession session, PurgeMapper mapper, PurgeVendorMapper vendorMapper) { + // Note : do not merge the delete statements into a single loop of resource ids. It's + // voluntarily grouped by tables in order to benefit from JDBC batch mode. + // Batch requests can only relate to the same PreparedStatement. + + for (Long resourceId : resourceIds) { + deleteSnapshots(PurgeSnapshotQuery.create().setResourceId(resourceId), session, mapper); + } + + // possible missing optimization: filter requests according to resource scope + + for (Long resourceId : resourceIds) { + mapper.deleteResourceLinks(resourceId); + } + session.commit(); + + for (Long resourceId : resourceIds) { + mapper.deleteResourceProperties(resourceId); + } + session.commit(); + + for (Long resourceId : resourceIds) { + mapper.deleteResourceIndex(resourceId); + } + session.commit(); + + for (Long resourceId : resourceIds) { + mapper.deleteResourceGroupRoles(resourceId); + } + session.commit(); + + for (Long resourceId : resourceIds) { + mapper.deleteResourceUserRoles(resourceId); + } + session.commit(); + + for (Long resourceId : resourceIds) { + mapper.deleteResourceManualMeasures(resourceId); + } + session.commit(); + + for (Long resourceId : resourceIds) { + vendorMapper.deleteResourceReviewComments(resourceId); + } + session.commit(); + + for (Long resourceId : resourceIds) { + vendorMapper.deleteResourceActionPlansReviews(resourceId); + } + session.commit(); + + for (Long resourceId : resourceIds) { + mapper.deleteResourceReviews(resourceId); + } + session.commit(); + + for (Long resourceId : resourceIds) { + mapper.deleteResourceActionPlans(resourceId); + } + session.commit(); + + for (Long resourceId : resourceIds) { + mapper.deleteResourceEvents(resourceId); + } + session.commit(); + + for (Long resourceId : resourceIds) { + mapper.deleteResource(resourceId); + } + session.commit(); + } + + @VisibleForTesting + static void deleteSnapshots(final PurgeSnapshotQuery query, final SqlSession session, final PurgeMapper mapper) { + deleteSnapshots(mapper.selectSnapshotIds(query), session, mapper); + } + + private static void deleteSnapshots(final List<Long> snapshotIds, final SqlSession session, final PurgeMapper mapper) { + for (Long snapshotId : snapshotIds) { + mapper.deleteSnapshotDependencies(snapshotId); + } + session.commit(); + + for (Long snapshotId : snapshotIds) { + mapper.deleteSnapshotDuplications(snapshotId); + } + session.commit(); + + for (Long snapshotId : snapshotIds) { + mapper.deleteSnapshotEvents(snapshotId); + } + session.commit(); + + for (Long snapshotId : snapshotIds) { + mapper.deleteSnapshotMeasureData(snapshotId); + } + session.commit(); + + for (Long snapshotId : snapshotIds) { + mapper.deleteSnapshotMeasures(snapshotId); + } + session.commit(); + + for (Long snapshotId : snapshotIds) { + mapper.deleteSnapshotSource(snapshotId); + } + session.commit(); + + for (Long snapshotId : snapshotIds) { + mapper.deleteSnapshotViolations(snapshotId); + } + session.commit(); + + for (Long snapshotId : snapshotIds) { + mapper.deleteSnapshot(snapshotId); + } + + session.commit(); + } + + @VisibleForTesting + static void purgeSnapshots(final PurgeSnapshotQuery query, final SqlSession session, final PurgeMapper mapper) { + purgeSnapshots(mapper.selectSnapshotIds(query), session, mapper); + } + + private static void purgeSnapshots(final List<Long> snapshotIds, final SqlSession session, final PurgeMapper mapper) { + // note that events are not deleted + for (Long snapshotId : snapshotIds) { + mapper.deleteSnapshotDependencies(snapshotId); + } + session.commit(); + + for (Long snapshotId : snapshotIds) { + mapper.deleteSnapshotDuplications(snapshotId); + } + session.commit(); + + for (Long snapshotId : snapshotIds) { + mapper.deleteSnapshotSource(snapshotId); + } + session.commit(); + + for (Long snapshotId : snapshotIds) { + mapper.deleteSnapshotViolations(snapshotId); + } + session.commit(); + + for (Long snapshotId : snapshotIds) { + mapper.deleteSnapshotWastedMeasures(snapshotId); + } + session.commit(); + + for (Long snapshotId : snapshotIds) { + mapper.deleteSnapshotMeasuresOnQualityModelRequirements(snapshotId); + } + session.commit(); + + for (Long snapshotId : snapshotIds) { + mapper.updatePurgeStatusToOne(snapshotId); + } + 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 b448eeb8775..a93661f87a0 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 @@ -25,15 +25,22 @@ import org.apache.commons.lang.ArrayUtils; import org.apache.ibatis.session.ResultContext; import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.SqlSession; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.sonar.core.persistence.MyBatis; import org.sonar.core.resource.ResourceDao; +import org.sonar.core.resource.ResourceDto; import java.util.Collections; import java.util.List; +/** + * @since 2.14 + */ public class PurgeDao { private final MyBatis mybatis; private final ResourceDao resourceDao; + private static final Logger LOG = LoggerFactory.getLogger(PurgeDao.class); public PurgeDao(MyBatis mybatis, ResourceDao resourceDao) { this.mybatis = mybatis; @@ -44,15 +51,14 @@ public class PurgeDao { SqlSession session = mybatis.openBatchSession(); PurgeMapper purgeMapper = session.getMapper(PurgeMapper.class); try { - List<Long> projectIds = getProjectIds(rootResourceId, session); - for (Long projectId : projectIds) { - deleteAbortedBuilds(projectId, session, purgeMapper); - deleteHistoricalData(projectId, scopesWithoutHistoricalData, session, purgeMapper); - purge(projectId, session, purgeMapper); + List<ResourceDto> projects = getProjects(rootResourceId, session); + for (ResourceDto project : projects) { + LOG.info("-> Clean " + project.getLongName() + " [id=" + project.getId() + "]"); + deleteAbortedBuilds(project, session, purgeMapper); + purge(project, scopesWithoutHistoricalData, session, purgeMapper); } - - for (Long projectId : projectIds) { - disableOrphanResources(projectId, session, purgeMapper); + for (ResourceDto project : projects) { + disableOrphanResources(project, session, purgeMapper); } } finally { MyBatis.closeQuietly(session); @@ -60,45 +66,53 @@ 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 deleteAbortedBuilds(ResourceDto project, SqlSession session, PurgeMapper purgeMapper) { + if (hasAbortedBuilds(project.getId(), purgeMapper)) { + LOG.info("<- Delete aborted builds"); + PurgeSnapshotQuery query = PurgeSnapshotQuery.create() + .setIslast(false) + .setStatus(new String[]{"U"}) + .setRootProjectId(project.getId()); + PurgeCommands.deleteSnapshots(query, session, purgeMapper); + session.commit(); + } } - private void deleteHistoricalData(long projectId, String[] scopesWithoutHistoricalData, SqlSession session, PurgeMapper purgeMapper) { - if (!ArrayUtils.isEmpty(scopesWithoutHistoricalData)) { - PurgeSnapshotQuery query = PurgeSnapshotQuery.create() + private boolean hasAbortedBuilds(Long projectId, PurgeMapper purgeMapper) { + PurgeSnapshotQuery query = PurgeSnapshotQuery.create() .setIslast(false) - .setScopes(scopesWithoutHistoricalData) - .setRootProjectId(projectId); - deleteSnapshots(query, session, purgeMapper); - } + .setStatus(new String[]{"U"}) + .setResourceId(projectId); + return !purgeMapper.selectSnapshotIds(query).isEmpty(); } - private void purge(final long projectId, final SqlSession session, final PurgeMapper purgeMapper) { - List<Long> projectSnapshotIds = purgeMapper.selectSnapshotIds(PurgeSnapshotQuery.create().setResourceId(projectId).setIslast(false).setNotPurged(true)); + private void purge(final ResourceDto project, final String[] scopesWithoutHistoricalData, final SqlSession session, final PurgeMapper purgeMapper) { + List<Long> projectSnapshotIds = purgeMapper.selectSnapshotIds( + PurgeSnapshotQuery.create().setResourceId(project.getId()).setIslast(false).setNotPurged(true) + ); for (final Long projectSnapshotId : projectSnapshotIds) { + LOG.info("<- Clean snapshot " + projectSnapshotId); + if (!ArrayUtils.isEmpty(scopesWithoutHistoricalData)) { + PurgeSnapshotQuery query = PurgeSnapshotQuery.create() + .setIslast(false) + .setScopes(scopesWithoutHistoricalData) + .setRootSnapshotId(projectSnapshotId); + PurgeCommands.deleteSnapshots(query, session, purgeMapper); + session.commit(); + } + PurgeSnapshotQuery query = PurgeSnapshotQuery.create().setRootSnapshotId(projectSnapshotId).setNotPurged(true); - session.select("org.sonar.core.purge.PurgeMapper.selectSnapshotIds", query, new ResultHandler() { - public void handleResult(ResultContext resultContext) { - Long snapshotId = (Long) resultContext.getResultObject(); - if (snapshotId != null) { - purgeSnapshot(snapshotId, purgeMapper); - } - } - }); + PurgeCommands.purgeSnapshots(query, session, purgeMapper); + session.commit(); // must be executed at the end for reentrance - purgeSnapshot(projectSnapshotId, purgeMapper); + PurgeCommands.purgeSnapshots(PurgeSnapshotQuery.create().setId(projectSnapshotId).setNotPurged(true), session, purgeMapper); + session.commit(); } - session.commit(); } - private void disableOrphanResources(final long projectId, final SqlSession session, final PurgeMapper purgeMapper) { - session.select("org.sonar.core.purge.PurgeMapper.selectResourceIdsToDisable", projectId, new ResultHandler() { + private void disableOrphanResources(final ResourceDto project, final SqlSession session, final PurgeMapper purgeMapper) { + session.select("org.sonar.core.purge.PurgeMapper.selectResourceIdsToDisable", project.getId(), new ResultHandler() { public void handleResult(ResultContext resultContext) { Long resourceId = (Long) resultContext.getResultObject(); if (resourceId != null) { @@ -135,47 +149,17 @@ public class PurgeDao { } } - private void deleteProject(final long rootProjectId, final SqlSession session, final PurgeMapper mapper, final PurgeVendorMapper vendorMapper) { + private void deleteProject(long rootProjectId, SqlSession session, PurgeMapper mapper, PurgeVendorMapper vendorMapper) { List<Long> childrenIds = mapper.selectProjectIdsByRootId(rootProjectId); for (Long childId : childrenIds) { 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(); - if (resourceId != null) { - deleteResource(resourceId, session, mapper, vendorMapper); - } - } - }); + List<Long> resourceIds = mapper.selectResourceIdsByRootId(rootProjectId); + PurgeCommands.deleteResources(resourceIds, session, mapper, vendorMapper); session.commit(); } - 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(); - if (snapshotId != null) { - deleteSnapshot(snapshotId, mapper); - } - } - }); - // possible optimization: filter requests according to resource scope - mapper.deleteResourceLinks(resourceId); - mapper.deleteResourceProperties(resourceId); - mapper.deleteResourceIndex(resourceId); - mapper.deleteResourceGroupRoles(resourceId); - mapper.deleteResourceUserRoles(resourceId); - mapper.deleteResourceManualMeasures(resourceId); - vendorMapper.deleteResourceReviewComments(resourceId); - vendorMapper.deleteResourceActionPlansReviews(resourceId); - mapper.deleteResourceReviews(resourceId); - mapper.deleteResourceActionPlans(resourceId); - mapper.deleteResourceEvents(resourceId); - mapper.deleteResource(resourceId); - } - @VisibleForTesting void disableResource(long resourceId, PurgeMapper mapper) { mapper.deleteResourceIndex(resourceId); @@ -188,7 +172,7 @@ public class PurgeDao { final SqlSession session = mybatis.openBatchSession(); try { final PurgeMapper mapper = session.getMapper(PurgeMapper.class); - deleteSnapshots(query, session, mapper); + PurgeCommands.deleteSnapshots(query, session, mapper); session.commit(); return this; @@ -197,47 +181,14 @@ 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(); - if (snapshotId != null) { - 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 - mapper.deleteSnapshotDependencies(snapshotId); - mapper.deleteSnapshotDuplications(snapshotId); - mapper.deleteSnapshotSource(snapshotId); - mapper.deleteSnapshotViolations(snapshotId); - mapper.deleteSnapshotWastedMeasures(snapshotId); - mapper.deleteSnapshotMeasuresOnQualityModelRequirements(snapshotId); - mapper.updatePurgeStatusToOne(snapshotId); + private List<ResourceDto> getProjects(long rootProjectId, SqlSession session) { + List<ResourceDto> projects = Lists.newArrayList(); + projects.add(resourceDao.getResource(rootProjectId, session)); + projects.addAll(resourceDao.getDescendantProjects(rootProjectId, session)); + return projects; } - @VisibleForTesting - void deleteSnapshot(long snapshotId, PurgeMapper mapper) { - mapper.deleteSnapshotDependencies(snapshotId); - mapper.deleteSnapshotDuplications(snapshotId); - mapper.deleteSnapshotEvents(snapshotId); - mapper.deleteSnapshotMeasureData(snapshotId); - mapper.deleteSnapshotMeasures(snapshotId); - mapper.deleteSnapshotSource(snapshotId); - mapper.deleteSnapshotViolations(snapshotId); - mapper.deleteSnapshot(snapshotId); - } } 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 3231b9c225e..2deacdd4600 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 @@ -80,4 +80,6 @@ public interface PurgeMapper { List<PurgeableSnapshotDto> selectPurgeableSnapshotsWithEvents(long resourceId); List<PurgeableSnapshotDto> selectPurgeableSnapshotsWithoutEvents(long resourceId); + + List<Long> selectResourceIdsByRootId(long rootProjectId); } diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeSnapshotQuery.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeSnapshotQuery.java index 7fca0f6773a..c3905abcd67 100644 --- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeSnapshotQuery.java +++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeSnapshotQuery.java @@ -20,6 +20,7 @@ package org.sonar.core.purge; public final class PurgeSnapshotQuery { + private Long id; private Long rootProjectId; private Long rootSnapshotId; private Long resourceId; @@ -37,6 +38,15 @@ public final class PurgeSnapshotQuery { return new PurgeSnapshotQuery(); } + public Long getId() { + return id; + } + + public PurgeSnapshotQuery setId(Long l) { + this.id = l; + return this; + } + public Long getRootProjectId() { return rootProjectId; } diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java index 421eca7304d..e97fb1d7795 100644 --- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java +++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java @@ -32,27 +32,40 @@ public class ResourceDao { this.mybatis = mybatis; } - public List<Long> getDescendantProjectIds(long projectId) { + public ResourceDto getResource(long projectId) { SqlSession session = mybatis.openSession(); try { - return getDescendantProjectIds(projectId, session); + return getResource(projectId, session); } finally { MyBatis.closeQuietly(session); } } - public List<Long> getDescendantProjectIds(long projectId, SqlSession session) { + public ResourceDto getResource(long projectId, SqlSession session) { + return session.getMapper(ResourceMapper.class).selectResource(projectId); + } + + public List<ResourceDto> getDescendantProjects(long projectId) { + SqlSession session = mybatis.openSession(); + try { + return getDescendantProjects(projectId, session); + } finally { + MyBatis.closeQuietly(session); + } + } + + public List<ResourceDto> getDescendantProjects(long projectId, SqlSession session) { ResourceMapper mapper = session.getMapper(ResourceMapper.class); - List<Long> ids = Lists.newArrayList(); - appendChildProjectIds(projectId, mapper, ids); - return ids; + List<ResourceDto> resources = Lists.newArrayList(); + appendChildProjects(projectId, mapper, resources); + return resources; } - private void appendChildProjectIds(long projectId, ResourceMapper mapper, List<Long> ids) { - List<Long> subProjectIds = mapper.selectDescendantProjectIds(projectId); - for (Long subProjectId : subProjectIds) { - ids.add(subProjectId); - appendChildProjectIds(subProjectId, mapper, ids); + private void appendChildProjects(long projectId, ResourceMapper mapper, List<ResourceDto> resources) { + List<ResourceDto> subProjects = mapper.selectDescendantProjects(projectId); + for (ResourceDto subProject : subProjects) { + resources.add(subProject); + appendChildProjects(subProject.getId(), mapper, resources); } } } diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDto.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDto.java index 8d0c3d2080c..4a672113359 100644 --- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDto.java +++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDto.java @@ -21,18 +21,18 @@ package org.sonar.core.resource; public final class ResourceDto { - private Integer id; + private Long id; private String name; private String longName; private Integer rootId; private String scope; private String qualifier; - public Integer getId() { + public Long getId() { return id; } - public ResourceDto setId(Integer id) { + public ResourceDto setId(Long id) { this.id = id; return this; } diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexDto.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexDto.java index 2ef069dd27c..54bb5485953 100644 --- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexDto.java +++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexDto.java @@ -24,8 +24,8 @@ public final class ResourceIndexDto { private String key; private int position; private int nameSize; - private int resourceId; - private int rootProjectId; + private long resourceId; + private long rootProjectId; private String qualifier; public String getKey() { @@ -46,20 +46,20 @@ public final class ResourceIndexDto { return this; } - public int getResourceId() { + public long getResourceId() { return resourceId; } - public ResourceIndexDto setResourceId(int i) { + public ResourceIndexDto setResourceId(long i) { this.resourceId = i; return this; } - public int getRootProjectId() { + public long getRootProjectId() { return rootProjectId; } - public ResourceIndexDto setRootProjectId(int i) { + public ResourceIndexDto setRootProjectId(long i) { this.rootProjectId = i; return this; } diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexerMapper.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexerMapper.java index d6785a7ad3b..53f00b440e5 100644 --- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexerMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexerMapper.java @@ -21,9 +21,9 @@ package org.sonar.core.resource; public interface ResourceIndexerMapper { - ResourceIndexDto selectMasterIndexByResourceId(int resourceId); + ResourceIndexDto selectMasterIndexByResourceId(long resourceId); - void deleteByResourceId(int resourceId); + void deleteByResourceId(long resourceId); void insert(ResourceIndexDto dto); } diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java index 24bdb00a289..626dfd61f12 100644 --- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java @@ -22,6 +22,7 @@ package org.sonar.core.resource; import java.util.List; public interface ResourceMapper { - SnapshotDto selectSnapshotById(Long snapshotId); - List<Long> selectDescendantProjectIds(long rootProjectId); + SnapshotDto selectSnapshot(Long snapshotId); + ResourceDto selectResource(long id); + List<ResourceDto> selectDescendantProjects(long rootProjectId); } 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 aad082e3516..1a58d70d02d 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 @@ -13,7 +13,10 @@ and (s.purge_status is null or s.purge_status=0) </if> <if test="rootSnapshotId != null"> - and (s.root_snapshot_id=#{rootSnapshotId} or s.id=#{rootSnapshotId}) + and s.root_snapshot_id=#{rootSnapshotId} + </if> + <if test="id != null"> + and s.id=#{id} </if> <if test="rootProjectId != null"> and s.root_project_id=#{rootProjectId} @@ -69,14 +72,10 @@ select id from projects where root_id=#{id} and scope='PRJ' </select> - <select id="selectResourceTreeIdsByRootId" resultType="long" parameterType="long"> + <select id="selectResourceIdsByRootId" resultType="long" parameterType="long"> select id from projects where root_id=#{id} or id=#{id} </select> - <select id="selectSnapshotIdsByResource" parameterType="long" resultType="long"> - select id from snapshots where project_id=#{id} - </select> - <delete id="deleteSnapshotMeasures" parameterType="long"> delete from project_measures where snapshot_id=#{id} </delete> diff --git a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceIndexerMapper.xml b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceIndexerMapper.xml index e5206a164be..b44c90dcc3e 100644 --- a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceIndexerMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceIndexerMapper.xml @@ -41,13 +41,13 @@ and qualifier in ('TRK', 'VW', 'SVW') </select> - <select id="selectMasterIndexByResourceId" parameterType="int" resultType="ResourceIndex"> + <select id="selectMasterIndexByResourceId" parameterType="long" resultType="ResourceIndex"> select kee as "key", resource_id as "resourceId" from resource_index where resource_id=#{id} and position=0 </select> - <delete id="deleteByResourceId" parameterType="int"> + <delete id="deleteByResourceId" parameterType="long"> delete from resource_index where resource_id=#{id} </delete> diff --git a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml index f16cc1849dd..2245bab7513 100644 --- a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml @@ -22,13 +22,25 @@ <result property="rootProjectId" column="root_project_id"/> </resultMap> + <resultMap id="resourceResultMap" type="Resource"> + <id property="id" column="id"/> + <result property="name" column="name"/> + <result property="longName" column="long_name"/> + <result property="rootId" column="root_id"/> + <result property="scope" column="scope"/> + <result property="qualifier" column="qualifier"/> + </resultMap> + + <select id="selectResource" parameterType="long" resultMap="resourceResultMap"> + select * from projects where id=#{id} + </select> - <select id="selectSnapshotById" parameterType="int" resultMap="snapshotResultMap"> + <select id="selectSnapshot" parameterType="long" resultMap="snapshotResultMap"> select * from snapshots where id=#{id} </select> - <select id="selectDescendantProjectIds" parameterType="long" resultType="long"> - select id from projects where scope='PRJ' and root_id=#{id} + <select id="selectDescendantProjects" parameterType="long" resultMap="resourceResultMap"> + select * from projects where scope='PRJ' and root_id=#{id} </select> </mapper> diff --git a/sonar-core/src/test/java/org/sonar/core/purge/PurgeCommandsTest.java b/sonar-core/src/test/java/org/sonar/core/purge/PurgeCommandsTest.java new file mode 100644 index 00000000000..d4411bfa8be --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/purge/PurgeCommandsTest.java @@ -0,0 +1,89 @@ +/* + * 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; + +import org.apache.ibatis.session.SqlSession; +import org.junit.Test; +import org.sonar.core.persistence.DaoTestCase; +import org.sonar.core.persistence.MyBatis; + +import java.util.Arrays; + +public class PurgeCommandsTest extends DaoTestCase { + /** + * Test that all related data is deleted. + */ + @Test + public void shouldDeleteSnapshot() { + setupData("shouldDeleteSnapshot"); + + SqlSession session = getMyBatis().openSession(); + try { + PurgeCommands.deleteSnapshots(PurgeSnapshotQuery.create().setId(5L), session, session.getMapper(PurgeMapper.class)); + } finally { + MyBatis.closeQuietly(session); + } + checkTables("shouldDeleteSnapshot", + "snapshots", "project_measures", "measure_data", "rule_failures", "snapshot_sources", "duplications_index", "events", "dependencies"); + } + + /** + * Test that all related data is purged. + */ + @Test + public void shouldPurgeSnapshot() { + setupData("shouldPurgeSnapshot"); + + SqlSession session = getMyBatis().openSession(); + try { + PurgeCommands.purgeSnapshots(PurgeSnapshotQuery.create().setId(1L), session, session.getMapper(PurgeMapper.class)); + } finally { + MyBatis.closeQuietly(session); + } + checkTables("shouldPurgeSnapshot", + "snapshots", "project_measures", "measure_data", "rule_failures", "snapshot_sources", "duplications_index", "events", "dependencies", "reviews"); + } + + @Test + public void shouldDeleteWastedMeasuresWhenPurgingSnapshot() { + setupData("shouldDeleteWastedMeasuresWhenPurgingSnapshot"); + + SqlSession session = getMyBatis().openSession(); + try { + PurgeCommands.purgeSnapshots(PurgeSnapshotQuery.create().setId(1L), session, session.getMapper(PurgeMapper.class)); + } finally { + MyBatis.closeQuietly(session); + } + checkTables("shouldDeleteWastedMeasuresWhenPurgingSnapshot", "project_measures"); + } + + @Test + public void shouldDeleteResource() { + setupData("shouldDeleteResource"); + SqlSession session = getMyBatis().openSession(); + try { + PurgeCommands.deleteResources(Arrays.asList(1L), session, session.getMapper(PurgeMapper.class), session.getMapper(PurgeVendorMapper.class)); + } finally { + MyBatis.closeQuietly(session); + } + assertEmptyTables("projects", "snapshots", "events", "reviews", "review_comments"); + } + +} diff --git a/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java b/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java index fbfe4661af2..9269f7c4daf 100644 --- a/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java @@ -44,60 +44,11 @@ public class PurgeDaoTest extends DaoTestCase { dao = new PurgeDao(getMyBatis(), new ResourceDao(getMyBatis())); } - /** - * Test that all related data is deleted. - */ @Test - public void shouldDeleteSnapshot() { - setupData("shouldDeleteSnapshot"); - - SqlSession session = getMyBatis().openSession(); - try { - // this method does not commit and close the session - dao.deleteSnapshot(5L, session.getMapper(PurgeMapper.class)); - session.commit(); - - } finally { - MyBatis.closeQuietly(session); - } - checkTables("shouldDeleteSnapshot", - "snapshots", "project_measures", "measure_data", "rule_failures", "snapshot_sources", "duplications_index", "events", "dependencies"); - } - - /** - * Test that all related data is purged. - */ - @Test - public void shouldPurgeSnapshot() { - setupData("shouldPurgeSnapshot"); - - SqlSession session = getMyBatis().openSession(); - try { - // this method does not commit and close the session - dao.purgeSnapshot(1L, session.getMapper(PurgeMapper.class)); - session.commit(); - - } finally { - MyBatis.closeQuietly(session); - } - checkTables("shouldPurgeSnapshot", - "snapshots", "project_measures", "measure_data", "rule_failures", "snapshot_sources", "duplications_index", "events", "dependencies", "reviews"); - } - - @Test - public void shouldDeleteWastedMeasuresWhenPurgingSnapshot() { - setupData("shouldDeleteWastedMeasuresWhenPurgingSnapshot"); - - SqlSession session = getMyBatis().openSession(); - try { - // this method does not commit and close the session - dao.purgeSnapshot(1L, session.getMapper(PurgeMapper.class)); - session.commit(); - - } finally { - MyBatis.closeQuietly(session); - } - checkTables("shouldDeleteWastedMeasuresWhenPurgingSnapshot", "project_measures"); + public void shouldDeleteAbortedBuilds() { + setupData("shouldDeleteAbortedBuilds"); + dao.purge(1L, new String[0]); + checkTables("shouldDeleteAbortedBuilds", "snapshots"); } @Test @@ -106,8 +57,9 @@ public class PurgeDaoTest extends DaoTestCase { SqlSession session = getMyBatis().openSession(); try { - // this method does not commit and close the session dao.disableResource(1L, session.getMapper(PurgeMapper.class)); + + // the above method does not commit and close the session session.commit(); } finally { @@ -125,10 +77,10 @@ public class PurgeDaoTest extends DaoTestCase { } @Test - public void shouldPurgeDirectoriesAndFiles() { - setupData("shouldPurgeDirectoriesAndFiles"); + public void shouldDeleteHistoricalDataOfDirectoriesAndFiles() { + setupData("shouldDeleteHistoricalDataOfDirectoriesAndFiles"); dao.purge(1, new String[]{Scopes.DIRECTORY, Scopes.FILE}); - checkTables("shouldPurgeDirectoriesAndFiles", "projects", "snapshots"); + checkTables("shouldDeleteHistoricalDataOfDirectoriesAndFiles", "projects", "snapshots"); } @Test @@ -157,21 +109,6 @@ public class PurgeDaoTest extends DaoTestCase { } @Test - public void shouldDeleteResource() { - setupData("shouldDeleteResource"); - SqlSession session = getMyBatis().openSession(); - try { - // this method does not commit and close the session - dao.deleteResource(1L, session, session.getMapper(PurgeMapper.class), session.getMapper(PurgeVendorMapper.class)); - session.commit(); - - } finally { - MyBatis.closeQuietly(session); - } - assertEmptyTables("projects", "snapshots", "events", "reviews", "review_comments"); - } - - @Test public void shouldDeleteProject() { setupData("shouldDeleteProject"); dao.deleteProject(1L); @@ -196,9 +133,9 @@ public class PurgeDaoTest extends DaoTestCase { public void describeTo(Description description) { description - .appendText("snapshotId").appendValue(snapshotId) - .appendText("isLast").appendValue(isLast) - .appendText("hasEvents").appendValue(hasEvents); + .appendText("snapshotId").appendValue(snapshotId) + .appendText("isLast").appendValue(isLast) + .appendText("hasEvents").appendValue(hasEvents); } } } diff --git a/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java b/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java index 0e22ee43154..cb9d765a95b 100644 --- a/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java @@ -26,10 +26,9 @@ import org.sonar.core.persistence.DaoTestCase; import java.util.List; -import static org.hamcrest.core.IsNot.not; -import static org.hamcrest.core.IsNull.nullValue; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; -import static org.junit.matchers.JUnitMatchers.hasItems; public class ResourceDaoTest extends DaoTestCase { @@ -41,23 +40,37 @@ public class ResourceDaoTest extends DaoTestCase { } @Test - public void testDescendantProjectIdsAndSelf() { + public void testDescendantProjects_do_not_include_self() { setupData("fixture"); - List<Long> ids = dao.getDescendantProjectIds(1L); + List<ResourceDto> resources = dao.getDescendantProjects(1L); - assertThat(ids, hasItems(2L)); - assertThat(ids.size(), Is.is(1)); + assertThat(resources.size(), Is.is(1)); + assertThat(resources.get(0).getId(), is(2L)); } @Test - public void testDescendantProjectIdsAndSelf_id_not_found() { + public void testDescendantProjects_id_not_found() { setupData("fixture"); - List<Long> ids = dao.getDescendantProjectIds(33333L); + assertThat(dao.getDescendantProjects(33333L).size(), Is.is(0)); + } + + @Test + public void getResource() { + setupData("fixture"); + + ResourceDto resource = dao.getResource(1L); + assertThat(resource.getName(), Is.is("Struts")); + assertThat(resource.getLongName(), Is.is("Apache Struts")); + assertThat(resource.getScope(), Is.is("PRJ")); + } + + @Test + public void getResource_not_found() { + setupData("fixture"); - assertThat(ids, not(nullValue())); - assertThat(ids.size(), Is.is(0)); + assertNull(dao.getResource(987654321L)); } } diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteResource.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteResource.xml index df9741558c4..df9741558c4 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteResource.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteResource.xml diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteSnapshot-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot-result.xml index 6734c0522a8..6734c0522a8 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteSnapshot-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot-result.xml diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteSnapshot.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot.xml index 61ebfe5caab..61ebfe5caab 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteSnapshot.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot.xml diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot-result.xml index d264293021c..d264293021c 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot-result.xml diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot.xml index b9fddbbc0c9..b9fddbbc0c9 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot.xml diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeSnapshot-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldPurgeSnapshot-result.xml index b8af6c0b035..b8af6c0b035 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeSnapshot-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldPurgeSnapshot-result.xml diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeSnapshot.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldPurgeSnapshot.xml index ef7489378b9..ef7489378b9 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeSnapshot.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldPurgeSnapshot.xml diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteAbortedBuilds-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteAbortedBuilds-result.xml new file mode 100644 index 00000000000..7f21ab01f6e --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteAbortedBuilds-result.xml @@ -0,0 +1,46 @@ +<!-- + +Snapshot 2 has been deleted + +--> +<dataset> + + <!-- the project --> + <projects id="1" enabled="[true]" root_id="[null]" + long_name="[null]" scope="PRJ" qualifier="TRK" kee="project" name="project" + description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" profile_id="[null]"/> + + <!-- past snapshot with status "processed" and already purged --> + <snapshots id="1" + project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]" + status="P" islast="[false]" purge_status="1" + period1_mode="[null]" period1_param="[null]" period1_date="[null]" + period2_mode="[null]" period2_param="[null]" period2_date="[null]" + period3_mode="[null]" period3_param="[null]" period3_date="[null]" + period4_mode="[null]" period4_param="[null]" period4_date="[null]" + period5_mode="[null]" period5_param="[null]" period5_date="[null]" + depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> + + <!-- snapshot with status "unprocessed" -> to be deleted --> + <!--<snapshots id="2"--> + <!--project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"--> + <!--status="U" islast="[false]" purge_status="0"--> + <!--period1_mode="[null]" period1_param="[null]" period1_date="[null]"--> + <!--period2_mode="[null]" period2_param="[null]" period2_date="[null]"--> + <!--period3_mode="[null]" period3_param="[null]" period3_date="[null]"--> + <!--period4_mode="[null]" period4_param="[null]" period4_date="[null]"--> + <!--period5_mode="[null]" period5_param="[null]" period5_date="[null]"--> + <!--depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/>--> + + <!-- snapshot with status "processed" and flagged as "last" -> do not purge and do not delete --> + <snapshots id="3" + project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]" + status="P" islast="[true]" purge_status="0" + period1_mode="[null]" period1_param="[null]" period1_date="[null]" + period2_mode="[null]" period2_param="[null]" period2_date="[null]" + period3_mode="[null]" period3_param="[null]" period3_date="[null]" + period4_mode="[null]" period4_param="[null]" period4_date="[null]" + period5_mode="[null]" period5_param="[null]" period5_date="[null]" + depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> + +</dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteAbortedBuilds.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteAbortedBuilds.xml new file mode 100644 index 00000000000..da6f52837c7 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteAbortedBuilds.xml @@ -0,0 +1,41 @@ +<dataset> + + <!-- the project --> + <projects id="1" enabled="[true]" root_id="[null]" + long_name="[null]" scope="PRJ" qualifier="TRK" kee="project" name="project" + description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" profile_id="[null]"/> + + <!-- past snapshot with status "processed" and already purged --> + <snapshots id="1" + project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]" + status="P" islast="[false]" purge_status="1" + period1_mode="[null]" period1_param="[null]" period1_date="[null]" + period2_mode="[null]" period2_param="[null]" period2_date="[null]" + period3_mode="[null]" period3_param="[null]" period3_date="[null]" + period4_mode="[null]" period4_param="[null]" period4_date="[null]" + period5_mode="[null]" period5_param="[null]" period5_date="[null]" + depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> + + <!-- snapshot with status "unprocessed" -> to be deleted --> + <snapshots id="2" + project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]" + status="U" islast="[false]" purge_status="0" + period1_mode="[null]" period1_param="[null]" period1_date="[null]" + period2_mode="[null]" period2_param="[null]" period2_date="[null]" + period3_mode="[null]" period3_param="[null]" period3_date="[null]" + period4_mode="[null]" period4_param="[null]" period4_date="[null]" + period5_mode="[null]" period5_param="[null]" period5_date="[null]" + depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> + + <!-- snapshot with status "processed" and flagged as "last" -> do not purge and do not delete --> + <snapshots id="3" + project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]" + status="P" islast="[true]" purge_status="0" + period1_mode="[null]" period1_param="[null]" period1_date="[null]" + period2_mode="[null]" period2_param="[null]" period2_date="[null]" + period3_mode="[null]" period3_param="[null]" period3_date="[null]" + period4_mode="[null]" period4_param="[null]" period4_date="[null]" + period5_mode="[null]" period5_param="[null]" period5_date="[null]" + depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> + +</dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeDirectoriesAndFiles-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml index a50174fdd99..c0f246cad7f 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeDirectoriesAndFiles-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml @@ -1,6 +1,6 @@ <!-- -What has been changed : purge_status=1 on snapshots 4, 5 and 6 +What has been changed : purge_status=1 on snapshot 4 (PRJ) and snapshots 5 and 6 (DIR/FIL) are deleted --> @@ -40,7 +40,7 @@ What has been changed : purge_status=1 on snapshots 4, 5 and 6 period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" - depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> + depth="[null]" scope="DIR" qualifier="DIR" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> <snapshots id="3" @@ -51,7 +51,7 @@ What has been changed : purge_status=1 on snapshots 4, 5 and 6 period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" - depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> + depth="[null]" scope="FIL" qualifier="FIL" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> <!-- snapshots to be purged --> <snapshots id="4" @@ -64,25 +64,25 @@ What has been changed : purge_status=1 on snapshots 4, 5 and 6 period5_mode="[null]" period5_param="[null]" period5_date="[null]" depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> - <snapshots id="5" - project_id="2" parent_snapshot_id="4" root_project_id="1" root_snapshot_id="4" - status="P" islast="[false]" purge_status="1" - period1_mode="[null]" period1_param="[null]" period1_date="[null]" - period2_mode="[null]" period2_param="[null]" period2_date="[null]" - period3_mode="[null]" period3_param="[null]" period3_date="[null]" - period4_mode="[null]" period4_param="[null]" period4_date="[null]" - period5_mode="[null]" period5_param="[null]" period5_date="[null]" - depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> + <!--<snapshots id="5"--> + <!--project_id="2" parent_snapshot_id="4" root_project_id="1" root_snapshot_id="4"--> + <!--status="P" islast="[false]" purge_status="1"--> + <!--period1_mode="[null]" period1_param="[null]" period1_date="[null]"--> + <!--period2_mode="[null]" period2_param="[null]" period2_date="[null]"--> + <!--period3_mode="[null]" period3_param="[null]" period3_date="[null]"--> + <!--period4_mode="[null]" period4_param="[null]" period4_date="[null]"--> + <!--period5_mode="[null]" period5_param="[null]" period5_date="[null]"--> + <!--depth="[null]" scope="DIR" qualifier="DIR" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/>--> - <snapshots id="6" - project_id="3" parent_snapshot_id="5" root_project_id="1" root_snapshot_id="4" - status="P" islast="[false]" purge_status="1" - period1_mode="[null]" period1_param="[null]" period1_date="[null]" - period2_mode="[null]" period2_param="[null]" period2_date="[null]" - period3_mode="[null]" period3_param="[null]" period3_date="[null]" - period4_mode="[null]" period4_param="[null]" period4_date="[null]" - period5_mode="[null]" period5_param="[null]" period5_date="[null]" - depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> + <!--<snapshots id="6"--> + <!--project_id="3" parent_snapshot_id="5" root_project_id="1" root_snapshot_id="4"--> + <!--status="P" islast="[false]" purge_status="1"--> + <!--period1_mode="[null]" period1_param="[null]" period1_date="[null]"--> + <!--period2_mode="[null]" period2_param="[null]" period2_date="[null]"--> + <!--period3_mode="[null]" period3_param="[null]" period3_date="[null]"--> + <!--period4_mode="[null]" period4_param="[null]" period4_date="[null]"--> + <!--period5_mode="[null]" period5_param="[null]" period5_date="[null]"--> + <!--depth="[null]" scope="FIL" qualifier="FIL" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/>--> </dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeDirectoriesAndFiles.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml index 955b522db3f..03cbbfc847b 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeDirectoriesAndFiles.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml @@ -34,7 +34,7 @@ period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" - depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> + depth="[null]" scope="DIR" qualifier="DIR" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> <snapshots id="3" @@ -45,7 +45,7 @@ period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" - depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> + depth="[null]" scope="FIL" qualifier="FIL" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> <!-- snapshots to be purged --> <snapshots id="4" @@ -66,7 +66,7 @@ period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" - depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> + depth="[null]" scope="DIR" qualifier="DIR" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> <snapshots id="6" @@ -77,6 +77,6 @@ period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" - depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> + depth="[null]" scope="FIL" qualifier="FIL" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> </dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/fixture.xml b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/fixture.xml index a993fe82a6f..e92a256f553 100644 --- a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/fixture.xml +++ b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/fixture.xml @@ -2,7 +2,7 @@ <!-- root project --> <projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts" - description="[null]" long_name="Struts" + description="[null]" long_name="Apache Struts" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/> <snapshots id="1" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]" status="P" islast="[false]" purge_status="[null]" |