From 1667ff43142ce1dedcf716f62734bf64264349d1 Mon Sep 17 00:00:00 2001 From: Sébastien Lesaint Date: Fri, 27 Jan 2017 09:28:59 +0100 Subject: SONAR-8648 add organization parameter to api/components/search --- .../java/org/sonar/db/component/ComponentDao.java | 29 ++++++++++++++++++---- .../org/sonar/db/component/ComponentMapper.java | 4 +-- 2 files changed, 26 insertions(+), 7 deletions(-) (limited to 'sonar-db/src/main/java/org') diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java index 9880e51467f..d475e9ead20 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java @@ -77,17 +77,37 @@ public class ComponentDao implements Dao { } public List selectByQuery(DbSession session, ComponentQuery query, int offset, int limit) { - if (query.getComponentIds() != null && query.getComponentIds().isEmpty()) { + return selectByQueryImpl(session, null, query, offset, limit); + } + + public List selectByQuery(DbSession dbSession, String organizationUuid, ComponentQuery query, int offset, int limit) { + requireNonNull(organizationUuid, "organizationUuid can't be null"); + return selectByQueryImpl(dbSession, organizationUuid, query, offset, limit); + } + + private static List selectByQueryImpl(DbSession session, @Nullable String organizationUuid, ComponentQuery query, int offset, int limit) { + Set componentIds = query.getComponentIds(); + if (componentIds != null && componentIds.isEmpty()) { return emptyList(); } - return mapper(session).selectByQuery(query, new RowBounds(offset, limit)); + return mapper(session).selectByQuery(organizationUuid, query, new RowBounds(offset, limit)); } public int countByQuery(DbSession session, ComponentQuery query) { - if (query.getComponentIds() != null && query.getComponentIds().isEmpty()) { + return countByQueryImpl(session, null, query); + } + + public int countByQuery(DbSession session, String organizationUuid, ComponentQuery query) { + requireNonNull(organizationUuid, "organizationUuid can't be null"); + return countByQueryImpl(session, organizationUuid, query); + } + + private static int countByQueryImpl(DbSession session, @Nullable String organizationUuid, ComponentQuery query) { + Set componentIds = query.getComponentIds(); + if (componentIds != null && componentIds.isEmpty()) { return 0; } - return mapper(session).countByQuery(query); + return mapper(session).countByQuery(organizationUuid, query); } public List selectSubProjectsByComponentUuids(DbSession session, Collection keys) { @@ -342,5 +362,4 @@ public class ComponentDao implements Dao { private static ComponentMapper mapper(DbSession session) { return session.getMapper(ComponentMapper.class); } - } 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 9c3bb96b7e5..2cddadffbd4 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 @@ -65,9 +65,9 @@ public interface ComponentMapper { */ int countComponentByOrganizationAndId(@Param("organizationUuid") String organizationUuid, @Param("componentId") long componentId); - List selectByQuery(@Param("query") ComponentQuery query, RowBounds rowBounds); + List selectByQuery(@Nullable @Param("organizationUuid") String organizationUuid, @Param("query") ComponentQuery query, RowBounds rowBounds); - int countByQuery(@Param("query") ComponentQuery query); + int countByQuery(@Nullable @Param("organizationUuid") String organizationUuid, @Param("query") ComponentQuery query); List selectDescendants(@Param("query") ComponentTreeQuery query, @Param("baseUuid") String baseUuid, @Param("baseUuidPath") String baseUuidPath); -- cgit v1.2.3