]> source.dussan.org Git - sonarqube.git/commitdiff
Improve testability of Dao
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Sun, 5 Jul 2015 19:45:32 +0000 (21:45 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 6 Jul 2015 07:22:50 +0000 (09:22 +0200)
166 files changed:
server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/SourceDbBenchmarkTest.java
server/sonar-server/src/main/java/org/sonar/server/activity/ActivityService.java
server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityIndexer.java
server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityResultSetIterator.java
server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java
server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentDao.java
server/sonar-server/src/main/java/org/sonar/server/computation/ReportQueue.java
server/sonar-server/src/main/java/org/sonar/server/computation/activity/ActivityManager.java
server/sonar-server/src/main/java/org/sonar/server/computation/issue/BaseIssuesLoader.java
server/sonar-server/src/main/java/org/sonar/server/computation/issue/NewDebtAggregator.java
server/sonar-server/src/main/java/org/sonar/server/computation/issue/TrackerBaseInputFactory.java
server/sonar-server/src/main/java/org/sonar/server/computation/measure/MeasureRepositoryImpl.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/ApplyPermissionsStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/FeedDebtModelStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/FillMeasuresWithVariationsStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/IndexComponentsStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistEventsStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistIssuesStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistMeasuresStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistProjectLinksStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistSnapshotsStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistTestsStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/PurgeDatastoresStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/SwitchSnapshotStep.java
server/sonar-server/src/main/java/org/sonar/server/db/DbClient.java
server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrator.java
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/ChangeLogMigrationStep.java
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/ConvertProfileMeasuresMigrationStep.java
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationStep.java
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v45/DeleteMeasuresOnDeletedProfilesMigrationStep.java
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationStep.java
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationStep.java
server/sonar-server/src/main/java/org/sonar/server/duplication/ws/ShowAction.java
server/sonar-server/src/main/java/org/sonar/server/issue/IssueCommentService.java
server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java
server/sonar-server/src/main/java/org/sonar/server/issue/IssueStorage.java
server/sonar-server/src/main/java/org/sonar/server/issue/ServerIssueStorage.java
server/sonar-server/src/main/java/org/sonar/server/issue/actionplan/ActionPlanService.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueAuthorizationDao.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueAuthorizationIndexer.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndexer.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueResultSetIterator.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java
server/sonar-server/src/main/java/org/sonar/server/notification/NotificationService.java
server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/DatabaseMonitor.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java
server/sonar-server/src/main/java/org/sonar/server/platform/ws/StatusAction.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileCopier.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLoader.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLookup.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectLookup.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/BackupAction.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangeParentAction.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CreateAction.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeleteAction.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/InheritanceAction.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProjectsAction.java
server/sonar-server/src/main/java/org/sonar/server/rule/RuleCreator.java
server/sonar-server/src/main/java/org/sonar/server/search/IndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/source/index/FileSourcesUpdaterHelper.java
server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineIndexer.java
server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineResultSetIterator.java
server/sonar-server/src/main/java/org/sonar/server/startup/RegisterMetrics.java
server/sonar-server/src/main/java/org/sonar/server/startup/RenameIssueWidgets.java
server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexer.java
server/sonar-server/src/main/java/org/sonar/server/test/index/TestResultSetIterator.java
server/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
server/sonar-server/src/main/java/org/sonar/server/user/index/UserIndexer.java
server/sonar-server/src/main/java/org/sonar/server/user/index/UserResultSetIterator.java
server/sonar-server/src/main/java/org/sonar/server/user/ws/DeactivateAction.java
server/sonar-server/src/main/java/org/sonar/server/user/ws/SearchAction.java
server/sonar-server/src/main/java/org/sonar/server/user/ws/UpdateAction.java
server/sonar-server/src/test/java/org/sonar/server/activity/index/ActivityResultSetIteratorTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexComponentsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexSourceLinesStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexTestsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/db/DbClientTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/DatabaseMigratorTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/ConvertProfileMeasuresMigrationTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueStorageTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueStorageTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueAuthorizationDaoTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueResultSetIteratorTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java
server/sonar-server/src/test/java/org/sonar/server/source/db/FileSourceTesting.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/source/index/FileSourceTesting.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/source/index/SourceLineIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/source/index/SourceLineResultSetIteratorTest.java
server/sonar-server/src/test/java/org/sonar/server/test/db/TestTesting.java
server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/test/index/TestResultSetIteratorTest.java
server/sonar-server/src/test/java/org/sonar/server/user/index/UserResultSetIteratorTest.java
sonar-db/src/main/java/org/sonar/db/DaoUtils.java
sonar-db/src/main/java/org/sonar/db/DbClient.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/DbClient2.java [deleted file]
sonar-db/src/main/java/org/sonar/db/MyBatis.java
sonar-db/src/main/java/org/sonar/db/component/ResourceIndexDao.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/component/ResourceIndexMapper.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/component/ResourceIndexQuery.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerDao.java [deleted file]
sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerMapper.java [deleted file]
sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerQuery.java [deleted file]
sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexMapper.xml [new file with mode: 0644]
sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexerMapper.xml [deleted file]
sonar-db/src/test/java/org/sonar/db/AbstractDaoTestCase.java
sonar-db/src/test/java/org/sonar/db/DatabaseUtilsTest.java
sonar-db/src/test/java/org/sonar/db/DbTester.java
sonar-db/src/test/java/org/sonar/db/ResultSetIteratorTest.java
sonar-db/src/test/java/org/sonar/db/TestDb.java
sonar-db/src/test/java/org/sonar/db/component/ResourceDaoTest.java
sonar-db/src/test/java/org/sonar/db/component/ResourceIndexDaoTest.java [new file with mode: 0644]
sonar-db/src/test/java/org/sonar/db/component/ResourceIndexerDaoTest.java [deleted file]
sonar-db/src/test/java/org/sonar/db/issue/ActionPlanDaoTest.java
sonar-db/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java
sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
sonar-db/src/test/java/org/sonar/db/qualitygate/QualityGateConditionDaoTest.java
sonar-db/src/test/java/org/sonar/db/user/AuthorDaoTest.java
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/select_project_ids_from_query_and_view_or_sub_view_uuid.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexMultiModulesProject-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexMultiModulesProject.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexProjects-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexProjects.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexResource-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexResource.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexTwoLettersLongResource-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexTwoLettersLongResource.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldNotIndexPackages.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldNotReindexUnchangedResource-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldNotReindexUnchangedResource.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexNewTwoLettersLongResource-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexNewTwoLettersLongResource.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexTwoLettersLongResource-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexTwoLettersLongResource.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexProjectAfterRenaming-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexProjectAfterRenaming.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexResource-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexResource.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/select_project_ids_from_query_and_view_or_sub_view_uuid.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexMultiModulesProject-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexMultiModulesProject.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexProjects-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexProjects.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexResource-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexResource.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexTwoLettersLongResource-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexTwoLettersLongResource.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldNotIndexPackages.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldNotReindexUnchangedResource-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldNotReindexUnchangedResource.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexNewTwoLettersLongResource-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexNewTwoLettersLongResource.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexTwoLettersLongResource-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexTwoLettersLongResource.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexProjectAfterRenaming-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexProjectAfterRenaming.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexResource-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexResource.xml [deleted file]

index 9fd6dceb0cc5f3e5f39643f5d3bb2d7737332cb4..64e9d9da58919f3f1c4e794e4e6aa64fe177f695 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.benchmark;
 
 import java.io.IOException;
-import java.sql.Connection;
 import java.util.Arrays;
 import java.util.Timer;
 import java.util.concurrent.atomic.AtomicLong;
@@ -30,11 +29,11 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.System2;
 import org.sonar.api.utils.internal.Uuids;
 import org.sonar.db.DbTester;
 import org.sonar.db.source.FileSourceDao;
 import org.sonar.db.source.FileSourceDto;
-import org.sonar.server.db.DbClient;
 import org.sonar.server.source.db.FileSourceDb;
 import org.sonar.server.source.index.FileSourcesUpdaterHelper;
 import org.sonar.server.source.index.SourceLineResultSetIterator;
@@ -50,7 +49,7 @@ public class SourceDbBenchmarkTest {
   public static final String PROJECT_UUID = Uuids.create();
 
   @Rule
-  public DbTester dbTester = new DbTester();
+  public DbTester dbTester = DbTester.create(System2.INSTANCE);
 
   @Rule
   public Benchmark benchmark = new Benchmark();
@@ -63,8 +62,6 @@ public class SourceDbBenchmarkTest {
 
   private void scrollRows() throws Exception {
     LOGGER.info("Scroll table FILE_SOURCES");
-    DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis());
-    Connection connection = dbTester.openConnection();
     AtomicLong counter = new AtomicLong();
     ProgressTask progress = new ProgressTask(LOGGER, "source file", counter);
     Timer timer = new Timer("SourceDbScroll");
@@ -72,7 +69,7 @@ public class SourceDbBenchmarkTest {
 
     try {
       long start = System.currentTimeMillis();
-      SourceLineResultSetIterator it = SourceLineResultSetIterator.create(dbClient, connection, 0L, null);
+      SourceLineResultSetIterator it = SourceLineResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L, null);
       while (it.hasNext()) {
         FileSourcesUpdaterHelper.Row row = it.next();
         assertThat(row.getUpdateRequests().size()).isEqualTo(NUMBER_OF_LINES);
@@ -86,7 +83,6 @@ public class SourceDbBenchmarkTest {
       benchmark.expectBetween("Throughput to scroll FILE_SOURCES", throughputPerSecond, 9, 13);
 
     } finally {
-      DbUtils.closeQuietly(connection);
       timer.cancel();
     }
   }
index 0aa9be229467ba5aa56948337f2454427bc71223..b44edeb98f7fbde01322a0ccd2c124851c57a66a 100644 (file)
  */
 package org.sonar.server.activity;
 
-import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.KeyValueFormat;
 import org.sonar.api.utils.internal.Uuids;
 import org.sonar.db.activity.ActivityDto;
 import org.sonar.server.activity.index.ActivityIndexer;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.user.UserSession;
 
-@ServerSide
 public class ActivityService {
 
   private final DbClient dbClient;
index d2b791292ec2f0d0a3b188839ad6c2dc80583afd..f5d651ad4f3e063b0697decbcd220479d0768d79 100644 (file)
  */
 package org.sonar.server.activity.index;
 
+import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.server.db.DbClient;
 import org.sonar.server.es.BaseIndexer;
 import org.sonar.server.es.BulkIndexer;
 import org.sonar.server.es.EsClient;
 
-import java.sql.Connection;
-
 /**
  * Add to Elasticsearch index {@link org.sonar.server.activity.index.ActivityIndexDefinition} the rows of
  * db table ACTIVITIES that are not indexed yet
@@ -47,9 +45,8 @@ public class ActivityIndexer extends BaseIndexer {
     bulk.setLarge(lastUpdatedAt == 0L);
 
     DbSession dbSession = dbClient.openSession(false);
-    Connection dbConnection = dbSession.getConnection();
     try {
-      ActivityResultSetIterator it = ActivityResultSetIterator.create(dbClient, dbConnection, lastUpdatedAt);
+      ActivityResultSetIterator it = ActivityResultSetIterator.create(dbClient, dbSession, lastUpdatedAt);
       bulk.start();
       while (it.hasNext()) {
         bulk.add(it.next());
index afef3531195013b5559728a08a6456f408fcbaa0..66df9694ce57d9dcbc0ed83d4e295457cf5bcff6 100644 (file)
  */
 package org.sonar.server.activity.index;
 
-import org.apache.commons.lang.StringUtils;
-import org.elasticsearch.action.update.UpdateRequest;
-import org.sonar.api.utils.KeyValueFormat;
-import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.server.db.DbClient;
-import org.sonar.db.ResultSetIterator;
-import org.sonar.server.es.EsUtils;
-import org.sonar.server.util.DateCollector;
-
 import java.io.ByteArrayOutputStream;
 import java.io.OutputStreamWriter;
 import java.nio.charset.StandardCharsets;
-import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Timestamp;
 import java.util.Date;
+import org.apache.commons.lang.StringUtils;
+import org.elasticsearch.action.update.UpdateRequest;
+import org.sonar.api.utils.KeyValueFormat;
+import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.ResultSetIterator;
+import org.sonar.server.es.EsUtils;
+import org.sonar.server.util.DateCollector;
 
 /**
  * Scrolls over table ACTIVITIES and reads documents to populate
@@ -64,10 +63,10 @@ class ActivityResultSetIterator extends ResultSetIterator<UpdateRequest> {
     super(stmt);
   }
 
-  static ActivityResultSetIterator create(DbClient dbClient, Connection connection, long afterDate) {
+  static ActivityResultSetIterator create(DbClient dbClient, DbSession session, long afterDate) {
     try {
       String sql = afterDate > 0L ? SQL_AFTER_DATE : SQL_ALL;
-      PreparedStatement stmt = dbClient.newScrollingSelectStatement(connection, sql);
+      PreparedStatement stmt = dbClient.getMyBatis().newScrollingSelectStatement(session, sql);
       if (afterDate > 0L) {
         stmt.setTimestamp(1, new Timestamp(afterDate));
       }
index 6e51c44b994f67aa9c200ba9ce2ed03b2930c372..6319895346356799dd2760d0115c142b38df0446 100644 (file)
@@ -42,7 +42,7 @@ import org.sonar.db.component.ComponentDto;
 import org.sonar.core.component.ComponentKeys;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbSession;
-import org.sonar.db.component.ResourceIndexerDao;
+import org.sonar.db.component.ResourceIndexDao;
 import org.sonar.db.component.ResourceKeyUpdaterDao;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.exceptions.BadRequestException;
@@ -58,16 +58,16 @@ public class ComponentService {
 
   private final ResourceKeyUpdaterDao resourceKeyUpdaterDao;
   private final I18n i18n;
-  private final ResourceIndexerDao resourceIndexerDao;
+  private final ResourceIndexDao resourceIndexDao;
   private final UserSession userSession;
   private final System2 system2;
 
-  public ComponentService(DbClient dbClient, ResourceKeyUpdaterDao resourceKeyUpdaterDao, I18n i18n, ResourceIndexerDao resourceIndexerDao,
+  public ComponentService(DbClient dbClient, ResourceKeyUpdaterDao resourceKeyUpdaterDao, I18n i18n, ResourceIndexDao resourceIndexDao,
                           UserSession userSession, System2 system2) {
     this.dbClient = dbClient;
     this.resourceKeyUpdaterDao = resourceKeyUpdaterDao;
     this.i18n = i18n;
-    this.resourceIndexerDao = resourceIndexerDao;
+    this.resourceIndexDao = resourceIndexDao;
     this.userSession = userSession;
     this.system2 = system2;
   }
@@ -177,7 +177,7 @@ public class ComponentService {
           .setCreatedAt(new Date(system2.now()))
         ;
       dbClient.componentDao().insert(session, component);
-      resourceIndexerDao.indexResource(session, component.getId());
+      resourceIndexDao.indexResource(session, component.getId());
       session.commit();
 
       return component.key();
index b0aa30c56a2db61d535b660682068739a6a27e08..8673e890fd8a846657be8d53f2a447150d54a1bb 100644 (file)
@@ -31,9 +31,7 @@ import javax.annotation.Nullable;
 import org.apache.ibatis.session.RowBounds;
 import org.sonar.api.resources.Qualifiers;
 import org.sonar.api.resources.Scopes;
-import org.sonar.api.server.ServerSide;
 import org.sonar.db.Dao;
-import org.sonar.db.DaoUtils;
 import org.sonar.db.DatabaseUtils;
 import org.sonar.db.DbSession;
 import org.sonar.db.component.ComponentDto;
@@ -45,10 +43,6 @@ import org.sonar.server.exceptions.NotFoundException;
 
 import static com.google.common.collect.Maps.newHashMapWithExpectedSize;
 
-/**
- * @since 4.3
- */
-@ServerSide
 public class ComponentDao implements Dao {
 
   public ComponentDto selectById(long id, DbSession session) {
index b644aa490bbf51785edec985f23ab94efe2564bd..d009e11e105090e0221f040332f5367d5270945c 100644 (file)
@@ -35,7 +35,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
 import org.sonar.process.ProcessProperties;
 import org.sonar.db.compute.AnalysisReportDao;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 
 import static org.sonar.db.compute.AnalysisReportDto.Status.PENDING;
 
index 3b73ce07bab226edc56d0f2aede05b7906b494ea..450a00ed4b6a21b21ad21958e6951d03ca77db6d 100644 (file)
 package org.sonar.server.computation.activity;
 
 import javax.annotation.CheckForNull;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.db.compute.AnalysisReportDto;
+import org.sonar.server.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
+import org.sonar.db.component.ComponentDto;
+import org.sonar.db.compute.AnalysisReportDto;
 import org.sonar.server.activity.Activity;
 import org.sonar.server.activity.ActivityService;
-import org.sonar.server.db.DbClient;
 
 import static org.sonar.api.utils.DateUtils.formatDateTimeNullSafe;
 import static org.sonar.api.utils.DateUtils.longToDate;
index 3aea99958789519b185785df3b675b1569d8c994..a16f57b281339b24cb0f9a3d3f1f30d50e0f0ff9 100644 (file)
@@ -35,7 +35,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
 import org.sonar.server.computation.batch.BatchReportReader;
 import org.sonar.server.computation.component.TreeRootHolder;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 
 import static com.google.common.collect.FluentIterable.from;
 import static org.sonar.core.rule.RuleKeyFunctions.stringToRuleKey;
index 6f0fef0c98866c52c70d1efe4af8c3984c728ad6..b616f550890985367076f0e51ceeca6f24a255bf 100644 (file)
@@ -36,7 +36,7 @@ import org.sonar.server.computation.metric.Metric;
 import org.sonar.server.computation.metric.MetricRepository;
 import org.sonar.server.computation.period.Period;
 import org.sonar.server.computation.period.PeriodsHolder;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 
 public class NewDebtAggregator extends IssueVisitor {
 
index d9b7438b240a39db1de2d5ed582928eae1425605..621172bc03912470a4b13d7a2304839852646ef1 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.core.issue.tracking.LineHashSequence;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
 import org.sonar.server.computation.component.Component;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 
 /**
  * Factory of {@link Input} of base data for issue tracking. Data are lazy-loaded.
index 6bc789371e67ebb9fa94d45235b7771ec7aeaf22..24e22c3e68c911b40921e35c91665e0c7a583742 100644 (file)
@@ -36,7 +36,7 @@ import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.debt.Characteristic;
 import org.sonar.server.computation.metric.Metric;
 import org.sonar.server.computation.metric.MetricRepository;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.lang.String.format;
index 8e69c81b61920de235ccf8f5dfb9a60723b197dd..c15eab8d19fa62f4f48eb2ab1d17a6608ca0b4e8 100644 (file)
@@ -26,7 +26,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
 import org.sonar.server.computation.component.DbIdsRepository;
 import org.sonar.server.computation.component.TreeRootHolder;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 
 /**
index 602e45a1ae85858f97f0f4dfbf285a9ded8228cc..6b3ae0b4de45ad4d9183cf61bd680d84ad242c7e 100644 (file)
@@ -31,7 +31,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.debt.CharacteristicDto;
 import org.sonar.server.computation.debt.Characteristic;
 import org.sonar.server.computation.debt.MutableDebtModelHolder;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 
 import static com.google.common.base.Predicates.not;
 import static com.google.common.collect.FluentIterable.from;
index 8b9773b90b53daead3fa49e682589c77f258f848..05c90a0451f2f04403b4519640d0dbb2984da723 100644 (file)
@@ -44,7 +44,7 @@ import org.sonar.server.computation.metric.Metric;
 import org.sonar.server.computation.metric.MetricRepository;
 import org.sonar.server.computation.period.Period;
 import org.sonar.server.computation.period.PeriodsHolder;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 
 import static org.sonar.server.computation.component.ComponentVisitor.Order.PRE_ORDER;
 
index 90998d7a0634327697c6a0a4091e05ed63362164..ba648fa1337677fa9d28e2fd29564799e483ac8d 100644 (file)
@@ -20,7 +20,7 @@
 
 package org.sonar.server.computation.step;
 
-import org.sonar.db.component.ResourceIndexerDao;
+import org.sonar.db.component.ResourceIndexDao;
 import org.sonar.server.computation.component.DbIdsRepository;
 import org.sonar.server.computation.component.TreeRootHolder;
 
@@ -29,19 +29,19 @@ import org.sonar.server.computation.component.TreeRootHolder;
  */
 public class IndexComponentsStep implements ComputationStep {
 
-  private final ResourceIndexerDao resourceIndexerDao;
+  private final ResourceIndexDao resourceIndexDao;
   private final DbIdsRepository dbIdsRepository;
   private final TreeRootHolder treeRootHolder;
 
-  public IndexComponentsStep(ResourceIndexerDao resourceIndexerDao, DbIdsRepository dbIdsRepository, TreeRootHolder treeRootHolder) {
-    this.resourceIndexerDao = resourceIndexerDao;
+  public IndexComponentsStep(ResourceIndexDao resourceIndexDao, DbIdsRepository dbIdsRepository, TreeRootHolder treeRootHolder) {
+    this.resourceIndexDao = resourceIndexDao;
     this.dbIdsRepository = dbIdsRepository;
     this.treeRootHolder = treeRootHolder;
   }
 
   @Override
   public void execute() {
-    resourceIndexerDao.indexProject(dbIdsRepository.getComponentId(treeRootHolder.getRoot()));
+    resourceIndexDao.indexProject(dbIdsRepository.getComponentId(treeRootHolder.getRoot()));
   }
 
   @Override
index ce318a5866b2349ad9ee681dcb94a2a64a97422e..a171a541f8e0a801db3ac866eeecd3b31b537d73 100644 (file)
@@ -33,7 +33,7 @@ import org.sonar.server.computation.component.DepthTraversalTypeAwareVisitor;
 import org.sonar.server.computation.component.TreeRootHolder;
 import org.sonar.server.computation.event.Event;
 import org.sonar.server.computation.event.EventRepository;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 
 import static com.google.common.collect.Iterables.transform;
 
index 922f19a2a183e840416b1506cc2f7d743792f9b2..8ad3021e97fe514c54a83f7a1c7a757df2d6458c 100644 (file)
@@ -45,7 +45,7 @@ import org.sonar.server.computation.source.HighlightingLineReader;
 import org.sonar.server.computation.source.LineReader;
 import org.sonar.server.computation.source.ScmLineReader;
 import org.sonar.server.computation.source.SymbolsLineReader;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.source.db.FileSourceDb;
 import org.sonar.server.util.CloseableIterator;
 
index ff2688091b7388254937320babf352e33402e37c..b9de241635fd9372e8e1e4f295de6e2eb895f379 100644 (file)
@@ -33,7 +33,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
 import org.sonar.server.computation.issue.IssueCache;
 import org.sonar.server.computation.issue.RuleRepository;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.util.CloseableIterator;
 
 public class PersistIssuesStep implements ComputationStep {
index 3fa2b54ec1b5348d07c3051300402cd42f36f801..263517c5349b51d42c211dc53d0b52fe9bd288bc 100644 (file)
@@ -41,7 +41,7 @@ import org.sonar.server.computation.measure.MeasureRepository;
 import org.sonar.server.computation.measure.MeasureToMeasureDto;
 import org.sonar.server.computation.metric.Metric;
 import org.sonar.server.computation.metric.MetricRepository;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 
 import static com.google.common.collect.FluentIterable.from;
 import static org.sonar.server.computation.component.ComponentVisitor.Order.PRE_ORDER;
index 113de32a2a2c0bb313b5650bfd60dc15067f0b9f..e7404d50684380187d1023e8a80c9f89f0916b9a 100644 (file)
@@ -35,7 +35,7 @@ import org.sonar.server.computation.component.DbIdsRepository;
 import org.sonar.server.computation.component.DepthTraversalTypeAwareVisitor;
 import org.sonar.server.computation.component.TreeRootHolder;
 import org.sonar.server.computation.metric.MetricRepository;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.source.index.SourceLineIndex;
 
 import static com.google.common.base.Objects.firstNonNull;
index c97fcf6a27584ad02e0ec067fe9c82c6e6fdb03b..0fabd53203ba1692d06c6ee9853c7e71371e3034 100644 (file)
@@ -38,7 +38,7 @@ import org.sonar.server.computation.batch.BatchReportReader;
 import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.component.DepthTraversalTypeAwareVisitor;
 import org.sonar.server.computation.component.TreeRootHolder;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 
 import static com.google.common.collect.Sets.newHashSet;
 import static org.sonar.server.computation.component.ComponentVisitor.Order.PRE_ORDER;
index 97d181137670b953ae682f77f877fa6c5f18cc80..3190f5e45fdf2ea736c4a66a74522aa46d53e6d3 100644 (file)
@@ -32,7 +32,7 @@ import org.sonar.server.computation.component.DbIdsRepository;
 import org.sonar.server.computation.component.TreeRootHolder;
 import org.sonar.server.computation.period.Period;
 import org.sonar.server.computation.period.PeriodsHolder;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 
 /**
  * Persist snapshots
index 436e5ac8e3882b412dffbddf422125fa52b02ffe..62119d32ad608a0292b39eb648e7494c984b888b 100644 (file)
@@ -48,7 +48,7 @@ import org.sonar.server.computation.batch.BatchReportReader;
 import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.component.DepthTraversalTypeAwareVisitor;
 import org.sonar.server.computation.component.TreeRootHolder;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.source.db.FileSourceDb;
 import org.sonar.server.source.db.FileSourceDb.Test.TestStatus;
 import org.sonar.server.util.CloseableIterator;
index e8cf0019ce50d38451542d28b0531f300dc19dff..c32a2c77ed43d5d0669ee057feeb393fb7d45577 100644 (file)
@@ -28,7 +28,7 @@ import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.component.DbIdsRepository;
 import org.sonar.server.computation.component.ProjectSettingsRepository;
 import org.sonar.server.computation.component.TreeRootHolder;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 
 public class PurgeDatastoresStep implements ComputationStep {
 
index 6e74b092366e2aaa500a634063686dbb1bc479a2..2152a24ff9a2b97c2d096d3615b4e4ca7f5e1b1d 100644 (file)
@@ -28,7 +28,7 @@ import org.sonar.db.component.SnapshotDao;
 import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.component.DbIdsRepository;
 import org.sonar.server.computation.component.TreeRootHolder;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 
 import static org.sonar.db.component.SnapshotDao.isLast;
 
index b89b0aa6d6706e134edd2f4766658f0284d9399d..ae9bab0f56c5d78f8bdc3041b81972885bd4771f 100644 (file)
  */
 package org.sonar.server.db;
 
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.IdentityHashMap;
 import java.util.Map;
-import javax.annotation.Nullable;
 import org.sonar.db.Dao;
 import org.sonar.db.Database;
-import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
-import org.sonar.db.activity.ActivityDao;
-import org.sonar.db.component.ComponentLinkDao;
-import org.sonar.db.component.ResourceDao;
-import org.sonar.db.component.ResourceIndexerDao;
-import org.sonar.db.component.SnapshotDao;
-import org.sonar.db.compute.AnalysisReportDao;
-import org.sonar.db.dashboard.DashboardDao;
-import org.sonar.db.dashboard.WidgetDao;
-import org.sonar.db.dashboard.WidgetPropertyDao;
-import org.sonar.db.debt.CharacteristicDao;
-import org.sonar.db.event.EventDao;
-import org.sonar.db.issue.ActionPlanDao;
-import org.sonar.db.issue.IssueChangeDao;
-import org.sonar.db.issue.IssueDao;
-import org.sonar.db.issue.IssueFilterDao;
-import org.sonar.db.loadedtemplate.LoadedTemplateDao;
-import org.sonar.db.measure.MeasureDao;
-import org.sonar.db.permission.PermissionTemplateDao;
-import org.sonar.db.property.PropertiesDao;
-import org.sonar.db.purge.PurgeDao;
-import org.sonar.db.qualitygate.QualityGateConditionDao;
-import org.sonar.db.qualityprofile.QualityProfileDao;
-import org.sonar.db.source.FileSourceDao;
-import org.sonar.db.user.AuthorDao;
-import org.sonar.db.user.AuthorizationDao;
-import org.sonar.db.user.GroupMembershipDao;
-import org.sonar.db.user.RoleDao;
-import org.sonar.db.user.UserGroupDao;
 import org.sonar.server.component.db.ComponentDao;
 import org.sonar.server.measure.custom.persistence.CustomMeasureDao;
 import org.sonar.server.metric.persistence.MetricDao;
@@ -66,271 +31,60 @@ import org.sonar.server.rule.db.RuleDao;
 import org.sonar.server.user.db.GroupDao;
 import org.sonar.server.user.db.UserDao;
 
-public class DbClient {
-
-  private final Database db;
-  private final MyBatis myBatis;
-  private final RuleDao ruleDao;
-  private final ActiveRuleDao activeRuleDao;
-  private final QualityProfileDao qualityProfileDao;
-  private final CharacteristicDao debtCharacteristicDao;
-  private final LoadedTemplateDao loadedTemplateDao;
-  private final PropertiesDao propertiesDao;
-  private final ComponentDao componentDao;
-  private final SnapshotDao snapshotDao;
-  private final ResourceDao resourceDao;
-  private final MeasureDao measureDao;
-  private final MetricDao metricDao;
-  private final ActivityDao activityDao;
-  private final AuthorizationDao authorizationDao;
-  private final UserDao userDao;
-  private final GroupDao groupDao;
-  private final UserGroupDao userGroupDao;
-  private final GroupMembershipDao groupMembershipDao;
-  private final RoleDao roleDao;
-  private final PermissionTemplateDao permissionTemplateDao;
-  private final IssueDao issueDao;
-  private final IssueFilterDao issueFilterDao;
-  private final IssueChangeDao issueChangeDao;
-  private final ActionPlanDao actionPlanDao;
-  private final AnalysisReportDao analysisReportDao;
-  private final DashboardDao dashboardDao;
-  private final WidgetDao widgetDao;
-  private final WidgetPropertyDao widgetPropertyDao;
-  private final FileSourceDao fileSourceDao;
-  private final AuthorDao authorDao;
-  private final ResourceIndexerDao componentIndexDao;
-  private final ComponentLinkDao componentLinkDao;
-  private final EventDao eventDao;
-  private final PurgeDao purgeDao;
-  private final CustomMeasureDao customMeasureDao;
-  private final QualityGateConditionDao gateConditionDao;
-
-  public DbClient(Database db, MyBatis myBatis, Dao... daos) {
-    this.db = db;
-    this.myBatis = myBatis;
-
-    Map<Class, Dao> map = new IdentityHashMap<>();
-    for (Dao dao : daos) {
-      map.put(dao.getClass(), dao);
-    }
-    ruleDao = getDao(map, RuleDao.class);
-    activeRuleDao = getDao(map, ActiveRuleDao.class);
-    debtCharacteristicDao = getDao(map, CharacteristicDao.class);
-    qualityProfileDao = getDao(map, QualityProfileDao.class);
-    loadedTemplateDao = getDao(map, LoadedTemplateDao.class);
-    propertiesDao = getDao(map, PropertiesDao.class);
-    componentDao = getDao(map, ComponentDao.class);
-    snapshotDao = getDao(map, SnapshotDao.class);
-    resourceDao = getDao(map, ResourceDao.class);
-    measureDao = getDao(map, MeasureDao.class);
-    metricDao = getDao(map, MetricDao.class);
-    customMeasureDao = getDao(map, CustomMeasureDao.class);
-    activityDao = getDao(map, ActivityDao.class);
-    authorizationDao = getDao(map, AuthorizationDao.class);
-    userDao = getDao(map, UserDao.class);
-    groupDao = getDao(map, GroupDao.class);
-    userGroupDao = getDao(map, UserGroupDao.class);
-    groupMembershipDao = getDao(map, GroupMembershipDao.class);
-    roleDao = getDao(map, RoleDao.class);
-    permissionTemplateDao = getDao(map, PermissionTemplateDao.class);
-    issueDao = getDao(map, IssueDao.class);
-    issueFilterDao = getDao(map, IssueFilterDao.class);
-    issueChangeDao = getDao(map, IssueChangeDao.class);
-    actionPlanDao = getDao(map, ActionPlanDao.class);
-    analysisReportDao = getDao(map, AnalysisReportDao.class);
-    dashboardDao = getDao(map, DashboardDao.class);
-    widgetDao = getDao(map, WidgetDao.class);
-    widgetPropertyDao = getDao(map, WidgetPropertyDao.class);
-    fileSourceDao = getDao(map, FileSourceDao.class);
-    authorDao = getDao(map, AuthorDao.class);
-    componentIndexDao = getDao(map, ResourceIndexerDao.class);
-    componentLinkDao = getDao(map, ComponentLinkDao.class);
-    eventDao = getDao(map, EventDao.class);
-    purgeDao = getDao(map, PurgeDao.class);
-    gateConditionDao = getDao(map, QualityGateConditionDao.class);
-  }
-
-  public Database database() {
-    return db;
-  }
+/**
+ * Should be replaced by {@link org.sonar.db.DbClient}, but some DAOs
+ * still depend on other sonar-server classes.
+ */
+public class DbClient extends org.sonar.db.DbClient {
 
-  public DbSession openSession(boolean batch) {
-    return myBatis.openSession(batch);
-  }
+  private ActiveRuleDao activeRuleDao;
+  private ComponentDao componentDao;
+  private CustomMeasureDao customMeasureDao;
+  private GroupDao groupDao;
+  private MetricDao metricDao;
+  private RuleDao ruleDao;
+  private UserDao userDao;
 
-  public void closeSession(@Nullable DbSession session) {
-    MyBatis.closeQuietly(session);
+  public DbClient(Database database, MyBatis myBatis, Dao... daos) {
+    super(database, myBatis, daos);
   }
 
-  public RuleDao ruleDao() {
-    return ruleDao;
+  @Override
+  protected void doOnLoad(Map<Class, Dao> daoByClass) {
+    this.activeRuleDao = (ActiveRuleDao) daoByClass.get(ActiveRuleDao.class);
+    this.componentDao = (ComponentDao) daoByClass.get(ComponentDao.class);
+    this.customMeasureDao = (CustomMeasureDao) daoByClass.get(CustomMeasureDao.class);
+    this.groupDao = (GroupDao) daoByClass.get(GroupDao.class);
+    this.metricDao = (MetricDao) daoByClass.get(MetricDao.class);
+    this.ruleDao = (RuleDao) daoByClass.get(RuleDao.class);
+    this.userDao = (UserDao) daoByClass.get(UserDao.class);
   }
 
   public ActiveRuleDao activeRuleDao() {
     return activeRuleDao;
   }
 
-  public IssueDao issueDao() {
-    return issueDao;
-  }
-
-  public IssueFilterDao issueFilterDao() {
-    return issueFilterDao;
-  }
-
-  public IssueChangeDao issueChangeDao() {
-    return issueChangeDao;
-  }
-
-  public QualityProfileDao qualityProfileDao() {
-    return qualityProfileDao;
-  }
-
-  public CharacteristicDao debtCharacteristicDao() {
-    return debtCharacteristicDao;
-  }
-
-  public LoadedTemplateDao loadedTemplateDao() {
-    return loadedTemplateDao;
-  }
-
-  public PropertiesDao propertiesDao() {
-    return propertiesDao;
-  }
-
   public ComponentDao componentDao() {
     return componentDao;
   }
 
-  public SnapshotDao snapshotDao() {
-    return snapshotDao;
-  }
-
-  public ResourceDao resourceDao() {
-    return resourceDao;
-  }
-
-  public MeasureDao measureDao() {
-    return measureDao;
-  }
-
-  public MetricDao metricDao() {
-    return metricDao;
-  }
-
   public CustomMeasureDao customMeasureDao() {
     return customMeasureDao;
   }
 
-  public ActivityDao activityDao() {
-    return activityDao;
-  }
-
-  public AuthorizationDao authorizationDao() {
-    return authorizationDao;
-  }
-
-  public UserDao userDao() {
-    return userDao;
-  }
-
   public GroupDao groupDao() {
     return groupDao;
   }
 
-  public UserGroupDao userGroupDao() {
-    return userGroupDao;
-  }
-
-  public GroupMembershipDao groupMembershipDao() {
-    return groupMembershipDao;
-  }
-
-  public RoleDao roleDao() {
-    return roleDao;
-  }
-
-  public PermissionTemplateDao permissionTemplateDao() {
-    return permissionTemplateDao;
-  }
-
-  public ActionPlanDao actionPlanDao() {
-    return actionPlanDao;
-  }
-
-  public AnalysisReportDao analysisReportDao() {
-    return analysisReportDao;
-  }
-
-  public DashboardDao dashboardDao() {
-    return dashboardDao;
-  }
-
-  public WidgetDao widgetDao() {
-    return widgetDao;
-  }
-
-  public WidgetPropertyDao widgetPropertyDao() {
-    return widgetPropertyDao;
-  }
-
-  public FileSourceDao fileSourceDao() {
-    return fileSourceDao;
-  }
-
-  public AuthorDao authorDao() {
-    return authorDao;
-  }
-
-  public ResourceIndexerDao componentIndexDao() {
-    return componentIndexDao;
-  }
-
-  public ComponentLinkDao componentLinkDao() {
-    return componentLinkDao;
-  }
-
-  public EventDao eventDao() {
-    return eventDao;
-  }
-
-  public PurgeDao purgeDao() {
-    return purgeDao;
-  }
-
-  public QualityGateConditionDao gateConditionDao() {
-    return gateConditionDao;
-  }
-
-  private <K> K getDao(Map<Class, Dao> map, Class<K> clazz) {
-    return (K) map.get(clazz);
-  }
-
-  /**
-   * Create a PreparedStatement for SELECT requests with scrolling of results
-   */
-  public final PreparedStatement newScrollingSelectStatement(Connection connection, String sql) {
-    int fetchSize = database().getDialect().getScrollDefaultFetchSize();
-    return newScrollingSelectStatement(connection, sql, fetchSize);
+  public MetricDao metricDao() {
+    return metricDao;
   }
 
-  /**
-   * Create a PreparedStatement for SELECT requests with scrolling of results row by row (only one row
-   * in memory at a time)
-   */
-  public final PreparedStatement newScrollingSingleRowSelectStatement(Connection connection, String sql) {
-    int fetchSize = database().getDialect().getScrollSingleRowFetchSize();
-    return newScrollingSelectStatement(connection, sql, fetchSize);
+  public RuleDao ruleDao() {
+    return ruleDao;
   }
 
-  private PreparedStatement newScrollingSelectStatement(Connection connection, String sql, int fetchSize) {
-    try {
-      PreparedStatement stmt = connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
-      stmt.setFetchSize(fetchSize);
-      return stmt;
-    } catch (SQLException e) {
-      throw new IllegalStateException("Fail to create SQL statement: " + sql, e);
-    }
+  public UserDao userDao() {
+    return userDao;
   }
 }
index f033cc4d55ce6016fddee32d0648c1f81b4c4c97..cd77d7addcc94a0d630faf7f77db862ff25cd249 100644 (file)
 package org.sonar.server.db.migrations;
 
 import com.google.common.annotations.VisibleForTesting;
+import java.sql.Connection;
 import org.apache.commons.dbutils.DbUtils;
 import org.apache.ibatis.session.SqlSession;
 import org.picocontainer.Startable;
-import org.sonar.api.server.ServerSide;
 import org.sonar.api.platform.ServerUpgradeStatus;
+import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.log.Loggers;
+import org.sonar.db.DbClient;
 import org.sonar.db.DdlUtils;
-import org.sonar.server.db.DbClient;
 import org.sonar.server.plugins.ServerPluginRepository;
 
-import java.sql.Connection;
-
 /**
  * Restore schema by executing DDL scripts. Only H2 database is supported.
  * Other databases are created by Ruby on Rails migrations.
@@ -70,13 +69,13 @@ public class DatabaseMigrator implements Startable {
    */
   @VisibleForTesting
   boolean createDatabase() {
-    if (DdlUtils.supportsDialect(dbClient.database().getDialect().getId()) && serverUpgradeStatus.isFreshInstall()) {
+    if (DdlUtils.supportsDialect(dbClient.getDatabase().getDialect().getId()) && serverUpgradeStatus.isFreshInstall()) {
       Loggers.get(getClass()).info("Create database");
       SqlSession session = dbClient.openSession(false);
       Connection connection = null;
       try {
         connection = session.getConnection();
-        createSchema(connection, dbClient.database().getDialect().getId());
+        createSchema(connection, dbClient.getDatabase().getDialect().getId());
         return true;
       } finally {
         session.close();
index 6d6d82f9e52147205002384b97fad664add33cc0..fab24b6f7d87106c32dad4fa5f5bcde74f94f470 100644 (file)
@@ -35,7 +35,7 @@ import org.sonar.db.qualityprofile.ActiveRuleKey;
 import org.sonar.core.rule.SeverityUtil;
 import org.sonar.server.activity.Activity;
 import org.sonar.db.activity.ActivityDao;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.db.migrations.MigrationStep;
 import org.sonar.server.qualityprofile.ActiveRuleChange;
 
index 75a8f2ace7fd0a83cd96b53dfdea0282337ded49..a9f13c6efa5573600271e1a452b8733cdbe202dc 100644 (file)
@@ -30,7 +30,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.version.v44.Migration44Mapper;
 import org.sonar.db.version.v44.ProfileMeasure;
 import org.sonar.db.version.v44.QProfileDto44;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.db.migrations.MigrationStep;
 
 /**
index fd379ea8dc66c1eb927ab2c2a003c6a70dac46b4..520528ddfd406c76bd27aa98acf02ef850d0c536 100644 (file)
@@ -28,7 +28,7 @@ import org.sonar.core.util.UtcDateUtils;
 import org.sonar.db.DbSession;
 import org.sonar.db.version.v44.Migration44Mapper;
 import org.sonar.db.version.v44.QProfileDto44;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.db.migrations.MigrationStep;
 
 /**
index d32d51cee622ab0be472f0787dcdbcbe9b24380a..fa2efde1b1e271172b6fd1ad940b909b2363a84b 100644 (file)
@@ -22,7 +22,7 @@ package org.sonar.server.db.migrations.v45;
 
 import org.sonar.db.DbSession;
 import org.sonar.db.version.v44.Migration44Mapper;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.db.migrations.MigrationStep;
 import org.sonar.server.db.migrations.v44.ConvertProfileMeasuresMigrationStep;
 
index 394c659fc6bbbe9211bab6ca5017507ea6e13670..bb131ab51057b2b0830dc3bda4a01601d36993c5 100644 (file)
@@ -34,7 +34,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.version.v45.Migration45Mapper;
 import org.sonar.db.version.v45.Rule;
 import org.sonar.db.version.v45.RuleParameter;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.db.migrations.MigrationStep;
 import org.sonar.core.util.ProgressLogger;
 
index 63bbbdc43fba111f8f262aa97a24d916bc2699ff..f677eee9c8ccd1a19a5ae049abd2713469b874ad 100644 (file)
@@ -31,7 +31,7 @@ import org.sonar.api.utils.log.Loggers;
 import org.sonar.db.DbSession;
 import org.sonar.db.version.v50.Component;
 import org.sonar.db.version.v50.Migration50Mapper;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.db.migrations.MigrationStep;
 import org.sonar.core.util.ProgressLogger;
 
index ac65f661afe279b1a5d48a2b90b8ccc88d3ad6a2..db850ec84405957ca04bf4669a9ae5ef755197e3 100644 (file)
@@ -34,7 +34,7 @@ import org.sonar.db.measure.MeasureDto;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
 import org.sonar.server.component.db.ComponentDao;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.db.measure.MeasureDao;
 import org.sonar.server.user.UserSession;
index faccdb814eded42f653075a17dabe01ec09c1c64..d821248ac6b043fc6c5d0cd1c5153fb6d564c7e5 100644 (file)
@@ -31,7 +31,7 @@ import org.sonar.api.utils.System2;
 import org.sonar.core.issue.IssueUpdater;
 import org.sonar.db.issue.IssueChangeDto;
 import org.sonar.db.DbSession;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
index dfdfaa020c13c39ede89703d222aebea7cdc02f2..39f082182625f7384b82f006111f3e5acb70fa60 100644 (file)
@@ -48,9 +48,9 @@ import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.System2;
 import org.sonar.api.web.UserRole;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.db.DbSession;
 import org.sonar.core.rule.RuleKeyFunctions;
+import org.sonar.db.DbSession;
+import org.sonar.db.component.ComponentDto;
 import org.sonar.server.component.ComponentService;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.issue.filter.IssueFilterParameters;
index b80bedf8f3540c89449f12df7b506bc1a1979cc9..e3359c77db7e15ce07822030a8257feacb99f808 100644 (file)
@@ -32,6 +32,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
 import org.sonar.db.issue.IssueChangeDto;
 import org.sonar.db.issue.IssueChangeMapper;
+import org.sonar.server.db.DbClient;
 
 import static com.google.common.collect.Lists.newArrayList;
 
@@ -46,14 +47,18 @@ import static com.google.common.collect.Lists.newArrayList;
  */
 public abstract class IssueStorage {
 
-  private final MyBatis mybatis;
   private final RuleFinder ruleFinder;
+  private final DbClient dbClient;
 
-  protected IssueStorage(MyBatis mybatis, RuleFinder ruleFinder) {
-    this.mybatis = mybatis;
+  protected IssueStorage(DbClient dbClient, RuleFinder ruleFinder) {
+    this.dbClient = dbClient;
     this.ruleFinder = ruleFinder;
   }
 
+  protected DbClient getDbClient() {
+    return dbClient;
+  }
+
   public void save(DefaultIssue issue) {
     save(newArrayList(issue));
   }
@@ -63,7 +68,7 @@ public abstract class IssueStorage {
   }
 
   public void save(Iterable<DefaultIssue> issues) {
-    DbSession session = mybatis.openSession(true);
+    DbSession session = dbClient.openSession(true);
     try {
       doSave(session, issues);
     } finally {
@@ -108,7 +113,7 @@ public abstract class IssueStorage {
 
   private void update(List<DefaultIssue> toBeUpdated, long now) {
     if (!toBeUpdated.isEmpty()) {
-      DbSession session = mybatis.openSession(false);
+      DbSession session = dbClient.openSession(false);
       try {
         IssueChangeMapper issueChangeMapper = session.getMapper(IssueChangeMapper.class);
         for (DefaultIssue issue : toBeUpdated) {
index 44d0366746246efdde5a66bbcb6c95b535f98c3f..c9359612698df5e8f336c774d050c204d83d2878 100644 (file)
  */
 package org.sonar.server.issue;
 
+import org.sonar.api.rules.RuleFinder;
 import org.sonar.api.server.ServerSide;
 import org.sonar.core.issue.DefaultIssue;
-import org.sonar.api.rules.RuleFinder;
+import org.sonar.db.DbSession;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.issue.IssueDto;
-import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.issue.index.IssueIndexer;
 
@@ -35,12 +34,10 @@ import org.sonar.server.issue.index.IssueIndexer;
 @ServerSide
 public class ServerIssueStorage extends IssueStorage {
 
-  private final DbClient dbClient;
   private final IssueIndexer indexer;
 
-  public ServerIssueStorage(MyBatis mybatis, RuleFinder ruleFinder, DbClient dbClient, IssueIndexer indexer) {
-    super(mybatis, ruleFinder);
-    this.dbClient = dbClient;
+  public ServerIssueStorage(RuleFinder ruleFinder, DbClient dbClient, IssueIndexer indexer) {
+    super(dbClient, ruleFinder);
     this.indexer = indexer;
   }
 
@@ -51,14 +48,14 @@ public class ServerIssueStorage extends IssueStorage {
     int ruleId = rule(issue).getId();
     IssueDto dto = IssueDto.toDtoForServerInsert(issue, component, project, ruleId, now);
 
-    dbClient.issueDao().insert(session, dto);
+    getDbClient().issueDao().insert(session, dto);
   }
 
   @Override
   protected void doUpdate(DbSession session, long now, DefaultIssue issue) {
     IssueDto dto = IssueDto.toDtoForUpdate(issue, now);
 
-    dbClient.issueDao().update(session, dto);
+    getDbClient().issueDao().update(session, dto);
   }
 
   @Override
@@ -67,10 +64,10 @@ public class ServerIssueStorage extends IssueStorage {
   }
 
   protected ComponentDto component(DbSession session, DefaultIssue issue) {
-    return dbClient.componentDao().selectByKey(session, issue.componentKey());
+    return getDbClient().componentDao().selectByKey(session, issue.componentKey());
   }
 
   protected ComponentDto project(DbSession session, DefaultIssue issue) {
-    return dbClient.componentDao().selectByKey(session, issue.projectKey());
+    return getDbClient().componentDao().selectByKey(session, issue.projectKey());
   }
 }
index 5b065874d058e6e4ee704c64337ec2bbaeea9bae..be321bda86bf9e47d52e5e26476aa15ea747b07b 100644 (file)
@@ -44,7 +44,7 @@ import org.sonar.db.issue.ActionPlanDto;
 import org.sonar.db.issue.ActionPlanStatsDao;
 import org.sonar.db.issue.ActionPlanStatsDto;
 import org.sonar.db.issue.IssueDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.issue.IssueStorage;
 import org.sonar.server.user.UserSession;
index f9c473153eab0fefdcd746fa3990fcb5ee59d090..89227b45e736b9667ab029f3620af87e9602a2a0 100644 (file)
@@ -21,17 +21,16 @@ package org.sonar.server.issue.index;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
-import org.apache.commons.dbutils.DbUtils;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.server.db.DbClient;
-
-import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
+import org.apache.commons.dbutils.DbUtils;
+import org.apache.commons.lang.StringUtils;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
 
 /**
  * No streaming because of union of joins -> no need to use ResultSetIterator
@@ -146,13 +145,13 @@ public class IssueAuthorizationDao {
       "        AND group_roles.group_id IS NULL " +
       "    ) project_authorization";
 
-  Collection<Dto> selectAfterDate(DbClient dbClient, Connection connection, long afterDate) {
+  Collection<Dto> selectAfterDate(DbClient dbClient, DbSession session, long afterDate) {
     try {
       Map<String, Dto> dtosByProjectUuid = Maps.newHashMap();
       PreparedStatement stmt = null;
       ResultSet rs = null;
       try {
-        stmt = createStatement(dbClient, connection, afterDate);
+        stmt = createStatement(dbClient, session, afterDate);
         rs = stmt.executeQuery();
         while (rs.next()) {
           processRow(rs, dtosByProjectUuid);
@@ -167,14 +166,14 @@ public class IssueAuthorizationDao {
     }
   }
 
-  private PreparedStatement createStatement(DbClient dbClient, Connection connection, long afterDate) throws SQLException {
+  private PreparedStatement createStatement(DbClient dbClient, DbSession session, long afterDate) throws SQLException {
     String sql;
     if (afterDate > 0L) {
       sql = StringUtils.replace(SQL_TEMPLATE, "{dateCondition}", " AND projects.authorization_updated_at>? ");
     } else {
       sql = StringUtils.replace(SQL_TEMPLATE, "{dateCondition}", "");
     }
-    PreparedStatement stmt = dbClient.newScrollingSelectStatement(connection, sql);
+    PreparedStatement stmt = dbClient.getMyBatis().newScrollingSelectStatement(session, sql);
     if (afterDate > 0L) {
       for (int i = 1; i <= 4; i++) {
         stmt.setLong(i, afterDate);
index 9428e77a6e1ae84bd96859cc004345b8b5ab8f3e..93a3b6e79097ef53aa72ac7e6be420c93102583e 100644 (file)
@@ -25,7 +25,7 @@ import org.apache.commons.dbutils.DbUtils;
 import org.elasticsearch.action.ActionRequest;
 import org.elasticsearch.action.update.UpdateRequest;
 import org.sonar.db.DbSession;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.es.BaseIndexer;
 import org.sonar.server.es.BulkIndexer;
 import org.sonar.server.es.EsClient;
@@ -58,14 +58,12 @@ public class IssueAuthorizationIndexer extends BaseIndexer {
     final BulkIndexer bulk = new BulkIndexer(esClient, IssueIndexDefinition.INDEX);
 
     DbSession dbSession = dbClient.openSession(false);
-    Connection dbConnection = dbSession.getConnection();
     try {
       IssueAuthorizationDao dao = new IssueAuthorizationDao();
-      Collection<IssueAuthorizationDao.Dto> authorizations = dao.selectAfterDate(dbClient, dbConnection, lastUpdatedAt);
+      Collection<IssueAuthorizationDao.Dto> authorizations = dao.selectAfterDate(dbClient, dbSession, lastUpdatedAt);
       return doIndex(bulk, authorizations);
 
     } finally {
-      DbUtils.closeQuietly(dbConnection);
       dbSession.close();
     }
   }
index e6889c1beb4d82c2d4ea9b4568bb4f108e078764..d7ff6d85eb0b338bca610a3977ae0619bf740b14 100644 (file)
  */
 package org.sonar.server.issue.index;
 
-import org.apache.commons.dbutils.DbUtils;
+import java.util.Iterator;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.update.UpdateRequest;
 import org.elasticsearch.index.query.FilterBuilders;
 import org.elasticsearch.index.query.QueryBuilders;
+import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.server.db.DbClient;
 import org.sonar.server.es.BaseIndexer;
 import org.sonar.server.es.BulkIndexer;
 import org.sonar.server.es.EsClient;
 
-import java.sql.Connection;
-import java.util.Iterator;
-
 public class IssueIndexer extends BaseIndexer {
 
   private final DbClient dbClient;
@@ -60,16 +57,13 @@ public class IssueIndexer extends BaseIndexer {
 
   private long doIndex(BulkIndexer bulk, long lastUpdatedAt) {
     DbSession dbSession = dbClient.openSession(false);
-    Connection dbConnection = dbSession.getConnection();
     long maxDate;
     try {
-      IssueResultSetIterator rowIt = IssueResultSetIterator.create(dbClient, dbConnection, lastUpdatedAt);
+      IssueResultSetIterator rowIt = IssueResultSetIterator.create(dbClient, dbSession, lastUpdatedAt);
       maxDate = doIndex(bulk, rowIt);
       rowIt.close();
       return maxDate;
-
     } finally {
-      DbUtils.closeQuietly(dbConnection);
       dbSession.close();
     }
   }
@@ -97,7 +91,7 @@ public class IssueIndexer extends BaseIndexer {
       .setQuery(QueryBuilders.filteredQuery(
         QueryBuilders.matchAllQuery(),
         FilterBuilders.boolFilter().must(FilterBuilders.termsFilter(IssueIndexDefinition.FIELD_ISSUE_PROJECT_UUID, uuid))
-      ));
+        ));
     bulk.addDeletion(search);
     bulk.stop();
   }
index 6876a2312655359c8e4b82d497769ef8997165db..35f3f39c6b60ceb0da30122fb46466cc2b31f086 100644 (file)
@@ -27,7 +27,8 @@ import com.google.common.collect.Maps;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.api.resources.Scopes;
 import org.sonar.api.rule.RuleKey;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
 import org.sonar.db.ResultSetIterator;
 import org.sonar.server.db.migrations.SqlUtil;
 
@@ -100,10 +101,10 @@ class IssueResultSetIterator extends ResultSetIterator<IssueDoc> {
     super(stmt);
   }
 
-  static IssueResultSetIterator create(DbClient dbClient, Connection connection, long afterDate) {
+  static IssueResultSetIterator create(DbClient dbClient, DbSession session, long afterDate) {
     try {
       String sql = afterDate > 0L ? SQL_AFTER_DATE : SQL_ALL;
-      PreparedStatement stmt = dbClient.newScrollingSelectStatement(connection, sql);
+      PreparedStatement stmt = dbClient.getMyBatis().newScrollingSelectStatement(session, sql);
       if (afterDate > 0L) {
         stmt.setLong(1, afterDate);
       }
index 3b1d7533bc11f6412fba187c2c8cb38b9b34c735..d0958780989697d9758e4c7d3afe155c66ee7a12 100644 (file)
@@ -54,7 +54,7 @@ import org.sonar.db.component.ComponentDto;
 import org.sonar.core.issue.DefaultIssueComment;
 import org.sonar.db.DbSession;
 import org.sonar.server.component.ws.ComponentJsonWriter;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.es.Facets;
 import org.sonar.server.es.SearchOptions;
 import org.sonar.server.es.SearchResult;
index 7cfa02572f441216a9f31585c6b3a05dd1c46d93..185a54e54c4ae113d9091850acb7fcd455db301b 100644 (file)
@@ -42,7 +42,7 @@ import org.sonar.api.notifications.NotificationChannel;
 import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 
 @Properties({
   @Property(
index f75952fc05f1568e21b7935dd2e69bf548933ded..fd6d4ae9a2fe962dafbc161638985f0777bd4b0c 100644 (file)
@@ -25,7 +25,7 @@ import org.apache.commons.dbutils.DbUtils;
 import org.sonar.db.version.DatabaseVersion;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
@@ -122,7 +122,7 @@ public class DatabaseMonitor extends BaseMonitorMBean implements DatabaseMonitor
   }
 
   private BasicDataSource commonsDbcp() {
-    return (BasicDataSource) dbClient.database().getDataSource();
+    return (BasicDataSource) dbClient.getDatabase().getDataSource();
   }
 
   private void completeDbAttributes(Map<String, Object> attributes) {
index 69ca28e06cab9b6c49e4716745e1fd63ca5a6dfb..621fa7848ecdfdfb2abd9f9e15052cedc17c7ede 100644 (file)
@@ -107,27 +107,23 @@ public class PlatformLevel1 extends PlatformLevel {
       // Elasticsearch
       EsSearchModule.class,
 
-      // users
+      // DAOs to be moved to sonar-db
       GroupDao.class,
       UserDao.class,
+      RuleDao.class,
+      ActiveRuleDao.class,
+      MetricDao.class,
+      CustomMeasureDao.class,
+      ComponentDao.class,
 
       // rules/qprofiles
       RuleNormalizer.class,
       ActiveRuleNormalizer.class,
       RuleIndex.class,
       ActiveRuleIndex.class,
-      RuleDao.class,
-      ActiveRuleDao.class,
 
       // issues
-      IssueIndex.class,
-
-      // measures
-      MetricDao.class,
-      CustomMeasureDao.class,
-
-      // components
-      ComponentDao.class);
+      IssueIndex.class);
     addAll(CorePropertyDefinitions.all());
     add(MigrationStepModule.class);
     addAll(DaoUtils.getDaoClasses());
index 6614dbd65d32f3627048a1e97a66771e43b39e56..ad0f8cc1369befc8e60aa58a870c76d7949ad1f7 100644 (file)
@@ -28,7 +28,7 @@ import org.sonar.api.utils.log.Loggers;
 import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.db.DbSession;
 import org.sonar.db.IsAliveMapper;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.db.migrations.DatabaseMigration;
 import org.sonar.server.platform.Platform;
 
index 6f1a47a091f0f91d77fc8b9d90465c5289963d3c..afad30cfaabde9f9ba5aaf0d5c4b094e284f482c 100644 (file)
@@ -45,7 +45,7 @@ import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.text.XmlWriter;
 import org.sonar.db.DbSession;
 import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
 import org.sonar.server.search.IndexClient;
 
index 01ec23e31140106591b770b791edad7b3f04467d..9fc6a66662871c055fb92db9e304803cbdd1b63a 100644 (file)
@@ -28,7 +28,7 @@ import org.sonar.api.rule.RuleKey;
 import org.sonar.db.DbSession;
 import org.sonar.db.qualityprofile.QualityProfileDto;
 import org.sonar.core.util.NonNullInputFunction;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 
 import java.util.Collection;
 import java.util.Map;
index 7e9f1abfb8a380de9be341b719bb83c96adfd40a..22685e1414f979c5b27a31df8c18ab15b8854449 100644 (file)
@@ -26,7 +26,7 @@ import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.TempFolder;
 import org.sonar.db.DbSession;
 import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 
 import java.io.File;
 import java.io.IOException;
index fd526765be79871abfece06cc5917e2ee12e67fc..f90be5b0e86edd085c3053584586b5fc089135d4 100644 (file)
 package org.sonar.server.qualityprofile;
 
 import com.google.common.collect.Lists;
+import java.util.Date;
+import java.util.List;
+import javax.annotation.CheckForNull;
 import org.apache.commons.lang.RandomStringUtils;
 import org.apache.commons.lang.StringUtils;
-import org.sonar.api.server.ServerSide;
+import org.sonar.core.util.Slug;
 import org.sonar.db.DbSession;
 import org.sonar.db.qualityprofile.QualityProfileDto;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.Verifications;
-import org.sonar.core.util.Slug;
-
-import javax.annotation.CheckForNull;
-
-import java.util.Date;
-import java.util.List;
 
 /**
  * Create, delete, rename and set as default profile.
  */
-@ServerSide
 public class QProfileFactory {
 
   private final DbClient db;
index 84f3e69b8125878a0f25520ff8c3d1afd1dafb81..50ae9a3b7777f05b7ab4496e4ff3b96f8b5fa646 100644 (file)
@@ -27,7 +27,7 @@ import org.sonar.api.rule.RuleStatus;
 import org.sonar.db.DbSession;
 import org.sonar.db.qualityprofile.ActiveRuleKey;
 import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
 import org.sonar.server.rule.index.RuleIndex;
 import org.sonar.server.rule.index.RuleQuery;
index 784e88acf5ff3bdb70ab4df53e81941714306688..5c0ad9b44dd2b8679135cbd8de2bfbe3f1636933 100644 (file)
@@ -28,7 +28,7 @@ import javax.annotation.Nonnull;
 import org.sonar.api.server.ServerSide;
 import org.sonar.db.DbSession;
 import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 
 import static com.google.common.collect.Lists.newArrayList;
 
index cea16eeaae1fb7d5052d276888b338ee48824dc3..76100b1d996c4c2387666348c0eb243415738772 100644 (file)
@@ -32,7 +32,7 @@ import org.sonar.api.web.UserRole;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
 import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.user.UserSession;
 
 import com.google.common.collect.Lists;
index ba6e90145ffaa83d9147473a25790d22f96fbe56..01d8a08ead5ce3900b15191fb431f995bb3834a3 100644 (file)
@@ -38,7 +38,7 @@ import org.sonar.api.utils.log.Profiler;
 import org.sonar.db.DbSession;
 import org.sonar.db.qualityprofile.QualityProfileDto;
 import org.sonar.db.loadedtemplate.LoadedTemplateDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.platform.PersistentSettings;
 
 import javax.annotation.Nullable;
index b7c9a97e4640fe2574096d44f7fb29b1babf2234..ebeff3fa87dffb87b6e9c04547341b638ceb05d6 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.api.server.ws.Response.Stream;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.server.ws.WebService.NewAction;
 import org.sonar.db.DbSession;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.plugins.MimeTypes;
 import org.sonar.server.qualityprofile.QProfileBackuper;
 import org.sonar.server.qualityprofile.QProfileFactory;
index e38514a5aa09dad2bc26a73e15eaa11b06b52d27..8e203c299700b42b7926e3d6183baf7d0935541c 100644 (file)
@@ -27,7 +27,7 @@ import org.sonar.api.server.ws.WebService.NewAction;
 import org.sonar.api.server.ws.WebService.NewController;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbSession;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.qualityprofile.QProfileFactory;
 import org.sonar.server.qualityprofile.RuleActivator;
 import org.sonar.server.user.UserSession;
index dea943ce53c9e13da743260d43e568ea616f35f4..07b626edc24507d4947b8c395db8fb020cab461d 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbSession;
 import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.qualityprofile.QProfileExporters;
 import org.sonar.server.qualityprofile.QProfileFactory;
 import org.sonar.server.qualityprofile.QProfileName;
index 5577a2eca66d798e16463cac41542a359d658f6c..124e3626fc43e4d827375930fd7f4c1c1eaf8529 100644 (file)
@@ -26,7 +26,7 @@ import org.sonar.api.server.ws.WebService.NewAction;
 import org.sonar.api.server.ws.WebService.NewController;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbSession;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.qualityprofile.QProfileFactory;
 import org.sonar.server.user.UserSession;
 
index 3a6516a2ceb7a9d1a190ac872a21a2b7d31e81ae..0c1b609314149dfcbfbf585f86f1d6aa1c8502a2 100644 (file)
@@ -31,7 +31,7 @@ import org.sonar.api.server.ws.WebService;
 import org.sonar.api.server.ws.WebService.NewAction;
 import org.sonar.db.DbSession;
 import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.plugins.MimeTypes;
 import org.sonar.server.qualityprofile.QProfileBackuper;
index a1dcc3fadf86cf076f08db9e05cd54f91a58582d..19ce4a83a37473c96b2693b86a30b00b33a98114 100644 (file)
@@ -28,7 +28,7 @@ import org.sonar.api.server.ws.WebService.NewController;
 import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.db.DbSession;
 import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.qualityprofile.QProfile;
 import org.sonar.server.qualityprofile.QProfileFactory;
index a9de9c71b1461362dbcffe2be7ce82e2574f6c6e..534b965477283aa76156ad29fa4176256a3c832f 100644 (file)
@@ -37,7 +37,7 @@ import org.sonar.api.web.UserRole;
 import org.sonar.db.DbSession;
 import org.sonar.db.qualityprofile.ProjectQprofileAssociationDto;
 import org.sonar.core.util.NonNullInputFunction;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.user.UserSession;
 
index c76757178d42f3f7bfc6dee444317eca81420fe1..69dd9390cd05233c418cc485d5506d5444fce1fa 100644 (file)
@@ -22,10 +22,13 @@ package org.sonar.server.rule;
 
 import com.google.common.base.Splitter;
 import com.google.common.base.Strings;
-import org.sonar.api.server.ServerSide;
+import java.util.List;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rule.RuleStatus;
 import org.sonar.api.rule.Severity;
+import org.sonar.api.server.ServerSide;
 import org.sonar.api.server.rule.RuleParamType;
 import org.sonar.db.DbSession;
 import org.sonar.db.rule.RuleDto;
@@ -38,11 +41,6 @@ import org.sonar.server.exceptions.Message;
 import org.sonar.server.rule.index.RuleDoc;
 import org.sonar.server.util.TypeValidations;
 
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-import java.util.List;
-
 import static com.google.common.collect.Lists.newArrayList;
 
 @ServerSide
index ffafa74a18a43edb373624ee45296600dd318064..9d8bf8d83117d17619d97e09c5ce9b0bdea3d8c2 100644 (file)
@@ -39,7 +39,6 @@ public class IndexDefinition {
 
   public static final IndexDefinition RULE = new IndexDefinition("rules", "rule");
   public static final IndexDefinition ACTIVE_RULE = new IndexDefinition("rules", "activeRule");
-  public static final IndexDefinition ISSUES = new IndexDefinition("issues", "issue");
 
   // Only used for test
   static final IndexDefinition TEST = new IndexDefinition("test", "test");
index 698ec88a8646c05dc06a904666b9a3a1c267e741..4ebd56a75642c502c3394a809043d7968e75ace9 100644 (file)
@@ -28,7 +28,8 @@ import java.util.ArrayList;
 import java.util.List;
 import javax.annotation.Nullable;
 import org.elasticsearch.action.update.UpdateRequest;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
 
 public class FileSourcesUpdaterHelper {
 
@@ -48,11 +49,11 @@ public class FileSourcesUpdaterHelper {
     // only static stuff
   }
 
-  public static PreparedStatement preparedStatementToSelectFileSources(DbClient dbClient, Connection connection, String dataType, long afterDate, @Nullable String projectUuid)
+  public static PreparedStatement preparedStatementToSelectFileSources(DbClient dbClient, DbSession session, String dataType, long afterDate, @Nullable String projectUuid)
     throws SQLException {
     String sql = createSQL(dataType, afterDate, projectUuid);
     // rows are big, so they are scrolled once at a time (one row in memory at a time)
-    PreparedStatement stmt = dbClient.newScrollingSingleRowSelectStatement(connection, sql);
+    PreparedStatement stmt = dbClient.getMyBatis().newScrollingSingleRowSelectStatement(session, sql);
     int index = 1;
     if (afterDate > 0L) {
       stmt.setLong(index, afterDate);
index 48dfb9ce7dc678f9dd200d49b69ebe4840d37257..52864517d150e34d15d04f71c1d6381c4e922e64 100644 (file)
  */
 package org.sonar.server.source.index;
 
+import java.util.Iterator;
+import javax.annotation.Nullable;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.update.UpdateRequest;
 import org.elasticsearch.index.query.FilterBuilders;
 import org.elasticsearch.index.query.QueryBuilders;
+import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.server.db.DbClient;
 import org.sonar.server.es.BaseIndexer;
 import org.sonar.server.es.BulkIndexer;
 import org.sonar.server.es.EsClient;
 
-import javax.annotation.Nullable;
-
-import java.sql.Connection;
-import java.util.Iterator;
-
 import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_FILE_UUID;
 import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_PROJECT_UUID;
 
@@ -50,7 +47,7 @@ public class SourceLineIndexer extends BaseIndexer {
     this.dbClient = dbClient;
   }
 
-  public void index(final String projectUuid){
+  public void index(final String projectUuid) {
     super.index(new IndexerTask() {
       @Override
       public long index(long lastUpdatedAt) {
@@ -69,9 +66,8 @@ public class SourceLineIndexer extends BaseIndexer {
     bulk.setLarge(lastUpdatedAt == 0L);
 
     DbSession dbSession = dbClient.openSession(false);
-    Connection dbConnection = dbSession.getConnection();
     try {
-      SourceLineResultSetIterator rowIt = SourceLineResultSetIterator.create(dbClient, dbConnection, lastUpdatedAt, projectUuid);
+      SourceLineResultSetIterator rowIt = SourceLineResultSetIterator.create(dbClient, dbSession, lastUpdatedAt, projectUuid);
       long maxUpdatedAt = doIndex(bulk, rowIt);
       rowIt.close();
       return maxUpdatedAt;
@@ -118,7 +114,7 @@ public class SourceLineIndexer extends BaseIndexer {
           .must(FilterBuilders.termFilter(FIELD_FILE_UUID, fileRow.getFileUuid()).cache(false))
           .must(FilterBuilders.rangeFilter(SourceLineIndexDefinition.FIELD_LINE).gt(numberOfLines).cache(false))
           .cache(false)
-      ));
+        ));
     bulk.addDeletion(searchRequest);
   }
 
index b899a5fa0b7efb41156d65e365cbc4960240a9e3..dda282ef135eb3ed765800251385ec0f285b6d13 100644 (file)
@@ -21,8 +21,9 @@ package org.sonar.server.source.index;
 
 import org.elasticsearch.action.update.UpdateRequest;
 import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.db.DbSession;
 import org.sonar.db.source.FileSourceDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.db.ResultSetIterator;
 import org.sonar.server.es.EsUtils;
 import org.sonar.server.source.db.FileSourceDb;
@@ -46,9 +47,9 @@ import static org.sonar.server.source.index.FileSourcesUpdaterHelper.Row;
  */
 public class SourceLineResultSetIterator extends ResultSetIterator<FileSourcesUpdaterHelper.Row> {
 
-  public static SourceLineResultSetIterator create(DbClient dbClient, Connection connection, long afterDate, @Nullable String projectUuid) {
+  public static SourceLineResultSetIterator create(DbClient dbClient, DbSession session, long afterDate, @Nullable String projectUuid) {
     try {
-      return new SourceLineResultSetIterator(FileSourcesUpdaterHelper.preparedStatementToSelectFileSources(dbClient, connection, FileSourceDto.Type.SOURCE, afterDate,
+      return new SourceLineResultSetIterator(FileSourcesUpdaterHelper.preparedStatementToSelectFileSources(dbClient, session, FileSourceDto.Type.SOURCE, afterDate,
         projectUuid));
     } catch (SQLException e) {
       throw new IllegalStateException("Fail to prepare SQL request to select all file sources", e);
index 27b31a4d3543a5446616f28040d8271e33cd2ddb..383d349e62495adff23e836392d35fb51fb2abba 100644 (file)
@@ -32,9 +32,9 @@ import org.sonar.api.measures.Metrics;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.api.utils.log.Profiler;
-import org.sonar.db.metric.MetricDto;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
+import org.sonar.db.metric.MetricDto;
 import org.sonar.server.db.DbClient;
 
 import static com.google.common.collect.FluentIterable.from;
index bce54a6a15e2e07403acbdfaacc08af73e55c1c6..0862b23e707b943e518d794ac10f5dbdef1e8b30 100644 (file)
@@ -32,7 +32,7 @@ import org.sonar.db.issue.IssueFilterDto;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
 import org.sonar.db.loadedtemplate.LoadedTemplateDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.issue.filter.RegisterIssueFilters;
 
 import java.util.Date;
index 1d7ce182aef5e177c676ab54551c043a0adea881..69476a22fed1c5bfa3cb9c616bba513b79926412 100644 (file)
 
 package org.sonar.server.test.index;
 
+import java.util.Iterator;
+import javax.annotation.Nullable;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.update.UpdateRequest;
 import org.elasticsearch.index.query.FilterBuilders;
 import org.elasticsearch.index.query.QueryBuilders;
+import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.server.db.DbClient;
 import org.sonar.server.es.BaseIndexer;
 import org.sonar.server.es.BulkIndexer;
 import org.sonar.server.es.EsClient;
 import org.sonar.server.source.index.FileSourcesUpdaterHelper;
 
-import javax.annotation.Nullable;
-import java.sql.Connection;
-import java.util.Iterator;
-
 import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_PROJECT_UUID;
-import static org.sonar.server.test.index.TestIndexDefinition.*;
+import static org.sonar.server.test.index.TestIndexDefinition.FIELD_FILE_UUID;
+import static org.sonar.server.test.index.TestIndexDefinition.FIELD_UPDATED_AT;
+import static org.sonar.server.test.index.TestIndexDefinition.INDEX;
+import static org.sonar.server.test.index.TestIndexDefinition.TYPE;
 
 /**
  * Add to Elasticsearch index {@link TestIndexDefinition} the rows of
@@ -76,9 +77,8 @@ public class TestIndexer extends BaseIndexer {
     bulk.setLarge(lastUpdatedAt == 0L);
 
     DbSession dbSession = dbClient.openSession(false);
-    Connection dbConnection = dbSession.getConnection();
     try {
-      TestResultSetIterator rowIt = TestResultSetIterator.create(dbClient, dbConnection, lastUpdatedAt, projectUuid);
+      TestResultSetIterator rowIt = TestResultSetIterator.create(dbClient, dbSession, lastUpdatedAt, projectUuid);
       long maxUpdatedAt = doIndex(bulk, rowIt);
       rowIt.close();
       return maxUpdatedAt;
index 61af83231293e2657f754e3876e30b83ceaf109a..67e9bb72e6a78a793c8a4e87919858826183d5fe 100644 (file)
@@ -22,8 +22,9 @@ package org.sonar.server.test.index;
 
 import org.elasticsearch.action.update.UpdateRequest;
 import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.db.DbSession;
 import org.sonar.db.source.FileSourceDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.db.ResultSetIterator;
 import org.sonar.server.source.db.FileSourceDb;
 import org.sonar.server.source.index.FileSourcesUpdaterHelper;
@@ -61,9 +62,9 @@ import static org.sonar.server.test.index.TestIndexDefinition.TYPE;
  */
 public class TestResultSetIterator extends ResultSetIterator<Row> {
 
-  public static TestResultSetIterator create(DbClient dbClient, Connection connection, long afterDate, @Nullable String projectUuid) {
+  public static TestResultSetIterator create(DbClient dbClient, DbSession session, long afterDate, @Nullable String projectUuid) {
     try {
-      return new TestResultSetIterator(FileSourcesUpdaterHelper.preparedStatementToSelectFileSources(dbClient, connection, FileSourceDto.Type.TEST, afterDate, projectUuid));
+      return new TestResultSetIterator(FileSourcesUpdaterHelper.preparedStatementToSelectFileSources(dbClient, session, FileSourceDto.Type.TEST, afterDate, projectUuid));
     } catch (SQLException e) {
       throw new IllegalStateException("Fail to prepare SQL request to select all tests", e);
     }
index 8cacd9ef64bd7bca8282c3a628d1e8bc6d1c0e5f..ec9acf8f4317ea91b99b577186c6d8f18ee56fb2 100644 (file)
@@ -46,7 +46,7 @@ import org.sonar.db.version.DatabaseVersion;
 import org.sonar.core.platform.ComponentContainer;
 import org.sonar.core.platform.PluginInfo;
 import org.sonar.core.platform.PluginRepository;
-import org.sonar.db.component.ResourceIndexerDao;
+import org.sonar.db.component.ResourceIndexDao;
 import org.sonar.core.timemachine.Periods;
 import org.sonar.process.ProcessProperties;
 import org.sonar.server.component.ComponentCleanerService;
@@ -304,11 +304,11 @@ public final class JRubyFacade {
   }
 
   public void indexProjects() {
-    get(ResourceIndexerDao.class).indexProjects();
+    get(ResourceIndexDao.class).indexProjects();
   }
 
   public void indexResource(long resourceId) {
-    get(ResourceIndexerDao.class).indexResource(resourceId);
+    get(ResourceIndexDao.class).indexResource(resourceId);
   }
 
   /*
index 8dc99faeff703adee7b742971ce39e85d4a5dac8..11db2d50caa3a82b7ce0b6c4c4e1515ea002790a 100644 (file)
 
 package org.sonar.server.user.index;
 
-import java.sql.Connection;
 import java.util.Iterator;
-import org.apache.commons.dbutils.DbUtils;
 import org.elasticsearch.action.update.UpdateRequest;
+import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.server.db.DbClient;
 import org.sonar.server.es.BaseIndexer;
 import org.sonar.server.es.BulkIndexer;
 import org.sonar.server.es.EsClient;
@@ -45,15 +43,12 @@ public class UserIndexer extends BaseIndexer {
     bulk.setLarge(lastUpdatedAt == 0L);
 
     DbSession dbSession = dbClient.openSession(false);
-    Connection dbConnection = dbSession.getConnection();
     try {
-      UserResultSetIterator rowIt = UserResultSetIterator.create(dbClient, dbConnection, lastUpdatedAt);
+      UserResultSetIterator rowIt = UserResultSetIterator.create(dbClient, dbSession, lastUpdatedAt);
       long maxUpdatedAt = doIndex(bulk, rowIt);
       rowIt.close();
       return maxUpdatedAt;
-
     } finally {
-      DbUtils.closeQuietly(dbConnection);
       dbSession.close();
     }
   }
index 22d1111613bc4416d15624fe865e928546d22ad0..ce94f359865efa889e30032ac98ee87141f6830e 100644 (file)
@@ -21,8 +21,9 @@ package org.sonar.server.user.index;
 
 import com.google.common.collect.Maps;
 import org.apache.commons.lang.StringUtils;
+import org.sonar.db.DbSession;
 import org.sonar.db.user.UserDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.db.ResultSetIterator;
 
 import java.sql.Connection;
@@ -50,10 +51,10 @@ class UserResultSetIterator extends ResultSetIterator<UserDoc> {
 
   private static final String SQL_AFTER_DATE = SQL_ALL + " where u.updated_at>?";
 
-  static UserResultSetIterator create(DbClient dbClient, Connection connection, long afterDate) {
+  static UserResultSetIterator create(DbClient dbClient, DbSession session, long afterDate) {
     try {
       String sql = afterDate > 0L ? SQL_AFTER_DATE : SQL_ALL;
-      PreparedStatement stmt = dbClient.newScrollingSelectStatement(connection, sql);
+      PreparedStatement stmt = dbClient.getMyBatis().newScrollingSelectStatement(session, sql);
       if (afterDate > 0L) {
         stmt.setLong(1, afterDate);
       }
index 2f6f5af199b2c0eb2d1d4c93f8b8650624463a38..c62f4742e13bdc884a08394d0b91fde473637a47 100644 (file)
@@ -31,7 +31,7 @@ import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.user.UserSession;
 import org.sonar.server.user.UserUpdater;
index bfb41852ae8a90171d0cabf5b2982f01f7f3df01..f5bbe77ccd0645ec428406d86c14b256c445d1bf 100644 (file)
@@ -35,7 +35,7 @@ import org.sonar.api.server.ws.WebService.Param;
 import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.es.SearchOptions;
 import org.sonar.server.es.SearchResult;
 import org.sonar.server.user.index.UserDoc;
index 3836b33390a3080ec6026f5d2c34ae1f9dd292c0..8ad3ffa13054568a7b10bf9629df54ded16075ea 100644 (file)
@@ -30,7 +30,7 @@ import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
 import org.sonar.server.user.UpdateUser;
 import org.sonar.server.user.UserSession;
 import org.sonar.server.user.UserUpdater;
index 0ece66fcd5771efaa6ee7da7297e015ed54662d7..184c841177d1c3ac124927fb4fe2187da0f487d6 100644 (file)
@@ -22,12 +22,14 @@ package org.sonar.server.activity.index;
 import org.apache.commons.dbutils.DbUtils;
 import org.assertj.core.data.MapEntry;
 import org.elasticsearch.action.update.UpdateRequest;
+import org.jruby.RubyProcess;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.sonar.api.utils.DateUtils;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.server.db.DbClient;
 import org.sonar.test.DbTests;
@@ -41,21 +43,11 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class ActivityResultSetIteratorTest {
 
   @ClassRule
-  public static DbTester dbTester = new DbTester();
-
-  DbClient client;
-  Connection connection;
+  public static DbTester dbTester = DbTester.create(System2.INSTANCE);
 
   @Before
   public void setUp() throws Exception {
     dbTester.truncateTables();
-    client = new DbClient(dbTester.database(), dbTester.myBatis());
-    connection = dbTester.openConnection();
-  }
-
-  @After
-  public void tearDown() {
-    DbUtils.closeQuietly(connection);
   }
 
   /**
@@ -64,7 +56,7 @@ public class ActivityResultSetIteratorTest {
   @Test
   public void traverse() {
     dbTester.prepareDbUnit(getClass(), "traverse.xml");
-    ActivityResultSetIterator it = ActivityResultSetIterator.create(client, connection, 0L);
+    ActivityResultSetIterator it = ActivityResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L);
 
     assertThat(it.hasNext()).isTrue();
     UpdateRequest request = it.next();
@@ -86,7 +78,7 @@ public class ActivityResultSetIteratorTest {
   @Test
   public void traverse_after_date() {
     dbTester.prepareDbUnit(getClass(), "traverse.xml");
-    ActivityResultSetIterator it = ActivityResultSetIterator.create(client, connection, DateUtils.parseDate("2014-12-01").getTime());
+    ActivityResultSetIterator it = ActivityResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), DateUtils.parseDate("2014-12-01").getTime());
 
     assertThat(it.hasNext()).isTrue();
     UpdateRequest request = it.next();
@@ -103,7 +95,7 @@ public class ActivityResultSetIteratorTest {
   @Test
   public void nothing_to_traverse() {
     dbTester.prepareDbUnit(getClass(), "traverse.xml");
-    ActivityResultSetIterator it = ActivityResultSetIterator.create(client, connection, DateUtils.parseDate("2030-01-01").getTime());
+    ActivityResultSetIterator it = ActivityResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), DateUtils.parseDate("2030-01-01").getTime());
 
     assertThat(it.hasNext()).isFalse();
     it.close();
index ae711a2e0d1f7418c4a47d6c3e5e088be481ae67..79a6a91e3d851015f92e4f30615b483a565a333a 100644 (file)
@@ -38,7 +38,7 @@ import org.sonar.db.component.ComponentDto;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
-import org.sonar.db.component.ResourceIndexerDao;
+import org.sonar.db.component.ResourceIndexDao;
 import org.sonar.db.component.ResourceKeyUpdaterDao;
 import org.sonar.server.component.db.ComponentDao;
 import org.sonar.server.db.DbClient;
@@ -75,7 +75,7 @@ public class ComponentServiceTest {
 
     when(i18n.message(Locale.getDefault(), "qualifier.TRK", "Project")).thenReturn("Project");
 
-    service = new ComponentService(dbClient, new ResourceKeyUpdaterDao(dbTester.myBatis()), i18n, new ResourceIndexerDao(dbTester.myBatis(), mock(System2.class)),
+    service = new ComponentService(dbClient, new ResourceKeyUpdaterDao(dbTester.myBatis()), i18n, new ResourceIndexDao(dbTester.myBatis(), mock(System2.class)),
       userSessionRule, System2.INSTANCE);
   }
 
index 1d5069f921bfffa33bdcfd4c1f86fa1027d76f2a..9682255f18b13ed19d04072057ddb02de0eaf800 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.api.server.ws.WebService.Param;
 import org.sonar.api.utils.System2;
 import org.sonar.api.web.UserRole;
 import org.sonar.db.DbTester;
-import org.sonar.db.component.ResourceIndexerDao;
+import org.sonar.db.component.ResourceIndexDao;
 import org.sonar.db.user.AuthorizationDao;
 import org.sonar.server.component.db.ComponentDao;
 import org.sonar.server.db.DbClient;
@@ -55,7 +55,7 @@ public class SearchActionTest {
   public void setUp() {
     dbTester.truncateTables();
     DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis(),
-      new ComponentDao(), new AuthorizationDao(dbTester.myBatis()), new ResourceIndexerDao(dbTester.myBatis(), mock(System2.class))
+      new ComponentDao(), new AuthorizationDao(dbTester.myBatis()), new ResourceIndexDao(dbTester.myBatis(), mock(System2.class))
       );
     tester = new WsTester(new ComponentsWs(mock(AppAction.class), new SearchAction(dbClient, userSessionRule)));
   }
index f5fe742e7cab4ff8c4e6f7c4a8e4eac8f0bf93ed..30a65aea399013838c85fe97c35dc5015982c939 100644 (file)
@@ -23,7 +23,7 @@ package org.sonar.server.computation.step;
 import java.io.IOException;
 import org.junit.Rule;
 import org.junit.Test;
-import org.sonar.db.component.ResourceIndexerDao;
+import org.sonar.db.component.ResourceIndexDao;
 import org.sonar.server.computation.batch.BatchReportReaderRule;
 import org.sonar.server.computation.batch.TreeRootHolderRule;
 import org.sonar.server.computation.component.Component;
@@ -43,9 +43,9 @@ public class IndexComponentsStepTest extends BaseStepTest {
   @Rule
   public BatchReportReaderRule reportReader = new BatchReportReaderRule();
 
-  ResourceIndexerDao resourceIndexerDao = mock(ResourceIndexerDao.class);
+  ResourceIndexDao resourceIndexDao = mock(ResourceIndexDao.class);
   DbIdsRepository dbIdsRepository = new DbIdsRepository();
-  IndexComponentsStep sut = new IndexComponentsStep(resourceIndexerDao, dbIdsRepository, treeRootHolder);
+  IndexComponentsStep sut = new IndexComponentsStep(resourceIndexDao, dbIdsRepository, treeRootHolder);
 
   @Test
   public void call_indexProject_of_dao() throws IOException {
@@ -55,7 +55,7 @@ public class IndexComponentsStepTest extends BaseStepTest {
 
     sut.execute();
 
-    verify(resourceIndexerDao).indexProject(123L);
+    verify(resourceIndexDao).indexProject(123L);
   }
 
   @Override
index 61384933f6b168a13a89f250acbed5a6b05d66d0..35f57a1b8bb735140ce69792246e5c4826619e58 100644 (file)
@@ -28,13 +28,13 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
 import org.sonar.db.DbTester;
+import org.sonar.db.source.FileSourceDao;
 import org.sonar.server.computation.batch.TreeRootHolderRule;
 import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.component.DumbComponent;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.es.EsTester;
-import org.sonar.db.source.FileSourceDao;
-import org.sonar.server.source.db.FileSourceTesting;
+import org.sonar.server.source.index.FileSourceTesting;
 import org.sonar.server.source.index.SourceLineDoc;
 import org.sonar.server.source.index.SourceLineIndexDefinition;
 import org.sonar.server.source.index.SourceLineIndexer;
@@ -69,9 +69,9 @@ public class IndexSourceLinesStepTest extends BaseStepTest {
   @Test
   public void index_source() throws Exception {
     dbTester.prepareDbUnit(getClass(), "index_source.xml");
-    Connection connection = dbTester.openConnection();
-    FileSourceTesting.updateDataColumn(connection, "FILE1_UUID", FileSourceTesting.newRandomData(1).build());
-    connection.close();
+    try (Connection connection = dbTester.openConnection()) {
+      FileSourceTesting.updateDataColumn(connection, "FILE1_UUID", FileSourceTesting.newRandomData(1).build());
+    }
 
     treeRootHolder.setRoot(DumbComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey("PROJECT_KEY").build());
 
index a4b020c034a17d66b989ac6f4d96304a68eb11d3..31653fafac38401ef3696d846772b279f52bd828 100644 (file)
@@ -20,7 +20,6 @@
 
 package org.sonar.server.computation.step;
 
-import java.sql.Connection;
 import java.util.List;
 import org.elasticsearch.search.SearchHit;
 import org.junit.Before;
@@ -28,13 +27,14 @@ import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
+import org.sonar.db.source.FileSourceDao;
 import org.sonar.server.computation.batch.TreeRootHolderRule;
 import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.component.DumbComponent;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.es.EsTester;
-import org.sonar.db.source.FileSourceDao;
 import org.sonar.server.test.db.TestTesting;
 import org.sonar.server.test.index.TestDoc;
 import org.sonar.server.test.index.TestIndexDefinition;
@@ -45,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class IndexTestsStepTest extends BaseStepTest {
 
   @ClassRule
-  public static DbTester dbTester = new DbTester();
+  public static DbTester dbTester = DbTester.create(System2.INSTANCE);
 
   @ClassRule
   public static EsTester esTester = new EsTester().addDefinitions(new TestIndexDefinition(new Settings()));
@@ -71,9 +71,7 @@ public class IndexTestsStepTest extends BaseStepTest {
   @Test
   public void index_test() throws Exception {
     dbTester.prepareDbUnit(getClass(), "index_source.xml");
-    Connection connection = dbTester.openConnection();
-    TestTesting.updateDataColumn(connection, "FILE1_UUID", TestTesting.newRandomTests(1));
-    connection.close();
+    TestTesting.updateDataColumn(dbTester.getSession(), "FILE1_UUID", TestTesting.newRandomTests(1));
 
     treeRootHolder.setRoot(DumbComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey("PROJECT_KEY").build());
 
index 8c9ae2e8e45eff23688b88a467db38fc8b5e57fa..c1726c38da54611b711d0e9d379a73061ef42017 100644 (file)
@@ -40,7 +40,7 @@ public class DbClientTest {
   public DbTester db = new DbTester();
 
   @Test
-  public void facade() throws Exception {
+  public void get_daos() throws Exception {
     MyBatis myBatis = db.myBatis();
     RuleDao ruleDao = new RuleDao(System2.INSTANCE);
     QualityProfileDao qualityProfileDao = new QualityProfileDao(myBatis, System2.INSTANCE);
@@ -48,7 +48,7 @@ public class DbClientTest {
 
     DbClient client = new DbClient(db.database(), myBatis, ruleDao, activeRuleDao, qualityProfileDao);
 
-    assertThat(client.database()).isSameAs(db.database());
+    assertThat(client.getDatabase()).isSameAs(db.database());
     DbSession dbSession = client.openSession(true);
     assertThat(dbSession).isNotNull();
     assertThat(dbSession.getConnection().isClosed()).isFalse();
index 15e6e013aba5a02190fe6639575d7146ba9b13ae..9575d534eee89963d7560a2f743f9fd5efad78ae 100644 (file)
@@ -58,7 +58,7 @@ public class DatabaseMigratorTest extends AbstractDaoTestCase {
 
   @Test
   public void should_support_only_creation_of_h2_database() {
-    when(dbClient.database().getDialect()).thenReturn(new MySql());
+    when(dbClient.getDatabase().getDialect()).thenReturn(new MySql());
 
     assertThat(migrator.createDatabase()).isFalse();
     verify(dbClient, never()).openSession(anyBoolean());
@@ -82,7 +82,7 @@ public class DatabaseMigratorTest extends AbstractDaoTestCase {
   @Test
   public void should_create_schema_on_h2() {
     Dialect supportedDialect = new H2();
-    when(dbClient.database().getDialect()).thenReturn(supportedDialect);
+    when(dbClient.getDatabase().getDialect()).thenReturn(supportedDialect);
     Connection connection = mock(Connection.class);
     DbSession session = mock(DbSession.class);
     when(session.getConnection()).thenReturn(connection);
index 7b83ac06d5c51dc3e2d2d12f442f658fdb4bef1c..e54d28ba0b58c2e71c6088a3abb066310316cf1c 100644 (file)
@@ -20,6 +20,9 @@
 
 package org.sonar.server.db.migrations.v44;
 
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
@@ -27,10 +30,6 @@ import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.server.db.DbClient;
 
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.Statement;
-
 import static org.assertj.core.api.Assertions.assertThat;
 
 public class ConvertProfileMeasuresMigrationTest {
@@ -100,16 +99,16 @@ public class ConvertProfileMeasuresMigrationTest {
 
     migration.execute();
 
-    Connection connection = db.openConnection();
-    Statement stmt = connection.createStatement();
-    ResultSet rs = stmt.executeQuery("select * from project_measures where id=2");
-    try {
-      // measure is deleted
-      assertThat(rs.next()).isFalse();
-    } finally {
-      rs.close();
-      stmt.close();
-      connection.close();
+    try (Connection connection = db.openConnection()) {
+      Statement stmt = connection.createStatement();
+      ResultSet rs = stmt.executeQuery("select * from project_measures where id=2");
+      try {
+        // measure is deleted
+        assertThat(rs.next()).isFalse();
+      } finally {
+        rs.close();
+        stmt.close();
+      }
     }
   }
 }
index 1ec06c329615c898b879e52b9dad60f9f089cfcc..c6c9cbdfd91bb1059ff1d089e4c9646b345d2938 100644 (file)
@@ -35,10 +35,10 @@ import org.sonar.core.issue.DefaultIssueComment;
 import org.sonar.core.issue.IssueChangeContext;
 import org.sonar.db.AbstractDaoTestCase;
 import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.issue.IssueDto;
 import org.sonar.db.issue.IssueMapper;
+import org.sonar.server.db.DbClient;
 
 public class IssueStorageTest extends AbstractDaoTestCase {
 
@@ -58,7 +58,8 @@ public class IssueStorageTest extends AbstractDaoTestCase {
 
   @Test
   public void batch_insert_new_issues() {
-    FakeBatchSaver saver = new FakeBatchSaver(getMyBatis(), new FakeRuleFinder());
+    DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis());
+    FakeBatchSaver saver = new FakeBatchSaver(dbClient, new FakeRuleFinder());
 
     DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
     // override generated key
@@ -93,7 +94,8 @@ public class IssueStorageTest extends AbstractDaoTestCase {
 
   @Test
   public void batch_insert_new_issues_with_session() {
-    FakeBatchSaver saver = new FakeBatchSaver(getMyBatis(), new FakeRuleFinder());
+    DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis());
+    FakeBatchSaver saver = new FakeBatchSaver(dbClient, new FakeRuleFinder());
 
     DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
     // override generated key
@@ -131,7 +133,8 @@ public class IssueStorageTest extends AbstractDaoTestCase {
   public void server_insert_new_issues_with_session() {
     ComponentDto project = new ComponentDto().setId(10L).setUuid("uuid-10");
     ComponentDto component = new ComponentDto().setId(100L).setUuid("uuid-100");
-    FakeServerSaver saver = new FakeServerSaver(getMyBatis(), new FakeRuleFinder(), component, project);
+    DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis());
+    FakeServerSaver saver = new FakeServerSaver(dbClient, new FakeRuleFinder(), component, project);
 
     DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
     // override generated key
@@ -169,7 +172,8 @@ public class IssueStorageTest extends AbstractDaoTestCase {
   public void batch_update_issues() {
     setupData("should_update_issues");
 
-    FakeBatchSaver saver = new FakeBatchSaver(getMyBatis(), new FakeRuleFinder());
+    DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis());
+    FakeBatchSaver saver = new FakeBatchSaver(dbClient, new FakeRuleFinder());
 
     DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
     // override generated key
@@ -215,7 +219,8 @@ public class IssueStorageTest extends AbstractDaoTestCase {
 
     ComponentDto project = new ComponentDto().setId(10L).setUuid("whatever-uuid");
     ComponentDto component = new ComponentDto().setId(100L).setUuid("whatever-uuid-2");
-    FakeServerSaver saver = new FakeServerSaver(getMyBatis(), new FakeRuleFinder(), component, project);
+    DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis());
+    FakeServerSaver saver = new FakeServerSaver(dbClient, new FakeRuleFinder(), component, project);
 
     DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
     // override generated key
@@ -256,8 +261,8 @@ public class IssueStorageTest extends AbstractDaoTestCase {
 
   static class FakeBatchSaver extends IssueStorage {
 
-    protected FakeBatchSaver(MyBatis mybatis, RuleFinder ruleFinder) {
-      super(mybatis, ruleFinder);
+    protected FakeBatchSaver(DbClient dbClient, RuleFinder ruleFinder) {
+      super(dbClient, ruleFinder);
     }
 
     @Override
@@ -280,8 +285,8 @@ public class IssueStorageTest extends AbstractDaoTestCase {
     private final ComponentDto component;
     private final ComponentDto project;
 
-    protected FakeServerSaver(MyBatis mybatis, RuleFinder ruleFinder, ComponentDto component, ComponentDto project) {
-      super(mybatis, ruleFinder);
+    protected FakeServerSaver(DbClient dbClient, RuleFinder ruleFinder, ComponentDto component, ComponentDto project) {
+      super(dbClient, ruleFinder);
       this.component = component;
       this.project = project;
     }
index 5b2b9d9c6759f02265df27d6bb6149d00560ad7c..26237ec19257ccdbdf487c98252b85909c0b8e97 100644 (file)
@@ -51,7 +51,6 @@ import static org.mockito.Mockito.when;
 public class ServerIssueStorageTest extends AbstractDaoTestCase {
 
   DbClient dbClient;
-  DbSession session;
 
   ServerIssueStorage storage;
 
@@ -59,26 +58,19 @@ public class ServerIssueStorageTest extends AbstractDaoTestCase {
   public void setupDbClient() {
     System2 system = mock(System2.class);
     when(system.now()).thenReturn(2000000000L);
-    dbClient = new DbClient(getDatabase(), getMyBatis(),
+    dbClient = new DbClient(dbTester.database(), getMyBatis(),
       new ComponentDao(),
       new IssueDao(getMyBatis()),
       new ResourceDao(getMyBatis(), system));
-    session = dbClient.openSession(false);
 
-    storage = new ServerIssueStorage(getMyBatis(), new FakeRuleFinder(), dbClient, mock(IssueIndexer.class));
-  }
-
-  @After
-  public void tearDown() {
-    session.close();
+    storage = new ServerIssueStorage(new FakeRuleFinder(), dbClient, mock(IssueIndexer.class));
   }
 
   @Test
   public void load_component_id_from_db() {
     setupData("load_component_id_from_db");
-    session.commit();
 
-    long componentId = storage.component(session, new DefaultIssue().setComponentKey("struts:Action")).getId();
+    long componentId = storage.component(dbTester.getSession(), new DefaultIssue().setComponentKey("struts:Action")).getId();
 
     assertThat(componentId).isEqualTo(100);
   }
@@ -86,9 +78,8 @@ public class ServerIssueStorageTest extends AbstractDaoTestCase {
   @Test
   public void load_project_id_from_db() {
     setupData("load_project_id_from_db");
-    session.commit();
 
-    long projectId = storage.project(session, new DefaultIssue().setProjectKey("struts")).getId();
+    long projectId = storage.project(dbTester.getSession(), new DefaultIssue().setProjectKey("struts")).getId();
 
     assertThat(projectId).isEqualTo(1);
   }
index cbfd4918f225e6ee825b3088104c756ebd49eabe..c0e8293cea5c74ea07d09b7e748b1c5fd85bddda 100644 (file)
@@ -21,48 +21,35 @@ package org.sonar.server.issue.index;
 
 import com.google.common.base.Predicate;
 import com.google.common.collect.Iterables;
-import org.apache.commons.dbutils.DbUtils;
-import org.junit.After;
+import java.util.Collection;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
-import org.sonar.server.db.DbClient;
 import org.sonar.test.DbTests;
 
-import java.sql.Connection;
-import java.util.Collection;
-
 import static org.assertj.core.api.Assertions.assertThat;
 
 @Category(DbTests.class)
 public class IssueAuthorizationDaoTest {
 
   @ClassRule
-  public static DbTester dbTester = new DbTester();
+  public static DbTester dbTester = DbTester.create(System2.INSTANCE);
 
   IssueAuthorizationDao dao = new IssueAuthorizationDao();
-  DbClient client;
-  Connection connection;
 
   @Before
   public void setUp() throws Exception {
     dbTester.truncateTables();
-    client = new DbClient(dbTester.database(), dbTester.myBatis());
-    connection = dbTester.openConnection();
-  }
-
-  @After
-  public void tearDown() {
-    DbUtils.closeQuietly(connection);
   }
 
   @Test
   public void select_all() {
     dbTester.prepareDbUnit(getClass(), "shared.xml");
 
-    Collection<IssueAuthorizationDao.Dto> dtos = dao.selectAfterDate(client, connection, 0L);
+    Collection<IssueAuthorizationDao.Dto> dtos = dao.selectAfterDate(dbTester.getDbClient(), dbTester.getSession(), 0L);
     assertThat(dtos).hasSize(2);
 
     IssueAuthorizationDao.Dto abc = Iterables.find(dtos, new ProjectPredicate("ABC"));
@@ -80,7 +67,7 @@ public class IssueAuthorizationDaoTest {
   public void select_after_date() {
     dbTester.prepareDbUnit(getClass(), "shared.xml");
 
-    Collection<IssueAuthorizationDao.Dto> dtos = dao.selectAfterDate(client, connection, 1500000000L);
+    Collection<IssueAuthorizationDao.Dto> dtos = dao.selectAfterDate(dbTester.getDbClient(), dbTester.getSession(), 1500000000L);
 
     // only project DEF was updated in this period
     assertThat(dtos).hasSize(1);
@@ -94,7 +81,7 @@ public class IssueAuthorizationDaoTest {
   public void no_authorization() {
     dbTester.prepareDbUnit(getClass(), "no_authorization.xml");
 
-    Collection<IssueAuthorizationDao.Dto> dtos = dao.selectAfterDate(client, connection, 0L);
+    Collection<IssueAuthorizationDao.Dto> dtos = dao.selectAfterDate(dbTester.getDbClient(), dbTester.getSession(), 0L);
 
     assertThat(dtos).hasSize(1);
     IssueAuthorizationDao.Dto abc = Iterables.find(dtos, new ProjectPredicate("ABC"));
index 9c9fd49f67fd6d4a7b507751c07258281748cae7..ffd4017770df48efd3fdac025701a2d0644cd319 100644 (file)
@@ -22,12 +22,14 @@ package org.sonar.server.issue.index;
 import com.google.common.base.Function;
 import com.google.common.collect.Maps;
 import org.apache.commons.dbutils.DbUtils;
+import org.jruby.RubyProcess;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.sonar.api.rule.RuleKey;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.server.db.DbClient;
 import org.sonar.test.DbTests;
@@ -41,27 +43,18 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class IssueResultSetIteratorTest {
 
   @ClassRule
-  public static DbTester dbTester = new DbTester();
+  public static DbTester dbTester = DbTester.create(System2.INSTANCE);
 
-  DbClient client;
-  Connection connection;
 
   @Before
   public void setUp() throws Exception {
     dbTester.truncateTables();
-    client = new DbClient(dbTester.database(), dbTester.myBatis());
-    connection = dbTester.openConnection();
-  }
-
-  @After
-  public void tearDown() {
-    DbUtils.closeQuietly(connection);
   }
 
   @Test
   public void iterator_over_one_issue() {
     dbTester.prepareDbUnit(getClass(), "one_issue.xml");
-    IssueResultSetIterator it = IssueResultSetIterator.create(client, connection, 0L);
+    IssueResultSetIterator it = IssueResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L);
     Map<String, IssueDoc> issuesByKey = issuesByKey(it);
     it.close();
 
@@ -95,7 +88,7 @@ public class IssueResultSetIteratorTest {
   @Test
   public void iterator_over_issues() {
     dbTester.prepareDbUnit(getClass(), "shared.xml");
-    IssueResultSetIterator it = IssueResultSetIterator.create(client, connection, 0L);
+    IssueResultSetIterator it = IssueResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L);
     Map<String, IssueDoc> issuesByKey = issuesByKey(it);
     it.close();
 
@@ -153,7 +146,7 @@ public class IssueResultSetIteratorTest {
   @Test
   public void extract_directory_path() {
     dbTester.prepareDbUnit(getClass(), "extract_directory_path.xml");
-    IssueResultSetIterator it = IssueResultSetIterator.create(client, connection, 0L);
+    IssueResultSetIterator it = IssueResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L);
     Map<String, IssueDoc> issuesByKey = issuesByKey(it);
     it.close();
 
@@ -175,7 +168,7 @@ public class IssueResultSetIteratorTest {
   @Test
   public void extract_file_path() {
     dbTester.prepareDbUnit(getClass(), "extract_file_path.xml");
-    IssueResultSetIterator it = IssueResultSetIterator.create(client, connection, 0L);
+    IssueResultSetIterator it = IssueResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L);
     Map<String, IssueDoc> issuesByKey = issuesByKey(it);
     it.close();
 
@@ -197,7 +190,7 @@ public class IssueResultSetIteratorTest {
   @Test
   public void select_after_date() {
     dbTester.prepareDbUnit(getClass(), "shared.xml");
-    IssueResultSetIterator it = IssueResultSetIterator.create(client, connection, 1420000000000L);
+    IssueResultSetIterator it = IssueResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 1_420_000_000_000L);
 
     assertThat(it.hasNext()).isTrue();
     IssueDoc issue = it.next();
index a5c3487e6ff0f78280fe0b309773dec24803db50..a9c6752d12e433797dfeb40f45d684ecfe7275fb 100644 (file)
@@ -66,7 +66,7 @@ public class RegisterRulesTest extends AbstractDaoTestCase {
     when(system.now()).thenReturn(DATE1.getTime());
     RuleDao ruleDao = new RuleDao(system);
     ActiveRuleDao activeRuleDao = new ActiveRuleDao(new QualityProfileDao(getMyBatis(), system), ruleDao, system);
-    dbClient = new DbClient(getDatabase(), getMyBatis(), ruleDao, activeRuleDao,
+    dbClient = new DbClient(dbTester.database(), getMyBatis(), ruleDao, activeRuleDao,
       new QualityProfileDao(getMyBatis(), system), new CharacteristicDao(getMyBatis()));
     dbSession = dbClient.openSession(false);
   }
diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/db/FileSourceTesting.java b/server/sonar-server/src/test/java/org/sonar/server/source/db/FileSourceTesting.java
deleted file mode 100644 (file)
index 5722ad6..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.source.db;
-
-import java.io.IOException;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.Arrays;
-import org.apache.commons.lang.RandomStringUtils;
-import org.apache.commons.lang.math.RandomUtils;
-import org.sonar.db.source.FileSourceDto;
-
-public class FileSourceTesting {
-
-  private FileSourceTesting() {
-    // only static stuff
-  }
-
-  public static void updateDataColumn(Connection connection, String fileUuid, FileSourceDb.Data data) throws SQLException {
-    updateDataColumn(connection, fileUuid, FileSourceDto.encodeSourceData(data));
-  }
-
-  public static void updateDataColumn(Connection connection, String fileUuid, byte[] data) throws SQLException {
-    PreparedStatement stmt = connection.prepareStatement("UPDATE file_sources SET binary_data = ? WHERE file_uuid=? AND data_type='" + FileSourceDto.Type.SOURCE + "'");
-    stmt.setBytes(1, data);
-    stmt.setString(2, fileUuid);
-    stmt.executeUpdate();
-    stmt.close();
-  }
-
-  /**
-   * Generate predefined fake data. Result is mutable.
-   */
-  public static FileSourceDb.Data.Builder newFakeData(int numberOfLines) throws IOException {
-    FileSourceDb.Data.Builder dataBuilder = FileSourceDb.Data.newBuilder();
-    for (int i = 1; i <= numberOfLines; i++) {
-      dataBuilder.addLinesBuilder()
-        .setLine(i)
-        .setScmRevision("REVISION_" + i)
-        .setScmAuthor("AUTHOR_" + i)
-        .setScmDate(1_500_000_000_00L + i)
-        .setSource("SOURCE_" + i)
-        .setUtLineHits(i)
-        .setUtConditions(i + 1)
-        .setUtCoveredConditions(i + 2)
-        .setItLineHits(i + 3)
-        .setItConditions(i + 4)
-        .setItCoveredConditions(i + 5)
-        .setOverallLineHits(i + 6)
-        .setOverallConditions(i + 7)
-        .setOverallCoveredConditions(i + 8)
-        .setHighlighting("HIGHLIGHTING_" + i)
-        .setSymbols("SYMBOLS_" + i)
-        .addAllDuplication(Arrays.asList(i))
-        .build();
-    }
-    return dataBuilder;
-  }
-
-  /**
-   * Generate random data. Result is mutable.
-   */
-  public static FileSourceDb.Data.Builder newRandomData(int numberOfLines) throws IOException {
-    FileSourceDb.Data.Builder dataBuilder = FileSourceDb.Data.newBuilder();
-    for (int i = 1; i <= numberOfLines; i++) {
-      dataBuilder.addLinesBuilder()
-        .setLine(i)
-        .setScmRevision(RandomStringUtils.randomAlphanumeric(15))
-        .setScmAuthor(RandomStringUtils.randomAlphanumeric(10))
-        .setScmDate(RandomUtils.nextLong())
-        .setSource(RandomStringUtils.randomAlphanumeric(20))
-        .setUtLineHits(RandomUtils.nextInt(4))
-        .setUtConditions(RandomUtils.nextInt(4))
-        .setUtCoveredConditions(RandomUtils.nextInt(4))
-        .setItLineHits(RandomUtils.nextInt(4))
-        .setItConditions(RandomUtils.nextInt(4))
-        .setItCoveredConditions(RandomUtils.nextInt(4))
-        .setOverallLineHits(RandomUtils.nextInt(4))
-        .setOverallConditions(RandomUtils.nextInt(4))
-        .setOverallCoveredConditions(RandomUtils.nextInt(4))
-        .setHighlighting(RandomStringUtils.randomAlphanumeric(40))
-        .setSymbols(RandomStringUtils.randomAlphanumeric(30))
-        .addAllDuplication(Arrays.asList(RandomUtils.nextInt(200), RandomUtils.nextInt(200)))
-        .build();
-    }
-    return dataBuilder;
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/index/FileSourceTesting.java b/server/sonar-server/src/test/java/org/sonar/server/source/index/FileSourceTesting.java
new file mode 100644 (file)
index 0000000..f6f0a0d
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.source.index;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.Arrays;
+import org.apache.commons.lang.RandomStringUtils;
+import org.apache.commons.lang.math.RandomUtils;
+import org.sonar.db.source.FileSourceDto;
+import org.sonar.server.source.db.FileSourceDb;
+
+public class FileSourceTesting {
+
+  private FileSourceTesting() {
+    // only static stuff
+  }
+
+  public static void updateDataColumn(Connection connection, String fileUuid, FileSourceDb.Data data) throws SQLException {
+    updateDataColumn(connection, fileUuid, FileSourceDto.encodeSourceData(data));
+  }
+
+  public static void updateDataColumn(Connection connection, String fileUuid, byte[] data) throws SQLException {
+    PreparedStatement stmt = connection.prepareStatement("UPDATE file_sources SET binary_data = ? WHERE file_uuid=? AND data_type='" + FileSourceDto.Type.SOURCE + "'");
+    stmt.setBytes(1, data);
+    stmt.setString(2, fileUuid);
+    stmt.executeUpdate();
+    stmt.close();
+    connection.commit();
+  }
+
+  /**
+   * Generate predefined fake data. Result is mutable.
+   */
+  public static FileSourceDb.Data.Builder newFakeData(int numberOfLines) throws IOException {
+    FileSourceDb.Data.Builder dataBuilder = FileSourceDb.Data.newBuilder();
+    for (int i = 1; i <= numberOfLines; i++) {
+      dataBuilder.addLinesBuilder()
+        .setLine(i)
+        .setScmRevision("REVISION_" + i)
+        .setScmAuthor("AUTHOR_" + i)
+        .setScmDate(1_500_000_000_00L + i)
+        .setSource("SOURCE_" + i)
+        .setUtLineHits(i)
+        .setUtConditions(i + 1)
+        .setUtCoveredConditions(i + 2)
+        .setItLineHits(i + 3)
+        .setItConditions(i + 4)
+        .setItCoveredConditions(i + 5)
+        .setOverallLineHits(i + 6)
+        .setOverallConditions(i + 7)
+        .setOverallCoveredConditions(i + 8)
+        .setHighlighting("HIGHLIGHTING_" + i)
+        .setSymbols("SYMBOLS_" + i)
+        .addAllDuplication(Arrays.asList(i))
+        .build();
+    }
+    return dataBuilder;
+  }
+
+  /**
+   * Generate random data. Result is mutable.
+   */
+  public static FileSourceDb.Data.Builder newRandomData(int numberOfLines) throws IOException {
+    FileSourceDb.Data.Builder dataBuilder = FileSourceDb.Data.newBuilder();
+    for (int i = 1; i <= numberOfLines; i++) {
+      dataBuilder.addLinesBuilder()
+        .setLine(i)
+        .setScmRevision(RandomStringUtils.randomAlphanumeric(15))
+        .setScmAuthor(RandomStringUtils.randomAlphanumeric(10))
+        .setScmDate(RandomUtils.nextLong())
+        .setSource(RandomStringUtils.randomAlphanumeric(20))
+        .setUtLineHits(RandomUtils.nextInt(4))
+        .setUtConditions(RandomUtils.nextInt(4))
+        .setUtCoveredConditions(RandomUtils.nextInt(4))
+        .setItLineHits(RandomUtils.nextInt(4))
+        .setItConditions(RandomUtils.nextInt(4))
+        .setItCoveredConditions(RandomUtils.nextInt(4))
+        .setOverallLineHits(RandomUtils.nextInt(4))
+        .setOverallConditions(RandomUtils.nextInt(4))
+        .setOverallCoveredConditions(RandomUtils.nextInt(4))
+        .setHighlighting(RandomStringUtils.randomAlphanumeric(40))
+        .setSymbols(RandomStringUtils.randomAlphanumeric(30))
+        .addAllDuplication(Arrays.asList(RandomUtils.nextInt(200), RandomUtils.nextInt(200)))
+        .build();
+    }
+    return dataBuilder;
+  }
+}
index cae481e0995271cddc8246c7e0e8271fb730f993..a93cfbe84548953f53c10c79be79bba84fdb4c81 100644 (file)
@@ -21,6 +21,11 @@ package org.sonar.server.source.index;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterators;
+import java.io.IOException;
+import java.sql.Connection;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
 import org.apache.commons.io.FileUtils;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
@@ -36,16 +41,9 @@ import org.sonar.db.DbTester;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.source.db.FileSourceDb;
-import org.sonar.server.source.db.FileSourceTesting;
 import org.sonar.test.DbTests;
 import org.sonar.test.TestUtils;
 
-import java.io.IOException;
-import java.sql.Connection;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.entry;
 import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_DUPLICATIONS;
@@ -90,9 +88,9 @@ public class SourceLineIndexerTest {
   public void index_source_lines() throws Exception {
     db.prepareDbUnit(getClass(), "db.xml");
 
-    Connection connection = db.openConnection();
-    FileSourceTesting.updateDataColumn(connection, "FILE_UUID", FileSourceTesting.newRandomData(3).build());
-    connection.close();
+    try (Connection connection = db.openConnection()) {
+      FileSourceTesting.updateDataColumn(connection, "FILE_UUID", FileSourceTesting.newRandomData(3).build());
+    }
 
     indexer.index();
     assertThat(countDocuments()).isEqualTo(3);
@@ -102,9 +100,9 @@ public class SourceLineIndexerTest {
   public void index_source_lines_from_project() throws Exception {
     db.prepareDbUnit(getClass(), "db.xml");
 
-    Connection connection = db.openConnection();
-    FileSourceTesting.updateDataColumn(connection, "FILE_UUID", FileSourceTesting.newRandomData(3).build());
-    connection.close();
+    try (Connection connection = db.openConnection()) {
+      FileSourceTesting.updateDataColumn(connection, "FILE_UUID", FileSourceTesting.newRandomData(3).build());
+    }
 
     indexer.index("PROJECT_UUID");
     assertThat(countDocuments()).isEqualTo(3);
@@ -114,9 +112,9 @@ public class SourceLineIndexerTest {
   public void index_nothing_from_unknown_project() throws Exception {
     db.prepareDbUnit(getClass(), "db.xml");
 
-    Connection connection = db.openConnection();
-    FileSourceTesting.updateDataColumn(connection, "FILE_UUID", FileSourceTesting.newRandomData(3).build());
-    connection.close();
+    try (Connection connection = db.openConnection()) {
+      FileSourceTesting.updateDataColumn(connection, "FILE_UUID", FileSourceTesting.newRandomData(3).build());
+    }
 
     indexer.index("UNKNOWN");
     assertThat(countDocuments()).isZero();
index 8d927b7b7be18c69a8e7acdb1b452ea1a1dd17f3..058990e7b033cde2e7d705f2837dbdef63008f37 100644 (file)
  */
 package org.sonar.server.source.index;
 
+import java.sql.Connection;
+import java.util.Map;
 import org.assertj.core.data.MapEntry;
 import org.elasticsearch.action.update.UpdateRequest;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
-import org.sonar.server.db.DbClient;
 import org.sonar.server.source.db.FileSourceDb;
-import org.sonar.server.source.db.FileSourceTesting;
 import org.sonar.test.DbTests;
 
-import java.sql.Connection;
-import java.util.Map;
-
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.fail;
 
@@ -43,34 +38,24 @@ import static org.junit.Assert.fail;
 public class SourceLineResultSetIteratorTest {
 
   @ClassRule
-  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, SourceLineResultSetIteratorTest.class, "schema.sql");
-
-  DbClient dbClient;
-
-  Connection connection;
+  public static DbTester db = DbTester.create(System2.INSTANCE);
 
   SourceLineResultSetIterator iterator;
 
-  @Before
-  public void setUp() throws Exception {
-    dbClient = new DbClient(db.database(), db.myBatis());
-    connection = db.openConnection();
-  }
-
-  @After
   public void after() throws Exception {
     if (iterator != null) {
       iterator.close();
     }
-    connection.close();
   }
 
   @Test
   public void traverse_db() throws Exception {
     db.prepareDbUnit(getClass(), "shared.xml");
-    FileSourceTesting.updateDataColumn(connection, "F1", FileSourceTesting.newFakeData(3).build());
+    try (Connection connection = db.openConnection()) {
+      FileSourceTesting.updateDataColumn(connection, "F1", FileSourceTesting.newFakeData(3).build());
+    }
 
-    iterator = SourceLineResultSetIterator.create(dbClient, connection, 0L, null);
+    iterator = SourceLineResultSetIterator.create(db.getDbClient(), db.getSession(), 0L, null);
     assertThat(iterator.hasNext()).isTrue();
     FileSourcesUpdaterHelper.Row row = iterator.next();
     assertThat(row.getProjectUuid()).isEqualTo("P1");
@@ -97,7 +82,7 @@ public class SourceLineResultSetIteratorTest {
       MapEntry.entry(SourceLineIndexDefinition.FIELD_OVERALL_LINE_HITS, 7),
       MapEntry.entry(SourceLineIndexDefinition.FIELD_OVERALL_CONDITIONS, 8),
       MapEntry.entry(SourceLineIndexDefinition.FIELD_OVERALL_COVERED_CONDITIONS, 9)
-    );
+      );
   }
 
   /**
@@ -108,9 +93,11 @@ public class SourceLineResultSetIteratorTest {
     db.prepareDbUnit(getClass(), "shared.xml");
     FileSourceDb.Data.Builder dataBuilder = FileSourceDb.Data.newBuilder();
     dataBuilder.addLinesBuilder().setLine(1).build();
-    FileSourceTesting.updateDataColumn(connection, "F1", dataBuilder.build());
+    try (Connection connection = db.openConnection()) {
+      FileSourceTesting.updateDataColumn(connection, "F1", dataBuilder.build());
+    }
 
-    iterator = SourceLineResultSetIterator.create(dbClient, connection, 0L, null);
+    iterator = SourceLineResultSetIterator.create(db.getDbClient(), db.getSession(), 0L, null);
     FileSourcesUpdaterHelper.Row row = iterator.next();
     assertThat(row.getProjectUuid()).isEqualTo("P1");
     assertThat(row.getFileUuid()).isEqualTo("F1");
@@ -122,7 +109,7 @@ public class SourceLineResultSetIteratorTest {
       MapEntry.entry(SourceLineIndexDefinition.FIELD_PROJECT_UUID, "P1"),
       MapEntry.entry(SourceLineIndexDefinition.FIELD_FILE_UUID, "F1"),
       MapEntry.entry(SourceLineIndexDefinition.FIELD_LINE, 1)
-    );
+      );
     // null values
     assertThat(doc).containsKeys(
       SourceLineIndexDefinition.FIELD_SCM_REVISION,
@@ -138,14 +125,14 @@ public class SourceLineResultSetIteratorTest {
       SourceLineIndexDefinition.FIELD_OVERALL_LINE_HITS,
       SourceLineIndexDefinition.FIELD_OVERALL_CONDITIONS,
       SourceLineIndexDefinition.FIELD_OVERALL_COVERED_CONDITIONS
-    );
+      );
   }
 
   @Test
   public void filter_by_date() {
     db.prepareDbUnit(getClass(), "shared.xml");
 
-    iterator = SourceLineResultSetIterator.create(dbClient, connection, 2000000000000L, null);
+    iterator = SourceLineResultSetIterator.create(db.getDbClient(), db.getSession(), 2000000000000L, null);
     assertThat(iterator.hasNext()).isFalse();
   }
 
@@ -154,9 +141,11 @@ public class SourceLineResultSetIteratorTest {
     db.prepareDbUnit(getClass(), "filter_by_project.xml");
     FileSourceDb.Data.Builder dataBuilder = FileSourceDb.Data.newBuilder();
     dataBuilder.addLinesBuilder().setLine(1).build();
-    FileSourceTesting.updateDataColumn(connection, "F1", dataBuilder.build());
+    try (Connection connection = db.openConnection()) {
+      FileSourceTesting.updateDataColumn(connection, "F1", dataBuilder.build());
+    }
 
-    iterator = SourceLineResultSetIterator.create(dbClient, connection, 0L, "P1");
+    iterator = SourceLineResultSetIterator.create(db.getDbClient(), db.getSession(), 0L, "P1");
 
     FileSourcesUpdaterHelper.Row row = iterator.next();
     assertThat(row.getProjectUuid()).isEqualTo("P1");
@@ -171,9 +160,11 @@ public class SourceLineResultSetIteratorTest {
     db.prepareDbUnit(getClass(), "filter_by_project_and_date.xml");
     FileSourceDb.Data.Builder dataBuilder = FileSourceDb.Data.newBuilder();
     dataBuilder.addLinesBuilder().setLine(1).build();
-    FileSourceTesting.updateDataColumn(connection, "F1", dataBuilder.build());
+    try (Connection connection = db.openConnection()) {
+      FileSourceTesting.updateDataColumn(connection, "F1", dataBuilder.build());
+    }
 
-    iterator = SourceLineResultSetIterator.create(dbClient, connection, 1400000000000L, "P1");
+    iterator = SourceLineResultSetIterator.create(db.getDbClient(), db.getSession(), 1400000000000L, "P1");
 
     FileSourcesUpdaterHelper.Row row = iterator.next();
     assertThat(row.getProjectUuid()).isEqualTo("P1");
@@ -187,9 +178,11 @@ public class SourceLineResultSetIteratorTest {
   public void fail_on_bad_data_format() throws Exception {
     db.prepareDbUnit(getClass(), "shared.xml");
 
-    FileSourceTesting.updateDataColumn(connection, "F1", "THIS_IS_NOT_PROTOBUF".getBytes());
+    try (Connection connection = db.openConnection()) {
+      FileSourceTesting.updateDataColumn(connection, "F1", "THIS_IS_NOT_PROTOBUF".getBytes());
+    }
 
-    iterator = SourceLineResultSetIterator.create(dbClient, connection, 0L, null);
+    iterator = SourceLineResultSetIterator.create(db.getDbClient(), db.getSession(), 0L, null);
     try {
       assertThat(iterator.hasNext()).isTrue();
       iterator.next();
index 79ef35166db231878030474c05d3e74059540763..bf900c2dd39a269926435b6da36ff80c989689cc 100644 (file)
@@ -23,6 +23,7 @@ package org.sonar.server.test.db;
 import org.apache.commons.lang.RandomStringUtils;
 import org.apache.commons.lang.math.RandomUtils;
 import org.sonar.api.utils.internal.Uuids;
+import org.sonar.db.DbSession;
 import org.sonar.db.source.FileSourceDto;
 import org.sonar.server.source.db.FileSourceDb;
 import org.sonar.server.source.db.FileSourceDb.Test.TestStatus;
@@ -40,16 +41,18 @@ public class TestTesting {
     // only static stuff
   }
 
-  public static void updateDataColumn(Connection connection, String fileUuid, List<FileSourceDb.Test> tests) throws SQLException {
-    updateDataColumn(connection, fileUuid, FileSourceDto.encodeTestData(tests));
+  public static void updateDataColumn(DbSession session, String fileUuid, List<FileSourceDb.Test> tests) throws SQLException {
+    updateDataColumn(session, fileUuid, FileSourceDto.encodeTestData(tests));
   }
 
-  public static void updateDataColumn(Connection connection, String fileUuid, byte[] data) throws SQLException {
+  public static void updateDataColumn(DbSession session, String fileUuid, byte[] data) throws SQLException {
+    Connection connection = session.getConnection();
     PreparedStatement stmt = connection.prepareStatement("UPDATE file_sources SET binary_data = ? WHERE file_uuid=? AND data_type='TEST'");
     stmt.setBytes(1, data);
     stmt.setString(2, fileUuid);
     stmt.executeUpdate();
     stmt.close();
+    connection.commit();
   }
 
   /**
index ae1809eefe98d4985a350267c3c6ff0e4003e164..c9fc0f497dcf43d723035be5ccec044f8366a2fa 100644 (file)
 package org.sonar.server.test.index;
 
 import com.google.common.collect.Iterators;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
 import org.apache.commons.io.FileUtils;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
@@ -31,6 +36,7 @@ import org.junit.ClassRule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.sonar.api.config.Settings;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.es.EsTester;
@@ -41,13 +47,6 @@ import org.sonar.server.test.db.TestTesting;
 import org.sonar.test.DbTests;
 import org.sonar.test.TestUtils;
 
-import java.io.IOException;
-import java.sql.Connection;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.entry;
 import static org.sonar.server.test.index.TestIndexDefinition.FIELD_DURATION_IN_MS;
@@ -68,7 +67,7 @@ public class TestIndexerTest {
   public static EsTester es = new EsTester().addDefinitions(new TestIndexDefinition(new Settings()));
 
   @ClassRule
-  public static DbTester db = new DbTester();
+  public static DbTester db = DbTester.create(System2.INSTANCE);
 
   private TestIndexer sut;
 
@@ -83,9 +82,7 @@ public class TestIndexerTest {
   @Test
   public void index_tests() throws Exception {
     db.prepareDbUnit(getClass(), "db.xml");
-    Connection connection = db.openConnection();
-    TestTesting.updateDataColumn(connection, "FILE_UUID", TestTesting.newRandomTests(3));
-    connection.close();
+    TestTesting.updateDataColumn(db.getSession(), "FILE_UUID", TestTesting.newRandomTests(3));
 
     sut.index();
 
@@ -96,9 +93,7 @@ public class TestIndexerTest {
   public void index_tests_from_project() throws Exception {
     db.prepareDbUnit(getClass(), "db.xml");
 
-    Connection connection = db.openConnection();
-    TestTesting.updateDataColumn(connection, "FILE_UUID", TestTesting.newRandomTests(3));
-    connection.close();
+    TestTesting.updateDataColumn(db.getSession(), "FILE_UUID", TestTesting.newRandomTests(3));
 
     sut.index("PROJECT_UUID");
     assertThat(countDocuments()).isEqualTo(3);
@@ -108,9 +103,7 @@ public class TestIndexerTest {
   public void index_nothing_from_unknown_project() throws Exception {
     db.prepareDbUnit(getClass(), "db.xml");
 
-    Connection connection = db.openConnection();
-    TestTesting.updateDataColumn(connection, "FILE_UUID", TestTesting.newRandomTests(3));
-    connection.close();
+    TestTesting.updateDataColumn(db.getSession(), "FILE_UUID", TestTesting.newRandomTests(3));
 
     sut.index("UNKNOWN");
     assertThat(countDocuments()).isZero();
index b144a1076202d76c9725fa39d1ff8973fee4a9b8..e18a89a85c1ffb39bd2b3b5aa301f5bc8581fb95 100644 (file)
 
 package org.sonar.server.test.index;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
 import org.assertj.core.data.MapEntry;
 import org.elasticsearch.action.update.UpdateRequest;
 import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
-import org.sonar.server.db.DbClient;
 import org.sonar.server.source.db.FileSourceDb;
 import org.sonar.server.source.db.FileSourceDb.Test.TestStatus;
 import org.sonar.server.source.index.FileSourcesUpdaterHelper;
-import org.sonar.server.source.index.SourceLineResultSetIteratorTest;
 import org.sonar.server.test.db.TestTesting;
 import org.sonar.test.DbTests;
 
-import java.sql.Connection;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.fail;
 
@@ -50,33 +45,22 @@ import static org.assertj.core.api.Assertions.fail;
 public class TestResultSetIteratorTest {
 
   @ClassRule
-  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, SourceLineResultSetIteratorTest.class, "schema.sql");
-
-  DbClient dbClient;
-
-  Connection connection;
+  public static DbTester dbTester = DbTester.create(System2.INSTANCE);
 
   TestResultSetIterator sut;
 
-  @Before
-  public void setUp() throws Exception {
-    dbClient = new DbClient(db.database(), db.myBatis());
-    connection = db.openConnection();
-  }
-
   @After
   public void after() throws Exception {
     if (sut != null) {
       sut.close();
     }
-    connection.close();
   }
 
   @Test
   public void traverse_db() throws Exception {
-    db.prepareDbUnit(getClass(), "shared.xml");
-    TestTesting.updateDataColumn(connection, "F1", newFakeTests(3));
-    sut = TestResultSetIterator.create(dbClient, connection, 0L, null);
+    dbTester.prepareDbUnit(getClass(), "shared.xml");
+    TestTesting.updateDataColumn(dbTester.getSession(), "F1", newFakeTests(3));
+    sut = TestResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L, null);
 
     FileSourcesUpdaterHelper.Row row = sut.next();
     assertThat(row.getProjectUuid()).isEqualTo("P1");
@@ -103,15 +87,15 @@ public class TestResultSetIteratorTest {
    */
   @Test
   public void minimal_data() throws Exception {
-    db.prepareDbUnit(getClass(), "shared.xml");
+    dbTester.prepareDbUnit(getClass(), "shared.xml");
     List<FileSourceDb.Test> tests = Arrays.asList(
       FileSourceDb.Test.newBuilder()
         .setUuid("U1")
         .setName("N1")
         .build()
       );
-    TestTesting.updateDataColumn(connection, "F1", tests);
-    sut = TestResultSetIterator.create(dbClient, connection, 0L, null);
+    TestTesting.updateDataColumn(dbTester.getSession(), "F1", tests);
+    sut = TestResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L, null);
 
     FileSourcesUpdaterHelper.Row row = sut.next();
 
@@ -139,18 +123,18 @@ public class TestResultSetIteratorTest {
 
   @Test
   public void filter_by_date() {
-    db.prepareDbUnit(getClass(), "shared.xml");
-    sut = TestResultSetIterator.create(dbClient, connection, 2000000000000L, null);
+    dbTester.prepareDbUnit(getClass(), "shared.xml");
+    sut = TestResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 2000000000000L, null);
 
     assertThat(sut.hasNext()).isFalse();
   }
 
   @Test
   public void filter_by_project() throws Exception {
-    db.prepareDbUnit(getClass(), "filter_by_project.xml");
-    TestTesting.updateDataColumn(connection, "F1", newFakeTests(1));
+    dbTester.prepareDbUnit(getClass(), "filter_by_project.xml");
+    TestTesting.updateDataColumn(dbTester.getSession(), "F1", newFakeTests(1));
 
-    sut = TestResultSetIterator.create(dbClient, connection, 0L, "P1");
+    sut = TestResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L, "P1");
 
     FileSourcesUpdaterHelper.Row row = sut.next();
     assertThat(row.getProjectUuid()).isEqualTo("P1");
@@ -162,10 +146,10 @@ public class TestResultSetIteratorTest {
 
   @Test
   public void filter_by_project_and_date() throws Exception {
-    db.prepareDbUnit(getClass(), "filter_by_project_and_date.xml");
-    TestTesting.updateDataColumn(connection, "F1", newFakeTests(1));
+    dbTester.prepareDbUnit(getClass(), "filter_by_project_and_date.xml");
+    TestTesting.updateDataColumn(dbTester.getSession(), "F1", newFakeTests(1));
 
-    sut = TestResultSetIterator.create(dbClient, connection, 1400000000000L, "P1");
+    sut = TestResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 1400000000000L, "P1");
 
     FileSourcesUpdaterHelper.Row row = sut.next();
     assertThat(row.getProjectUuid()).isEqualTo("P1");
@@ -177,11 +161,11 @@ public class TestResultSetIteratorTest {
 
   @Test
   public void fail_on_bad_data_format() throws Exception {
-    db.prepareDbUnit(getClass(), "shared.xml");
+    dbTester.prepareDbUnit(getClass(), "shared.xml");
 
-    TestTesting.updateDataColumn(connection, "F1", "THIS_IS_NOT_PROTOBUF".getBytes());
+    TestTesting.updateDataColumn(dbTester.getSession(), "F1", "THIS_IS_NOT_PROTOBUF".getBytes());
 
-    sut = TestResultSetIterator.create(dbClient, connection, 0L, null);
+    sut = TestResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L, null);
     try {
       assertThat(sut.hasNext()).isTrue();
       sut.next();
index ec9285357f415279c5765cf83df371693e12bca2..8d56bf29ca14bcdde638d463ef038906f664de91 100644 (file)
@@ -21,46 +21,32 @@ package org.sonar.server.user.index;
 
 import com.google.common.base.Function;
 import com.google.common.collect.Maps;
-import org.apache.commons.dbutils.DbUtils;
-import org.junit.After;
+import java.util.Map;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
-import org.sonar.server.db.DbClient;
 import org.sonar.test.DbTests;
 
-import java.sql.Connection;
-import java.util.Map;
-
 import static org.assertj.core.api.Assertions.assertThat;
 
 @Category(DbTests.class)
 public class UserResultSetIteratorTest {
 
   @ClassRule
-  public static DbTester dbTester = new DbTester();
-
-  DbClient client;
-  Connection connection;
+  public static DbTester dbTester = DbTester.create(System2.INSTANCE);
 
   @Before
   public void setUp() throws Exception {
     dbTester.truncateTables();
-    client = new DbClient(dbTester.database(), dbTester.myBatis());
-    connection = dbTester.openConnection();
-  }
-
-  @After
-  public void tearDown() {
-    DbUtils.closeQuietly(connection);
   }
 
   @Test
   public void iterator_over_users() {
     dbTester.prepareDbUnit(getClass(), "shared.xml");
-    UserResultSetIterator it = UserResultSetIterator.create(client, connection, 0L);
+    UserResultSetIterator it = UserResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L);
     Map<String, UserDoc> usersByLogin = Maps.uniqueIndex(it, new Function<UserDoc, String>() {
       @Override
       public String apply(UserDoc user) {
@@ -99,7 +85,7 @@ public class UserResultSetIteratorTest {
   @Test
   public void select_after_date() {
     dbTester.prepareDbUnit(getClass(), "shared.xml");
-    UserResultSetIterator it = UserResultSetIterator.create(client, connection, 1520000000000L);
+    UserResultSetIterator it = UserResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 1520000000000L);
 
     assertThat(it.hasNext()).isTrue();
     UserDoc user = it.next();
index 7e3773f2b0d6a9502871032df4709cdddbee4fa1..4269182f2a746cb3f7f5931ebbb9a72a5f62b50e 100644 (file)
@@ -24,7 +24,7 @@ import java.util.List;
 import org.sonar.db.activity.ActivityDao;
 import org.sonar.db.component.ComponentLinkDao;
 import org.sonar.db.component.ResourceDao;
-import org.sonar.db.component.ResourceIndexerDao;
+import org.sonar.db.component.ResourceIndexDao;
 import org.sonar.db.component.ResourceKeyUpdaterDao;
 import org.sonar.db.component.SnapshotDao;
 import org.sonar.db.compute.AnalysisReportDao;
@@ -97,7 +97,7 @@ public final class DaoUtils {
       QualityProfileDao.class,
       PurgeDao.class,
       CharacteristicDao.class,
-      ResourceIndexerDao.class,
+      ResourceIndexDao.class,
       ResourceDao.class,
       ResourceKeyUpdaterDao.class,
       RoleDao.class,
diff --git a/sonar-db/src/main/java/org/sonar/db/DbClient.java b/sonar-db/src/main/java/org/sonar/db/DbClient.java
new file mode 100644 (file)
index 0000000..aad304f
--- /dev/null
@@ -0,0 +1,270 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.db;
+
+import java.util.IdentityHashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.sonar.db.activity.ActivityDao;
+import org.sonar.db.component.ComponentLinkDao;
+import org.sonar.db.component.ResourceDao;
+import org.sonar.db.component.ResourceIndexDao;
+import org.sonar.db.component.SnapshotDao;
+import org.sonar.db.compute.AnalysisReportDao;
+import org.sonar.db.dashboard.DashboardDao;
+import org.sonar.db.dashboard.WidgetDao;
+import org.sonar.db.dashboard.WidgetPropertyDao;
+import org.sonar.db.debt.CharacteristicDao;
+import org.sonar.db.event.EventDao;
+import org.sonar.db.issue.ActionPlanDao;
+import org.sonar.db.issue.ActionPlanStatsDao;
+import org.sonar.db.issue.IssueChangeDao;
+import org.sonar.db.issue.IssueDao;
+import org.sonar.db.issue.IssueFilterDao;
+import org.sonar.db.loadedtemplate.LoadedTemplateDao;
+import org.sonar.db.measure.MeasureDao;
+import org.sonar.db.permission.PermissionTemplateDao;
+import org.sonar.db.property.PropertiesDao;
+import org.sonar.db.purge.PurgeDao;
+import org.sonar.db.qualitygate.QualityGateConditionDao;
+import org.sonar.db.qualityprofile.QualityProfileDao;
+import org.sonar.db.source.FileSourceDao;
+import org.sonar.db.user.AuthorDao;
+import org.sonar.db.user.AuthorizationDao;
+import org.sonar.db.user.GroupMembershipDao;
+import org.sonar.db.user.RoleDao;
+import org.sonar.db.user.UserGroupDao;
+
+public class DbClient {
+
+  private final Database database;
+  private final MyBatis myBatis;
+  private final QualityProfileDao qualityProfileDao;
+  private final CharacteristicDao debtCharacteristicDao;
+  private final LoadedTemplateDao loadedTemplateDao;
+  private final PropertiesDao propertiesDao;
+  private final SnapshotDao snapshotDao;
+  private final ResourceDao resourceDao;
+  private final MeasureDao measureDao;
+  private final ActivityDao activityDao;
+  private final AuthorizationDao authorizationDao;
+  private final UserGroupDao userGroupDao;
+  private final GroupMembershipDao groupMembershipDao;
+  private final RoleDao roleDao;
+  private final PermissionTemplateDao permissionTemplateDao;
+  private final IssueDao issueDao;
+  private final IssueFilterDao issueFilterDao;
+  private final IssueChangeDao issueChangeDao;
+  private final ActionPlanDao actionPlanDao;
+  private final ActionPlanStatsDao actionPlanStatsDao;
+  private final AnalysisReportDao analysisReportDao;
+  private final DashboardDao dashboardDao;
+  private final WidgetDao widgetDao;
+  private final WidgetPropertyDao widgetPropertyDao;
+  private final FileSourceDao fileSourceDao;
+  private final AuthorDao authorDao;
+  private final ResourceIndexDao componentIndexDao;
+  private final ComponentLinkDao componentLinkDao;
+  private final EventDao eventDao;
+  private final PurgeDao purgeDao;
+  private final QualityGateConditionDao gateConditionDao;
+
+  public DbClient(Database database, MyBatis myBatis, Dao[] daos) {
+    this.database = database;
+    this.myBatis = myBatis;
+
+    Map<Class, Dao> map = new IdentityHashMap<>();
+    for (Dao dao : daos) {
+      map.put(dao.getClass(), dao);
+    }
+    debtCharacteristicDao = getDao(map, CharacteristicDao.class);
+    qualityProfileDao = getDao(map, QualityProfileDao.class);
+    loadedTemplateDao = getDao(map, LoadedTemplateDao.class);
+    propertiesDao = getDao(map, PropertiesDao.class);
+    snapshotDao = getDao(map, SnapshotDao.class);
+    resourceDao = getDao(map, ResourceDao.class);
+    measureDao = getDao(map, MeasureDao.class);
+    activityDao = getDao(map, ActivityDao.class);
+    authorizationDao = getDao(map, AuthorizationDao.class);
+    userGroupDao = getDao(map, UserGroupDao.class);
+    groupMembershipDao = getDao(map, GroupMembershipDao.class);
+    roleDao = getDao(map, RoleDao.class);
+    permissionTemplateDao = getDao(map, PermissionTemplateDao.class);
+    issueDao = getDao(map, IssueDao.class);
+    issueFilterDao = getDao(map, IssueFilterDao.class);
+    issueChangeDao = getDao(map, IssueChangeDao.class);
+    actionPlanDao = getDao(map, ActionPlanDao.class);
+    actionPlanStatsDao = getDao(map, ActionPlanStatsDao.class);
+    analysisReportDao = getDao(map, AnalysisReportDao.class);
+    dashboardDao = getDao(map, DashboardDao.class);
+    widgetDao = getDao(map, WidgetDao.class);
+    widgetPropertyDao = getDao(map, WidgetPropertyDao.class);
+    fileSourceDao = getDao(map, FileSourceDao.class);
+    authorDao = getDao(map, AuthorDao.class);
+    componentIndexDao = getDao(map, ResourceIndexDao.class);
+    componentLinkDao = getDao(map, ComponentLinkDao.class);
+    eventDao = getDao(map, EventDao.class);
+    purgeDao = getDao(map, PurgeDao.class);
+    gateConditionDao = getDao(map, QualityGateConditionDao.class);
+    doOnLoad(map);
+  }
+
+  // should be removed, but till used by sonar-server
+  protected void doOnLoad(Map<Class, Dao> daoByClass) {
+
+  }
+
+  public DbSession openSession(boolean batch) {
+    return myBatis.openSession(batch);
+  }
+
+  public void closeSession(@Nullable DbSession session) {
+    MyBatis.closeQuietly(session);
+  }
+
+  public Database getDatabase() {
+    return database;
+  }
+
+  public IssueDao issueDao() {
+    return issueDao;
+  }
+
+  public IssueFilterDao issueFilterDao() {
+    return issueFilterDao;
+  }
+
+  public IssueChangeDao issueChangeDao() {
+    return issueChangeDao;
+  }
+
+  public QualityProfileDao qualityProfileDao() {
+    return qualityProfileDao;
+  }
+
+  public CharacteristicDao debtCharacteristicDao() {
+    return debtCharacteristicDao;
+  }
+
+  public LoadedTemplateDao loadedTemplateDao() {
+    return loadedTemplateDao;
+  }
+
+  public PropertiesDao propertiesDao() {
+    return propertiesDao;
+  }
+
+  public SnapshotDao snapshotDao() {
+    return snapshotDao;
+  }
+
+  public ResourceDao resourceDao() {
+    return resourceDao;
+  }
+
+  public MeasureDao measureDao() {
+    return measureDao;
+  }
+
+  public ActivityDao activityDao() {
+    return activityDao;
+  }
+
+  public AuthorizationDao authorizationDao() {
+    return authorizationDao;
+  }
+
+  public UserGroupDao userGroupDao() {
+    return userGroupDao;
+  }
+
+  public GroupMembershipDao groupMembershipDao() {
+    return groupMembershipDao;
+  }
+
+  public RoleDao roleDao() {
+    return roleDao;
+  }
+
+  public PermissionTemplateDao permissionTemplateDao() {
+    return permissionTemplateDao;
+  }
+
+  public ActionPlanDao actionPlanDao() {
+    return actionPlanDao;
+  }
+
+  public AnalysisReportDao analysisReportDao() {
+    return analysisReportDao;
+  }
+
+  public DashboardDao dashboardDao() {
+    return dashboardDao;
+  }
+
+  public WidgetDao widgetDao() {
+    return widgetDao;
+  }
+
+  public WidgetPropertyDao widgetPropertyDao() {
+    return widgetPropertyDao;
+  }
+
+  public FileSourceDao fileSourceDao() {
+    return fileSourceDao;
+  }
+
+  public AuthorDao authorDao() {
+    return authorDao;
+  }
+
+  public ResourceIndexDao componentIndexDao() {
+    return componentIndexDao;
+  }
+
+  public ComponentLinkDao componentLinkDao() {
+    return componentLinkDao;
+  }
+
+  public EventDao eventDao() {
+    return eventDao;
+  }
+
+  public PurgeDao purgeDao() {
+    return purgeDao;
+  }
+
+  public ActionPlanStatsDao getActionPlanStatsDao() {
+    return actionPlanStatsDao;
+  }
+
+  public QualityGateConditionDao gateConditionDao() {
+    return gateConditionDao;
+  }
+
+  protected <K extends Dao> K getDao(Map<Class, Dao> map, Class<K> clazz) {
+    return (K) map.get(clazz);
+  }
+
+  // should be removed. Still used by some old DAO in sonar-server
+  public MyBatis getMyBatis() {
+    return myBatis;
+  }
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/DbClient2.java b/sonar-db/src/main/java/org/sonar/db/DbClient2.java
deleted file mode 100644 (file)
index 92cbd39..0000000
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.db;
-
-import java.util.IdentityHashMap;
-import java.util.Map;
-import javax.annotation.Nullable;
-import org.sonar.db.activity.ActivityDao;
-import org.sonar.db.component.ComponentLinkDao;
-import org.sonar.db.component.ResourceDao;
-import org.sonar.db.component.ResourceIndexerDao;
-import org.sonar.db.component.SnapshotDao;
-import org.sonar.db.compute.AnalysisReportDao;
-import org.sonar.db.dashboard.DashboardDao;
-import org.sonar.db.dashboard.WidgetDao;
-import org.sonar.db.dashboard.WidgetPropertyDao;
-import org.sonar.db.debt.CharacteristicDao;
-import org.sonar.db.event.EventDao;
-import org.sonar.db.issue.ActionPlanDao;
-import org.sonar.db.issue.ActionPlanStatsDao;
-import org.sonar.db.issue.IssueChangeDao;
-import org.sonar.db.issue.IssueDao;
-import org.sonar.db.issue.IssueFilterDao;
-import org.sonar.db.loadedtemplate.LoadedTemplateDao;
-import org.sonar.db.measure.MeasureDao;
-import org.sonar.db.permission.PermissionTemplateDao;
-import org.sonar.db.property.PropertiesDao;
-import org.sonar.db.purge.PurgeDao;
-import org.sonar.db.qualitygate.QualityGateConditionDao;
-import org.sonar.db.qualityprofile.QualityProfileDao;
-import org.sonar.db.source.FileSourceDao;
-import org.sonar.db.user.AuthorDao;
-import org.sonar.db.user.AuthorizationDao;
-import org.sonar.db.user.GroupMembershipDao;
-import org.sonar.db.user.RoleDao;
-import org.sonar.db.user.UserGroupDao;
-
-public class DbClient2 {
-
-  private final MyBatis myBatis;
-  private final QualityProfileDao qualityProfileDao;
-  private final CharacteristicDao debtCharacteristicDao;
-  private final LoadedTemplateDao loadedTemplateDao;
-  private final PropertiesDao propertiesDao;
-  private final SnapshotDao snapshotDao;
-  private final ResourceDao resourceDao;
-  private final MeasureDao measureDao;
-  private final ActivityDao activityDao;
-  private final AuthorizationDao authorizationDao;
-  private final UserGroupDao userGroupDao;
-  private final GroupMembershipDao groupMembershipDao;
-  private final RoleDao roleDao;
-  private final PermissionTemplateDao permissionTemplateDao;
-  private final IssueDao issueDao;
-  private final IssueFilterDao issueFilterDao;
-  private final IssueChangeDao issueChangeDao;
-  private final ActionPlanDao actionPlanDao;
-  private final ActionPlanStatsDao actionPlanStatsDao;
-  private final AnalysisReportDao analysisReportDao;
-  private final DashboardDao dashboardDao;
-  private final WidgetDao widgetDao;
-  private final WidgetPropertyDao widgetPropertyDao;
-  private final FileSourceDao fileSourceDao;
-  private final AuthorDao authorDao;
-  private final ResourceIndexerDao componentIndexDao;
-  private final ComponentLinkDao componentLinkDao;
-  private final EventDao eventDao;
-  private final PurgeDao purgeDao;
-  private final QualityGateConditionDao gateConditionDao;
-
-  public DbClient2(MyBatis myBatis, Dao[] daos) {
-    this.myBatis = myBatis;
-
-    Map<Class, Dao> map = new IdentityHashMap<>();
-    for (Dao dao : daos) {
-      map.put(dao.getClass(), dao);
-    }
-    debtCharacteristicDao = getDao(map, CharacteristicDao.class);
-    qualityProfileDao = getDao(map, QualityProfileDao.class);
-    loadedTemplateDao = getDao(map, LoadedTemplateDao.class);
-    propertiesDao = getDao(map, PropertiesDao.class);
-    snapshotDao = getDao(map, SnapshotDao.class);
-    resourceDao = getDao(map, ResourceDao.class);
-    measureDao = getDao(map, MeasureDao.class);
-    activityDao = getDao(map, ActivityDao.class);
-    authorizationDao = getDao(map, AuthorizationDao.class);
-    userGroupDao = getDao(map, UserGroupDao.class);
-    groupMembershipDao = getDao(map, GroupMembershipDao.class);
-    roleDao = getDao(map, RoleDao.class);
-    permissionTemplateDao = getDao(map, PermissionTemplateDao.class);
-    issueDao = getDao(map, IssueDao.class);
-    issueFilterDao = getDao(map, IssueFilterDao.class);
-    issueChangeDao = getDao(map, IssueChangeDao.class);
-    actionPlanDao = getDao(map, ActionPlanDao.class);
-    actionPlanStatsDao = getDao(map, ActionPlanStatsDao.class);
-    analysisReportDao = getDao(map, AnalysisReportDao.class);
-    dashboardDao = getDao(map, DashboardDao.class);
-    widgetDao = getDao(map, WidgetDao.class);
-    widgetPropertyDao = getDao(map, WidgetPropertyDao.class);
-    fileSourceDao = getDao(map, FileSourceDao.class);
-    authorDao = getDao(map, AuthorDao.class);
-    componentIndexDao = getDao(map, ResourceIndexerDao.class);
-    componentLinkDao = getDao(map, ComponentLinkDao.class);
-    eventDao = getDao(map, EventDao.class);
-    purgeDao = getDao(map, PurgeDao.class);
-    gateConditionDao = getDao(map, QualityGateConditionDao.class);
-  }
-
-  public DbSession openSession(boolean batch) {
-    return myBatis.openSession(batch);
-  }
-
-  public void closeSession(@Nullable DbSession session) {
-    MyBatis.closeQuietly(session);
-  }
-
-  public IssueDao issueDao() {
-    return issueDao;
-  }
-
-  public IssueFilterDao issueFilterDao() {
-    return issueFilterDao;
-  }
-
-  public IssueChangeDao issueChangeDao() {
-    return issueChangeDao;
-  }
-
-  public QualityProfileDao qualityProfileDao() {
-    return qualityProfileDao;
-  }
-
-  public CharacteristicDao debtCharacteristicDao() {
-    return debtCharacteristicDao;
-  }
-
-  public LoadedTemplateDao loadedTemplateDao() {
-    return loadedTemplateDao;
-  }
-
-  public PropertiesDao propertiesDao() {
-    return propertiesDao;
-  }
-
-  public SnapshotDao snapshotDao() {
-    return snapshotDao;
-  }
-
-  public ResourceDao resourceDao() {
-    return resourceDao;
-  }
-
-  public MeasureDao measureDao() {
-    return measureDao;
-  }
-
-  public ActivityDao activityDao() {
-    return activityDao;
-  }
-
-  public AuthorizationDao authorizationDao() {
-    return authorizationDao;
-  }
-
-  public UserGroupDao userGroupDao() {
-    return userGroupDao;
-  }
-
-  public GroupMembershipDao groupMembershipDao() {
-    return groupMembershipDao;
-  }
-
-  public RoleDao roleDao() {
-    return roleDao;
-  }
-
-  public PermissionTemplateDao permissionTemplateDao() {
-    return permissionTemplateDao;
-  }
-
-  public ActionPlanDao actionPlanDao() {
-    return actionPlanDao;
-  }
-
-  public AnalysisReportDao analysisReportDao() {
-    return analysisReportDao;
-  }
-
-  public DashboardDao dashboardDao() {
-    return dashboardDao;
-  }
-
-  public WidgetDao widgetDao() {
-    return widgetDao;
-  }
-
-  public WidgetPropertyDao widgetPropertyDao() {
-    return widgetPropertyDao;
-  }
-
-  public FileSourceDao fileSourceDao() {
-    return fileSourceDao;
-  }
-
-  public AuthorDao authorDao() {
-    return authorDao;
-  }
-
-  public ResourceIndexerDao componentIndexDao() {
-    return componentIndexDao;
-  }
-
-  public ComponentLinkDao componentLinkDao() {
-    return componentLinkDao;
-  }
-
-  public EventDao eventDao() {
-    return eventDao;
-  }
-
-  public PurgeDao purgeDao() {
-    return purgeDao;
-  }
-
-  public ActionPlanStatsDao getActionPlanStatsDao() {
-    return actionPlanStatsDao;
-  }
-
-  public QualityGateConditionDao gateConditionDao() {
-    return gateConditionDao;
-  }
-
-  private <K extends Dao> K getDao(Map<Class, Dao> map, Class<K> clazz) {
-    return (K) map.get(clazz);
-  }
-}
index 5926def8753d67003faa705ccdde8eb81e856bb4..e4e3bce008bd2b4186991b9eaf811a69863b2925 100644 (file)
@@ -48,7 +48,7 @@ import org.sonar.db.component.ComponentMapper;
 import org.sonar.db.component.FilePathWithHashDto;
 import org.sonar.db.component.ResourceDto;
 import org.sonar.db.component.ResourceIndexDto;
-import org.sonar.db.component.ResourceIndexerMapper;
+import org.sonar.db.component.ResourceIndexMapper;
 import org.sonar.db.component.ResourceKeyUpdaterMapper;
 import org.sonar.db.component.ResourceMapper;
 import org.sonar.db.component.SnapshotDto;
@@ -249,7 +249,7 @@ public class MyBatis {
       IssueMapper.class, IssueChangeMapper.class, IssueFilterMapper.class, IssueFilterFavouriteMapper.class,
       IsAliveMapper.class,
       LoadedTemplateMapper.class, MeasureFilterMapper.class, Migration44Mapper.class, PermissionTemplateMapper.class, PropertiesMapper.class, PurgeMapper.class,
-      ResourceKeyUpdaterMapper.class, ResourceIndexerMapper.class, RoleMapper.class, RuleMapper.class,
+      ResourceKeyUpdaterMapper.class, ResourceIndexMapper.class, RoleMapper.class, RuleMapper.class,
       SchemaMigrationMapper.class, SemaphoreMapper.class, UserMapper.class, GroupMapper.class, UserGroupMapper.class, WidgetMapper.class, WidgetPropertyMapper.class,
       FileSourceMapper.class, ActionPlanMapper.class,
       ActionPlanStatsMapper.class,
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
new file mode 100644 (file)
index 0000000..b146a51
--- /dev/null
@@ -0,0 +1,221 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.db.component;
+
+import java.util.List;
+import org.apache.commons.lang.StringUtils;
+import org.apache.ibatis.session.ResultContext;
+import org.apache.ibatis.session.ResultHandler;
+import org.apache.ibatis.session.SqlSession;
+import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.resources.Scopes;
+import org.sonar.api.utils.System2;
+import org.sonar.db.AbstractDao;
+import org.sonar.db.DbSession;
+import org.sonar.db.MyBatis;
+
+public class ResourceIndexDao extends AbstractDao {
+
+  private static final String SELECT_RESOURCES = "org.sonar.db.component.ResourceIndexMapper.selectResources";
+  public static final int MINIMUM_KEY_SIZE = 3;
+  public static final int SINGLE_INDEX_SIZE = 2;
+
+  // The scopes and qualifiers that are not in the following constants are not indexed at all.
+  // Directories and packages are explicitly excluded.
+  private static final String[] RENAMABLE_QUALIFIERS = {Qualifiers.PROJECT, Qualifiers.MODULE, Qualifiers.VIEW, Qualifiers.SUBVIEW};
+  private static final String[] RENAMABLE_SCOPES = {Scopes.PROJECT};
+  private static final String[] NOT_RENAMABLE_QUALIFIERS = {Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE, Qualifiers.CLASS};
+  private static final String[] NOT_RENAMABLE_SCOPES = {Scopes.FILE};
+
+  public ResourceIndexDao(MyBatis myBatis, System2 system2) {
+    super(myBatis, system2);
+  }
+
+  public List<Long> selectProjectIdsFromQueryAndViewOrSubViewUuid(DbSession session, String query, String viewOrSubViewUuid) {
+    return session.getMapper(ResourceIndexMapper.class).selectProjectIdsFromQueryAndViewOrSubViewUuid(query + "%", "%." + viewOrSubViewUuid + ".%");
+  }
+
+  /**
+   * This method is reentrant. It can be executed even if the project is already indexed.
+   */
+  public ResourceIndexDao indexProject(final long rootProjectId) {
+    DbSession session = myBatis().openSession(true);
+    try {
+      indexProject(rootProjectId, session);
+      session.commit();
+      return this;
+
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public void indexProject(final long rootProjectId, DbSession session) {
+    ResourceIndexMapper mapper = session.getMapper(ResourceIndexMapper.class);
+    doIndexProject(rootProjectId, session, 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) {
+    // non indexed resources
+    ResourceIndexQuery query = ResourceIndexQuery.create()
+      .setNonIndexedOnly(true)
+      .setQualifiers(NOT_RENAMABLE_QUALIFIERS)
+      .setScopes(NOT_RENAMABLE_SCOPES)
+      .setRootProjectId(rootProjectId);
+
+    session.select(SELECT_RESOURCES, query, new ResultHandler() {
+      @Override
+      public void handleResult(ResultContext context) {
+        ResourceDto resource = (ResourceDto) context.getResultObject();
+        doIndex(resource, mapper);
+      }
+    });
+
+    // some resources can be renamed, so index must be regenerated
+    // -> delete existing rows and create them again
+    query = ResourceIndexQuery.create()
+      .setNonIndexedOnly(false)
+      .setQualifiers(RENAMABLE_QUALIFIERS)
+      .setScopes(RENAMABLE_SCOPES)
+      .setRootProjectId(rootProjectId);
+
+    session.select(SELECT_RESOURCES, query, new ResultHandler() {
+      @Override
+      public void handleResult(ResultContext context) {
+        ResourceDto resource = (ResourceDto) context.getResultObject();
+
+        mapper.deleteByResourceId(resource.getId());
+        doIndex(resource, mapper);
+      }
+    });
+  }
+
+  void doIndex(ResourceDto resource, ResourceIndexMapper mapper) {
+    String key = nameToKey(resource.getName());
+    if (key.length() >= MINIMUM_KEY_SIZE || key.length() == SINGLE_INDEX_SIZE) {
+      insertIndexEntries(key, resource.getId(), resource.getQualifier(), resource.getRootId(), resource.getName().length(), mapper);
+    }
+  }
+
+  public boolean indexResource(long id) {
+    DbSession session = myBatis().openSession(false);
+    try {
+      return indexResource(session, id);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public boolean indexResource(DbSession session, long id) {
+    boolean indexed = false;
+    ResourceIndexMapper mapper = session.getMapper(ResourceIndexMapper.class);
+    ResourceDto resource = mapper.selectResourceToIndex(id);
+    if (resource != null) {
+      Long rootId = resource.getRootId();
+      if (rootId == null) {
+        rootId = resource.getId();
+      }
+      indexed = indexResource(resource.getId(), resource.getName(), resource.getQualifier(), rootId, session, mapper);
+    }
+    return indexed;
+  }
+
+  public boolean indexResource(int id, String name, String qualifier, int rootId) {
+    boolean indexed = false;
+    SqlSession session = myBatis().openSession(false);
+    ResourceIndexMapper mapper = session.getMapper(ResourceIndexMapper.class);
+    try {
+      indexed = indexResource(id, name, qualifier, rootId, session, mapper);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+    return indexed;
+  }
+
+  private boolean indexResource(long id, String name, String qualifier, long rootId, SqlSession session, ResourceIndexMapper mapper) {
+    boolean indexed = false;
+    String key = nameToKey(name);
+    if (key.length() >= MINIMUM_KEY_SIZE || key.length() == SINGLE_INDEX_SIZE) {
+      indexed = true;
+      boolean toBeIndexed = sanitizeIndex(id, key, mapper);
+      if (toBeIndexed) {
+        insertIndexEntries(key, id, qualifier, rootId, name.length(), mapper);
+        session.commit();
+      }
+    }
+    return indexed;
+  }
+
+  private void insertIndexEntries(String key, long resourceId, String qualifier, long rootId, int nameLength, ResourceIndexMapper mapper) {
+    ResourceIndexDto dto = new ResourceIndexDto()
+      .setResourceId(resourceId)
+      .setQualifier(qualifier)
+      .setRootProjectId(rootId)
+      .setNameSize(nameLength);
+
+    int maxPosition = key.length() == SINGLE_INDEX_SIZE ? 0 : key.length() - MINIMUM_KEY_SIZE;
+    for (int position = 0; position <= maxPosition; position++) {
+      dto.setPosition(position);
+      dto.setKey(StringUtils.substring(key, position));
+      mapper.insert(dto);
+    }
+  }
+
+  /**
+   * Return true if the resource must be indexed, false if the resource is already indexed.
+   * If the resource is indexed with a different key, then this index is dropped and the
+   * resource must be indexed again.
+   */
+  private boolean sanitizeIndex(long resourceId, String key, ResourceIndexMapper mapper) {
+    ResourceIndexDto masterIndex = mapper.selectMasterIndexByResourceId(resourceId);
+    if (masterIndex != null && !StringUtils.equals(key, masterIndex.getKey())) {
+      // resource has been renamed -> drop existing indexes
+      mapper.deleteByResourceId(resourceId);
+      masterIndex = null;
+    }
+    return masterIndex == null;
+  }
+
+  static String nameToKey(String input) {
+    return StringUtils.lowerCase(StringUtils.trimToEmpty(input));
+  }
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexMapper.java b/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexMapper.java
new file mode 100644 (file)
index 0000000..31efd21
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.db.component;
+
+import java.util.List;
+import org.apache.ibatis.annotations.Param;
+
+public interface ResourceIndexMapper {
+
+  List<Long> selectProjectIdsFromQueryAndViewOrSubViewUuid(@Param("query") String query, @Param("viewUuidQuery") String viewUuidQuery);
+
+  ResourceIndexDto selectMasterIndexByResourceId(long resourceId);
+
+  ResourceDto selectResourceToIndex(long resourceId);
+
+  void deleteByResourceId(long resourceId);
+
+  void insert(ResourceIndexDto dto);
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexQuery.java b/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexQuery.java
new file mode 100644 (file)
index 0000000..6d5e495
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.db.component;
+
+final class ResourceIndexQuery {
+  private long rootProjectId;
+  private String[] scopes = null;
+  private String[] qualifiers = null;
+  private boolean nonIndexedOnly = false;
+
+  private ResourceIndexQuery() {
+  }
+
+  public static ResourceIndexQuery create() {
+    return new ResourceIndexQuery();
+  }
+
+  public String[] getScopes() {
+    return scopes;
+  }
+
+  public String[] getQualifiers() {
+    return qualifiers;
+  }
+
+  public ResourceIndexQuery setScopes(String[] scopes) {
+    this.scopes = scopes;
+    return this;
+  }
+
+  public ResourceIndexQuery setQualifiers(String[] qualifiers) {
+    this.qualifiers = qualifiers;
+    return this;
+  }
+
+  public long getRootProjectId() {
+    return rootProjectId;
+  }
+
+  public ResourceIndexQuery setRootProjectId(long i) {
+    this.rootProjectId = i;
+    return this;
+  }
+
+  public boolean isNonIndexedOnly() {
+    return nonIndexedOnly;
+  }
+
+  public ResourceIndexQuery setNonIndexedOnly(boolean b) {
+    this.nonIndexedOnly = b;
+    return this;
+  }
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerDao.java b/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerDao.java
deleted file mode 100644 (file)
index 827ece8..0000000
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.db.component;
-
-import java.util.List;
-import org.apache.commons.lang.StringUtils;
-import org.apache.ibatis.session.ResultContext;
-import org.apache.ibatis.session.ResultHandler;
-import org.apache.ibatis.session.SqlSession;
-import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.resources.Scopes;
-import org.sonar.api.utils.System2;
-import org.sonar.db.AbstractDao;
-import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
-
-public class ResourceIndexerDao extends AbstractDao {
-
-  private static final String SELECT_RESOURCES = "org.sonar.db.component.ResourceIndexerMapper.selectResources";
-  public static final int MINIMUM_KEY_SIZE = 3;
-  public static final int SINGLE_INDEX_SIZE = 2;
-
-  // The scopes and qualifiers that are not in the following constants are not indexed at all.
-  // Directories and packages are explicitly excluded.
-  private static final String[] RENAMABLE_QUALIFIERS = {Qualifiers.PROJECT, Qualifiers.MODULE, Qualifiers.VIEW, Qualifiers.SUBVIEW};
-  private static final String[] RENAMABLE_SCOPES = {Scopes.PROJECT};
-  private static final String[] NOT_RENAMABLE_QUALIFIERS = {Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE, Qualifiers.CLASS};
-  private static final String[] NOT_RENAMABLE_SCOPES = {Scopes.FILE};
-
-  public ResourceIndexerDao(MyBatis myBatis, System2 system2) {
-    super(myBatis, system2);
-  }
-
-  public List<Long> selectProjectIdsFromQueryAndViewOrSubViewUuid(DbSession session, String query, String viewOrSubViewUuid) {
-    return session.getMapper(ResourceIndexerMapper.class).selectProjectIdsFromQueryAndViewOrSubViewUuid(query + "%", "%." + viewOrSubViewUuid + ".%");
-  }
-
-  /**
-   * This method is reentrant. It can be executed even if the project is already indexed.
-   */
-  public ResourceIndexerDao indexProject(final long rootProjectId) {
-    DbSession session = myBatis().openSession(true);
-    try {
-      indexProject(rootProjectId, session);
-      session.commit();
-      return this;
-
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public void indexProject(final long rootProjectId, DbSession session) {
-    ResourceIndexerMapper mapper = session.getMapper(ResourceIndexerMapper.class);
-    doIndexProject(rootProjectId, session, mapper);
-  }
-
-  /**
-   * This method is reentrant. It can be executed even if some projects are already indexed.
-   */
-  public ResourceIndexerDao indexProjects() {
-    final DbSession session = myBatis().openSession(true);
-    try {
-      final ResourceIndexerMapper mapper = session.getMapper(ResourceIndexerMapper.class);
-      session.select("org.sonar.db.component.ResourceIndexerMapper.selectRootProjectIds", /* workaround to get booleans */ResourceIndexerQuery.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 ResourceIndexerMapper mapper) {
-    // non indexed resources
-    ResourceIndexerQuery query = ResourceIndexerQuery.create()
-      .setNonIndexedOnly(true)
-      .setQualifiers(NOT_RENAMABLE_QUALIFIERS)
-      .setScopes(NOT_RENAMABLE_SCOPES)
-      .setRootProjectId(rootProjectId);
-
-    session.select(SELECT_RESOURCES, query, new ResultHandler() {
-      @Override
-      public void handleResult(ResultContext context) {
-        ResourceDto resource = (ResourceDto) context.getResultObject();
-        doIndex(resource, mapper);
-      }
-    });
-
-    // some resources can be renamed, so index must be regenerated
-    // -> delete existing rows and create them again
-    query = ResourceIndexerQuery.create()
-      .setNonIndexedOnly(false)
-      .setQualifiers(RENAMABLE_QUALIFIERS)
-      .setScopes(RENAMABLE_SCOPES)
-      .setRootProjectId(rootProjectId);
-
-    session.select(SELECT_RESOURCES, query, new ResultHandler() {
-      @Override
-      public void handleResult(ResultContext context) {
-        ResourceDto resource = (ResourceDto) context.getResultObject();
-
-        mapper.deleteByResourceId(resource.getId());
-        doIndex(resource, mapper);
-      }
-    });
-  }
-
-  void doIndex(ResourceDto resource, ResourceIndexerMapper mapper) {
-    String key = nameToKey(resource.getName());
-    if (key.length() >= MINIMUM_KEY_SIZE || key.length() == SINGLE_INDEX_SIZE) {
-      insertIndexEntries(key, resource.getId(), resource.getQualifier(), resource.getRootId(), resource.getName().length(), mapper);
-    }
-  }
-
-  public boolean indexResource(long id) {
-    DbSession session = myBatis().openSession(false);
-    try {
-      return indexResource(session, id);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public boolean indexResource(DbSession session, long id) {
-    boolean indexed = false;
-    ResourceIndexerMapper mapper = session.getMapper(ResourceIndexerMapper.class);
-    ResourceDto resource = mapper.selectResourceToIndex(id);
-    if (resource != null) {
-      Long rootId = resource.getRootId();
-      if (rootId == null) {
-        rootId = resource.getId();
-      }
-      indexed = indexResource(resource.getId(), resource.getName(), resource.getQualifier(), rootId, session, mapper);
-    }
-    return indexed;
-  }
-
-  public boolean indexResource(int id, String name, String qualifier, int rootId) {
-    boolean indexed = false;
-    SqlSession session = myBatis().openSession(false);
-    ResourceIndexerMapper mapper = session.getMapper(ResourceIndexerMapper.class);
-    try {
-      indexed = indexResource(id, name, qualifier, rootId, session, mapper);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-    return indexed;
-  }
-
-  private boolean indexResource(long id, String name, String qualifier, long rootId, SqlSession session, ResourceIndexerMapper mapper) {
-    boolean indexed = false;
-    String key = nameToKey(name);
-    if (key.length() >= MINIMUM_KEY_SIZE || key.length() == SINGLE_INDEX_SIZE) {
-      indexed = true;
-      boolean toBeIndexed = sanitizeIndex(id, key, mapper);
-      if (toBeIndexed) {
-        insertIndexEntries(key, id, qualifier, rootId, name.length(), mapper);
-        session.commit();
-      }
-    }
-    return indexed;
-  }
-
-  private void insertIndexEntries(String key, long resourceId, String qualifier, long rootId, int nameLength, ResourceIndexerMapper mapper) {
-    ResourceIndexDto dto = new ResourceIndexDto()
-      .setResourceId(resourceId)
-      .setQualifier(qualifier)
-      .setRootProjectId(rootId)
-      .setNameSize(nameLength);
-
-    int maxPosition = key.length() == SINGLE_INDEX_SIZE ? 0 : key.length() - MINIMUM_KEY_SIZE;
-    for (int position = 0; position <= maxPosition; position++) {
-      dto.setPosition(position);
-      dto.setKey(StringUtils.substring(key, position));
-      mapper.insert(dto);
-    }
-  }
-
-  /**
-   * Return true if the resource must be indexed, false if the resource is already indexed.
-   * If the resource is indexed with a different key, then this index is dropped and the
-   * resource must be indexed again.
-   */
-  private boolean sanitizeIndex(long resourceId, String key, ResourceIndexerMapper mapper) {
-    ResourceIndexDto masterIndex = mapper.selectMasterIndexByResourceId(resourceId);
-    if (masterIndex != null && !StringUtils.equals(key, masterIndex.getKey())) {
-      // resource has been renamed -> drop existing indexes
-      mapper.deleteByResourceId(resourceId);
-      masterIndex = null;
-    }
-    return masterIndex == null;
-  }
-
-  static String nameToKey(String input) {
-    return StringUtils.lowerCase(StringUtils.trimToEmpty(input));
-  }
-}
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerMapper.java b/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerMapper.java
deleted file mode 100644 (file)
index a0cb17b..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.db.component;
-
-import java.util.List;
-import org.apache.ibatis.annotations.Param;
-
-public interface ResourceIndexerMapper {
-
-  List<Long> selectProjectIdsFromQueryAndViewOrSubViewUuid(@Param("query") String query, @Param("viewUuidQuery") String viewUuidQuery);
-
-  ResourceIndexDto selectMasterIndexByResourceId(long resourceId);
-
-  ResourceDto selectResourceToIndex(long resourceId);
-
-  void deleteByResourceId(long resourceId);
-
-  void insert(ResourceIndexDto dto);
-}
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerQuery.java b/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerQuery.java
deleted file mode 100644 (file)
index f05204a..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.db.component;
-
-final class ResourceIndexerQuery {
-  private long rootProjectId;
-  private String[] scopes = null;
-  private String[] qualifiers = null;
-  private boolean nonIndexedOnly = false;
-
-  private ResourceIndexerQuery() {
-  }
-
-  public static ResourceIndexerQuery create() {
-    return new ResourceIndexerQuery();
-  }
-
-  public String[] getScopes() {
-    return scopes;
-  }
-
-  public String[] getQualifiers() {
-    return qualifiers;
-  }
-
-  public ResourceIndexerQuery setScopes(String[] scopes) {
-    this.scopes = scopes;
-    return this;
-  }
-
-  public ResourceIndexerQuery setQualifiers(String[] qualifiers) {
-    this.qualifiers = qualifiers;
-    return this;
-  }
-
-  public long getRootProjectId() {
-    return rootProjectId;
-  }
-
-  public ResourceIndexerQuery setRootProjectId(long i) {
-    this.rootProjectId = i;
-    return this;
-  }
-
-  public boolean isNonIndexedOnly() {
-    return nonIndexedOnly;
-  }
-
-  public ResourceIndexerQuery setNonIndexedOnly(boolean b) {
-    this.nonIndexedOnly = b;
-    return this;
-  }
-}
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
new file mode 100644 (file)
index 0000000..1228c97
--- /dev/null
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="org.sonar.db.component.ResourceIndexMapper">
+
+  <select id="selectProjectIdsFromQueryAndViewOrSubViewUuid" parameterType="map" resultType="long">
+    SELECT r.resource_id FROM resource_index r
+    INNER JOIN projects copy ON copy.copy_resource_id = r.resource_id
+    <where>
+      AND copy.module_uuid_path LIKE #{viewUuidQuery}
+      AND r.kee LIKE #{query}
+    </where>
+    ORDER BY r.name_size
+  </select>
+
+  <!--
+  The column PROJECTS.ROOT_ID is not exact on multi-modules projects. The root id must
+  be loaded from the table SNAPSHOTS
+  -->
+  <select id="selectResources" parameterType="map" resultType="Resource">
+    select p.name as "name", p.id as "id", p.scope as "scope", p.qualifier as "qualifier", s.root_project_id as "rootId"
+    from projects p, snapshots s
+    <where>
+      p.enabled=${_true}
+      and p.copy_resource_id is null
+      and p.id=s.project_id
+      and s.islast=${_true}
+      <if test="scopes != null">
+        and p.scope in
+        <foreach item="scope" index="index" collection="scopes" open="(" separator="," close=")">#{scope}</foreach>
+      </if>
+      <if test="qualifiers != null">
+        and p.qualifier in
+        <foreach item="qualifier" index="index" collection="qualifiers" open="(" separator="," close=")">#{qualifier}
+        </foreach>
+      </if>
+      <if test="rootProjectId != null">
+        and s.root_project_id=#{rootProjectId}
+      </if>
+      <if test="nonIndexedOnly">
+        and not exists(select * from resource_index ri where ri.resource_id=p.id)
+      </if>
+    </where>
+    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
+    where resource_id=#{id} and position=0
+  </select>
+
+  <select id="selectResourceToIndex" parameterType="long" resultType="Resource">
+    select id, name, root_id as "rootId", qualifier
+    from projects
+    where id=#{id} and enabled=${_true}
+  </select>
+
+  <delete id="deleteByResourceId" parameterType="long">
+    delete from resource_index
+    where resource_id=#{id}
+  </delete>
+
+  <insert id="insert" parameterType="ResourceIndex" useGeneratedKeys="false">
+    insert into resource_index (kee, position, name_size, resource_id, root_project_id, qualifier)
+    values (#{key}, #{position}, #{nameSize},
+    #{resourceId}, #{rootProjectId}, #{qualifier})
+  </insert>
+
+</mapper>
+
diff --git a/sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexerMapper.xml b/sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexerMapper.xml
deleted file mode 100644 (file)
index b9a1067..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.db.component.ResourceIndexerMapper">
-
-  <select id="selectProjectIdsFromQueryAndViewOrSubViewUuid" parameterType="map" resultType="long">
-    SELECT r.resource_id FROM resource_index r
-    INNER JOIN projects copy ON copy.copy_resource_id = r.resource_id
-    <where>
-      AND copy.module_uuid_path LIKE #{viewUuidQuery}
-      AND r.kee LIKE #{query}
-    </where>
-    ORDER BY r.name_size
-  </select>
-
-  <!--
-  The column PROJECTS.ROOT_ID is not exact on multi-modules projects. The root id must
-  be loaded from the table SNAPSHOTS
-  -->
-  <select id="selectResources" parameterType="map" resultType="Resource">
-    select p.name as "name", p.id as "id", p.scope as "scope", p.qualifier as "qualifier", s.root_project_id as "rootId"
-    from projects p, snapshots s
-    <where>
-      p.enabled=${_true}
-      and p.copy_resource_id is null
-      and p.id=s.project_id
-      and s.islast=${_true}
-      <if test="scopes != null">
-        and p.scope in
-        <foreach item="scope" index="index" collection="scopes" open="(" separator="," close=")">#{scope}</foreach>
-      </if>
-      <if test="qualifiers != null">
-        and p.qualifier in
-        <foreach item="qualifier" index="index" collection="qualifiers" open="(" separator="," close=")">#{qualifier}
-        </foreach>
-      </if>
-      <if test="rootProjectId != null">
-        and s.root_project_id=#{rootProjectId}
-      </if>
-      <if test="nonIndexedOnly">
-        and not exists(select * from resource_index ri where ri.resource_id=p.id)
-      </if>
-    </where>
-    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
-    where resource_id=#{id} and position=0
-  </select>
-
-  <select id="selectResourceToIndex" parameterType="long" resultType="Resource">
-    select id, name, root_id as "rootId", qualifier
-    from projects
-    where id=#{id} and enabled=${_true}
-  </select>
-
-  <delete id="deleteByResourceId" parameterType="long">
-    delete from resource_index
-    where resource_id=#{id}
-  </delete>
-
-  <insert id="insert" parameterType="ResourceIndex" useGeneratedKeys="false">
-    insert into resource_index (kee, position, name_size, resource_id, root_project_id, qualifier)
-    values (#{key}, #{position}, #{nameSize},
-    #{resourceId}, #{rootProjectId}, #{qualifier})
-  </insert>
-
-</mapper>
-
index 756a3437595a4e41076c71dd104237733e706fe1..43b8c75e036b2e75321ffa97c30d28bdff01eca5 100644 (file)
  */
 package org.sonar.db;
 
-import com.google.common.collect.Maps;
-import com.google.common.io.Closeables;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.Map;
-import java.util.Properties;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.text.StrSubstitutor;
-import org.dbunit.Assertion;
-import org.dbunit.DataSourceDatabaseTester;
-import org.dbunit.DatabaseUnitException;
-import org.dbunit.IDatabaseTester;
-import org.dbunit.database.DatabaseConfig;
-import org.dbunit.database.IDatabaseConnection;
-import org.dbunit.dataset.CompositeDataSet;
-import org.dbunit.dataset.DataSetException;
-import org.dbunit.dataset.IDataSet;
-import org.dbunit.dataset.ITable;
-import org.dbunit.dataset.ReplacementDataSet;
-import org.dbunit.dataset.filter.DefaultColumnFilter;
-import org.dbunit.dataset.xml.FlatXmlDataSet;
-import org.dbunit.ext.mssql.InsertIdentityOperation;
-import org.dbunit.ext.mysql.MySqlMetadataHandler;
-import org.dbunit.operation.DatabaseOperation;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Rule;
 import org.junit.experimental.categories.Category;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.config.Settings;
-import org.sonar.db.deprecated.NullQueue;
-import org.sonar.db.dialect.MySql;
+import org.sonar.api.utils.System2;
 import org.sonar.test.DbTests;
 
-import static org.junit.Assert.fail;
-
 /**
  * @deprecated use an instance of {@link DbTester instead} instead,
  * and do no forget to annotated the test class with {@link org.sonar.test.DbTests}.
@@ -71,130 +34,15 @@ import static org.junit.Assert.fail;
 @Deprecated
 public abstract class AbstractDaoTestCase {
 
-  private static final Logger LOG = LoggerFactory.getLogger(AbstractDaoTestCase.class);
-  private static Database database;
-  private static DatabaseCommands databaseCommands;
-  private static MyBatis myBatis;
-  private static String login;
-
-  private IDatabaseTester databaseTester;
-
-  @BeforeClass
-  public static void startDatabase() throws Exception {
-    if (database == null) {
-      Settings settings = new Settings().setProperties(Maps.fromProperties(System.getProperties()));
-      if (settings.hasKey("orchestrator.configUrl")) {
-        loadOrchestratorSettings(settings);
-      }
-      login = settings.getString("sonar.jdbc.username");
-      for (String key : settings.getKeysStartingWith("sonar.jdbc")) {
-        LOG.info(key + ": " + settings.getString(key));
-      }
-      boolean hasDialect = settings.hasKey("sonar.jdbc.dialect");
-      if (hasDialect) {
-        database = new DefaultDatabase(settings);
-      } else {
-        database = new H2Database("test", true);
-      }
-      database.start();
-      LOG.info("Test Database: " + database);
-      databaseCommands = DatabaseCommands.forDialect(database.getDialect());
-
-      myBatis = new MyBatis(database, new NullQueue());
-      myBatis.start();
-    }
-  }
-
-  /**
-   * Orchestrator is the name of a SonarSource close-source library for database and integration testing.
-   */
-  private static void loadOrchestratorSettings(Settings settings) throws URISyntaxException, IOException {
-    String url = settings.getString("orchestrator.configUrl");
-    URI uri = new URI(url);
-    InputStream input = null;
-    try {
-      if (url.startsWith("file:")) {
-        File file = new File(uri);
-        input = FileUtils.openInputStream(file);
-      } else {
-        HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection();
-        int responseCode = connection.getResponseCode();
-        if (responseCode >= 400) {
-          throw new IllegalStateException("Fail to request: " + uri + ". Status code=" + responseCode);
-        }
-
-        input = connection.getInputStream();
-
-      }
-      Properties props = new Properties();
-      props.load(input);
-      settings.addProperties(props);
-      for (Map.Entry<String, String> entry : settings.getProperties().entrySet()) {
-        String interpolatedValue = StrSubstitutor.replace(entry.getValue(), System.getenv(), "${", "}");
-        settings.setProperty(entry.getKey(), interpolatedValue);
-      }
-    } finally {
-      IOUtils.closeQuietly(input);
-    }
-  }
-
-  private static RuntimeException translateException(String msg, Exception cause) {
-    RuntimeException runtimeException = new RuntimeException(String.format("%s: [%s] %s", msg, cause.getClass().getName(), cause.getMessage()));
-    runtimeException.setStackTrace(cause.getStackTrace());
-    return runtimeException;
-  }
-
-  @Before
-  public void startDbUnit() throws Exception {
-    databaseCommands.truncateDatabase(database.getDataSource());
-    databaseTester = new DataSourceDatabaseTester(database.getDataSource(), databaseCommands.useLoginAsSchema() ? login : null);
-  }
-
-  protected MyBatis getMyBatis() {
-    return myBatis;
-  }
-
-  protected Database getDatabase() {
-    return database;
-  }
+  @Rule
+  public DbTester dbTester = DbTester.create(System2.INSTANCE);
 
   protected void setupData(String... testNames) {
-    InputStream[] streams = new InputStream[testNames.length];
-    try {
-      for (int i = 0; i < testNames.length; i++) {
-        String className = getClass().getName();
-        className = String.format("/%s/%s.xml", className.replace(".", "/"), testNames[i]);
-        streams[i] = getClass().getResourceAsStream(className);
-        if (streams[i] == null) {
-          throw new RuntimeException("Test not found :" + className);
-        }
-      }
-
-      setupData(streams);
-      databaseCommands.resetPrimaryKeys(database.getDataSource());
-    } catch (SQLException e) {
-      throw translateException("Could not setup DBUnit data", e);
-    } finally {
-      for (InputStream stream : streams) {
-        IOUtils.closeQuietly(stream);
-      }
-    }
-  }
-
-  private void setupData(InputStream... dataSetStream) {
-    IDatabaseConnection connection = openDbUnitConnection();
-    try {
-      IDataSet[] dataSets = new IDataSet[dataSetStream.length];
-      for (int i = 0; i < dataSetStream.length; i++) {
-        dataSets[i] = getData(dataSetStream[i]);
-      }
-      databaseTester.setDataSet(new CompositeDataSet(dataSets));
-      new InsertIdentityOperation(DatabaseOperation.INSERT).execute(connection, databaseTester.getDataSet());
-    } catch (Exception e) {
-      throw translateException("Could not setup DBUnit data", e);
-    } finally {
-      closeDbUnitConnection(connection);
+    List<String> filenames = new ArrayList<>();
+    for (String testName : testNames) {
+      filenames.add(testName + (testName.endsWith(".xml") ? "" : ".xml"));
     }
+    dbTester.prepareDbUnit(getClass(), filenames.toArray(new String[filenames.size()]));
   }
 
   protected void checkTables(String testName, String... tables) {
@@ -202,107 +50,15 @@ public abstract class AbstractDaoTestCase {
   }
 
   protected void checkTables(String testName, String[] excludedColumnNames, String... tables) {
-    IDatabaseConnection connection = openDbUnitConnection();
-    try {
-      IDataSet dataSet = connection.createDataSet();
-      IDataSet expectedDataSet = getExpectedData(testName);
-      for (String table : tables) {
-        ITable filteredTable = DefaultColumnFilter.excludedColumnsTable(dataSet.getTable(table), excludedColumnNames);
-        ITable filteredExpectedTable = DefaultColumnFilter.excludedColumnsTable(expectedDataSet.getTable(table), excludedColumnNames);
-        Assertion.assertEquals(filteredExpectedTable, filteredTable);
-      }
-    } catch (DatabaseUnitException e) {
-      fail(e.getMessage());
-    } catch (SQLException e) {
-      throw translateException("Error while checking results", e);
-    } finally {
-      closeDbUnitConnection(connection);
-    }
+    dbTester.assertDbUnit(getClass(), testName + (testName.endsWith("-result.xml") ? "" : "-result.xml"), excludedColumnNames, tables);
   }
 
   protected void checkTable(String testName, String table, String... columns) {
-    IDatabaseConnection connection = openDbUnitConnection();
-    try {
-      IDataSet dataSet = connection.createDataSet();
-      IDataSet expectedDataSet = getExpectedData(testName);
-      ITable filteredTable = DefaultColumnFilter.includedColumnsTable(dataSet.getTable(table), columns);
-      ITable filteredExpectedTable = DefaultColumnFilter.includedColumnsTable(expectedDataSet.getTable(table), columns);
-      Assertion.assertEquals(filteredExpectedTable, filteredTable);
-    } catch (DatabaseUnitException e) {
-      fail(e.getMessage());
-    } catch (SQLException e) {
-      throw translateException("Error while checking results", e);
-    } finally {
-      closeDbUnitConnection(connection);
-    }
-  }
-
-  protected void assertEmptyTables(String... emptyTables) {
-    IDatabaseConnection connection = openDbUnitConnection();
-    try {
-      IDataSet dataSet = connection.createDataSet();
-      for (String table : emptyTables) {
-        try {
-          Assert.assertEquals("Table " + table + " not empty.", 0, dataSet.getTable(table).getRowCount());
-        } catch (DataSetException e) {
-          throw translateException("Error while checking results", e);
-        }
-      }
-    } catch (SQLException e) {
-      throw translateException("Error while checking results", e);
-    } finally {
-      closeDbUnitConnection(connection);
-    }
-  }
-
-  private IDatabaseConnection openDbUnitConnection() {
-    try {
-      IDatabaseConnection connection = databaseTester.getConnection();
-      connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, databaseCommands.getDbUnitFactory());
-      connection.getConfig().setFeature(DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES, false);
-      connection.getConfig().setFeature(DatabaseConfig.FEATURE_SKIP_ORACLE_RECYCLEBIN_TABLES, true);
-      if (MySql.ID.equals(database.getDialect().getId())) {
-        connection.getConfig().setProperty(DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES, false);
-        connection.getConfig().setProperty(DatabaseConfig.PROPERTY_METADATA_HANDLER, new MySqlMetadataHandler());
-      }
-      return connection;
-    } catch (Exception e) {
-      throw new IllegalStateException("Fail to open dbunit connection", e);
-    }
+    dbTester.assertDbUnitTable(getClass(), testName + (testName.endsWith("-result.xml") ? "" : "-result.xml"), table, columns);
   }
 
-  private void closeDbUnitConnection(IDatabaseConnection c) {
-    try {
-      c.close();
-    } catch (SQLException e) {
-      throw new IllegalStateException("Fail to close dbunit connection", e);
-    }
-  }
-
-  private IDataSet getExpectedData(String testName) {
-    String className = getClass().getName();
-    String fileName = String.format("/%s/%s-result.xml", className.replace('.', '/'), testName);
-    InputStream in = getClass().getResourceAsStream(fileName);
-    try {
-      return getData(in);
-    } finally {
-      Closeables.closeQuietly(in);
-    }
-  }
-
-  private IDataSet getData(InputStream stream) {
-    try {
-      ReplacementDataSet dataSet = new ReplacementDataSet(new FlatXmlDataSet(stream));
-      dataSet.addReplacementObject("[null]", null);
-      dataSet.addReplacementObject("[false]", Boolean.FALSE);
-      dataSet.addReplacementObject("[true]", Boolean.TRUE);
-      return dataSet;
-    } catch (Exception e) {
-      throw translateException("Could not read the dataset stream", e);
-    }
-  }
-
-  protected Connection getConnection() throws SQLException {
-    return database.getDataSource().getConnection();
+  @Deprecated
+  protected MyBatis getMyBatis() {
+    return dbTester.myBatis();
   }
 }
index 1b6acbb3eb25d2d5e3ff3e5dba698c93f3b3c25a..9a619b36a1efada46c0f9895c5e7612977f5167c 100644 (file)
@@ -41,8 +41,8 @@ import static org.mockito.Mockito.verify;
 public class DatabaseUtilsTest extends AbstractDaoTestCase {
 
   @Test
-  public void should_close_connection() throws SQLException {
-    Connection connection = getConnection();
+  public void should_close_connection() throws Exception {
+    Connection connection = dbTester.openConnection();
     assertThat(isClosed(connection)).isFalse();
 
     DatabaseUtils.closeQuietly(connection);
@@ -56,8 +56,8 @@ public class DatabaseUtilsTest extends AbstractDaoTestCase {
   }
 
   @Test
-  public void should_close_statement_and_resultset() throws SQLException {
-    Connection connection = getConnection();
+  public void should_close_statement_and_resultset() throws Exception {
+    Connection connection = dbTester.openConnection();
     try {
       PreparedStatement statement = connection.prepareStatement(selectDual());
       ResultSet rs = statement.executeQuery();
@@ -143,7 +143,7 @@ public class DatabaseUtilsTest extends AbstractDaoTestCase {
 
   private String selectDual() {
     String sql = "SELECT 1";
-    if (Oracle.ID.equals(getDatabase().getDialect().getId())) {
+    if (Oracle.ID.equals(dbTester.database().getDialect().getId())) {
       sql = "SELECT 1 FROM DUAL";
     }
     return sql;
index dfa4e9cfef01fe70e1409e6ecab066ed5d6e76c2..30bc65fa1e364e0d30b292b2f37c09170d52cae8 100644 (file)
@@ -49,7 +49,6 @@ import org.dbunit.dataset.filter.DefaultColumnFilter;
 import org.dbunit.dataset.xml.FlatXmlDataSet;
 import org.dbunit.ext.mssql.InsertIdentityOperation;
 import org.dbunit.operation.DatabaseOperation;
-import org.junit.After;
 import org.junit.rules.ExternalResource;
 import org.picocontainer.containers.TransientPicoContainer;
 import org.sonar.api.utils.System2;
@@ -71,7 +70,7 @@ public class DbTester extends ExternalResource {
 
   private final System2 system2;
   private final TestDb db;
-  private DbClient2 client;
+  private DbClient client;
   private DbSession session = null;
 
   @Deprecated
@@ -100,11 +99,12 @@ public class DbTester extends ExternalResource {
     truncateTables();
   }
 
-  @After
-  public void closeSession() throws Exception {
+  @Override
+  protected void after() {
     if (session != null) {
       MyBatis.closeQuietly(session);
     }
+    db.close();
   }
 
   public DbSession getSession() {
@@ -118,7 +118,7 @@ public class DbTester extends ExternalResource {
     db.truncateTables();
   }
 
-  public DbClient2 getDbClient() {
+  public DbClient getDbClient() {
     if (client == null) {
       TransientPicoContainer ioc = new TransientPicoContainer();
       ioc.addComponent(db.getMyBatis());
@@ -127,7 +127,7 @@ public class DbTester extends ExternalResource {
         ioc.addComponent(daoClass);
       }
       List<Dao> daos = ioc.getComponents(Dao.class);
-      client = new DbClient2(db.getMyBatis(), daos.toArray(new Dao[daos.size()]));
+      client = new DbClient(db.getDatabase(), db.getMyBatis(), daos.toArray(new Dao[daos.size()]));
     }
     return client;
   }
@@ -263,6 +263,24 @@ public class DbTester extends ExternalResource {
     }
   }
 
+  public void assertDbUnitTable(Class testClass, String filename, String table, String... columns) {
+    IDatabaseConnection connection = dbUnitConnection();
+    try {
+      IDataSet dataSet = connection.createDataSet();
+      String path = "/" + testClass.getName().replace('.', '/') + "/" + filename;
+      IDataSet expectedDataSet = dbUnitDataSet(testClass.getResourceAsStream(path));
+      ITable filteredTable = DefaultColumnFilter.includedColumnsTable(dataSet.getTable(table), columns);
+      ITable filteredExpectedTable = DefaultColumnFilter.includedColumnsTable(expectedDataSet.getTable(table), columns);
+      Assertion.assertEquals(filteredExpectedTable, filteredTable);
+    } catch (DatabaseUnitException e) {
+      fail(e.getMessage());
+    } catch (SQLException e) {
+      throw translateException("Error while checking results", e);
+    } finally {
+      closeQuietly(connection);
+    }
+  }
+
   public void assertDbUnit(Class testClass, String filename, String... tables) {
     assertDbUnit(testClass, filename, new String[0], tables);
   }
@@ -372,7 +390,7 @@ public class DbTester extends ExternalResource {
     }
   }
 
-  private static RuntimeException translateException(String msg, Exception cause) {
+  public static RuntimeException translateException(String msg, Exception cause) {
     RuntimeException runtimeException = new RuntimeException(String.format("%s: [%s] %s", msg, cause.getClass().getName(), cause.getMessage()));
     runtimeException.setStackTrace(cause.getStackTrace());
     return runtimeException;
@@ -400,4 +418,9 @@ public class DbTester extends ExternalResource {
   public Database database() {
     return db.getDatabase();
   }
+
+  public DatabaseCommands getCommands() {
+    return db.getCommands();
+  }
+
 }
index 970f9090fd1d97180d014257d52171cd3346add4..4326aa15b88bf8892e5f5e516428fb0687188c21 100644 (file)
@@ -24,9 +24,6 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.NoSuchElementException;
-import org.apache.commons.dbutils.DbUtils;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -42,107 +39,105 @@ public class ResultSetIteratorTest {
   @ClassRule
   public static DbTester dbTester = DbTester.createForSchema(System2.INSTANCE, ResultSetIteratorTest.class, "schema.sql");
 
-  Connection connection = null;
-
-  @Before
-  public void setUp() throws Exception {
-    connection = dbTester.openConnection();
-  }
-
-  @After
-  public void tearDown() {
-    DbUtils.closeQuietly(connection);
-  }
-
   @Test
   public void create_iterator_from_statement() throws Exception {
     dbTester.prepareDbUnit(getClass(), "feed.xml");
 
-    PreparedStatement stmt = connection.prepareStatement("select * from issues order by id");
-    FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt);
+    try (Connection connection = dbTester.openConnection()) {
+      PreparedStatement stmt = connection.prepareStatement("select * from issues order by id");
+      FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt);
 
-    assertThat(iterator.hasNext()).isTrue();
+      assertThat(iterator.hasNext()).isTrue();
 
-    // calling multiple times hasNext() is ok
-    assertThat(iterator.hasNext()).isTrue();
+      // calling multiple times hasNext() is ok
+      assertThat(iterator.hasNext()).isTrue();
 
-    assertThat(iterator.next()).isEqualTo(10);
-    assertThat(iterator.hasNext()).isTrue();
-    assertThat(iterator.next()).isEqualTo(20);
+      assertThat(iterator.next()).isEqualTo(10);
+      assertThat(iterator.hasNext()).isTrue();
+      assertThat(iterator.next()).isEqualTo(20);
 
-    // call next() without calling hasNext()
-    assertThat(iterator.next()).isEqualTo(30);
-    assertThat(iterator.hasNext()).isFalse();
+      // call next() without calling hasNext()
+      assertThat(iterator.next()).isEqualTo(30);
+      assertThat(iterator.hasNext()).isFalse();
 
-    try {
-      iterator.next();
-      fail();
-    } catch (NoSuchElementException e) {
-      // ok
-    }
+      try {
+        iterator.next();
+        fail();
+      } catch (NoSuchElementException e) {
+        // ok
+      }
 
-    iterator.close();
-    // statement is closed by ResultSetIterator
-    assertThat(stmt.isClosed()).isTrue();
+      iterator.close();
+      // statement is closed by ResultSetIterator
+      assertThat(stmt.isClosed()).isTrue();
+    }
   }
 
   @Test
   public void iterate_empty_list() throws Exception {
     dbTester.prepareDbUnit(getClass(), "feed.xml");
 
-    PreparedStatement stmt = connection.prepareStatement("select * from issues where id < 0");
-    FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt);
+    try (Connection connection = dbTester.openConnection()) {
+      PreparedStatement stmt = connection.prepareStatement("select * from issues where id < 0");
+      FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt);
 
-    assertThat(iterator.hasNext()).isFalse();
+      assertThat(iterator.hasNext()).isFalse();
+    }
   }
 
   @Test
   public void create_iterator_from_result_set() throws Exception {
     dbTester.prepareDbUnit(getClass(), "feed.xml");
 
-    PreparedStatement stmt = connection.prepareStatement("select * from issues order by id");
-    ResultSet rs = stmt.executeQuery();
-    FirstIntColumnIterator iterator = new FirstIntColumnIterator(rs);
+    try (Connection connection = dbTester.openConnection()) {
+      PreparedStatement stmt = connection.prepareStatement("select * from issues order by id");
+      ResultSet rs = stmt.executeQuery();
+      FirstIntColumnIterator iterator = new FirstIntColumnIterator(rs);
 
-    assertThat(iterator.next()).isEqualTo(10);
-    assertThat(iterator.next()).isEqualTo(20);
-    assertThat(iterator.next()).isEqualTo(30);
+      assertThat(iterator.next()).isEqualTo(10);
+      assertThat(iterator.next()).isEqualTo(20);
+      assertThat(iterator.next()).isEqualTo(30);
 
-    iterator.close();
-    assertThat(rs.isClosed()).isTrue();
-    stmt.close();
+      iterator.close();
+      assertThat(rs.isClosed()).isTrue();
+      stmt.close();
+    }
   }
 
   @Test
   public void remove_row_is_not_supported() throws Exception {
-    PreparedStatement stmt = connection.prepareStatement("select * from issues order by id");
-    FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt);
-
-    try {
-      iterator.remove();
-      fail();
-    } catch (UnsupportedOperationException ok) {
-      // ok
+    try (Connection connection = dbTester.openConnection()) {
+      PreparedStatement stmt = connection.prepareStatement("select * from issues order by id");
+      FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt);
+
+      try {
+        iterator.remove();
+        fail();
+      } catch (UnsupportedOperationException ok) {
+        // ok
+      }
+
+      iterator.close();
     }
-
-    iterator.close();
   }
 
   @Test
   public void fail_to_read_row() throws Exception {
     dbTester.prepareDbUnit(getClass(), "feed.xml");
 
-    PreparedStatement stmt = connection.prepareStatement("select * from issues order by id");
-    FailIterator iterator = new FailIterator(stmt);
-
-    assertThat(iterator.hasNext()).isTrue();
-    try {
-      iterator.next();
-      fail();
-    } catch (IllegalStateException e) {
-      assertThat(e.getCause()).isInstanceOf(SQLException.class);
+    try (Connection connection = dbTester.openConnection()) {
+      PreparedStatement stmt = connection.prepareStatement("select * from issues order by id");
+      FailIterator iterator = new FailIterator(stmt);
+
+      assertThat(iterator.hasNext()).isTrue();
+      try {
+        iterator.next();
+        fail();
+      } catch (IllegalStateException e) {
+        assertThat(e.getCause()).isInstanceOf(SQLException.class);
+      }
+      iterator.close();
     }
-    iterator.close();
   }
 
   private static class FirstIntColumnIterator extends ResultSetIterator<Integer> {
index 715ea17af6d569b991efafd0d9a5515cfff4bae3..3ab4fc413463c195756ba8d79a66dd01be31bd5f 100644 (file)
@@ -60,6 +60,17 @@ class TestDb {
   private DatabaseCommands commands;
   private IDatabaseTester tester;
   private MyBatis myBatis;
+  private boolean isDefault;
+
+  static TestDb create(@Nullable String schemaPath) {
+    if (schemaPath == null) {
+      if (DEFAULT == null) {
+        DEFAULT = new TestDb(null);
+      }
+      return DEFAULT;
+    }
+    return new TestDb(schemaPath);
+  }
 
   private TestDb(@Nullable String schemaPath) {
     if (db == null) {
@@ -87,6 +98,7 @@ class TestDb {
           throw new AssumptionViolatedException("Test disabled because it supports only H2");
         }
       }
+      isDefault = (schemaPath == null);
       LOG.info("Test Database: " + db);
 
       commands = DatabaseCommands.forDialect(db.getDialect());
@@ -105,20 +117,10 @@ class TestDb {
     }
   }
 
-  static TestDb create(@Nullable String schemaPath) {
-    if (schemaPath == null) {
-      if (DEFAULT == null) {
-        DEFAULT = new TestDb(null);
-      }
-      return DEFAULT;
+  void close() {
+    if (!isDefault) {
+      db.stop();
     }
-    return new TestDb(schemaPath);
-  }
-
-  void stop() {
-    db.stop();
-    db = null;
-    myBatis = null;
   }
 
   Database getDatabase() {
index a6c809330f1232bc76a73e4fb363ea089bd565a8..0936f6c8f76c9dabda52565fbf3d9a790069ae09 100644 (file)
@@ -307,7 +307,7 @@ public class ResourceDaoTest extends AbstractDaoTestCase {
 
     session.rollback();
 
-    assertEmptyTables("projects");
+    assertThat(dbTester.countRowsOfTable("projects")).isZero();
   }
 
   @Test
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
new file mode 100644 (file)
index 0000000..df1195d
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.db.component;
+
+import java.sql.SQLException;
+import org.junit.Test;
+import org.sonar.api.resources.Qualifiers;
+import org.sonar.db.AbstractDaoTestCase;
+import org.sonar.db.DbSession;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ResourceIndexDaoTest extends AbstractDaoTestCase {
+
+  ResourceIndexDao dao = dbTester.getDbClient().componentIndexDao();
+
+  @Test
+  public void shouldIndexResource() {
+    setupData("shouldIndexResource");
+
+    dao.indexResource(10, "ZipUtils", "FIL", 8);
+
+    checkTables("shouldIndexResource", new String[] {"id"}, "resource_index");
+  }
+
+  @Test
+  public void shouldIndexProjects() {
+    setupData("shouldIndexProjects");
+
+    dao.indexProjects();
+
+    checkTables("shouldIndexProjects", new String[] {"id"}, "resource_index");
+  }
+
+  @Test
+  public void shouldIndexMultiModulesProject() {
+    setupData("shouldIndexMultiModulesProject");
+
+    dao.indexProject(1);
+
+    checkTables("shouldIndexMultiModulesProject", new String[] {"id"}, "resource_index");
+  }
+
+  @Test
+  public void shouldReindexProjectAfterRenaming() {
+    setupData("shouldReindexProjectAfterRenaming");
+
+    dao.indexProject(1);
+
+    checkTables("shouldReindexProjectAfterRenaming", new String[] {"id"}, "resource_index");
+  }
+
+  @Test
+  public void shouldNotIndexPackages() throws SQLException {
+    setupData("shouldNotIndexPackages");
+
+    dao.indexProject(1);
+    // project
+    assertThat(dbTester.countSql("select count(resource_id) from resource_index where resource_id=1")).isGreaterThan(0);
+    // directory
+    assertThat(dbTester.countSql("select count(resource_id) from resource_index where resource_id=2")).isEqualTo(0);
+    // file
+    assertThat(dbTester.countSql("select count(resource_id) from resource_index where resource_id=3")).isGreaterThan(0);
+  }
+
+  @Test
+  public void shouldIndexTwoLettersLongResources() {
+    setupData("shouldIndexTwoLettersLongResource");
+
+    dao.indexResource(10, "AB", Qualifiers.PROJECT, 3);
+
+    checkTables("shouldIndexTwoLettersLongResource", new String[] {"id"}, "resource_index");
+  }
+
+  @Test
+  public void shouldReIndexTwoLettersLongResources() {
+    setupData("shouldReIndexTwoLettersLongResource");
+
+    dao.indexResource(1, "AS", Qualifiers.PROJECT, 1);
+
+    checkTables("shouldReIndexTwoLettersLongResource", new String[] {"id"}, "resource_index");
+  }
+
+  @Test
+  public void shouldReIndexNewTwoLettersLongResource() {
+    setupData("shouldReIndexNewTwoLettersLongResource");
+
+    dao.indexResource(1, "AS", Qualifiers.PROJECT, 1);
+
+    checkTables("shouldReIndexNewTwoLettersLongResource", new String[] {"id"}, "resource_index");
+  }
+
+  @Test
+  public void shouldReindexResource() {
+    setupData("shouldReindexResource");
+
+    dao.indexResource(1, "New Struts", Qualifiers.PROJECT, 1);
+
+    checkTables("shouldReindexResource", new String[] {"id"}, "resource_index");
+  }
+
+  @Test
+  public void shouldNotReindexUnchangedResource() {
+    setupData("shouldNotReindexUnchangedResource");
+
+    dao.indexResource(1, "Struts", Qualifiers.PROJECT, 1);
+
+    checkTables("shouldNotReindexUnchangedResource", new String[] {"id"}, "resource_index");
+  }
+
+  @Test
+  public void select_project_ids_from_query_and_view_or_sub_view_uuid() {
+    setupData("select_project_ids_from_query_and_view_or_sub_view_uuid");
+    String viewUuid = "EFGH";
+
+    DbSession session = dbTester.getSession();
+    assertThat(dao.selectProjectIdsFromQueryAndViewOrSubViewUuid(session, "project", viewUuid)).containsOnly(1L, 2L);
+    assertThat(dao.selectProjectIdsFromQueryAndViewOrSubViewUuid(session, "one", viewUuid)).containsOnly(1L);
+    assertThat(dao.selectProjectIdsFromQueryAndViewOrSubViewUuid(session, "two", viewUuid)).containsOnly(2L);
+    assertThat(dao.selectProjectIdsFromQueryAndViewOrSubViewUuid(session, "unknown", viewUuid)).isEmpty();
+  }
+}
diff --git a/sonar-db/src/test/java/org/sonar/db/component/ResourceIndexerDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ResourceIndexerDaoTest.java
deleted file mode 100644 (file)
index deb992b..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.db.component;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.utils.System2;
-import org.sonar.db.AbstractDaoTestCase;
-import org.sonar.db.DbSession;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-public class ResourceIndexerDaoTest extends AbstractDaoTestCase {
-
-  private static ResourceIndexerDao dao;
-
-  @Before
-  public void createDao() {
-    dao = new ResourceIndexerDao(getMyBatis(), mock(System2.class));
-  }
-
-  @Test
-  public void shouldIndexResource() {
-    setupData("shouldIndexResource");
-
-    dao.indexResource(10, "ZipUtils", "FIL", 8);
-
-    checkTables("shouldIndexResource", new String[] {"id"}, "resource_index");
-  }
-
-  @Test
-  public void shouldIndexProjects() {
-    setupData("shouldIndexProjects");
-
-    dao.indexProjects();
-
-    checkTables("shouldIndexProjects", new String[] {"id"}, "resource_index");
-  }
-
-  @Test
-  public void shouldIndexMultiModulesProject() {
-    setupData("shouldIndexMultiModulesProject");
-
-    dao.indexProject(1);
-
-    checkTables("shouldIndexMultiModulesProject", new String[] {"id"}, "resource_index");
-  }
-
-  @Test
-  public void shouldReindexProjectAfterRenaming() {
-    setupData("shouldReindexProjectAfterRenaming");
-
-    dao.indexProject(1);
-
-    checkTables("shouldReindexProjectAfterRenaming", new String[] {"id"}, "resource_index");
-  }
-
-  @Test
-  public void shouldNotIndexPackages() throws SQLException {
-    setupData("shouldNotIndexPackages");
-
-    dao.indexProject(1);
-
-    Connection connection = getConnection();
-    ResultSet rs = null;
-    try {
-      // project
-      rs = connection.createStatement().executeQuery("select count(resource_id) from resource_index where resource_id=1");
-      rs.next();
-      assertThat(rs.getInt(1)).isGreaterThan(0);
-
-      // directory
-      rs = connection.createStatement().executeQuery("select count(resource_id) from resource_index where resource_id=2");
-      rs.next();
-      assertThat(rs.getInt(1)).isEqualTo(0);
-
-      // file
-      rs = connection.createStatement().executeQuery("select count(resource_id) from resource_index where resource_id=3");
-      rs.next();
-      assertThat(rs.getInt(1)).isGreaterThan(0);
-    } finally {
-      if (null != rs) {
-        rs.close();
-      }
-    }
-  }
-
-  @Test
-  public void shouldIndexTwoLettersLongResources() {
-    setupData("shouldIndexTwoLettersLongResource");
-
-    dao.indexResource(10, "AB", Qualifiers.PROJECT, 3);
-
-    checkTables("shouldIndexTwoLettersLongResource", new String[] {"id"}, "resource_index");
-  }
-
-  @Test
-  public void shouldReIndexTwoLettersLongResources() {
-    setupData("shouldReIndexTwoLettersLongResource");
-
-    dao.indexResource(1, "AS", Qualifiers.PROJECT, 1);
-
-    checkTables("shouldReIndexTwoLettersLongResource", new String[] {"id"}, "resource_index");
-  }
-
-  @Test
-  public void shouldReIndexNewTwoLettersLongResource() {
-    setupData("shouldReIndexNewTwoLettersLongResource");
-
-    dao.indexResource(1, "AS", Qualifiers.PROJECT, 1);
-
-    checkTables("shouldReIndexNewTwoLettersLongResource", new String[] {"id"}, "resource_index");
-  }
-
-  @Test
-  public void shouldReindexResource() {
-    setupData("shouldReindexResource");
-
-    dao.indexResource(1, "New Struts", Qualifiers.PROJECT, 1);
-
-    checkTables("shouldReindexResource", new String[] {"id"}, "resource_index");
-  }
-
-  @Test
-  public void shouldNotReindexUnchangedResource() {
-    setupData("shouldNotReindexUnchangedResource");
-
-    dao.indexResource(1, "Struts", Qualifiers.PROJECT, 1);
-
-    checkTables("shouldNotReindexUnchangedResource", new String[] {"id"}, "resource_index");
-  }
-
-  @Test
-  public void select_project_ids_from_query_and_view_or_sub_view_uuid() {
-    setupData("select_project_ids_from_query_and_view_or_sub_view_uuid");
-    String viewUuid = "EFGH";
-
-    DbSession session = getMyBatis().openSession(false);
-    assertThat(dao.selectProjectIdsFromQueryAndViewOrSubViewUuid(session, "project", viewUuid)).containsOnly(1L, 2L);
-    assertThat(dao.selectProjectIdsFromQueryAndViewOrSubViewUuid(session, "one", viewUuid)).containsOnly(1L);
-    assertThat(dao.selectProjectIdsFromQueryAndViewOrSubViewUuid(session, "two", viewUuid)).containsOnly(2L);
-    assertThat(dao.selectProjectIdsFromQueryAndViewOrSubViewUuid(session, "unknown", viewUuid)).isEmpty();
-  }
-}
index 939fc01ed36e2685d8c7a9dc71c7c2aeca916c9f..85439f61db8001599ebd1a3b68d8643a41ff096f 100644 (file)
@@ -22,23 +22,15 @@ package org.sonar.db.issue;
 
 import java.util.Collection;
 import java.util.List;
-import org.apache.ibatis.session.SqlSession;
-import org.junit.Before;
 import org.junit.Test;
 import org.sonar.db.AbstractDaoTestCase;
-import org.sonar.db.MyBatis;
 
 import static com.google.common.collect.Lists.newArrayList;
 import static org.assertj.core.api.Assertions.assertThat;
 
 public class ActionPlanDaoTest extends AbstractDaoTestCase {
 
-  ActionPlanDao dao;
-
-  @Before
-  public void createDao() {
-    dao = new ActionPlanDao(getMyBatis());
-  }
+  ActionPlanDao dao = dbTester.getDbClient().actionPlanDao();
 
   @Test
   public void should_insert_new_action_plan() {
@@ -92,13 +84,11 @@ public class ActionPlanDaoTest extends AbstractDaoTestCase {
   public void should_find_by_keys_on_huge_number_of_keys() {
     setupData("shared");
 
-    SqlSession session = getMyBatis().openSession();
     List<String> hugeNbOKeys = newArrayList();
     for (int i = 0; i < 4500; i++) {
       hugeNbOKeys.add("ABCD" + i);
     }
     List<ActionPlanDto> result = dao.findByKeys(hugeNbOKeys);
-    MyBatis.closeQuietly(session);
 
     // The goal of this test is only to check that the query do no fail, not to check the number of results
     assertThat(result).isEmpty();
index 0da36e52b04ab8e9a48f120fb1535ace938d869a..1c6e6f67b8f550e3bffd3e036170f69e26abdff1 100644 (file)
@@ -27,6 +27,7 @@ import org.sonar.db.AbstractDaoTestCase;
 import org.sonar.db.MyBatis;
 
 import static com.google.common.collect.Lists.newArrayList;
+import static org.assertj.core.api.Assertions.assertThat;
 
 public class PurgeCommandsTest extends AbstractDaoTestCase {
 
@@ -117,7 +118,12 @@ public class PurgeCommandsTest extends AbstractDaoTestCase {
       new PurgeCommands(session, profiler).deleteResources(newArrayList(new IdUuidPair(1L, "1")));
     }
 
-    assertEmptyTables("projects", "snapshots", "events", "issues", "issue_changes", "authors");
+    assertThat(dbTester.countRowsOfTable("projects")).isZero();
+    assertThat(dbTester.countRowsOfTable("snapshots")).isZero();
+    assertThat(dbTester.countRowsOfTable("events")).isZero();
+    assertThat(dbTester.countRowsOfTable("issues")).isZero();
+    assertThat(dbTester.countRowsOfTable("issue_changes")).isZero();
+    assertThat(dbTester.countRowsOfTable("authors")).isZero();
   }
 
   /**
index 11aa33abc18f51d963149e9068334f2040fbfca7..0417fb5e919cd0e25d6260b053a9f0c6ce52f418 100644 (file)
 package org.sonar.db.purge;
 
 import java.util.List;
-import org.junit.After;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.experimental.categories.Category;
 import org.sonar.api.resources.Scopes;
 import org.sonar.api.utils.System2;
-import org.sonar.db.AbstractDaoTestCase;
-import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
-import org.sonar.db.component.ResourceDao;
+import org.sonar.db.DbTester;
+import org.sonar.test.DbTests;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-public class PurgeDaoTest extends AbstractDaoTestCase {
+@Category(DbTests.class)
+public class PurgeDaoTest {
 
-  private PurgeDao sut;
-  private System2 system2;
-  private DbSession dbSession;
+  System2 system2 = mock(System2.class);
 
-  private static PurgeableSnapshotDto getById(List<PurgeableSnapshotDto> snapshots, long id) {
-    for (PurgeableSnapshotDto snapshot : snapshots) {
-      if (snapshot.getSnapshotId() == id) {
-        return snapshot;
-      }
-    }
-    return null;
-  }
+  @Rule
+  public DbTester dbTester = DbTester.create(system2);
+
+  PurgeDao sut = dbTester.getDbClient().purgeDao();
 
   @Before
   public void before() {
-    system2 = mock(System2.class);
     when(system2.now()).thenReturn(1450000000000L);
-    dbSession = getMyBatis().openSession(false);
-
-    sut = new PurgeDao(getMyBatis(), new ResourceDao(getMyBatis(), system2), system2);
-  }
-
-  @After
-  public void after() {
-    MyBatis.closeQuietly(dbSession);
   }
 
   @Test
   public void shouldDeleteAbortedBuilds() {
-    setupData("shouldDeleteAbortedBuilds");
+    dbTester.prepareDbUnit(getClass(), "shouldDeleteAbortedBuilds.xml");
     sut.purge(newConfigurationWith30Days(), PurgeListener.EMPTY, new PurgeProfiler());
-    checkTables("shouldDeleteAbortedBuilds", "snapshots");
+    dbTester.assertDbUnit(getClass(), "shouldDeleteAbortedBuilds-result.xml", "snapshots");
   }
 
   @Test
   public void should_purge_project() {
-    setupData("shouldPurgeProject");
+    dbTester.prepareDbUnit(getClass(), "shouldPurgeProject.xml");
     sut.purge(newConfigurationWith30Days(), PurgeListener.EMPTY, new PurgeProfiler());
-    checkTables("shouldPurgeProject", "projects", "snapshots");
+    dbTester.assertDbUnit(getClass(), "shouldPurgeProject-result.xml", "projects", "snapshots");
   }
 
   private PurgeConfiguration newConfigurationWith30Days() {
@@ -87,35 +72,35 @@ public class PurgeDaoTest extends AbstractDaoTestCase {
 
   @Test
   public void delete_file_sources_of_disabled_resources() {
-    setupData("delete_file_sources_of_disabled_resources");
+    dbTester.prepareDbUnit(getClass(), "delete_file_sources_of_disabled_resources.xml");
     sut.purge(newConfigurationWith30Days(system2), PurgeListener.EMPTY, new PurgeProfiler());
-    checkTables("delete_file_sources_of_disabled_resources", "file_sources");
+    dbTester.assertDbUnit(getClass(), "delete_file_sources_of_disabled_resources-result.xml", "file_sources");
   }
 
   @Test
   public void shouldDeleteHistoricalDataOfDirectoriesAndFiles() {
-    setupData("shouldDeleteHistoricalDataOfDirectoriesAndFiles");
+    dbTester.prepareDbUnit(getClass(), "shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml");
     sut.purge(new PurgeConfiguration(new IdUuidPair(1L, "1"), new String[] {Scopes.DIRECTORY, Scopes.FILE}, 30), PurgeListener.EMPTY, new PurgeProfiler());
-    checkTables("shouldDeleteHistoricalDataOfDirectoriesAndFiles", "projects", "snapshots");
+    dbTester.assertDbUnit(getClass(), "shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml", "projects", "snapshots");
   }
 
   @Test
   public void disable_resources_without_last_snapshot() {
-    setupData("disable_resources_without_last_snapshot");
+    dbTester.prepareDbUnit(getClass(), "disable_resources_without_last_snapshot.xml");
     sut.purge(newConfigurationWith30Days(system2), PurgeListener.EMPTY, new PurgeProfiler());
-    checkTables("disable_resources_without_last_snapshot", new String[] {"issue_close_date", "issue_update_date"}, "projects", "snapshots", "issues");
+    dbTester.assertDbUnit(getClass(), "disable_resources_without_last_snapshot-result.xml", new String[]{"issue_close_date", "issue_update_date"}, "projects", "snapshots", "issues");
   }
 
   @Test
   public void shouldDeleteSnapshots() {
-    setupData("shouldDeleteSnapshots");
+    dbTester.prepareDbUnit(getClass(), "shouldDeleteSnapshots.xml");
     sut.deleteSnapshots(PurgeSnapshotQuery.create().setIslast(false).setResourceId(1L), new PurgeProfiler());
-    checkTables("shouldDeleteSnapshots", "snapshots");
+    dbTester.assertDbUnit(getClass(), "shouldDeleteSnapshots-result.xml", "snapshots");
   }
 
   @Test
   public void shouldSelectPurgeableSnapshots() {
-    setupData("shouldSelectPurgeableSnapshots");
+    dbTester.prepareDbUnit(getClass(), "shouldSelectPurgeableSnapshots.xml");
     List<PurgeableSnapshotDto> snapshots = sut.selectPurgeableSnapshots(1L);
 
     assertThat(snapshots).hasSize(3);
@@ -129,31 +114,45 @@ public class PurgeDaoTest extends AbstractDaoTestCase {
 
   @Test
   public void should_delete_project_and_associated_data() {
-    setupData("shouldDeleteProject");
+    dbTester.prepareDbUnit(getClass(), "shouldDeleteProject.xml");
     sut.deleteResourceTree(new IdUuidPair(1L, "A"), new PurgeProfiler());
-    assertEmptyTables("projects", "snapshots", "action_plans", "issues", "issue_changes", "file_sources");
+    assertThat(dbTester.countRowsOfTable("projects")).isZero();
+    assertThat(dbTester.countRowsOfTable("snapshots")).isZero();
+    assertThat(dbTester.countRowsOfTable("action_plans")).isZero();
+    assertThat(dbTester.countRowsOfTable("issues")).isZero();
+    assertThat(dbTester.countRowsOfTable("issue_changes")).isZero();
+    assertThat(dbTester.countRowsOfTable("file_sources")).isZero();
   }
 
   @Test
   public void should_delete_old_closed_issues() {
-    setupData("should_delete_old_closed_issues");
+    dbTester.prepareDbUnit(getClass(), "should_delete_old_closed_issues.xml");
     sut.purge(newConfigurationWith30Days(), PurgeListener.EMPTY, new PurgeProfiler());
-    checkTables("should_delete_old_closed_issues", "issues", "issue_changes");
+    dbTester.assertDbUnit(getClass(), "should_delete_old_closed_issues-result.xml", "issues", "issue_changes");
   }
 
   @Test
   public void should_delete_all_closed_issues() {
-    setupData("should_delete_all_closed_issues");
+    dbTester.prepareDbUnit(getClass(), "should_delete_all_closed_issues.xml");
     sut.purge(new PurgeConfiguration(new IdUuidPair(1L, "1"), new String[0], 0), PurgeListener.EMPTY, new PurgeProfiler());
-    checkTables("should_delete_all_closed_issues", "issues", "issue_changes");
+    dbTester.assertDbUnit(getClass(), "should_delete_all_closed_issues-result.xml", "issues", "issue_changes");
   }
 
   @Test
   public void select_purgeable_file_uuids_and_only_them() {
-    setupData("select_purgeable_file_uuids");
+    dbTester.prepareDbUnit(getClass(), "select_purgeable_file_uuids.xml");
 
-    List<String> uuids = sut.selectPurgeableFiles(dbSession, 1L);
+    List<String> uuids = sut.selectPurgeableFiles(dbTester.getSession(), 1L);
 
     assertThat(uuids).containsOnly("GHIJ");
   }
+
+  private static PurgeableSnapshotDto getById(List<PurgeableSnapshotDto> snapshots, long id) {
+    for (PurgeableSnapshotDto snapshot : snapshots) {
+      if (snapshot.getSnapshotId() == id) {
+        return snapshot;
+      }
+    }
+    return null;
+  }
 }
index 8e2840e09df5673765fbd9d20b64d6658d203d5f..daa5b1d5777fd825518e948bfb15f085b0696555 100644 (file)
@@ -31,16 +31,11 @@ public class QualityGateConditionDaoTest extends AbstractDaoTestCase {
     "id", "qgate_id", "metric_id", "operator", "value_warning", "value_error", "period"
   };
 
-  private static QualityGateConditionDao dao;
-
-  @Before
-  public void createDao() {
-    dao = new QualityGateConditionDao(getMyBatis());
-  }
+  QualityGateConditionDao dao = dbTester.getDbClient().gateConditionDao();
 
   @Test
   public void testInsert() throws Exception {
-    setupData("insert");
+    setupData("insert.xml");
     QualityGateConditionDto newCondition = new QualityGateConditionDto()
       .setQualityGateId(1L).setMetricId(2L).setOperator("GT").setWarningThreshold("10").setErrorThreshold("20").setPeriod(3);
     dao.insert(newCondition);
@@ -50,14 +45,14 @@ public class QualityGateConditionDaoTest extends AbstractDaoTestCase {
 
   @Test
   public void testSelectForQualityGate() throws Exception {
-    setupData("selectForQualityGate");
+    setupData("selectForQualityGate.xml");
     assertThat(dao.selectForQualityGate(1L)).hasSize(3);
     assertThat(dao.selectForQualityGate(2L)).hasSize(2);
   }
 
   @Test
   public void testSelectById() throws Exception {
-    setupData("selectForQualityGate");
+    setupData("selectForQualityGate.xml");
     QualityGateConditionDto selectById = dao.selectById(1L);
     assertThat(selectById).isNotNull();
     assertThat(selectById.getId()).isNotNull().isNotEqualTo(0L);
@@ -72,21 +67,22 @@ public class QualityGateConditionDaoTest extends AbstractDaoTestCase {
 
   @Test
   public void testDelete() throws Exception {
-    setupData("selectForQualityGate");
+    setupData("selectForQualityGate.xml");
     dao.delete(new QualityGateConditionDto().setId(1L));
     checkTable("delete", "quality_gate_conditions", COLUMNS_WITHOUT_TIMESTAMPS);
   }
 
   @Test
   public void testUpdate() throws Exception {
-    setupData("selectForQualityGate");
+    setupData("selectForQualityGate.xml");
     dao.update(new QualityGateConditionDto().setId(1L).setMetricId(7L).setOperator(">").setPeriod(1).setWarningThreshold("50").setErrorThreshold("80"));
-    checkTable("update", "quality_gate_conditions", COLUMNS_WITHOUT_TIMESTAMPS);
+    checkTable("update-result.xml", "quality_gate_conditions", COLUMNS_WITHOUT_TIMESTAMPS);
   }
 
+  @Test
   public void shouldCleanConditions() {
-    setupData("shouldCleanConditions");
+    setupData("shouldCleanConditions.xml");
     dao.deleteConditionsWithInvalidMetrics();
-    checkTables("shouldCleanConditions", "quality_gate_conditions");
+    checkTables("shouldCleanConditions-result.xml", new String[]{"created_at", "updated_at"}, "quality_gate_conditions");
   }
 }
index 9cda23c341709ae8c29b4545f70b0076ac38623c..4c845c60381b42e730f3803a00aee919c16397b9 100644 (file)
  */
 package org.sonar.db.user;
 
-import org.junit.Before;
 import org.junit.Test;
-import org.sonar.api.utils.System2;
 import org.sonar.db.AbstractDaoTestCase;
-import org.sonar.db.component.ResourceDao;
 import org.sonar.db.component.ResourceDto;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -31,12 +28,7 @@ import static org.junit.Assert.fail;
 
 public class AuthorDaoTest extends AbstractDaoTestCase {
 
-  private AuthorDao dao;
-
-  @Before
-  public void setUp() {
-    dao = new AuthorDao(getMyBatis(), new ResourceDao(getMyBatis(), System2.INSTANCE));
-  }
+  AuthorDao dao = dbTester.getDbClient().authorDao();
 
   @Test
   public void shouldSelectByLogin() {
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/select_project_ids_from_query_and_view_or_sub_view_uuid.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/select_project_ids_from_query_and_view_or_sub_view_uuid.xml
new file mode 100644 (file)
index 0000000..aff6947
--- /dev/null
@@ -0,0 +1,32 @@
+<dataset>
+
+  <!-- Real projects -->
+  <projects id="1" uuid="ABCD" project_uuid="ABCD" module_uuid_path=".ABCD." copy_resource_id="[null]" name="Project One" qualifier="TRK" scope="PRJ"/>
+  <projects id="2" uuid="BCDE" project_uuid="BCDE" module_uuid_path=".BCDE." copy_resource_id="[null]" name="Project Two" qualifier="TRK" scope="PRJ"/>
+
+  <!-- Copy projects -->
+  <projects id="3" uuid="CDEF" project_uuid="EFGH" module_uuid_path=".EFGH." copy_resource_id="1" name="Copy Project One" qualifier="TRK" scope="FIL"/>
+  <projects id="4" uuid="DEFG" project_uuid="EFGH" module_uuid_path=".EFGH." copy_resource_id="2" name="Copy Project One" qualifier="TRK" scope="FIL"/>
+
+  <!-- View containing all projects -->
+  <projects id="5" uuid="EFGH" project_uuid="EFGH" module_uuid_path=".EFGH." copy_resource_id="[null]" name="All projects" qualifier="VW" scope="PRJ"/>
+
+  <resource_index id="1" kee="project one" resource_id="1" root_project_id="1" position="0" name_size="11" qualifier="TRK"/>
+  <resource_index id="2" kee="roject one" resource_id="1" root_project_id="1" position="1" name_size="11" qualifier="TRK"/>
+  <resource_index id="3" kee="oject one" resource_id="1" root_project_id="1" position="2" name_size="11" qualifier="TRK"/>
+  <resource_index id="4" kee="ject one" resource_id="1" root_project_id="1" position="3" name_size="11" qualifier="TRK"/>
+  <resource_index id="5" kee="ect one" resource_id="1" root_project_id="1" position="4" name_size="11" qualifier="TRK"/>
+  <resource_index id="6" kee="ct one" resource_id="1" root_project_id="1" position="5" name_size="11" qualifier="TRK"/>
+  <resource_index id="7" kee="t one" resource_id="1" root_project_id="1" position="6" name_size="11" qualifier="TRK"/>
+  <resource_index id="8" kee=" one" resource_id="1" root_project_id="1" position="7" name_size="11" qualifier="TRK"/>
+  <resource_index id="9" kee="one" resource_id="1" root_project_id="1" position="8" name_size="11" qualifier="TRK"/>
+  <resource_index id="10" kee="project two" resource_id="2" root_project_id="2" position="0" name_size="11" qualifier="TRK"/>
+  <resource_index id="11" kee="roject two" resource_id="2" root_project_id="2" position="1" name_size="11" qualifier="TRK"/>
+  <resource_index id="12" kee="oject two" resource_id="2" root_project_id="2" position="2" name_size="11" qualifier="TRK"/>
+  <resource_index id="13" kee="ject two" resource_id="2" root_project_id="2" position="3" name_size="11" qualifier="TRK"/>
+  <resource_index id="14" kee="ect two" resource_id="2" root_project_id="2" position="4" name_size="11" qualifier="TRK"/>
+  <resource_index id="15" kee="ct two" resource_id="2" root_project_id="2" position="5" name_size="11" qualifier="TRK"/>
+  <resource_index id="16" kee="t two" resource_id="2" root_project_id="2" position="6" name_size="11" qualifier="TRK"/>
+  <resource_index id="17" kee="two" resource_id="2" root_project_id="2" position="7" name_size="11" qualifier="TRK"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexMultiModulesProject-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexMultiModulesProject-result.xml
new file mode 100644 (file)
index 0000000..48899d9
--- /dev/null
@@ -0,0 +1,69 @@
+<dataset>
+
+  <!-- project "struts" -> module "struts-core" -> package org.struts -> file "RequestContext" -->
+  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
+            uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
+            root_id="[null]"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <projects long_name="[null]" id="2" scope="PRJ" qualifier="BRC" kee="org.struts:struts-core" name="Struts Core"
+            uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
+            root_id="1"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <!-- note that the root_id of package/file is wrong. It references the module but not the root project -->
+  <projects long_name="org.struts" id="3" scope="DIR" qualifier="PAC" kee="org.struts:struts-core:org.struts"
+            uuid="CDEF" project_uuid="ABCD" module_uuid="BCDE" module_uuid_path=".ABCD.BCDE"
+            name="org.struts" root_id="2"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <projects long_name="org.struts.RequestContext" id="4" scope="CLA" qualifier="CLA"
+            uuid="DEFG" project_uuid="ABCD" module_uuid="BCDE" module_uuid_path=".ABCD.BCDE"
+            kee="org.struts:struts-core:org.struts.RequestContext"
+            name="RequestContext" root_id="2"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1"/>
+  <snapshots purge_status="[null]" id="2" islast="[true]" root_project_id="1" project_id="2"/>
+  <snapshots purge_status="[null]" id="3" islast="[true]" root_project_id="1" project_id="3"/>
+  <snapshots purge_status="[null]" id="4" islast="[true]" root_project_id="1" project_id="4"/>
+
+  <!-- The major goal is to test root_project_id -->
+
+  <!-- RequestContext -->
+  <resource_index kee="requestcontext" position="0" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+  <resource_index kee="equestcontext" position="1" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+  <resource_index kee="questcontext" position="2" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+  <resource_index kee="uestcontext" position="3" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+  <resource_index kee="estcontext" position="4" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+  <resource_index kee="stcontext" position="5" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+  <resource_index kee="tcontext" position="6" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+  <resource_index kee="context" position="7" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+  <resource_index kee="ontext" position="8" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+  <resource_index kee="ntext" position="9" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+  <resource_index kee="text" position="10" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+  <resource_index kee="ext" position="11" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+
+  <!-- Struts -->
+  <resource_index kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+
+  <!-- Struts Core -->
+  <resource_index kee="struts core" position="0" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
+  <resource_index kee="truts core" position="1" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
+  <resource_index kee="ruts core" position="2" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
+  <resource_index kee="uts core" position="3" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
+  <resource_index kee="ts core" position="4" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
+  <resource_index kee="s core" position="5" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
+  <resource_index kee=" core" position="6" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
+  <resource_index kee="core" position="7" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
+  <resource_index kee="ore" position="8" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
+
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexMultiModulesProject.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexMultiModulesProject.xml
new file mode 100644 (file)
index 0000000..a1cd4ef
--- /dev/null
@@ -0,0 +1,34 @@
+<dataset>
+
+  <!-- project "struts" -> module "struts-core" -> package org.struts -> file "RequestContext" -->
+  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
+            uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
+            root_id="[null]"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <projects long_name="[null]" id="2" scope="PRJ" qualifier="BRC" kee="org.struts:struts-core" name="Struts Core"
+            uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
+            root_id="1"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <!-- note that the root_id of package/file is wrong. It references the module but not the root project -->
+  <projects long_name="org.struts" id="3" scope="DIR" qualifier="PAC" kee="org.struts:struts-core:org.struts"
+            uuid="CDEF" project_uuid="ABCD" module_uuid="BCDE" module_uuid_path=".ABCD.BCDE"
+            name="org.struts" root_id="2"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <projects long_name="org.struts.RequestContext" id="4" scope="FIL" qualifier="CLA"
+            uuid="DEFG" project_uuid="ABCD" module_uuid="BCDE" module_uuid_path=".ABCD.BCDE"
+            kee="org.struts:struts-core:org.struts.RequestContext"
+            name="RequestContext" root_id="2"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1"/>
+  <snapshots purge_status="[null]" id="2" islast="[true]" root_project_id="1" project_id="2"/>
+  <snapshots purge_status="[null]" id="3" islast="[true]" root_project_id="1" project_id="3"/>
+  <snapshots purge_status="[null]" id="4" islast="[true]" root_project_id="1" project_id="4"/>
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexProjects-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexProjects-result.xml
new file mode 100644 (file)
index 0000000..ee9ab48
--- /dev/null
@@ -0,0 +1,52 @@
+<dataset>
+
+  <!-- project -->
+  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
+            uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
+            root_id="[null]"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <!-- directory -->
+  <projects long_name="org.struts" id="2" scope="DIR" qualifier="PAC" kee="org.struts:struts:org.struts"
+            uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
+            name="org.struts" root_id="1"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <!-- file -->
+  <projects long_name="org.struts.RequestContext" id="3" scope="CLA" qualifier="CLA"
+            uuid="CDEF" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
+            kee="org.struts:struts:org.struts.RequestContext"
+            name="RequestContext" root_id="1"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
+             qualifier="TRK"/>
+  <snapshots purge_status="[null]" id="2" islast="[true]" root_project_id="1" project_id="2" scope="DIR"
+             qualifier="PAC"/>
+  <snapshots purge_status="[null]" id="3" islast="[true]" root_project_id="1" project_id="3" scope="CLA"
+             qualifier="CLA"/>
+
+  <!-- RequestContext -->
+  <resource_index kee="requestcontext" position="0" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+  <resource_index kee="equestcontext" position="1" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+  <resource_index kee="questcontext" position="2" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+  <resource_index kee="uestcontext" position="3" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+  <resource_index kee="estcontext" position="4" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+  <resource_index kee="stcontext" position="5" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+  <resource_index kee="tcontext" position="6" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+  <resource_index kee="context" position="7" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+  <resource_index kee="ontext" position="8" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+  <resource_index kee="ntext" position="9" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+  <resource_index kee="text" position="10" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+  <resource_index kee="ext" position="11" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+
+  <!-- Struts -->
+  <resource_index kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexProjects.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexProjects.xml
new file mode 100644 (file)
index 0000000..0043b4c
--- /dev/null
@@ -0,0 +1,31 @@
+<dataset>
+
+  <!-- project -->
+  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
+            uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
+            root_id="[null]"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <!-- directory -->
+  <projects long_name="org.struts" id="2" scope="DIR" qualifier="PAC" kee="org.struts:struts:org.struts"
+            uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
+            name="org.struts" root_id="1"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <!-- file -->
+  <projects long_name="org.struts.RequestContext" id="3" scope="FIL" qualifier="CLA"
+            kee="org.struts:struts:org.struts.RequestContext"
+            uuid="CDEF" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
+            name="RequestContext" root_id="1"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
+             qualifier="TRK"/>
+  <snapshots purge_status="[null]" id="2" islast="[true]" root_project_id="1" project_id="2" scope="DIR"
+             qualifier="PAC"/>
+  <snapshots purge_status="[null]" id="3" islast="[true]" root_project_id="1" project_id="3" scope="FIL"
+             qualifier="CLA"/>
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexResource-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexResource-result.xml
new file mode 100644 (file)
index 0000000..f4cf080
--- /dev/null
@@ -0,0 +1,8 @@
+<dataset>
+  <resource_index kee="ziputils" position="0" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
+  <resource_index kee="iputils" position="1" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
+  <resource_index kee="putils" position="2" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
+  <resource_index kee="utils" position="3" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
+  <resource_index kee="tils" position="4" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
+  <resource_index kee="ils" position="5" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexResource.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexResource.xml
new file mode 100644 (file)
index 0000000..5a4a28b
--- /dev/null
@@ -0,0 +1 @@
+<dataset></dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexTwoLettersLongResource-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexTwoLettersLongResource-result.xml
new file mode 100644 (file)
index 0000000..c9941e4
--- /dev/null
@@ -0,0 +1,3 @@
+<dataset>
+  <resource_index kee="ab" position="0" name_size="2" resource_id="10" root_project_id="3" qualifier="TRK"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexTwoLettersLongResource.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexTwoLettersLongResource.xml
new file mode 100644 (file)
index 0000000..5a4a28b
--- /dev/null
@@ -0,0 +1 @@
+<dataset></dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldNotIndexPackages.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldNotIndexPackages.xml
new file mode 100644 (file)
index 0000000..0043b4c
--- /dev/null
@@ -0,0 +1,31 @@
+<dataset>
+
+  <!-- project -->
+  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
+            uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
+            root_id="[null]"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <!-- directory -->
+  <projects long_name="org.struts" id="2" scope="DIR" qualifier="PAC" kee="org.struts:struts:org.struts"
+            uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
+            name="org.struts" root_id="1"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <!-- file -->
+  <projects long_name="org.struts.RequestContext" id="3" scope="FIL" qualifier="CLA"
+            kee="org.struts:struts:org.struts.RequestContext"
+            uuid="CDEF" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
+            name="RequestContext" root_id="1"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
+             qualifier="TRK"/>
+  <snapshots purge_status="[null]" id="2" islast="[true]" root_project_id="1" project_id="2" scope="DIR"
+             qualifier="PAC"/>
+  <snapshots purge_status="[null]" id="3" islast="[true]" root_project_id="1" project_id="3" scope="FIL"
+             qualifier="CLA"/>
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldNotReindexUnchangedResource-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldNotReindexUnchangedResource-result.xml
new file mode 100644 (file)
index 0000000..4292af5
--- /dev/null
@@ -0,0 +1,6 @@
+<dataset>
+  <resource_index kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldNotReindexUnchangedResource.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldNotReindexUnchangedResource.xml
new file mode 100644 (file)
index 0000000..89a3a8c
--- /dev/null
@@ -0,0 +1,6 @@
+<dataset>
+  <resource_index id="1" kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index id="2" kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index id="3" kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index id="4" kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexNewTwoLettersLongResource-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexNewTwoLettersLongResource-result.xml
new file mode 100644 (file)
index 0000000..52db35f
--- /dev/null
@@ -0,0 +1,3 @@
+<dataset>
+  <resource_index kee="as" position="0" name_size="2" resource_id="1" root_project_id="1" qualifier="TRK"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexNewTwoLettersLongResource.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexNewTwoLettersLongResource.xml
new file mode 100644 (file)
index 0000000..af5863e
--- /dev/null
@@ -0,0 +1,18 @@
+<dataset>
+
+  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="AS"
+            uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
+            root_id="[null]"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
+             qualifier="TRK"/>
+
+  <!-- the index is on the old name "ST" but not on "AS" -->
+  <resource_index id="1" kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index id="2" kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index id="3" kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index id="4" kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexTwoLettersLongResource-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexTwoLettersLongResource-result.xml
new file mode 100644 (file)
index 0000000..52db35f
--- /dev/null
@@ -0,0 +1,3 @@
+<dataset>
+  <resource_index kee="as" position="0" name_size="2" resource_id="1" root_project_id="1" qualifier="TRK"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexTwoLettersLongResource.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexTwoLettersLongResource.xml
new file mode 100644 (file)
index 0000000..529e83c
--- /dev/null
@@ -0,0 +1,15 @@
+<dataset>
+
+  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="AS"
+            uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
+            root_id="[null]"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
+             qualifier="TRK"/>
+
+  <!-- the index is on the old name "ST" but not on "AS" -->
+  <resource_index id="1" kee="st" position="0" name_size="2" resource_id="1" root_project_id="1" qualifier="TRK"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexProjectAfterRenaming-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexProjectAfterRenaming-result.xml
new file mode 100644 (file)
index 0000000..e28b594
--- /dev/null
@@ -0,0 +1,24 @@
+<dataset>
+
+  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Apache Struts"
+            uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
+            root_id="[null]"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
+             qualifier="TRK"/>
+
+  <resource_index kee="apache struts" position="0" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="pache struts" position="1" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="ache struts" position="2" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="che struts" position="3" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="he struts" position="4" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="e struts" position="5" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee=" struts" position="6" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="struts" position="7" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="truts" position="8" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="ruts" position="9" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="uts" position="10" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexProjectAfterRenaming.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexProjectAfterRenaming.xml
new file mode 100644 (file)
index 0000000..84815e5
--- /dev/null
@@ -0,0 +1,18 @@
+<dataset>
+
+  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Apache Struts"
+            uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
+            root_id="[null]"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
+             qualifier="TRK"/>
+
+  <!-- the index is on the old name "Struts" but not on "Apache Struts -->
+  <resource_index id="1" kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index id="2" kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index id="3" kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index id="4" kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexResource-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexResource-result.xml
new file mode 100644 (file)
index 0000000..b9f3915
--- /dev/null
@@ -0,0 +1,10 @@
+<dataset>
+  <resource_index kee="new struts" position="0" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="ew struts" position="1" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="w struts" position="2" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee=" struts" position="3" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="struts" position="4" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="truts" position="5" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="ruts" position="6" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index kee="uts" position="7" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexResource.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexResource.xml
new file mode 100644 (file)
index 0000000..89a3a8c
--- /dev/null
@@ -0,0 +1,6 @@
+<dataset>
+  <resource_index id="1" kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index id="2" kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index id="3" kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+  <resource_index id="4" kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/select_project_ids_from_query_and_view_or_sub_view_uuid.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/select_project_ids_from_query_and_view_or_sub_view_uuid.xml
deleted file mode 100644 (file)
index aff6947..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-<dataset>
-
-  <!-- Real projects -->
-  <projects id="1" uuid="ABCD" project_uuid="ABCD" module_uuid_path=".ABCD." copy_resource_id="[null]" name="Project One" qualifier="TRK" scope="PRJ"/>
-  <projects id="2" uuid="BCDE" project_uuid="BCDE" module_uuid_path=".BCDE." copy_resource_id="[null]" name="Project Two" qualifier="TRK" scope="PRJ"/>
-
-  <!-- Copy projects -->
-  <projects id="3" uuid="CDEF" project_uuid="EFGH" module_uuid_path=".EFGH." copy_resource_id="1" name="Copy Project One" qualifier="TRK" scope="FIL"/>
-  <projects id="4" uuid="DEFG" project_uuid="EFGH" module_uuid_path=".EFGH." copy_resource_id="2" name="Copy Project One" qualifier="TRK" scope="FIL"/>
-
-  <!-- View containing all projects -->
-  <projects id="5" uuid="EFGH" project_uuid="EFGH" module_uuid_path=".EFGH." copy_resource_id="[null]" name="All projects" qualifier="VW" scope="PRJ"/>
-
-  <resource_index id="1" kee="project one" resource_id="1" root_project_id="1" position="0" name_size="11" qualifier="TRK"/>
-  <resource_index id="2" kee="roject one" resource_id="1" root_project_id="1" position="1" name_size="11" qualifier="TRK"/>
-  <resource_index id="3" kee="oject one" resource_id="1" root_project_id="1" position="2" name_size="11" qualifier="TRK"/>
-  <resource_index id="4" kee="ject one" resource_id="1" root_project_id="1" position="3" name_size="11" qualifier="TRK"/>
-  <resource_index id="5" kee="ect one" resource_id="1" root_project_id="1" position="4" name_size="11" qualifier="TRK"/>
-  <resource_index id="6" kee="ct one" resource_id="1" root_project_id="1" position="5" name_size="11" qualifier="TRK"/>
-  <resource_index id="7" kee="t one" resource_id="1" root_project_id="1" position="6" name_size="11" qualifier="TRK"/>
-  <resource_index id="8" kee=" one" resource_id="1" root_project_id="1" position="7" name_size="11" qualifier="TRK"/>
-  <resource_index id="9" kee="one" resource_id="1" root_project_id="1" position="8" name_size="11" qualifier="TRK"/>
-  <resource_index id="10" kee="project two" resource_id="2" root_project_id="2" position="0" name_size="11" qualifier="TRK"/>
-  <resource_index id="11" kee="roject two" resource_id="2" root_project_id="2" position="1" name_size="11" qualifier="TRK"/>
-  <resource_index id="12" kee="oject two" resource_id="2" root_project_id="2" position="2" name_size="11" qualifier="TRK"/>
-  <resource_index id="13" kee="ject two" resource_id="2" root_project_id="2" position="3" name_size="11" qualifier="TRK"/>
-  <resource_index id="14" kee="ect two" resource_id="2" root_project_id="2" position="4" name_size="11" qualifier="TRK"/>
-  <resource_index id="15" kee="ct two" resource_id="2" root_project_id="2" position="5" name_size="11" qualifier="TRK"/>
-  <resource_index id="16" kee="t two" resource_id="2" root_project_id="2" position="6" name_size="11" qualifier="TRK"/>
-  <resource_index id="17" kee="two" resource_id="2" root_project_id="2" position="7" name_size="11" qualifier="TRK"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexMultiModulesProject-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexMultiModulesProject-result.xml
deleted file mode 100644 (file)
index 48899d9..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-<dataset>
-
-  <!-- project "struts" -> module "struts-core" -> package org.struts -> file "RequestContext" -->
-  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
-            uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
-            root_id="[null]"
-            description="[null]"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
-  <projects long_name="[null]" id="2" scope="PRJ" qualifier="BRC" kee="org.struts:struts-core" name="Struts Core"
-            uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
-            root_id="1"
-            description="[null]"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
-  <!-- note that the root_id of package/file is wrong. It references the module but not the root project -->
-  <projects long_name="org.struts" id="3" scope="DIR" qualifier="PAC" kee="org.struts:struts-core:org.struts"
-            uuid="CDEF" project_uuid="ABCD" module_uuid="BCDE" module_uuid_path=".ABCD.BCDE"
-            name="org.struts" root_id="2"
-            description="[null]"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
-  <projects long_name="org.struts.RequestContext" id="4" scope="CLA" qualifier="CLA"
-            uuid="DEFG" project_uuid="ABCD" module_uuid="BCDE" module_uuid_path=".ABCD.BCDE"
-            kee="org.struts:struts-core:org.struts.RequestContext"
-            name="RequestContext" root_id="2"
-            description="[null]"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
-  <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1"/>
-  <snapshots purge_status="[null]" id="2" islast="[true]" root_project_id="1" project_id="2"/>
-  <snapshots purge_status="[null]" id="3" islast="[true]" root_project_id="1" project_id="3"/>
-  <snapshots purge_status="[null]" id="4" islast="[true]" root_project_id="1" project_id="4"/>
-
-  <!-- The major goal is to test root_project_id -->
-
-  <!-- RequestContext -->
-  <resource_index kee="requestcontext" position="0" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
-  <resource_index kee="equestcontext" position="1" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
-  <resource_index kee="questcontext" position="2" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
-  <resource_index kee="uestcontext" position="3" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
-  <resource_index kee="estcontext" position="4" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
-  <resource_index kee="stcontext" position="5" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
-  <resource_index kee="tcontext" position="6" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
-  <resource_index kee="context" position="7" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
-  <resource_index kee="ontext" position="8" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
-  <resource_index kee="ntext" position="9" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
-  <resource_index kee="text" position="10" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
-  <resource_index kee="ext" position="11" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
-
-  <!-- Struts -->
-  <resource_index kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-
-  <!-- Struts Core -->
-  <resource_index kee="struts core" position="0" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
-  <resource_index kee="truts core" position="1" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
-  <resource_index kee="ruts core" position="2" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
-  <resource_index kee="uts core" position="3" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
-  <resource_index kee="ts core" position="4" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
-  <resource_index kee="s core" position="5" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
-  <resource_index kee=" core" position="6" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
-  <resource_index kee="core" position="7" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
-  <resource_index kee="ore" position="8" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
-
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexMultiModulesProject.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexMultiModulesProject.xml
deleted file mode 100644 (file)
index a1cd4ef..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-<dataset>
-
-  <!-- project "struts" -> module "struts-core" -> package org.struts -> file "RequestContext" -->
-  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
-            uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
-            root_id="[null]"
-            description="[null]"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
-  <projects long_name="[null]" id="2" scope="PRJ" qualifier="BRC" kee="org.struts:struts-core" name="Struts Core"
-            uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
-            root_id="1"
-            description="[null]"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
-  <!-- note that the root_id of package/file is wrong. It references the module but not the root project -->
-  <projects long_name="org.struts" id="3" scope="DIR" qualifier="PAC" kee="org.struts:struts-core:org.struts"
-            uuid="CDEF" project_uuid="ABCD" module_uuid="BCDE" module_uuid_path=".ABCD.BCDE"
-            name="org.struts" root_id="2"
-            description="[null]"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
-  <projects long_name="org.struts.RequestContext" id="4" scope="FIL" qualifier="CLA"
-            uuid="DEFG" project_uuid="ABCD" module_uuid="BCDE" module_uuid_path=".ABCD.BCDE"
-            kee="org.struts:struts-core:org.struts.RequestContext"
-            name="RequestContext" root_id="2"
-            description="[null]"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
-  <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1"/>
-  <snapshots purge_status="[null]" id="2" islast="[true]" root_project_id="1" project_id="2"/>
-  <snapshots purge_status="[null]" id="3" islast="[true]" root_project_id="1" project_id="3"/>
-  <snapshots purge_status="[null]" id="4" islast="[true]" root_project_id="1" project_id="4"/>
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexProjects-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexProjects-result.xml
deleted file mode 100644 (file)
index ee9ab48..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-<dataset>
-
-  <!-- project -->
-  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
-            uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
-            root_id="[null]"
-            description="[null]"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
-  <!-- directory -->
-  <projects long_name="org.struts" id="2" scope="DIR" qualifier="PAC" kee="org.struts:struts:org.struts"
-            uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
-            name="org.struts" root_id="1"
-            description="[null]"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
-  <!-- file -->
-  <projects long_name="org.struts.RequestContext" id="3" scope="CLA" qualifier="CLA"
-            uuid="CDEF" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
-            kee="org.struts:struts:org.struts.RequestContext"
-            name="RequestContext" root_id="1"
-            description="[null]"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
-  <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
-             qualifier="TRK"/>
-  <snapshots purge_status="[null]" id="2" islast="[true]" root_project_id="1" project_id="2" scope="DIR"
-             qualifier="PAC"/>
-  <snapshots purge_status="[null]" id="3" islast="[true]" root_project_id="1" project_id="3" scope="CLA"
-             qualifier="CLA"/>
-
-  <!-- RequestContext -->
-  <resource_index kee="requestcontext" position="0" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
-  <resource_index kee="equestcontext" position="1" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
-  <resource_index kee="questcontext" position="2" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
-  <resource_index kee="uestcontext" position="3" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
-  <resource_index kee="estcontext" position="4" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
-  <resource_index kee="stcontext" position="5" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
-  <resource_index kee="tcontext" position="6" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
-  <resource_index kee="context" position="7" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
-  <resource_index kee="ontext" position="8" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
-  <resource_index kee="ntext" position="9" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
-  <resource_index kee="text" position="10" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
-  <resource_index kee="ext" position="11" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
-
-  <!-- Struts -->
-  <resource_index kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexProjects.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexProjects.xml
deleted file mode 100644 (file)
index 0043b4c..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<dataset>
-
-  <!-- project -->
-  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
-            uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
-            root_id="[null]"
-            description="[null]"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
-  <!-- directory -->
-  <projects long_name="org.struts" id="2" scope="DIR" qualifier="PAC" kee="org.struts:struts:org.struts"
-            uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
-            name="org.struts" root_id="1"
-            description="[null]"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
-  <!-- file -->
-  <projects long_name="org.struts.RequestContext" id="3" scope="FIL" qualifier="CLA"
-            kee="org.struts:struts:org.struts.RequestContext"
-            uuid="CDEF" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
-            name="RequestContext" root_id="1"
-            description="[null]"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
-  <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
-             qualifier="TRK"/>
-  <snapshots purge_status="[null]" id="2" islast="[true]" root_project_id="1" project_id="2" scope="DIR"
-             qualifier="PAC"/>
-  <snapshots purge_status="[null]" id="3" islast="[true]" root_project_id="1" project_id="3" scope="FIL"
-             qualifier="CLA"/>
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexResource-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexResource-result.xml
deleted file mode 100644 (file)
index f4cf080..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<dataset>
-  <resource_index kee="ziputils" position="0" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
-  <resource_index kee="iputils" position="1" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
-  <resource_index kee="putils" position="2" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
-  <resource_index kee="utils" position="3" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
-  <resource_index kee="tils" position="4" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
-  <resource_index kee="ils" position="5" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexResource.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexResource.xml
deleted file mode 100644 (file)
index 5a4a28b..0000000
+++ /dev/null
@@ -1 +0,0 @@
-<dataset></dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexTwoLettersLongResource-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexTwoLettersLongResource-result.xml
deleted file mode 100644 (file)
index c9941e4..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<dataset>
-  <resource_index kee="ab" position="0" name_size="2" resource_id="10" root_project_id="3" qualifier="TRK"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexTwoLettersLongResource.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexTwoLettersLongResource.xml
deleted file mode 100644 (file)
index 5a4a28b..0000000
+++ /dev/null
@@ -1 +0,0 @@
-<dataset></dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldNotIndexPackages.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldNotIndexPackages.xml
deleted file mode 100644 (file)
index 0043b4c..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<dataset>
-
-  <!-- project -->
-  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
-            uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
-            root_id="[null]"
-            description="[null]"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
-  <!-- directory -->
-  <projects long_name="org.struts" id="2" scope="DIR" qualifier="PAC" kee="org.struts:struts:org.struts"
-            uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
-            name="org.struts" root_id="1"
-            description="[null]"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
-  <!-- file -->
-  <projects long_name="org.struts.RequestContext" id="3" scope="FIL" qualifier="CLA"
-            kee="org.struts:struts:org.struts.RequestContext"
-            uuid="CDEF" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
-            name="RequestContext" root_id="1"
-            description="[null]"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
-  <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
-             qualifier="TRK"/>
-  <snapshots purge_status="[null]" id="2" islast="[true]" root_project_id="1" project_id="2" scope="DIR"
-             qualifier="PAC"/>
-  <snapshots purge_status="[null]" id="3" islast="[true]" root_project_id="1" project_id="3" scope="FIL"
-             qualifier="CLA"/>
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldNotReindexUnchangedResource-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldNotReindexUnchangedResource-result.xml
deleted file mode 100644 (file)
index 4292af5..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<dataset>
-  <resource_index kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldNotReindexUnchangedResource.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldNotReindexUnchangedResource.xml
deleted file mode 100644 (file)
index 89a3a8c..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<dataset>
-  <resource_index id="1" kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index id="2" kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index id="3" kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index id="4" kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexNewTwoLettersLongResource-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexNewTwoLettersLongResource-result.xml
deleted file mode 100644 (file)
index 52db35f..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<dataset>
-  <resource_index kee="as" position="0" name_size="2" resource_id="1" root_project_id="1" qualifier="TRK"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexNewTwoLettersLongResource.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexNewTwoLettersLongResource.xml
deleted file mode 100644 (file)
index af5863e..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<dataset>
-
-  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="AS"
-            uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
-            root_id="[null]"
-            description="[null]"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
-  <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
-             qualifier="TRK"/>
-
-  <!-- the index is on the old name "ST" but not on "AS" -->
-  <resource_index id="1" kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index id="2" kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index id="3" kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index id="4" kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexTwoLettersLongResource-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexTwoLettersLongResource-result.xml
deleted file mode 100644 (file)
index 52db35f..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<dataset>
-  <resource_index kee="as" position="0" name_size="2" resource_id="1" root_project_id="1" qualifier="TRK"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexTwoLettersLongResource.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexTwoLettersLongResource.xml
deleted file mode 100644 (file)
index 529e83c..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<dataset>
-
-  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="AS"
-            uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
-            root_id="[null]"
-            description="[null]"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
-  <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
-             qualifier="TRK"/>
-
-  <!-- the index is on the old name "ST" but not on "AS" -->
-  <resource_index id="1" kee="st" position="0" name_size="2" resource_id="1" root_project_id="1" qualifier="TRK"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexProjectAfterRenaming-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexProjectAfterRenaming-result.xml
deleted file mode 100644 (file)
index e28b594..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-<dataset>
-
-  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Apache Struts"
-            uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
-            root_id="[null]"
-            description="[null]"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
-  <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
-             qualifier="TRK"/>
-
-  <resource_index kee="apache struts" position="0" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="pache struts" position="1" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="ache struts" position="2" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="che struts" position="3" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="he struts" position="4" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="e struts" position="5" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee=" struts" position="6" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="struts" position="7" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="truts" position="8" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="ruts" position="9" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="uts" position="10" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexProjectAfterRenaming.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexProjectAfterRenaming.xml
deleted file mode 100644 (file)
index 84815e5..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<dataset>
-
-  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Apache Struts"
-            uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
-            root_id="[null]"
-            description="[null]"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
-  <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
-             qualifier="TRK"/>
-
-  <!-- the index is on the old name "Struts" but not on "Apache Struts -->
-  <resource_index id="1" kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index id="2" kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index id="3" kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index id="4" kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexResource-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexResource-result.xml
deleted file mode 100644 (file)
index b9f3915..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-<dataset>
-  <resource_index kee="new struts" position="0" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="ew struts" position="1" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="w struts" position="2" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee=" struts" position="3" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="struts" position="4" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="truts" position="5" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="ruts" position="6" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index kee="uts" position="7" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexResource.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexResource.xml
deleted file mode 100644 (file)
index 89a3a8c..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<dataset>
-  <resource_index id="1" kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index id="2" kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index id="3" kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-  <resource_index id="4" kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-</dataset>
\ No newline at end of file