From d3a59c7cd59ac7dd3328ef25172542dd30f376fd Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Tue, 10 May 2016 14:07:19 +0200 Subject: [PATCH] Remove ResourceIndexDao.indexProjects() --- .../server/component/ws/TreeActionTest.java | 14 ++++----- .../SearchProjectPermissionsActionTest.java | 6 ++-- .../template/BulkApplyTemplateActionTest.java | 2 +- .../sonar/db/component/ResourceIndexDao.java | 30 +++---------------- .../db/component/ResourceIndexMapper.xml | 8 ----- .../sonar/db/component/ComponentDaoTest.java | 26 ++++++++-------- .../sonar/db/component/ComponentDbTester.java | 12 ++++++-- .../db/component/ResourceIndexDaoTest.java | 11 +------ 8 files changed, 39 insertions(+), 70 deletions(-) diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java index 81f47d59f97..9617ea2e474 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java @@ -118,7 +118,7 @@ public class TreeActionTest { SnapshotDto directorySnapshot = componentDb.insertComponentAndSnapshot(newDirectory(project, "directory-path-1"), moduleSnapshot); componentDb.insertComponentAndSnapshot(newFileDto(project, 10), directorySnapshot); db.commit(); - componentDb.indexProjectsAndViews(); + componentDb.indexAllComponents(); TreeWsResponse response = call(ws.newRequest() .setParam(PARAM_STRATEGY, "children") @@ -149,7 +149,7 @@ public class TreeActionTest { SnapshotDto directorySnapshot = componentDb.insertComponentAndSnapshot(newDirectory(project, "directory-path-1"), moduleSnapshot); componentDb.insertComponentAndSnapshot(newFileDto(project, 1), directorySnapshot); db.commit(); - componentDb.indexProjectsAndViews(); + componentDb.indexAllComponents(); TreeWsResponse response = call(ws.newRequest() .setParam(PARAM_STRATEGY, "all") @@ -175,7 +175,7 @@ public class TreeActionTest { SnapshotDto directorySnapshot = componentDb.insertComponentAndSnapshot(newDirectory(project, "directory-path-1"), moduleSnapshot); componentDb.insertComponentAndSnapshot(newFileDto(project, 3), directorySnapshot); db.commit(); - componentDb.indexProjectsAndViews(); + componentDb.indexAllComponents(); TreeWsResponse response = call(ws.newRequest() .setParam(PARAM_STRATEGY, "leaves") @@ -195,7 +195,7 @@ public class TreeActionTest { componentDb.insertComponentAndSnapshot(newFileDto(project, 2), projectSnapshot); componentDb.insertComponentAndSnapshot(newModuleDto("module-uuid-1", project), projectSnapshot); db.commit(); - componentDb.indexProjectsAndViews(); + componentDb.indexAllComponents(); TreeWsResponse response = call(ws.newRequest() .setParam(PARAM_STRATEGY, "all") @@ -215,7 +215,7 @@ public class TreeActionTest { componentDb.insertComponentAndSnapshot(module, projectSnapshot); componentDb.insertComponentAndSnapshot(newDirectory(project, "path/directory/", "directory-uuid-1"), projectSnapshot); db.commit(); - componentDb.indexProjectsAndViews(); + componentDb.indexAllComponents(); TreeWsResponse response = call(ws.newRequest() .setParam(PARAM_STRATEGY, "all") @@ -234,7 +234,7 @@ public class TreeActionTest { componentDb.insertComponentAndSnapshot(newProjectCopy("project-uuid-1-copy", project, view), viewSnapshot); componentDb.insertComponentAndSnapshot(newSubView(view, "sub-view-uuid", "sub-view-key").setName("sub-view-name"), viewSnapshot); db.commit(); - componentDb.indexProjectsAndViews(); + componentDb.indexAllComponents(); TreeWsResponse response = call(ws.newRequest() .setParam(PARAM_STRATEGY, "children") @@ -414,7 +414,7 @@ public class TreeActionTest { projectSnapshot); } db.commit(); - componentDb.indexProjectsAndViews(); + componentDb.indexAllComponents(); return project; } diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java index 73e96ee5aec..d2b05d5525d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java @@ -184,7 +184,7 @@ public class SearchProjectPermissionsActionTest { public void search_by_query_on_name() { componentDb.insertProjectAndSnapshot(newProjectDto().setName("project-name")); componentDb.insertProjectAndSnapshot(newProjectDto().setName("another-name")); - componentDb.indexProjectsAndViews(); + componentDb.indexAllComponents(); String result = ws.newRequest() .setParam(TEXT_QUERY, "project") @@ -198,7 +198,7 @@ public class SearchProjectPermissionsActionTest { public void search_by_query_on_key_must_match_exactly() { componentDb.insertProjectAndSnapshot(newProjectDto().setKey("project-key")); componentDb.insertProjectAndSnapshot(newProjectDto().setKey("another-key")); - componentDb.indexProjectsAndViews(); + componentDb.indexAllComponents(); String result = ws.newRequest() .setParam(TEXT_QUERY, "project-key") @@ -213,7 +213,7 @@ public class SearchProjectPermissionsActionTest { for (int i = 1; i <= 1001; i++) { componentDb.insertProjectAndSnapshot(newProjectDto("project-uuid-" + i)); } - componentDb.indexProjectsAndViews(); + componentDb.indexAllComponents(); String result = ws.newRequest() .setParam(TEXT_QUERY, "project") diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java index 8b3e5a8a9df..a85274eaa32 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java @@ -181,7 +181,7 @@ public class BulkApplyTemplateActionTest { // match must be exact on key ComponentDto projectUntouched = newProjectDto().setKey("new-sonar").setName("project-name"); componentDb.insertProjectAndSnapshot(projectUntouched); - componentDb.indexProjectsAndViews(); + componentDb.indexAllComponents(); call(ws.newRequest() .setParam(PARAM_TEMPLATE_ID, template1.getUuid()) diff --git a/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexDao.java b/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexDao.java index 74c67181f52..5081fb1fa10 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexDao.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexDao.java @@ -65,7 +65,7 @@ public class ResourceIndexDao extends AbstractDao { public ResourceIndexDao indexProject(final long rootProjectId) { DbSession session = myBatis().openSession(true); try { - indexProject(rootProjectId, session); + indexProject(session, rootProjectId); session.commit(); return this; @@ -74,34 +74,12 @@ public class ResourceIndexDao extends AbstractDao { } } - public void indexProject(final long rootProjectId, DbSession session) { + public void indexProject(DbSession session, final long rootProjectId) { ResourceIndexMapper mapper = session.getMapper(ResourceIndexMapper.class); - doIndexProject(rootProjectId, session, mapper); + doIndexProject(session, rootProjectId, mapper); } - /** - * This method is reentrant. It can be executed even if some projects are already indexed. - */ - public ResourceIndexDao indexProjects() { - final DbSession session = myBatis().openSession(true); - try { - final ResourceIndexMapper mapper = session.getMapper(ResourceIndexMapper.class); - session.select(ResourceIndexMapper.class.getName() + ".selectRootProjectIds", /* workaround to get booleans */ResourceIndexQuery.create(), new ResultHandler() { - @Override - public void handleResult(ResultContext context) { - Integer rootProjectId = (Integer) context.getResultObject(); - doIndexProject(rootProjectId, session, mapper); - session.commit(); - } - }); - return this; - - } finally { - MyBatis.closeQuietly(session); - } - } - - private void doIndexProject(long rootProjectId, SqlSession session, final ResourceIndexMapper mapper) { + private void doIndexProject(DbSession session, long rootProjectId, final ResourceIndexMapper mapper) { // non indexed resources ResourceIndexQuery query = ResourceIndexQuery.create() .setNonIndexedOnly(true) diff --git a/sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexMapper.xml b/sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexMapper.xml index 1228c975365..66265a1d3ef 100644 --- a/sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexMapper.xml @@ -44,14 +44,6 @@ order by p.id - -