diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-01-18 16:34:27 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-01-18 20:47:59 +0100 |
commit | 24bbe5fa06ce151aad7519b23034a94b00c34ff7 (patch) | |
tree | 439b5a84c78e17fe2291409112616d35bdb9a151 /sonar-db/src | |
parent | 44f030c6fb48d4ee3faf8a7499acc82efa812a9d (diff) | |
download | sonarqube-24bbe5fa06ce151aad7519b23034a94b00c34ff7.tar.gz sonarqube-24bbe5fa06ce151aad7519b23034a94b00c34ff7.zip |
Remove dead code related to ResourceDao
Diffstat (limited to 'sonar-db/src')
6 files changed, 0 insertions, 368 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java index 46f0010223b..f57fc3384c1 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java @@ -28,9 +28,6 @@ import org.apache.ibatis.annotations.Param; import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.RowBounds; -/** - * @since 4.3 - */ public interface ComponentMapper { @CheckForNull @@ -63,26 +60,15 @@ public interface ComponentMapper { int countByQuery(@Param("query") ComponentQuery query); - List<ComponentDto> selectAncestors(@Param("query") ComponentTreeQuery query, @Param("baseUuidPathLike") String baseUuidPathLike); - List<ComponentDto> selectDescendants(@Param("query") ComponentTreeQuery query, @Param("baseUuid") String baseUuid, @Param("baseUuidPath") String baseUuidPath); /** - * Return all project (PRJ/TRK) uuids - */ - List<String> selectProjectUuids(); - - /** * Returns all enabled projects (Scope {@link org.sonar.api.resources.Scopes#PROJECT} and qualifier * {@link org.sonar.api.resources.Qualifiers#PROJECT}) no matter if they are ghost project, provisioned projects or * regular ones. */ List<ComponentDto> selectProjects(); - List<ComponentDto> selectComponents(Map<String, Object> parameters, RowBounds rowBounds); - - int countRootComponents(Map<String, Object> parameters); - /** * Return all descendant modules (including itself) from a given component uuid and scope */ @@ -120,8 +106,6 @@ public interface ComponentMapper { */ List<String> selectProjectsFromView(@Param("viewUuidLikeQuery") String viewUuidLikeQuery, @Param("projectViewUuid") String projectViewUuid); - long countById(long id); - List<ComponentDto> selectProvisionedProjects(Map<String, Object> parameters, RowBounds rowBounds); int countProvisionedProjects(Map<String, Object> parameters); diff --git a/sonar-db/src/main/java/org/sonar/db/component/ResourceDao.java b/sonar-db/src/main/java/org/sonar/db/component/ResourceDao.java index 8c5a2959344..c7852d0e0ba 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ResourceDao.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ResourceDao.java @@ -19,42 +19,22 @@ */ package org.sonar.db.component; -import com.google.common.base.Function; -import com.google.common.collect.Iterables; import java.util.Collection; import java.util.Collections; import java.util.List; import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; import org.apache.ibatis.session.SqlSession; -import org.sonar.api.component.Component; import org.sonar.api.utils.System2; import org.sonar.db.AbstractDao; import org.sonar.db.DbSession; import org.sonar.db.MyBatis; -import static com.google.common.collect.Lists.newArrayList; - public class ResourceDao extends AbstractDao { public ResourceDao(MyBatis myBatis, System2 system2) { super(myBatis, system2); } - /** - * Return a single result or null. If the request returns multiple rows, then - * the first row is returned. - */ - @CheckForNull - public ResourceDto selectResource(ResourceQuery query) { - DbSession session = myBatis().openSession(false); - try { - return selectResource(query, session); - } finally { - MyBatis.closeQuietly(session); - } - } - @CheckForNull private static ResourceDto selectResource(ResourceQuery query, DbSession session) { List<ResourceDto> resources = getResources(query, session); @@ -83,29 +63,10 @@ public class ResourceDao extends AbstractDao { return session.getMapper(ResourceMapper.class).selectResourceByUuid(componentUuid); } - public ResourceDto selectResource(long projectId, SqlSession session) { - return session.getMapper(ResourceMapper.class).selectResource(projectId); - } - - @CheckForNull - public SnapshotDto getLastSnapshot(String resourceKey, SqlSession session) { - return session.getMapper(ResourceMapper.class).selectLastSnapshotByResourceKey(resourceKey); - } - - public List<ResourceDto> selectWholeTreeForRootId(SqlSession session, long rootId, String scope) { - return session.getMapper(ResourceMapper.class).selectWholeTreeForRootId(rootId, scope); - } - public void updateAuthorizationDate(Long projectId, SqlSession session) { session.getMapper(ResourceMapper.class).updateAuthorizationDate(projectId, now()); } - @CheckForNull - public Component selectByKey(String key) { - ResourceDto resourceDto = selectResource(ResourceQuery.create().setKey(key)); - return resourceDto != null ? toComponent(resourceDto) : null; - } - /** * Return the root project of a component. * Will return the component itself if it's already the root project @@ -151,51 +112,6 @@ public class ResourceDao extends AbstractDao { return null; } - public List<Component> selectProjectsByQualifiers(Collection<String> qualifiers) { - if (qualifiers.isEmpty()) { - return Collections.emptyList(); - } - SqlSession session = myBatis().openSession(false); - try { - return toComponents(session.getMapper(ResourceMapper.class).selectProjectsByQualifiers(qualifiers)); - } finally { - MyBatis.closeQuietly(session); - } - } - - /** - * Return enabled projects including not completed ones, ie without snapshots or without snapshot having islast=true - */ - public List<Component> selectProjectsIncludingNotCompletedOnesByQualifiers(Collection<String> qualifiers) { - if (qualifiers.isEmpty()) { - return Collections.emptyList(); - } - SqlSession session = myBatis().openSession(false); - try { - return toComponents(session.getMapper(ResourceMapper.class).selectProjectsIncludingNotCompletedOnesByQualifiers(qualifiers)); - } finally { - MyBatis.closeQuietly(session); - } - } - - /** - * Return ghosts projects : - * - not enabled projects - * - enabled projects without snapshot having islast=true - * - enabled projects without snapshot - */ - public List<Component> selectGhostsProjects(Collection<String> qualifiers) { - if (qualifiers.isEmpty()) { - return Collections.emptyList(); - } - SqlSession session = myBatis().openSession(false); - try { - return toComponents(session.getMapper(ResourceMapper.class).selectGhostsProjects(qualifiers)); - } finally { - MyBatis.closeQuietly(session); - } - } - /** * Return provisioned projects = enabled projects without snapshot */ @@ -218,26 +134,4 @@ public class ResourceDao extends AbstractDao { return session.getMapper(ResourceMapper.class).selectProvisionedProject(key); } - public static ComponentDto toComponent(ResourceDto resourceDto) { - return new ComponentDto() - .setId(resourceDto.getId()) - .setKey(resourceDto.getKey()) - .setPath(resourceDto.getPath()) - .setLongName(resourceDto.getLongName()) - .setName(resourceDto.getName()) - .setQualifier(resourceDto.getQualifier()); - } - - public static List<Component> toComponents(List<ResourceDto> resourceDto) { - return newArrayList(Iterables.transform(resourceDto, ToComponent.INSTANCE)); - } - - private enum ToComponent implements Function<ResourceDto, Component> { - INSTANCE; - - @Override - public Component apply(@Nonnull ResourceDto resourceDto) { - return toComponent(resourceDto); - } - } } diff --git a/sonar-db/src/main/java/org/sonar/db/component/ResourceMapper.java b/sonar-db/src/main/java/org/sonar/db/component/ResourceMapper.java index 86e1f747c27..296ba846eaf 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ResourceMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ResourceMapper.java @@ -22,42 +22,12 @@ package org.sonar.db.component; import java.util.Collection; import java.util.List; import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.session.ResultHandler; public interface ResourceMapper { - SnapshotDto selectSnapshot(Long snapshotId); - - SnapshotDto selectLastSnapshotByResourceKey(String resourceKey); - - SnapshotDto selectLastSnapshotByResourceUuid(String componentUuid); - - ResourceDto selectResource(long id); - ResourceDto selectResourceByUuid(String uuid); - List<ResourceDto> selectWholeTreeForRootId(@Param("rootId") long rootId, @Param("scope") String scope); - - /** - * @since 3.0 - */ List<ResourceDto> selectResources(ResourceQuery query); - /** - * @since 3.0 - */ - List<Long> selectResourceIds(ResourceQuery query); - - /** - * @since 3.2 - */ - void selectResources(ResourceQuery query, ResultHandler resultHandler); - - List<ResourceDto> selectProjectsIncludingNotCompletedOnesByQualifiers(@Param("qualifiers") Collection<String> qualifier); - - List<ResourceDto> selectProjectsByQualifiers(@Param("qualifiers") Collection<String> qualifier); - - List<ResourceDto> selectGhostsProjects(@Param("qualifiers") Collection<String> qualifier); - List<ResourceDto> selectProvisionedProjects(@Param("qualifiers") Collection<String> qualifier); ResourceDto selectProvisionedProject(@Param("key") String key); diff --git a/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml index 6ac9bfbc672..8bbb25cad00 100644 --- a/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml @@ -71,14 +71,6 @@ root.uuid=#{projectUuid} </select> - <select id="countById" parameterType="long" resultType="long"> - SELECT count(p.id) - FROM projects p - <where> - AND p.id=#{id} - </where> - </select> - <select id="selectByKeys" parameterType="String" resultType="Component"> select <include refid="componentColumns"/> @@ -211,16 +203,6 @@ <include refid="modulesTreeQuery"/> </select> - <select id="selectProjectUuids" resultType="String"> - SELECT p.uuid - FROM projects p - <where> - AND p.enabled=${_true} - AND p.scope='PRJ' - AND p.qualifier='TRK' - </where> - </select> - <select id="selectProjects" resultType="Component"> select <include refid="componentColumns"/> @@ -243,27 +225,6 @@ </where> </select> - <select id="selectComponents" resultType="Component"> - select - <include refid="componentColumns"/> - from projects p - <where> - AND p.enabled=${_true} - AND p.copy_component_uuid is null - AND p.qualifier in - <foreach collection="qualifiers" open="(" close=")" item="qualifier" separator=","> - #{qualifier} - </foreach> - <if test="query!=null"> - and ( - UPPER(p.name) like #{query} - or UPPER(p.kee) like #{query} - ) - </if> - </where> - ORDER BY UPPER(p.name), p.name - </select> - <select id="selectByQuery" resultType="Component"> select <include refid="componentColumns"/> @@ -315,20 +276,6 @@ </if> </sql> - <!-- "p" is ancestors --> - <select id="selectAncestors" resultType="Component"> - select - <include refid="componentColumns"/> - from projects base - inner join projects p on p.project_uuid = base.project_uuid - where - base.uuid = #{query.baseUuid} - and base.uuid_path like #{baseUuidPathLike} - and p.uuid != base.uuid - and p.enabled = ${_true} - order by ${query.sqlSort} - </select> - <select id="selectDescendants" resultType="Component"> select <include refid="componentColumns"/> @@ -378,25 +325,6 @@ </if> </sql> - <select id="countRootComponents" resultType="int"> - select count(p.id) - from projects p - <where> - p.enabled=${_true} - AND p.copy_component_uuid is null - AND p.qualifier in - <foreach collection="qualifiers" open="(" close=")" item="qualifier" separator=","> - #{qualifier} - </foreach> - <if test="query!=null"> - and ( - UPPER(p.name) like #{query} - or UPPER(p.kee) like #{query} - ) - </if> - </where> - </select> - <select id="selectUuidsForQualifiers" resultType="UuidWithProjectUuid"> SELECT p.uuid as "uuid", p.project_uuid as "projectUuid" FROM projects p <where> diff --git a/sonar-db/src/main/resources/org/sonar/db/component/ResourceMapper.xml b/sonar-db/src/main/resources/org/sonar/db/component/ResourceMapper.xml index 8316ec08936..9b87197a94d 100644 --- a/sonar-db/src/main/resources/org/sonar/db/component/ResourceMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/component/ResourceMapper.xml @@ -88,98 +88,11 @@ </where> </select> - <select id="selectResource" parameterType="long" resultMap="resourceResultMap"> - select * from projects p - where p.id=#{id} - </select> - <select id="selectResourceByUuid" parameterType="String" resultMap="resourceResultMap"> select * from projects p where p.uuid=#{uuid} </select> - <select id="selectSnapshot" parameterType="long" resultMap="snapshotResultMap"> - select * from snapshots where id=#{id} - </select> - - <select id="selectLastSnapshotByResourceKey" parameterType="string" resultMap="snapshotResultMap"> - SELECT s.* FROM snapshots s - INNER JOIN projects p on p.uuid=s.component_uuid AND p.enabled=${_true} AND p.copy_component_uuid is null - <where> - AND p.kee=#{id} - AND s.islast=${_true} - </where> - </select> - - <select id="selectLastSnapshotByResourceUuid" parameterType="string" resultMap="snapshotResultMap"> - SELECT s.* from snapshots s - INNER JOIN projects p on p.uuid=s.component_uuid AND p.enabled=${_true} AND p.copy_component_uuid is null - <where> - AND p.uuid=#{uuid} - AND s.islast=${_true} - </where> - </select> - - <select id="selectWholeTreeForRootId" parameterType="long" resultMap="resourceResultMap"> - select - pAll.* - from projects pAll - inner join projects pRoot on pAll.project_uuid = pRoot.uuid and pRoot.id = #{rootId} - <where> - pAll.scope = #{scope} - </where> - </select> - - <select id="selectProjectsIncludingNotCompletedOnesByQualifiers" parameterType="map" resultMap="resourceResultMap"> - select * from projects p - <where> - <if test="qualifiers != null and qualifiers.size() > 0"> - and - <foreach item="qualifier" index="index" collection="qualifiers" open="(" separator=" or " close=")"> - p.qualifier=#{qualifier} - </foreach> - </if> - and p.enabled=${_true} - and p.copy_component_uuid is null - </where> - </select> - - <select id="selectProjectsByQualifiers" parameterType="map" resultMap="resourceResultMap"> - <include refid="selectProjectsByQualifiersQuery"/> - </select> - - <sql id="selectProjectsByQualifiersQuery"> - select p.* from projects p - inner join snapshots s on s.component_uuid=p.uuid - <where> - <if test="qualifiers != null and qualifiers.size() > 0"> - and - <foreach item="qualifier" index="index" collection="qualifiers" open="(" separator=" or " close=")"> - p.qualifier=#{qualifier} - </foreach> - </if> - and p.enabled=${_true} - and p.copy_component_uuid is null - and s.islast=${_true} - </where> - </sql> - - <select id="selectGhostsProjects" parameterType="map" resultMap="resourceResultMap"> - select distinct p.* from projects p - inner join snapshots s1 on s1.component_uuid = p.uuid and s1.status='U' - left join snapshots s2 on s2.component_uuid = p.uuid and s2.status='P' - <where> - and s2.id is null - <if test="qualifiers != null and qualifiers.size() > 0"> - and - <foreach item="qualifier" index="index" collection="qualifiers" open="(" separator=" or " close=")"> - p.qualifier=#{qualifier} - </foreach> - </if> - and p.copy_component_uuid is null - </where> - </select> - <select id="selectProvisionedProjects" parameterType="map" resultMap="resourceResultMap"> select p.* from projects p left join snapshots s on s.component_uuid=p.uuid diff --git a/sonar-db/src/test/java/org/sonar/db/component/ResourceDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ResourceDaoTest.java index b3dceba464e..c37aa18db02 100644 --- a/sonar-db/src/test/java/org/sonar/db/component/ResourceDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/component/ResourceDaoTest.java @@ -33,7 +33,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; - public class ResourceDaoTest { static System2 system = mock(System2.class); @@ -63,15 +62,6 @@ public class ResourceDaoTest { } @Test - public void getResource_filter_by_key() { - dbTester.prepareDbUnit(getClass(), "fixture.xml"); - - ResourceQuery query = ResourceQuery.create().setKey("org.struts:struts-core"); - - assertThat(underTest.selectResource(query).getKey()).isEqualTo("org.struts:struts-core"); - } - - @Test public void find_root_project_by_component_key() { dbTester.prepareDbUnit(getClass(), "fixture.xml"); @@ -84,53 +74,6 @@ public class ResourceDaoTest { } @Test - public void should_find_component_by_key() { - dbTester.prepareDbUnit(getClass(), "fixture.xml"); - - assertThat(underTest.selectByKey("org.struts:struts")).isNotNull(); - Component component = underTest.selectByKey("org.struts:struts-core:src/org/struts/RequestContext.java"); - assertThat(component).isNotNull(); - assertThat(component.path()).isEqualTo("src/org/struts/RequestContext.java"); - assertThat(underTest.selectByKey("unknown")).isNull(); - } - - @Test - public void should_select_projects_by_qualifiers() { - dbTester.prepareDbUnit(getClass(), "fixture-including-ghost-projects-and-technical-project.xml"); - - List<Component> components = underTest.selectProjectsByQualifiers(newArrayList("TRK")); - assertThat(components).hasSize(1); - assertThat(components.get(0).key()).isEqualTo("org.struts:struts"); - assertThat(((ComponentDto) components.get(0)).getId()).isEqualTo(1L); - - assertThat(underTest.selectProjectsIncludingNotCompletedOnesByQualifiers(newArrayList("unknown"))).isEmpty(); - assertThat(underTest.selectProjectsIncludingNotCompletedOnesByQualifiers(Collections.<String>emptyList())).isEmpty(); - } - - @Test - public void should_select_projects_including_not_finished_by_qualifiers() { - dbTester.prepareDbUnit(getClass(), "fixture-including-ghost-projects-and-technical-project.xml"); - - List<Component> components = underTest.selectProjectsIncludingNotCompletedOnesByQualifiers(newArrayList("TRK")); - assertThat(getKeys(components)).containsOnly("org.struts:struts", "org.apache.shindig", "org.sample:sample"); - - assertThat(underTest.selectProjectsIncludingNotCompletedOnesByQualifiers(newArrayList("unknown"))).isEmpty(); - assertThat(underTest.selectProjectsIncludingNotCompletedOnesByQualifiers(Collections.<String>emptyList())).isEmpty(); - } - - @Test - public void should_select_ghosts_projects_by_qualifiers() { - dbTester.prepareDbUnit(getClass(), "fixture-including-ghost-projects-and-technical-project.xml"); - - List<Component> components = underTest.selectGhostsProjects(newArrayList("TRK")); - assertThat(components).hasSize(1); - assertThat(getKeys(components)).containsOnly("org.apache.shindig"); - - assertThat(underTest.selectGhostsProjects(newArrayList("unknown"))).isEmpty(); - assertThat(underTest.selectGhostsProjects(Collections.<String>emptyList())).isEmpty(); - } - - @Test public void should_select_provisioned_projects_by_qualifiers() { dbTester.prepareDbUnit(getClass(), "fixture-including-ghost-projects-and-technical-project.xml"); |