aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-05-10 14:07:19 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-05-10 15:05:57 +0200
commitd3a59c7cd59ac7dd3328ef25172542dd30f376fd (patch)
treed2b0329bbc65ffd8d472d9e5ae6407483516469b
parent2d9bae8c4d2d03c0cccd77d567678af84ed271d5 (diff)
downloadsonarqube-d3a59c7cd59ac7dd3328ef25172542dd30f376fd.tar.gz
sonarqube-d3a59c7cd59ac7dd3328ef25172542dd30f376fd.zip
Remove ResourceIndexDao.indexProjects()
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java14
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java2
-rw-r--r--sonar-db/src/main/java/org/sonar/db/component/ResourceIndexDao.java30
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexMapper.xml8
-rw-r--r--sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java26
-rw-r--r--sonar-db/src/test/java/org/sonar/db/component/ComponentDbTester.java12
-rw-r--r--sonar-db/src/test/java/org/sonar/db/component/ResourceIndexDaoTest.java11
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
</select>
- <select id="selectRootProjectIds" parameterType="map" resultType="int">
- select distinct root_project_id
- from snapshots
- where islast=${_true}
- and scope='PRJ'
- and qualifier in ('TRK', 'VW', 'SVW')
- </select>
-
<select id="selectMasterIndexByResourceId" parameterType="long" resultType="ResourceIndex">
select kee as "key", resource_id as "resourceId"
from resource_index
diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java
index 6c4308fd068..7ea5b6ad6c9 100644
--- a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java
@@ -695,7 +695,7 @@ public class ComponentDaoTest {
for (int i = 9; i >= 1; i--) {
componentDb.insertProjectAndSnapshot(newProjectDto().setName("project-" + i));
}
- componentDb.indexProjectsAndViews();
+ componentDb.indexAllComponents();
ComponentQuery query = ComponentQuery.builder().setNameOrKeyQuery("oJect").setQualifiers(Qualifiers.PROJECT).build();
List<ComponentDto> result = underTest.selectByQuery(dbSession, query, 1, 3);
@@ -708,7 +708,7 @@ public class ComponentDaoTest {
@Test
public void select_by_query_name_with_special_characters() {
componentDb.insertProjectAndSnapshot(newProjectDto().setName("project-\\_%/-name"));
- componentDb.indexProjectsAndViews();
+ componentDb.indexAllComponents();
ComponentQuery query = ComponentQuery.builder().setNameOrKeyQuery("-\\_%/-").setQualifiers(Qualifiers.PROJECT).build();
List<ComponentDto> result = underTest.selectByQuery(dbSession, query, 0, 10);
@@ -720,7 +720,7 @@ public class ComponentDaoTest {
@Test
public void select_by_query_key_with_special_characters() {
componentDb.insertProjectAndSnapshot(newProjectDto().setKey("project-_%-key"));
- componentDb.indexProjectsAndViews();
+ componentDb.indexAllComponents();
ComponentQuery query = ComponentQuery.builder().setNameOrKeyQuery("project-_%-key").setQualifiers(Qualifiers.PROJECT).build();
List<ComponentDto> result = underTest.selectByQuery(dbSession, query, 0, 10);
@@ -749,7 +749,7 @@ public class ComponentDaoTest {
componentDb.insertComponentAndSnapshot(newFileDto(project, "file-1-uuid"), projectSnapshot);
componentDb.insertComponentAndSnapshot(newFileDto(project, "file-2-uuid"), moduleSnapshot);
db.commit();
- componentDb.indexProjectsAndViews();
+ componentDb.indexAllComponents();
ComponentTreeQuery query = newTreeQuery(projectSnapshot).build();
@@ -768,7 +768,7 @@ public class ComponentDaoTest {
componentDb.insertComponentAndSnapshot(newFileDto(project, "file-1-uuid").setName("file-name-1"), projectSnapshot);
componentDb.insertComponentAndSnapshot(newFileDto(project, "file-2-uuid").setName("file-name-2"), moduleSnapshot);
db.commit();
- componentDb.indexProjectsAndViews();
+ componentDb.indexAllComponents();
ComponentTreeQuery query = newTreeQuery(projectSnapshot)
.setNameOrKeyQuery("file-name").build();
@@ -788,7 +788,7 @@ public class ComponentDaoTest {
componentDb.insertComponentAndSnapshot(newFileDto(project, "file-1-uuid").setKey("file-key-1").setName("File one"), projectSnapshot);
componentDb.insertComponentAndSnapshot(newFileDto(project, "file-2-uuid").setKey("file-key-2").setName("File two"), moduleSnapshot);
db.commit();
- componentDb.indexProjectsAndViews();
+ componentDb.indexAllComponents();
ComponentTreeQuery query = newTreeQuery(projectSnapshot)
.setNameOrKeyQuery("file-key-1").build();
@@ -808,7 +808,7 @@ public class ComponentDaoTest {
componentDb.insertComponentAndSnapshot(newFileDto(project, "file-uuid-" + i), projectSnapshot);
}
db.commit();
- componentDb.indexProjectsAndViews();
+ componentDb.indexAllComponents();
ComponentTreeQuery query = newTreeQuery(projectSnapshot)
.setPage(2)
@@ -831,7 +831,7 @@ public class ComponentDaoTest {
componentDb.insertComponentAndSnapshot(newFileDto(project, "file-uuid-2").setName("file-name-2").setPath("2"), projectSnapshot);
componentDb.insertComponentAndSnapshot(newFileDto(project, "file-uuid-3").setName("file-name-3").setPath("1"), projectSnapshot);
db.commit();
- componentDb.indexProjectsAndViews();
+ componentDb.indexAllComponents();
ComponentTreeQuery query = newTreeQuery(projectSnapshot)
.setSortFields(singletonList("path"))
@@ -851,7 +851,7 @@ public class ComponentDaoTest {
componentDb.insertComponentAndSnapshot(newFileDto(project, "file-1-uuid"), projectSnapshot);
componentDb.insertComponentAndSnapshot(newFileDto(project, "file-2-uuid"), moduleSnapshot);
db.commit();
- componentDb.indexProjectsAndViews();
+ componentDb.indexAllComponents();
ComponentTreeQuery query = newTreeQuery(moduleSnapshot).build();
@@ -868,7 +868,7 @@ public class ComponentDaoTest {
componentDb.insertComponentAndSnapshot(newFileDto(project, "file-1-uuid"), projectSnapshot);
componentDb.insertComponentAndSnapshot(newFileDto(project, "file-2-uuid"), moduleSnapshot);
db.commit();
- componentDb.indexProjectsAndViews();
+ componentDb.indexAllComponents();
ComponentTreeQuery query = newTreeQuery(projectSnapshot).build();
@@ -890,7 +890,7 @@ public class ComponentDaoTest {
ComponentDto project = newProjectDto("project-uuid").setName("project-name");
componentDb.insertProjectAndSnapshot(project);
componentDb.insertComponentAndSnapshot(newProjectCopy("project-copy-uuid", project, view), viewSnapshot);
- componentDb.indexProjectsAndViews();
+ componentDb.indexAllComponents();
ComponentTreeQuery dbQuery = newTreeQuery(viewSnapshot).build();
List<ComponentDtoWithSnapshotId> components = underTest.selectDirectChildren(dbSession, dbQuery);
@@ -909,7 +909,7 @@ public class ComponentDaoTest {
ComponentDto project = newProjectDto("project-uuid").setName("project name");
componentDb.insertProjectAndSnapshot(project);
componentDb.insertComponentAndSnapshot(newProjectCopy("project-copy-uuid", project, view), viewSnapshot);
- componentDb.indexProjectsAndViews();
+ componentDb.indexAllComponents();
ComponentTreeQuery dbQuery = newTreeQuery(viewSnapshot).setNameOrKeyQuery("name").build();
List<ComponentDtoWithSnapshotId> components = underTest.selectDirectChildren(dbSession, dbQuery);
@@ -928,7 +928,7 @@ public class ComponentDaoTest {
componentDb.insertComponentAndSnapshot(newFileDto(project, "file-uuid-" + i).setName("file-name-" + i), moduleSnapshot);
}
db.commit();
- componentDb.indexProjectsAndViews();
+ componentDb.indexAllComponents();
ComponentTreeQuery query = newTreeQuery(projectSnapshot)
.setQualifiers(newArrayList(Qualifiers.FILE))
diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentDbTester.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentDbTester.java
index 389e674b6e8..8666df9742a 100644
--- a/sonar-db/src/test/java/org/sonar/db/component/ComponentDbTester.java
+++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentDbTester.java
@@ -19,6 +19,8 @@
*/
package org.sonar.db.component;
+import java.util.List;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
@@ -83,8 +85,14 @@ public class ComponentDbTester {
db.commit();
}
- public void indexProjectsAndViews() {
- dbClient.componentIndexDao().indexProjects();
+ public void indexAllComponents() {
+ ComponentQuery dbQuery = ComponentQuery.builder()
+ .setQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW, "DEV")
+ .build();
+ List<ComponentDto> rootProjects = dbClient.componentDao().selectByQuery(dbSession, dbQuery, 0, Integer.MAX_VALUE);
+ for (ComponentDto project : rootProjects) {
+ dbClient.componentIndexDao().indexProject(dbSession, project.getId());
+ }
db.commit();
}
diff --git a/sonar-db/src/test/java/org/sonar/db/component/ResourceIndexDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ResourceIndexDaoTest.java
index 092b7ba651a..c1735a9da54 100644
--- a/sonar-db/src/test/java/org/sonar/db/component/ResourceIndexDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/component/ResourceIndexDaoTest.java
@@ -53,15 +53,6 @@ public class ResourceIndexDaoTest {
}
@Test
- public void shouldIndexProjects() {
- dbTester.prepareDbUnit(getClass(), "shouldIndexProjects.xml");
-
- underTest.indexProjects();
-
- dbTester.assertDbUnit(getClass(), "shouldIndexProjects-result.xml", new String[] {"id"}, "resource_index");
- }
-
- @Test
public void shouldIndexMultiModulesProject() {
dbTester.prepareDbUnit(getClass(), "shouldIndexMultiModulesProject.xml");
@@ -163,7 +154,7 @@ public class ResourceIndexDaoTest {
dbTester.getDbClient().componentDao().insert(session, project);
dbTester.getDbClient().snapshotDao().insert(session, new SnapshotDto().setComponentId(project.getId()).setRootProjectId(project.getId()).setLast(true));
- underTest.indexProject(project.getId(), session);
+ underTest.indexProject(session, project.getId());
session.commit();
assertThat(dbTester.countRowsOfTable("resource_index")).isEqualTo(longName.length() - ResourceIndexDao.MINIMUM_KEY_SIZE + 1);