aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
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 /sonar-db
parent2d9bae8c4d2d03c0cccd77d567678af84ed271d5 (diff)
downloadsonarqube-d3a59c7cd59ac7dd3328ef25172542dd30f376fd.tar.gz
sonarqube-d3a59c7cd59ac7dd3328ef25172542dd30f376fd.zip
Remove ResourceIndexDao.indexProjects()
Diffstat (limited to 'sonar-db')
-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
5 files changed, 28 insertions, 59 deletions
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);