From a715acffcf1fa4f56c3edbc8ec2e58e69cce7550 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Mon, 27 May 2013 09:58:52 +0200 Subject: [PATCH] SONAR-4301 Remove project_id when querying issues --- .../org/sonar/core/issue/db/IssueDao.java | 17 ++--- .../org/sonar/core/issue/db/IssueMapper.java | 2 +- .../org/sonar/core/issue/db/IssueMapper.xml | 21 +++--- .../org/sonar/core/issue/db/IssueDaoTest.java | 67 +++++++++---------- .../server/issue/DefaultIssueFinder.java | 2 +- .../server/issue/DefaultIssueFinderTest.java | 6 +- 6 files changed, 59 insertions(+), 56 deletions(-) diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java index 9c46d100585..7489e27e786 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java @@ -71,19 +71,20 @@ public class IssueDao implements BatchComponent, ServerComponent { } @VisibleForTesting - List selectIssueAndProjectIds(IssueQuery query, Collection authorizedRootProjectIds, Integer maxResult) { + List selectIssues(IssueQuery query, Collection authorizedRootProjectIds, Integer maxResult) { SqlSession session = mybatis.openSession(); try { - return selectIssueAndProjectIds(query, authorizedRootProjectIds, maxResult, session); + return selectIssues(query, authorizedRootProjectIds, maxResult, session); } finally { MyBatis.closeQuietly(session); } } - List selectIssueAndProjectIds(IssueQuery query, Collection authorizedRootProjectIds) { + @VisibleForTesting + List selectIssues(IssueQuery query, Collection authorizedRootProjectIds) { SqlSession session = mybatis.openSession(); try { - return selectIssueAndProjectIds(query, authorizedRootProjectIds, Integer.MAX_VALUE, session); + return selectIssues(query, authorizedRootProjectIds, Integer.MAX_VALUE, session); } finally { MyBatis.closeQuietly(session); } @@ -92,17 +93,17 @@ public class IssueDao implements BatchComponent, ServerComponent { /** * The returned IssueDto list contains only the issue id, the project id and the sort column */ - public List selectIssueAndProjectIds(IssueQuery query, Collection authorizedRootProjectIds, SqlSession session){ - return selectIssueAndProjectIds(query, authorizedRootProjectIds, query.maxResults(), session); + public List selectIssues(IssueQuery query, Collection authorizedRootProjectIds, SqlSession session){ + return selectIssues(query, authorizedRootProjectIds, query.maxResults(), session); } - private List selectIssueAndProjectIds(IssueQuery query, Collection authorizedRootProjectIds, Integer maxResults, SqlSession session){ + private List selectIssues(IssueQuery query, Collection authorizedRootProjectIds, Integer maxResults, SqlSession session){ if (authorizedRootProjectIds.isEmpty()) { return Collections.emptyList(); } IssueMapper mapper = session.getMapper(IssueMapper.class); List> idsPartition = Lists.partition(newArrayList(authorizedRootProjectIds), 1000); - return mapper.selectIssueAndProjectIds(query, idsPartition, maxResults); + return mapper.selectIssues(query, idsPartition, maxResults); } @VisibleForTesting diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java index 210f04a3d15..59826460c46 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java @@ -30,7 +30,7 @@ public interface IssueMapper { List selectNonClosedIssues(int rootComponentId); - List selectIssueAndProjectIds(@Param("query") IssueQuery query, @Param("authorizedRootProjectIds") List> authorizedRootProjectIds, + List selectIssues(@Param("query") IssueQuery query, @Param("authorizedRootProjectIds") List> authorizedRootProjectIds, @Param("maxResults") Integer maxResult); void insert(IssueDto issue); diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml index 90e60093e22..2b2f9f5969c 100644 --- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml @@ -30,8 +30,12 @@ i.updated_at as updatedAt, r.plugin_rule_key as ruleKey, r.plugin_name as ruleRepo, - p.kee as componentKey, - root.kee as projectKey + p.kee as componentKey + + + + + , root.kee as projectKey @@ -113,14 +117,14 @@ select - + from issues i, rules r, projects p, projects root and @@ -146,8 +150,8 @@ - + select i.id @@ -163,7 +167,7 @@ - from issues i, projects p, rules r, projects root + from issues i, projects p, rules r , projects rootprojects, snapshots rootsnapshots, snapshots s @@ -172,7 +176,6 @@ and i.resource_id=p.id - and i.project_id=root.id and diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java index 5c262b7d813..c7bc22653c8 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java @@ -81,13 +81,13 @@ public class IssueDaoTest extends AbstractDaoTestCase { setupData("shared", "should_select_by_rules"); IssueQuery query = IssueQuery.builder().rules(newArrayList(RuleKey.of("squid", "AvoidCycle"))).build(); - assertThat(dao.selectIssueAndProjectIds(query, newArrayList(399))).hasSize(2); + assertThat(dao.selectIssues(query, newArrayList(399))).hasSize(2); query = IssueQuery.builder().rules(newArrayList(RuleKey.of("squid", "AvoidCycle"), RuleKey.of("squid", "NullRef"))).build(); - assertThat(dao.selectIssueAndProjectIds(query, newArrayList(399))).hasSize(3); + assertThat(dao.selectIssues(query, newArrayList(399))).hasSize(3); query = IssueQuery.builder().rules(newArrayList(RuleKey.of("squid", "Other"))).build(); - assertThat(dao.selectIssueAndProjectIds(query, newArrayList(399))).isEmpty(); + assertThat(dao.selectIssues(query, newArrayList(399))).isEmpty(); } @Test @@ -95,10 +95,10 @@ public class IssueDaoTest extends AbstractDaoTestCase { setupData("shared", "should_select_by_date_creation"); IssueQuery query = IssueQuery.builder().createdAfter(DateUtils.parseDate("2013-04-15")).build(); - assertThat(dao.selectIssueAndProjectIds(query, newArrayList(399))).hasSize(1); + assertThat(dao.selectIssues(query, newArrayList(399))).hasSize(1); query = IssueQuery.builder().createdBefore(DateUtils.parseDate("2013-04-17")).build(); - assertThat(dao.selectIssueAndProjectIds(query, newArrayList(399))).hasSize(2); + assertThat(dao.selectIssues(query, newArrayList(399))).hasSize(2); } @Test @@ -106,24 +106,24 @@ public class IssueDaoTest extends AbstractDaoTestCase { setupData("shared", "should_select_by_component_root"); IssueQuery query = IssueQuery.builder().componentRoots(newArrayList("struts")).build(); - List issues = newArrayList(dao.selectIssueAndProjectIds(query, newArrayList(399))); + List issues = newArrayList(dao.selectIssues(query, newArrayList(399))); assertThat(issues).hasSize(2); assertThat(issues.get(0).getId()).isEqualTo(100); assertThat(issues.get(1).getId()).isEqualTo(101); query = IssueQuery.builder().componentRoots(newArrayList("struts-core")).build(); - issues = newArrayList(dao.selectIssueAndProjectIds(query, newArrayList(399))); + issues = newArrayList(dao.selectIssues(query, newArrayList(399))); assertThat(issues).hasSize(2); assertThat(issues.get(0).getId()).isEqualTo(100); assertThat(issues.get(1).getId()).isEqualTo(101); query = IssueQuery.builder().componentRoots(newArrayList("Filter.java")).build(); - issues = newArrayList(dao.selectIssueAndProjectIds(query, newArrayList(399))); + issues = newArrayList(dao.selectIssues(query, newArrayList(399))); assertThat(issues).hasSize(1); assertThat(issues.get(0).getId()).isEqualTo(101); query = IssueQuery.builder().componentRoots(newArrayList("not-found")).build(); - issues = newArrayList(dao.selectIssueAndProjectIds(query, newArrayList(399))); + issues = newArrayList(dao.selectIssues(query, newArrayList(399))); assertThat(issues).isEmpty(); } @@ -132,15 +132,15 @@ public class IssueDaoTest extends AbstractDaoTestCase { setupData("shared", "should_select_by_assigned"); IssueQuery query = IssueQuery.builder().assigned(true).build(); - List issues = newArrayList(dao.selectIssueAndProjectIds(query, newArrayList(399))); + List issues = newArrayList(dao.selectIssues(query, newArrayList(399))); assertThat(issues).hasSize(2); query = IssueQuery.builder().assigned(false).build(); - issues = newArrayList(dao.selectIssueAndProjectIds(query, newArrayList(399))); + issues = newArrayList(dao.selectIssues(query, newArrayList(399))); assertThat(issues).hasSize(1); query = IssueQuery.builder().assigned(null).build(); - issues = newArrayList(dao.selectIssueAndProjectIds(query, newArrayList(399))); + issues = newArrayList(dao.selectIssues(query, newArrayList(399))); assertThat(issues).hasSize(3); } @@ -149,15 +149,15 @@ public class IssueDaoTest extends AbstractDaoTestCase { setupData("shared", "should_select_by_planned"); IssueQuery query = IssueQuery.builder().planned(true).build(); - List issues = newArrayList(dao.selectIssueAndProjectIds(query, newArrayList(399))); + List issues = newArrayList(dao.selectIssues(query, newArrayList(399))); assertThat(issues).hasSize(2); query = IssueQuery.builder().planned(false).build(); - issues = newArrayList(dao.selectIssueAndProjectIds(query, newArrayList(399))); + issues = newArrayList(dao.selectIssues(query, newArrayList(399))); assertThat(issues).hasSize(1); query = IssueQuery.builder().planned(null).build(); - issues = newArrayList(dao.selectIssueAndProjectIds(query, newArrayList(399))); + issues = newArrayList(dao.selectIssues(query, newArrayList(399))); assertThat(issues).hasSize(3); } @@ -166,15 +166,15 @@ public class IssueDaoTest extends AbstractDaoTestCase { setupData("shared", "should_select_by_resolved"); IssueQuery query = IssueQuery.builder().resolved(true).build(); - List issues = newArrayList(dao.selectIssueAndProjectIds(query, newArrayList(399))); + List issues = newArrayList(dao.selectIssues(query, newArrayList(399))); assertThat(issues).hasSize(2); query = IssueQuery.builder().resolved(false).build(); - issues = newArrayList(dao.selectIssueAndProjectIds(query, newArrayList(399))); + issues = newArrayList(dao.selectIssues(query, newArrayList(399))); assertThat(issues).hasSize(1); query = IssueQuery.builder().resolved(null).build(); - issues = newArrayList(dao.selectIssueAndProjectIds(query, newArrayList(399))); + issues = newArrayList(dao.selectIssues(query, newArrayList(399))); assertThat(issues).hasSize(3); } @@ -183,13 +183,13 @@ public class IssueDaoTest extends AbstractDaoTestCase { setupData("shared", "should_select_by_action_plans"); IssueQuery query = IssueQuery.builder().actionPlans(newArrayList("ABC")).build(); - assertThat(dao.selectIssueAndProjectIds(query, newArrayList(399))).hasSize(2); + assertThat(dao.selectIssues(query, newArrayList(399))).hasSize(2); query = IssueQuery.builder().actionPlans(newArrayList("ABC", "DEF")).build(); - assertThat(dao.selectIssueAndProjectIds(query, newArrayList(399))).hasSize(3); + assertThat(dao.selectIssues(query, newArrayList(399))).hasSize(3); query = IssueQuery.builder().actionPlans(newArrayList("")).build(); - assertThat(dao.selectIssueAndProjectIds(query, newArrayList(399))).isEmpty(); + assertThat(dao.selectIssues(query, newArrayList(399))).isEmpty(); } @Test @@ -197,54 +197,53 @@ public class IssueDaoTest extends AbstractDaoTestCase { setupData("shared", "should_select_all"); IssueQuery query = IssueQuery.builder().build(); - assertThat(dao.selectIssueAndProjectIds(query, newArrayList(399))).hasSize(3); + assertThat(dao.selectIssues(query, newArrayList(399))).hasSize(3); } @Test - public void should_select_issue_and_project_ids() { + public void should_select_issues() { setupData("shared", "should_select_issue_and_project_ids"); IssueQuery query = IssueQuery.builder().build(); - List results = dao.selectIssueAndProjectIds(query, newArrayList(399)); + List results = dao.selectIssues(query, newArrayList(399)); assertThat(results).hasSize(3); IssueDto issueDto = results.get(0); assertThat(issueDto.getId()).isNotNull(); - assertThat(issueDto.getProjectId()).isNotNull(); - results = dao.selectIssueAndProjectIds(query, Collections.emptyList()); + results = dao.selectIssues(query, Collections.emptyList()); assertThat(results).isEmpty(); - results = dao.selectIssueAndProjectIds(query, newArrayList(399), 2); + results = dao.selectIssues(query, newArrayList(399), 2); assertThat(results).hasSize(2); } @Test - public void should_select_issue_and_project_ids_with_sort_column() { + public void should_select_issues_with_sort_column() { setupData("shared", "should_select_issue_and_project_ids"); IssueQuery query = IssueQuery.builder().sort(IssueQuery.Sort.ASSIGNEE).build(); - List results = dao.selectIssueAndProjectIds(query, newArrayList(399)); + List results = dao.selectIssues(query, newArrayList(399)); assertThat(results.get(0).getAssignee()).isNotNull(); query = IssueQuery.builder().sort(IssueQuery.Sort.SEVERITY).build(); - results = dao.selectIssueAndProjectIds(query, newArrayList(399)); + results = dao.selectIssues(query, newArrayList(399)); assertThat(results.get(0).getSeverity()).isNotNull(); query = IssueQuery.builder().sort(IssueQuery.Sort.STATUS).build(); - results = dao.selectIssueAndProjectIds(query, newArrayList(399)); + results = dao.selectIssues(query, newArrayList(399)); assertThat(results.get(0).getStatus()).isNotNull(); query = IssueQuery.builder().sort(IssueQuery.Sort.CREATION_DATE).build(); - results = dao.selectIssueAndProjectIds(query, newArrayList(399)); + results = dao.selectIssues(query, newArrayList(399)); assertThat(results.get(0).getIssueCreationDate()).isNotNull(); query = IssueQuery.builder().sort(IssueQuery.Sort.UPDATE_DATE).build(); - results = dao.selectIssueAndProjectIds(query, newArrayList(399)); + results = dao.selectIssues(query, newArrayList(399)); assertThat(results.get(0).getIssueUpdateDate()).isNotNull(); query = IssueQuery.builder().sort(IssueQuery.Sort.CLOSE_DATE).build(); - results = dao.selectIssueAndProjectIds(query, newArrayList(399)); + results = dao.selectIssues(query, newArrayList(399)); assertThat(results.get(0).getIssueCloseDate()).isNotNull(); } diff --git a/sonar-server/src/main/java/org/sonar/server/issue/DefaultIssueFinder.java b/sonar-server/src/main/java/org/sonar/server/issue/DefaultIssueFinder.java index b95d56f7a45..14ea062275b 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/DefaultIssueFinder.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/DefaultIssueFinder.java @@ -101,7 +101,7 @@ public class DefaultIssueFinder implements IssueFinder { Collection rootProjectIds = authorizationDao.selectAuthorizedRootProjectsIds(UserSession.get().userId(), query.requiredRole(), sqlSession); // 2. Select the authorized ids of all the issues that match the query - List authorizedIssues = issueDao.selectIssueAndProjectIds(query, rootProjectIds, sqlSession); + List authorizedIssues = issueDao.selectIssues(query, rootProjectIds, sqlSession); // 3. Sort all authorized issues List authorizedSortedIssues = sort(authorizedIssues, query, authorizedIssues.size()); diff --git a/sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java b/sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java index fd0fd24063e..2acdecc2cc3 100644 --- a/sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java +++ b/sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java @@ -83,7 +83,7 @@ public class DefaultIssueFinderTest { when(issueDao.selectByIds(anyCollection(), any(SqlSession.class))).thenReturn(dtoList); IssueQueryResult results = finder.find(query); - verify(issueDao).selectIssueAndProjectIds(eq(query), eq(newHashSet(100)), any(SqlSession.class)); + verify(issueDao).selectIssues(eq(query), eq(newHashSet(100)), any(SqlSession.class)); assertThat(results.issues()).hasSize(2); Issue issue = results.issues().iterator().next(); @@ -111,7 +111,7 @@ public class DefaultIssueFinderTest { .setRuleKey_unit_test_only("squid", "AvoidCycle") .setStatus("OPEN").setResolution("OPEN"); List dtoList = newArrayList(issue1, issue2); - when(issueDao.selectIssueAndProjectIds(eq(query), eq(newHashSet(100)), any(SqlSession.class))).thenReturn(dtoList); + when(issueDao.selectIssues(eq(query), eq(newHashSet(100)), any(SqlSession.class))).thenReturn(dtoList); when(issueDao.selectByIds(anyCollection(), any(SqlSession.class))).thenReturn(dtoList); IssueQueryResult results = finder.find(query); @@ -252,7 +252,7 @@ public class DefaultIssueFinderTest { public void should_get_empty_result_when_no_issue() { grantAccessRights(); IssueQuery query = IssueQuery.builder().build(); - when(issueDao.selectIssueAndProjectIds(eq(query), anyCollection(), any(SqlSession.class))).thenReturn(Collections.emptyList()); + when(issueDao.selectIssues(eq(query), anyCollection(), any(SqlSession.class))).thenReturn(Collections.emptyList()); when(issueDao.selectByIds(anyCollection(), any(SqlSession.class))).thenReturn(Collections.emptyList()); IssueQueryResult results = finder.find(query); -- 2.39.5