diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2011-12-23 12:27:39 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2011-12-23 12:28:50 +0100 |
commit | dffb2a58206c68b7ae69cbcdebdfb7c30cdbf579 (patch) | |
tree | 5435e6cf451e9c8668d8a63ed4860c0564ffd559 /sonar-batch/src | |
parent | 5d6ab3e62e41fc1d9928156557c96c301bc50ce5 (diff) | |
download | sonarqube-dffb2a58206c68b7ae69cbcdebdfb7c30cdbf579.tar.gz sonarqube-dffb2a58206c68b7ae69cbcdebdfb7c30cdbf579.zip |
SONAR-983 provide the component org.sonar.core.resource.ResourceIndexer that is a layer over ResourceIndexerDao
+ move derby SQL files to org.sonar.core.persistence
Diffstat (limited to 'sonar-batch/src')
4 files changed, 15 insertions, 13 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 21f6824c713..b40aa67a45a 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,6 +27,7 @@ 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; @@ -66,6 +67,7 @@ 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 a681b32dabf..5386b61414d 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,6 +27,7 @@ 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; @@ -40,9 +41,9 @@ public final class DefaultResourcePersister implements ResourcePersister { private DatabaseSession session; private Map<Resource, Snapshot> snapshotsByResource = Maps.newHashMap(); - private ResourceIndexerDao indexer; + private ResourceIndexer indexer; - public DefaultResourcePersister(DatabaseSession session, ResourceIndexerDao indexer) { + public DefaultResourcePersister(DatabaseSession session, ResourceIndexer indexer) { this.session = session; this.indexer = indexer; } @@ -126,15 +127,14 @@ public final class DefaultResourcePersister implements ResourcePersister { if (resource instanceof Project) { // should not occur, please use the method saveProject() snapshot = persistProject((Project) resource, project); - indexer.index(resource.getName(), snapshot.getQualifier(), snapshot.getResourceId(), snapshot.getRootProjectId()); } else if (resource instanceof Library) { snapshot = persistLibrary(project, (Library) resource); } else { snapshot = persistFileOrDirectory(project, resource, parent); - indexer.index(resource.getName(), snapshot.getQualifier(), snapshot.getResourceId(), snapshot.getRootProjectId()); } + 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 7a7877287ea..35277ff3436 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,7 @@ 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.ResourceIndexerDao; +import org.sonar.core.resource.ResourceIndexer; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -67,7 +67,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase { public void shouldSaveNewProject() { setupData("shared"); - ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourceIndexerDao.class)); + ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourceIndexer.class)); persister.saveProject(singleProject, null); checkTables("shouldSaveNewProject", "projects", "snapshots"); @@ -77,7 +77,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase { public void shouldSaveNewMultiModulesProject() throws ParseException { setupData("shared"); - ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourceIndexerDao.class)); + ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourceIndexer.class)); persister.saveProject(multiModuleProject, null); persister.saveProject(moduleA, multiModuleProject); persister.saveProject(moduleB, multiModuleProject); @@ -90,7 +90,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase { public void shouldSaveNewDirectory() { setupData("shared"); - ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourceIndexerDao.class)); + ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourceIndexer.class)); persister.saveProject(singleProject, null); persister.saveResource(singleProject, new JavaPackage("org.foo").setEffectiveKey("foo:org.foo")); @@ -102,7 +102,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase { public void shouldSaveNewLibrary() { setupData("shared"); - ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourceIndexerDao.class)); + ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourceIndexer.class)); 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 +115,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase { public void shouldClearResourcesExceptProjects() { setupData("shared"); - DefaultResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourceIndexerDao.class)); + DefaultResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourceIndexer.class)); persister.saveProject(multiModuleProject, null); persister.saveProject(moduleA, multiModuleProject); persister.saveResource(moduleA, new JavaPackage("org.foo").setEffectiveKey("a:org.foo")); @@ -131,7 +131,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase { public void shouldUpdateExistingResource() { setupData("shouldUpdateExistingResource"); - ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourceIndexerDao.class)); + ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourceIndexer.class)); 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 d7d211fab8d..21b784d1ff3 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,8 +24,8 @@ 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 org.sonar.core.resource.ResourceIndexerDao; import javax.persistence.Query; @@ -51,7 +51,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(ResourceIndexerDao.class)), loadSnapshot(snapshotId)); + UpdateStatusJob sensor = new UpdateStatusJob(mock(ServerMetadata.class), session, new DefaultResourcePersister(session, mock(ResourceIndexer.class)), loadSnapshot(snapshotId)); sensor.execute(); getSession().stop(); |