aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-12-30 18:55:14 +0100
committersimonbrandhof <simon.brandhof@gmail.com>2011-12-30 18:55:14 +0100
commit981885cad7f17858718c7e905868befc568e9f8f (patch)
tree67cda52bcb87a8776ffc539dfd50489d064723eb /sonar-batch
parentff9d267c623de885c6a02f6ed4c6831084009a58 (diff)
downloadsonarqube-981885cad7f17858718c7e905868befc568e9f8f.tar.gz
sonarqube-981885cad7f17858718c7e905868befc568e9f8f.zip
SONAR-983 index the project from a dedicated post-job in order to optimize SQL requests
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java8
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java14
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java3
4 files changed, 8 insertions, 19 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java
index b40aa67a45a..21f6824c713 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java
@@ -27,7 +27,6 @@ import org.sonar.batch.MavenPluginExecutor;
import org.sonar.batch.ServerMetadata;
import org.sonar.batch.config.BatchSettings;
import org.sonar.batch.config.BatchSettingsEnhancer;
-import org.sonar.core.resource.ResourceIndexer;
import org.sonar.jpa.session.DatabaseSessionProvider;
import org.sonar.jpa.session.DefaultDatabaseConnector;
import org.sonar.jpa.session.ThreadLocalDatabaseSessionFactory;
@@ -67,7 +66,6 @@ public class BootstrapModule extends Module {
addCoreSingleton(BatchDatabase.class);
addCoreSingleton(MyBatis.class);
- addCoreSingleton(ResourceIndexer.class);
addCoreSingleton(DefaultDatabaseConnector.class);
addCoreSingleton(ThreadLocalDatabaseSessionFactory.class);
for (Class daoClass : DaoUtils.getDaoClasses()) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
index 5386b61414d..57037c987fd 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
@@ -27,8 +27,6 @@ import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.*;
import org.sonar.api.utils.SonarException;
-import org.sonar.core.resource.ResourceIndexer;
-import org.sonar.core.resource.ResourceIndexerDao;
import javax.persistence.NonUniqueResultException;
import javax.persistence.Query;
@@ -41,11 +39,9 @@ public final class DefaultResourcePersister implements ResourcePersister {
private DatabaseSession session;
private Map<Resource, Snapshot> snapshotsByResource = Maps.newHashMap();
- private ResourceIndexer indexer;
- public DefaultResourcePersister(DatabaseSession session, ResourceIndexer indexer) {
+ public DefaultResourcePersister(DatabaseSession session) {
this.session = session;
- this.indexer = indexer;
}
public Snapshot saveProject(Project project, Project parent) {
@@ -84,7 +80,6 @@ public final class DefaultResourcePersister implements ResourcePersister {
snapshot.setCreatedAt(project.getAnalysisDate());
snapshot = session.save(snapshot);
session.commit();
- indexer.index(project.getName(), snapshot.getQualifier(), snapshot.getResourceId(), snapshot.getRootProjectId());
return snapshot;
}
@@ -134,7 +129,6 @@ public final class DefaultResourcePersister implements ResourcePersister {
} else {
snapshot = persistFileOrDirectory(project, resource, parent);
}
- indexer.index(resource.getName(), snapshot.getQualifier(), snapshot.getResourceId(), snapshot.getRootProjectId());
return snapshot;
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java
index 35277ff3436..3491738c922 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java
@@ -26,7 +26,6 @@ import org.sonar.api.resources.JavaPackage;
import org.sonar.api.resources.Library;
import org.sonar.api.resources.Project;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
-import org.sonar.core.resource.ResourceIndexer;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -34,7 +33,6 @@ import java.text.SimpleDateFormat;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
-import static org.mockito.Mockito.mock;
public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
@@ -67,7 +65,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
public void shouldSaveNewProject() {
setupData("shared");
- ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourceIndexer.class));
+ ResourcePersister persister = new DefaultResourcePersister(getSession());
persister.saveProject(singleProject, null);
checkTables("shouldSaveNewProject", "projects", "snapshots");
@@ -77,7 +75,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
public void shouldSaveNewMultiModulesProject() throws ParseException {
setupData("shared");
- ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourceIndexer.class));
+ ResourcePersister persister = new DefaultResourcePersister(getSession());
persister.saveProject(multiModuleProject, null);
persister.saveProject(moduleA, multiModuleProject);
persister.saveProject(moduleB, multiModuleProject);
@@ -90,7 +88,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
public void shouldSaveNewDirectory() {
setupData("shared");
- ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourceIndexer.class));
+ ResourcePersister persister = new DefaultResourcePersister(getSession());
persister.saveProject(singleProject, null);
persister.saveResource(singleProject, new JavaPackage("org.foo").setEffectiveKey("foo:org.foo"));
@@ -102,7 +100,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
public void shouldSaveNewLibrary() {
setupData("shared");
- ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourceIndexer.class));
+ ResourcePersister persister = new DefaultResourcePersister(getSession());
persister.saveProject(singleProject, null);
persister.saveResource(singleProject, new Library("junit:junit", "4.8.2").setEffectiveKey("junit:junit"));
persister.saveResource(singleProject, new Library("junit:junit", "4.8.2").setEffectiveKey("junit:junit"));// do nothing, already saved
@@ -115,7 +113,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
public void shouldClearResourcesExceptProjects() {
setupData("shared");
- DefaultResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourceIndexer.class));
+ DefaultResourcePersister persister = new DefaultResourcePersister(getSession());
persister.saveProject(multiModuleProject, null);
persister.saveProject(moduleA, multiModuleProject);
persister.saveResource(moduleA, new JavaPackage("org.foo").setEffectiveKey("a:org.foo"));
@@ -131,7 +129,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
public void shouldUpdateExistingResource() {
setupData("shouldUpdateExistingResource");
- ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourceIndexer.class));
+ ResourcePersister persister = new DefaultResourcePersister(getSession());
singleProject.setName("new name");
singleProject.setDescription("new description");
persister.saveProject(singleProject, null);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java b/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java
index 21b784d1ff3..320db8e9608 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java
@@ -24,7 +24,6 @@ import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
import org.sonar.batch.ServerMetadata;
import org.sonar.batch.index.DefaultResourcePersister;
-import org.sonar.core.resource.ResourceIndexer;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
import javax.persistence.Query;
@@ -51,7 +50,7 @@ public class UpdateStatusJobTest extends AbstractDbUnitTestCase {
private void assertAnalysis(int snapshotId, String fixture) {
setupData("sharedFixture", fixture);
DatabaseSession session = getSession();
- UpdateStatusJob sensor = new UpdateStatusJob(mock(ServerMetadata.class), session, new DefaultResourcePersister(session, mock(ResourceIndexer.class)), loadSnapshot(snapshotId));
+ UpdateStatusJob sensor = new UpdateStatusJob(mock(ServerMetadata.class), session, new DefaultResourcePersister(session), loadSnapshot(snapshotId));
sensor.execute();
getSession().stop();