]> source.dussan.org Git - sonarqube.git/commitdiff
Move some classes from sonar-server to sonar-db
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Sun, 5 Jul 2015 08:06:55 +0000 (10:06 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 6 Jul 2015 07:22:44 +0000 (09:22 +0200)
409 files changed:
server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/PersistFileSourcesStepTest.java
server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/SourceDbBenchmarkTest.java
server/sonar-server/src/main/java/org/sonar/core/computation/dbcleaner/ProjectCleaner.java
server/sonar-server/src/main/java/org/sonar/server/activity/db/ActivityDao.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/activity/db/package-info.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityResultSetIterator.java
server/sonar-server/src/main/java/org/sonar/server/component/ComponentCleanerService.java
server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentDao.java
server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentIndexDao.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentLinkDao.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/component/db/SnapshotDao.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/computation/ReportQueue.java
server/sonar-server/src/main/java/org/sonar/server/computation/db/AnalysisReportDao.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/computation/db/package-info.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/computation/step/SwitchSnapshotStep.java
server/sonar-server/src/main/java/org/sonar/server/dashboard/db/DashboardDao.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/dashboard/db/WidgetDao.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/dashboard/db/WidgetPropertyDao.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/dashboard/db/package-info.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java
server/sonar-server/src/main/java/org/sonar/server/db/DatabaseChecker.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/db/DbClient.java
server/sonar-server/src/main/java/org/sonar/server/db/ResultSetIterator.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdate.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/FeedQProfileKeysMigrationStep.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/db/migrations/v51/CopyScmAccountsFromAuthorsToUsers.java
server/sonar-server/src/main/java/org/sonar/server/duplication/ws/ShowAction.java
server/sonar-server/src/main/java/org/sonar/server/es/BulkIndexer.java
server/sonar-server/src/main/java/org/sonar/server/event/db/EventDao.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/event/db/package-info.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/issue/actionplan/ActionPlanService.java
server/sonar-server/src/main/java/org/sonar/server/issue/db/IssueDao.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/issue/db/package-info.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueResultSetIterator.java
server/sonar-server/src/main/java/org/sonar/server/measure/custom/persistence/CustomMeasureDao.java
server/sonar-server/src/main/java/org/sonar/server/measure/persistence/MeasureDao.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/measure/persistence/package-info.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/metric/persistence/MetricDao.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java
server/sonar-server/src/main/java/org/sonar/server/source/db/FileSourceDao.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/source/db/package-info.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineResultSetIterator.java
server/sonar-server/src/main/java/org/sonar/server/test/CoverageService.java
server/sonar-server/src/main/java/org/sonar/server/test/index/TestResultSetIterator.java
server/sonar-server/src/main/java/org/sonar/server/user/db/GroupDao.java
server/sonar-server/src/main/java/org/sonar/server/user/db/UserGroupDao.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/user/index/UserResultSetIterator.java
server/sonar-server/src/main/java/org/sonar/server/usergroups/package-info.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/util/ProgressLogger.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/util/Slug.java [deleted file]
server/sonar-server/src/test/java/org/sonar/core/computation/dbcleaner/ProjectCleanerTest.java
server/sonar-server/src/test/java/org/sonar/server/activity/ActivityServiceTest.java
server/sonar-server/src/test/java/org/sonar/server/activity/db/ActivityDaoTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java
server/sonar-server/src/test/java/org/sonar/server/batch/ProjectRepositoryLoaderMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceTest.java
server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentDaoTest.java
server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentIndexDaoTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentLinkDaoTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/component/db/SnapshotDaoTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/ReportQueueTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/computation/issue/DebtAggregatorTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/issue/DebtCalculatorTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/issue/IssueCounterTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/issue/RuleRepositoryImplTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/issue/RuleTagsCopierTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryImplTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedPeriodsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/FillMeasuresWithVariationsStepTest.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/computation/step/PersistComponentsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistEventsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistIssuesStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistProjectLinksStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistSnapshotsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistTestsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/SwitchSnapshotStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/ValidateProjectStepTest.java
server/sonar-server/src/test/java/org/sonar/server/dashboard/db/WidgetDaoTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/db/BaseDaoTest.java
server/sonar-server/src/test/java/org/sonar/server/db/DatabaseCheckerTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/db/ResultSetIteratorTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/db/migrations/BaseDataChangeTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v36/ViolationMigrationTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v42/CompleteIssueMessageMigrationTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v42/PackageKeysMigrationTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigrationStepTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigrationStepTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/IssueChangelogMigrationStepTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/NotResolvedIssuesOnRemovedComponentsMigrationStepTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/RequirementMeasuresMigrationStepTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigrationStepTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/ChangeLogMigrationTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/ConvertProfileMeasuresMigrationTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/FeedQProfileKeysMigrationTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/IssueActionPlanKeyMigrationTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/MeasureDataMigrationTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v45/AddMissingRuleParameterDefaultValuesMigrationTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v45/DeleteMeasuresOnDeletedProfilesMigrationTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedFileSourcesTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedIssueLongDatesTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/InsertProjectsAuthorizationUpdatedAtMigrationTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/RemoveSortFieldFromIssueFiltersMigrationTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddIssuesColumnsTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/CopyScmAccountsFromAuthorsToUsersTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedAnalysisReportsLongDatesTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedEventsLongDatesTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedFileSourcesBinaryDataTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDatesTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssueComponentUuidsTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssueTagsTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssuesLongDatesTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedManualMeasuresLongDatesTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSemaphoresLongDatesTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDatesTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedUsersLongDatesTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/RemovePermissionsOnModulesMigrationTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/RenameComponentRelatedParamsInIssueFiltersMigrationTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/UpdateProjectsModuleUuidPathTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/AddManualMeasuresComponentUuidColumnTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedFileSourcesDataTypeTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedManualMeasuresComponentUuidTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedMetricsBooleansTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociationTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/RemoveComponentLibrariesTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/RemoveSnapshotLibrariesTest.java
server/sonar-server/src/test/java/org/sonar/server/duplication/ws/DuplicationsWsTest.java
server/sonar-server/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java
server/sonar-server/src/test/java/org/sonar/server/event/db/EventDaoTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/issue/ActionServiceTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueTesting.java
server/sonar-server/src/test/java/org/sonar/server/issue/RulesAggregationTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueStorageTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/actionplan/ActionPlanServiceTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/db/IssueDaoTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/persistence/MeasureDaoTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/GhostsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/ProvisionedActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleBackendMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileServiceMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/RuleBackendMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/RuleCreatorMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/RuleDeleterMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/RuleServiceMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/RuleTesting.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/source/SourceServiceTest.java
server/sonar-server/src/test/java/org/sonar/server/source/db/FileSourceDaoTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/source/index/SourceLineResultSetIteratorTest.java
server/sonar-server/src/test/java/org/sonar/server/source/ws/HashActionTest.java
server/sonar-server/src/test/java/org/sonar/server/startup/RenameIssueWidgetsTest.java
server/sonar-server/src/test/java/org/sonar/server/test/CoverageServiceTest.java
server/sonar-server/src/test/java/org/sonar/server/test/index/TestResultSetIteratorTest.java
server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java
server/sonar-server/src/test/java/org/sonar/server/user/db/UserGroupDaoTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/GroupsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/AddUserActionTest.java
server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/RemoveUserActionTest.java
server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UpdateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UsersActionTest.java
server/sonar-server/src/test/java/org/sonar/server/util/ProgressLoggerTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/util/SlugTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java
server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentIndexDaoTest/select_project_ids_from_query_and_view_or_sub_view_uuid.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/delete.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/empty.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/insert-result.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/shared.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/update-result.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/update.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/empty.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/insert-result.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/modules.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/select_previous_version_snapshots.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/select_snapshots_by_query.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/shared.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/snapshots.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/any-analysis-reports.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/book_available_report_analysis_while_having_one_working_on_another_project.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/empty.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/one_analysis_report.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/pop_null_if_no_pending_reports.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/pop_oldest_pending.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/select.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/three_analysis_reports.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/truncate-result.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/update-all-to-status-pending-result.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/update-all-to-status-pending.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/zip.zip [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/dashboard/db/WidgetDaoTest/before.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/db/ResultSetIteratorTest/feed.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/db/ResultSetIteratorTest/schema.sql [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/delete.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/empty.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/insert-result.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/shared.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/empty.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/insert-result.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/past_measures.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/past_measures_with_characteristic_id.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/past_measures_with_person_id.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/past_measures_with_rule_id.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/shared.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/insert-result.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/no_line_hashes_when_only_test_data.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/shared.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/update-result.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/update_date_when_updated_date_is_zero-result.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/update_date_when_updated_date_is_zero.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/user/db/UserGroupDaoTest/delete_members_by_group_id-result.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/user/db/UserGroupDaoTest/delete_members_by_group_id.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/user/db/UserGroupDaoTest/insert-result.xml [deleted file]
sonar-core/src/main/java/org/sonar/core/util/ProgressLogger.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/util/Slug.java [new file with mode: 0644]
sonar-core/src/test/java/org/sonar/core/util/ProgressLoggerTest.java [new file with mode: 0644]
sonar-core/src/test/java/org/sonar/core/util/SlugTest.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/batch/index/ResourceCopy.java [deleted file]
sonar-db/src/main/java/org/sonar/core/issue/db/package-info.java [deleted file]
sonar-db/src/main/java/org/sonar/core/timemachine/Periods.java
sonar-db/src/main/java/org/sonar/db/AbstractDao.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/DaoUtils.java
sonar-db/src/main/java/org/sonar/db/DatabaseChecker.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/DatabaseUtils.java
sonar-db/src/main/java/org/sonar/db/DbClient2.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/DefaultDatabase.java
sonar-db/src/main/java/org/sonar/db/MyBatis.java
sonar-db/src/main/java/org/sonar/db/ResultSetIterator.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/activity/ActivityDao.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/component/ComponentIndexMapper.java [deleted file]
sonar-db/src/main/java/org/sonar/db/component/ComponentLinkDao.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/component/ResourceDao.java
sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerDao.java
sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerMapper.java
sonar-db/src/main/java/org/sonar/db/component/ResourceKeyUpdaterDao.java
sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/compute/AnalysisReportDao.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/dashboard/ActiveDashboardDao.java
sonar-db/src/main/java/org/sonar/db/dashboard/DashboardDao.java
sonar-db/src/main/java/org/sonar/db/dashboard/WidgetDao.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/dashboard/WidgetPropertyDao.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/duplication/DuplicationDao.java
sonar-db/src/main/java/org/sonar/db/event/EventDao.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/issue/ActionPlanDao.java
sonar-db/src/main/java/org/sonar/db/issue/ActionPlanStatsDao.java
sonar-db/src/main/java/org/sonar/db/issue/IssueDao.java
sonar-db/src/main/java/org/sonar/db/issue/IssueFilterFavouriteDao.java
sonar-db/src/main/java/org/sonar/db/measure/MeasureDao.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterDao.java
sonar-db/src/main/java/org/sonar/db/notification/NotificationQueueDao.java
sonar-db/src/main/java/org/sonar/db/permission/PermissionDao.java
sonar-db/src/main/java/org/sonar/db/property/PropertiesDao.java
sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java
sonar-db/src/main/java/org/sonar/db/purge/period/DefaultPeriodCleaner.java
sonar-db/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java [deleted file]
sonar-db/src/main/java/org/sonar/db/rule/RuleDao.java
sonar-db/src/main/java/org/sonar/db/semaphore/SemaphoreDao.java
sonar-db/src/main/java/org/sonar/db/source/FileSourceDao.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/user/AuthorDao.java
sonar-db/src/main/java/org/sonar/db/user/AuthorizationDao.java
sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDao.java
sonar-db/src/main/java/org/sonar/db/user/UserGroupDao.java [new file with mode: 0644]
sonar-db/src/main/resources/org/sonar/db/component/ComponentIndexMapper.xml [deleted file]
sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexerMapper.xml
sonar-db/src/test/java/org/sonar/db/DaoUtilsTest.java
sonar-db/src/test/java/org/sonar/db/DatabaseCheckerTest.java [new file with mode: 0644]
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/MyBatisTest.java
sonar-db/src/test/java/org/sonar/db/ResultSetIteratorTest.java [new file with mode: 0644]
sonar-db/src/test/java/org/sonar/db/TestDb.java [new file with mode: 0644]
sonar-db/src/test/java/org/sonar/db/activity/ActivityDaoTest.java [new file with mode: 0644]
sonar-db/src/test/java/org/sonar/db/component/ComponentLinkDaoTest.java [new file with mode: 0644]
sonar-db/src/test/java/org/sonar/db/component/ResourceIndexerDaoTest.java
sonar-db/src/test/java/org/sonar/db/component/SnapshotDaoTest.java [new file with mode: 0644]
sonar-db/src/test/java/org/sonar/db/compute/AnalysisReportDaoTest.java [new file with mode: 0644]
sonar-db/src/test/java/org/sonar/db/dashboard/WidgetDaoTest.java [new file with mode: 0644]
sonar-db/src/test/java/org/sonar/db/event/EventDaoTest.java [new file with mode: 0644]
sonar-db/src/test/java/org/sonar/db/issue/ActionPlanStatsDaoTest.java
sonar-db/src/test/java/org/sonar/db/issue/IssueDaoTest.java
sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java [new file with mode: 0644]
sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
sonar-db/src/test/java/org/sonar/db/purge/period/DefaultPeriodCleanerTest.java
sonar-db/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java [deleted file]
sonar-db/src/test/java/org/sonar/db/rule/RuleTesting.java [new file with mode: 0644]
sonar-db/src/test/java/org/sonar/db/source/FileSourceDaoTest.java [new file with mode: 0644]
sonar-db/src/test/java/org/sonar/db/user/UserGroupDaoTest.java [new file with mode: 0644]
sonar-db/src/test/java/org/sonar/jpa/test/AbstractDbUnitTestCase.java [deleted file]
sonar-db/src/test/resources/org/sonar/api/database/configuration/DatabaseConfigurationTest/some-properties.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/ResultSetIteratorTest/feed.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/ResultSetIteratorTest/schema.sql [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/delete.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/empty.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/insert-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/shared.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/update-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/update.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 [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/empty.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/insert-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/modules.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/select_previous_version_snapshots.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/select_snapshots_by_query.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/shared.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/snapshots.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/any-analysis-reports.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/book_available_report_analysis_while_having_one_working_on_another_project.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/empty.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/insert-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/one_analysis_report.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/pop_null_if_no_pending_reports.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/pop_oldest_pending.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/select.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/three_analysis_reports.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/truncate-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/update-all-to-status-pending-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/update-all-to-status-pending.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/zip.zip [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/dashboard/WidgetDaoTest/before.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/event/EventDaoTest/delete.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/event/EventDaoTest/empty.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/event/EventDaoTest/insert-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/event/EventDaoTest/shared.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/find_by_action_plan.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/get_by_key.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/insert-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/update-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/update.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/empty.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/insert-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_characteristic_id.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_person_id.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_rule_id.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/shared.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_from_profile-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_from_rule-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_parameter-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_parameters-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_parameters_from_profile_id-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_parameters_from_profile_id.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/empty.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/insert-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/insert_parameter-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/shared.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/update-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/update_parameter-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/insert-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/no_line_hashes_when_only_test_data.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/shared.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update_date_when_updated_date_is_zero-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update_date_when_updated_date_is_zero.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/user/UserGroupDaoTest/delete_members_by_group_id-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/user/UserGroupDaoTest/delete_members_by_group_id.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/user/UserGroupDaoTest/insert-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/jpa/dao/ProfilesDaoTest/shouldGetProfiles.xml [deleted file]

index d520fba19e070f55e4898803e2609839ec47190f..f9ecc562ee9bbc496d95447492c9a48421247447 100644 (file)
@@ -43,7 +43,7 @@ import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.component.DumbComponent;
 import org.sonar.server.computation.step.PersistFileSourcesStep;
 import org.sonar.server.db.DbClient;
-import org.sonar.server.source.db.FileSourceDao;
+import org.sonar.db.source.FileSourceDao;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
index 1bef6b936d86b4e0b00d4889c3739d83197a5b89..9fd6dceb0cc5f3e5f39643f5d3bb2d7737332cb4 100644 (file)
  */
 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;
 import org.apache.commons.dbutils.DbUtils;
 import org.apache.commons.io.IOUtils;
 import org.junit.Rule;
@@ -27,20 +32,13 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 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.FileSourceDao;
 import org.sonar.server.source.db.FileSourceDb;
 import org.sonar.server.source.index.FileSourcesUpdaterHelper;
 import org.sonar.server.source.index.SourceLineResultSetIterator;
 
-import java.io.IOException;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.Arrays;
-import java.util.Timer;
-import java.util.concurrent.atomic.AtomicLong;
-
 import static org.assertj.core.api.Assertions.assertThat;
 
 public class SourceDbBenchmarkTest {
@@ -63,7 +61,7 @@ public class SourceDbBenchmarkTest {
     scrollRows();
   }
 
-  private void scrollRows() throws SQLException {
+  private void scrollRows() throws Exception {
     LOGGER.info("Scroll table FILE_SOURCES");
     DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis());
     Connection connection = dbTester.openConnection();
index b8dc2920284c1251238fcc0c77f90b7706c45799..0c756dcf18e09967920b858d21b82bbaa63e73f9 100644 (file)
@@ -28,13 +28,13 @@ import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.TimeUtils;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
-import org.sonar.db.purge.period.DefaultPeriodCleaner;
 import org.sonar.db.DbSession;
 import org.sonar.db.purge.IdUuidPair;
 import org.sonar.db.purge.PurgeConfiguration;
 import org.sonar.db.purge.PurgeDao;
 import org.sonar.db.purge.PurgeListener;
 import org.sonar.db.purge.PurgeProfiler;
+import org.sonar.db.purge.period.DefaultPeriodCleaner;
 import org.sonar.server.issue.index.IssueIndex;
 
 import static org.sonar.db.purge.PurgeConfiguration.newDefaultPurgeConfiguration;
@@ -100,7 +100,7 @@ public class ProjectCleaner {
 
   private void doPurge(DbSession session, PurgeConfiguration configuration) {
     try {
-      purgeDao.purge(session, configuration, purgeListener);
+      purgeDao.purge(session, configuration, purgeListener, profiler);
     } catch (Exception e) {
       // purge errors must no fail the report analysis
       LOG.error("Fail to purge data [id=" + configuration.rootProjectIdUuid().getId() + "]", e);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/activity/db/ActivityDao.java b/server/sonar-server/src/main/java/org/sonar/server/activity/db/ActivityDao.java
deleted file mode 100644 (file)
index c2043ce..0000000
+++ /dev/null
@@ -1,58 +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.activity.db;
-
-import org.sonar.api.server.ServerSide;
-import org.sonar.api.utils.System2;
-import org.sonar.db.activity.ActivityDto;
-import org.sonar.db.activity.ActivityMapper;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
-
-import java.util.Date;
-
-@ServerSide
-public class ActivityDao implements Dao {
-
-  private final MyBatis mybatis;
-  private final System2 system;
-
-  public ActivityDao(MyBatis mybatis, System2 system) {
-    this.mybatis = mybatis;
-    this.system = system;
-  }
-
-  public void insert(ActivityDto dto) {
-    DbSession session = mybatis.openSession(false);
-    try {
-      insert(session, dto);
-      session.commit();
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public void insert(DbSession session, ActivityDto dto) {
-    dto.setCreatedAt(new Date(system.now()));
-    session.getMapper(ActivityMapper.class).insert(dto);
-  }
-
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/activity/db/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/activity/db/package-info.java
deleted file mode 100644 (file)
index 302c555..0000000
+++ /dev/null
@@ -1,23 +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.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.server.activity.db;
-
-import javax.annotation.ParametersAreNonnullByDefault;
index df6fbf59c8a609b251658bce19fd8b67a1fbd9af..afef3531195013b5559728a08a6456f408fcbaa0 100644 (file)
@@ -24,7 +24,7 @@ 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.server.db.ResultSetIterator;
+import org.sonar.db.ResultSetIterator;
 import org.sonar.server.es.EsUtils;
 import org.sonar.server.util.DateCollector;
 
index b318762647f64f76abf5718a14132e4402d58ef5..44550420d40c3d4d07d9be5c697ae26b7536a4c9 100644 (file)
 
 package org.sonar.server.component;
 
-import org.sonar.api.server.ServerSide;
+import java.util.List;
 import org.sonar.api.resources.ResourceType;
 import org.sonar.api.resources.ResourceTypes;
 import org.sonar.api.resources.Scopes;
-import org.sonar.db.component.ComponentDto;
+import org.sonar.api.server.ServerSide;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
+import org.sonar.db.component.ComponentDto;
 import org.sonar.db.purge.IdUuidPair;
+import org.sonar.db.purge.PurgeProfiler;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 import org.sonar.server.issue.index.IssueIndexer;
 import org.sonar.server.source.index.SourceLineIndexer;
 import org.sonar.server.test.index.TestIndexer;
 
-import java.util.List;
-
 @ServerSide
 public class ComponentCleanerService {
 
@@ -76,7 +76,7 @@ public class ComponentCleanerService {
     if (hasNotProjectScope(project) || isNotDeletable(project)) {
       throw new IllegalArgumentException("Only projects can be deleted");
     }
-    dbClient.purgeDao().deleteResourceTree(dbSession, new IdUuidPair(project.getId(), project.uuid()));
+    dbClient.purgeDao().deleteResourceTree(dbSession, new IdUuidPair(project.getId(), project.uuid()), new PurgeProfiler());
     dbSession.commit();
 
     deleteFromIndices(project.uuid());
index 85d7feccbc1cb78f6e0063f3f12caeb4f85927b5..b0aa30c56a2db61d535b660682068739a6a27e08 100644 (file)
@@ -32,13 +32,14 @@ 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.component.ComponentDto;
-import org.sonar.db.component.FilePathWithHashDto;
-import org.sonar.db.component.UuidWithProjectUuidDto;
-import org.sonar.db.component.ComponentMapper;
 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;
+import org.sonar.db.component.ComponentMapper;
+import org.sonar.db.component.FilePathWithHashDto;
+import org.sonar.db.component.UuidWithProjectUuidDto;
 import org.sonar.server.es.SearchOptions;
 import org.sonar.server.exceptions.NotFoundException;
 
@@ -50,16 +51,16 @@ import static com.google.common.collect.Maps.newHashMapWithExpectedSize;
 @ServerSide
 public class ComponentDao implements Dao {
 
-  public ComponentDto selectById(Long id, DbSession session) {
+  public ComponentDto selectById(long id, DbSession session) {
     ComponentDto componentDto = selectNullableById(id, session);
     if (componentDto == null) {
-      throw new NotFoundException(String.format("Project with id '%s' not found", id));
+      throw new IllegalArgumentException(String.format("Component id does not exist: %d", id));
     }
     return componentDto;
   }
 
   @CheckForNull
-  public ComponentDto selectNullableById(Long id, DbSession session) {
+  public ComponentDto selectNullableById(long id, DbSession session) {
     return mapper(session).selectById(id);
   }
 
@@ -104,7 +105,7 @@ public class ComponentDao implements Dao {
   }
 
   public List<ComponentDto> selectByIds(final DbSession session, Collection<Long> ids) {
-    return DaoUtils.executeLargeInputs(ids, new Function<List<Long>, List<ComponentDto>>() {
+    return DatabaseUtils.executeLargeInputs(ids, new Function<List<Long>, List<ComponentDto>>() {
       @Override
       public List<ComponentDto> apply(List<Long> partition) {
         return mapper(session).selectByIds(partition);
@@ -113,7 +114,7 @@ public class ComponentDao implements Dao {
   }
 
   public List<ComponentDto> selectByUuids(final DbSession session, Collection<String> uuids) {
-    return DaoUtils.executeLargeInputs(uuids, new Function<List<String>, List<ComponentDto>>() {
+    return DatabaseUtils.executeLargeInputs(uuids, new Function<List<String>, List<ComponentDto>>() {
       @Override
       public List<ComponentDto> apply(List<String> partition) {
         return mapper(session).selectByUuids(partition);
@@ -122,7 +123,7 @@ public class ComponentDao implements Dao {
   }
 
   public List<String> selectExistingUuids(final DbSession session, Collection<String> uuids) {
-    return DaoUtils.executeLargeInputs(uuids, new Function<List<String>, List<String>>() {
+    return DatabaseUtils.executeLargeInputs(uuids, new Function<List<String>, List<String>>() {
       @Override
       public List<String> apply(List<String> partition) {
         return mapper(session).selectExistingUuids(partition);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentIndexDao.java b/server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentIndexDao.java
deleted file mode 100644 (file)
index 0ec4e5f..0000000
+++ /dev/null
@@ -1,37 +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.component.db;
-
-import org.sonar.api.server.ServerSide;
-import org.sonar.db.component.ComponentIndexMapper;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-
-import java.util.List;
-
-@ServerSide
-public class ComponentIndexDao implements Dao {
-
-  public List<Long> selectProjectIdsFromQueryAndViewOrSubViewUuid(DbSession session, String query, String viewOrSubViewUuid) {
-    return session.getMapper(ComponentIndexMapper.class).selectProjectIdsFromQueryAndViewOrSubViewUuid(query + "%", "%." + viewOrSubViewUuid + ".%");
-  }
-
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentLinkDao.java b/server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentLinkDao.java
deleted file mode 100644 (file)
index 18662e8..0000000
+++ /dev/null
@@ -1,50 +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.component.db;
-
-import org.sonar.api.server.ServerSide;
-import org.sonar.db.component.ComponentLinkDto;
-import org.sonar.db.component.ComponentLinkMapper;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-
-import java.util.List;
-
-@ServerSide
-public class ComponentLinkDao implements Dao {
-
-  public List<ComponentLinkDto> selectByComponentUuid(DbSession session, String componentUuid) {
-    return session.getMapper(ComponentLinkMapper.class).selectByComponentUuid(componentUuid);
-  }
-
-  public void insert(DbSession session, ComponentLinkDto item) {
-    session.getMapper(ComponentLinkMapper.class).insert(item);
-  }
-
-  public void update(DbSession session, ComponentLinkDto item) {
-    session.getMapper(ComponentLinkMapper.class).update(item);
-  }
-
-  public void delete(DbSession session, long id) {
-    session.getMapper(ComponentLinkMapper.class).delete(id);
-  }
-
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/db/SnapshotDao.java b/server/sonar-server/src/main/java/org/sonar/server/component/db/SnapshotDao.java
deleted file mode 100644 (file)
index 4be141c..0000000
+++ /dev/null
@@ -1,111 +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.component.db;
-
-import com.google.common.base.Strings;
-import com.google.common.collect.Lists;
-import java.util.Collection;
-import java.util.List;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import org.sonar.api.resources.Scopes;
-import org.sonar.db.component.SnapshotDto;
-import org.sonar.db.component.SnapshotMapper;
-import org.sonar.db.component.SnapshotQuery;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-import org.sonar.server.exceptions.NotFoundException;
-
-public class SnapshotDao implements Dao {
-
-  @CheckForNull
-  public SnapshotDto selectNullableById(DbSession session, Long id) {
-    return mapper(session).selectByKey(id);
-  }
-
-  public SnapshotDto selectById(DbSession session, Long key) {
-    SnapshotDto value = selectNullableById(session, key);
-    if (value == null) {
-      throw new NotFoundException(String.format("Key '%s' not found", key));
-    }
-    return value;
-  }
-
-  @CheckForNull
-  public SnapshotDto selectLastSnapshotByComponentId(DbSession session, long componentId) {
-    return mapper(session).selectLastSnapshot(componentId);
-  }
-
-  public List<SnapshotDto> selectSnapshotsByComponentId(DbSession session, long componentId) {
-    return mapper(session).selectSnapshotsByQuery(new SnapshotQuery().setComponentId(componentId));
-  }
-
-  public List<SnapshotDto> selectSnapshotsByQuery(DbSession session, SnapshotQuery query) {
-    return mapper(session).selectSnapshotsByQuery(query);
-  }
-
-  public List<SnapshotDto> selectPreviousVersionSnapshots(DbSession session, long componentId, String lastVersion) {
-    return mapper(session).selectPreviousVersionSnapshots(componentId, lastVersion);
-  }
-
-  public List<SnapshotDto> selectSnapshotAndChildrenOfProjectScope(DbSession session, long snapshotId) {
-    return mapper(session).selectSnapshotAndChildrenOfScope(snapshotId, Scopes.PROJECT);
-  }
-
-  public int updateSnapshotAndChildrenLastFlagAndStatus(DbSession session, SnapshotDto snapshot, boolean isLast, String status) {
-    Long rootId = snapshot.getId();
-    String path = Strings.nullToEmpty(snapshot.getPath()) + snapshot.getId() + ".%";
-    Long pathRootId = snapshot.getRootIdOrSelf();
-
-    return mapper(session).updateSnapshotAndChildrenLastFlagAndStatus(rootId, pathRootId, path, isLast, status);
-  }
-
-  public int updateSnapshotAndChildrenLastFlag(DbSession session, SnapshotDto snapshot, boolean isLast) {
-    Long rootId = snapshot.getId();
-    String path = Strings.nullToEmpty(snapshot.getPath()) + snapshot.getId() + ".%";
-    Long pathRootId = snapshot.getRootIdOrSelf();
-
-    return mapper(session).updateSnapshotAndChildrenLastFlag(rootId, pathRootId, path, isLast);
-  }
-
-  public static boolean isLast(SnapshotDto snapshotTested, @Nullable SnapshotDto previousLastSnapshot) {
-    return previousLastSnapshot == null || previousLastSnapshot.getCreatedAt() < snapshotTested.getCreatedAt();
-  }
-
-  public SnapshotDto insert(DbSession session, SnapshotDto item) {
-    mapper(session).insert(item);
-    return item;
-  }
-
-  public void insert(DbSession session, Collection<SnapshotDto> items) {
-    for (SnapshotDto item : items) {
-      insert(session, item);
-    }
-  }
-
-  public void insert(DbSession session, SnapshotDto item, SnapshotDto... others) {
-    insert(session, Lists.asList(item, others));
-  }
-
-  private SnapshotMapper mapper(DbSession session) {
-    return session.getMapper(SnapshotMapper.class);
-  }
-}
index cb08dcf7b243386fbc7f442d82b8215bcc6951a6..b644aa490bbf51785edec985f23ab94efe2564bd 100644 (file)
@@ -34,7 +34,7 @@ import org.sonar.db.compute.AnalysisReportDto;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
 import org.sonar.process.ProcessProperties;
-import org.sonar.server.computation.db.AnalysisReportDao;
+import org.sonar.db.compute.AnalysisReportDao;
 import org.sonar.server.db.DbClient;
 
 import static org.sonar.db.compute.AnalysisReportDto.Status.PENDING;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/db/AnalysisReportDao.java b/server/sonar-server/src/main/java/org/sonar/server/computation/db/AnalysisReportDao.java
deleted file mode 100644 (file)
index 6bb7237..0000000
+++ /dev/null
@@ -1,107 +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.computation.db;
-
-import com.google.common.annotations.VisibleForTesting;
-import org.sonar.api.utils.System2;
-import org.sonar.db.compute.AnalysisReportDto;
-import org.sonar.db.compute.AnalysisReportMapper;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-
-import javax.annotation.CheckForNull;
-
-import java.util.List;
-
-import static org.sonar.db.compute.AnalysisReportDto.Status.PENDING;
-import static org.sonar.db.compute.AnalysisReportDto.Status.WORKING;
-
-public class AnalysisReportDao implements Dao {
-
-  private System2 system2;
-
-  public AnalysisReportDao(System2 system2) {
-    this.system2 = system2;
-  }
-
-  /**
-   * Update all rows with: STATUS='PENDING', STARTED_AT=NULL, UPDATED_AT={now}
-   */
-  public void resetAllToPendingStatus(DbSession session) {
-    mapper(session).resetAllToPendingStatus(system2.now());
-  }
-
-  public void truncate(DbSession session) {
-    mapper(session).truncate();
-  }
-
-  public List<AnalysisReportDto> selectByProjectKey(DbSession session, String projectKey) {
-    return mapper(session).selectByProjectKey(projectKey);
-  }
-
-  @VisibleForTesting
-  AnalysisReportDto selectById(DbSession session, long id) {
-    return mapper(session).selectById(id);
-  }
-
-  @CheckForNull
-  public AnalysisReportDto pop(DbSession session) {
-    List<Long> reportIds = mapper(session).selectAvailables(PENDING, WORKING);
-    if (reportIds.isEmpty()) {
-      return null;
-    }
-
-    long reportId = reportIds.get(0);
-    return tryToPop(session, reportId);
-  }
-
-  @VisibleForTesting
-  AnalysisReportDto tryToPop(DbSession session, long reportId) {
-    AnalysisReportMapper mapper = mapper(session);
-    int nbOfReportBooked = mapper.updateWithBookingReport(reportId, system2.now(), PENDING, WORKING);
-    if (nbOfReportBooked == 0) {
-      return null;
-    }
-
-    AnalysisReportDto result = mapper.selectById(reportId);
-    session.commit();
-    return result;
-  }
-
-  public List<AnalysisReportDto> selectAll(DbSession session) {
-    return mapper(session).selectAll();
-  }
-
-  public AnalysisReportDto insert(DbSession session, AnalysisReportDto report) {
-    report.setCreatedAt(system2.now());
-    report.setUpdatedAt(system2.now());
-    mapper(session).insert(report);
-    return report;
-  }
-
-  public void delete(DbSession session, long id) {
-    mapper(session).delete(id);
-  }
-
-  private AnalysisReportMapper mapper(DbSession session) {
-    return session.getMapper(AnalysisReportMapper.class);
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/db/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/computation/db/package-info.java
deleted file mode 100644 (file)
index d34d492..0000000
+++ /dev/null
@@ -1,24 +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.
- */
-
-@ParametersAreNonnullByDefault
-package org.sonar.server.computation.db;
-
-import javax.annotation.ParametersAreNonnullByDefault;
index 659577bb868fa54235ece6250dfd7ccc77095486..6e74b092366e2aaa500a634063686dbb1bc479a2 100644 (file)
@@ -24,13 +24,13 @@ import java.util.List;
 import org.sonar.db.component.SnapshotDto;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
-import org.sonar.server.component.db.SnapshotDao;
+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 static org.sonar.server.component.db.SnapshotDao.isLast;
+import static org.sonar.db.component.SnapshotDao.isLast;
 
 public class SwitchSnapshotStep implements ComputationStep {
 
diff --git a/server/sonar-server/src/main/java/org/sonar/server/dashboard/db/DashboardDao.java b/server/sonar-server/src/main/java/org/sonar/server/dashboard/db/DashboardDao.java
deleted file mode 100644 (file)
index 760d276..0000000
+++ /dev/null
@@ -1,49 +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.dashboard.db;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import org.sonar.db.dashboard.DashboardDto;
-import org.sonar.db.dashboard.DashboardMapper;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-
-public class DashboardDao implements Dao {
-
-  @CheckForNull
-  public DashboardDto getNullableByKey(DbSession session, Long key) {
-    return mapper(session).selectById(key);
-  }
-
-  /**
-   * Get dashboard if allowed : shared or owned by logged-in user
-   * @param userId id of logged-in user, null if anonymous
-   */
-  @CheckForNull
-  public DashboardDto getAllowedByKey(DbSession session, Long key, @Nullable Long userId) {
-    return mapper(session).selectAllowedById(key, userId != null ? userId : -1L);
-  }
-
-  private DashboardMapper mapper(DbSession session) {
-    return session.getMapper(DashboardMapper.class);
-  }
-
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/dashboard/db/WidgetDao.java b/server/sonar-server/src/main/java/org/sonar/server/dashboard/db/WidgetDao.java
deleted file mode 100644 (file)
index b44bb15..0000000
+++ /dev/null
@@ -1,76 +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.dashboard.db;
-
-import java.util.Collection;
-import org.sonar.db.dashboard.WidgetDto;
-import org.sonar.db.dashboard.WidgetMapper;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
-
-public class WidgetDao implements Dao {
-
-  private MyBatis myBatis;
-
-  public WidgetDao(MyBatis myBatis) {
-    this.myBatis = myBatis;
-  }
-
-  public WidgetDto getNullableByKey(Long widgetId) {
-    DbSession session = myBatis.openSession(false);
-    try {
-      return getNullableByKey(session, widgetId);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public WidgetDto getNullableByKey(DbSession session, Long widgetId) {
-    return mapper(session).selectById(widgetId);
-  }
-
-  public WidgetDto update(WidgetDto item) {
-    DbSession session = myBatis.openSession(false);
-    try {
-      return update(session, item);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public WidgetDto update(DbSession session, WidgetDto item) {
-    mapper(session).update(item);
-    return item;
-  }
-
-  public Collection<WidgetDto> findByDashboard(DbSession session, long dashboardKey) {
-    return mapper(session).selectByDashboard(dashboardKey);
-  }
-
-  public Collection<WidgetDto> findAll(DbSession session) {
-    return mapper(session).selectAll();
-  }
-
-  private WidgetMapper mapper(DbSession session) {
-    return session.getMapper(WidgetMapper.class);
-  }
-
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/dashboard/db/WidgetPropertyDao.java b/server/sonar-server/src/main/java/org/sonar/server/dashboard/db/WidgetPropertyDao.java
deleted file mode 100644 (file)
index 5aad93e..0000000
+++ /dev/null
@@ -1,91 +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.dashboard.db;
-
-import com.google.common.base.Function;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import org.sonar.db.dashboard.WidgetPropertyDto;
-import org.sonar.db.dashboard.WidgetPropertyMapper;
-import org.sonar.db.Dao;
-import org.sonar.db.DaoUtils;
-import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
-
-public class WidgetPropertyDao implements Dao {
-
-  private final MyBatis myBatis;
-
-  public WidgetPropertyDao(MyBatis myBatis) {
-    this.myBatis = myBatis;
-  }
-
-  public WidgetPropertyDto insert(WidgetPropertyDto item) {
-    DbSession session = myBatis.openSession(false);
-    try {
-      return insert(session, item);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public WidgetPropertyDto insert(DbSession session, WidgetPropertyDto item) {
-    mapper(session).insert(item);
-    return item;
-  }
-
-  public void insert(DbSession session, Collection<WidgetPropertyDto> items) {
-    for (WidgetPropertyDto item : items) {
-      insert(session, item);
-    }
-  }
-
-  public WidgetPropertyDto getNullableByKey(Long propertyId) {
-    DbSession session = myBatis.openSession(false);
-    try {
-      return getNullableByKey(session, propertyId);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public WidgetPropertyDto getNullableByKey(DbSession session, Long propertyId) {
-    return mapper(session).selectById(propertyId);
-  }
-
-  public Collection<WidgetPropertyDto> findByDashboard(DbSession session, long dashboardKey) {
-    return mapper(session).selectByDashboard(dashboardKey);
-  }
-
-  public void deleteByWidgetIds(final DbSession session, List<Long> widgetIdsWithPropertiesToDelete) {
-    DaoUtils.executeLargeInputs(widgetIdsWithPropertiesToDelete, new Function<List<Long>, List<Void>>() {
-      @Override
-      public List<Void> apply(List<Long> input) {
-        mapper(session).deleteByWidgetIds(input);
-        return Arrays.asList();
-      }
-    });
-  }
-
-  private WidgetPropertyMapper mapper(DbSession session) {
-    return session.getMapper(WidgetPropertyMapper.class);
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/dashboard/db/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/dashboard/db/package-info.java
deleted file mode 100644 (file)
index ab56ded..0000000
+++ /dev/null
@@ -1,24 +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.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.server.dashboard.db;
-
-import javax.annotation.ParametersAreNonnullByDefault;
-
index df21adcba652b9e9ce21acb2f86ff7ef52863fd5..80c2173af2c6bfb36646a78ef1eb0364c0a7c62d 100644 (file)
  */
 package org.sonar.server.db;
 
-import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import java.io.Serializable;
 import java.sql.Timestamp;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
-import java.util.List;
 import java.util.Map;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
@@ -49,7 +46,6 @@ import org.sonar.server.search.action.RefreshIndex;
 import org.sonar.server.search.action.UpsertDto;
 import org.sonar.server.search.action.UpsertNestedItem;
 
-import static com.google.common.collect.Lists.newArrayList;
 import static com.google.common.collect.Maps.newHashMap;
 
 /**
@@ -120,7 +116,7 @@ import static com.google.common.collect.Maps.newHashMap;
  * @param <DTO> Produced DTO class from this dao
  * @param <KEY> DTO Key class
  */
-public abstract class BaseDao<MAPPER, DTO extends Dto<KEY>, KEY extends Serializable> implements DeprecatedDao<DTO,KEY>, Dao {
+public abstract class BaseDao<MAPPER, DTO extends Dto<KEY>, KEY extends Serializable> implements DeprecatedDao<DTO, KEY>, Dao {
 
   private static final Logger LOGGER = Loggers.get(BaseDao.class);
 
@@ -138,10 +134,6 @@ public abstract class BaseDao<MAPPER, DTO extends Dto<KEY>, KEY extends Serializ
     this.system2 = system2;
   }
 
-  protected BaseDao(Class<MAPPER> mapperClass, System2 system2) {
-    this(null, mapperClass, system2);
-  }
-
   public String getIndexType() {
     return indexDefinition != null ? this.indexDefinition.getIndexType() : null;
   }
@@ -165,27 +157,6 @@ public abstract class BaseDao<MAPPER, DTO extends Dto<KEY>, KEY extends Serializ
     return value;
   }
 
-  public List<DTO> getByKeys(DbSession session, KEY... keys) {
-    return getByKeys(session, ImmutableList.<KEY>copyOf(keys));
-  }
-
-  public List<DTO> getByKeys(DbSession session, Collection<KEY> keys) {
-    if (keys.isEmpty()) {
-      return Collections.emptyList();
-    }
-    List<DTO> components = newArrayList();
-    List<List<KEY>> partitionList = Lists.partition(newArrayList(keys), 1000);
-    for (List<KEY> partition : partitionList) {
-      List<DTO> dtos = doGetByKeys(session, partition);
-      components.addAll(dtos);
-    }
-    return components;
-  }
-
-  protected List<DTO> doGetByKeys(DbSession session, Collection<KEY> keys) {
-    throw notImplemented(this);
-  }
-
   @Override
   public DTO update(DbSession session, DTO item) {
     Date now = new Date(system2.now());
@@ -195,7 +166,7 @@ public abstract class BaseDao<MAPPER, DTO extends Dto<KEY>, KEY extends Serializ
 
   @Override
   public DTO update(DbSession session, DTO item, DTO... others) {
-    update(session, Lists.<DTO>asList(item, others));
+    update(session, Lists.asList(item, others));
     return item;
   }
 
@@ -307,16 +278,6 @@ public abstract class BaseDao<MAPPER, DTO extends Dto<KEY>, KEY extends Serializ
     }
   }
 
-  @VisibleForTesting
-  public List<DTO> findAfterDate(final DbSession session, Date date, Map<String, String> params) {
-    return session.selectList(getSynchronizeStatementFQN(), getSynchronizationParams(date, params));
-  }
-
-  @VisibleForTesting
-  public List<DTO> findAfterDate(final DbSession session, Date date) {
-    return findAfterDate(session, date, Collections.<String, String>emptyMap());
-  }
-
   // Synchronization methods
 
   protected DbSynchronizationHandler getSynchronizationResultHandler(final DbSession session, Map<String, String> params) {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/DatabaseChecker.java b/server/sonar-server/src/main/java/org/sonar/server/db/DatabaseChecker.java
deleted file mode 100644 (file)
index 61659ff..0000000
+++ /dev/null
@@ -1,90 +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.db;
-
-import com.google.common.base.Throwables;
-import org.apache.commons.dbutils.DbUtils;
-import org.apache.commons.lang.StringUtils;
-import org.picocontainer.Startable;
-import org.sonar.api.server.ServerSide;
-import org.sonar.api.utils.MessageException;
-import org.sonar.api.utils.log.Loggers;
-import org.sonar.db.Database;
-import org.sonar.db.dialect.H2;
-import org.sonar.db.dialect.Oracle;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-
-@ServerSide
-public class DatabaseChecker implements Startable {
-
-  public static final int ORACLE_MIN_MAJOR_VERSION = 11;
-
-  private final Database db;
-
-  public DatabaseChecker(Database db) {
-    this.db = db;
-  }
-
-  @Override
-  public void start() {
-    try {
-      if (H2.ID.equals(db.getDialect().getId())) {
-        Loggers.get(DatabaseChecker.class).warn("H2 database should be used for evaluation purpose only");
-      } else if (Oracle.ID.equals(db.getDialect().getId())) {
-        checkOracleVersion();
-      }
-    } catch (Exception e) {
-      Throwables.propagate(e);
-    }
-  }
-
-  @Override
-  public void stop() {
-    // nothing to do
-  }
-
-  private void checkOracleVersion() throws SQLException {
-    Connection connection = db.getDataSource().getConnection();
-    try {
-      // check version of db
-      // See http://jira.sonarsource.com/browse/SONAR-6434
-      int majorVersion = connection.getMetaData().getDatabaseMajorVersion();
-      if (majorVersion < ORACLE_MIN_MAJOR_VERSION) {
-        throw MessageException.of(String.format(
-          "Unsupported Oracle version: %s. Minimal required version is %d.", connection.getMetaData().getDatabaseProductVersion(), ORACLE_MIN_MAJOR_VERSION));
-      }
-
-      // check version of driver
-      String driverVersion = connection.getMetaData().getDriverVersion();
-      String[] parts = StringUtils.split(driverVersion, ".");
-      int intVersion = Integer.parseInt(parts[0]) * 100 + Integer.parseInt(parts[1]);
-      if (intVersion < 1102) {
-        throw MessageException.of(String.format(
-          "Unsupported Oracle JDBC driver version: %s. Minimal required version is 11.2.", driverVersion));
-      }
-
-    } finally {
-      DbUtils.closeQuietly(connection);
-    }
-  }
-
-}
index 9ff768712310baa4d7c74f731753e8c508df66a6..b89b0aa6d6706e134edd2f4766658f0284d9399d 100644 (file)
@@ -25,51 +25,47 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.IdentityHashMap;
 import java.util.Map;
-import org.sonar.api.server.ServerSide;
-import org.sonar.db.issue.ActionPlanDao;
-import org.sonar.db.issue.IssueChangeDao;
-import org.sonar.db.issue.IssueFilterDao;
-import org.sonar.db.permission.PermissionTemplateDao;
+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.component.ResourceDao;
-import org.sonar.db.debt.CharacteristicDao;
-import org.sonar.db.loadedtemplate.LoadedTemplateDao;
+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.server.activity.db.ActivityDao;
+import org.sonar.db.user.UserGroupDao;
 import org.sonar.server.component.db.ComponentDao;
-import org.sonar.server.component.db.ComponentIndexDao;
-import org.sonar.server.component.db.ComponentLinkDao;
-import org.sonar.server.component.db.SnapshotDao;
-import org.sonar.server.computation.db.AnalysisReportDao;
 import org.sonar.server.measure.custom.persistence.CustomMeasureDao;
-import org.sonar.server.dashboard.db.DashboardDao;
-import org.sonar.server.dashboard.db.WidgetDao;
-import org.sonar.server.dashboard.db.WidgetPropertyDao;
-import org.sonar.server.event.db.EventDao;
-import org.sonar.server.issue.db.IssueDao;
-import org.sonar.server.measure.persistence.MeasureDao;
 import org.sonar.server.metric.persistence.MetricDao;
 import org.sonar.server.qualityprofile.db.ActiveRuleDao;
 import org.sonar.server.rule.db.RuleDao;
-import org.sonar.server.source.db.FileSourceDao;
 import org.sonar.server.user.db.GroupDao;
 import org.sonar.server.user.db.UserDao;
-import org.sonar.server.user.db.UserGroupDao;
 
-/**
- * Facade for all db components, mainly DAOs
- */
-@ServerSide
 public class DbClient {
 
   private final Database db;
@@ -103,7 +99,7 @@ public class DbClient {
   private final WidgetPropertyDao widgetPropertyDao;
   private final FileSourceDao fileSourceDao;
   private final AuthorDao authorDao;
-  private final ComponentIndexDao componentIndexDao;
+  private final ResourceIndexerDao componentIndexDao;
   private final ComponentLinkDao componentLinkDao;
   private final EventDao eventDao;
   private final PurgeDao purgeDao;
@@ -148,7 +144,7 @@ public class DbClient {
     widgetPropertyDao = getDao(map, WidgetPropertyDao.class);
     fileSourceDao = getDao(map, FileSourceDao.class);
     authorDao = getDao(map, AuthorDao.class);
-    componentIndexDao = getDao(map, ComponentIndexDao.class);
+    componentIndexDao = getDao(map, ResourceIndexerDao.class);
     componentLinkDao = getDao(map, ComponentLinkDao.class);
     eventDao = getDao(map, EventDao.class);
     purgeDao = getDao(map, PurgeDao.class);
@@ -163,6 +159,10 @@ public class DbClient {
     return myBatis.openSession(batch);
   }
 
+  public void closeSession(@Nullable DbSession session) {
+    MyBatis.closeQuietly(session);
+  }
+
   public RuleDao ruleDao() {
     return ruleDao;
   }
@@ -283,7 +283,7 @@ public class DbClient {
     return authorDao;
   }
 
-  public ComponentIndexDao componentIndexDao() {
+  public ResourceIndexerDao componentIndexDao() {
     return componentIndexDao;
   }
 
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/ResultSetIterator.java b/server/sonar-server/src/main/java/org/sonar/server/db/ResultSetIterator.java
deleted file mode 100644 (file)
index ec5fa2a..0000000
+++ /dev/null
@@ -1,115 +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.db;
-
-import org.apache.commons.dbutils.DbUtils;
-
-import java.io.Closeable;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-/**
- * Forward-only {@link java.util.Iterator} over a {@link java.sql.ResultSet}. Rows are
- * lazily loaded. The underlying ResultSet must be closed by calling the method
- * {@link #close()}
- * <p/>
- * As a safeguard, the ResultSet is automatically closed after the last element has
- * been retrieved via {@link #next()} or {@link #hasNext()} is called (which will return false).
- * This automagic behavior is not enough to remove explicit calls to {@link #close()}
- * from caller methods. Errors raised before end of traversal must still be handled.
- */
-public abstract class ResultSetIterator<E> implements Iterator<E>, Closeable {
-
-  private final ResultSet rs;
-  private final PreparedStatement stmt;
-
-  private volatile boolean didNext = false;
-  private volatile boolean hasNext = false;
-  private volatile boolean closed = false;
-
-  public ResultSetIterator(PreparedStatement stmt) throws SQLException {
-    this.stmt = stmt;
-    this.rs = stmt.executeQuery();
-  }
-
-  protected ResultSetIterator(ResultSet rs) {
-    this.stmt = null;
-    this.rs = rs;
-  }
-
-  @Override
-  public boolean hasNext() {
-    if (closed) {
-      return false;
-    }
-    if (!didNext) {
-      hasNext = doNextQuietly();
-      if (hasNext) {
-        didNext = true;
-      } else {
-        close();
-      }
-    }
-    return hasNext;
-  }
-
-  @Override
-  public E next() {
-    if (!hasNext()) {
-      close();
-      throw new NoSuchElementException();
-    }
-    try {
-      return read(rs);
-    } catch (SQLException e) {
-      throw new IllegalStateException("Fail to read result set row", e);
-    } finally {
-      hasNext = doNextQuietly();
-      if (!hasNext) {
-        close();
-      }
-    }
-  }
-
-  @Override
-  public void remove() {
-    throw new UnsupportedOperationException();
-  }
-
-  @Override
-  public void close() {
-    closed = true;
-    DbUtils.closeQuietly(rs);
-    DbUtils.closeQuietly(stmt);
-  }
-
-  protected abstract E read(ResultSet rs) throws SQLException;
-
-  private boolean doNextQuietly() {
-    try {
-      return rs.next();
-    } catch (SQLException e) {
-      throw new IllegalStateException("Fail to read row of JDBC result set", e);
-    }
-  }
-}
index 39793966f9ef9c4bdf58b6d4cf26703edf450333..725600feff9a5ce2cd24539bf0b76c303d8c99aa 100644 (file)
@@ -23,7 +23,7 @@ import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.concurrent.atomic.AtomicLong;
 import org.sonar.db.Database;
-import org.sonar.server.util.ProgressLogger;
+import org.sonar.core.util.ProgressLogger;
 
 public class MassUpdate {
 
index 8193233b43ddf5a1f97fa325ab7bf73cfc16a0cb..6d6d82f9e52147205002384b97fad664add33cc0 100644 (file)
@@ -34,7 +34,7 @@ import org.sonar.db.version.v44.Migration44Mapper;
 import org.sonar.db.qualityprofile.ActiveRuleKey;
 import org.sonar.core.rule.SeverityUtil;
 import org.sonar.server.activity.Activity;
-import org.sonar.server.activity.db.ActivityDao;
+import org.sonar.db.activity.ActivityDao;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.db.migrations.MigrationStep;
 import org.sonar.server.qualityprofile.ActiveRuleChange;
index b9dc3245c7fdc08b3eaf29c8d3489e479419734a..cfd0b2532e7b38fdd7320ed057b8caba6fb818a4 100644 (file)
@@ -28,7 +28,7 @@ import org.sonar.server.db.migrations.BaseDataChange;
 import org.sonar.server.db.migrations.MassUpdate;
 import org.sonar.server.db.migrations.Select;
 import org.sonar.server.db.migrations.SqlStatement;
-import org.sonar.server.util.Slug;
+import org.sonar.core.util.Slug;
 
 /**
  * Feed the new columns RULES_PROFILES.KEE and PARENT_KEE.
index 046a8d8d7612c13294d89e7204849783a7d27b93..394c659fc6bbbe9211bab6ca5017507ea6e13670 100644 (file)
@@ -36,7 +36,7 @@ import org.sonar.db.version.v45.Rule;
 import org.sonar.db.version.v45.RuleParameter;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.db.migrations.MigrationStep;
-import org.sonar.server.util.ProgressLogger;
+import org.sonar.core.util.ProgressLogger;
 
 /**
  * See http://jira.sonarsource.com/browse/SONAR-5575
index 441f370a544dfad69520da5642e67077779b2805..63bbbdc43fba111f8f262aa97a24d916bc2699ff 100644 (file)
@@ -33,7 +33,7 @@ import org.sonar.db.version.v50.Component;
 import org.sonar.db.version.v50.Migration50Mapper;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.db.migrations.MigrationStep;
-import org.sonar.server.util.ProgressLogger;
+import org.sonar.core.util.ProgressLogger;
 
 import java.util.List;
 import java.util.Map;
index f5679a9eef32121c4b7a42df5db12268d7fa07bd..751339a6e398a6e211eb1c345c82017334a9aa30 100644 (file)
@@ -34,7 +34,7 @@ import org.sonar.server.db.migrations.BaseDataChange;
 import org.sonar.server.db.migrations.Select;
 import org.sonar.server.db.migrations.Upsert;
 import org.sonar.server.db.migrations.UpsertImpl;
-import org.sonar.server.util.ProgressLogger;
+import org.sonar.core.util.ProgressLogger;
 
 import static com.google.common.collect.Lists.newArrayList;
 
index 87b696a98b469003c12c011e33f76824b60df33d..ac65f661afe279b1a5d48a2b90b8ccc88d3ad6a2 100644 (file)
@@ -36,7 +36,7 @@ import org.sonar.db.MyBatis;
 import org.sonar.server.component.db.ComponentDao;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.measure.persistence.MeasureDao;
+import org.sonar.db.measure.MeasureDao;
 import org.sonar.server.user.UserSession;
 
 import javax.annotation.CheckForNull;
index aaf7c746f405eb3f0213b34016fe69e10f6923c0..56352214b12f9b8f34cbd5578419083cf8113652 100644 (file)
@@ -39,7 +39,7 @@ import org.elasticsearch.search.SearchHit;
 import org.picocontainer.Startable;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
-import org.sonar.server.util.ProgressLogger;
+import org.sonar.core.util.ProgressLogger;
 
 import java.util.Map;
 import java.util.concurrent.Semaphore;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/event/db/EventDao.java b/server/sonar-server/src/main/java/org/sonar/server/event/db/EventDao.java
deleted file mode 100644 (file)
index ede3edb..0000000
+++ /dev/null
@@ -1,46 +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.event.db;
-
-import org.sonar.api.server.ServerSide;
-import org.sonar.db.event.EventDto;
-import org.sonar.db.event.EventMapper;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-
-import java.util.List;
-
-@ServerSide
-public class EventDao implements Dao {
-
-  public List<EventDto> selectByComponentUuid(DbSession session, String componentUuid) {
-    return session.getMapper(EventMapper.class).selectByComponentUuid(componentUuid);
-  }
-
-  public void insert(DbSession session, EventDto dto) {
-    session.getMapper(EventMapper.class).insert(dto);
-  }
-
-  public void delete(DbSession session, Long id) {
-    session.getMapper(EventMapper.class).delete(id);
-  }
-
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/event/db/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/event/db/package-info.java
deleted file mode 100644 (file)
index b0e2602..0000000
+++ /dev/null
@@ -1,24 +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.
- */
-
-@ParametersAreNonnullByDefault
-package org.sonar.server.event.db;
-
-import javax.annotation.ParametersAreNonnullByDefault;
index 81ad2decc9bb8e21db66e09fa05ca0dd26dd9498..5b065874d058e6e4ee704c64337ec2bbaeea9bae 100644 (file)
@@ -29,33 +29,28 @@ import java.util.List;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import org.sonar.api.issue.ActionPlan;
-import org.sonar.core.issue.DefaultIssue;
-import org.sonar.core.issue.IssueChangeContext;
-import org.sonar.api.server.ServerSide;
 import org.sonar.api.web.UserRole;
 import org.sonar.core.issue.ActionPlanStats;
 import org.sonar.core.issue.DefaultActionPlan;
+import org.sonar.core.issue.DefaultIssue;
+import org.sonar.core.issue.IssueChangeContext;
 import org.sonar.core.issue.IssueUpdater;
+import org.sonar.db.DbSession;
+import org.sonar.db.component.ResourceDao;
+import org.sonar.db.component.ResourceDto;
+import org.sonar.db.component.ResourceQuery;
 import org.sonar.db.issue.ActionPlanDao;
 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.issue.IssueStorage;
-import org.sonar.db.DbSession;
-import org.sonar.db.component.ResourceDao;
-import org.sonar.db.component.ResourceDto;
-import org.sonar.db.component.ResourceQuery;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.exceptions.NotFoundException;
+import org.sonar.server.issue.IssueStorage;
 import org.sonar.server.user.UserSession;
 
 import static com.google.common.collect.Lists.newArrayList;
 
-/**
- * @since 3.6
- */
-@ServerSide
 public class ActionPlanService {
 
   private final DbClient dbClient;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/db/IssueDao.java b/server/sonar-server/src/main/java/org/sonar/server/issue/db/IssueDao.java
deleted file mode 100644 (file)
index 3033fc3..0000000
+++ /dev/null
@@ -1,78 +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.issue.db;
-
-import java.util.List;
-import java.util.Set;
-import javax.annotation.CheckForNull;
-import org.sonar.db.issue.IssueDto;
-import org.sonar.db.issue.IssueMapper;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
-import org.sonar.server.exceptions.NotFoundException;
-
-public class IssueDao extends org.sonar.db.issue.IssueDao implements Dao {
-
-  public IssueDao(MyBatis mybatis) {
-    super(mybatis);
-  }
-
-  @CheckForNull
-  public IssueDto selectNullableByKey(DbSession session, String key) {
-    return mapper(session).selectByKey(key);
-  }
-
-  public IssueDto selectByKey(DbSession session, String key) {
-    IssueDto issue = selectNullableByKey(session, key);
-    if (issue == null) {
-      throw new NotFoundException(String.format("Key '%s' not found", key));
-    }
-    return issue;
-  }
-
-  public List<IssueDto> findByActionPlan(DbSession session, String actionPlan) {
-    return mapper(session).selectByActionPlan(actionPlan);
-  }
-
-  public List<IssueDto> selectByKeys(DbSession session, List<String> keys) {
-    return mapper(session).selectByKeys(keys);
-  }
-
-  public Set<String> selectComponentUuidsOfOpenIssuesForProjectUuid(DbSession session, String projectUuid) {
-    return mapper(session).selectComponentUuidsOfOpenIssuesForProjectUuid(projectUuid);
-  }
-
-  public void insert(DbSession session, IssueDto dto) {
-    mapper(session).insert(dto);
-  }
-
-  public void insert(DbSession session, IssueDto dto, IssueDto... others) {
-    IssueMapper mapper = mapper(session);
-    mapper.insert(dto);
-    for (IssueDto other : others) {
-      mapper.insert(other);
-    }
-  }
-
-  public void update(DbSession session, IssueDto dto) {
-    mapper(session).update(dto);
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/db/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/issue/db/package-info.java
deleted file mode 100644 (file)
index 9d25d51..0000000
+++ /dev/null
@@ -1,24 +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.
- */
-
-@ParametersAreNonnullByDefault
-package org.sonar.server.issue.db;
-
-import javax.annotation.ParametersAreNonnullByDefault;
index 76de0d8236321e7cef969ff6811c97aa8828c5ad..6876a2312655359c8e4b82d497769ef8997165db 100644 (file)
@@ -28,7 +28,7 @@ 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.server.db.ResultSetIterator;
+import org.sonar.db.ResultSetIterator;
 import org.sonar.server.db.migrations.SqlUtil;
 
 import javax.annotation.CheckForNull;
index a818880acad136eba0fb643da92a83a70b2499df..90da55fd8b7ebdc9e531d3bf371fc90badcc3146 100644 (file)
@@ -26,6 +26,7 @@ import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import org.apache.ibatis.session.RowBounds;
 import org.sonar.api.server.ServerSide;
+import org.sonar.db.DatabaseUtils;
 import org.sonar.db.measure.CustomMeasureDto;
 import org.sonar.db.measure.CustomMeasureMapper;
 import org.sonar.db.Dao;
@@ -49,7 +50,7 @@ public class CustomMeasureDao implements Dao {
   }
 
   public void deleteByMetricIds(final DbSession session, final List<Integer> metricIds) {
-    DaoUtils.executeLargeInputsWithoutOutput(metricIds, new Function<List<Integer>, Void>() {
+    DatabaseUtils.executeLargeInputsWithoutOutput(metricIds, new Function<List<Integer>, Void>() {
       @Override
       public Void apply(@Nonnull List<Integer> input) {
         mapper(session).deleteByMetricIds(metricIds);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/persistence/MeasureDao.java b/server/sonar-server/src/main/java/org/sonar/server/measure/persistence/MeasureDao.java
deleted file mode 100644 (file)
index 5f0660b..0000000
+++ /dev/null
@@ -1,91 +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.measure.persistence;
-
-import com.google.common.base.Function;
-import com.google.common.collect.Lists;
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-import javax.annotation.CheckForNull;
-import org.sonar.api.server.ServerSide;
-import org.sonar.db.component.SnapshotDto;
-import org.sonar.db.measure.MeasureDto;
-import org.sonar.db.measure.MeasureMapper;
-import org.sonar.db.measure.PastMeasureDto;
-import org.sonar.db.Dao;
-import org.sonar.db.DaoUtils;
-import org.sonar.db.DbSession;
-
-@ServerSide
-public class MeasureDao implements Dao {
-
-  public boolean existsByKey(DbSession session, String componentKey, String metricKey) {
-    return mapper(session).countByComponentAndMetric(componentKey, metricKey) > 0;
-  }
-
-  @CheckForNull
-  public MeasureDto findByComponentKeyAndMetricKey(DbSession session, String componentKey, String metricKey) {
-    return mapper(session).selectByComponentAndMetric(componentKey, metricKey);
-  }
-
-  public List<MeasureDto> findByComponentKeyAndMetricKeys(final DbSession session, final String componentKey, List<String> metricKeys) {
-    return DaoUtils.executeLargeInputs(metricKeys, new Function<List<String>, List<MeasureDto>>() {
-      @Override
-      public List<MeasureDto> apply(List<String> keys) {
-        return mapper(session).selectByComponentAndMetrics(componentKey, keys);
-      }
-    });
-  }
-
-  public List<PastMeasureDto> selectByComponentUuidAndProjectSnapshotIdAndMetricIds(final DbSession session, final String componentUuid, final long projectSnapshotId,
-    Set<Integer> metricIds) {
-    return DaoUtils.executeLargeInputs(metricIds, new Function<List<Integer>, List<PastMeasureDto>>() {
-      @Override
-      public List<PastMeasureDto> apply(List<Integer> ids) {
-        return mapper(session).selectByComponentUuidAndProjectSnapshotIdAndStatusAndMetricIds(componentUuid, projectSnapshotId, ids,
-          SnapshotDto.STATUS_PROCESSED);
-      }
-    });
-  }
-
-  public void insert(DbSession session, MeasureDto measureDto) {
-    mapper(session).insert(measureDto);
-  }
-
-  public void insert(DbSession session, Collection<MeasureDto> items) {
-    for (MeasureDto item : items) {
-      insert(session, item);
-    }
-  }
-
-  public void insert(DbSession session, MeasureDto item, MeasureDto... others) {
-    insert(session, Lists.asList(item, others));
-  }
-
-  public List<String> selectMetricKeysForSnapshot(DbSession session, long snapshotId) {
-    return mapper(session).selectMetricKeysForSnapshot(snapshotId);
-  }
-
-  private MeasureMapper mapper(DbSession session) {
-    return session.getMapper(MeasureMapper.class);
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/persistence/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/measure/persistence/package-info.java
deleted file mode 100644 (file)
index e4c4083..0000000
+++ /dev/null
@@ -1,24 +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.
- */
-
-@ParametersAreNonnullByDefault
-package org.sonar.server.measure.persistence;
-
-import javax.annotation.ParametersAreNonnullByDefault;
index 01340086029b086e579fce3731393ac8002a2140..2fe2cd21c9f07bf438fd332af9b6ceeabaa6af40 100644 (file)
@@ -34,18 +34,17 @@ import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import org.apache.ibatis.session.RowBounds;
-import org.sonar.api.server.ServerSide;
-import org.sonar.db.metric.MetricDto;
-import org.sonar.db.metric.MetricMapper;
 import org.sonar.db.Dao;
 import org.sonar.db.DaoUtils;
+import org.sonar.db.DatabaseUtils;
 import org.sonar.db.DbSession;
+import org.sonar.db.metric.MetricDto;
+import org.sonar.db.metric.MetricMapper;
 import org.sonar.server.es.SearchOptions;
 import org.sonar.server.exceptions.NotFoundException;
 
 import static com.google.common.collect.Lists.newArrayList;
 
-@ServerSide
 public class MetricDao implements Dao {
 
   @CheckForNull
@@ -54,7 +53,7 @@ public class MetricDao implements Dao {
   }
 
   public List<MetricDto> selectNullableByKeys(final DbSession session, List<String> keys) {
-    return DaoUtils.executeLargeInputs(keys, new Function<List<String>, List<MetricDto>>() {
+    return DatabaseUtils.executeLargeInputs(keys, new Function<List<String>, List<MetricDto>>() {
       @Override
       public List<MetricDto> apply(@Nonnull List<String> input) {
         return mapper(session).selectByKeys(input);
@@ -115,7 +114,7 @@ public class MetricDao implements Dao {
 
   public List<MetricDto> selectByIds(final DbSession session, Set<Integer> idsSet) {
     List<Integer> ids = new ArrayList<>(idsSet);
-    return DaoUtils.executeLargeInputs(ids, new Function<List<Integer>, List<MetricDto>>() {
+    return DatabaseUtils.executeLargeInputs(ids, new Function<List<Integer>, List<MetricDto>>() {
       @Override
       public List<MetricDto> apply(@Nonnull List<Integer> ids) {
         return mapper(session).selectByIds(ids);
@@ -136,7 +135,7 @@ public class MetricDao implements Dao {
   }
 
   public void disableByIds(final DbSession session, List<Integer> ids) {
-    DaoUtils.executeLargeInputsWithoutOutput(ids, new Function<List<Integer>, Void>() {
+    DatabaseUtils.executeLargeInputsWithoutOutput(ids, new Function<List<Integer>, Void>() {
       @Override
       public Void apply(@Nonnull List<Integer> input) {
         mapper(session).disableByIds(input);
index a4f2ab62212a4d07e5e3872ec9dedf22490135dd..69ca28e06cab9b6c49e4716745e1fd63ca5a6dfb 100644 (file)
@@ -25,32 +25,20 @@ import org.sonar.api.utils.System2;
 import org.sonar.api.utils.internal.TempFolderCleaner;
 import org.sonar.core.config.CorePropertyDefinitions;
 import org.sonar.core.config.Logback;
-import org.sonar.db.measure.MeasureFilterDao;
 import org.sonar.db.DaoUtils;
-import org.sonar.db.version.DatabaseVersion;
+import org.sonar.db.DatabaseChecker;
 import org.sonar.db.DefaultDatabase;
 import org.sonar.db.MyBatis;
+import org.sonar.db.purge.PurgeProfiler;
 import org.sonar.db.semaphore.SemaphoreUpdater;
 import org.sonar.db.semaphore.SemaphoresImpl;
-import org.sonar.db.purge.PurgeProfiler;
-import org.sonar.server.activity.db.ActivityDao;
+import org.sonar.db.version.DatabaseVersion;
 import org.sonar.server.component.db.ComponentDao;
-import org.sonar.server.component.db.ComponentIndexDao;
-import org.sonar.server.component.db.ComponentLinkDao;
-import org.sonar.server.component.db.SnapshotDao;
-import org.sonar.server.computation.db.AnalysisReportDao;
-import org.sonar.server.measure.custom.persistence.CustomMeasureDao;
-import org.sonar.server.dashboard.db.DashboardDao;
-import org.sonar.server.dashboard.db.WidgetDao;
-import org.sonar.server.dashboard.db.WidgetPropertyDao;
-import org.sonar.server.db.DatabaseChecker;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.db.EmbeddedDatabaseFactory;
 import org.sonar.server.db.migrations.MigrationStepModule;
-import org.sonar.server.event.db.EventDao;
-import org.sonar.server.issue.db.IssueDao;
 import org.sonar.server.issue.index.IssueIndex;
-import org.sonar.server.measure.persistence.MeasureDao;
+import org.sonar.server.measure.custom.persistence.CustomMeasureDao;
 import org.sonar.server.metric.persistence.MetricDao;
 import org.sonar.server.platform.DatabaseServerCompatibility;
 import org.sonar.server.platform.DefaultServerFileSystem;
@@ -67,11 +55,9 @@ import org.sonar.server.rule.index.RuleIndex;
 import org.sonar.server.rule.index.RuleNormalizer;
 import org.sonar.server.search.EsSearchModule;
 import org.sonar.server.search.IndexQueue;
-import org.sonar.server.source.db.FileSourceDao;
 import org.sonar.server.user.ThreadLocalUserSession;
 import org.sonar.server.user.db.GroupDao;
 import org.sonar.server.user.db.UserDao;
-import org.sonar.server.user.db.UserGroupDao;
 
 public class PlatformLevel1 extends PlatformLevel {
   private final Platform platform;
@@ -124,12 +110,6 @@ public class PlatformLevel1 extends PlatformLevel {
       // users
       GroupDao.class,
       UserDao.class,
-      UserGroupDao.class,
-
-      // dashboards
-      DashboardDao.class,
-      WidgetDao.class,
-      WidgetPropertyDao.class,
 
       // rules/qprofiles
       RuleNormalizer.class,
@@ -141,24 +121,13 @@ public class PlatformLevel1 extends PlatformLevel {
 
       // issues
       IssueIndex.class,
-      IssueDao.class,
 
       // measures
-      MeasureDao.class,
       MetricDao.class,
-      MeasureFilterDao.class,
       CustomMeasureDao.class,
 
       // components
-      ComponentDao.class,
-      ComponentIndexDao.class,
-      ComponentLinkDao.class,
-      SnapshotDao.class,
-
-      EventDao.class,
-      ActivityDao.class,
-      AnalysisReportDao.class,
-      FileSourceDao.class);
+      ComponentDao.class);
     addAll(CorePropertyDefinitions.all());
     add(MigrationStepModule.class);
     addAll(DaoUtils.getDaoClasses());
index b6664b71e461977a2f1c832919752d67a21e0192..fd526765be79871abfece06cc5917e2ee12e67fc 100644 (file)
@@ -28,7 +28,7 @@ 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.server.util.Slug;
+import org.sonar.core.util.Slug;
 
 import javax.annotation.CheckForNull;
 
index a5bbb93523014a4100e950aa35a371233141ba70..3926fbf095eaccb739fac30ed6a34d16ea9c9f6d 100644 (file)
@@ -21,6 +21,12 @@ package org.sonar.server.qualityprofile;
 
 import com.google.common.base.Splitter;
 import com.google.common.collect.Lists;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
 import org.sonar.api.server.ServerSide;
 import org.sonar.api.server.rule.RuleParamType;
 import org.sonar.db.DbSession;
@@ -44,14 +50,6 @@ import org.sonar.server.search.Result;
 import org.sonar.server.user.UserSession;
 import org.sonar.server.util.TypeValidations;
 
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
 import static com.google.common.collect.Lists.newArrayList;
 
 /**
diff --git a/server/sonar-server/src/main/java/org/sonar/server/source/db/FileSourceDao.java b/server/sonar-server/src/main/java/org/sonar/server/source/db/FileSourceDao.java
deleted file mode 100644 (file)
index ba1eb20..0000000
+++ /dev/null
@@ -1,150 +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 com.google.common.base.Function;
-import com.google.common.base.Splitter;
-import java.io.Reader;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.List;
-import javax.annotation.CheckForNull;
-import org.apache.commons.dbutils.DbUtils;
-import org.apache.commons.io.IOUtils;
-import org.sonar.api.server.ServerSide;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
-import org.sonar.db.source.FileSourceDto;
-import org.sonar.db.source.FileSourceDto.Type;
-import org.sonar.db.source.FileSourceMapper;
-
-@ServerSide
-public class FileSourceDao implements Dao {
-
-  private static final Splitter END_OF_LINE_SPLITTER = Splitter.on('\n');
-  private final MyBatis mybatis;
-
-  public FileSourceDao(MyBatis myBatis) {
-    this.mybatis = myBatis;
-  }
-
-  @CheckForNull
-  public FileSourceDto selectSource(String fileUuid) {
-    DbSession session = mybatis.openSession(false);
-    try {
-      return mapper(session).select(fileUuid, Type.SOURCE);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  @CheckForNull
-  public FileSourceDto selectTest(String fileUuid) {
-    DbSession session = mybatis.openSession(false);
-    try {
-      return mapper(session).select(fileUuid, Type.TEST);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  @CheckForNull
-  public List<String> selectLineHashes(DbSession dbSession, String fileUuid) {
-    Connection connection = dbSession.getConnection();
-    PreparedStatement pstmt = null;
-    ResultSet rs = null;
-    try {
-      pstmt = connection.prepareStatement("SELECT line_hashes FROM file_sources WHERE file_uuid=? AND data_type=?");
-      pstmt.setString(1, fileUuid);
-      pstmt.setString(2, Type.SOURCE);
-      rs = pstmt.executeQuery();
-      if (rs.next()) {
-        return END_OF_LINE_SPLITTER.splitToList(rs.getString(1));
-      }
-      return null;
-    } catch (SQLException e) {
-      throw new IllegalStateException("Fail to read FILE_SOURCES.LINE_HASHES of file " + fileUuid, e);
-    } finally {
-      DbUtils.closeQuietly(connection, pstmt, rs);
-    }
-  }
-
-  public <T> void readLineHashesStream(DbSession dbSession, String fileUuid, Function<Reader, T> function) {
-    Connection connection = dbSession.getConnection();
-    PreparedStatement pstmt = null;
-    ResultSet rs = null;
-    Reader reader = null;
-    try {
-      pstmt = connection.prepareStatement("SELECT line_hashes FROM file_sources WHERE file_uuid=? AND data_type=?");
-      pstmt.setString(1, fileUuid);
-      pstmt.setString(2, Type.SOURCE);
-      rs = pstmt.executeQuery();
-      if (rs.next()) {
-        reader = rs.getCharacterStream(1);
-        function.apply(reader);
-      }
-    } catch (SQLException e) {
-      throw new IllegalStateException("Fail to read FILE_SOURCES.LINE_HASHES of file " + fileUuid, e);
-    } finally {
-      IOUtils.closeQuietly(reader);
-      DbUtils.closeQuietly(connection, pstmt, rs);
-    }
-  }
-
-  public void insert(FileSourceDto dto) {
-    DbSession session = mybatis.openSession(false);
-    try {
-      insert(session, dto);
-      session.commit();
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public void insert(DbSession session, FileSourceDto dto) {
-    mapper(session).insert(dto);
-  }
-
-  public void update(FileSourceDto dto) {
-    DbSession session = mybatis.openSession(false);
-    try {
-      update(session, dto);
-      session.commit();
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public void update(DbSession session, FileSourceDto dto) {
-    mapper(session).update(dto);
-  }
-
-  public void updateDateWhenUpdatedDateIsZero(DbSession session, String projectUuid, long updateDate) {
-    mapper(session).updateDateWhenUpdatedDateIsZero(projectUuid, updateDate);
-  }
-
-  private FileSourceMapper mapper(DbSession session) {
-    return session.getMapper(FileSourceMapper.class);
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/source/db/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/source/db/package-info.java
deleted file mode 100644 (file)
index 83a499f..0000000
+++ /dev/null
@@ -1,24 +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.
- */
-
-@ParametersAreNonnullByDefault
-package org.sonar.server.source.db;
-
-import javax.annotation.ParametersAreNonnullByDefault;
index cfe8967a8c6c9b7d0dd94b557e5be11f48a542fa..b899a5fa0b7efb41156d65e365cbc4960240a9e3 100644 (file)
@@ -23,7 +23,7 @@ import org.elasticsearch.action.update.UpdateRequest;
 import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.db.source.FileSourceDto;
 import org.sonar.server.db.DbClient;
-import org.sonar.server.db.ResultSetIterator;
+import org.sonar.db.ResultSetIterator;
 import org.sonar.server.es.EsUtils;
 import org.sonar.server.source.db.FileSourceDb;
 
index b454c0bcb776e41fe80994a7dfc23f8e0562277d..1c8d1e0b3ec5659764cb8e84a8ad1eb4f558ac29 100644 (file)
@@ -30,7 +30,7 @@ import org.sonar.api.web.UserRole;
 import org.sonar.db.measure.MeasureDto;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
-import org.sonar.server.measure.persistence.MeasureDao;
+import org.sonar.db.measure.MeasureDao;
 import org.sonar.server.user.UserSession;
 
 @ServerSide
index c0117b7526e73d2e8312a210b2256006e218abe1..61af83231293e2657f754e3876e30b83ceaf109a 100644 (file)
@@ -24,7 +24,7 @@ import org.elasticsearch.action.update.UpdateRequest;
 import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.db.source.FileSourceDto;
 import org.sonar.server.db.DbClient;
-import org.sonar.server.db.ResultSetIterator;
+import org.sonar.db.ResultSetIterator;
 import org.sonar.server.source.db.FileSourceDb;
 import org.sonar.server.source.index.FileSourcesUpdaterHelper;
 import org.sonar.server.source.index.FileSourcesUpdaterHelper.Row;
index 5556381a2bda586276e404917f6e4435b3a636ce..acedc2aa42cbb7623dd3efe469aa1538e11c727e 100644 (file)
@@ -33,9 +33,6 @@ import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.GroupMapper;
 import org.sonar.server.exceptions.NotFoundException;
 
-/**
- * @since 3.2
- */
 public class GroupDao implements Dao {
 
   private static final String SQL_WILDCARD = "%";
diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/db/UserGroupDao.java b/server/sonar-server/src/main/java/org/sonar/server/user/db/UserGroupDao.java
deleted file mode 100644 (file)
index 413378e..0000000
+++ /dev/null
@@ -1,46 +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.user.db;
-
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-import org.sonar.db.user.UserGroupDto;
-import org.sonar.db.user.UserGroupMapper;
-
-public class UserGroupDao implements Dao {
-
-  public UserGroupDto insert(DbSession session, UserGroupDto dto) {
-    mapper(session).insert(dto);
-    return dto;
-  }
-
-  public void delete(DbSession session, UserGroupDto dto) {
-    mapper(session).delete(dto);
-  }
-
-  public void deleteMembersByGroupId(DbSession session, long groupId) {
-    mapper(session).deleteMembersByGroup(groupId);
-  }
-
-  protected UserGroupMapper mapper(DbSession session) {
-    return session.getMapper(UserGroupMapper.class);
-  }
-}
index c7e834d0e76c5219eb9f07813feb8ed4d5cbc27f..22d1111613bc4416d15624fe865e928546d22ad0 100644 (file)
@@ -23,7 +23,7 @@ import com.google.common.collect.Maps;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.db.DbClient;
-import org.sonar.server.db.ResultSetIterator;
+import org.sonar.db.ResultSetIterator;
 
 import java.sql.Connection;
 import java.sql.PreparedStatement;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/usergroups/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/usergroups/package-info.java
deleted file mode 100644 (file)
index d8a077d..0000000
+++ /dev/null
@@ -1,25 +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.
- */
-
-@ParametersAreNonnullByDefault
-package org.sonar.server.usergroups;
-
-import javax.annotation.ParametersAreNonnullByDefault;
-
diff --git a/server/sonar-server/src/main/java/org/sonar/server/util/ProgressLogger.java b/server/sonar-server/src/main/java/org/sonar/server/util/ProgressLogger.java
deleted file mode 100644 (file)
index a159389..0000000
+++ /dev/null
@@ -1,115 +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.util;
-
-
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
-
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.concurrent.atomic.AtomicLong;
-
-/**
- * Background thread that logs the state of a counter at fixed intervals.
- */
-public class ProgressLogger {
-
-  public static final long DEFAULT_PERIOD_MS = 60000L;
-
-  private final Timer timer;
-  private final LoggerTimerTask task;
-  private long periodMs = DEFAULT_PERIOD_MS;
-
-  public ProgressLogger(String threadName, AtomicLong counter, Logger logger) {
-    this.timer = new Timer(threadName);
-    this.task = new LoggerTimerTask(counter, logger);
-  }
-
-  public static ProgressLogger create(Class clazz, AtomicLong counter) {
-    String threadName = String.format("ProgressLogger[%s]", clazz.getSimpleName());
-    Logger logger = Loggers.get(clazz);
-    return new ProgressLogger(threadName, counter, logger);
-  }
-
-  /**
-   * Warning, does not check if already started.
-   */
-  public void start() {
-    // first log after {periodMs} milliseconds
-    timer.schedule(task, periodMs, periodMs);
-  }
-
-  public void stop() {
-    timer.cancel();
-    timer.purge();
-  }
-
-  /**
-   * Default is 1 minute
-   */
-  public ProgressLogger setPeriodMs(long l) {
-    this.periodMs = l;
-    return this;
-  }
-
-  public long getPeriodMs() {
-    return periodMs;
-  }
-
-  /**
-   * For example "issues", "measures", ... Default is "rows".
-   */
-  public ProgressLogger setPluralLabel(String s) {
-    task.pluralLabel = s;
-    return this;
-  }
-
-  public String getPluralLabel() {
-    return task.pluralLabel;
-  }
-
-  public void log() {
-    task.log();
-  }
-
-  private class LoggerTimerTask extends TimerTask {
-    private final AtomicLong counter;
-    private final Logger logger;
-    private String pluralLabel = "rows";
-    private long previousCounter = 0L;
-
-    private LoggerTimerTask(AtomicLong counter, Logger logger) {
-      this.counter = counter;
-      this.logger = logger;
-    }
-
-    @Override
-    public void run() {
-      log();
-    }
-
-    private void log() {
-      long current = counter.get();
-      logger.info(String.format("%d %s processed (%d items/sec)", current, pluralLabel, 1000 * (current-previousCounter) / periodMs));
-      previousCounter = current;
-    }
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/util/Slug.java b/server/sonar-server/src/main/java/org/sonar/server/util/Slug.java
deleted file mode 100644 (file)
index 60b89d5..0000000
+++ /dev/null
@@ -1,39 +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.util;
-
-import java.text.Normalizer;
-import java.util.Locale;
-
-public class Slug {
-
-  private Slug() {
-  }
-
-  public static String slugify(String s) {
-    return Normalizer.normalize(s, Normalizer.Form.NFD)
-      .replaceAll("[^\\p{ASCII}]", "")
-      .replaceAll("[^\\w+]", "-")
-      .replaceAll("\\s+", "-")
-      .replaceAll("[-]+", "-")
-      .replaceAll("^-", "")
-      .replaceAll("-$", "").toLowerCase(Locale.ENGLISH);
-  }
-}
index bf85d76c00b323e509ca1f50cf6cbb1d0561bac1..df018db96bdd83f67fa52eb3fe90b405c6d0fb21 100644 (file)
 
 package org.sonar.core.computation.dbcleaner;
 
+import java.util.Date;
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.config.Settings;
 import org.sonar.api.utils.log.Logger;
-import org.sonar.db.purge.period.DefaultPeriodCleaner;
+import org.sonar.core.config.PurgeConstants;
 import org.sonar.db.DbSession;
 import org.sonar.db.purge.IdUuidPair;
 import org.sonar.db.purge.PurgeConfiguration;
-import org.sonar.core.config.PurgeConstants;
 import org.sonar.db.purge.PurgeDao;
 import org.sonar.db.purge.PurgeListener;
 import org.sonar.db.purge.PurgeProfiler;
+import org.sonar.db.purge.period.DefaultPeriodCleaner;
 import org.sonar.server.issue.index.IssueIndex;
 
-import java.util.Date;
-
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyLong;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
 
 public class ProjectCleanerTest {
 
@@ -86,17 +91,17 @@ public class ProjectCleanerTest {
     sut.purge(mock(DbSession.class), mock(IdUuidPair.class), settings);
 
     verify(periodCleaner).clean(any(DbSession.class), any(Long.class), any(Settings.class));
-    verify(dao).purge(any(DbSession.class), any(PurgeConfiguration.class), any(PurgeListener.class));
+    verify(dao).purge(any(DbSession.class), any(PurgeConfiguration.class), any(PurgeListener.class), any(PurgeProfiler.class));
     verify(issueIndex).deleteClosedIssuesOfProjectBefore(any(String.class), any(Date.class));
   }
 
   @Test
   public void if_dao_purge_fails_it_should_not_interrupt_program_execution() {
-    doThrow(RuntimeException.class).when(dao).purge(any(DbSession.class), any(PurgeConfiguration.class), any(PurgeListener.class));
+    doThrow(RuntimeException.class).when(dao).purge(any(DbSession.class), any(PurgeConfiguration.class), any(PurgeListener.class), any(PurgeProfiler.class));
 
     sut.purge(mock(DbSession.class), mock(IdUuidPair.class), settings);
 
-    verify(dao).purge(any(DbSession.class), any(PurgeConfiguration.class), any(PurgeListener.class));
+    verify(dao).purge(any(DbSession.class), any(PurgeConfiguration.class), any(PurgeListener.class), any(PurgeProfiler.class));
   }
 
   @Test
index 487c3abcca01ab29aecc863e63af16a9aafa408e..76722086d5feec2122b69708d9adc9757cd9135a 100644 (file)
@@ -29,13 +29,13 @@ import org.junit.Test;
 import org.sonar.api.config.Settings;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
-import org.sonar.server.activity.db.ActivityDao;
+import org.sonar.db.activity.ActivityDao;
+import org.sonar.db.issue.IssueDao;
 import org.sonar.server.activity.index.ActivityDoc;
 import org.sonar.server.activity.index.ActivityIndexDefinition;
 import org.sonar.server.activity.index.ActivityIndexer;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.es.EsTester;
-import org.sonar.server.issue.db.IssueDao;
 import org.sonar.server.tester.UserSessionRule;
 
 import static org.assertj.core.api.Assertions.assertThat;
diff --git a/server/sonar-server/src/test/java/org/sonar/server/activity/db/ActivityDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/activity/db/ActivityDaoTest.java
deleted file mode 100644 (file)
index bfdf049..0000000
+++ /dev/null
@@ -1,66 +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.activity.db;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.sonar.api.utils.System2;
-import org.sonar.db.activity.ActivityDto;
-import org.sonar.db.DbTester;
-import org.sonar.test.DbTests;
-
-import java.util.Map;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-@Category(DbTests.class)
-public class ActivityDaoTest {
-
-  @Rule
-  public DbTester dbTester = new DbTester();
-
-  System2 system = mock(System2.class);
-  ActivityDao sut;
-
-  @Before
-  public void before() {
-    sut = new ActivityDao(dbTester.myBatis(), system);
-  }
-
-  @Test
-  public void insert() {
-    when(system.now()).thenReturn(1_500_000_000_000L);
-    ActivityDto dto = new ActivityDto()
-      .setKey("UUID_1").setAction("THE_ACTION").setType("THE_TYPE")
-      .setAuthor("THE_AUTHOR").setData("THE_DATA");
-    sut.insert(dto);
-
-    Map<String, Object> map = dbTester.selectFirst("select created_at as \"createdAt\", log_action as \"action\", data_field as \"data\" from activities where log_key='UUID_1'");
-    assertThat(map.get("action")).isEqualTo("THE_ACTION");
-    // not possible to check exact date yet. dbTester#selectFirst() uses ResultSet#getObject(), which returns
-    // non-JDBC interface in Oracle driver.
-    assertThat(map.get("createdAt")).isNotNull();
-    assertThat(map.get("data")).isEqualTo("THE_DATA");
-  }
-}
index 6a106265a184b61f257851df3aa2f4cc6d377924..fd29bbc34398a804358c5b5c73d06e6846f4e196 100644 (file)
@@ -36,13 +36,13 @@ 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.issue.IssueDao;
 import org.sonar.server.component.ComponentTesting;
 import org.sonar.server.component.db.ComponentDao;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.issue.IssueTesting;
-import org.sonar.server.issue.db.IssueDao;
 import org.sonar.server.issue.index.IssueAuthorizationDao;
 import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 import org.sonar.server.issue.index.IssueDoc;
index 01c98a28d0133a6aa23c5995a8975a32f3f158d0..c8cd38afac71eec7a8e8f3a2b41306efb5e5ff9f 100644 (file)
@@ -54,8 +54,8 @@ import org.sonar.server.qualityprofile.QProfileName;
 import org.sonar.server.qualityprofile.QProfileTesting;
 import org.sonar.server.qualityprofile.RuleActivation;
 import org.sonar.server.qualityprofile.RuleActivator;
-import org.sonar.server.rule.RuleTesting;
-import org.sonar.server.source.db.FileSourceDao;
+import org.sonar.db.rule.RuleTesting;
+import org.sonar.db.source.FileSourceDao;
 import org.sonar.server.tester.ServerTester;
 import org.sonar.server.tester.UserSessionRule;
 
index 838ab5af06f3fd017683b93723d8997adc5baf3b..ae711a2e0d1f7418c4a47d6c3e5e088be481ae67 100644 (file)
@@ -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()),
+    service = new ComponentService(dbClient, new ResourceKeyUpdaterDao(dbTester.myBatis()), i18n, new ResourceIndexerDao(dbTester.myBatis(), mock(System2.class)),
       userSessionRule, System2.INSTANCE);
   }
 
index c0efcd49313d35ef93c45229ff742d107e49e9e8..32ed4afe0fe8e507558b54db72994146a0fbd776 100644 (file)
@@ -30,10 +30,10 @@ import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.utils.DateUtils;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.FilePathWithHashDto;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
+import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.FilePathWithHashDto;
 import org.sonar.server.es.SearchOptions;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.test.DbTests;
@@ -290,7 +290,7 @@ public class ComponentDaoTest {
     assertThat(result.isEnabled()).isFalse();
   }
 
-  @Test(expected = NotFoundException.class)
+  @Test(expected = IllegalArgumentException.class)
   public void fail_to_get_by_id_when_project_not_found() {
     loadBasicDataInDatabase();
 
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentIndexDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentIndexDaoTest.java
deleted file mode 100644 (file)
index c14695e..0000000
+++ /dev/null
@@ -1,66 +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.component.db;
-
-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.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.test.DbTests;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-@Category(DbTests.class)
-public class ComponentIndexDaoTest {
-
-  @ClassRule
-  public static DbTester dbTester = new DbTester();
-
-  DbSession session;
-
-  ComponentIndexDao dao;
-
-  @Before
-  public void createDao() {
-    dbTester.truncateTables();
-    session = dbTester.myBatis().openSession(false);
-    dao = new ComponentIndexDao();
-  }
-
-  @After
-  public void tearDown() {
-    session.close();
-  }
-
-  @Test
-  public void select_project_ids_from_query_and_view_or_sub_view_uuid() {
-    dbTester.prepareDbUnit(getClass(), "select_project_ids_from_query_and_view_or_sub_view_uuid.xml");
-    String viewUuid = "EFGH";
-
-    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/server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentLinkDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentLinkDaoTest.java
deleted file mode 100644 (file)
index 68b86c3..0000000
+++ /dev/null
@@ -1,117 +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.component.db;
-
-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.db.component.ComponentLinkDto;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.test.DbTests;
-
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-@Category(DbTests.class)
-public class ComponentLinkDaoTest {
-
-  @ClassRule
-  public static DbTester dbTester = new DbTester();
-
-  DbSession session;
-
-  ComponentLinkDao dao;
-
-  @Before
-  public void createDao() {
-    session = dbTester.myBatis().openSession(false);
-    dao = new ComponentLinkDao();
-  }
-
-  @After
-  public void tearDown() {
-    session.close();
-  }
-
-  @Test
-  public void select_by_component_uuid() {
-    dbTester.prepareDbUnit(getClass(), "shared.xml");
-
-    List<ComponentLinkDto> links = dao.selectByComponentUuid(session, "ABCD");
-    assertThat(links).hasSize(2);
-
-    links = dao.selectByComponentUuid(session, "BCDE");
-    assertThat(links).hasSize(1);
-
-    ComponentLinkDto link = links.get(0);
-    assertThat(link.getId()).isEqualTo(3L);
-    assertThat(link.getComponentUuid()).isEqualTo("BCDE");
-    assertThat(link.getType()).isEqualTo("homepage");
-    assertThat(link.getName()).isEqualTo("Home");
-    assertThat(link.getHref()).isEqualTo("http://www.struts.org");
-  }
-
-  @Test
-  public void insert() {
-    dbTester.prepareDbUnit(getClass(), "empty.xml");
-
-    dao.insert(session, new ComponentLinkDto()
-        .setComponentUuid("ABCD")
-        .setType("homepage")
-        .setName("Home")
-        .setHref("http://www.sonarqube.org")
-      );
-    session.commit();
-
-    dbTester.assertDbUnit(getClass(), "insert-result.xml", new String[]{"id"}, "project_links");
-  }
-
-  @Test
-  public void update() {
-    dbTester.prepareDbUnit(getClass(), "update.xml");
-
-    dao.update(session, new ComponentLinkDto()
-      .setId(1L)
-      .setComponentUuid("ABCD")
-      .setType("homepage")
-      .setName("Home")
-      .setHref("http://www.sonarqube.org")
-      );
-    session.commit();
-
-    dbTester.assertDbUnit(getClass(), "update-result.xml", "project_links");
-  }
-
-  @Test
-  public void delete() {
-    dbTester.prepareDbUnit(getClass(), "delete.xml");
-
-    dao.delete(session, 1L);
-    session.commit();
-
-    assertThat(dbTester.countRowsOfTable("project_links")).isEqualTo(0);
-  }
-
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/db/SnapshotDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/db/SnapshotDaoTest.java
deleted file mode 100644 (file)
index 7305427..0000000
+++ /dev/null
@@ -1,307 +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.component.db;
-
-import java.util.Date;
-import java.util.List;
-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.db.component.SnapshotDto;
-import org.sonar.db.component.SnapshotQuery;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.test.DbTests;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.component.SnapshotQuery.SORT_FIELD.BY_DATE;
-import static org.sonar.db.component.SnapshotQuery.SORT_ORDER.ASC;
-import static org.sonar.db.component.SnapshotQuery.SORT_ORDER.DESC;
-
-@Category(DbTests.class)
-public class SnapshotDaoTest {
-
-  @ClassRule
-  public static DbTester db = new DbTester();
-
-  DbSession session;
-
-  SnapshotDao sut;
-
-  @Before
-  public void createDao() {
-    session = db.myBatis().openSession(false);
-    sut = new SnapshotDao();
-  }
-
-  @After
-  public void tearDown() {
-    session.close();
-  }
-
-  @Test
-  public void get_by_key() {
-    db.prepareDbUnit(getClass(), "shared.xml");
-
-    SnapshotDto result = sut.selectNullableById(session, 3L);
-    assertThat(result).isNotNull();
-    assertThat(result.getId()).isEqualTo(3L);
-    assertThat(result.getComponentId()).isEqualTo(3L);
-    assertThat(result.getRootProjectId()).isEqualTo(1L);
-    assertThat(result.getParentId()).isEqualTo(2L);
-    assertThat(result.getRootId()).isEqualTo(1L);
-    assertThat(result.getStatus()).isEqualTo("P");
-    assertThat(result.getLast()).isTrue();
-    assertThat(result.getPurgeStatus()).isEqualTo(1);
-    assertThat(result.getDepth()).isEqualTo(1);
-    assertThat(result.getScope()).isEqualTo("DIR");
-    assertThat(result.getQualifier()).isEqualTo("PAC");
-    assertThat(result.getVersion()).isEqualTo("2.1-SNAPSHOT");
-    assertThat(result.getPath()).isEqualTo("1.2.");
-
-    assertThat(result.getPeriodMode(1)).isEqualTo("days1");
-    assertThat(result.getPeriodModeParameter(1)).isEqualTo("30");
-    assertThat(result.getPeriodDate(1)).isEqualTo(1316815200000L);
-    assertThat(result.getPeriodMode(2)).isEqualTo("days2");
-    assertThat(result.getPeriodModeParameter(2)).isEqualTo("31");
-    assertThat(result.getPeriodDate(2)).isEqualTo(1316901600000L);
-    assertThat(result.getPeriodMode(3)).isEqualTo("days3");
-    assertThat(result.getPeriodModeParameter(3)).isEqualTo("32");
-    assertThat(result.getPeriodDate(3)).isEqualTo(1316988000000L);
-    assertThat(result.getPeriodMode(4)).isEqualTo("days4");
-    assertThat(result.getPeriodModeParameter(4)).isEqualTo("33");
-    assertThat(result.getPeriodDate(4)).isEqualTo(1317074400000L);
-    assertThat(result.getPeriodMode(5)).isEqualTo("days5");
-    assertThat(result.getPeriodModeParameter(5)).isEqualTo("34");
-    assertThat(result.getPeriodDate(5)).isEqualTo(1317160800000L);
-
-    assertThat(result.getCreatedAt()).isEqualTo(1228172400000L);
-    assertThat(result.getBuildDate()).isEqualTo(1317247200000L);
-
-    assertThat(sut.selectNullableById(session, 999L)).isNull();
-  }
-
-  @Test
-  public void lastSnapshot_returns_null_when_no_last_snapshot() {
-    SnapshotDto snapshot = sut.selectLastSnapshotByComponentId(session, 123L);
-
-    assertThat(snapshot).isNull();
-  }
-
-  @Test
-  public void lastSnapshot_from_one_resource() {
-    db.prepareDbUnit(getClass(), "snapshots.xml");
-
-    SnapshotDto snapshot = sut.selectLastSnapshotByComponentId(session, 2L);
-
-    assertThat(snapshot).isNotNull();
-    assertThat(snapshot.getId()).isEqualTo(4L);
-  }
-
-  @Test
-  public void lastSnapshot_from_one_resource_without_last_is_null() {
-    db.prepareDbUnit(getClass(), "snapshots.xml");
-
-    SnapshotDto snapshot = sut.selectLastSnapshotByComponentId(session, 5L);
-
-    assertThat(snapshot).isNull();
-  }
-
-  @Test
-  public void snapshot_and_child_retrieved() {
-    db.prepareDbUnit(getClass(), "snapshots.xml");
-
-    List<SnapshotDto> snapshots = sut.selectSnapshotAndChildrenOfProjectScope(session, 1L);
-
-    assertThat(snapshots).isNotEmpty();
-    assertThat(snapshots).extracting("id").containsOnly(1L, 6L);
-  }
-
-  @Test
-  public void select_snapshots_by_component_id() {
-    db.prepareDbUnit(getClass(), "snapshots.xml");
-
-    List<SnapshotDto> snapshots = sut.selectSnapshotsByComponentId(session, 1L);
-
-    assertThat(snapshots).hasSize(3);
-  }
-
-  @Test
-  public void select_snapshots_by_query() {
-    db.prepareDbUnit(getClass(), "select_snapshots_by_query.xml");
-
-    assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery())).hasSize(6);
-
-    assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L))).hasSize(3);
-
-    assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setVersion("2.2-SNAPSHOT"))).extracting("id").containsOnly(3L);
-
-    assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setIsLast(true))).extracting("id").containsOnly(1L);
-    assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setIsLast(false))).extracting("id").containsOnly(2L, 3L);
-
-    assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setCreatedAfter(1228172400002L))).extracting("id").containsOnly(2L, 3L);
-    assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setCreatedBefore(1228172400002L))).extracting("id").containsOnly(1L);
-
-    assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(2L).setStatus("P"))).hasSize(1);
-    assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(2L).setStatus("U"))).hasSize(1);
-
-    assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setSort(BY_DATE, ASC)).get(0).getId()).isEqualTo(1L);
-    assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setSort(BY_DATE, DESC)).get(0).getId()).isEqualTo(3L);
-  }
-
-  @Test
-  public void select_previous_version_snapshots() throws Exception {
-    db.prepareDbUnit(getClass(), "select_previous_version_snapshots.xml");
-
-    List<SnapshotDto> snapshots = sut.selectPreviousVersionSnapshots(session, 1L, "1.2-SNAPSHOT");
-    assertThat(snapshots).hasSize(2);
-
-    SnapshotDto firstSnapshot = snapshots.get(0);
-    assertThat(firstSnapshot.getVersion()).isEqualTo("1.1");
-
-    // All snapshots are returned on an unknown version
-    assertThat(sut.selectPreviousVersionSnapshots(session, 1L, "UNKNOWN")).hasSize(3);
-  }
-
-  @Test
-  public void insert() {
-    db.prepareDbUnit(getClass(), "empty.xml");
-
-    SnapshotDto dto = defaultSnapshot().setCreatedAt(1403042400000L);
-
-    sut.insert(session, dto);
-    session.commit();
-
-    assertThat(dto.getId()).isNotNull();
-    db.assertDbUnit(getClass(), "insert-result.xml", new String[] {"id"}, "snapshots");
-  }
-
-  @Test
-  public void insert_snapshots() {
-    db.prepareDbUnit(getClass(), "empty.xml");
-
-    sut.insert(session,
-      new SnapshotDto().setComponentId(1L).setLast(false),
-      new SnapshotDto().setComponentId(2L).setLast(false));
-    session.commit();
-
-    assertThat(db.countRowsOfTable("snapshots")).isEqualTo(2);
-  }
-
-  @Test
-  public void set_snapshot_and_children_to_false_and_status_processed() {
-    db.prepareDbUnit(getClass(), "snapshots.xml");
-    SnapshotDto snapshot = defaultSnapshot().setId(1L);
-
-    sut.updateSnapshotAndChildrenLastFlagAndStatus(session, snapshot, false, SnapshotDto.STATUS_PROCESSED);
-    session.commit();
-
-    List<SnapshotDto> snapshots = sut.selectSnapshotAndChildrenOfProjectScope(session, 1L);
-    assertThat(snapshots).hasSize(2);
-    assertThat(snapshots).extracting("id").containsOnly(1L, 6L);
-    assertThat(snapshots).extracting("last").containsOnly(false);
-    assertThat(snapshots).extracting("status").containsOnly(SnapshotDto.STATUS_PROCESSED);
-  }
-
-  @Test
-  public void set_snapshot_and_children_isLast_flag_to_false() {
-    db.prepareDbUnit(getClass(), "snapshots.xml");
-    SnapshotDto snapshot = defaultSnapshot().setId(1L);
-
-    sut.updateSnapshotAndChildrenLastFlag(session, snapshot, false);
-    session.commit();
-
-    List<SnapshotDto> snapshots = sut.selectSnapshotAndChildrenOfProjectScope(session, 1L);
-    assertThat(snapshots).hasSize(2);
-    assertThat(snapshots).extracting("id").containsOnly(1L, 6L);
-    assertThat(snapshots).extracting("last").containsOnly(false);
-  }
-
-  @Test
-  public void is_last_snapshot_when_no_previous_snapshot() {
-    SnapshotDto snapshot = defaultSnapshot();
-
-    boolean isLast = SnapshotDao.isLast(snapshot, null);
-
-    assertThat(isLast).isTrue();
-  }
-
-  @Test
-  public void is_last_snapshot_when_previous_snapshot_is_older() {
-    Date today = new Date();
-    Date yesterday = DateUtils.addDays(today, -1);
-
-    SnapshotDto snapshot = defaultSnapshot().setCreatedAt(today.getTime());
-    SnapshotDto previousLastSnapshot = defaultSnapshot().setCreatedAt(yesterday.getTime());
-
-    boolean isLast = SnapshotDao.isLast(snapshot, previousLastSnapshot);
-
-    assertThat(isLast).isTrue();
-  }
-
-  @Test
-  public void is_not_last_snapshot_when_previous_snapshot_is_newer() {
-    Date today = new Date();
-    Date yesterday = DateUtils.addDays(today, -1);
-
-    SnapshotDto snapshot = defaultSnapshot().setCreatedAt(yesterday.getTime());
-    SnapshotDto previousLastSnapshot = defaultSnapshot().setCreatedAt(today.getTime());
-
-    boolean isLast = SnapshotDao.isLast(snapshot, previousLastSnapshot);
-
-    assertThat(isLast).isFalse();
-  }
-
-  private static SnapshotDto defaultSnapshot() {
-    return new SnapshotDto()
-      .setComponentId(3L)
-      .setRootProjectId(1L)
-      .setParentId(2L)
-      .setRootId(1L)
-      .setStatus("P")
-      .setLast(true)
-      .setPurgeStatus(1)
-      .setDepth(1)
-      .setScope("DIR")
-      .setQualifier("PAC")
-      .setVersion("2.1-SNAPSHOT")
-      .setPath("1.2.")
-      .setPeriodMode(1, "days1")
-      .setPeriodMode(2, "days2")
-      .setPeriodMode(3, "days3")
-      .setPeriodMode(4, "days4")
-      .setPeriodMode(5, "days5")
-      .setPeriodParam(1, "30")
-      .setPeriodParam(2, "31")
-      .setPeriodParam(3, "32")
-      .setPeriodParam(4, "33")
-      .setPeriodParam(5, "34")
-      .setPeriodDate(1, 1_500_000_000_001L)
-      .setPeriodDate(2, 1_500_000_000_002L)
-      .setPeriodDate(3, 1_500_000_000_003L)
-      .setPeriodDate(4, 1_500_000_000_004L)
-      .setPeriodDate(5, 1_500_000_000_005L)
-      .setBuildDate(1_500_000_000_006L);
-  }
-}
index 354b78903519c65906390df9cbeb0e2a14a42b21..a12152dd953b1dc2a43843a89cdaca3f1fd8ce46 100644 (file)
@@ -45,7 +45,7 @@ import org.sonar.server.component.ComponentTesting;
 import org.sonar.server.component.db.ComponentDao;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.measure.persistence.MeasureDao;
+import org.sonar.db.measure.MeasureDao;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsTester;
 
index 32caf9546164b10aaa5b4a95add420a7d4500c28..1d5069f921bfffa33bdcfd4c1f86fa1027d76f2a 100644 (file)
@@ -26,11 +26,12 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 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.user.AuthorizationDao;
 import org.sonar.server.component.db.ComponentDao;
-import org.sonar.server.component.db.ComponentIndexDao;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsTester;
@@ -54,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 ComponentIndexDao()
+      new ComponentDao(), new AuthorizationDao(dbTester.myBatis()), new ResourceIndexerDao(dbTester.myBatis(), mock(System2.class))
       );
     tester = new WsTester(new ComponentsWs(mock(AppAction.class), new SearchAction(dbClient, userSessionRule)));
   }
index b2156df45faa2abeadfed928a2ab66dfe3946975..137eb422086a6b74a9c95e769ae106e30cdcbeb7 100644 (file)
@@ -35,7 +35,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.process.ProcessProperties;
 import org.sonar.server.component.db.ComponentDao;
-import org.sonar.server.computation.db.AnalysisReportDao;
+import org.sonar.db.compute.AnalysisReportDao;
 import org.sonar.server.db.DbClient;
 import org.sonar.test.DbTests;
 
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java
deleted file mode 100644 (file)
index 1748075..0000000
+++ /dev/null
@@ -1,211 +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.computation.db;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.api.utils.System2;
-import org.sonar.db.compute.AnalysisReportDto;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.db.MyBatis;
-import org.sonar.test.DbTests;
-
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.sonar.db.compute.AnalysisReportDto.Status.PENDING;
-import static org.sonar.db.compute.AnalysisReportDto.Status.WORKING;
-
-@Category(DbTests.class)
-public class AnalysisReportDaoTest {
-
-  private static final String DEFAULT_PROJECT_KEY = "123456789-987654321";
-
-  @ClassRule
-  public static DbTester db = new DbTester();
-
-  @Rule
-  public TemporaryFolder temp = new TemporaryFolder();
-
-  AnalysisReportDao sut;
-  DbSession session;
-  System2 system2;
-
-  @Before
-  public void before() {
-    this.session = db.myBatis().openSession(false);
-    this.system2 = mock(System2.class);
-    this.sut = new AnalysisReportDao(system2);
-
-    when(system2.now()).thenReturn(1_500_000_000_000L);
-  }
-
-  @After
-  public void after() {
-    MyBatis.closeQuietly(session);
-  }
-
-  @Test
-  public void insert_multiple_reports() {
-    db.prepareDbUnit(getClass(), "empty.xml");
-
-    AnalysisReportDto report1 = new AnalysisReportDto().setProjectKey("ProjectKey1").setProjectName("Project 1").setUuid("UUID_1").setStatus(PENDING);
-    AnalysisReportDto report2 = new AnalysisReportDto().setProjectKey("ProjectKey2").setProjectName("Project 2").setUuid("UUID_2").setStatus(PENDING);
-
-    sut.insert(session, report1);
-    sut.insert(session, report2);
-    session.commit();
-
-    db.assertDbUnit(getClass(), "insert-result.xml", "analysis_reports");
-  }
-
-  @Test
-  public void resetAllToPendingStatus() {
-    db.prepareDbUnit(getClass(), "update-all-to-status-pending.xml");
-
-    sut.resetAllToPendingStatus(session);
-    session.commit();
-
-    db.assertDbUnit(getClass(), "update-all-to-status-pending-result.xml", "analysis_reports");
-  }
-
-  @Test
-  public void truncate() {
-    db.prepareDbUnit(getClass(), "any-analysis-reports.xml");
-
-    sut.truncate(session);
-    session.commit();
-
-    db.assertDbUnit(getClass(), "truncate-result.xml", "analysis_reports");
-  }
-
-  @Test
-  public void find_one_report_by_project_key() {
-    db.prepareDbUnit(getClass(), "select.xml");
-
-    final String projectKey = "123456789-987654321";
-    List<AnalysisReportDto> reports = sut.selectByProjectKey(session, projectKey);
-    AnalysisReportDto report = reports.get(0);
-
-    assertThat(reports).hasSize(1);
-    assertThat(report.getProjectKey()).isEqualTo(projectKey);
-    assertThat(report.getProjectName()).isEqualTo("Project 1");
-    assertThat(report.getStatus()).isEqualTo(AnalysisReportDto.Status.WORKING);
-    assertThat(report.getId()).isEqualTo(1);
-  }
-
-  @Test
-  public void find_several_reports_by_project_key() {
-    db.prepareDbUnit(getClass(), "select.xml");
-
-    final String projectKey = "987654321-123456789";
-    List<AnalysisReportDto> reports = sut.selectByProjectKey(session, projectKey);
-
-    assertThat(reports).hasSize(2);
-  }
-
-  @Test
-  public void pop_oldest_pending() {
-    db.prepareDbUnit(getClass(), "pop_oldest_pending.xml");
-
-    AnalysisReportDto nextAvailableReport = sut.pop(session);
-
-    assertThat(nextAvailableReport.getId()).isEqualTo(3);
-    assertThat(nextAvailableReport.getProjectKey()).isEqualTo("P2");
-  }
-
-  @Test
-  public void pop_null_if_no_pending_reports() {
-    db.prepareDbUnit(getClass(), "pop_null_if_no_pending_reports.xml");
-
-    AnalysisReportDto nextAvailableReport = sut.pop(session);
-
-    assertThat(nextAvailableReport).isNull();
-  }
-
-  @Test
-  public void getById_maps_all_the_fields_except_the_data() {
-    db.prepareDbUnit(getClass(), "one_analysis_report.xml");
-
-    AnalysisReportDto report = sut.selectById(session, 1L);
-
-    assertThat(report.getProjectKey()).isEqualTo(DEFAULT_PROJECT_KEY);
-    assertThat(report.getCreatedAt()).isEqualTo(1_500_000_000_001L);
-    assertThat(report.getUpdatedAt()).isEqualTo(1_500_000_000_002L);
-    assertThat(report.getStartedAt()).isEqualTo(1_500_000_000_003L);
-    assertThat(report.getFinishedAt()).isEqualTo(1_500_000_000_004L);
-    assertThat(report.getStatus()).isEqualTo(WORKING);
-  }
-
-  @Test
-  public void getById_returns_null_when_id_not_found() {
-    db.prepareDbUnit(getClass(), "select.xml");
-
-    AnalysisReportDto report = sut.selectById(session, 4L);
-
-    assertThat(report).isNull();
-  }
-
-  @Test
-  public void delete_one_analysis_report() {
-    db.prepareDbUnit(getClass(), "one_analysis_report.xml");
-
-    sut.delete(session, 1);
-    session.commit();
-
-    db.assertDbUnit(getClass(), "truncate-result.xml", "analysis_reports");
-  }
-
-  @Test
-  public void findAll_one_analysis_report() {
-    db.prepareDbUnit(getClass(), "one_analysis_report.xml");
-
-    List<AnalysisReportDto> reports = sut.selectAll(session);
-
-    assertThat(reports).hasSize(1);
-  }
-
-  @Test
-  public void findAll_empty_table() {
-    db.prepareDbUnit(getClass(), "empty.xml");
-
-    List<AnalysisReportDto> reports = sut.selectAll(session);
-
-    assertThat(reports).isEmpty();
-  }
-
-  @Test
-  public void findAll_three_analysis_reports() {
-    db.prepareDbUnit(getClass(), "three_analysis_reports.xml");
-
-    List<AnalysisReportDto> reports = sut.selectAll(session);
-
-    assertThat(reports).hasSize(3);
-  }
-}
index 44af4c3436e6356563603fd81e206ddbeb86a546..9470ff2708263ceec358cbd3235c1c28fb1b76cf 100644 (file)
@@ -25,7 +25,6 @@ import org.junit.Test;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.utils.Duration;
 import org.sonar.core.issue.DefaultIssue;
-import org.sonar.core.issue.tracking.Tracking;
 import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.component.DumbComponent;
 import org.sonar.server.computation.debt.Characteristic;
@@ -34,7 +33,7 @@ import org.sonar.server.computation.debt.MutableDebtModelHolder;
 import org.sonar.server.computation.measure.Measure;
 import org.sonar.server.computation.measure.MeasureRepositoryRule;
 import org.sonar.server.computation.metric.MetricRepositoryRule;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 
 import static java.util.Arrays.asList;
 import static org.assertj.core.api.Assertions.assertThat;
index cf57d9aa6827cc1f55b5325368f83a37d7aa275e..db2bd4d1327a1faa71471461ac673448b4699da3 100644 (file)
@@ -26,7 +26,7 @@ import org.sonar.api.server.debt.DebtRemediationFunction;
 import org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction;
 import org.sonar.api.utils.Durations;
 import org.sonar.core.issue.DefaultIssue;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
index d4f2994eda1d834c4e159148d24237f0f870c38d..4b957ccceac3b3785fb91e483e2bc0c998a3f519 100644 (file)
@@ -37,7 +37,7 @@ import org.sonar.server.computation.metric.MetricImpl;
 import org.sonar.server.computation.metric.MetricRepository;
 import org.sonar.server.computation.period.Period;
 import org.sonar.server.computation.period.PeriodsHolderRule;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
index a7f5c5fba82b18cdc94e1ec88db64e80f3d4f341..5084e420e1cca26387bd9e4b63b501ea1c49a6d3 100644 (file)
@@ -26,7 +26,7 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 import static org.mockito.internal.verification.VerificationModeFactory.times;
-import static org.sonar.server.rule.RuleTesting.XOO_X1;
+import static org.sonar.db.rule.RuleTesting.XOO_X1;
 
 public class RuleRepositoryImplTest {
 
index df0a3d4c9d9085128b5099a4b9ddad9f946f5ec1..becc308bc91d4b37b99d98447148d3b0d64080bb 100644 (file)
@@ -28,7 +28,7 @@ import org.sonar.server.computation.component.Component;
 import static java.util.Arrays.asList;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
-import static org.sonar.server.rule.RuleTesting.XOO_X1;
+import static org.sonar.db.rule.RuleTesting.XOO_X1;
 
 public class RuleTagsCopierTest {
 
index 15c46891992d0fbedbee93bfc54792e9e1db5d11..5d7f8309e1f93aff4c04a8000324a5995737255c 100644 (file)
@@ -43,7 +43,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.server.component.db.ComponentDao;
-import org.sonar.server.component.db.SnapshotDao;
+import org.sonar.db.component.SnapshotDao;
 import org.sonar.server.computation.batch.BatchReportReader;
 import org.sonar.server.computation.batch.BatchReportReaderRule;
 import org.sonar.server.computation.component.Component;
@@ -53,7 +53,7 @@ import org.sonar.server.computation.metric.Metric;
 import org.sonar.server.computation.metric.MetricImpl;
 import org.sonar.server.computation.metric.MetricRepository;
 import org.sonar.server.db.DbClient;
-import org.sonar.server.measure.persistence.MeasureDao;
+import org.sonar.db.measure.MeasureDao;
 import org.sonar.server.metric.persistence.MetricDao;
 
 import static com.google.common.collect.FluentIterable.from;
index 632569fa956cd88888d5105f8c5919340dcef524..943f6a67596fd9f6f62bb630b1c4fdeb4de99646 100644 (file)
@@ -37,7 +37,7 @@ import org.sonar.batch.protocol.output.BatchReport;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.server.component.db.ComponentDao;
-import org.sonar.server.component.db.SnapshotDao;
+import org.sonar.db.component.SnapshotDao;
 import org.sonar.server.computation.batch.BatchReportReaderRule;
 import org.sonar.server.computation.batch.TreeRootHolderRule;
 import org.sonar.server.computation.component.Component;
index 1cdc8389733b087af01e425a9acf52834f7c4c41..79fced156a8bea5f689c9c48c30eabb5e712b846 100644 (file)
@@ -38,7 +38,7 @@ import org.sonar.db.DbTester;
 import org.sonar.db.debt.CharacteristicDao;
 import org.sonar.server.component.ComponentTesting;
 import org.sonar.server.component.db.ComponentDao;
-import org.sonar.server.component.db.SnapshotDao;
+import org.sonar.db.component.SnapshotDao;
 import org.sonar.server.computation.batch.BatchReportReaderRule;
 import org.sonar.server.computation.batch.TreeRootHolderRule;
 import org.sonar.server.computation.component.Component;
@@ -53,7 +53,7 @@ import org.sonar.server.computation.metric.MetricRepositoryImpl;
 import org.sonar.server.computation.period.Period;
 import org.sonar.server.computation.period.PeriodsHolderRule;
 import org.sonar.server.db.DbClient;
-import org.sonar.server.measure.persistence.MeasureDao;
+import org.sonar.db.measure.MeasureDao;
 import org.sonar.server.metric.persistence.MetricDao;
 import org.sonar.server.rule.db.RuleDao;
 import org.sonar.test.DbTests;
index 1203f3a8ac281cbbc34810fd219fd68a9fd71514..61384933f6b168a13a89f250acbed5a6b05d66d0 100644 (file)
@@ -33,7 +33,7 @@ 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.server.source.db.FileSourceDao;
+import org.sonar.db.source.FileSourceDao;
 import org.sonar.server.source.db.FileSourceTesting;
 import org.sonar.server.source.index.SourceLineDoc;
 import org.sonar.server.source.index.SourceLineIndexDefinition;
index ba2491deaa8b52aea28fe98407fb70118f40011b..a4b020c034a17d66b989ac6f4d96304a68eb11d3 100644 (file)
@@ -34,7 +34,7 @@ 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.server.source.db.FileSourceDao;
+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;
index abf452c57a493447a8d70f312d72766ef4035cd9..82c34394825eb4ff8d7e92c0e1e169015a726baf 100644 (file)
@@ -37,7 +37,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.server.component.ComponentTesting;
 import org.sonar.server.component.db.ComponentDao;
-import org.sonar.server.component.db.SnapshotDao;
+import org.sonar.db.component.SnapshotDao;
 import org.sonar.server.computation.batch.BatchReportReaderRule;
 import org.sonar.server.computation.batch.TreeRootHolderRule;
 import org.sonar.server.computation.component.Component;
index 47676ecf0c7249f877070ec611275f1da19a81ea..ff2e82e08d752c8bf2499d213435daa30d075530 100644 (file)
@@ -39,7 +39,7 @@ import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.component.DbIdsRepository;
 import org.sonar.server.computation.component.DumbComponent;
 import org.sonar.server.db.DbClient;
-import org.sonar.server.measure.persistence.MeasureDao;
+import org.sonar.db.measure.MeasureDao;
 import org.sonar.server.metric.persistence.MetricDao;
 import org.sonar.test.DbTests;
 
index a2294bb153071755732d537e9aaa11731c21f5c0..00b3962dd904a3bce0f2cb5ab6da4772a645dff8 100644 (file)
@@ -40,7 +40,7 @@ import org.sonar.server.computation.component.DumbComponent;
 import org.sonar.server.computation.event.Event;
 import org.sonar.server.computation.event.EventRepository;
 import org.sonar.server.db.DbClient;
-import org.sonar.server.event.db.EventDao;
+import org.sonar.db.event.EventDao;
 import org.sonar.test.DbTests;
 
 import static org.mockito.Matchers.any;
index a425810a066a4a697ecbfa509fcb67c6805f5ea3..cb22b25f35e8ec1f3909ac1a1154bc66b225532a 100644 (file)
@@ -44,7 +44,7 @@ import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.component.DumbComponent;
 import org.sonar.server.computation.language.LanguageRepository;
 import org.sonar.server.db.DbClient;
-import org.sonar.server.source.db.FileSourceDao;
+import org.sonar.db.source.FileSourceDao;
 import org.sonar.server.source.db.FileSourceDb;
 import org.sonar.test.DbTests;
 
index 07fea4201d738e63dccbd2aed9628049c1b7be6d..eb09904d24cd33b904ada18249c59ec842de6e9d 100644 (file)
@@ -34,15 +34,15 @@ import org.sonar.batch.protocol.output.BatchReport;
 import org.sonar.core.issue.DefaultIssue;
 import org.sonar.core.issue.DefaultIssueComment;
 import org.sonar.core.issue.FieldDiffs;
-import org.sonar.server.computation.issue.UpdateConflictResolver;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
+import org.sonar.db.issue.IssueDao;
 import org.sonar.server.computation.batch.BatchReportReaderRule;
 import org.sonar.server.computation.issue.IssueCache;
 import org.sonar.server.computation.issue.RuleCacheLoader;
 import org.sonar.server.computation.issue.RuleRepositoryImpl;
+import org.sonar.server.computation.issue.UpdateConflictResolver;
 import org.sonar.server.db.DbClient;
-import org.sonar.server.issue.db.IssueDao;
 import org.sonar.server.rule.db.RuleDao;
 
 import static org.mockito.Mockito.mock;
index 7d3ad333d7f3dd3a2bde70abcdb83ddd364fd45d..0380c1a868c08f8cf9735b86ac018d3ead0dd117 100644 (file)
@@ -47,7 +47,7 @@ import org.sonar.server.computation.measure.MeasureRepository;
 import org.sonar.server.computation.measure.MeasureRepositoryImpl;
 import org.sonar.server.computation.metric.MetricRepositoryRule;
 import org.sonar.server.db.DbClient;
-import org.sonar.server.measure.persistence.MeasureDao;
+import org.sonar.db.measure.MeasureDao;
 import org.sonar.server.metric.persistence.MetricDao;
 import org.sonar.server.rule.db.RuleDao;
 import org.sonar.test.DbTests;
index 28a82331bc3db563db1037410e9a4da8cfe14729..bd95ab9ec83db835fa6a7321704aea9b8e268852 100644 (file)
@@ -40,7 +40,7 @@ import org.sonar.server.computation.metric.Metric;
 import org.sonar.server.computation.metric.MetricImpl;
 import org.sonar.server.computation.metric.MetricRepository;
 import org.sonar.server.db.DbClient;
-import org.sonar.server.measure.persistence.MeasureDao;
+import org.sonar.db.measure.MeasureDao;
 import org.sonar.server.source.index.SourceLineIndex;
 
 import static org.mockito.Matchers.anyString;
index 5996fc35d2279a6ed156a4f94fb4984071d2c2b8..3c23953d7fa102cb942c2051da6bf129386dc10a 100644 (file)
@@ -32,7 +32,7 @@ import org.sonar.batch.protocol.Constants;
 import org.sonar.batch.protocol.output.BatchReport;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
-import org.sonar.server.component.db.ComponentLinkDao;
+import org.sonar.db.component.ComponentLinkDao;
 import org.sonar.server.computation.batch.BatchReportReaderRule;
 import org.sonar.server.computation.batch.TreeRootHolderRule;
 import org.sonar.server.computation.component.Component;
index d4c583cc7397b4e43f427a48db684a2df40dbe8e..24a4526ef5cb26d7a054ece694c59f5bb0831ab9 100644 (file)
@@ -39,7 +39,7 @@ import org.sonar.db.DbTester;
 import org.sonar.server.component.ComponentTesting;
 import org.sonar.server.component.SnapshotTesting;
 import org.sonar.server.component.db.ComponentDao;
-import org.sonar.server.component.db.SnapshotDao;
+import org.sonar.db.component.SnapshotDao;
 import org.sonar.server.computation.batch.BatchReportReaderRule;
 import org.sonar.server.computation.batch.TreeRootHolderRule;
 import org.sonar.server.computation.component.Component;
index cf96586ebe9ee072fe64eb8bc7fac0c54c5b28f4..29a9cd6613404300c913d855df518204945fbe88 100644 (file)
@@ -43,7 +43,7 @@ import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.component.DumbComponent;
 import org.sonar.server.computation.component.FileAttributes;
 import org.sonar.server.db.DbClient;
-import org.sonar.server.source.db.FileSourceDao;
+import org.sonar.db.source.FileSourceDao;
 import org.sonar.server.source.db.FileSourceDb;
 
 import static org.assertj.core.api.Assertions.assertThat;
index 0e6362328d45fbccb17a049f148cdcfd5890c0e4..eae3c53a99e4282deb21eca715f78a169ca840fc 100644 (file)
@@ -28,7 +28,7 @@ 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.component.db.SnapshotDao;
+import org.sonar.db.component.SnapshotDao;
 import org.sonar.server.computation.batch.TreeRootHolderRule;
 import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.component.DbIdsRepository;
index 6c9d67d28c8764b1b7a3d4b3f2b71c2ec2a78c7b..baa9bbd924e89ccade143af8c6a6d610ff6f3b8f 100644 (file)
@@ -38,7 +38,7 @@ import org.sonar.db.DbTester;
 import org.sonar.server.component.ComponentTesting;
 import org.sonar.server.component.SnapshotTesting;
 import org.sonar.server.component.db.ComponentDao;
-import org.sonar.server.component.db.SnapshotDao;
+import org.sonar.db.component.SnapshotDao;
 import org.sonar.server.computation.batch.BatchReportReaderRule;
 import org.sonar.server.computation.batch.TreeRootHolderRule;
 import org.sonar.server.computation.component.Component;
diff --git a/server/sonar-server/src/test/java/org/sonar/server/dashboard/db/WidgetDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/dashboard/db/WidgetDaoTest.java
deleted file mode 100644 (file)
index 7d8d059..0000000
+++ /dev/null
@@ -1,71 +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.dashboard.db;
-
-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.db.dashboard.WidgetDto;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.db.MyBatis;
-import org.sonar.test.DbTests;
-
-import java.util.Collection;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-@Category(DbTests.class)
-public class WidgetDaoTest {
-
-  WidgetDao dao;
-
-  @Rule
-  public DbTester dbTester = new DbTester();
-
-  private DbSession session;
-
-  @Before
-  public void setUp() {
-    dao = new WidgetDao(dbTester.myBatis());
-    session = dbTester.myBatis().openSession(false);
-  }
-
-  @After
-  public void tearDown() {
-    MyBatis.closeQuietly(session);
-  }
-
-  @Test
-  public void should_select_all() {
-    dbTester.prepareDbUnit(this.getClass(), "before.xml");
-    session.commit();
-
-    Collection<WidgetDto> widgets = dao.findAll(session);
-    assertThat(widgets).hasSize(5);
-    for (WidgetDto widget : widgets) {
-      assertThat(widget.getId()).isNotNull();
-      assertThat(widget.getName()).isNotNull();
-      assertThat(widget.getDescription()).isNotNull();
-    }
-  }
-}
index 59d860f1dc9be22c1984cdf633b3692d3ada39ab..afd5995cef8d479b7680b2065e5004647033d6e8 100644 (file)
@@ -43,8 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class BaseDaoTest {
 
   @ClassRule
-  public static DbTester db = new DbTester()
-    .schema(BaseDaoTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, BaseDaoTest.class, "schema.sql");
 
   private static final String DTO_ALIAS = "fake";
 
diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/DatabaseCheckerTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/DatabaseCheckerTest.java
deleted file mode 100644 (file)
index da0e53d..0000000
+++ /dev/null
@@ -1,116 +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.db;
-
-import org.apache.commons.lang.StringUtils;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.sonar.api.utils.MessageException;
-import org.sonar.db.Database;
-import org.sonar.db.dialect.Dialect;
-import org.sonar.db.dialect.H2;
-import org.sonar.db.dialect.MySql;
-import org.sonar.db.dialect.Oracle;
-
-import java.sql.SQLException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class DatabaseCheckerTest {
-
-  @Test
-  public void requires_oracle_driver_11_2() throws Exception {
-    Database db = mockDb(new Oracle(), "11.2.1", "11.2.0.0.1");
-    new DatabaseChecker(db).start();
-    // no error
-
-    db = mockDb(new Oracle(), "11.2.1", "11.3.1");
-    new DatabaseChecker(db).start();
-    // no error
-
-    db = mockDb(new Oracle(), "11.2.1", "12.0.2");
-    new DatabaseChecker(db).start();
-    // no error
-
-    db = mockDb(new Oracle(), "11.2.1", "11.1.0.2");
-    try {
-      new DatabaseChecker(db).start();
-      fail();
-    } catch (MessageException e) {
-      assertThat(e).hasMessage("Unsupported Oracle JDBC driver version: 11.1.0.2. Minimal required version is 11.2.");
-    }
-  }
-
-  @Test
-  public void requires_oracle_11g_or_greater() throws Exception {
-    // oracle 11.0 is ok
-    Database db = mockDb(new Oracle(), "11.0.1", "11.2.0.0.1");
-    new DatabaseChecker(db).start();
-
-    // oracle 11.1 is ok
-    db = mockDb(new Oracle(), "11.1.1", "11.2.0.0.1");
-    new DatabaseChecker(db).start();
-
-    // oracle 11.2 is ok
-    db = mockDb(new Oracle(), "11.2.1", "11.2.0.0.1");
-    new DatabaseChecker(db).start();
-
-    // oracle 12 is ok
-    db = mockDb(new Oracle(), "12.0.1", "11.2.0.0.1");
-    new DatabaseChecker(db).start();
-
-    // oracle 10 is not supported
-    db = mockDb(new Oracle(), "10.2.1",  "11.2.0.0.1");
-    try {
-      new DatabaseChecker(db).start();
-      fail();
-    } catch (MessageException e) {
-      assertThat(e).hasMessage("Unsupported Oracle version: 10.2.1. Minimal required version is 11.");
-    }
-  }
-
-  @Test
-  public void log_warning_if_h2() throws Exception {
-    Database db = mockDb(new H2(), "13.4", "13.4");
-    DatabaseChecker checker = new DatabaseChecker(db);
-    checker.start();
-    checker.stop();
-    // TODO test log
-  }
-
-  @Test
-  public void do_not_fail_if_mysql() throws Exception {
-    Database db = mockDb(new MySql(), "5.7", "5.7");
-    new DatabaseChecker(db).start();
-    // no error
-  }
-
-  private Database mockDb(Dialect dialect, String dbVersion, String driverVersion) throws SQLException {
-    Database db = mock(Database.class, Mockito.RETURNS_DEEP_STUBS);
-    when(db.getDialect()).thenReturn(dialect);
-    when(db.getDataSource().getConnection().getMetaData().getDatabaseMajorVersion()).thenReturn(Integer.parseInt(StringUtils.substringBefore(dbVersion, ".")));
-    when(db.getDataSource().getConnection().getMetaData().getDatabaseProductVersion()).thenReturn(dbVersion);
-    when(db.getDataSource().getConnection().getMetaData().getDriverVersion()).thenReturn(driverVersion);
-    return db;
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/ResultSetIteratorTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/ResultSetIteratorTest.java
deleted file mode 100644 (file)
index 3aa7f6a..0000000
+++ /dev/null
@@ -1,177 +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.db;
-
-import org.apache.commons.dbutils.DbUtils;
-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.db.DbTester;
-import org.sonar.test.DbTests;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.NoSuchElementException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.fail;
-
-@Category(DbTests.class)
-public class ResultSetIteratorTest {
-
-  @Rule
-  public DbTester dbTester = new DbTester().schema(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 fake order by id");
-    FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt);
-
-    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);
-
-    // call next() without calling hasNext()
-    assertThat(iterator.next()).isEqualTo(30);
-    assertThat(iterator.hasNext()).isFalse();
-
-    try {
-      iterator.next();
-      fail();
-    } catch (NoSuchElementException e) {
-      // ok
-    }
-
-    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 fake where id < 0");
-    FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt);
-
-    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 fake 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);
-
-    iterator.close();
-    assertThat(rs.isClosed()).isTrue();
-    stmt.close();
-  }
-
-  @Test
-  public void remove_row_is_not_supported() throws Exception {
-    PreparedStatement stmt = connection.prepareStatement("select * from fake order by id");
-    FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt);
-
-    try {
-      iterator.remove();
-      fail();
-    } catch (UnsupportedOperationException ok) {
-      // ok
-    }
-
-    iterator.close();
-  }
-
-  @Test
-  public void fail_to_read_row() throws Exception {
-    dbTester.prepareDbUnit(getClass(), "feed.xml");
-
-    PreparedStatement stmt = connection.prepareStatement("select * from fake 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();
-  }
-
-  private static class FirstIntColumnIterator extends ResultSetIterator<Integer> {
-
-    public FirstIntColumnIterator(PreparedStatement stmt) throws SQLException {
-      super(stmt);
-    }
-
-    public FirstIntColumnIterator(ResultSet rs) {
-      super(rs);
-    }
-
-    @Override
-    protected Integer read(ResultSet rs) throws SQLException {
-      return rs.getInt(1);
-    }
-  }
-
-  private static class FailIterator extends ResultSetIterator<Integer> {
-
-    public FailIterator(PreparedStatement stmt) throws SQLException {
-      super(stmt);
-    }
-
-    @Override
-    protected Integer read(ResultSet rs) throws SQLException {
-      // column does not exist
-      return rs.getInt(1234);
-    }
-  }
-}
index 5ae0b495006c1473108b24611f915b7b4ddbda06..49e5bf4a3ff51c410cb7127256e59764a5f43e05 100644 (file)
@@ -25,6 +25,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.junit.rules.ExpectedException;
+import org.sonar.api.utils.System2;
 import org.sonar.db.AbstractDaoTestCase;
 import org.sonar.db.BatchSession;
 import org.sonar.db.DbTester;
@@ -44,7 +45,7 @@ import static org.junit.Assert.fail;
 public class BaseDataChangeTest extends AbstractDaoTestCase {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(BaseDataChangeTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, BaseDataChangeTest.class, "schema.sql");
 
   @Rule
   public ExpectedException thrown = ExpectedException.none();
index 5d377c2c6fc9afa28558480cf99dc6e5604e575e..0f355a3e7ee7c97bac53c49d22b9be0a8eb1789e 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.db.migrations.v36;
 import org.junit.ClassRule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -29,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class ViolationMigrationTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(ViolationMigrationTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, ViolationMigrationTest.class, "schema.sql");
 
   @Test
   public void migrate_violations() {
index a98a6615f9493222d3c60699b15095b8d69da5c6..c6ee1dfb608a926a5860b8e29471f3144724ec03 100644 (file)
@@ -21,13 +21,14 @@ package org.sonar.server.db.migrations.v42;
 
 import org.junit.ClassRule;
 import org.junit.Test;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.server.db.migrations.MigrationStep;
 
 public class CompleteIssueMessageMigrationTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(CompleteIssueMessageMigrationTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, CompleteIssueMessageMigrationTest.class, "schema.sql");
 
   MigrationStep migration = new CompleteIssueMessageMigrationStep(db.database());
 
index 8fa88c87fd2ba748aff3d305c14ce28c7cb310e8..bb1daab2e9b40f2d40d07a559a017ee366ecd35a 100644 (file)
@@ -21,13 +21,14 @@ package org.sonar.server.db.migrations.v42;
 
 import org.junit.ClassRule;
 import org.junit.Test;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.server.db.migrations.MigrationStep;
 
 public class PackageKeysMigrationTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(PackageKeysMigrationTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, PackageKeysMigrationTest.class, "schema.sql");
 
   MigrationStep migration = new PackageKeysMigrationStep(db.database());
 
index be103757c156ae84d2bf42d2be327f3a96d2da93..58b65c0e6266dcb93a254a2fff14e5b716abf0bb 100644 (file)
@@ -42,7 +42,7 @@ import static org.mockito.Mockito.when;
 public class ConvertIssueDebtToMinutesMigrationStepTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(ConvertIssueDebtToMinutesMigrationStepTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, ConvertIssueDebtToMinutesMigrationStepTest.class, "schema.sql");
 
   @Mock
   System2 system2;
index f644089664919d71f297d3edd1080207dcf850b9..0fd6e8ae4aa17cc2d68933e16b886e5d7071850c 100644 (file)
@@ -26,6 +26,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.db.property.PropertiesDao;
 import org.sonar.db.property.PropertyDto;
@@ -36,7 +37,7 @@ import static org.mockito.Mockito.when;
 public class DevelopmentCostMeasuresMigrationStepTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(DevelopmentCostMeasuresMigrationStepTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, DevelopmentCostMeasuresMigrationStepTest.class, "schema.sql");
 
   @Mock
   PropertiesDao propertiesDao;
index ef4a0d175af5b08bf7f1b57fd319110b9d085c29..0e6d06c1fe8f7c064f2fdfd45518acc74c62b489 100644 (file)
@@ -39,7 +39,7 @@ import static org.mockito.Mockito.when;
 public class IssueChangelogMigrationStepTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(IssueChangelogMigrationStepTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, IssueChangelogMigrationStepTest.class, "schema.sql");
 
   @Mock
   System2 system2;
@@ -65,7 +65,7 @@ public class IssueChangelogMigrationStepTest {
 
     migration.execute();
 
-    db.assertDbUnit(getClass(), "migrate_issue_changelog_debt_result.xml", new String[]{"updated_at"}, "issue_changes");
+    db.assertDbUnit(getClass(), "migrate_issue_changelog_debt_result.xml", new String[] {"updated_at"}, "issue_changes");
   }
 
   @Test
index 9c2098288fe38f16e71dd2ff276ef47d400a894e..9df9e8c62a60cfe7b685a9bc4ff6ca7438c2e5c3 100644 (file)
@@ -36,7 +36,7 @@ import static org.mockito.Mockito.when;
 public class NotResolvedIssuesOnRemovedComponentsMigrationStepTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(NotResolvedIssuesOnRemovedComponentsMigrationStepTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, NotResolvedIssuesOnRemovedComponentsMigrationStepTest.class, "schema.sql");
 
   @Mock
   System2 system2;
index 2a95d9aff1d42eb99c5c3737713f56113b3f2326..faf17f4dd385a31a5cf649118369dc8183266a70 100644 (file)
@@ -23,12 +23,13 @@ package org.sonar.server.db.migrations.v43;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 
 public class RequirementMeasuresMigrationStepTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(RequirementMeasuresMigrationStepTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, RequirementMeasuresMigrationStepTest.class, "schema.sql");
 
   RequirementMeasuresMigrationStep migration;
 
index b50adc14f4d035fd0f8ee3f88c1c14cb73256786..63f0d0df7f834c871617990c82537f39c15b8a0d 100644 (file)
@@ -26,6 +26,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.db.property.PropertiesDao;
 import org.sonar.db.property.PropertyDto;
@@ -36,7 +37,7 @@ import static org.mockito.Mockito.when;
 public class TechnicalDebtMeasuresMigrationStepTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(TechnicalDebtMeasuresMigrationStepTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, TechnicalDebtMeasuresMigrationStepTest.class, "schema.sql");
 
   @Mock
   PropertiesDao propertiesDao;
index c48f20771e4294b58623e8177b27eb60df3a7629..0f312ca080e1072237c0e25a5cf386299e2e9402 100644 (file)
@@ -27,7 +27,7 @@ import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
-import org.sonar.server.activity.db.ActivityDao;
+import org.sonar.db.activity.ActivityDao;
 import org.sonar.server.db.DbClient;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -37,7 +37,7 @@ import static org.mockito.Mockito.when;
 public class ChangeLogMigrationTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(ChangeLogMigrationTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, ChangeLogMigrationTest.class, "schema.sql");
 
   System2 system2 = mock(System2.class);
   DbClient dbClient;
index c9823f04f56aadcaf812d754c4ebb5a0b2525e82..7b83ac06d5c51dc3e2d2d12f442f658fdb4bef1c 100644 (file)
@@ -23,6 +23,7 @@ package org.sonar.server.db.migrations.v44;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.server.db.DbClient;
 
@@ -35,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class ConvertProfileMeasuresMigrationTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(ConvertProfileMeasuresMigrationTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, ConvertProfileMeasuresMigrationTest.class, "schema.sql");
 
   ConvertProfileMeasuresMigrationStep migration;
 
index aca0c351dcbd9e1a4fb778d798f0641414c1c3f7..93a25de9a565a3a39fc6b36221d228af748b120e 100644 (file)
@@ -37,7 +37,7 @@ import static org.mockito.Mockito.when;
 public class FeedQProfileDatesMigrationTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(FeedQProfileDatesMigrationTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedQProfileDatesMigrationTest.class, "schema.sql");
 
   FeedQProfileDatesMigrationStep migration;
 
index 770fb78dd872a9e8b85ec61c4e91b0ff56a0e4fa..f54e91d76493317eb13b437543efdf54d9ae501f 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.db.migrations.v44;
 
 import org.junit.ClassRule;
 import org.junit.Test;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 
 import java.util.List;
@@ -32,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class FeedQProfileKeysMigrationTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(FeedQProfileKeysMigrationTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedQProfileKeysMigrationTest.class, "schema.sql");
 
   @Test
   public void feed_keys() throws Exception {
index 5c0e4ac744a0f7f3b49a85977c85b4ed986a31df..cc1b1697192d108446d43f370355e4b7de554dbf 100644 (file)
@@ -36,7 +36,7 @@ import static org.mockito.Mockito.when;
 public class IssueActionPlanKeyMigrationTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(IssueActionPlanKeyMigrationTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, IssueActionPlanKeyMigrationTest.class, "schema.sql");
 
   @Mock
   System2 system2;
index b863f7fb2d8b3c52e77f35f5ddbdbdc78589c718..315bc16133c593f9327b3884b941fc6518e8f6b3 100644 (file)
@@ -25,13 +25,14 @@ import org.junit.ClassRule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.runners.MockitoJUnitRunner;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 
 @RunWith(MockitoJUnitRunner.class)
 public class MeasureDataMigrationTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(MeasureDataMigrationTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, MeasureDataMigrationTest.class, "schema.sql");
 
   MeasureDataMigrationStep migration;
 
index b58f35660f74bd8c1a3fa12edfcbd6fa37084e3e..fd993bff0bdce9a4d3b310296cfd54e659206197 100644 (file)
@@ -33,7 +33,7 @@ import static org.mockito.Mockito.when;
 public class AddMissingRuleParameterDefaultValuesMigrationTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(AddMissingRuleParameterDefaultValuesMigrationTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, AddMissingRuleParameterDefaultValuesMigrationTest.class, "schema.sql");
 
   MigrationStep migration;
   System2 system = mock(System2.class);
index d54558542004d1890a331d7123fa6bd0b11aa05f..a82f93792fcab08b4122f23c21e29f0320a0e91a 100644 (file)
@@ -23,6 +23,7 @@ package org.sonar.server.db.migrations.v45;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.db.migrations.MigrationStep;
@@ -36,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class DeleteMeasuresOnDeletedProfilesMigrationTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(DeleteMeasuresOnDeletedProfilesMigrationTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, DeleteMeasuresOnDeletedProfilesMigrationTest.class, "schema.sql");
 
   MigrationStep migration;
 
index f8e732e4346cbd715121136590a5ddad8ec149ed..ef738d505eaad06a67fd39f082ac1f5ab6d6a073 100644 (file)
@@ -34,7 +34,7 @@ import static org.mockito.Mockito.when;
 public class AddMissingCustomRuleParametersMigrationTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(AddMissingCustomRuleParametersMigrationTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, AddMissingCustomRuleParametersMigrationTest.class, "schema.sql");
 
   MigrationStep migration;
   System2 system = mock(System2.class);
index cd4c5c60cc15181a164a5bbff7549258100cbe35..b9dae4d600b0ca7f66f82dce4e1ab260c3fac142 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.server.db.migrations.v451;
 
 import org.junit.ClassRule;
 import org.junit.Test;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.server.db.migrations.MigrationStep;
 
@@ -29,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class DeleteUnescapedActivitiesTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(DeleteUnescapedActivitiesTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, DeleteUnescapedActivitiesTest.class, "schema.sql");
 
   MigrationStep migration;
 
index 9460abe4a4a39e3ae126e6e641fd769eb4b723f5..9abd9a8948451e380afd6f43bb9b9aca3d9ef052 100644 (file)
@@ -41,7 +41,7 @@ import static org.mockito.Mockito.when;
 public class FeedFileSourcesTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(FeedFileSourcesTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedFileSourcesTest.class, "schema.sql");
 
   private static final long NOW = 1414770242000L;
 
index 9b2d498301720f59723b10822eeb222332b4cc86..889512860f18a6e9057cf7746f5fedfea2e30e2d 100644 (file)
@@ -33,7 +33,7 @@ import static org.mockito.Mockito.when;
 public class FeedIssueLongDatesTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(FeedIssueLongDatesTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedIssueLongDatesTest.class, "schema.sql");
 
   @Test
   public void execute() throws Exception {
index 78e4b4fcb260135b721b6b24a6d35c6021c2b41c..760fd7e70587f7e426831136440b3c3228e288b3 100644 (file)
@@ -33,7 +33,7 @@ import static org.mockito.Mockito.when;
 public class InsertProjectsAuthorizationUpdatedAtMigrationTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(InsertProjectsAuthorizationUpdatedAtMigrationTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, InsertProjectsAuthorizationUpdatedAtMigrationTest.class, "schema.sql");
 
   MigrationStep migration;
   System2 system = mock(System2.class);
index 7548811cf6238b175e8065b81d1ef13ff99eff5f..e5b2cb634b5e12d99b4903749330807b47a11596 100644 (file)
@@ -25,6 +25,7 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.version.v50.Component;
@@ -37,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class PopulateProjectsUuidColumnsMigrationTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(PopulateProjectsUuidColumnsMigrationTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, PopulateProjectsUuidColumnsMigrationTest.class, "schema.sql");
 
   DbSession session;
 
index 50e117e9a3c54bf83bc942b68518e70735dc4cb7..fee6b50959a8a3b2298d005914bd7e92d73560fc 100644 (file)
@@ -33,7 +33,7 @@ import static org.mockito.Mockito.when;
 public class RemoveSortFieldFromIssueFiltersMigrationTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(RemoveSortFieldFromIssueFiltersMigrationTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, RemoveSortFieldFromIssueFiltersMigrationTest.class, "schema.sql");
 
   MigrationStep migration;
   System2 system = mock(System2.class);
index 11f82c5557fb8a50d66f888a8c9e14a954085611..964eac8bba28398596c76428e7bf75c1e676c486 100644 (file)
@@ -33,7 +33,7 @@ import static org.mockito.Mockito.when;
 public class ReplaceIssueFiltersProjectKeyByUuidTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(ReplaceIssueFiltersProjectKeyByUuidTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, ReplaceIssueFiltersProjectKeyByUuidTest.class, "schema.sql");
 
   MigrationStep migration;
   System2 system = mock(System2.class);
index 1d275951535f5f3b6dee123ba1d3edcce24ae3cb..547350d0dc49e1e0ee2d692f320a8f79620a22d0 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.db.migrations.v51;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.server.db.migrations.MigrationStep;
 
@@ -30,7 +31,7 @@ import java.sql.Types;
 public class AddIssuesColumnsTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(AddIssuesColumnsTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, AddIssuesColumnsTest.class, "schema.sql");
 
   MigrationStep migration;
 
index 611b36302a89b2f21b295df44c171491156ef199..ab3ff130e90dba29a25c0f94d5f421790c8ec796 100644 (file)
@@ -36,7 +36,7 @@ import static org.mockito.Mockito.when;
 public class AddNewCharacteristicsTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(AddNewCharacteristicsTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, AddNewCharacteristicsTest.class, "schema.sql");
 
   MigrationStep migration;
 
index 425ebef8ddf8269011f6271c84f255c1d8d1c5c5..794dfd2321c72444c01d269ffc7fbf89f53b6a7f 100644 (file)
@@ -37,7 +37,7 @@ import static org.mockito.Mockito.when;
 public class CopyScmAccountsFromAuthorsToUsersTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(CopyScmAccountsFromAuthorsToUsersTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, CopyScmAccountsFromAuthorsToUsersTest.class, "schema.sql");
 
   MigrationStep migration;
   System2 system = mock(System2.class);
index c60ff98f2a5a9267d467246a4deb67114c9916ae..518d9a94818252e007d23a83cc27faa834497500 100644 (file)
@@ -32,7 +32,7 @@ import static org.mockito.Mockito.when;
 
 public class FeedAnalysisReportsLongDatesTest {
   @ClassRule
-  public static DbTester db = new DbTester().schema(FeedAnalysisReportsLongDatesTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedAnalysisReportsLongDatesTest.class, "schema.sql");
 
   @Test
   public void execute() throws Exception {
index 996f5541efd40d9f83b7f8d3327322b538aab343..b13564590472cf62401ea73b5497170cf2b1b8cb 100644 (file)
@@ -34,7 +34,7 @@ import static org.sonar.api.utils.DateUtils.parseDate;
 
 public class FeedEventsLongDatesTest {
   @ClassRule
-  public static DbTester db = new DbTester().schema(FeedEventsLongDatesTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedEventsLongDatesTest.class, "schema.sql");
 
   @Before
   public void before() {
index 050bcd4acb9d58881a355e34c63c4afa64cf57ef..fd8f492e2780dbd8d5852090d7c498f8b7273d0f 100644 (file)
@@ -24,6 +24,7 @@ import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.db.source.FileSourceDto;
 import org.sonar.server.db.migrations.MigrationStep;
@@ -43,7 +44,7 @@ public class FeedFileSourcesBinaryDataTest {
   public ExpectedException thrown = ExpectedException.none();
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(FeedFileSourcesBinaryDataTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedFileSourcesBinaryDataTest.class, "schema.sql");
 
   @Test
   public void convert_csv_to_protobuf() throws Exception {
index 3dcb9dbd0b3709ff85e5096d9e418793282e39b0..3d1d9b2eceabd0334a6555245986c4f608a1ffc9 100644 (file)
@@ -32,7 +32,7 @@ import static org.mockito.Mockito.when;
 
 public class FeedIssueChangesLongDatesTest {
   @ClassRule
-  public static DbTester db = new DbTester().schema(FeedIssueChangesLongDatesTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedIssueChangesLongDatesTest.class, "schema.sql");
 
   @Test
   public void execute() throws Exception {
index c7cb885211ce291da0a12bbfd82ddd46c4e155cb..a74873863d60949481fc57cc76d9eb1adf87970c 100644 (file)
@@ -23,11 +23,12 @@ package org.sonar.server.db.migrations.v51;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 
 public class FeedIssueComponentUuidsTest {
   @ClassRule
-  public static DbTester db = new DbTester().schema(FeedIssueComponentUuidsTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedIssueComponentUuidsTest.class, "schema.sql");
 
   FeedIssueComponentUuids sut;
 
index 9ca104a837bf9c8deda5ee07c5a2ecc32108ca54..613591cd576c72fde720d60199008381282697cd 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.db.migrations.v51;
 
+import java.util.Date;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
@@ -26,15 +27,13 @@ import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 
-import java.util.Date;
-
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 public class FeedIssueTagsTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(FeedIssueTagsTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedIssueTagsTest.class, "schema.sql");
 
   FeedIssueTags migration;
 
index cc818e5b5eec25bf87e4f2c90f06bd9b20d191f5..b323eab74015d8559fb422584b1858f358fb46a7 100644 (file)
@@ -33,7 +33,7 @@ import static org.sonar.api.utils.DateUtils.parseDate;
 
 public class FeedIssuesLongDatesTest {
   @ClassRule
-  public static DbTester db = new DbTester().schema(FeedIssuesLongDatesTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedIssuesLongDatesTest.class, "schema.sql");
 
   @Test
   public void execute() throws Exception {
index 01007f370f2ec15d0f44d4273968ddcb188aea39..66d2dd201f24fd38204fffada105612789a00f49 100644 (file)
@@ -34,7 +34,7 @@ import static org.sonar.api.utils.DateUtils.parseDate;
 
 public class FeedManualMeasuresLongDatesTest {
   @ClassRule
-  public static DbTester db = new DbTester().schema(FeedManualMeasuresLongDatesTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedManualMeasuresLongDatesTest.class, "schema.sql");
 
   @Before
   public void before() {
index 172ea26ba2a92973cbdf4746ac2df68672874b78..1b16d9ebc93705eb7d28ad7871d7f91a9b11ba9c 100644 (file)
@@ -34,7 +34,7 @@ import static org.sonar.api.utils.DateUtils.parseDate;
 
 public class FeedSemaphoresLongDatesTest {
   @ClassRule
-  public static DbTester db = new DbTester().schema(FeedSemaphoresLongDatesTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedSemaphoresLongDatesTest.class, "schema.sql");
 
   @Before
   public void before() {
index bcdeaa857578b8b0309b6ae02d0c20f4c727f6d9..0638f9a0f9b2fbbe150c3decb4a3307169e7c68b 100644 (file)
@@ -33,7 +33,7 @@ import static org.sonar.api.utils.DateUtils.parseDate;
 
 public class FeedSnapshotsLongDatesTest {
   @ClassRule
-  public static DbTester db = new DbTester().schema(FeedSnapshotsLongDatesTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedSnapshotsLongDatesTest.class, "schema.sql");
 
   @Test
   public void execute() throws Exception {
index 25b2d3551c3cb60a997b55e82d5e7294424a0f33..4ddebaec50dc81f8f8e03e7174837a2c18c1793a 100644 (file)
@@ -33,7 +33,7 @@ import static org.mockito.Mockito.when;
 public class FeedUsersLongDatesTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(FeedUsersLongDatesTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedUsersLongDatesTest.class, "schema.sql");
 
   @Test
   public void execute() throws Exception {
index e004d2c4b7efa4dcd801a3921b8511580c62c2cf..9d019b9be009f99769e390f34f4b343d97d8cadf 100644 (file)
@@ -22,13 +22,14 @@ package org.sonar.server.db.migrations.v51;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.server.db.migrations.MigrationStep;
 
 public class RemovePermissionsOnModulesMigrationTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(RemovePermissionsOnModulesMigrationTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, RemovePermissionsOnModulesMigrationTest.class, "schema.sql");
 
   MigrationStep migration;
 
index dc27518622e7e2f96bb97229a2aecfb2706fa180..38993ee081ef2e23fc5958d9eaa0ed484c9f3573 100644 (file)
@@ -33,7 +33,7 @@ import static org.mockito.Mockito.when;
 public class RenameComponentRelatedParamsInIssueFiltersMigrationTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(RenameComponentRelatedParamsInIssueFiltersMigrationTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, RenameComponentRelatedParamsInIssueFiltersMigrationTest.class, "schema.sql");
 
   MigrationStep migration;
   System2 system = mock(System2.class);
index 541ee1faf30a13f71398c7ac779606b42ecd96b3..d780cf31b98d623a225f4dc56c15acd198c934c2 100644 (file)
@@ -30,7 +30,7 @@ import org.sonar.server.db.migrations.MigrationStep;
 public class UpdateProjectsModuleUuidPathTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(UpdateProjectsModuleUuidPathTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, UpdateProjectsModuleUuidPathTest.class, "schema.sql");
 
   MigrationStep migration;
 
index 03eca8a0adfc8fb352c76bcf0479c418532710ea..3711965faf42b6da04aa2bdc18518692f9578429 100644 (file)
@@ -24,12 +24,13 @@ import java.sql.Types;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 
 public class AddManualMeasuresComponentUuidColumnTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(AddManualMeasuresComponentUuidColumnTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, AddManualMeasuresComponentUuidColumnTest.class, "schema.sql");
 
   AddManualMeasuresComponentUuidColumn sut;
 
index d733f25596a6295902dec618b21fbb057b840f80..b556338893bb0ef7c357c664c138fec4f72495c2 100644 (file)
@@ -23,13 +23,14 @@ package org.sonar.server.db.migrations.v52;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.server.db.migrations.MigrationStep;
 
 public class FeedEventsComponentUuidTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(FeedEventsComponentUuidTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedEventsComponentUuidTest.class, "schema.sql");
 
   MigrationStep migration;
 
index f39d1e0c6888fb7ed0df91a2a7e520533ec01568..1f368e5ca3a0c33c6cd70239a2f0fcfd6877a564 100644 (file)
@@ -23,13 +23,14 @@ package org.sonar.server.db.migrations.v52;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.server.db.migrations.MigrationStep;
 
 public class FeedFileSourcesDataTypeTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(FeedFileSourcesDataTypeTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedFileSourcesDataTypeTest.class, "schema.sql");
 
   MigrationStep migration;
 
index ff79022f42a0ef77e27ee4f90fcd5ba4a232a03e..bb392df7ac8f98da0ef6094970caaaf61f1aa1b3 100644 (file)
@@ -23,12 +23,13 @@ package org.sonar.server.db.migrations.v52;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 
 public class FeedManualMeasuresComponentUuidTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(FeedManualMeasuresComponentUuidTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedManualMeasuresComponentUuidTest.class, "schema.sql");
 
   FeedManualMeasuresComponentUuid sut;
 
index 078ed7b348ddef1cfefee234fd8f6ed935cc3653..63c680b6dd874cb61fc7d2a2cac40047cae5b994 100644 (file)
@@ -23,12 +23,13 @@ package org.sonar.server.db.migrations.v52;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.server.db.migrations.MigrationStep;
 
 public class FeedMetricsBooleansTest {
   @ClassRule
-  public static DbTester db = new DbTester().schema(FeedMetricsBooleansTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedMetricsBooleansTest.class, "schema.sql");
 
   MigrationStep migration;
 
index cea982f96ed32dfb54c85c3d21f5fddc48750f38..b2fcb227d5e99390602c201da844fad2da44a12f 100644 (file)
@@ -23,13 +23,14 @@ package org.sonar.server.db.migrations.v52;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.server.db.migrations.MigrationStep;
 
 public class FeedProjectLinksComponentUuidTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(FeedProjectLinksComponentUuidTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedProjectLinksComponentUuidTest.class, "schema.sql");
 
   MigrationStep migration;
 
index 75fff962568b05b74a6500522bf1d6de16553c60..0fb93eb8a5c02d702b07e4a81ec335cdba00d196 100644 (file)
@@ -23,13 +23,14 @@ package org.sonar.server.db.migrations.v52;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.server.db.migrations.MigrationStep;
 
 public class MoveProjectProfileAssociationTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(MoveProjectProfileAssociationTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, MoveProjectProfileAssociationTest.class, "schema.sql");
 
   MigrationStep migration;
 
index f6bdb94d675bc9e8a9f39a344718414dd50131c5..21b9eab4107845870b82105430451f5851902984 100644 (file)
@@ -23,13 +23,14 @@ package org.sonar.server.db.migrations.v52;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.server.db.migrations.MigrationStep;
 
 public class RemoveComponentLibrariesTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(RemoveComponentLibrariesTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, RemoveComponentLibrariesTest.class, "schema.sql");
 
   MigrationStep migration;
 
index 96bdf99c7faaa8ed2e6f219f08698c2440cb660b..51cd6cad239765be520510923a6f9512c2fc1d54 100644 (file)
@@ -23,13 +23,14 @@ package org.sonar.server.db.migrations.v52;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
+import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.server.db.migrations.MigrationStep;
 
 public class RemoveSnapshotLibrariesTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(RemoveSnapshotLibrariesTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, RemoveSnapshotLibrariesTest.class, "schema.sql");
 
   MigrationStep migration;
 
index 6dd6ad0f873bbb84dcf1974bc73e41da654abf55..31b90bb972f19ba10af6c4d4c34b0b25b509d04b 100644 (file)
@@ -25,7 +25,7 @@ import org.junit.Test;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.server.component.db.ComponentDao;
 import org.sonar.server.db.DbClient;
-import org.sonar.server.measure.persistence.MeasureDao;
+import org.sonar.db.measure.MeasureDao;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsTester;
 
index 0786e0bf6fae30c55de08880636a5ed73f7cc6b9..449adfdc1d87c757d371ec7e82ccc8f3d8bcbe19 100644 (file)
@@ -36,7 +36,7 @@ import org.sonar.db.DbSession;
 import org.sonar.server.component.db.ComponentDao;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.measure.persistence.MeasureDao;
+import org.sonar.db.measure.MeasureDao;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsTester;
 
diff --git a/server/sonar-server/src/test/java/org/sonar/server/event/db/EventDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/event/db/EventDaoTest.java
deleted file mode 100644 (file)
index f30b437..0000000
+++ /dev/null
@@ -1,118 +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.event.db;
-
-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.db.event.EventDto;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.test.DbTests;
-
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-@Category(DbTests.class)
-public class EventDaoTest {
-
-  @ClassRule
-  public static DbTester dbTester = new DbTester();
-
-  DbSession session;
-
-  EventDao dao;
-
-  @Before
-  public void setup() {
-    dbTester.truncateTables();
-    session = dbTester.myBatis().openSession(false);
-    dao = new EventDao();
-  }
-
-  @After
-  public void tearDown() {
-    session.close();
-  }
-
-  @Test
-  public void select_by_component_uuid() {
-    dbTester.prepareDbUnit(getClass(), "shared.xml");
-
-    List<EventDto> dtos = dao.selectByComponentUuid(session, "ABCD");
-    assertThat(dtos).hasSize(3);
-
-    dtos = dao.selectByComponentUuid(session, "BCDE");
-    assertThat(dtos).hasSize(1);
-
-    EventDto dto = dtos.get(0);
-    assertThat(dto.getId()).isEqualTo(4L);
-    assertThat(dto.getComponentUuid()).isEqualTo("BCDE");
-    assertThat(dto.getSnapshotId()).isEqualTo(1000L);
-    assertThat(dto.getName()).isEqualTo("1.0");
-    assertThat(dto.getCategory()).isEqualTo("Version");
-    assertThat(dto.getDescription()).isEqualTo("Version 1.0");
-    assertThat(dto.getData()).isEqualTo("some data");
-    assertThat(dto.getDate()).isEqualTo(1413407091086L);
-    assertThat(dto.getCreatedAt()).isEqualTo(1225630680000L);
-  }
-
-  @Test
-  public void return_different_categories() {
-    dbTester.prepareDbUnit(getClass(), "shared.xml");
-
-    List<EventDto> dtos = dao.selectByComponentUuid(session, "ABCD");
-    assertThat(dtos).extracting("category").containsOnly(EventDto.CATEGORY_ALERT, EventDto.CATEGORY_PROFILE, EventDto.CATEGORY_VERSION);
-  }
-
-  @Test
-  public void insert() {
-    dbTester.prepareDbUnit(getClass(), "empty.xml");
-
-    dao.insert(session, new EventDto()
-      .setName("1.0")
-      .setCategory(EventDto.CATEGORY_VERSION)
-      .setDescription("Version 1.0")
-      .setData("some data")
-      .setDate(1413407091086L)
-      .setComponentUuid("ABCD")
-      .setSnapshotId(1000L)
-      .setCreatedAt(1225630680000L)
-      );
-    session.commit();
-
-    dbTester.assertDbUnit(getClass(), "insert-result.xml", new String[]{"id"}, "events");
-  }
-
-  @Test
-  public void delete() {
-    dbTester.prepareDbUnit(getClass(), "delete.xml");
-
-    dao.delete(session, 1L);
-    session.commit();
-
-    assertThat(dbTester.countRowsOfTable("events")).isEqualTo(0);
-  }
-
-}
index 0334d107abce7873f47fc9d41405e180d7f53b5a..472ee85a00645a10badd60b33b9a3f8fbba4db83 100644 (file)
@@ -39,7 +39,7 @@ import org.sonar.db.property.PropertyDto;
 import org.sonar.server.component.ComponentTesting;
 import org.sonar.server.component.db.ComponentDao;
 import org.sonar.server.db.DbClient;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.user.ThreadLocalUserSession;
 import org.sonar.server.user.UserSession;
 
index 9500605c7ef50d91213e008d9da40d2b90623f1b..36d27f3c4578039687c52d3ef1c5e6890adb8314 100644 (file)
@@ -34,6 +34,7 @@ import org.sonar.api.security.DefaultGroups;
 import org.sonar.api.web.UserRole;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.SnapshotDto;
+import org.sonar.db.issue.IssueDao;
 import org.sonar.db.issue.IssueDto;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbSession;
@@ -42,13 +43,12 @@ import org.sonar.db.user.UserDto;
 import org.sonar.server.component.ComponentTesting;
 import org.sonar.server.component.SnapshotTesting;
 import org.sonar.server.component.db.ComponentDao;
-import org.sonar.server.component.db.SnapshotDao;
+import org.sonar.db.component.SnapshotDao;
 import org.sonar.server.db.DbClient;
-import org.sonar.server.issue.db.IssueDao;
 import org.sonar.server.issue.index.IssueIndexer;
 import org.sonar.server.permission.InternalPermissionService;
 import org.sonar.server.permission.PermissionChange;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.rule.db.RuleDao;
 import org.sonar.server.tester.ServerTester;
 import org.sonar.server.tester.UserSessionRule;
index 99f0bde1609d91ebf32814c20fad794e024083e6..2b6ea4036338b525ac19ef07a2406ef585f726cc 100644 (file)
@@ -34,6 +34,7 @@ import org.sonar.api.security.DefaultGroups;
 import org.sonar.api.web.UserRole;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.SnapshotDto;
+import org.sonar.db.issue.IssueDao;
 import org.sonar.db.issue.IssueDto;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbSession;
@@ -41,13 +42,12 @@ import org.sonar.db.rule.RuleDto;
 import org.sonar.server.component.ComponentTesting;
 import org.sonar.server.component.SnapshotTesting;
 import org.sonar.server.component.db.ComponentDao;
-import org.sonar.server.component.db.SnapshotDao;
+import org.sonar.db.component.SnapshotDao;
 import org.sonar.server.db.DbClient;
-import org.sonar.server.issue.db.IssueDao;
 import org.sonar.server.issue.index.IssueIndexer;
 import org.sonar.server.permission.InternalPermissionService;
 import org.sonar.server.permission.PermissionChange;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.rule.db.RuleDao;
 import org.sonar.server.search.IndexClient;
 import org.sonar.server.tester.ServerTester;
index 808b900ca0ea9b451a95e5b7de886ff05a509ac9..c4be0fa051ca664f26298af7273763f40f9ba2a5 100644 (file)
@@ -43,7 +43,7 @@ import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.exceptions.UnauthorizedException;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.tester.UserSessionRule;
 
 import static com.google.common.collect.Lists.newArrayList;
index 3f7085ff1a1e00e462a686ab6a7a9abe3dbb3582..b6b3a65ccc6c8c0faa4c6090dcd880f05cfbe1ab 100644 (file)
@@ -40,6 +40,7 @@ import org.sonar.api.security.DefaultGroups;
 import org.sonar.api.web.UserRole;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.issue.ActionPlanDto;
+import org.sonar.db.issue.IssueDao;
 import org.sonar.db.issue.IssueDto;
 import org.sonar.core.issue.workflow.Transition;
 import org.sonar.core.permission.GlobalPermissions;
@@ -54,13 +55,12 @@ import org.sonar.server.es.SearchOptions;
 import org.sonar.server.es.SearchResult;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.issue.db.IssueDao;
 import org.sonar.server.issue.index.IssueDoc;
 import org.sonar.server.issue.index.IssueIndex;
 import org.sonar.server.issue.index.IssueIndexer;
 import org.sonar.server.permission.InternalPermissionService;
 import org.sonar.server.permission.PermissionChange;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.rule.db.RuleDao;
 import org.sonar.server.source.db.FileSourceDb;
 import org.sonar.server.source.index.FileSourcesUpdaterHelper;
index e3311a9110a33e1b8384b3acec7af0a8ef084c7c..c2eb0018e3c4fd0af54ea939c6fd226d899df6cb 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.db.component.ComponentDto;
 import org.sonar.db.issue.IssueDto;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.server.issue.index.IssueDoc;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 
 public class IssueTesting {
 
index 2714599bb2c784287f439eb3f779f91efcd2f198..3eb034fc6aff1dc25d829195f29092ac0076f2d1 100644 (file)
@@ -23,7 +23,7 @@ package org.sonar.server.issue;
 import org.junit.Test;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.db.rule.RuleDto;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
index 09c84f75816eb4dea2c896647a1a36bf7f414b4f..5b2b9d9c6759f02265df27d6bb6149d00560ad7c 100644 (file)
@@ -38,7 +38,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.component.ResourceDao;
 import org.sonar.server.component.db.ComponentDao;
 import org.sonar.server.db.DbClient;
-import org.sonar.server.issue.db.IssueDao;
+import org.sonar.db.issue.IssueDao;
 import org.sonar.server.issue.index.IssueIndexer;
 
 import java.util.Collection;
index c05dfceaa140ed9050d842b4ce32dc40955b565f..81a7ff8311497627b244f8800c7178ae79412188 100644 (file)
@@ -38,6 +38,7 @@ import org.sonar.db.issue.ActionPlanDao;
 import org.sonar.db.issue.ActionPlanDto;
 import org.sonar.db.issue.ActionPlanStatsDao;
 import org.sonar.db.issue.ActionPlanStatsDto;
+import org.sonar.db.issue.IssueDao;
 import org.sonar.db.issue.IssueDto;
 import org.sonar.server.issue.IssueStorage;
 import org.sonar.db.DbSession;
@@ -77,7 +78,7 @@ public class ActionPlanServiceTest {
   ResourceDao resourceDao;
 
   @Mock
-  org.sonar.server.issue.db.IssueDao issueDao;
+  IssueDao issueDao;
 
   @Mock
   IssueUpdater issueUpdater;
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/db/IssueDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/db/IssueDaoTest.java
deleted file mode 100644 (file)
index 580336a..0000000
+++ /dev/null
@@ -1,164 +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.issue.db;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.db.issue.IssueDto;
-import org.sonar.db.AbstractDaoTestCase;
-import org.sonar.db.DbSession;
-import org.sonar.server.rule.RuleTesting;
-
-import java.util.Arrays;
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class IssueDaoTest extends AbstractDaoTestCase {
-
-  private IssueDao sut;
-  private DbSession session;
-
-  @Before
-  public void before() {
-    this.session = getMyBatis().openSession(false);
-    this.sut = new IssueDao(getMyBatis());
-  }
-
-  @After
-  public void after() {
-    this.session.close();
-  }
-
-  @Test
-  public void get_by_key() {
-    setupData("shared", "get_by_key");
-
-    IssueDto issue = sut.selectByKey(session, "ABCDE");
-    assertThat(issue.getKee()).isEqualTo("ABCDE");
-    assertThat(issue.getId()).isEqualTo(100L);
-    assertThat(issue.getComponentUuid()).isEqualTo("CDEF");
-    assertThat(issue.getProjectUuid()).isEqualTo("ABCD");
-    assertThat(issue.getRuleId()).isEqualTo(500);
-    assertThat(issue.getLanguage()).isEqualTo("java");
-    assertThat(issue.getSeverity()).isEqualTo("BLOCKER");
-    assertThat(issue.isManualSeverity()).isFalse();
-    assertThat(issue.getMessage()).isNull();
-    assertThat(issue.getLine()).isEqualTo(200);
-    assertThat(issue.getEffortToFix()).isEqualTo(4.2);
-    assertThat(issue.getStatus()).isEqualTo("OPEN");
-    assertThat(issue.getResolution()).isEqualTo("FIXED");
-    assertThat(issue.getChecksum()).isEqualTo("XXX");
-    assertThat(issue.getAuthorLogin()).isEqualTo("karadoc");
-    assertThat(issue.getReporter()).isEqualTo("arthur");
-    assertThat(issue.getAssignee()).isEqualTo("perceval");
-    assertThat(issue.getIssueAttributes()).isEqualTo("JIRA=FOO-1234");
-    assertThat(issue.getIssueCreationDate()).isNotNull();
-    assertThat(issue.getIssueUpdateDate()).isNotNull();
-    assertThat(issue.getIssueCloseDate()).isNotNull();
-    assertThat(issue.getCreatedAt()).isEqualTo(1400000000000L);
-    assertThat(issue.getUpdatedAt()).isEqualTo(1450000000000L);
-    assertThat(issue.getRuleRepo()).isEqualTo("squid");
-    assertThat(issue.getRule()).isEqualTo("AvoidCycle");
-    assertThat(issue.getComponentKey()).isEqualTo("Action.java");
-    assertThat(issue.getProjectKey()).isEqualTo("struts");
-  }
-
-  @Test
-  public void get_by_keys() {
-    setupData("shared", "get_by_key");
-
-    List<IssueDto> issues = sut.selectByKeys(session, Arrays.asList("ABCDE"));
-    assertThat(issues).hasSize(1);
-  }
-
-  @Test
-  public void find_by_action_plan() {
-    setupData("shared", "find_by_action_plan");
-
-    List<IssueDto> issues = sut.findByActionPlan(session, "AP-1");
-    assertThat(issues).hasSize(1);
-
-    IssueDto issue = issues.get(0);
-    assertThat(issue.getKee()).isEqualTo("ABCDE");
-    assertThat(issue.getActionPlanKey()).isEqualTo("AP-1");
-    assertThat(issue.getComponentUuid()).isEqualTo("CDEF");
-    assertThat(issue.getProjectUuid()).isEqualTo("ABCD");
-    assertThat(issue.getRuleId()).isEqualTo(500);
-    assertThat(issue.getLanguage()).isEqualTo("java");
-    assertThat(issue.getSeverity()).isEqualTo("BLOCKER");
-    assertThat(issue.isManualSeverity()).isFalse();
-    assertThat(issue.getMessage()).isNull();
-    assertThat(issue.getLine()).isEqualTo(200);
-    assertThat(issue.getEffortToFix()).isEqualTo(4.2);
-    assertThat(issue.getStatus()).isEqualTo("OPEN");
-    assertThat(issue.getResolution()).isEqualTo("FIXED");
-    assertThat(issue.getChecksum()).isEqualTo("XXX");
-    assertThat(issue.getAuthorLogin()).isEqualTo("karadoc");
-    assertThat(issue.getReporter()).isEqualTo("arthur");
-    assertThat(issue.getAssignee()).isEqualTo("perceval");
-    assertThat(issue.getIssueAttributes()).isEqualTo("JIRA=FOO-1234");
-    assertThat(issue.getIssueCreationDate()).isNotNull();
-    assertThat(issue.getIssueUpdateDate()).isNotNull();
-    assertThat(issue.getIssueCloseDate()).isNotNull();
-    assertThat(issue.getCreatedAt()).isNotNull();
-    assertThat(issue.getUpdatedAt()).isNotNull();
-    assertThat(issue.getRuleRepo()).isEqualTo("squid");
-    assertThat(issue.getRule()).isEqualTo("AvoidCycle");
-    assertThat(issue.getComponentKey()).isEqualTo("Action.java");
-    assertThat(issue.getProjectKey()).isEqualTo("struts");
-  }
-
-  @Test
-  public void insert() {
-    IssueDto dto = new IssueDto();
-    dto.setComponent(new ComponentDto().setKey("struts:Action").setId(123L).setUuid("component-uuid"));
-    dto.setProject(new ComponentDto().setKey("struts").setId(100L).setUuid("project-uuid"));
-    dto.setRule(RuleTesting.newDto(RuleKey.of("squid", "S001")).setId(200));
-    dto.setKee("ABCDE");
-    dto.setLine(500);
-    dto.setEffortToFix(3.14);
-    dto.setDebt(10L);
-    dto.setResolution("FIXED");
-    dto.setStatus("RESOLVED");
-    dto.setSeverity("BLOCKER");
-    dto.setReporter("emmerik");
-    dto.setAuthorLogin("morgan");
-    dto.setAssignee("karadoc");
-    dto.setActionPlanKey("current_sprint");
-    dto.setIssueAttributes("JIRA=FOO-1234");
-    dto.setChecksum("123456789");
-    dto.setMessage("the message");
-
-    dto.setIssueCreationTime(1_500_000_000_000L);
-    dto.setIssueUpdateTime(1_500_000_000_001L);
-    dto.setIssueCloseTime(1_500_000_000_002L);
-    dto.setCreatedAt(1_400_000_000_000L);
-    dto.setUpdatedAt(1_450_000_000_000L);
-
-    sut.insert(session, dto);
-    session.commit();
-
-    checkTables("insert", new String[] {"id"}, "issues");
-  }
-}
index 1d249d407b21a3c8dffd361e67e6f1d4ae008ddf..5da4dd01c1765fa73d6a58c505098b7c8c1c57dc 100644 (file)
@@ -43,7 +43,7 @@ import org.sonar.server.issue.filter.IssueFilterParameters;
 import org.sonar.server.issue.index.IssueIndexer;
 import org.sonar.server.permission.InternalPermissionService;
 import org.sonar.server.permission.PermissionChange;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.rule.db.RuleDao;
 import org.sonar.server.tester.ServerTester;
 import org.sonar.server.tester.UserSessionRule;
index 05088a66e48dce9f49da9795646e2fe749ca8be1..b6daf433d8c6f2d705c1741b4cc3f76555ea08d6 100644 (file)
@@ -37,6 +37,7 @@ import org.sonar.db.issue.ActionPlanDao;
 import org.sonar.db.issue.ActionPlanDto;
 import org.sonar.db.issue.IssueChangeDao;
 import org.sonar.db.issue.IssueChangeDto;
+import org.sonar.db.issue.IssueDao;
 import org.sonar.db.issue.IssueDto;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbSession;
@@ -46,12 +47,11 @@ import org.sonar.server.component.ComponentTesting;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.issue.IssueQuery;
 import org.sonar.server.issue.IssueTesting;
-import org.sonar.server.issue.db.IssueDao;
 import org.sonar.server.issue.filter.IssueFilterParameters;
 import org.sonar.server.issue.index.IssueIndexer;
 import org.sonar.server.permission.InternalPermissionService;
 import org.sonar.server.permission.PermissionChange;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.rule.db.RuleDao;
 import org.sonar.server.search.QueryContext;
 import org.sonar.server.tester.ServerTester;
index 504e22ca63a4330718d087f2b8d1927760c31dff..c8518c406cdd7a2fbd5f92508020d0a9f4cd3900 100644 (file)
@@ -43,7 +43,7 @@ import org.sonar.db.DbTester;
 import org.sonar.server.component.ComponentTesting;
 import org.sonar.server.component.SnapshotTesting;
 import org.sonar.server.component.db.ComponentDao;
-import org.sonar.server.component.db.SnapshotDao;
+import org.sonar.db.component.SnapshotDao;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.exceptions.ForbiddenException;
diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/persistence/MeasureDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/persistence/MeasureDaoTest.java
deleted file mode 100644 (file)
index 1a79760..0000000
+++ /dev/null
@@ -1,332 +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.measure.persistence;
-
-import com.google.common.base.Function;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.ImmutableSet;
-import java.util.List;
-import java.util.Map;
-import javax.annotation.Nullable;
-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.db.measure.MeasureDto;
-import org.sonar.db.measure.PastMeasureDto;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.test.DbTests;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static org.assertj.core.api.Assertions.assertThat;
-
-@Category(DbTests.class)
-public class MeasureDaoTest {
-
-  @ClassRule
-  public static DbTester db = new DbTester();
-
-  DbSession session;
-  MeasureDao sut;
-
-  @Before
-  public void setUp() {
-    db.truncateTables();
-    session = db.myBatis().openSession(false);
-    sut = new MeasureDao();
-  }
-
-  @After
-  public void tearDown() {
-    session.close();
-  }
-
-  @Test
-  public void get_value_by_key() {
-    db.prepareDbUnit(getClass(), "shared.xml");
-
-    MeasureDto result = sut.findByComponentKeyAndMetricKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "ncloc");
-    assertThat(result.getId()).isEqualTo(22);
-    assertThat(result.getValue()).isEqualTo(10d);
-    assertThat(result.getData()).isNull();
-    assertThat(result.getVariation(1)).isEqualTo(1d);
-    assertThat(result.getVariation(2)).isEqualTo(2d);
-    assertThat(result.getVariation(3)).isEqualTo(3d);
-    assertThat(result.getVariation(4)).isEqualTo(4d);
-    assertThat(result.getVariation(5)).isEqualTo(-5d);
-    assertThat(result.getAlertStatus()).isEqualTo("OK");
-    assertThat(result.getAlertText()).isEqualTo("Green");
-  }
-
-  @Test
-  // TODO the string must be longer than 4000 char to be persisted in the data field
-  public void get_data_by_key() {
-    db.prepareDbUnit(getClass(), "shared.xml");
-
-    MeasureDto result = sut.findByComponentKeyAndMetricKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "authors_by_line");
-    assertThat(result.getId()).isEqualTo(20);
-    assertThat(result.getData()).isEqualTo("0123456789012345678901234567890123456789");
-  }
-
-  @Test
-  public void get_text_value_by_key() {
-    db.prepareDbUnit(getClass(), "shared.xml");
-
-    MeasureDto result = sut.findByComponentKeyAndMetricKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "coverage_line_hits_data");
-    assertThat(result.getId()).isEqualTo(21);
-    assertThat(result.getData()).isEqualTo("36=1;37=1;38=1;39=1;43=1;48=1;53=1");
-  }
-
-  @Test
-  public void find_by_component_key_and_metrics() {
-    db.prepareDbUnit(getClass(), "shared.xml");
-
-    List<MeasureDto> results = sut.findByComponentKeyAndMetricKeys(session, "org.struts:struts-core:src/org/struts/RequestContext.java",
-      newArrayList("ncloc", "authors_by_line"));
-    assertThat(results).hasSize(2);
-
-    results = sut.findByComponentKeyAndMetricKeys(session, "org.struts:struts-core:src/org/struts/RequestContext.java", newArrayList("ncloc"));
-    assertThat(results).hasSize(1);
-
-    MeasureDto result = results.get(0);
-    assertThat(result.getId()).isEqualTo(22);
-    assertThat(result.getValue()).isEqualTo(10d);
-    assertThat(result.getComponentKey()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java");
-    assertThat(result.getMetricKey()).isEqualTo("ncloc");
-    assertThat(result.getVariation(1)).isEqualTo(1d);
-    assertThat(result.getVariation(2)).isEqualTo(2d);
-    assertThat(result.getVariation(3)).isEqualTo(3d);
-    assertThat(result.getVariation(4)).isEqualTo(4d);
-    assertThat(result.getVariation(5)).isEqualTo(-5d);
-  }
-
-  @Test
-  public void find_by_component_key_and_metric() {
-    db.prepareDbUnit(getClass(), "shared.xml");
-
-    MeasureDto result = sut.findByComponentKeyAndMetricKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "ncloc");
-    assertThat(result.getId()).isEqualTo(22);
-    assertThat(result.getValue()).isEqualTo(10d);
-    assertThat(result.getMetricKey()).isEqualTo("ncloc");
-    assertThat(result.getComponentKey()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java");
-    assertThat(result.getVariation(1)).isEqualTo(1d);
-    assertThat(result.getVariation(2)).isEqualTo(2d);
-    assertThat(result.getVariation(3)).isEqualTo(3d);
-    assertThat(result.getVariation(4)).isEqualTo(4d);
-    assertThat(result.getVariation(5)).isEqualTo(-5d);
-
-    assertThat(sut.findByComponentKeyAndMetricKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "unknown")).isNull();
-  }
-
-  @Test
-  public void exists_by_key() {
-    db.prepareDbUnit(getClass(), "shared.xml");
-
-    assertThat(sut.existsByKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "ncloc")).isTrue();
-    assertThat(sut.existsByKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "unknown")).isFalse();
-  }
-
-  @Test
-  public void select_past_measures_by_component_uuid_and_root_snapshot_id_and_metric_keys() {
-    db.prepareDbUnit(getClass(), "past_measures.xml");
-
-    List<PastMeasureDto> fileMeasures = sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "CDEF", 1000L, ImmutableSet.of(1, 2));
-    assertThat(fileMeasures).hasSize(2);
-
-    PastMeasureDto fileMeasure1 = fileMeasures.get(0);
-    assertThat(fileMeasure1.getValue()).isEqualTo(5d);
-    assertThat(fileMeasure1.getMetricId()).isEqualTo(1);
-    assertThat(fileMeasure1.getRuleId()).isNull();
-    assertThat(fileMeasure1.getCharacteristicId()).isNull();
-    assertThat(fileMeasure1.getPersonId()).isNull();
-
-    PastMeasureDto fileMeasure2 = fileMeasures.get(1);
-    assertThat(fileMeasure2.getValue()).isEqualTo(60d);
-    assertThat(fileMeasure2.getMetricId()).isEqualTo(2);
-
-    List<PastMeasureDto> projectMeasures = sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "ABCD", 1000L, ImmutableSet.of(1, 2));
-    assertThat(projectMeasures).hasSize(2);
-
-    PastMeasureDto projectMeasure1 = projectMeasures.get(0);
-    assertThat(projectMeasure1.getValue()).isEqualTo(60d);
-    assertThat(projectMeasure1.getMetricId()).isEqualTo(1);
-
-    PastMeasureDto projectMeasure2 = projectMeasures.get(1);
-    assertThat(projectMeasure2.getValue()).isEqualTo(80d);
-    assertThat(projectMeasure2.getMetricId()).isEqualTo(2);
-
-    assertThat(sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "UNKNOWN", 1000L, ImmutableSet.of(1, 2))).isEmpty();
-    assertThat(sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "CDEF", 987654L, ImmutableSet.of(1, 2))).isEmpty();
-    assertThat(sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "CDEF", 1000L, ImmutableSet.of(123, 456))).isEmpty();
-  }
-
-  @Test
-  public void select_past_measures_on_rule_by_component_uuid_and_root_snapshot_id_and_metric_keys() {
-    db.prepareDbUnit(getClass(), "past_measures_with_rule_id.xml");
-
-    List<PastMeasureDto> measures = sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "ABCD", 1000L, ImmutableSet.of(1));
-    assertThat(measures).hasSize(3);
-
-    Map<Long, PastMeasureDto> pastMeasuresById = pastMeasuresById(measures);
-
-    PastMeasureDto measure1 = pastMeasuresById.get(1L);
-    assertThat(measure1.getValue()).isEqualTo(60d);
-    assertThat(measure1.getMetricId()).isEqualTo(1);
-    assertThat(measure1.getRuleId()).isNull();
-    assertThat(measure1.getCharacteristicId()).isNull();
-    assertThat(measure1.getPersonId()).isNull();
-
-    PastMeasureDto measure2 = pastMeasuresById.get(2L);
-    assertThat(measure2.getValue()).isEqualTo(20d);
-    assertThat(measure2.getMetricId()).isEqualTo(1);
-    assertThat(measure2.getRuleId()).isEqualTo(30);
-    assertThat(measure2.getCharacteristicId()).isNull();
-    assertThat(measure2.getPersonId()).isNull();
-
-    PastMeasureDto measure3 = pastMeasuresById.get(3L);
-    assertThat(measure3.getValue()).isEqualTo(40d);
-    assertThat(measure3.getMetricId()).isEqualTo(1);
-    assertThat(measure3.getRuleId()).isEqualTo(31);
-    assertThat(measure3.getCharacteristicId()).isNull();
-    assertThat(measure3.getPersonId()).isNull();
-  }
-
-  @Test
-  public void select_past_measures_on_characteristic_by_component_uuid_and_root_snapshot_id_and_metric_keys() {
-    db.prepareDbUnit(getClass(), "past_measures_with_characteristic_id.xml");
-
-    List<PastMeasureDto> measures = sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "ABCD", 1000L, ImmutableSet.of(1));
-    assertThat(measures).hasSize(3);
-
-    Map<Long, PastMeasureDto> pastMeasuresById = pastMeasuresById(measures);
-
-    PastMeasureDto measure1 = pastMeasuresById.get(1L);
-    assertThat(measure1.getValue()).isEqualTo(60d);
-    assertThat(measure1.getMetricId()).isEqualTo(1);
-    assertThat(measure1.getRuleId()).isNull();
-    assertThat(measure1.getCharacteristicId()).isNull();
-    assertThat(measure1.getPersonId()).isNull();
-
-    PastMeasureDto measure2 = pastMeasuresById.get(2L);
-    assertThat(measure2.getValue()).isEqualTo(20d);
-    assertThat(measure2.getMetricId()).isEqualTo(1);
-    assertThat(measure2.getRuleId()).isNull();
-    assertThat(measure2.getCharacteristicId()).isEqualTo(10);
-    assertThat(measure2.getPersonId()).isNull();
-
-    PastMeasureDto measure3 = pastMeasuresById.get(3L);
-    assertThat(measure3.getValue()).isEqualTo(40d);
-    assertThat(measure3.getMetricId()).isEqualTo(1);
-    assertThat(measure3.getRuleId()).isNull();
-    assertThat(measure3.getCharacteristicId()).isEqualTo(11);
-    assertThat(measure3.getPersonId()).isNull();
-  }
-
-  @Test
-  public void select_past_measures_on_person_by_component_uuid_and_root_snapshot_id_and_metric_keys() {
-    db.prepareDbUnit(getClass(), "past_measures_with_person_id.xml");
-
-    List<PastMeasureDto> measures = sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "ABCD", 1000L, ImmutableSet.of(1));
-    assertThat(measures).hasSize(3);
-
-    Map<Long, PastMeasureDto> pastMeasuresById = pastMeasuresById(measures);
-
-    PastMeasureDto measure1 = pastMeasuresById.get(1L);
-    assertThat(measure1.getValue()).isEqualTo(60d);
-    assertThat(measure1.getMetricId()).isEqualTo(1);
-    assertThat(measure1.getRuleId()).isNull();
-    assertThat(measure1.getCharacteristicId()).isNull();
-    assertThat(measure1.getPersonId()).isNull();
-
-    PastMeasureDto measure2 = pastMeasuresById.get(2L);
-    assertThat(measure2.getValue()).isEqualTo(20d);
-    assertThat(measure2.getMetricId()).isEqualTo(1);
-    assertThat(measure2.getRuleId()).isNull();
-    assertThat(measure2.getCharacteristicId()).isNull();
-    assertThat(measure2.getPersonId()).isEqualTo(20);
-
-    PastMeasureDto measure3 = pastMeasuresById.get(3L);
-    assertThat(measure3.getValue()).isEqualTo(40d);
-    assertThat(measure3.getMetricId()).isEqualTo(1);
-    assertThat(measure3.getRuleId()).isNull();
-    assertThat(measure3.getCharacteristicId()).isNull();
-    assertThat(measure3.getPersonId()).isEqualTo(21);
-  }
-
-  @Test
-  public void insert() {
-    db.prepareDbUnit(getClass(), "empty.xml");
-
-    sut.insert(session, new MeasureDto()
-      .setSnapshotId(2L)
-      .setMetricId(3)
-      .setCharacteristicId(4)
-      .setPersonId(23)
-      .setRuleId(5)
-      .setComponentId(6L)
-      .setValue(2.0d)
-      .setData("measure-value")
-      .setVariation(1, 1.0d)
-      .setVariation(2, 2.0d)
-      .setVariation(3, 3.0d)
-      .setVariation(4, 4.0d)
-      .setVariation(5, 5.0d)
-      .setAlertStatus("alert")
-      .setAlertText("alert-text")
-      .setDescription("measure-description")
-      );
-    session.commit();
-
-    db.assertDbUnit(getClass(), "insert-result.xml", new String[] {"id"}, "project_measures");
-  }
-
-  @Test
-  public void insert_measures() {
-    db.prepareDbUnit(getClass(), "empty.xml");
-
-    sut.insert(session, new MeasureDto()
-      .setSnapshotId(2L)
-      .setMetricId(3)
-      .setComponentId(6L)
-      .setValue(2.0d),
-      new MeasureDto()
-        .setSnapshotId(3L)
-        .setMetricId(4)
-        .setComponentId(6L)
-        .setValue(4.0d)
-      );
-    session.commit();
-
-    assertThat(db.countRowsOfTable("project_measures")).isEqualTo(2);
-  }
-
-  private static Map<Long, PastMeasureDto> pastMeasuresById(List<PastMeasureDto> pastMeasures) {
-    return FluentIterable.from(pastMeasures).uniqueIndex(new Function<PastMeasureDto, Long>() {
-      @Nullable
-      @Override
-      public Long apply(PastMeasureDto input) {
-        return input.getId();
-      }
-    });
-  }
-}
index 413da3ae015630c1d0726d2e73b1e2e3a34faa01..6a25d8d283c1013430ec557323f93a1e3650a526 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.db.DbTester;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.issue.IssueTesting;
 import org.sonar.server.issue.index.IssueIndexDefinition;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.rule.index.RuleDoc;
 import org.sonar.server.rule.index.RuleNormalizer;
 import org.sonar.server.search.IndexDefinition;
index b4313c5a144b2a552481e447f8631f0dee04d600..afbb161a5aefea712a981f314554533f37728d10 100644 (file)
@@ -36,30 +36,29 @@ import org.sonar.api.resources.ResourceTypes;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.utils.System2;
 import org.sonar.api.web.UserRole;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.SnapshotDto;
-import org.sonar.db.issue.IssueDto;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
-import org.sonar.db.purge.PurgeDao;
-import org.sonar.db.purge.PurgeProfiler;
+import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ResourceDao;
+import org.sonar.db.component.SnapshotDao;
+import org.sonar.db.component.SnapshotDto;
+import org.sonar.db.issue.IssueDao;
+import org.sonar.db.issue.IssueDto;
+import org.sonar.db.purge.PurgeDao;
 import org.sonar.db.rule.RuleDto;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.component.ComponentCleanerService;
 import org.sonar.server.component.ComponentTesting;
 import org.sonar.server.component.SnapshotTesting;
 import org.sonar.server.component.db.ComponentDao;
-import org.sonar.server.component.db.SnapshotDao;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.issue.IssueTesting;
-import org.sonar.server.issue.db.IssueDao;
 import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 import org.sonar.server.issue.index.IssueIndexDefinition;
 import org.sonar.server.issue.index.IssueIndexer;
-import org.sonar.server.rule.RuleTesting;
 import org.sonar.server.rule.db.RuleDao;
 import org.sonar.server.source.index.SourceLineDoc;
 import org.sonar.server.source.index.SourceLineIndexDefinition;
@@ -100,7 +99,7 @@ public class BulkDeleteActionTest {
   public void setUp() throws Exception {
     ComponentDao componentDao = new ComponentDao();
     ResourceDao resourceDao = new ResourceDao(db.myBatis(), System2.INSTANCE);
-    PurgeDao purgeDao = new PurgeDao(db.myBatis(), resourceDao, new PurgeProfiler(), System2.INSTANCE);
+    PurgeDao purgeDao = new PurgeDao(db.myBatis(), resourceDao, System2.INSTANCE);
     dbClient = new DbClient(db.database(), db.myBatis(), componentDao, purgeDao, new RuleDao(System2.INSTANCE), new IssueDao(db.myBatis()), new SnapshotDao());
     dbSession = dbClient.openSession(false);
     resourceType = mock(ResourceType.class);
index 6d24ca4ee0652c1af9da27cbeb365757a27d4351..4e277b951e5bfb5b45043a8b220fc1f1c670486c 100644 (file)
@@ -35,29 +35,28 @@ import org.sonar.api.resources.ResourceTypes;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.utils.System2;
 import org.sonar.api.web.UserRole;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ResourceDao;
+import org.sonar.db.component.SnapshotDao;
 import org.sonar.db.component.SnapshotDto;
+import org.sonar.db.issue.IssueDao;
 import org.sonar.db.issue.IssueDto;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
 import org.sonar.db.purge.PurgeDao;
-import org.sonar.db.purge.PurgeProfiler;
-import org.sonar.db.component.ResourceDao;
 import org.sonar.db.rule.RuleDto;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.component.ComponentCleanerService;
 import org.sonar.server.component.ComponentTesting;
 import org.sonar.server.component.SnapshotTesting;
 import org.sonar.server.component.db.ComponentDao;
-import org.sonar.server.component.db.SnapshotDao;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.issue.IssueTesting;
-import org.sonar.server.issue.db.IssueDao;
 import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 import org.sonar.server.issue.index.IssueIndexDefinition;
 import org.sonar.server.issue.index.IssueIndexer;
-import org.sonar.server.rule.RuleTesting;
 import org.sonar.server.rule.db.RuleDao;
 import org.sonar.server.source.index.SourceLineDoc;
 import org.sonar.server.source.index.SourceLineIndexDefinition;
@@ -98,7 +97,7 @@ public class DeleteActionTest {
   public void setUp() throws Exception {
     ComponentDao componentDao = new ComponentDao();
     ResourceDao resourceDao = new ResourceDao(db.myBatis(), System2.INSTANCE);
-    PurgeDao purgeDao = new PurgeDao(db.myBatis(), resourceDao, new PurgeProfiler(), System2.INSTANCE);
+    PurgeDao purgeDao = new PurgeDao(db.myBatis(), resourceDao, System2.INSTANCE);
     dbClient = new DbClient(db.database(), db.myBatis(), componentDao, purgeDao, new RuleDao(System2.INSTANCE), new IssueDao(db.myBatis()), new SnapshotDao());
     dbSession = dbClient.openSession(false);
     resourceType = mock(ResourceType.class);
index ab55f9bd35c4e8a77cf77d46bf5ae2126dc0a0f3..ec4712b59e8c89f6c3e6dbf56b87c36a075213ce 100644 (file)
@@ -38,7 +38,7 @@ import org.sonar.db.DbTester;
 import org.sonar.server.component.ComponentTesting;
 import org.sonar.server.component.SnapshotTesting;
 import org.sonar.server.component.db.ComponentDao;
-import org.sonar.server.component.db.SnapshotDao;
+import org.sonar.db.component.SnapshotDao;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.tester.UserSessionRule;
index ed5f5fe242cb610c90630fe070f2ecec19e55b9d..8bb35266ebca17b27f994c6d6a1ae3ef5066f414 100644 (file)
@@ -39,7 +39,7 @@ import org.sonar.db.DbTester;
 import org.sonar.server.component.ComponentTesting;
 import org.sonar.server.component.SnapshotTesting;
 import org.sonar.server.component.db.ComponentDao;
-import org.sonar.server.component.db.SnapshotDao;
+import org.sonar.db.component.SnapshotDao;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.tester.UserSessionRule;
index 7ec9a26b61cd4761346e93ea69523d05675a5a03..8cc6afdc0c93c33f8224abc3110bb93ffe79856f 100644 (file)
@@ -41,7 +41,7 @@ import org.sonar.server.db.DbClient;
 import org.sonar.server.platform.Platform;
 import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
 import org.sonar.server.qualityprofile.index.ActiveRuleNormalizer;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.rule.db.RuleDao;
 import org.sonar.server.search.FacetValue;
 import org.sonar.server.search.IndexClient;
index 39a914313ceb38e96bab65ebd16322b8447b10cf..041eac7282951cf6371e7ef1858b92157c8e07e5 100644 (file)
@@ -36,7 +36,7 @@ import org.sonar.db.qualityprofile.QualityProfileDto;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.db.rule.RuleParamDto;
 import org.sonar.server.db.DbClient;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.tester.ServerTester;
 import org.sonar.server.tester.UserSessionRule;
 
index c133a198f2632a4ca0f844509a828feb11916622..0662f249453a3acef32fcc0bd7aecf56e6bf31d5 100644 (file)
@@ -36,7 +36,7 @@ import org.sonar.server.db.DbClient;
 import org.sonar.server.qualityprofile.QProfileComparison.ActiveRuleDiff;
 import org.sonar.server.qualityprofile.QProfileComparison.QProfileComparisonResult;
 import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.tester.ServerTester;
 import org.sonar.server.tester.UserSessionRule;
 
index 1fe25bf4f5e3ad0c461424a67ecad8750c0578c4..0ca036e8e3dc1828c8456e22b613a2afa893aff2 100644 (file)
@@ -35,7 +35,7 @@ import org.sonar.db.rule.RuleDto;
 import org.sonar.db.rule.RuleParamDto;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.tester.ServerTester;
 
 import javax.annotation.Nullable;
index cbf48ac91bea7c4d7dbfbb60117dc7adf1e27c96..fb36be893ea08e55fe43627a343cd571c3af6be1 100644 (file)
@@ -34,7 +34,7 @@ import org.sonar.db.rule.RuleParamDto;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.search.IndexClient;
 import org.sonar.server.tester.ServerTester;
 import org.sonar.server.tester.UserSessionRule;
index 549328c7e63bb97ab71cf5f4a27ceb104ef6ff13..51f79e99c98364a304c7ac3217248be09dda2efc 100644 (file)
@@ -51,7 +51,7 @@ import org.sonar.server.activity.ActivityService;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.es.SearchOptions;
 import org.sonar.server.qualityprofile.index.ActiveRuleNormalizer;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.search.FacetValue;
 import org.sonar.server.search.Result;
 import org.sonar.server.tester.ServerTester;
index 1aeeeee45d0a7b9255f1f3c1ad095bf73035a24c..5b2d52de134351ebb97c1ff12a8f07350be3d9d1 100644 (file)
@@ -46,7 +46,7 @@ import org.sonar.server.db.DbClient;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.Message;
 import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.rule.index.RuleIndex;
 import org.sonar.server.rule.index.RuleQuery;
 import org.sonar.server.search.QueryContext;
index c145248e8cf42e74fff6de0dc04634f55b850714..1378b15e00a584b8cc27f69be38bf1ac8e00e0be 100644 (file)
@@ -51,7 +51,7 @@ import org.sonar.server.qualityprofile.ActiveRuleChange;
 import org.sonar.server.qualityprofile.ActiveRuleChange.Type;
 import org.sonar.server.qualityprofile.QProfileFactory;
 import org.sonar.server.qualityprofile.QProfileTesting;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.rule.db.RuleDao;
 import org.sonar.server.user.db.UserDao;
 import org.sonar.server.ws.WsTester;
index 727a15dae873675242f10c7c1bd8392943f7efd0..c512eda67be471453252cdab18a92022d806c8f3 100644 (file)
@@ -31,6 +31,7 @@ import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.RuleQuery;
 import org.sonar.db.DbSession;
 import org.sonar.db.rule.RuleDto;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.tester.ServerTester;
 import org.sonar.server.tester.UserSessionRule;
index 0ee1ca1327524dc58734a9ca058ca5d3da44ca3d..6a0ade0a8936230fee65d8cba750d197b25b3829 100644 (file)
@@ -42,6 +42,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.qualityprofile.ActiveRuleKey;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.db.rule.RuleParamDto;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.platform.Platform;
 import org.sonar.server.qualityprofile.ActiveRule;
index c93de49e8cb8a421d11bc5a0d6cc1186827d6fbf..d2e8b50693636914f5f19844f3e39439f342bd20 100644 (file)
@@ -31,6 +31,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.db.rule.RuleParamDto;
 import org.sonar.db.debt.CharacteristicDto;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.debt.DebtTesting;
 import org.sonar.server.platform.Platform;
index c0622369a394f5d2d04c2f3ef6d5c0f59f42ef3d..19abfcac3d2d0c32b3af31fa8298afd96db78298 100644 (file)
@@ -35,6 +35,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.db.rule.RuleDto.Format;
 import org.sonar.db.rule.RuleParamDto;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.rule.db.RuleDao;
index 7c618e5f3f1d41f579a569b4a8a52c8716f61374..d9831030d9e9cdc788663d81a2d19aec2130b099 100644 (file)
@@ -31,6 +31,7 @@ import org.sonar.api.rule.Severity;
 import org.sonar.db.DbSession;
 import org.sonar.db.qualityprofile.QualityProfileDto;
 import org.sonar.db.rule.RuleDto;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.qualityprofile.ActiveRule;
 import org.sonar.server.qualityprofile.QProfileTesting;
index 290b86d2f21284e61fe8f55aa386b856ad8c1669..e540087388a984de6ddf4a1d3153fdeae636fed2 100644 (file)
@@ -33,6 +33,7 @@ import org.sonar.api.rule.Severity;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbSession;
 import org.sonar.db.rule.RuleDto;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.exceptions.UnauthorizedException;
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleTesting.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleTesting.java
deleted file mode 100644 (file)
index d521ead..0000000
+++ /dev/null
@@ -1,107 +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.rule;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableSet;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.rule.RuleStatus;
-import org.sonar.api.rule.Severity;
-import org.sonar.api.server.debt.DebtRemediationFunction;
-import org.sonar.db.rule.RuleDto;
-import org.sonar.db.rule.RuleDto.Format;
-
-/**
- * Utility class for tests involving rules
- */
-public class RuleTesting {
-
-  public static final RuleKey XOO_X1 = RuleKey.of("xoo", "x1");
-  public static final RuleKey XOO_X2 = RuleKey.of("xoo", "x2");
-  public static final RuleKey XOO_X3 = RuleKey.of("xoo", "x3");
-
-  private RuleTesting() {
-    // only static helpers
-  }
-
-  public static RuleDto newXooX1() {
-    return newDto(XOO_X1).setLanguage("xoo");
-  }
-
-  public static RuleDto newXooX2() {
-    return newDto(XOO_X2).setLanguage("xoo");
-  }
-
-  public static RuleDto newXooX3() {
-    return newDto(XOO_X3).setLanguage("xoo");
-  }
-
-  /**
-   * Full RuleDto used to feed database with fake data. Tests must not rely on the
-   * field contents declared here. They should override the fields they need to test,
-   * for example:
-   * <pre>
-   *   ruleDao.insert(dbSession, RuleTesting.newDto(key).setStatus(RuleStatus.BETA));
-   * </pre>
-   */
-  public static RuleDto newDto(RuleKey ruleKey) {
-    return new RuleDto()
-      .setRuleKey(ruleKey.rule())
-      .setRepositoryKey(ruleKey.repository())
-      .setName("Rule " + ruleKey.rule())
-      .setDescription("Description " + ruleKey.rule())
-      .setDescriptionFormat(Format.HTML)
-      .setStatus(RuleStatus.READY)
-      .setConfigKey("InternalKey" + ruleKey.rule())
-      .setSeverity(Severity.INFO)
-      .setIsTemplate(false)
-      .setTags(ImmutableSet.of("tag1", "tag2"))
-      .setSystemTags(ImmutableSet.of("systag1", "systag2"))
-      .setLanguage("js")
-      .setRemediationFunction(DebtRemediationFunction.Type.LINEAR.toString())
-      .setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.toString())
-      .setRemediationCoefficient("1h")
-      .setDefaultRemediationCoefficient("5d")
-      .setRemediationOffset("5min")
-      .setDefaultRemediationOffset("10h")
-      .setEffortToFixDescription(ruleKey.repository() + "." + ruleKey.rule() + ".effortToFix");
-  }
-
-  public static RuleDto newTemplateRule(RuleKey ruleKey){
-    return newDto(ruleKey)
-      .setIsTemplate(true);
-  }
-
-  public static RuleDto newCustomRule(RuleDto templateRule){
-    Preconditions.checkNotNull(templateRule.getId(), "The template rule need to be persisted before creating this custom rule.");
-    return newDto(RuleKey.of(templateRule.getRepositoryKey(), templateRule.getRuleKey() + "_" + System.currentTimeMillis()))
-      .setLanguage(templateRule.getLanguage())
-      .setTemplateId(templateRule.getId());
-  }
-
-  public static RuleDto newManualRule(String manualKey){
-    return new RuleDto().setRuleKey(manualKey)
-      .setName("Name " + manualKey)
-      .setRepositoryKey(RuleKey.MANUAL_REPOSITORY_KEY)
-      .setDescription("Description " + manualKey)
-      .setStatus(RuleStatus.READY);
-  }
-
-}
index 5c5d2b9e40e2419be9850433c6b17f0121b0180a..7e8de30fc8a5f356731c9762fb08507716d7afc6 100644 (file)
@@ -38,6 +38,7 @@ import org.sonar.db.qualityprofile.QualityProfileDto;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.db.rule.RuleParamDto;
 import org.sonar.db.debt.CharacteristicDto;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.debt.DebtTesting;
 import org.sonar.server.qualityprofile.ActiveRule;
index d4d85f431badaf0bacd20f31f283dd3bd06a48a1..688f59672971b148ebf61778cb02583356efc051 100644 (file)
@@ -43,7 +43,7 @@ import org.sonar.server.debt.DebtTesting;
 import org.sonar.server.qualityprofile.ActiveRule;
 import org.sonar.server.qualityprofile.QProfileTesting;
 import org.sonar.server.rule.Rule;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.rule.db.RuleDao;
 import org.sonar.server.search.FacetValue;
 import org.sonar.server.search.QueryContext;
index be4ad2c558ad6a1ff501d00c137a7939ed3ac59c..4145b41208c69b4dce27229d9011e3c7506b8960 100644 (file)
@@ -36,7 +36,7 @@ import org.sonar.db.rule.RuleDto;
 import org.sonar.db.rule.RuleParamDto;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.rule.db.RuleDao;
 import org.sonar.server.tester.ServerTester;
 import org.sonar.server.tester.UserSessionRule;
index bbdb3340c0aabcc44ad971773dd2d03b1eebb46d..9cc24440ba4fcfbf0f0645b6b305760322655a27 100644 (file)
@@ -47,7 +47,7 @@ import org.sonar.server.db.DbClient;
 import org.sonar.server.debt.DebtTesting;
 import org.sonar.server.qualityprofile.QProfileTesting;
 import org.sonar.server.qualityprofile.db.ActiveRuleDao;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.rule.db.RuleDao;
 import org.sonar.server.rule.index.RuleNormalizer;
 import org.sonar.server.tester.ServerTester;
index 1798f42cb9a279f1f5a85ff89be0f72cd0dbc818..3717910d88d0a4febb12c8d1a32848ad91cd4299 100644 (file)
@@ -38,7 +38,7 @@ import org.sonar.db.debt.CharacteristicDto;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.rule.NewRule;
 import org.sonar.server.rule.RuleService;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.rule.db.RuleDao;
 import org.sonar.server.tester.ServerTester;
 import org.sonar.server.tester.UserSessionRule;
index aefeea4bd49d741c4742d5ab301f87e00f7420ab..35229551239bf1db43f41fca040197d10f0facf2 100644 (file)
@@ -36,7 +36,7 @@ import org.sonar.db.rule.RuleParamDto;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.rule.NewRule;
 import org.sonar.server.rule.RuleService;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.rule.db.RuleDao;
 import org.sonar.server.tester.ServerTester;
 import org.sonar.server.tester.UserSessionRule;
index 256f2206e3b85efd8a1358682bfbc364f82cb180..ace7b68352cfa568df8e798531119f2b70ad3da3 100644 (file)
@@ -25,7 +25,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.server.measure.persistence.MeasureDao;
+import org.sonar.db.measure.MeasureDao;
 import org.sonar.server.source.index.SourceLineDoc;
 import org.sonar.server.source.index.SourceLineIndex;
 
diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/db/FileSourceDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/source/db/FileSourceDaoTest.java
deleted file mode 100644 (file)
index 2c3e2ab..0000000
+++ /dev/null
@@ -1,176 +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 com.google.common.base.Function;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import org.apache.commons.io.IOUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.db.AbstractDaoTestCase;
-import org.sonar.db.DbSession;
-import org.sonar.db.source.FileSourceDto;
-import org.sonar.db.source.FileSourceDto.Type;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class FileSourceDaoTest extends AbstractDaoTestCase {
-
-  DbSession session;
-
-  FileSourceDao sut;
-
-  @Before
-  public void setUpTestData() {
-    session = getMyBatis().openSession(false);
-    sut = new FileSourceDao(getMyBatis());
-  }
-
-  @After
-  public void tearDown() {
-    session.close();
-  }
-
-  @Test
-  public void select() {
-    setupData("shared");
-
-    FileSourceDto fileSourceDto = sut.selectSource("FILE1_UUID");
-
-    assertThat(fileSourceDto.getBinaryData()).isNotEmpty();
-    assertThat(fileSourceDto.getDataHash()).isEqualTo("hash");
-    assertThat(fileSourceDto.getProjectUuid()).isEqualTo("PRJ_UUID");
-    assertThat(fileSourceDto.getFileUuid()).isEqualTo("FILE1_UUID");
-    assertThat(fileSourceDto.getCreatedAt()).isEqualTo(1500000000000L);
-    assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(1500000000000L);
-    assertThat(fileSourceDto.getDataType()).isEqualTo(Type.SOURCE);
-  }
-
-  @Test
-  public void select_line_hashes() {
-    setupData("shared");
-
-    ReaderToStringFunction fn = new ReaderToStringFunction();
-    sut.readLineHashesStream(session, "FILE1_UUID", fn);
-
-    assertThat(fn.result).isEqualTo("ABC\\nDEF\\nGHI");
-  }
-
-  @Test
-  public void no_line_hashes_on_unknown_file() {
-    setupData("shared");
-
-    ReaderToStringFunction fn = new ReaderToStringFunction();
-    sut.readLineHashesStream(session, "unknown", fn);
-
-    assertThat(fn.result).isNull();
-  }
-
-  @Test
-  public void no_line_hashes_when_only_test_data() {
-    setupData("no_line_hashes_when_only_test_data");
-
-    ReaderToStringFunction fn = new ReaderToStringFunction();
-    sut.readLineHashesStream(session, "FILE1_UUID", fn);
-
-    assertThat(fn.result).isNull();
-  }
-
-  @Test
-  public void insert() {
-    setupData("shared");
-
-    sut.insert(new FileSourceDto()
-      .setProjectUuid("PRJ_UUID")
-      .setFileUuid("FILE2_UUID")
-      .setBinaryData("FILE2_BINARY_DATA".getBytes())
-      .setDataHash("FILE2_DATA_HASH")
-      .setLineHashes("LINE1_HASH\\nLINE2_HASH")
-      .setSrcHash("FILE2_HASH")
-      .setDataType(Type.SOURCE)
-      .setCreatedAt(1500000000000L)
-      .setUpdatedAt(1500000000001L));
-
-    checkTable("insert", "file_sources", "project_uuid", "file_uuid", "data_hash", "line_hashes", "src_hash", "created_at", "updated_at", "data_type");
-  }
-
-  @Test
-  public void update() {
-    setupData("shared");
-
-    sut.update(new FileSourceDto()
-      .setId(101L)
-      .setProjectUuid("PRJ_UUID")
-      .setFileUuid("FILE1_UUID")
-      .setBinaryData("updated data".getBytes())
-      .setDataHash("NEW_DATA_HASH")
-      .setSrcHash("NEW_FILE_HASH")
-      .setLineHashes("NEW_LINE_HASHES")
-      .setDataType(Type.SOURCE)
-      .setUpdatedAt(1500000000002L));
-
-    checkTable("update", "file_sources", "project_uuid", "file_uuid", "data_hash", "line_hashes", "src_hash", "created_at", "updated_at", "data_type");
-  }
-
-  @Test
-  public void update_date_when_updated_date_is_zero() {
-    setupData("update_date_when_updated_date_is_zero");
-
-    sut.updateDateWhenUpdatedDateIsZero(session, "ABCD", 1500000000002L);
-    session.commit();
-
-    checkTable("update_date_when_updated_date_is_zero", "file_sources", "project_uuid", "file_uuid", "data_hash", "line_hashes", "src_hash", "created_at", "updated_at",
-      "data_type");
-  }
-
-  private static class ReaderToStringFunction implements Function<Reader, String> {
-
-    String result = null;
-
-    @Override
-    public String apply(Reader input) {
-      try {
-        result = IOUtils.toString(input);
-        return IOUtils.toString(input);
-      } catch (IOException e) {
-        throw new RuntimeException(e);
-      }
-    }
-  }
-
-  private static class InputStreamToStringFunction implements Function<InputStream, String> {
-
-    String result = null;
-
-    @Override
-    public String apply(InputStream input) {
-      try {
-        result = IOUtils.toString(input);
-        return IOUtils.toString(input);
-      } catch (IOException e) {
-        throw new RuntimeException(e);
-      }
-    }
-  }
-}
index ea481ab7f119867d3f279bbe5a066bb8bd9889ff..8d927b7b7be18c69a8e7acdb1b452ea1a1dd17f3 100644 (file)
@@ -26,6 +26,7 @@ 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;
@@ -42,7 +43,7 @@ import static org.junit.Assert.fail;
 public class SourceLineResultSetIteratorTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(SourceLineResultSetIteratorTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, SourceLineResultSetIteratorTest.class, "schema.sql");
 
   DbClient dbClient;
 
index 85bb53dacd88590aa266fefc9fbdb9e5275aa1e1..8e848028297f91b78a760f9df666756fbcb3fe84 100644 (file)
@@ -34,7 +34,7 @@ import org.sonar.server.component.db.ComponentDao;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.source.db.FileSourceDao;
+import org.sonar.db.source.FileSourceDao;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsTester;
 import org.sonar.test.DbTests;
index 6eb2e705d6cdc48d26bb6486e4a778df67ef0324..dc5e60c7c0bc78f1e46d7b8c690ca028d0d7c011 100644 (file)
  */
 package org.sonar.server.startup;
 
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
 import org.junit.Rule;
 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.issue.IssueFilterDao;
 import org.sonar.db.DbTester;
+import org.sonar.db.dashboard.DashboardDao;
+import org.sonar.db.dashboard.WidgetDao;
+import org.sonar.db.dashboard.WidgetPropertyDao;
+import org.sonar.db.issue.IssueFilterDao;
 import org.sonar.db.loadedtemplate.LoadedTemplateDao;
-import org.sonar.server.dashboard.db.DashboardDao;
-import org.sonar.server.dashboard.db.WidgetDao;
-import org.sonar.server.dashboard.db.WidgetPropertyDao;
 import org.sonar.server.db.DbClient;
 import org.sonar.test.DbTests;
 
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -86,7 +85,7 @@ public class RenameIssueWidgetsTest {
         new WidgetPropertyDao(dbTester.myBatis()),
         new IssueFilterDao(dbTester.myBatis()),
         new LoadedTemplateDao(dbTester.myBatis()),
-        new DashboardDao()
+        new DashboardDao(dbTester.myBatis())
       ),
       system2,
       null);
index 3a10470bd05a42aedfb7b2ce85bb8fb317907e77..447158852ba6ca518602120d0f3b6ef5a5d1e87c 100644 (file)
@@ -32,7 +32,7 @@ import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.web.UserRole;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
-import org.sonar.server.measure.persistence.MeasureDao;
+import org.sonar.db.measure.MeasureDao;
 import org.sonar.server.tester.UserSessionRule;
 
 import static org.assertj.core.api.Assertions.assertThat;
index 7e6e9e9bac830a343a8f5e8cdf537d7c268ac141..b144a1076202d76c9725fa39d1ff8973fee4a9b8 100644 (file)
@@ -27,6 +27,7 @@ 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;
@@ -49,7 +50,7 @@ import static org.assertj.core.api.Assertions.fail;
 public class TestResultSetIteratorTest {
 
   @ClassRule
-  public static DbTester db = new DbTester().schema(SourceLineResultSetIteratorTest.class, "schema.sql");
+  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, SourceLineResultSetIteratorTest.class, "schema.sql");
 
   DbClient dbClient;
 
index 7a29f2c991658266e9414812082192285bc73093..55332a06cc2e2c8c06386a75964e655ca9c105be 100644 (file)
@@ -55,11 +55,11 @@ import org.sonar.db.property.PropertyDto;
 import org.sonar.server.component.ComponentTesting;
 import org.sonar.server.component.SnapshotTesting;
 import org.sonar.server.component.db.ComponentDao;
-import org.sonar.server.component.db.SnapshotDao;
+import org.sonar.db.component.SnapshotDao;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.measure.persistence.MeasureDao;
+import org.sonar.db.measure.MeasureDao;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ui.Views;
 import org.sonar.server.user.db.UserDao;
index 531c7454b98f1590fb335daa98c7de1890b2d2c0..129b04fbd31660e26019ed73b9909af2fd7b58f0 100644 (file)
@@ -46,7 +46,7 @@ import org.sonar.server.exceptions.Message;
 import org.sonar.server.exceptions.ServerException;
 import org.sonar.server.user.db.GroupDao;
 import org.sonar.server.user.db.UserDao;
-import org.sonar.server.user.db.UserGroupDao;
+import org.sonar.db.user.UserGroupDao;
 import org.sonar.server.user.index.UserIndexDefinition;
 import org.sonar.server.user.index.UserIndexer;
 import org.sonar.server.util.Validation;
diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/db/UserGroupDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/db/UserGroupDaoTest.java
deleted file mode 100644 (file)
index a1a6b3d..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.server.user.db;
-
-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.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.db.user.UserGroupDto;
-import org.sonar.test.DbTests;
-
-@Category(DbTests.class)
-public class UserGroupDaoTest {
-
-  @ClassRule
-  public static DbTester db = new DbTester();
-
-  private UserGroupDao dao;
-  private DbSession session;
-
-  @Before
-  public void before() {
-    db.truncateTables();
-    this.session = db.myBatis().openSession(false);
-    this.dao = new UserGroupDao();
-  }
-
-  @After
-  public void after() {
-    this.session.close();
-  }
-
-  @Test
-  public void insert() {
-    UserGroupDto userGroupDto = new UserGroupDto().setUserId(1L).setGroupId(2L);
-    dao.insert(session, userGroupDto);
-    session.commit();
-
-    db.assertDbUnit(getClass(), "insert-result.xml", "groups_users");
-  }
-
-  @Test
-  public void delete_members_by_group_id() {
-    db.prepareDbUnit(getClass(), "delete_members_by_group_id.xml");
-    dao.deleteMembersByGroupId(session, 1L);
-    session.commit();
-    db.assertDbUnit(getClass(), "delete_members_by_group_id-result.xml", "groups_users");
-  }
-}
index fb7d43a9ba7bf973fb300aafe9eb2e9e7615bede..799f08c055bbda47f636569982fd9590e0073a14 100644 (file)
@@ -44,7 +44,7 @@ import org.sonar.server.user.SecurityRealmFactory;
 import org.sonar.server.user.UserUpdater;
 import org.sonar.server.user.db.GroupDao;
 import org.sonar.server.user.db.UserDao;
-import org.sonar.server.user.db.UserGroupDao;
+import org.sonar.db.user.UserGroupDao;
 import org.sonar.server.user.index.UserIndex;
 import org.sonar.server.user.index.UserIndexDefinition;
 import org.sonar.server.user.index.UserIndexer;
index 8f2dec21f98f60aed9d51a3635886310999c6897..ba7b24895e941eac58bafb21e96569a263885f5c 100644 (file)
@@ -45,7 +45,7 @@ import org.sonar.server.user.SecurityRealmFactory;
 import org.sonar.server.user.UserUpdater;
 import org.sonar.server.user.db.GroupDao;
 import org.sonar.server.user.db.UserDao;
-import org.sonar.server.user.db.UserGroupDao;
+import org.sonar.db.user.UserGroupDao;
 import org.sonar.server.user.index.UserDoc;
 import org.sonar.server.user.index.UserIndex;
 import org.sonar.server.user.index.UserIndexDefinition;
index fcebfae115fab5575ba094db0cfeecacb636e700..a9706d90a29f7d160d94671101101ed95ff3af02 100644 (file)
@@ -41,7 +41,7 @@ import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.user.db.GroupDao;
 import org.sonar.server.user.db.UserDao;
-import org.sonar.server.user.db.UserGroupDao;
+import org.sonar.db.user.UserGroupDao;
 import org.sonar.server.ws.WsTester;
 
 public class GroupsActionTest {
index 167d9104766faa06417917cbddc28cc7422a8075..9ff7ac2f9b1ad1e589c552f92bb04f2d1caa315f 100644 (file)
@@ -45,7 +45,7 @@ import org.sonar.server.es.EsTester;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.user.db.GroupDao;
 import org.sonar.server.user.db.UserDao;
-import org.sonar.server.user.db.UserGroupDao;
+import org.sonar.db.user.UserGroupDao;
 import org.sonar.server.user.index.UserDoc;
 import org.sonar.server.user.index.UserIndex;
 import org.sonar.server.user.index.UserIndexDefinition;
index f8b8dc24c943ba28b24c8a2d1d56fbe0e386b7e5..a69e8f946127c03f06b0cae5e989d68820463edb 100644 (file)
@@ -43,7 +43,7 @@ import org.sonar.server.user.SecurityRealmFactory;
 import org.sonar.server.user.UserUpdater;
 import org.sonar.server.user.db.GroupDao;
 import org.sonar.server.user.db.UserDao;
-import org.sonar.server.user.db.UserGroupDao;
+import org.sonar.db.user.UserGroupDao;
 import org.sonar.server.user.index.UserIndex;
 import org.sonar.server.user.index.UserIndexDefinition;
 import org.sonar.server.user.index.UserIndexer;
index 8c485f961429ee1e3adeb7eeaa7cabbfe1a2710e..bda2bf1b2ad9ff52fcd224c54419609dcee009bb 100644 (file)
@@ -43,7 +43,7 @@ import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.user.db.GroupDao;
 import org.sonar.server.user.db.UserDao;
-import org.sonar.server.user.db.UserGroupDao;
+import org.sonar.db.user.UserGroupDao;
 import org.sonar.server.ws.WsTester;
 import org.sonar.test.DbTests;
 
index 9a968201f4ea089b1b9d52c3641ae20b3cc40770..1d081d61fc3f55f14a9dd7993bb431ebff3dc62c 100644 (file)
@@ -42,7 +42,7 @@ import org.sonar.server.db.DbClient;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.user.db.GroupDao;
-import org.sonar.server.user.db.UserGroupDao;
+import org.sonar.db.user.UserGroupDao;
 import org.sonar.server.ws.WsTester;
 import org.sonar.test.DbTests;
 
index 4ea662d56ff5f8a79ece8ce88955ff27e753425a..e247b1c638aafd28c49b4485e4a7f4e6c66494a8 100644 (file)
@@ -42,7 +42,7 @@ import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.user.db.GroupDao;
 import org.sonar.server.user.db.UserDao;
-import org.sonar.server.user.db.UserGroupDao;
+import org.sonar.db.user.UserGroupDao;
 import org.sonar.server.ws.WsTester;
 import org.sonar.test.DbTests;
 
index 1b0c32aa1535e91098d563b565a783d6c435cdb7..c4652ddb63cfe3f89f8c0de8baaba01a5fa16566 100644 (file)
@@ -35,7 +35,7 @@ import org.sonar.db.user.GroupMembershipDao;
 import org.sonar.db.user.UserGroupDto;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.user.db.GroupDao;
-import org.sonar.server.user.db.UserGroupDao;
+import org.sonar.db.user.UserGroupDao;
 import org.sonar.server.ws.WsTester;
 import org.sonar.test.DbTests;
 
index ddf0684c8ec590960f310be3c9a528d9ca088843..b1a19799695ea22f2d471b3e1ca2c96690445490 100644 (file)
@@ -42,7 +42,7 @@ import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.exceptions.ServerException;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.user.db.GroupDao;
-import org.sonar.server.user.db.UserGroupDao;
+import org.sonar.db.user.UserGroupDao;
 import org.sonar.server.ws.WsTester;
 import org.sonar.test.DbTests;
 
index 3f0e123f116d1d8755db294d09e64942163f28f8..0976291ae7892d96eab5b87c3dd7f2f663d39ee7 100644 (file)
@@ -42,7 +42,7 @@ import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.user.db.GroupDao;
 import org.sonar.server.user.db.UserDao;
-import org.sonar.server.user.db.UserGroupDao;
+import org.sonar.db.user.UserGroupDao;
 import org.sonar.server.ws.WsTester;
 import org.sonar.server.ws.WsTester.TestRequest;
 import org.sonar.test.DbTests;
diff --git a/server/sonar-server/src/test/java/org/sonar/server/util/ProgressLoggerTest.java b/server/sonar-server/src/test/java/org/sonar/server/util/ProgressLoggerTest.java
deleted file mode 100644 (file)
index 2ffd1a9..0000000
+++ /dev/null
@@ -1,64 +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.util;
-
-import org.junit.Test;
-import org.sonar.api.utils.log.Logger;
-
-import java.util.concurrent.atomic.AtomicLong;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.*;
-
-public class ProgressLoggerTest {
-
-  @Test(timeout = 1000L)
-  public void log_at_fixed_intervals() throws Exception {
-    Logger logger = mock(Logger.class);
-    AtomicLong counter = new AtomicLong(42L);
-    ProgressLogger progress = new ProgressLogger("ProgressLoggerTest", counter, logger);
-    progress.setPeriodMs(1L);
-    progress.start();
-    Thread.sleep(80L);
-    progress.stop();
-    verify(logger, atLeast(1)).info(startsWith("42 rows processed"));
-
-    // ability to manual log, generally final status
-    counter.incrementAndGet();
-    progress.log();
-    verify(logger).info(startsWith("43 rows processed"));
-  }
-
-  @Test
-  public void create() {
-    ProgressLogger progress = ProgressLogger.create(getClass(), new AtomicLong());
-
-    // default values
-    assertThat(progress.getPeriodMs()).isEqualTo(60000L);
-    assertThat(progress.getPluralLabel()).isEqualTo("rows");
-
-    // override values
-    progress.setPeriodMs(10L);
-    progress.setPluralLabel("issues");
-    assertThat(progress.getPeriodMs()).isEqualTo(10L);
-    assertThat(progress.getPluralLabel()).isEqualTo("issues");
-
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/util/SlugTest.java b/server/sonar-server/src/test/java/org/sonar/server/util/SlugTest.java
deleted file mode 100644 (file)
index c2fe1f3..0000000
+++ /dev/null
@@ -1,39 +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.util;
-
-import org.junit.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class SlugTest {
-
-  @Test
-  public void slugify() {
-    assertThat(Slug.slugify("foo")).isEqualTo("foo");
-    assertThat(Slug.slugify("  FOO ")).isEqualTo("foo");
-    assertThat(Slug.slugify("he's here")).isEqualTo("he-s-here");
-    assertThat(Slug.slugify("foo-bar")).isEqualTo("foo-bar");
-    assertThat(Slug.slugify("foo_bar")).isEqualTo("foo_bar");
-    assertThat(Slug.slugify("accents Ã©Ã ")).isEqualTo("accents-ea");
-    assertThat(Slug.slugify("<foo>")).isEqualTo("foo");
-    assertThat(Slug.slugify("<\"foo:\">")).isEqualTo("foo");
-  }
-}
index a8fe4fd41c0ef1ded1c55f53b3487cdf37ec98c1..848293f400c02503a5432f0e3eae896ee0027a10 100644 (file)
@@ -48,13 +48,13 @@ import org.sonar.server.es.SearchOptions;
 import org.sonar.server.es.SearchResult;
 import org.sonar.server.issue.IssueQuery;
 import org.sonar.server.issue.IssueTesting;
-import org.sonar.server.issue.db.IssueDao;
+import org.sonar.db.issue.IssueDao;
 import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 import org.sonar.server.issue.index.IssueDoc;
 import org.sonar.server.issue.index.IssueIndex;
 import org.sonar.server.issue.index.IssueIndexDefinition;
 import org.sonar.server.issue.index.IssueIndexer;
-import org.sonar.server.rule.RuleTesting;
+import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.rule.db.RuleDao;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.test.DbTests;
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentIndexDaoTest/select_project_ids_from_query_and_view_or_sub_view_uuid.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentIndexDaoTest/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/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/delete.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/delete.xml
deleted file mode 100644 (file)
index 8b89e72..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-
-  <project_links id="1" component_uuid="ABCD" link_type="homepage" name="Home" href="http://www.sonarqube.org"/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/empty.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/empty.xml
deleted file mode 100644 (file)
index 871dedc..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<dataset>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/insert-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/insert-result.xml
deleted file mode 100644 (file)
index 8b89e72..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-
-  <project_links id="1" component_uuid="ABCD" link_type="homepage" name="Home" href="http://www.sonarqube.org"/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/shared.xml
deleted file mode 100644 (file)
index 33e9449..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<dataset>
-
-  <project_links id="1" component_uuid="ABCD" link_type="homepage" name="Home" href="http://www.sonarqube.org"/>
-  <project_links id="2" component_uuid="ABCD" link_type="scm" name="Sources" href="https://github.com/SonarSource/sonar"/>
-  <project_links id="3" component_uuid="BCDE" link_type="homepage" name="Home" href="http://www.struts.org"/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/update-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/update-result.xml
deleted file mode 100644 (file)
index 8b89e72..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-
-  <project_links id="1" component_uuid="ABCD" link_type="homepage" name="Home" href="http://www.sonarqube.org"/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/update.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/update.xml
deleted file mode 100644 (file)
index 6b80fc9..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-
-  <project_links id="1" component_uuid="BCDE" link_type="ci" name="CI" href="github"/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/empty.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/empty.xml
deleted file mode 100644 (file)
index 871dedc..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<dataset>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/insert-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/insert-result.xml
deleted file mode 100644 (file)
index a138d68..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-<dataset>
-
-  <snapshots id="1" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
-             status="P" islast="[true]" purge_status="1"
-             period1_mode="days1" period1_param="30" period1_date="1500000000001"
-             period2_mode="days2" period2_param="31" period2_date="1500000000002"
-             period3_mode="days3" period3_param="32" period3_date="1500000000003"
-             period4_mode="days4" period4_param="33" period4_date="1500000000004"
-             period5_mode="days5" period5_param="34" period5_date="1500000000005"
-             depth="1" scope="DIR" qualifier="PAC" created_at="1403042400000" build_date="1500000000006"
-             version="2.1-SNAPSHOT" path="1.2."/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/modules.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/modules.xml
deleted file mode 100644 (file)
index 9ba70be..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-<dataset>
-
-  <!-- root project -->
-  <projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
-            uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
-            description="the description" long_name="Apache Struts"
-            enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" path="[null]" authorization_updated_at="[null]" />
-  <snapshots id="1" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
-             status="P" islast="[true]" purge_status="[null]"
-             period1_mode="[null]" period1_param="[null]" period1_date="[null]"
-             period2_mode="[null]" period2_param="[null]" period2_date="[null]"
-             period3_mode="[null]" period3_param="[null]" period3_date="[null]"
-             period4_mode="[null]" period4_param="[null]" period4_date="[null]"
-             period5_mode="[null]" period5_param="[null]" period5_date="[null]"
-             depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000"
-             version="[null]" path=""/>
-  <snapshots id="10" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
-             status="P" islast="[false]" purge_status="[null]"
-             period1_mode="[null]" period1_param="[null]" period1_date="[null]"
-             period2_mode="[null]" period2_param="[null]" period2_date="[null]"
-             period3_mode="[null]" period3_param="[null]" period3_date="[null]"
-             period4_mode="[null]" period4_param="[null]" period4_date="[null]"
-             period5_mode="[null]" period5_param="[null]" period5_date="[null]"
-             depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228136280000" build_date="1228136280000"
-             version="[null]" path=""/>
-
-  <!-- module -->
-  <projects id="2" root_id="1" kee="org.struts:struts-core" name="Struts Core"
-            uuid="EFGH" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD."
-            scope="PRJ" qualifier="BRC" long_name="Struts Core"
-            description="[null]" enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" authorization_updated_at="[null]" />
-  <snapshots id="2" project_id="2" parent_snapshot_id="1" root_project_id="1" root_snapshot_id="1"
-             status="P" islast="[true]" purge_status="[null]"
-             period1_mode="[null]" period1_param="[null]" period1_date="[null]"
-             period2_mode="[null]" period2_param="[null]" period2_date="[null]"
-             period3_mode="[null]" period3_param="[null]" period3_date="[null]"
-             period4_mode="[null]" period4_param="[null]" period4_date="[null]"
-             period5_mode="[null]" period5_param="[null]" period5_date="[null]"
-             depth="[null]" scope="PRJ" qualifier="BRC" created_at="1228222680000" build_date="1228222680000"
-             version="[null]" path="1."/>
-
-  <!-- sub module -->
-  <projects id="3" root_id="1" kee="org.struts:struts-data" name="Struts Data"
-            uuid="FGHI" project_uuid="ABCD" module_uuid="EFGH" module_uuid_path=".ABCD.EFGH."
-            scope="PRJ" qualifier="BRC" long_name="Struts Data"
-            description="[null]" enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" authorization_updated_at="[null]" />
-  <snapshots id="3" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
-             status="P" islast="[true]" purge_status="[null]"
-             period1_mode="[null]" period1_param="[null]" period1_date="[null]"
-             period2_mode="[null]" period2_param="[null]" period2_date="[null]"
-             period3_mode="[null]" period3_param="[null]" period3_date="[null]"
-             period4_mode="[null]" period4_param="[null]" period4_date="[null]"
-             period5_mode="[null]" period5_param="[null]" period5_date="[null]"
-             depth="[null]" scope="PRJ" qualifier="BRC" created_at="1228222680000" build_date="1228222680000"
-             version="[null]" path="1.2."/>
-
-  <!-- directory -->
-  <projects long_name="org.struts" id="4" scope="DIR" qualifier="DIR" kee="org.struts:struts-core:src/org/struts"
-            uuid="GHIJ" project_uuid="ABCD" module_uuid="FGHI" module_uuid_path=".ABCD.EFGH.FGHI."
-            name="src/org/struts" root_id="3"
-            description="[null]"
-            enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" path="src/org/struts" authorization_updated_at="[null]" />
-  <snapshots id="4" project_id="4" parent_snapshot_id="3" root_project_id="1" root_snapshot_id="1"
-             status="P" islast="[true]" purge_status="[null]"
-             period1_mode="[null]" period1_param="[null]" period1_date="[null]"
-             period2_mode="[null]" period2_param="[null]" period2_date="[null]"
-             period3_mode="[null]" period3_param="[null]" period3_date="[null]"
-             period4_mode="[null]" period4_param="[null]" period4_date="[null]"
-             period5_mode="[null]" period5_param="[null]" period5_date="[null]"
-             depth="[null]" scope="DIR" qualifier="PAC" created_at="1228222680000" build_date="1228222680000"
-             version="[null]" path="1.2.3."/>
-
-  <!-- file -->
-  <projects long_name="org.struts.RequestContext" id="5" scope="FIL" qualifier="FIL" kee="org.struts:struts-core:src/org/struts/RequestContext.java"
-            uuid="HIJK" project_uuid="ABCD" module_uuid="FGHI" module_uuid_path=".ABCD.EFGH.FGHI."
-            name="RequestContext.java" root_id="3"
-            description="[null]"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" path="src/org/struts/RequestContext.java" authorization_updated_at="[null]" />
-
-  <snapshots id="5" project_id="5" parent_snapshot_id="4" root_project_id="1" root_snapshot_id="1"
-             status="P" islast="[true]" purge_status="[null]"
-             period1_mode="[null]" period1_param="[null]" period1_date="[null]"
-             period2_mode="[null]" period2_param="[null]" period2_date="[null]"
-             period3_mode="[null]" period3_param="[null]" period3_date="[null]"
-             period4_mode="[null]" period4_param="[null]" period4_date="[null]"
-             period5_mode="[null]" period5_param="[null]" period5_date="[null]"
-             depth="[null]" scope="FIL" qualifier="CLA" created_at="1228222680000" build_date="1228222680000"
-             version="[null]" path="1.2.3.4."/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/select_previous_version_snapshots.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/select_previous_version_snapshots.xml
deleted file mode 100644 (file)
index 3f56960..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-<dataset>
-
-  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
-            root_id="[null]" uuid="ABCD"
-            description="[null]"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
-  <!-- version 1.0 -->
-  <snapshots id="1000" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
-             period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
-             period5_param="[null]" period5_date="[null]"
-             project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="1225630680000" build_date="1225630680000" version="1.0" path=""
-             status="P" islast="[false]" depth="0"/>
-
-  <!-- version 1.1 -->
-  <snapshots id="1001" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
-             period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
-             period5_param="[null]" period5_date="[null]"
-             project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="1225803480000" build_date="1225803480000" version="1.1" path=""
-             status="P" islast="[false]" depth="0"/>
-
-  <!-- version 1.2-SNAPSHOT -->
-  <snapshots id="1002" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
-             period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
-             period5_param="[null]" period5_date="[null]"
-             project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="1225976280000" build_date="1225976280000" version="1.2-SNAPSHOT" path=""
-             status="P" islast="[false]" depth="0"/>
-
-  <!-- version 1.2-SNAPSHOT, current analysis -->
-  <snapshots id="1003" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
-             period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
-             period5_param="[null]" period5_date="[null]"
-             project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="1226235480000" build_date="1226235480000" version="1.2-SNAPSHOT" path=""
-             status="U" islast="[true]" depth="0"/>
-
-  <events id="1" name="1.0" component_uuid="ABCD" snapshot_id="1000" category="Version" event_date="1225630680000" created_at="1225630680000" description="" event_data="[null]"/>
-  <events id="2" name="Foo" component_uuid="ABCD" snapshot_id="1000" category="Other" event_date="1225717080000" created_at="1225717080000" description="" event_data="[null]"/>
-  <events id="3" name="1.1" component_uuid="ABCD" snapshot_id="1001" category="Version" event_date="1225803480000" created_at="1225803480000" description="" event_data="[null]"/>
-  <events id="4" name="Bar" component_uuid="ABCD" snapshot_id="1001" category="Other" event_date="1225889880000" created_at="1225889880000" description="" event_data="[null]"/>
-  <events id="5" name="Uhh" component_uuid="ABCD" snapshot_id="1002" category="Other" event_date="1226062680000" created_at="1226062680000" description="" event_data="[null]"/>
-  <events id="6" name="1.2-SNAPSHOT" component_uuid="ABCD" snapshot_id="1003" category="Version" event_date="1226235480000" created_at="1226235480000" description=""
-          event_data="[null]"/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/select_snapshots_by_query.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/select_snapshots_by_query.xml
deleted file mode 100644 (file)
index 1f32010..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-<dataset>
-
-  <!-- PROJECT_ID = 1 -->
-  <snapshots id="1" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
-             status="P" islast="[true]" purge_status="1"
-             period1_mode="days1" period1_param="30" period1_date="1316815200000"
-             period2_mode="days2" period2_param="31" period2_date="1316901600000"
-             period3_mode="days3" period3_param="32" period3_date="1316988000000"
-             period4_mode="days4" period4_param="33" period4_date="1317074400000"
-             period5_mode="days5" period5_param="34" period5_date="1317160800000"
-             depth="1" scope="PRJ" qualifier="PAC" created_at="1228172400001" build_date="1317247200000"
-             version="2.0-SNAPSHOT" path="1.2."/>
-  <snapshots id="2" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
-             status="P" islast="[false]" purge_status="1"
-             period1_mode="days1" period1_param="30" period1_date="1316815200000"
-             period2_mode="days2" period2_param="31" period2_date="1316901600000"
-             period3_mode="days3" period3_param="32" period3_date="1316988000000"
-             period4_mode="days4" period4_param="33" period4_date="1317074400000"
-             period5_mode="days5" period5_param="34" period5_date="1317160800000"
-             depth="1" scope="DIR" qualifier="PAC" created_at="1228172400002" build_date="1317247200000"
-             version="2.1-SNAPSHOT" path="1.2."/>
-  <snapshots id="3" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
-             status="P" islast="[false]" purge_status="1"
-             period1_mode="days1" period1_param="30" period1_date="1316815200000"
-             period2_mode="days2" period2_param="31" period2_date="1316901600000"
-             period3_mode="days3" period3_param="32" period3_date="1316988000000"
-             period4_mode="days4" period4_param="33" period4_date="1317074400000"
-             period5_mode="days5" period5_param="34" period5_date="1317160800000"
-             depth="1" scope="DIR" qualifier="PAC" created_at="1228172400003" build_date="1317247200000"
-             version="2.2-SNAPSHOT" path="1.2."/>
-
-  <!-- PROJECT_ID = 2 -->
-  <snapshots id="4" project_id="2" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
-             status="P" islast="[true]" purge_status="1"
-             period1_mode="days1" period1_param="30" period1_date="1316815200000"
-             period2_mode="days2" period2_param="31" period2_date="1316901600000"
-             period3_mode="days3" period3_param="32" period3_date="1316988000000"
-             period4_mode="days4" period4_param="33" period4_date="1317074400000"
-             period5_mode="days5" period5_param="34" period5_date="1317160800000"
-             depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
-             version="2.1-SNAPSHOT" path="1.2."/>
-  <!-- Unprocessed snapshot -->
-  <snapshots id="5" project_id="2" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
-             status="U" islast="[true]" purge_status="1"
-             period1_mode="days1" period1_param="30" period1_date="1316815200000"
-             period2_mode="days2" period2_param="31" period2_date="1316901600000"
-             period3_mode="days3" period3_param="32" period3_date="1316988000000"
-             period4_mode="days4" period4_param="33" period4_date="1317074400000"
-             period5_mode="days5" period5_param="34" period5_date="1317160800000"
-             depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
-             version="2.1-SNAPSHOT" path="1.2."/>
-
-  <!-- PROJECT_ID = 3 - no last snapshot -->
-  <snapshots id="6" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
-             status="P" islast="[false]" purge_status="1"
-             period1_mode="days1" period1_param="30" period1_date="1316815200000"
-             period2_mode="days2" period2_param="31" period2_date="1316901600000"
-             period3_mode="days3" period3_param="32" period3_date="1316988000000"
-             period4_mode="days4" period4_param="33" period4_date="1317074400000"
-             period5_mode="days5" period5_param="34" period5_date="1317160800000"
-             depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
-             version="2.1-SNAPSHOT" path="1.2."/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/shared.xml
deleted file mode 100644 (file)
index a52b271..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-<dataset>
-
-  <snapshots id="3" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
-             status="P" islast="[true]" purge_status="1"
-             period1_mode="days1" period1_param="30" period1_date="1316815200000"
-             period2_mode="days2" period2_param="31" period2_date="1316901600000"
-             period3_mode="days3" period3_param="32" period3_date="1316988000000"
-             period4_mode="days4" period4_param="33" period4_date="1317074400000"
-             period5_mode="days5" period5_param="34" period5_date="1317160800000"
-             depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
-             version="2.1-SNAPSHOT" path="1.2."/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/snapshots.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/snapshots.xml
deleted file mode 100644 (file)
index 4c18e25..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-<dataset>
-
-  <!-- PROJECT_ID = 1 -->
-  <snapshots id="1" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
-             status="P" islast="[true]" purge_status="1"
-             period1_mode="days1" period1_param="30" period1_date="1316815200000"
-             period2_mode="days2" period2_param="31" period2_date="1316901600000"
-             period3_mode="days3" period3_param="32" period3_date="1316988000000"
-             period4_mode="days4" period4_param="33" period4_date="1317074400000"
-             period5_mode="days5" period5_param="34" period5_date="1317160800000"
-             depth="1" scope="PRJ" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
-             version="2.1-SNAPSHOT" path="1.2."/>
-  <snapshots id="2" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
-             status="P" islast="[false]" purge_status="1"
-             period1_mode="days1" period1_param="30" period1_date="1316815200000"
-             period2_mode="days2" period2_param="31" period2_date="1316901600000"
-             period3_mode="days3" period3_param="32" period3_date="1316988000000"
-             period4_mode="days4" period4_param="33" period4_date="1317074400000"
-             period5_mode="days5" period5_param="34" period5_date="1317160800000"
-             depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
-             version="2.1-SNAPSHOT" path="1.2."/>
-  <snapshots id="3" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
-             status="P" islast="[false]" purge_status="1"
-             period1_mode="days1" period1_param="30" period1_date="1316815200000"
-             period2_mode="days2" period2_param="31" period2_date="1316901600000"
-             period3_mode="days3" period3_param="32" period3_date="1316988000000"
-             period4_mode="days4" period4_param="33" period4_date="1317074400000"
-             period5_mode="days5" period5_param="34" period5_date="1317160800000"
-             depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
-             version="2.1-SNAPSHOT" path="1.2."/>
-
-
-  <!-- PROJECT_ID = 2 -->
-  <snapshots id="4" project_id="2" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
-             status="P" islast="[true]" purge_status="1"
-             period1_mode="days1" period1_param="30" period1_date="1316815200000"
-             period2_mode="days2" period2_param="31" period2_date="1316901600000"
-             period3_mode="days3" period3_param="32" period3_date="1316988000000"
-             period4_mode="days4" period4_param="33" period4_date="1317074400000"
-             period5_mode="days5" period5_param="34" period5_date="1317160800000"
-             depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
-             version="2.1-SNAPSHOT" path="1.2."/>
-
-  <!-- PROJECT_ID = 3 - no last snapshot -->
-  <snapshots id="5" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
-             status="P" islast="[false]" purge_status="1"
-             period1_mode="days1" period1_param="30" period1_date="1316815200000"
-             period2_mode="days2" period2_param="31" period2_date="1316901600000"
-             period3_mode="days3" period3_param="32" period3_date="1316988000000"
-             period4_mode="days4" period4_param="33" period4_date="1317074400000"
-             period5_mode="days5" period5_param="34" period5_date="1317160800000"
-             depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
-             version="2.1-SNAPSHOT" path="1.2."/>
-
-  <!-- Child of snapshot id=1 -->
-  <snapshots id="6" project_id="55" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
-             status="P" islast="[true]" purge_status="1"
-             period1_mode="days1" period1_param="30" period1_date="1316815200000"
-             period2_mode="days2" period2_param="31" period2_date="1316901600000"
-             period3_mode="days3" period3_param="32" period3_date="1316988000000"
-             period4_mode="days4" period4_param="33" period4_date="1317074400000"
-             period5_mode="days5" period5_param="34" period5_date="1317160800000"
-             depth="1" scope="PRJ" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
-             version="2.1-SNAPSHOT" path="1.2."/>
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/any-analysis-reports.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/any-analysis-reports.xml
deleted file mode 100644 (file)
index dba17d0..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<dataset>
-  <analysis_reports
-      id="1"
-      uuid="REPORT_1"
-      project_key="123456789-987654321"
-      report_status="WORKING"
-      created_at="1411509600000"
-      updated_at="1411509600000"
-      />
-  <analysis_reports
-      id="2"
-      uuid="REPORT_2"
-      project_key="123456789-987654321"
-      report_status="WORKING"
-      created_at="1411596000000"
-      updated_at="1411596000000"
-      />
-  <analysis_reports
-      id="3"
-      uuid="REPORT_3"
-      project_key="123456789-987654321"
-      report_status="PENDING"
-      created_at="1411682400000"
-      updated_at="1411682400000"
-      />
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/book_available_report_analysis_while_having_one_working_on_another_project.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/book_available_report_analysis_while_having_one_working_on_another_project.xml
deleted file mode 100644 (file)
index ae28bef..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<dataset>
-  <analysis_reports
-      id="1"
-      project_key="123456789-987654321"
-      uuid="REPORT_1"
-      report_status="PENDING"
-      created_at="1411509600000"
-      updated_at="1411596000000"
-      />
-  <analysis_reports
-      id="2"
-      project_key="987654321-123456789"
-      uuid="REPORT_2"
-      report_status="WORKING"
-      created_at="1411423200000"
-      updated_at="1411682400000"
-      />
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/empty.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/empty.xml
deleted file mode 100644 (file)
index 871dedc..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<dataset>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml
deleted file mode 100644 (file)
index d25e364..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-<dataset>
-  <analysis_reports
-      id="1"
-      project_key="ProjectKey1"
-      project_name="Project 1"
-      uuid="UUID_1"
-      report_status="PENDING"
-      started_at="[null]"
-      finished_at="[null]"
-      created_at="1500000000000"
-      updated_at="1500000000000"
-      />
-  <analysis_reports
-      id="2"
-      project_key="ProjectKey2"
-      project_name="Project 2"
-      uuid="UUID_2"
-      report_status="PENDING"
-      started_at="[null]"
-      finished_at="[null]"
-      created_at="1500000000000"
-      updated_at="1500000000000"
-      />
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/one_analysis_report.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/one_analysis_report.xml
deleted file mode 100644 (file)
index c38ac12..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<dataset>
-  <analysis_reports
-      id="1"
-      project_key="123456789-987654321"
-      uuid="REPORT_1"
-      report_status="WORKING"
-      created_at="1500000000001"
-      updated_at="1500000000002"
-      started_at="1500000000003"
-      finished_at="1500000000004"
-      />
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/pop_null_if_no_pending_reports.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/pop_null_if_no_pending_reports.xml
deleted file mode 100644 (file)
index 82f93e9..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-<dataset>
-  <analysis_reports
-      id="1"
-      project_key="111111111-987654321"
-      uuid="UUID_1"
-      report_status="WORKING"
-      created_at="1411596000000"
-      updated_at="1411682400000"
-      />
-  <analysis_reports
-      id="2"
-      project_key="123456789-987654321"
-      uuid="UUID_2"
-      report_status="WORKING"
-      created_at="1411509600000"
-      updated_at="1411682400000"
-      />
-  <!-- not select as the previous report which is working is on the same project -->
-  <analysis_reports
-      id="3"
-      project_key="123456789-987654321"
-      uuid="UUID_3"
-      report_status="PENDING"
-      created_at="1411596000000"
-      updated_at="1411682400000"
-      />
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/pop_oldest_pending.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/pop_oldest_pending.xml
deleted file mode 100644 (file)
index 972fde8..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-<dataset>
-  <!-- WORKING -->
-  <analysis_reports
-    id="1"
-    project_key="P1"
-    uuid="UUID_1"
-    report_status="WORKING"
-    created_at="1411596000000"
-    updated_at="1411682400000"
-    />
-
-  <!-- PENDING on P1, which is already being WORKING-->
-  <analysis_reports
-    id="2"
-    project_key="P1"
-    uuid="UUID_2"
-    report_status="PENDING"
-    created_at="1411509600000"
-    updated_at="1411682400000"
-    />
-  <analysis_reports
-    id="3"
-    project_key="P2"
-    uuid="UUID_3"
-    report_status="PENDING"
-    created_at="1411596000000"
-    updated_at="1411682400000"
-    />
-  <analysis_reports
-    id="4"
-    project_key="P2"
-    uuid="UUID_4"
-    report_status="PENDING"
-    created_at="1420066800000"
-    updated_at="1420066800000"
-    />
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/select.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/select.xml
deleted file mode 100644 (file)
index de9d5b9..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-<dataset>
-  <analysis_reports
-      id="1"
-      project_key="123456789-987654321"
-      project_name="Project 1"
-      uuid="UUID_1"
-      report_status="WORKING"
-      created_at="1411509600000"
-      updated_at="1411596000000"
-      />
-  <analysis_reports
-      id="2"
-      project_key="987654321-123456789"
-      project_name="Project 2"
-      uuid="UUID_2"
-      report_status="WORKING"
-      created_at="1411596000000"
-      updated_at="1411596000000"
-      />
-  <analysis_reports
-      id="3"
-      project_key="987654321-123456789"
-      project_name="Project 2"
-      uuid="UUID_3"
-      report_status="PENDING"
-      created_at="1411682400000"
-      updated_at="1411682400000"
-      />
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/three_analysis_reports.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/three_analysis_reports.xml
deleted file mode 100644 (file)
index c1e3284..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<dataset>
-  <analysis_reports
-      id="1"
-      project_key="123456789-987654321"
-      uuid="UUID_1"
-      report_status="WORKING"
-      created_at="1411509600000"
-      updated_at="1411596000000"
-      />
-  <analysis_reports
-      id="2"
-      project_key="987654321-123456789"
-      uuid="UUID_2"
-      report_status="WORKING"
-      created_at="1411596000000"
-      updated_at="1411596000000"
-      />
-  <analysis_reports
-      id="3"
-      project_key="987654321-123456789"
-      uuid="UUID_3"
-      report_status="PENDING"
-      created_at="1411682400000"
-      updated_at="1411682400000"
-      />
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/truncate-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/truncate-result.xml
deleted file mode 100644 (file)
index e573e0c..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<dataset>
-  <analysis_reports/>
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/update-all-to-status-pending-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/update-all-to-status-pending-result.xml
deleted file mode 100644 (file)
index 16fb8dc..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-<dataset>
-    <!-- all rows are PENDING, updated_at is now, started_at is null -->
-    <analysis_reports
-      id="1"
-      project_key="P1"
-      project_name="Project1"
-      uuid="UUID_1"
-      report_status="PENDING"
-      created_at="1411509600000"
-      updated_at="1500000000000"
-      started_at="[null]"
-      finished_at="[null]"
-      />
-    <analysis_reports
-      id="2"
-      project_key="P2"
-      project_name="Project2"
-      uuid="UUID_2"
-      report_status="PENDING"
-      created_at="1411596000000"
-      updated_at="1500000000000"
-      started_at="[null]"
-      finished_at="[null]"
-      />
-    <analysis_reports
-      id="3"
-      project_key="P1"
-      project_name="Project1"
-      uuid="UUID_3"
-      report_status="PENDING"
-      created_at="1411682400000"
-      updated_at="1500000000000"
-      started_at="[null]"
-      finished_at="[null]"
-      />
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/update-all-to-status-pending.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/update-all-to-status-pending.xml
deleted file mode 100644 (file)
index a630cb4..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-<dataset>
-  <analysis_reports
-      id="1"
-      project_key="P1"
-      project_name="Project1"
-      uuid="UUID_1"
-      report_status="WORKING"
-      created_at="1411509600000"
-      updated_at="1411509600000"
-      started_at="1411509600000"
-      finished_at="[null]"
-      />
-  <analysis_reports
-      id="2"
-      project_key="P2"
-      project_name="Project2"
-      uuid="UUID_2"
-      report_status="WORKING"
-      created_at="1411596000000"
-      updated_at="1411596000000"
-      started_at="1411509600000"
-      finished_at="[null]"
-      />
-  <analysis_reports
-      id="3"
-      project_key="P1"
-      project_name="Project1"
-      uuid="UUID_3"
-      report_status="PENDING"
-      created_at="1411682400000"
-      updated_at="1411682400000"
-      started_at="[null]"
-      finished_at="[null]"
-      />
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/zip.zip b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/zip.zip
deleted file mode 100644 (file)
index a540bc5..0000000
Binary files a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/zip.zip and /dev/null differ
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/dashboard/db/WidgetDaoTest/before.xml b/server/sonar-server/src/test/resources/org/sonar/server/dashboard/db/WidgetDaoTest/before.xml
deleted file mode 100644 (file)
index a942341..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<dataset>
-
-  <widgets id="1" dashboard_id="1" widget_key="polop" name="Polop" description="Palap"
-     column_index="1" row_index="1" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
-
-  <widgets id="2" dashboard_id="1" widget_key="false_positive_reviews" name="Polop" description="Palap"
-     column_index="1" row_index="2" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
-
-  <widgets id="3" dashboard_id="1" widget_key="my_reviews" name="Polop" description="Palap"
-     column_index="1" row_index="3" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
-
-  <widgets id="4" dashboard_id="1" widget_key="reviews_per_developer" name="Polop" description="Palap"
-     column_index="1" row_index="4" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
-
-  <widgets id="5" dashboard_id="1" widget_key="unresolved_issues_statuses" name="Polop" description="Palap"
-     column_index="1" row_index="5" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/ResultSetIteratorTest/feed.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/ResultSetIteratorTest/feed.xml
deleted file mode 100644 (file)
index f072b93..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-  <fake id="10" kee="AB" />
-  <fake id="20" kee="CD" />
-  <fake id="30" kee="EF" />
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/ResultSetIteratorTest/schema.sql b/server/sonar-server/src/test/resources/org/sonar/server/db/ResultSetIteratorTest/schema.sql
deleted file mode 100644 (file)
index 09a2922..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-CREATE TABLE "FAKE" (
-  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
-  "KEE" VARCHAR(200) NOT NULL
-);
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/delete.xml b/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/delete.xml
deleted file mode 100644 (file)
index c22a68e..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<dataset>
-
-  <events id="1" name="1.0" category="Version" description="Version 1.0" event_data="some data" event_date="1225630680000"
-          component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/empty.xml b/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/empty.xml
deleted file mode 100644 (file)
index 871dedc..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<dataset>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/insert-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/insert-result.xml
deleted file mode 100644 (file)
index 27a2a24..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<dataset>
-
-  <events id="1" name="1.0" category="Version" description="Version 1.0" event_data="some data" event_date="1413407091086"
-          component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/shared.xml
deleted file mode 100644 (file)
index 0002dee..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-<dataset>
-
-  <events id="1" name="1.0" category="Version" description="Version 1.0" event_data="some data" event_date="1413407091086"
-          component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
-  <events id="2" name="Red (was Orange)" category="Alert" description="Critical issues variation > 0 since previous version (1.0 - 2015 Feb 09), Open issues > 0"
-          event_data="[null]" event_date="1413407091086" component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
-  <events id="3" name="Changes in 'Default' (Java)" category="Profile" description="Version 1.0" event_data="from=2014-10-12T08:36:25+0000;key=java-default;to=2014-10-12T10:36:25+0000"
-          event_date="1413407091086" component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
-
-  <events id="4" name="1.0" category="Version" description="Version 1.0" event_data="some data" event_date="1413407091086"
-          component_uuid="BCDE" snapshot_id="1000" created_at="1225630680000" />
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/empty.xml b/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/empty.xml
deleted file mode 100644 (file)
index dda1882..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<dataset>
-  <project_measures/>
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/insert-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/insert-result.xml
deleted file mode 100644 (file)
index 26c55c5..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-<dataset>
-  <project_measures
-      id="1"
-      snapshot_id="2"
-      metric_id="3"
-      characteristic_id="4"
-      rule_id="5"
-      project_id="6"
-      person_id="23"
-      value="2.0"
-      text_value="measure-value"
-      tendency="[null]"
-      rule_priority="[null]"
-      measure_date="[null]"
-      measure_data="[null]"
-      variation_value_1="1.0"
-      variation_value_2="2.0"
-      variation_value_3="3.0"
-      variation_value_4="4.0"
-      variation_value_5="5.0"
-      alert_status="alert"
-      alert_text="alert-text"
-      url="[null]"
-      description="measure-description"
-      rules_category_id="[null]"
-      />
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/past_measures.xml b/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/past_measures.xml
deleted file mode 100644 (file)
index 1a9eaec..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-<dataset>
-
-  <metrics id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]" enabled="[true]"/>
-
-  <metrics id="2" name="coverage" VAL_TYPE="INT" enabled="[true]"/>
-
-
-  <rules tags="[null]" system_tags="[null]" id="30" name="Check Header" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck"
-         plugin_config_key="Checker/Treewalker/HeaderCheck" plugin_name="checkstyle" description="[null]" priority="4" status="READY"
-         is_template="[false]" template_id="[null]"/>
-
-  <rules tags="[null]" system_tags="[null]" id="31" name="Equals Avoid Null" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck"
-         plugin_config_key="Checker/TreeWalker/EqualsAvoidNull" plugin_name="checkstyle" description="[null]" priority="4" status="READY"
-         is_template="[false]" template_id="[null]"/>
-
-  <!-- project -->
-  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
-            root_id="[null]" uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD."
-            enabled="[true]"/>
-
-  <!-- package -->
-  <projects long_name="[null]" id="2" scope="DIR" qualifier="PAC" kee="project:org.foo" name="org.foo"
-            root_id="1" uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
-            enabled="[true]"/>
-
-  <!-- file -->
-  <projects long_name="org.foo.Bar" id="3" scope="FIL" qualifier="CLA" kee="project:org.foo.Bar"
-            name="Bar" root_id="[null]" uuid="CDEF" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
-            enabled="[true]"/>
-
-
-  <!-- snapshots -->
-  <snapshots id="1000" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="1225544280000" build_date="1225544280000" version="[null]" path=""
-             status="P" islast="[false]" depth="0"/>
-  <snapshots id="1001" project_id="2" parent_snapshot_id="1000" root_project_id="1" root_snapshot_id="1000"
-             scope="DIR" qualifier="PAC" created_at="1225544280000" build_date="1225544280000" version="[null]" path="1000."
-             status="P" islast="[false]" depth="1"/>
-  <snapshots id="1002" project_id="3" parent_snapshot_id="1001" root_project_id="1" root_snapshot_id="1000"
-             scope="FIL" qualifier="CLA" created_at="1225544280000" build_date="1225544280000" version="[null]" path="1000.1001."
-             status="P" islast="[false]" depth="2"/>
-
-
-  <!-- project measures -->
-  <project_measures id="1" VALUE="60" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
-
-  <project_measures id="2" VALUE="80" METRIC_ID="2" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
-
-  <!-- package measures -->
-  <project_measures id="3" VALUE="20" METRIC_ID="1" SNAPSHOT_ID="1001" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
-
-  <project_measures id="4" VALUE="70" METRIC_ID="2" SNAPSHOT_ID="1001" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
-
-  <!-- file measures -->
-  <project_measures id="5" VALUE="5" METRIC_ID="1" SNAPSHOT_ID="1002" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
-
-  <project_measures id="6" VALUE="60" METRIC_ID="2" SNAPSHOT_ID="1002" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/past_measures_with_characteristic_id.xml b/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/past_measures_with_characteristic_id.xml
deleted file mode 100644 (file)
index 7e06f10..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-<dataset>
-
-  <metrics id="1" name="sqale_index" VAL_TYPE="WORK_DUR" DESCRIPTION="[null]" short_name="" enabled="[true]"/>
-
-  <!-- Root characteristic -->
-  <characteristics id="10" kee="PORTABILITY" name="Portability" parent_id="[null]" characteristic_order="1" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
-
-  <!-- Characteristic -->
-  <characteristics id="11" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" parent_id="10" characteristic_order="[null]" enabled="[true]"
-                   created_at="2013-11-20" updated_at="2013-11-22"/>
-
-  <!-- project -->
-  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
-            root_id="[null]" uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD." enabled="[true]"/>
-
-  <!-- snapshots -->
-  <snapshots id="1000" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="1225544280000" build_date="1225544280000" version="[null]" path=""
-             status="P" islast="[false]" depth="0"/>
-
-  <!-- project measures -->
-  <project_measures id="1" VALUE="60" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="[null]"/>
-
-  <project_measures id="2" VALUE="20" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="10"/>
-
-  <project_measures id="3" VALUE="40" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="11"/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/past_measures_with_person_id.xml b/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/past_measures_with_person_id.xml
deleted file mode 100644 (file)
index 47a1c69..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-<dataset>
-
-  <metrics delete_historical_data="[null]" id="1" name="sqale_index" VAL_TYPE="INT" DESCRIPTION="[null]" enabled="[true]"/>
-
-  <!-- project -->
-  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
-            root_id="[null]" uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD."
-            enabled="[true]"/>
-
-  <!-- snapshots -->
-  <snapshots id="1000" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="1225544280000" build_date="1225544280000" version="[null]" path=""
-             status="P" islast="[false]" depth="0"/>
-
-  <!-- project measures -->
-  <project_measures id="1" VALUE="60" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" person_id="[null]"/>
-
-  <project_measures id="2" VALUE="20" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" person_id="20"/>
-
-  <project_measures id="3" VALUE="40" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" person_id="21"/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/past_measures_with_rule_id.xml b/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/past_measures_with_rule_id.xml
deleted file mode 100644 (file)
index b6ccf49..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-<dataset>
-
-  <metrics delete_historical_data="[null]" id="1" name="minor_violations" VAL_TYPE="INT" DESCRIPTION="[null]" enabled="[true]"/>
-
-  <rules tags="[null]" system_tags="[null]" id="30" name="Classes that override clone should be Cloneable and call super.clone()"
-         plugin_rule_key="S1182"
-         plugin_config_key="S1182" plugin_name="squid" description="[null]" priority="4" status="READY"
-         is_template="[false]" template_id="[null]"/>
-
-  <rules tags="[null]" system_tags="[null]" id="31" name="Overriding methods should do more than simply call the same method in the super class"
-         plugin_rule_key="S1185"
-         plugin_config_key="S1185" plugin_name="squid" description="[null]" priority="1" status="READY"
-         is_template="[false]" template_id="[null]"/>
-
-  <!-- project -->
-  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
-            root_id="[null]" uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD."
-            enabled="[true]"/>
-
-  <!-- snapshots -->
-  <snapshots id="1000" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="1225544280000" build_date="1225544280000" version="[null]" path=""
-             status="P" islast="[false]" depth="0"/>
-
-  <!-- project measures -->
-  <project_measures id="1" VALUE="60" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
-
-  <project_measures id="2" VALUE="20" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="30" characteristic_id="[null]" person_id="[null]"/>
-
-  <project_measures id="3" VALUE="40" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="31" characteristic_id="[null]" person_id="[null]"/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/shared.xml
deleted file mode 100644 (file)
index c27311c..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<dataset>
-
-  <metrics id="10" name="authors_by_line"/>
-  <metrics id="11" name="coverage_line_hits_data"/>
-  <metrics id="12" name="ncloc"/>
-
-  <projects id="1" kee="org.struts:struts-core:src/org/struts/RequestContext.java" enabled="[true]"/>
-
-  <snapshots id="5" project_id="1" islast="[true]" />
-
-  <project_measures id="20" snapshot_id="5" metric_id="10" value="[null]" text_value="0123456789012345678901234567890123456789" measure_data="[null]"
-                    variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
-                    alert_status="[null]" alert_text="[null]" />
-  <project_measures id="21" snapshot_id="5" metric_id="11" value="[null]" text_value="36=1;37=1;38=1;39=1;43=1;48=1;53=1" measure_data="[null]"
-                    variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
-                    alert_status="[null]" alert_text="[null]" />
-  <project_measures id="22" snapshot_id="5" metric_id="12" value="10" text_value="[null]" measure_data="[null]"
-                    variation_value_1="1" variation_value_2="2" variation_value_3="3" variation_value_4="4" variation_value_5="-5"
-                    alert_status="OK" alert_text="Green"/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/insert-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/insert-result.xml
deleted file mode 100644 (file)
index 4f34778..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<dataset>
-
-  <file_sources id="101" project_uuid="PRJ_UUID" file_uuid="FILE1_UUID"
-                binary_data="abcde" data_hash="hash"
-                line_hashes="ABC\nDEF\nGHI"
-                src_hash="FILE_HASH"
-                created_at="1500000000000" updated_at="1500000000000"  data_type="SOURCE" />
-
-
-  <file_sources id="102" project_uuid="PRJ_UUID" file_uuid="FILE2_UUID"
-                binary_data="[ignore]"
-                data_hash="FILE2_DATA_HASH"
-                line_hashes="LINE1_HASH\nLINE2_HASH"
-                src_hash="FILE2_HASH"
-                created_at="1500000000000" updated_at="1500000000001"  data_type="SOURCE" />
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/no_line_hashes_when_only_test_data.xml b/server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/no_line_hashes_when_only_test_data.xml
deleted file mode 100644 (file)
index 010394a..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<dataset>
-
-    <file_sources id="101" project_uuid="PRJ_UUID" file_uuid="FILE1_UUID"
-                  binary_data="abcde" data_hash="[null]"
-                  line_hashes="[null]"
-                  src_hash="[null]"
-                  created_at="1500000000000" updated_at="1500000000000"  data_type="TEST" />
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/shared.xml
deleted file mode 100644 (file)
index 5187ca2..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<dataset>
-
-    <file_sources id="101" project_uuid="PRJ_UUID" file_uuid="FILE1_UUID"
-                  binary_data="abcde" data_hash="hash"
-                  line_hashes="ABC\nDEF\nGHI"
-                  src_hash="FILE_HASH"
-                  created_at="1500000000000" updated_at="1500000000000"  data_type="SOURCE" />
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/update-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/update-result.xml
deleted file mode 100644 (file)
index 8dbe32d..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<dataset>
-
-  <file_sources id="101" project_uuid="PRJ_UUID" file_uuid="FILE1_UUID"
-                binary_data="[ignore]"
-                data_hash="NEW_DATA_HASH"
-                line_hashes="NEW_LINE_HASHES"
-                src_hash="NEW_FILE_HASH"
-                created_at="1500000000000" updated_at="1500000000002"  data_type="SOURCE" />
-
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/update_date_when_updated_date_is_zero-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/update_date_when_updated_date_is_zero-result.xml
deleted file mode 100644 (file)
index 1ba1fe6..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<dataset>
-
-  <!-- Updated -->
-  <file_sources id="101" project_uuid="ABCD" file_uuid="FILE1_UUID"
-                binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
-                created_at="1500000000000" updated_at="1500000000002" data_type="SOURCE" />
-
-  <!-- Not updated because updated_at is not null -->
-  <file_sources id="102" project_uuid="ABCD" file_uuid="FILE2_UUID"
-                binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
-                created_at="1500000000000" updated_at="1500000000000" data_type="SOURCE" />
-
-  <!-- Not updated because on another project -->
-  <file_sources id="103" project_uuid="BCDE" file_uuid="FILE3_UUID"
-                binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
-                created_at="1500000000000" updated_at="0" data_type="SOURCE" />
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/update_date_when_updated_date_is_zero.xml b/server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/update_date_when_updated_date_is_zero.xml
deleted file mode 100644 (file)
index 77a1f85..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-<dataset>
-
-  <!-- Only this source should be updated -->
-  <file_sources id="101" project_uuid="ABCD" file_uuid="FILE1_UUID"
-                binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
-                created_at="1500000000000" updated_at="0" data_type="SOURCE" />
-
-  <file_sources id="102" project_uuid="ABCD" file_uuid="FILE2_UUID"
-                binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
-                created_at="1500000000000" updated_at="1500000000000" data_type="SOURCE" />
-
-  <file_sources id="103" project_uuid="BCDE" file_uuid="FILE3_UUID"
-                binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
-                created_at="1500000000000" updated_at="0" data_type="SOURCE" />
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/user/db/UserGroupDaoTest/delete_members_by_group_id-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/user/db/UserGroupDaoTest/delete_members_by_group_id-result.xml
deleted file mode 100644 (file)
index edac414..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<dataset>
-
-  <groups_users user_id="1" group_id="2"/>
-  <groups_users user_id="2" group_id="2"/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/user/db/UserGroupDaoTest/delete_members_by_group_id.xml b/server/sonar-server/src/test/resources/org/sonar/server/user/db/UserGroupDaoTest/delete_members_by_group_id.xml
deleted file mode 100644 (file)
index 2430e53..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<dataset>
-
-  <groups_users user_id="1" group_id="1"/>
-  <groups_users user_id="2" group_id="1"/>
-  <groups_users user_id="1" group_id="2"/>
-  <groups_users user_id="2" group_id="2"/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/user/db/UserGroupDaoTest/insert-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/user/db/UserGroupDaoTest/insert-result.xml
deleted file mode 100644 (file)
index 2e5bb1a..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-
-  <groups_users user_id="1" group_id="2"/>
-
-</dataset>
diff --git a/sonar-core/src/main/java/org/sonar/core/util/ProgressLogger.java b/sonar-core/src/main/java/org/sonar/core/util/ProgressLogger.java
new file mode 100644 (file)
index 0000000..c77da8e
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * 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.core.util;
+
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.atomic.AtomicLong;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+
+/**
+ * Background thread that logs the state of a counter at fixed intervals.
+ */
+public class ProgressLogger {
+
+  public static final long DEFAULT_PERIOD_MS = 60000L;
+
+  private final Timer timer;
+  private final LoggerTimerTask task;
+  private long periodMs = DEFAULT_PERIOD_MS;
+
+  public ProgressLogger(String threadName, AtomicLong counter, Logger logger) {
+    this.timer = new Timer(threadName);
+    this.task = new LoggerTimerTask(counter, logger);
+  }
+
+  public static ProgressLogger create(Class clazz, AtomicLong counter) {
+    String threadName = String.format("ProgressLogger[%s]", clazz.getSimpleName());
+    Logger logger = Loggers.get(clazz);
+    return new ProgressLogger(threadName, counter, logger);
+  }
+
+  /**
+   * Warning, does not check if already started.
+   */
+  public void start() {
+    // first log after {periodMs} milliseconds
+    timer.schedule(task, periodMs, periodMs);
+  }
+
+  public void stop() {
+    timer.cancel();
+    timer.purge();
+  }
+
+  /**
+   * Default is 1 minute
+   */
+  public ProgressLogger setPeriodMs(long l) {
+    this.periodMs = l;
+    return this;
+  }
+
+  public long getPeriodMs() {
+    return periodMs;
+  }
+
+  /**
+   * For example "issues", "measures", ... Default is "rows".
+   */
+  public ProgressLogger setPluralLabel(String s) {
+    task.pluralLabel = s;
+    return this;
+  }
+
+  public String getPluralLabel() {
+    return task.pluralLabel;
+  }
+
+  public void log() {
+    task.log();
+  }
+
+  private class LoggerTimerTask extends TimerTask {
+    private final AtomicLong counter;
+    private final Logger logger;
+    private String pluralLabel = "rows";
+    private long previousCounter = 0L;
+
+    private LoggerTimerTask(AtomicLong counter, Logger logger) {
+      this.counter = counter;
+      this.logger = logger;
+    }
+
+    @Override
+    public void run() {
+      log();
+    }
+
+    private void log() {
+      long current = counter.get();
+      logger.info(String.format("%d %s processed (%d items/sec)", current, pluralLabel, 1000 * (current - previousCounter) / periodMs));
+      previousCounter = current;
+    }
+  }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/util/Slug.java b/sonar-core/src/main/java/org/sonar/core/util/Slug.java
new file mode 100644 (file)
index 0000000..47e820d
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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.core.util;
+
+import java.text.Normalizer;
+import java.util.Locale;
+
+public class Slug {
+
+  private Slug() {
+  }
+
+  public static String slugify(String s) {
+    return Normalizer.normalize(s, Normalizer.Form.NFD)
+      .replaceAll("[^\\p{ASCII}]", "")
+      .replaceAll("[^\\w+]", "-")
+      .replaceAll("\\s+", "-")
+      .replaceAll("[-]+", "-")
+      .replaceAll("^-", "")
+      .replaceAll("-$", "").toLowerCase(Locale.ENGLISH);
+  }
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/util/ProgressLoggerTest.java b/sonar-core/src/test/java/org/sonar/core/util/ProgressLoggerTest.java
new file mode 100644 (file)
index 0000000..ecbaee6
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * 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.core.util;
+
+import java.util.concurrent.atomic.AtomicLong;
+import org.junit.Test;
+import org.sonar.api.utils.log.Logger;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.atLeast;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.startsWith;
+import static org.mockito.Mockito.verify;
+
+public class ProgressLoggerTest {
+
+  @Test(timeout = 1000L)
+  public void log_at_fixed_intervals() throws Exception {
+    Logger logger = mock(Logger.class);
+    AtomicLong counter = new AtomicLong(42L);
+    ProgressLogger progress = new ProgressLogger("ProgressLoggerTest", counter, logger);
+    progress.setPeriodMs(1L);
+    progress.start();
+    Thread.sleep(80L);
+    progress.stop();
+    verify(logger, atLeast(1)).info(startsWith("42 rows processed"));
+
+    // ability to manual log, generally final status
+    counter.incrementAndGet();
+    progress.log();
+    verify(logger).info(startsWith("43 rows processed"));
+  }
+
+  @Test
+  public void create() {
+    ProgressLogger progress = ProgressLogger.create(getClass(), new AtomicLong());
+
+    // default values
+    assertThat(progress.getPeriodMs()).isEqualTo(60000L);
+    assertThat(progress.getPluralLabel()).isEqualTo("rows");
+
+    // override values
+    progress.setPeriodMs(10L);
+    progress.setPluralLabel("issues");
+    assertThat(progress.getPeriodMs()).isEqualTo(10L);
+    assertThat(progress.getPluralLabel()).isEqualTo("issues");
+
+  }
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/util/SlugTest.java b/sonar-core/src/test/java/org/sonar/core/util/SlugTest.java
new file mode 100644 (file)
index 0000000..5e45bb8
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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.core.util;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class SlugTest {
+
+  @Test
+  public void slugify() {
+    assertThat(Slug.slugify("foo")).isEqualTo("foo");
+    assertThat(Slug.slugify("  FOO ")).isEqualTo("foo");
+    assertThat(Slug.slugify("he's here")).isEqualTo("he-s-here");
+    assertThat(Slug.slugify("foo-bar")).isEqualTo("foo-bar");
+    assertThat(Slug.slugify("foo_bar")).isEqualTo("foo_bar");
+    assertThat(Slug.slugify("accents Ã©Ã ")).isEqualTo("accents-ea");
+    assertThat(Slug.slugify("<foo>")).isEqualTo("foo");
+    assertThat(Slug.slugify("<\"foo:\">")).isEqualTo("foo");
+  }
+}
diff --git a/sonar-db/src/main/java/org/sonar/batch/index/ResourceCopy.java b/sonar-db/src/main/java/org/sonar/batch/index/ResourceCopy.java
deleted file mode 100644 (file)
index 6a3ccd8..0000000
+++ /dev/null
@@ -1,29 +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.batch.index;
-
-/**
- * Used by views !!
- */
-public interface ResourceCopy {
-
-  int getCopyResourceId();
-
-}
diff --git a/sonar-db/src/main/java/org/sonar/core/issue/db/package-info.java b/sonar-db/src/main/java/org/sonar/core/issue/db/package-info.java
deleted file mode 100644 (file)
index 55dc491..0000000
+++ /dev/null
@@ -1,24 +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.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.core.issue.db;
-
-import javax.annotation.ParametersAreNonnullByDefault;
-
index 2d16c7137d0ebe7f50df270713038c229e4cc0d3..9a70977c140ef8e869bfadd7577dc1b9e375a8ab 100644 (file)
@@ -30,11 +30,9 @@ import org.sonar.api.CoreProperties;
 import org.sonar.api.config.Settings;
 import org.sonar.api.database.model.Snapshot;
 import org.sonar.api.i18n.I18n;
-import org.sonar.api.server.ServerSide;
 
 import static org.sonar.api.utils.DateUtils.longToDate;
 
-@ServerSide
 public class Periods {
 
   private final Settings settings;
diff --git a/sonar-db/src/main/java/org/sonar/db/AbstractDao.java b/sonar-db/src/main/java/org/sonar/db/AbstractDao.java
new file mode 100644 (file)
index 0000000..245f0e8
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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 org.sonar.api.utils.System2;
+
+public abstract class AbstractDao implements Dao {
+
+  private final MyBatis myBatis;
+  private final System2 system2;
+
+  public AbstractDao(MyBatis myBatis, System2 system2) {
+    this.myBatis = myBatis;
+    this.system2 = system2;
+  }
+
+  protected MyBatis myBatis() {
+    return myBatis;
+  }
+
+  protected long now() {
+    return system2.now();
+  }
+}
index 5c0d3269e3c2a83c6a0c076a4af3b29264f7bd19..7e3773f2b0d6a9502871032df4709cdddbee4fa1 100644 (file)
  */
 package org.sonar.db;
 
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import java.util.Collection;
-import java.util.Collections;
+import java.util.Arrays;
 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.ResourceKeyUpdaterDao;
+import org.sonar.db.component.SnapshotDao;
+import org.sonar.db.compute.AnalysisReportDao;
 import org.sonar.db.dashboard.ActiveDashboardDao;
 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.duplication.DuplicationDao;
+import org.sonar.db.event.EventDao;
 import org.sonar.db.issue.ActionPlanDao;
 import org.sonar.db.issue.ActionPlanStatsDao;
 import org.sonar.db.issue.IssueChangeDao;
@@ -39,48 +42,53 @@ import org.sonar.db.issue.IssueDao;
 import org.sonar.db.issue.IssueFilterDao;
 import org.sonar.db.issue.IssueFilterFavouriteDao;
 import org.sonar.db.loadedtemplate.LoadedTemplateDao;
+import org.sonar.db.measure.MeasureDao;
+import org.sonar.db.measure.MeasureFilterDao;
 import org.sonar.db.notification.NotificationQueueDao;
 import org.sonar.db.permission.PermissionDao;
 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.ActiveRuleDao;
 import org.sonar.db.qualityprofile.QualityProfileDao;
 import org.sonar.db.rule.RuleDao;
 import org.sonar.db.semaphore.SemaphoreDao;
+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.UserDao;
-
-import static com.google.common.collect.Lists.newArrayList;
+import org.sonar.db.user.UserGroupDao;
 
 public final class DaoUtils {
 
-  private static final int PARTITION_SIZE_FOR_ORACLE = 1000;
-
   private DaoUtils() {
     // only static stuff
   }
 
-  public static List<Class> getDaoClasses() {
-    return ImmutableList.<Class>of(
+  public static List<Class<? extends Dao>> getDaoClasses() {
+    return Arrays.asList(
       ActionPlanDao.class,
       ActionPlanStatsDao.class,
       ActiveDashboardDao.class,
-      ActiveRuleDao.class,
+      ActivityDao.class,
+      AnalysisReportDao.class,
       AuthorDao.class,
       AuthorizationDao.class,
+      ComponentLinkDao.class,
       DashboardDao.class,
       DuplicationDao.class,
+      EventDao.class,
+      FileSourceDao.class,
       GroupMembershipDao.class,
       IssueDao.class,
       IssueChangeDao.class,
       IssueFilterDao.class,
       IssueFilterFavouriteDao.class,
       LoadedTemplateDao.class,
+      MeasureDao.class,
+      MeasureFilterDao.class,
       NotificationQueueDao.class,
       PermissionDao.class,
       PermissionTemplateDao.class,
@@ -95,55 +103,11 @@ public final class DaoUtils {
       RoleDao.class,
       RuleDao.class,
       SemaphoreDao.class,
-      UserDao.class
+      SnapshotDao.class,
+      UserDao.class,
+      UserGroupDao.class,
+      WidgetDao.class,
+      WidgetPropertyDao.class
       );
   }
-
-  /**
-   * Partition by 1000 elements a list of input and execute a function on each part.
-   *
-   * The goal is to prevent issue with ORACLE when there's more than 1000 elements in a 'in ('X', 'Y', ...)'
-   * and with MsSQL when there's more than 2000 parameters in a query
-   */
-  public static <OUTPUT, INPUT> List<OUTPUT> executeLargeInputs(Collection<INPUT> input, Function<List<INPUT>, List<OUTPUT>> function) {
-    if (input.isEmpty()) {
-      return Collections.emptyList();
-    }
-    List<OUTPUT> results = newArrayList();
-    List<List<INPUT>> partitionList = Lists.partition(newArrayList(input), PARTITION_SIZE_FOR_ORACLE);
-    for (List<INPUT> partition : partitionList) {
-      List<OUTPUT> subResults = function.apply(partition);
-      results.addAll(subResults);
-    }
-    return results;
-  }
-
-  /**
-   * Partition by 1000 elements a list of input and execute a function on each part.
-   * The function has not output (ex: delete operation)
-   *
-   * The goal is to prevent issue with ORACLE when there's more than 1000 elements in a 'in ('X', 'Y', ...)'
-   * and with MsSQL when there's more than 2000 parameters in a query
-   */
-  public static <INPUT> void executeLargeInputsWithoutOutput(Collection<INPUT> input, Function<List<INPUT>, Void> function) {
-    if (input.isEmpty()) {
-      return;
-    }
-
-    List<List<INPUT>> partitions = Lists.partition(newArrayList(input), PARTITION_SIZE_FOR_ORACLE);
-    for (List<INPUT> partition : partitions) {
-      function.apply(partition);
-    }
-  }
-
-  public static String repeatCondition(String sql, int count, String separator) {
-    StringBuilder sb = new StringBuilder();
-    for (int i = 0; i < count; i++) {
-      sb.append(sql);
-      if (i < count - 1) {
-        sb.append(" ").append(separator).append(" ");
-      }
-    }
-    return sb.toString();
-  }
 }
diff --git a/sonar-db/src/main/java/org/sonar/db/DatabaseChecker.java b/sonar-db/src/main/java/org/sonar/db/DatabaseChecker.java
new file mode 100644 (file)
index 0000000..31dc571
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * 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 com.google.common.base.Throwables;
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.apache.commons.dbutils.DbUtils;
+import org.apache.commons.lang.StringUtils;
+import org.picocontainer.Startable;
+import org.sonar.api.utils.MessageException;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.db.dialect.H2;
+import org.sonar.db.dialect.Oracle;
+
+public class DatabaseChecker implements Startable {
+
+  public static final int ORACLE_MIN_MAJOR_VERSION = 11;
+
+  private final Database db;
+
+  public DatabaseChecker(Database db) {
+    this.db = db;
+  }
+
+  @Override
+  public void start() {
+    try {
+      if (H2.ID.equals(db.getDialect().getId())) {
+        Loggers.get(DatabaseChecker.class).warn("H2 database should be used for evaluation purpose only");
+      } else if (Oracle.ID.equals(db.getDialect().getId())) {
+        checkOracleVersion();
+      }
+    } catch (Exception e) {
+      Throwables.propagate(e);
+    }
+  }
+
+  @Override
+  public void stop() {
+    // nothing to do
+  }
+
+  private void checkOracleVersion() throws SQLException {
+    Connection connection = db.getDataSource().getConnection();
+    try {
+      // check version of db
+      // See http://jira.sonarsource.com/browse/SONAR-6434
+      int majorVersion = connection.getMetaData().getDatabaseMajorVersion();
+      if (majorVersion < ORACLE_MIN_MAJOR_VERSION) {
+        throw MessageException.of(String.format(
+          "Unsupported Oracle version: %s. Minimal required version is %d.", connection.getMetaData().getDatabaseProductVersion(), ORACLE_MIN_MAJOR_VERSION));
+      }
+
+      // check version of driver
+      String driverVersion = connection.getMetaData().getDriverVersion();
+      String[] parts = StringUtils.split(driverVersion, ".");
+      int intVersion = Integer.parseInt(parts[0]) * 100 + Integer.parseInt(parts[1]);
+      if (intVersion < 1102) {
+        throw MessageException.of(String.format(
+          "Unsupported Oracle JDBC driver version: %s. Minimal required version is 11.2.", driverVersion));
+      }
+
+    } finally {
+      DbUtils.closeQuietly(connection);
+    }
+  }
+
+}
index 28ac5923b72dad79d83122098770abb3fd9c76bb..6d74d2474cca356c567deae93d7a2e40f57dc2f1 100644 (file)
  */
 package org.sonar.db;
 
+import com.google.common.base.Function;
+import com.google.common.collect.Lists;
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
 import javax.annotation.Nullable;
 import org.slf4j.LoggerFactory;
 
-/**
- * @since 2.13
- */
+import static com.google.common.collect.Lists.newArrayList;
+
 public final class DatabaseUtils {
+
+  private static final int PARTITION_SIZE_FOR_ORACLE = 1000;
+
   private DatabaseUtils() {
     // only static methods
   }
@@ -66,4 +73,52 @@ public final class DatabaseUtils {
       }
     }
   }
+
+  /**
+   * Partition by 1000 elements a list of input and execute a function on each part.
+   *
+   * The goal is to prevent issue with ORACLE when there's more than 1000 elements in a 'in ('X', 'Y', ...)'
+   * and with MsSQL when there's more than 2000 parameters in a query
+   */
+  public static <OUTPUT, INPUT> List<OUTPUT> executeLargeInputs(Collection<INPUT> input, Function<List<INPUT>, List<OUTPUT>> function) {
+    if (input.isEmpty()) {
+      return Collections.emptyList();
+    }
+    List<OUTPUT> results = newArrayList();
+    List<List<INPUT>> partitionList = Lists.partition(newArrayList(input), PARTITION_SIZE_FOR_ORACLE);
+    for (List<INPUT> partition : partitionList) {
+      List<OUTPUT> subResults = function.apply(partition);
+      results.addAll(subResults);
+    }
+    return results;
+  }
+
+  /**
+   * Partition by 1000 elements a list of input and execute a function on each part.
+   * The function has not output (ex: delete operation)
+   *
+   * The goal is to prevent issue with ORACLE when there's more than 1000 elements in a 'in ('X', 'Y', ...)'
+   * and with MsSQL when there's more than 2000 parameters in a query
+   */
+  public static <INPUT> void executeLargeInputsWithoutOutput(Collection<INPUT> input, Function<List<INPUT>, Void> function) {
+    if (input.isEmpty()) {
+      return;
+    }
+
+    List<List<INPUT>> partitions = Lists.partition(newArrayList(input), PARTITION_SIZE_FOR_ORACLE);
+    for (List<INPUT> partition : partitions) {
+      function.apply(partition);
+    }
+  }
+
+  public static String repeatCondition(String sql, int count, String separator) {
+    StringBuilder sb = new StringBuilder();
+    for (int i = 0; i < count; i++) {
+      sb.append(sql);
+      if (i < count - 1) {
+        sb.append(" ").append(separator).append(" ");
+      }
+    }
+    return sb.toString();
+  }
 }
diff --git a/sonar-db/src/main/java/org/sonar/db/DbClient2.java b/sonar-db/src/main/java/org/sonar/db/DbClient2.java
new file mode 100644 (file)
index 0000000..92cbd39
--- /dev/null
@@ -0,0 +1,253 @@
+/*
+ * 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 c5e5e1c12b8882443f65ffcc353278522bc5bc89..47db0259f00013f94ba44c3b4d80c11229eed04c 100644 (file)
@@ -30,10 +30,10 @@ import org.apache.commons.dbcp.BasicDataSource;
 import org.apache.commons.dbcp.BasicDataSourceFactory;
 import org.apache.commons.dbutils.DbUtils;
 import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.sonar.api.config.Settings;
 import org.sonar.api.database.DatabaseProperties;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
 import org.sonar.db.dialect.Dialect;
 import org.sonar.db.dialect.DialectUtils;
 import org.sonar.db.profiling.ProfiledDataSource;
@@ -43,7 +43,7 @@ import org.sonar.db.profiling.ProfiledDataSource;
  */
 public class DefaultDatabase implements Database {
 
-  private static final Logger LOG = LoggerFactory.getLogger(Database.class);
+  private static final Logger LOG = Loggers.get(Database.class);
 
   private static final String DEFAULT_URL = "jdbc:h2:tcp://localhost/sonar";
   private static final String SONAR_JDBC = "sonar.jdbc.";
@@ -65,20 +65,12 @@ public class DefaultDatabase implements Database {
       initSettings();
       initDatasource();
       checkConnection();
-      doAfterStart();
 
     } catch (Exception e) {
       throw new IllegalStateException("Fail to connect to database", e);
     }
   }
 
-  /**
-   * Override to execute post-startup code.
-   */
-  protected void doAfterStart() {
-    // nothing to do
-  }
-
   @VisibleForTesting
   void initSettings() {
     properties = new Properties();
@@ -104,7 +96,6 @@ public class DefaultDatabase implements Database {
   private void checkConnection() {
     Connection connection = null;
     try {
-      LOG.debug("Testing JDBC connection");
       connection = datasource.getConnection();
     } catch (SQLException e) {
       throw new IllegalStateException("Can not connect to database. Please check connectivity and settings (see the properties prefixed by 'sonar.jdbc.').", e);
@@ -176,7 +167,7 @@ public class DefaultDatabase implements Database {
   }
 
   private static void completeDefaultProperty(Properties props, String key, String defaultValue) {
-    if (props.getProperty(key) == null && defaultValue != null) {
+    if (props.getProperty(key) == null) {
       props.setProperty(key, defaultValue);
     }
   }
index a6aa01cbc4fb3931685f09a9b99e01e19cb3d74e..5926def8753d67003faa705ccdde8eb81e856bb4 100644 (file)
@@ -23,6 +23,9 @@ package org.sonar.db;
 import ch.qos.logback.classic.Level;
 import com.google.common.io.Closeables;
 import java.io.InputStream;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
 import javax.annotation.Nullable;
 import org.apache.ibatis.builder.xml.XMLMapperBuilder;
 import org.apache.ibatis.logging.LogFactory;
@@ -35,10 +38,10 @@ import org.apache.ibatis.session.SqlSessionFactoryBuilder;
 import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
 import org.apache.ibatis.type.JdbcType;
 import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Loggers;
 import org.sonar.db.activity.ActivityDto;
 import org.sonar.db.activity.ActivityMapper;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.ComponentIndexMapper;
 import org.sonar.db.component.ComponentLinkDto;
 import org.sonar.db.component.ComponentLinkMapper;
 import org.sonar.db.component.ComponentMapper;
@@ -144,8 +147,6 @@ public class MyBatis {
 
   private final Database database;
   private SqlSessionFactory sessionFactory;
-
-  // TODO this queue should directly be an IndexQueue. Pending move of persistence to sonar-server
   private WorkQueue<?> queue;
 
   public MyBatis(Database database, WorkQueue<?> queue) {
@@ -153,12 +154,13 @@ public class MyBatis {
     this.queue = queue;
   }
 
+  // FIXME should be visible only to DAOs -> to be moved to AbstractDao
   public static void closeQuietly(@Nullable SqlSession session) {
     if (session != null) {
       try {
         session.close();
       } catch (Exception e) {
-        LoggerFactory.getLogger(MyBatis.class).warn("Fail to close session", e);
+        Loggers.get(MyBatis.class).warn("Fail to close db session", e);
         // do not re-throw the exception
       }
     }
@@ -255,7 +257,7 @@ public class MyBatis {
       GroupMembershipMapper.class, QualityProfileMapper.class, ActiveRuleMapper.class,
       MeasureMapper.class, MetricMapper.class, CustomMeasureMapper.class, QualityGateMapper.class, QualityGateConditionMapper.class, ComponentMapper.class, SnapshotMapper.class,
       ProjectQgateAssociationMapper.class, EventMapper.class,
-      AnalysisReportMapper.class, ComponentIndexMapper.class, ComponentLinkMapper.class,
+      AnalysisReportMapper.class, ComponentLinkMapper.class,
       Migration45Mapper.class, Migration50Mapper.class
     };
     loadMappers(conf, mappers);
@@ -276,14 +278,6 @@ public class MyBatis {
     return openSession(false);
   }
 
-  /**
-   * @deprecated since 4.4. Replaced by <code>openSession(true)</code>.
-   */
-  @Deprecated
-  public BatchSession openBatchSession() {
-    return (BatchSession) openSession(true);
-  }
-
   /**
    * @since 4.4
    */
@@ -323,4 +317,31 @@ public class MyBatis {
   private void loadAlias(Configuration conf, String alias, Class dtoClass) {
     conf.getTypeAliasRegistry().registerAlias(alias, dtoClass);
   }
+
+  /**
+   * Create a PreparedStatement for SELECT requests with scrolling of results
+   */
+  public PreparedStatement newScrollingSelectStatement(DbSession session, String sql) {
+    int fetchSize = database.getDialect().getScrollDefaultFetchSize();
+    return newScrollingSelectStatement(session, sql, fetchSize);
+  }
+
+  /**
+   * Create a PreparedStatement for SELECT requests with scrolling of results row by row (only one row
+   * in memory at a time)
+   */
+  public PreparedStatement newScrollingSingleRowSelectStatement(DbSession session, String sql) {
+    int fetchSize = database.getDialect().getScrollSingleRowFetchSize();
+    return newScrollingSelectStatement(session, sql, fetchSize);
+  }
+
+  private PreparedStatement newScrollingSelectStatement(DbSession session, String sql, int fetchSize) {
+    try {
+      PreparedStatement stmt = session.getConnection().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);
+    }
+  }
 }
diff --git a/sonar-db/src/main/java/org/sonar/db/ResultSetIterator.java b/sonar-db/src/main/java/org/sonar/db/ResultSetIterator.java
new file mode 100644 (file)
index 0000000..e96a957
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * 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 org.apache.commons.dbutils.DbUtils;
+
+import java.io.Closeable;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/**
+ * Forward-only {@link java.util.Iterator} over a {@link java.sql.ResultSet}. Rows are
+ * lazily loaded. The underlying ResultSet must be closed by calling the method
+ * {@link #close()}
+ * <p/>
+ * As a safeguard, the ResultSet is automatically closed after the last element has
+ * been retrieved via {@link #next()} or {@link #hasNext()} is called (which will return false).
+ * This automagic behavior is not enough to remove explicit calls to {@link #close()}
+ * from caller methods. Errors raised before end of traversal must still be handled.
+ */
+public abstract class ResultSetIterator<E> implements Iterator<E>, Closeable {
+
+  private final ResultSet rs;
+  private final PreparedStatement stmt;
+
+  private volatile boolean didNext = false;
+  private volatile boolean hasNext = false;
+  private volatile boolean closed = false;
+
+  public ResultSetIterator(PreparedStatement stmt) throws SQLException {
+    this.stmt = stmt;
+    this.rs = stmt.executeQuery();
+  }
+
+  protected ResultSetIterator(ResultSet rs) {
+    this.stmt = null;
+    this.rs = rs;
+  }
+
+  @Override
+  public boolean hasNext() {
+    if (closed) {
+      return false;
+    }
+    if (!didNext) {
+      hasNext = doNextQuietly();
+      if (hasNext) {
+        didNext = true;
+      } else {
+        close();
+      }
+    }
+    return hasNext;
+  }
+
+  @Override
+  public E next() {
+    if (!hasNext()) {
+      close();
+      throw new NoSuchElementException();
+    }
+    try {
+      return read(rs);
+    } catch (SQLException e) {
+      throw new IllegalStateException("Fail to read result set row", e);
+    } finally {
+      hasNext = doNextQuietly();
+      if (!hasNext) {
+        close();
+      }
+    }
+  }
+
+  @Override
+  public void remove() {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public void close() {
+    closed = true;
+    DbUtils.closeQuietly(rs);
+    DbUtils.closeQuietly(stmt);
+  }
+
+  protected abstract E read(ResultSet rs) throws SQLException;
+
+  private boolean doNextQuietly() {
+    try {
+      return rs.next();
+    } catch (SQLException e) {
+      throw new IllegalStateException("Fail to read row of JDBC result set", e);
+    }
+  }
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/activity/ActivityDao.java b/sonar-db/src/main/java/org/sonar/db/activity/ActivityDao.java
new file mode 100644 (file)
index 0000000..25b7539
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * 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.activity;
+
+import java.util.Date;
+import org.sonar.api.utils.System2;
+import org.sonar.db.AbstractDao;
+import org.sonar.db.DbSession;
+import org.sonar.db.MyBatis;
+
+public class ActivityDao extends AbstractDao {
+
+  public ActivityDao(MyBatis mybatis, System2 system) {
+    super(mybatis, system);
+  }
+
+  public void insert(ActivityDto dto) {
+    DbSession session = myBatis().openSession(false);
+    try {
+      insert(session, dto);
+      session.commit();
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public void insert(DbSession session, ActivityDto dto) {
+    dto.setCreatedAt(new Date(now()));
+    session.getMapper(ActivityMapper.class).insert(dto);
+  }
+
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentIndexMapper.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentIndexMapper.java
deleted file mode 100644 (file)
index 44eafac..0000000
+++ /dev/null
@@ -1,29 +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 ComponentIndexMapper {
-
-  List<Long> selectProjectIdsFromQueryAndViewOrSubViewUuid(@Param("query") String query, @Param("viewUuidQuery") String viewUuidQuery);
-}
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentLinkDao.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentLinkDao.java
new file mode 100644 (file)
index 0000000..9c4f294
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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.sonar.db.Dao;
+import org.sonar.db.DbSession;
+
+public class ComponentLinkDao implements Dao {
+
+  public List<ComponentLinkDto> selectByComponentUuid(DbSession session, String componentUuid) {
+    return session.getMapper(ComponentLinkMapper.class).selectByComponentUuid(componentUuid);
+  }
+
+  public void insert(DbSession session, ComponentLinkDto dto) {
+    session.getMapper(ComponentLinkMapper.class).insert(dto);
+  }
+
+  public void update(DbSession session, ComponentLinkDto dto) {
+    session.getMapper(ComponentLinkMapper.class).update(dto);
+  }
+
+  public void delete(DbSession session, long id) {
+    session.getMapper(ComponentLinkMapper.class).delete(id);
+  }
+
+}
index 2ebd03ec015096cc9abdbec0e124ce46be67490b..80addc6dd54d4ab36d6480295c16489f80bd45fa 100644 (file)
@@ -32,27 +32,24 @@ import org.sonar.api.component.Component;
 import org.sonar.api.resources.Scopes;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.internal.Uuids;
-import org.sonar.db.Dao;
+import org.sonar.db.AbstractDao;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
 
 import static com.google.common.collect.Lists.newArrayList;
 
-public class ResourceDao implements Dao {
-  private MyBatis mybatis;
-  private System2 system2;
+public class ResourceDao extends AbstractDao {
 
-  public ResourceDao(MyBatis mybatis, System2 system2) {
-    this.mybatis = mybatis;
-    this.system2 = system2;
+  public ResourceDao(MyBatis myBatis, System2 system2) {
+    super(myBatis, system2);
   }
 
   public List<ResourceDto> getResources(ResourceQuery query) {
-    SqlSession session = mybatis.openSession(false);
+    SqlSession session = myBatis().openSession(false);
     try {
       return session.getMapper(ResourceMapper.class).selectResources(query);
     } finally {
-      MyBatis.closeQuietly(session);
+      myBatis().closeQuietly(session);
     }
   }
 
@@ -66,11 +63,11 @@ public class ResourceDao implements Dao {
    */
   @CheckForNull
   public ResourceDto getResource(ResourceQuery query) {
-    DbSession session = mybatis.openSession(false);
+    DbSession session = myBatis().openSession(false);
     try {
       return getResource(query, session);
     } finally {
-      MyBatis.closeQuietly(session);
+      myBatis().closeQuietly(session);
     }
   }
 
@@ -84,30 +81,30 @@ public class ResourceDao implements Dao {
   }
 
   public List<Long> getResourceIds(ResourceQuery query) {
-    SqlSession session = mybatis.openSession(false);
+    SqlSession session = myBatis().openSession(false);
     try {
       return session.getMapper(ResourceMapper.class).selectResourceIds(query);
     } finally {
-      MyBatis.closeQuietly(session);
+      myBatis().closeQuietly(session);
     }
   }
 
   public ResourceDto getResource(long projectId) {
-    SqlSession session = mybatis.openSession(false);
+    SqlSession session = myBatis().openSession(false);
     try {
       return getResource(projectId, session);
     } finally {
-      MyBatis.closeQuietly(session);
+      myBatis().closeQuietly(session);
     }
   }
 
   @CheckForNull
   public ResourceDto getResource(String componentUuid) {
-    SqlSession session = mybatis.openSession(false);
+    SqlSession session = myBatis().openSession(false);
     try {
       return session.getMapper(ResourceMapper.class).selectResourceByUuid(componentUuid);
     } finally {
-      MyBatis.closeQuietly(session);
+      myBatis().closeQuietly(session);
     }
   }
 
@@ -126,11 +123,11 @@ public class ResourceDao implements Dao {
   }
 
   public List<ResourceDto> getDescendantProjects(long projectId) {
-    SqlSession session = mybatis.openSession(false);
+    SqlSession session = myBatis().openSession(false);
     try {
       return getDescendantProjects(projectId, session);
     } finally {
-      MyBatis.closeQuietly(session);
+      myBatis().closeQuietly(session);
     }
   }
 
@@ -153,9 +150,9 @@ public class ResourceDao implements Dao {
    * Used by the Views Plugin
    */
   public ResourceDao insertOrUpdate(ResourceDto... resources) {
-    SqlSession session = mybatis.openSession(false);
+    SqlSession session = myBatis().openSession(false);
     ResourceMapper mapper = session.getMapper(ResourceMapper.class);
-    Date now = new Date(system2.now());
+    Date now = new Date(now());
     try {
       for (ResourceDto resource : resources) {
         if (resource.getId() == null) {
@@ -175,7 +172,7 @@ public class ResourceDao implements Dao {
       }
       session.commit();
     } finally {
-      MyBatis.closeQuietly(session);
+      myBatis().closeQuietly(session);
     }
     return this;
   }
@@ -184,7 +181,7 @@ public class ResourceDao implements Dao {
    * Should not be called from batch side (used to reindex permission in E/S)
    */
   public void updateAuthorizationDate(Long projectId, SqlSession session) {
-    session.getMapper(ResourceMapper.class).updateAuthorizationDate(projectId, system2.now());
+    session.getMapper(ResourceMapper.class).updateAuthorizationDate(projectId, now());
   }
 
   @CheckForNull
@@ -222,11 +219,11 @@ public class ResourceDao implements Dao {
 
   @CheckForNull
   public ResourceDto getRootProjectByComponentKey(String componentKey) {
-    DbSession session = mybatis.openSession(false);
+    DbSession session = myBatis().openSession(false);
     try {
       return getRootProjectByComponentKey(session, componentKey);
     } finally {
-      MyBatis.closeQuietly(session);
+      myBatis().closeQuietly(session);
     }
   }
 
@@ -253,7 +250,7 @@ public class ResourceDao implements Dao {
    */
   @CheckForNull
   public ResourceDto getRootProjectByComponentId(long componentId) {
-    DbSession session = mybatis.openSession(false);
+    DbSession session = myBatis().openSession(false);
     try {
       ResourceDto component = getParentModuleByComponentId(componentId, session);
       Long rootId = component != null ? component.getRootId() : null;
@@ -263,7 +260,7 @@ public class ResourceDao implements Dao {
         return component;
       }
     } finally {
-      MyBatis.closeQuietly(session);
+      myBatis().closeQuietly(session);
     }
   }
 
@@ -271,11 +268,11 @@ public class ResourceDao implements Dao {
     if (qualifiers.isEmpty()) {
       return Collections.emptyList();
     }
-    SqlSession session = mybatis.openSession(false);
+    SqlSession session = myBatis().openSession(false);
     try {
       return toComponents(session.getMapper(ResourceMapper.class).selectProjectsByQualifiers(qualifiers));
     } finally {
-      MyBatis.closeQuietly(session);
+      myBatis().closeQuietly(session);
     }
   }
 
@@ -286,11 +283,11 @@ public class ResourceDao implements Dao {
     if (qualifiers.isEmpty()) {
       return Collections.emptyList();
     }
-    SqlSession session = mybatis.openSession(false);
+    SqlSession session = myBatis().openSession(false);
     try {
       return toComponents(session.getMapper(ResourceMapper.class).selectProjectsIncludingNotCompletedOnesByQualifiers(qualifiers));
     } finally {
-      MyBatis.closeQuietly(session);
+      myBatis().closeQuietly(session);
     }
   }
 
@@ -304,11 +301,11 @@ public class ResourceDao implements Dao {
     if (qualifiers.isEmpty()) {
       return Collections.emptyList();
     }
-    SqlSession session = mybatis.openSession(false);
+    SqlSession session = myBatis().openSession(false);
     try {
       return toComponents(session.getMapper(ResourceMapper.class).selectGhostsProjects(qualifiers));
     } finally {
-      MyBatis.closeQuietly(session);
+      myBatis().closeQuietly(session);
     }
   }
 
@@ -319,11 +316,11 @@ public class ResourceDao implements Dao {
     if (qualifiers.isEmpty()) {
       return Collections.emptyList();
     }
-    SqlSession session = mybatis.openSession(false);
+    SqlSession session = myBatis().openSession(false);
     try {
       return session.getMapper(ResourceMapper.class).selectProvisionedProjects(qualifiers);
     } finally {
-      MyBatis.closeQuietly(session);
+      myBatis().closeQuietly(session);
     }
   }
 
@@ -335,11 +332,11 @@ public class ResourceDao implements Dao {
   }
 
   public ResourceDto selectProvisionedProject(String key) {
-    DbSession session = mybatis.openSession(false);
+    DbSession session = myBatis().openSession(false);
     try {
       return selectProvisionedProject(session, key);
     } finally {
-      MyBatis.closeQuietly(session);
+      myBatis().closeQuietly(session);
     }
   }
 
index 6a61ef714e6a0b8d1e3ed7bdbe32c14a149aef0f..827ece8fd1ba8b351086d0f3346998ec0ace0669 100644 (file)
  */
 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 {
+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;
@@ -41,17 +44,19 @@ public class ResourceIndexerDao {
   private static final String[] NOT_RENAMABLE_QUALIFIERS = {Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE, Qualifiers.CLASS};
   private static final String[] NOT_RENAMABLE_SCOPES = {Scopes.FILE};
 
-  private final MyBatis mybatis;
+  public ResourceIndexerDao(MyBatis myBatis, System2 system2) {
+    super(myBatis, system2);
+  }
 
-  public ResourceIndexerDao(MyBatis mybatis) {
-    this.mybatis = mybatis;
+  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);
+    DbSession session = myBatis().openSession(true);
     try {
       indexProject(rootProjectId, session);
       session.commit();
@@ -71,7 +76,7 @@ public class ResourceIndexerDao {
    * This method is reentrant. It can be executed even if some projects are already indexed.
    */
   public ResourceIndexerDao indexProjects() {
-    final DbSession session = mybatis.openSession(true);
+    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() {
@@ -132,7 +137,7 @@ public class ResourceIndexerDao {
   }
 
   public boolean indexResource(long id) {
-    DbSession session = mybatis.openSession(false);
+    DbSession session = myBatis().openSession(false);
     try {
       return indexResource(session, id);
     } finally {
@@ -156,7 +161,7 @@ public class ResourceIndexerDao {
 
   public boolean indexResource(int id, String name, String qualifier, int rootId) {
     boolean indexed = false;
-    SqlSession session = mybatis.openSession(false);
+    SqlSession session = myBatis().openSession(false);
     ResourceIndexerMapper mapper = session.getMapper(ResourceIndexerMapper.class);
     try {
       indexed = indexResource(id, name, qualifier, rootId, session, mapper);
index ecbacc7da82b49c75f114ff5d48b2ba769853175..a0cb17b2ccf9e4c76bd2924d19a5b0f9c437b13d 100644 (file)
  */
 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);
index 6441c88df37481931d7f459346a1bcecbc9efe45..78217f48edd990c8e8f687ea3a3a2193514c5c98 100644 (file)
@@ -28,6 +28,7 @@ import java.util.Map;
 import java.util.Set;
 import org.apache.commons.lang.StringUtils;
 import org.apache.ibatis.session.SqlSession;
+import org.sonar.db.Dao;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
 
@@ -36,7 +37,7 @@ import org.sonar.db.MyBatis;
  *
  * @since 3.2
  */
-public class ResourceKeyUpdaterDao {
+public class ResourceKeyUpdaterDao implements Dao {
   private MyBatis mybatis;
 
   public ResourceKeyUpdaterDao(MyBatis mybatis) {
diff --git a/sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java b/sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java
new file mode 100644 (file)
index 0000000..d23eeb5
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * 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 com.google.common.base.Strings;
+import com.google.common.collect.Lists;
+import java.util.Collection;
+import java.util.List;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.sonar.api.resources.Scopes;
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+
+public class SnapshotDao implements Dao {
+
+  @CheckForNull
+  public SnapshotDto selectNullableById(DbSession session, long id) {
+    return mapper(session).selectByKey(id);
+  }
+
+  public SnapshotDto selectById(DbSession session, long id) {
+    SnapshotDto value = selectNullableById(session, id);
+    if (value == null) {
+      throw new IllegalArgumentException(String.format("Snapshot id does not exist: %d", id));
+    }
+    return value;
+  }
+
+  @CheckForNull
+  public SnapshotDto selectLastSnapshotByComponentId(DbSession session, long componentId) {
+    return mapper(session).selectLastSnapshot(componentId);
+  }
+
+  public List<SnapshotDto> selectSnapshotsByComponentId(DbSession session, long componentId) {
+    return mapper(session).selectSnapshotsByQuery(new SnapshotQuery().setComponentId(componentId));
+  }
+
+  public List<SnapshotDto> selectSnapshotsByQuery(DbSession session, SnapshotQuery query) {
+    return mapper(session).selectSnapshotsByQuery(query);
+  }
+
+  public List<SnapshotDto> selectPreviousVersionSnapshots(DbSession session, long componentId, String lastVersion) {
+    return mapper(session).selectPreviousVersionSnapshots(componentId, lastVersion);
+  }
+
+  public List<SnapshotDto> selectSnapshotAndChildrenOfProjectScope(DbSession session, long snapshotId) {
+    return mapper(session).selectSnapshotAndChildrenOfScope(snapshotId, Scopes.PROJECT);
+  }
+
+  public int updateSnapshotAndChildrenLastFlagAndStatus(DbSession session, SnapshotDto snapshot, boolean isLast, String status) {
+    Long rootId = snapshot.getId();
+    String path = Strings.nullToEmpty(snapshot.getPath()) + snapshot.getId() + ".%";
+    Long pathRootId = snapshot.getRootIdOrSelf();
+
+    return mapper(session).updateSnapshotAndChildrenLastFlagAndStatus(rootId, pathRootId, path, isLast, status);
+  }
+
+  public int updateSnapshotAndChildrenLastFlag(DbSession session, SnapshotDto snapshot, boolean isLast) {
+    Long rootId = snapshot.getId();
+    String path = Strings.nullToEmpty(snapshot.getPath()) + snapshot.getId() + ".%";
+    Long pathRootId = snapshot.getRootIdOrSelf();
+
+    return mapper(session).updateSnapshotAndChildrenLastFlag(rootId, pathRootId, path, isLast);
+  }
+
+  public static boolean isLast(SnapshotDto snapshotTested, @Nullable SnapshotDto previousLastSnapshot) {
+    return previousLastSnapshot == null || previousLastSnapshot.getCreatedAt() < snapshotTested.getCreatedAt();
+  }
+
+  public SnapshotDto insert(DbSession session, SnapshotDto item) {
+    mapper(session).insert(item);
+    return item;
+  }
+
+  public void insert(DbSession session, Collection<SnapshotDto> items) {
+    for (SnapshotDto item : items) {
+      insert(session, item);
+    }
+  }
+
+  public void insert(DbSession session, SnapshotDto item, SnapshotDto... others) {
+    insert(session, Lists.asList(item, others));
+  }
+
+  private SnapshotMapper mapper(DbSession session) {
+    return session.getMapper(SnapshotMapper.class);
+  }
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/compute/AnalysisReportDao.java b/sonar-db/src/main/java/org/sonar/db/compute/AnalysisReportDao.java
new file mode 100644 (file)
index 0000000..d805044
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * 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.compute;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.sonar.api.utils.System2;
+import org.sonar.db.compute.AnalysisReportDto;
+import org.sonar.db.compute.AnalysisReportMapper;
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+
+import javax.annotation.CheckForNull;
+
+import java.util.List;
+
+import static org.sonar.db.compute.AnalysisReportDto.Status.PENDING;
+import static org.sonar.db.compute.AnalysisReportDto.Status.WORKING;
+
+public class AnalysisReportDao implements Dao {
+
+  private System2 system2;
+
+  public AnalysisReportDao(System2 system2) {
+    this.system2 = system2;
+  }
+
+  /**
+   * Update all rows with: STATUS='PENDING', STARTED_AT=NULL, UPDATED_AT={now}
+   */
+  public void resetAllToPendingStatus(DbSession session) {
+    mapper(session).resetAllToPendingStatus(system2.now());
+  }
+
+  public void truncate(DbSession session) {
+    mapper(session).truncate();
+  }
+
+  public List<AnalysisReportDto> selectByProjectKey(DbSession session, String projectKey) {
+    return mapper(session).selectByProjectKey(projectKey);
+  }
+
+  @VisibleForTesting
+  AnalysisReportDto selectById(DbSession session, long id) {
+    return mapper(session).selectById(id);
+  }
+
+  @CheckForNull
+  public AnalysisReportDto pop(DbSession session) {
+    List<Long> reportIds = mapper(session).selectAvailables(PENDING, WORKING);
+    if (reportIds.isEmpty()) {
+      return null;
+    }
+
+    long reportId = reportIds.get(0);
+    return tryToPop(session, reportId);
+  }
+
+  @VisibleForTesting
+  AnalysisReportDto tryToPop(DbSession session, long reportId) {
+    AnalysisReportMapper mapper = mapper(session);
+    int nbOfReportBooked = mapper.updateWithBookingReport(reportId, system2.now(), PENDING, WORKING);
+    if (nbOfReportBooked == 0) {
+      return null;
+    }
+
+    AnalysisReportDto result = mapper.selectById(reportId);
+    session.commit();
+    return result;
+  }
+
+  public List<AnalysisReportDto> selectAll(DbSession session) {
+    return mapper(session).selectAll();
+  }
+
+  public AnalysisReportDto insert(DbSession session, AnalysisReportDto report) {
+    report.setCreatedAt(system2.now());
+    report.setUpdatedAt(system2.now());
+    mapper(session).insert(report);
+    return report;
+  }
+
+  public void delete(DbSession session, long id) {
+    mapper(session).delete(id);
+  }
+
+  private AnalysisReportMapper mapper(DbSession session) {
+    return session.getMapper(AnalysisReportMapper.class);
+  }
+}
index 8463da58cfae6d2e0b7fe9c794ca7b0500358009..c29f495047efd39898f2e4111e31bd02189ad580 100644 (file)
@@ -22,11 +22,9 @@ package org.sonar.db.dashboard;
 import java.util.List;
 import javax.annotation.Nullable;
 import org.apache.ibatis.session.SqlSession;
-import org.sonar.api.server.ServerSide;
 import org.sonar.db.Dao;
 import org.sonar.db.MyBatis;
 
-@ServerSide
 public class ActiveDashboardDao implements Dao {
 
   private MyBatis mybatis;
index 40b151e7ec965da43ed556a3fc4d464a3738be7d..4462c1c24c877418757e552713a80c839c07e3bd 100644 (file)
  */
 package org.sonar.db.dashboard;
 
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
 import org.apache.ibatis.session.SqlSession;
 import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
 
 public class DashboardDao implements Dao {
@@ -62,4 +65,21 @@ public class DashboardDao implements Dao {
     }
   }
 
+  @CheckForNull
+  public DashboardDto getNullableByKey(DbSession session, Long key) {
+    return mapper(session).selectById(key);
+  }
+
+  /**
+   * Get dashboard if allowed : shared or owned by logged-in user
+   * @param userId id of logged-in user, null if anonymous
+   */
+  @CheckForNull
+  public DashboardDto getAllowedByKey(DbSession session, Long key, @Nullable Long userId) {
+    return mapper(session).selectAllowedById(key, userId != null ? userId : -1L);
+  }
+
+  private DashboardMapper mapper(DbSession session) {
+    return session.getMapper(DashboardMapper.class);
+  }
 }
diff --git a/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetDao.java b/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetDao.java
new file mode 100644 (file)
index 0000000..dec9816
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * 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.dashboard;
+
+import java.util.Collection;
+import org.sonar.db.dashboard.WidgetDto;
+import org.sonar.db.dashboard.WidgetMapper;
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+import org.sonar.db.MyBatis;
+
+public class WidgetDao implements Dao {
+
+  private MyBatis myBatis;
+
+  public WidgetDao(MyBatis myBatis) {
+    this.myBatis = myBatis;
+  }
+
+  public WidgetDto getNullableByKey(Long widgetId) {
+    DbSession session = myBatis.openSession(false);
+    try {
+      return getNullableByKey(session, widgetId);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public WidgetDto getNullableByKey(DbSession session, Long widgetId) {
+    return mapper(session).selectById(widgetId);
+  }
+
+  public WidgetDto update(WidgetDto item) {
+    DbSession session = myBatis.openSession(false);
+    try {
+      return update(session, item);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public WidgetDto update(DbSession session, WidgetDto item) {
+    mapper(session).update(item);
+    return item;
+  }
+
+  public Collection<WidgetDto> findByDashboard(DbSession session, long dashboardKey) {
+    return mapper(session).selectByDashboard(dashboardKey);
+  }
+
+  public Collection<WidgetDto> findAll(DbSession session) {
+    return mapper(session).selectAll();
+  }
+
+  private WidgetMapper mapper(DbSession session) {
+    return session.getMapper(WidgetMapper.class);
+  }
+
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetPropertyDao.java b/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetPropertyDao.java
new file mode 100644 (file)
index 0000000..0102d33
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * 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.dashboard;
+
+import com.google.common.base.Function;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import org.sonar.db.Dao;
+import org.sonar.db.DaoUtils;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.db.DbSession;
+import org.sonar.db.MyBatis;
+
+public class WidgetPropertyDao implements Dao {
+
+  private final MyBatis myBatis;
+
+  public WidgetPropertyDao(MyBatis myBatis) {
+    this.myBatis = myBatis;
+  }
+
+  public WidgetPropertyDto insert(WidgetPropertyDto item) {
+    DbSession session = myBatis.openSession(false);
+    try {
+      return insert(session, item);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public WidgetPropertyDto insert(DbSession session, WidgetPropertyDto item) {
+    mapper(session).insert(item);
+    return item;
+  }
+
+  public void insert(DbSession session, Collection<WidgetPropertyDto> items) {
+    for (WidgetPropertyDto item : items) {
+      insert(session, item);
+    }
+  }
+
+  public WidgetPropertyDto getNullableByKey(Long propertyId) {
+    DbSession session = myBatis.openSession(false);
+    try {
+      return getNullableByKey(session, propertyId);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public WidgetPropertyDto getNullableByKey(DbSession session, Long propertyId) {
+    return mapper(session).selectById(propertyId);
+  }
+
+  public Collection<WidgetPropertyDto> findByDashboard(DbSession session, long dashboardKey) {
+    return mapper(session).selectByDashboard(dashboardKey);
+  }
+
+  public void deleteByWidgetIds(final DbSession session, List<Long> widgetIdsWithPropertiesToDelete) {
+    DatabaseUtils.executeLargeInputs(widgetIdsWithPropertiesToDelete, new Function<List<Long>, List<Void>>() {
+      @Override
+      public List<Void> apply(List<Long> input) {
+        mapper(session).deleteByWidgetIds(input);
+        return Arrays.asList();
+      }
+    });
+  }
+
+  private WidgetPropertyMapper mapper(DbSession session) {
+    return session.getMapper(WidgetPropertyMapper.class);
+  }
+}
index 25690f3556953a95e8ddf28df0595f3792e30955..94d7ef81c731a746ed01fd6c844e8a0a98d15b2f 100644 (file)
@@ -22,10 +22,11 @@ package org.sonar.db.duplication;
 import java.util.Collection;
 import java.util.List;
 import org.apache.ibatis.session.SqlSession;
+import org.sonar.db.Dao;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
 
-public class DuplicationDao {
+public class DuplicationDao implements Dao {
 
   private final MyBatis mybatis;
 
diff --git a/sonar-db/src/main/java/org/sonar/db/event/EventDao.java b/sonar-db/src/main/java/org/sonar/db/event/EventDao.java
new file mode 100644 (file)
index 0000000..0f58097
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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.event;
+
+import java.util.List;
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+
+public class EventDao implements Dao {
+
+  public List<EventDto> selectByComponentUuid(DbSession session, String componentUuid) {
+    return session.getMapper(EventMapper.class).selectByComponentUuid(componentUuid);
+  }
+
+  public void insert(DbSession session, EventDto dto) {
+    session.getMapper(EventMapper.class).insert(dto);
+  }
+
+  public void delete(DbSession session, Long id) {
+    session.getMapper(EventMapper.class).delete(id);
+  }
+
+}
index bb63a3c9b90a7d0ec8d47ba0d92846a02dd4e189..5c061ad24070be4885689426a279f3d600c6cd6b 100644 (file)
@@ -25,13 +25,11 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import org.apache.ibatis.session.SqlSession;
-import org.sonar.api.server.ServerSide;
 import org.sonar.db.Dao;
 import org.sonar.db.MyBatis;
 
 import static com.google.common.collect.Lists.newArrayList;
 
-@ServerSide
 public class ActionPlanDao implements Dao {
 
   private final MyBatis mybatis;
index dfd4192922b022409dcf54de6f1cb785635771bd..4d653374b5c078f5f9597b62bfb2771278f6686d 100644 (file)
@@ -22,18 +22,18 @@ package org.sonar.db.issue;
 
 import java.util.List;
 import org.apache.ibatis.session.SqlSession;
+import org.sonar.api.utils.System2;
+import org.sonar.db.AbstractDao;
 import org.sonar.db.MyBatis;
 
-public class ActionPlanStatsDao {
+public class ActionPlanStatsDao extends AbstractDao {
 
-  private final MyBatis mybatis;
-
-  public ActionPlanStatsDao(MyBatis mybatis) {
-    this.mybatis = mybatis;
+  public ActionPlanStatsDao(MyBatis myBatis, System2 system2) {
+    super(myBatis, system2);
   }
 
   public List<ActionPlanStatsDto> findByProjectId(Long projectId) {
-    SqlSession session = mybatis.openSession(false);
+    SqlSession session = myBatis().openSession(false);
     try {
       return session.getMapper(ActionPlanStatsMapper.class).findByProjectId(projectId);
     } finally {
index edc89f9c26782e07e5d257a0b5be4bd2f2e80c28..cecd0fe0f0866a84934cc4ca33a08fca51314385 100644 (file)
 
 package org.sonar.db.issue;
 
+import java.util.List;
+import java.util.Set;
+import javax.annotation.CheckForNull;
 import org.apache.ibatis.session.ResultHandler;
 import org.apache.ibatis.session.SqlSession;
+import org.sonar.db.Dao;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
 
-public class IssueDao {
+public class IssueDao implements Dao {
 
   private final MyBatis mybatis;
 
@@ -43,7 +47,48 @@ public class IssueDao {
     }
   }
 
-  protected IssueMapper mapper(DbSession session) {
+  @CheckForNull
+  public IssueDto selectNullableByKey(DbSession session, String key) {
+    return mapper(session).selectByKey(key);
+  }
+
+  public IssueDto selectByKey(DbSession session, String key) {
+    IssueDto issue = selectNullableByKey(session, key);
+    if (issue == null) {
+      throw new IllegalArgumentException(String.format("Issue key '%s' does not exist", key));
+    }
+    return issue;
+  }
+
+  public List<IssueDto> findByActionPlan(DbSession session, String actionPlan) {
+    return mapper(session).selectByActionPlan(actionPlan);
+  }
+
+  public List<IssueDto> selectByKeys(DbSession session, List<String> keys) {
+    return mapper(session).selectByKeys(keys);
+  }
+
+  public Set<String> selectComponentUuidsOfOpenIssuesForProjectUuid(DbSession session, String projectUuid) {
+    return mapper(session).selectComponentUuidsOfOpenIssuesForProjectUuid(projectUuid);
+  }
+
+  public void insert(DbSession session, IssueDto dto) {
+    mapper(session).insert(dto);
+  }
+
+  public void insert(DbSession session, IssueDto dto, IssueDto... others) {
+    IssueMapper mapper = mapper(session);
+    mapper.insert(dto);
+    for (IssueDto other : others) {
+      mapper.insert(other);
+    }
+  }
+
+  public void update(DbSession session, IssueDto dto) {
+    mapper(session).update(dto);
+  }
+
+  private IssueMapper mapper(DbSession session) {
     return session.getMapper(IssueMapper.class);
   }
 
index f9de1a199638acfe59fe3cfbb189a74c960f63a9..7f1f06ce32457de46f0984d3bed9bc008bcfc811 100644 (file)
@@ -22,9 +22,10 @@ package org.sonar.db.issue;
 
 import java.util.List;
 import org.apache.ibatis.session.SqlSession;
+import org.sonar.db.Dao;
 import org.sonar.db.MyBatis;
 
-public class IssueFilterFavouriteDao {
+public class IssueFilterFavouriteDao implements Dao {
 
   private final MyBatis mybatis;
 
diff --git a/sonar-db/src/main/java/org/sonar/db/measure/MeasureDao.java b/sonar-db/src/main/java/org/sonar/db/measure/MeasureDao.java
new file mode 100644 (file)
index 0000000..ff4b710
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * 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.measure;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Lists;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+import javax.annotation.CheckForNull;
+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.SnapshotDto;
+
+public class MeasureDao implements Dao {
+
+  public boolean existsByKey(DbSession session, String componentKey, String metricKey) {
+    return mapper(session).countByComponentAndMetric(componentKey, metricKey) > 0;
+  }
+
+  @CheckForNull
+  public MeasureDto findByComponentKeyAndMetricKey(DbSession session, String componentKey, String metricKey) {
+    return mapper(session).selectByComponentAndMetric(componentKey, metricKey);
+  }
+
+  public List<MeasureDto> findByComponentKeyAndMetricKeys(final DbSession session, final String componentKey, List<String> metricKeys) {
+    return DatabaseUtils.executeLargeInputs(metricKeys, new Function<List<String>, List<MeasureDto>>() {
+      @Override
+      public List<MeasureDto> apply(List<String> keys) {
+        return mapper(session).selectByComponentAndMetrics(componentKey, keys);
+      }
+    });
+  }
+
+  public List<PastMeasureDto> selectByComponentUuidAndProjectSnapshotIdAndMetricIds(final DbSession session, final String componentUuid, final long projectSnapshotId,
+    Set<Integer> metricIds) {
+    return DatabaseUtils.executeLargeInputs(metricIds, new Function<List<Integer>, List<PastMeasureDto>>() {
+      @Override
+      public List<PastMeasureDto> apply(List<Integer> ids) {
+        return mapper(session).selectByComponentUuidAndProjectSnapshotIdAndStatusAndMetricIds(componentUuid, projectSnapshotId, ids,
+          SnapshotDto.STATUS_PROCESSED);
+      }
+    });
+  }
+
+  public void insert(DbSession session, MeasureDto measureDto) {
+    mapper(session).insert(measureDto);
+  }
+
+  public void insert(DbSession session, Collection<MeasureDto> items) {
+    for (MeasureDto item : items) {
+      insert(session, item);
+    }
+  }
+
+  public void insert(DbSession session, MeasureDto item, MeasureDto... others) {
+    insert(session, Lists.asList(item, others));
+  }
+
+  public List<String> selectMetricKeysForSnapshot(DbSession session, long snapshotId) {
+    return mapper(session).selectMetricKeysForSnapshot(snapshotId);
+  }
+
+  private MeasureMapper mapper(DbSession session) {
+    return session.getMapper(MeasureMapper.class);
+  }
+}
index 50d0bad2f534140bcf2adf39a0bfac61d0733fb6..8b5981caa453e03655f793a8ee313c9853a5d085 100644 (file)
 package org.sonar.db.measure;
 
 import org.apache.ibatis.session.SqlSession;
+import org.sonar.db.Dao;
 import org.sonar.db.MyBatis;
 
-public class MeasureFilterDao {
+public class MeasureFilterDao implements Dao {
   private MyBatis mybatis;
 
   public MeasureFilterDao(MyBatis mybatis) {
index b82ba01dd09f4ca169512ddd05643655adb2638e..6fc69f7818e690d6477f05ea69fa1bfdef061583 100644 (file)
@@ -23,10 +23,11 @@ package org.sonar.db.notification;
 import java.util.Collections;
 import java.util.List;
 import org.apache.ibatis.session.SqlSession;
+import org.sonar.db.Dao;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
 
-public class NotificationQueueDao {
+public class NotificationQueueDao implements Dao {
 
   private final MyBatis mybatis;
 
index e6a1508e222594c4214478a5a375bff04f57b8d2..e18bdbbcb57a5dbd641c67ad5b70c2503cce45f5 100644 (file)
@@ -27,13 +27,12 @@ import javax.annotation.Nullable;
 import org.apache.ibatis.session.RowBounds;
 import org.apache.ibatis.session.SqlSession;
 import org.sonar.api.security.DefaultGroups;
-import org.sonar.api.server.ServerSide;
+import org.sonar.db.Dao;
 import org.sonar.db.MyBatis;
 
 import static com.google.common.collect.Maps.newHashMap;
 
-@ServerSide
-public class PermissionDao {
+public class PermissionDao implements Dao {
 
   private static final String QUERY_PARAMETER = "query";
   private static final String COMPONENT_ID_PARAMETER = "componentId";
index cb1a63adbe3986e54065ba2e080291fa60f825b2..c69532dc8eab7ada0cdf2edfad80375eb9972359 100644 (file)
@@ -36,6 +36,7 @@ import org.apache.ibatis.session.SqlSession;
 import org.sonar.api.resources.Scopes;
 import org.sonar.db.Dao;
 import org.sonar.db.DaoUtils;
+import org.sonar.db.DatabaseUtils;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
 
@@ -83,7 +84,7 @@ public class PropertiesDao implements Dao {
     String sql = "SELECT count(*) FROM properties pp " +
       "left outer join projects pj on pp.resource_id = pj.id " +
       "where pp.user_id is not null and (pp.resource_id is null or pj.uuid=?) " +
-      "and (" + DaoUtils.repeatCondition("pp.prop_key like ?", dispatcherKeys.size(), "or") + ")";
+      "and (" + DatabaseUtils.repeatCondition("pp.prop_key like ?", dispatcherKeys.size(), "or") + ")";
     try {
       pstmt = connection.prepareStatement(sql);
       pstmt.setString(1, projectUuid);
index a06767ab51cb6913b2b3462b76de4d6511b19c7a..f4ddf2478b696c15dc04562035ffd3f7b514811c 100644 (file)
@@ -48,19 +48,17 @@ public class PurgeDao implements Dao {
   private final MyBatis mybatis;
   private final ResourceDao resourceDao;
   private final System2 system2;
-  private final PurgeProfiler profiler;
 
-  public PurgeDao(MyBatis mybatis, ResourceDao resourceDao, PurgeProfiler profiler, System2 system2) {
+  public PurgeDao(MyBatis mybatis, ResourceDao resourceDao, System2 system2) {
     this.mybatis = mybatis;
     this.resourceDao = resourceDao;
-    this.profiler = profiler;
     this.system2 = system2;
   }
 
-  public PurgeDao purge(PurgeConfiguration conf, PurgeListener purgeListener) {
+  public PurgeDao purge(PurgeConfiguration conf, PurgeListener listener, PurgeProfiler profiler) {
     DbSession session = mybatis.openSession(true);
     try {
-      purge(session, conf, purgeListener);
+      purge(session, conf, listener, profiler);
       session.commit();
     } finally {
       MyBatis.closeQuietly(session);
@@ -68,7 +66,7 @@ public class PurgeDao implements Dao {
     return this;
   }
 
-  public void purge(DbSession session, PurgeConfiguration conf, PurgeListener purgeListener) {
+  public void purge(DbSession session, PurgeConfiguration conf, PurgeListener listener, PurgeProfiler profiler) {
     PurgeMapper mapper = session.getMapper(PurgeMapper.class);
     PurgeCommands commands = new PurgeCommands(session, mapper, profiler);
     List<ResourceDto> projects = getProjects(conf.rootProjectIdUuid().getId(), session);
@@ -78,7 +76,7 @@ public class PurgeDao implements Dao {
       purge(project, conf.scopesWithoutHistoricalData(), commands);
     }
     for (ResourceDto project : projects) {
-      disableOrphanResources(project, session, mapper, purgeListener);
+      disableOrphanResources(project, session, mapper, listener);
     }
     deleteOldClosedIssues(conf, mapper);
   }
@@ -171,16 +169,16 @@ public class PurgeDao implements Dao {
     return result;
   }
 
-  public PurgeDao deleteResourceTree(IdUuidPair rootIdUuid) {
+  public PurgeDao deleteResourceTree(IdUuidPair rootIdUuid, PurgeProfiler profiler) {
     DbSession session = mybatis.openSession(true);
     try {
-      return deleteResourceTree(session, rootIdUuid);
+      return deleteResourceTree(session, rootIdUuid, profiler);
     } finally {
       MyBatis.closeQuietly(session);
     }
   }
 
-  public PurgeDao deleteResourceTree(DbSession session, IdUuidPair rootIdUuid) {
+  public PurgeDao deleteResourceTree(DbSession session, IdUuidPair rootIdUuid, PurgeProfiler profiler) {
     deleteProject(rootIdUuid, mapper(session), new PurgeCommands(session, profiler));
     deleteFileSources(rootIdUuid.getUuid(), new PurgeCommands(session, profiler));
     return this;
@@ -209,17 +207,17 @@ public class PurgeDao implements Dao {
     mapper.resolveResourceIssuesNotAlreadyResolved(componentIdUuid.getUuid(), system2.now());
   }
 
-  public PurgeDao deleteSnapshots(PurgeSnapshotQuery query) {
+  public PurgeDao deleteSnapshots(PurgeSnapshotQuery query, PurgeProfiler profiler) {
     final DbSession session = mybatis.openSession(true);
     try {
-      return deleteSnapshots(query, session);
+      return deleteSnapshots(query, session, profiler);
 
     } finally {
       MyBatis.closeQuietly(session);
     }
   }
 
-  public PurgeDao deleteSnapshots(PurgeSnapshotQuery query, final DbSession session) {
+  public PurgeDao deleteSnapshots(PurgeSnapshotQuery query, DbSession session, PurgeProfiler profiler) {
     new PurgeCommands(session, profiler).deleteSnapshots(query);
     return this;
   }
index ac7bad54d1ad88b4d01f418a2e19cba6f66ce06e..35c035781225dcecda722be984d8741ee67b7d65 100644 (file)
@@ -29,6 +29,7 @@ import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.db.DbSession;
 import org.sonar.db.purge.PurgeDao;
+import org.sonar.db.purge.PurgeProfiler;
 import org.sonar.db.purge.PurgeSnapshotQuery;
 import org.sonar.db.purge.PurgeableSnapshotDto;
 
@@ -36,10 +37,12 @@ import org.sonar.db.purge.PurgeableSnapshotDto;
 public class DefaultPeriodCleaner {
 
   private static final Logger LOG = Loggers.get(DefaultPeriodCleaner.class);
-  private PurgeDao purgeDao;
+  private final PurgeDao purgeDao;
+  private final PurgeProfiler profiler;
 
-  public DefaultPeriodCleaner(PurgeDao purgeDao) {
+  public DefaultPeriodCleaner(PurgeDao purgeDao, PurgeProfiler profiler) {
     this.purgeDao = purgeDao;
+    this.profiler = profiler;
   }
 
   public void clean(DbSession session, long projectId, Settings settings) {
@@ -58,8 +61,8 @@ public class DefaultPeriodCleaner {
   private void delete(List<PurgeableSnapshotDto> snapshots, DbSession session) {
     for (PurgeableSnapshotDto snapshot : snapshots) {
       LOG.debug("<- Delete snapshot: {} [{}]", DateUtils.formatDateTime(snapshot.getDate()), snapshot.getSnapshotId());
-      purgeDao.deleteSnapshots(PurgeSnapshotQuery.create().setRootSnapshotId(snapshot.getSnapshotId()), session);
-      purgeDao.deleteSnapshots(PurgeSnapshotQuery.create().setId(snapshot.getSnapshotId()), session);
+      purgeDao.deleteSnapshots(PurgeSnapshotQuery.create().setRootSnapshotId(snapshot.getSnapshotId()), session, profiler);
+      purgeDao.deleteSnapshots(PurgeSnapshotQuery.create().setId(snapshot.getSnapshotId()), session, profiler);
     }
   }
 
diff --git a/sonar-db/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java b/sonar-db/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java
deleted file mode 100644 (file)
index 24efe18..0000000
+++ /dev/null
@@ -1,67 +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.qualityprofile;
-
-import java.util.List;
-import org.apache.ibatis.session.SqlSession;
-import org.sonar.api.server.ServerSide;
-import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
-
-/**
- * @deprecated use the ActiveRuleDao class defined in sonar-server
- */
-@Deprecated
-@ServerSide
-public class ActiveRuleDao {
-
-  private final MyBatis mybatis;
-
-  public ActiveRuleDao(MyBatis mybatis) {
-    this.mybatis = mybatis;
-  }
-
-  public void insert(ActiveRuleDto dto, SqlSession session) {
-    session.getMapper(ActiveRuleMapper.class).insert(dto);
-  }
-
-  public List<ActiveRuleDto> selectByProfileKey(String profileKey) {
-    DbSession session = mybatis.openSession(false);
-    try {
-      return session.getMapper(ActiveRuleMapper.class).selectByProfileKey(profileKey);
-    } finally {
-      session.close();
-    }
-  }
-
-  public void insert(ActiveRuleParamDto dto, SqlSession session) {
-    session.getMapper(ActiveRuleMapper.class).insertParameter(dto);
-  }
-
-  public List<ActiveRuleParamDto> selectParamsByProfileKey(String profileKey) {
-    DbSession session = mybatis.openSession(false);
-    try {
-      return session.getMapper(ActiveRuleMapper.class).selectParamsByProfileKey(profileKey);
-    } finally {
-      session.close();
-    }
-  }
-}
index 25236bc2bcb39163fcd0b4ebd8a868b61a444928..8991c688db61a4f29b4aa4f342d109d63d472a33 100644 (file)
@@ -21,13 +21,14 @@ package org.sonar.db.rule;
 
 import java.util.List;
 import org.apache.ibatis.session.SqlSession;
+import org.sonar.db.Dao;
 import org.sonar.db.MyBatis;
 
 /**
  * @deprecated in 4.4 moved to org.sonar.server.rule.db.RuleDao.
  */
 @Deprecated
-public class RuleDao {
+public class RuleDao implements Dao {
 
   private MyBatis mybatis;
 
index c34a9b89542d52c6c3028acfb59c3325415d7804..59c89c738b1c75339fa434b94646133b336ae1d3 100644 (file)
@@ -24,15 +24,13 @@ import javax.annotation.CheckForNull;
 import org.apache.ibatis.session.SqlSession;
 import org.sonar.api.utils.Semaphores;
 import org.sonar.api.utils.System2;
+import org.sonar.db.Dao;
 import org.sonar.db.MyBatis;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static org.sonar.api.utils.DateUtils.longToDate;
 
-/**
- * @since 3.4
- */
-public class SemaphoreDao {
+public class SemaphoreDao implements Dao {
 
   private static final String SEMAPHORE_NAME_MUST_NOT_BE_EMPTY = "Semaphore name must not be empty";
   private final MyBatis mybatis;
diff --git a/sonar-db/src/main/java/org/sonar/db/source/FileSourceDao.java b/sonar-db/src/main/java/org/sonar/db/source/FileSourceDao.java
new file mode 100644 (file)
index 0000000..6aeb7d0
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ * 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.source;
+
+import com.google.common.base.Function;
+import com.google.common.base.Splitter;
+import java.io.Reader;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+import javax.annotation.CheckForNull;
+import org.apache.commons.dbutils.DbUtils;
+import org.apache.commons.io.IOUtils;
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+import org.sonar.db.MyBatis;
+import org.sonar.db.source.FileSourceDto.Type;
+
+public class FileSourceDao implements Dao {
+
+  private static final Splitter END_OF_LINE_SPLITTER = Splitter.on('\n');
+  private final MyBatis mybatis;
+
+  public FileSourceDao(MyBatis myBatis) {
+    this.mybatis = myBatis;
+  }
+
+  @CheckForNull
+  public FileSourceDto selectSource(String fileUuid) {
+    DbSession session = mybatis.openSession(false);
+    try {
+      return mapper(session).select(fileUuid, Type.SOURCE);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  @CheckForNull
+  public FileSourceDto selectTest(String fileUuid) {
+    DbSession session = mybatis.openSession(false);
+    try {
+      return mapper(session).select(fileUuid, Type.TEST);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  @CheckForNull
+  public List<String> selectLineHashes(DbSession dbSession, String fileUuid) {
+    Connection connection = dbSession.getConnection();
+    PreparedStatement pstmt = null;
+    ResultSet rs = null;
+    try {
+      pstmt = connection.prepareStatement("SELECT line_hashes FROM file_sources WHERE file_uuid=? AND data_type=?");
+      pstmt.setString(1, fileUuid);
+      pstmt.setString(2, Type.SOURCE);
+      rs = pstmt.executeQuery();
+      if (rs.next()) {
+        return END_OF_LINE_SPLITTER.splitToList(rs.getString(1));
+      }
+      return null;
+    } catch (SQLException e) {
+      throw new IllegalStateException("Fail to read FILE_SOURCES.LINE_HASHES of file " + fileUuid, e);
+    } finally {
+      DbUtils.closeQuietly(connection, pstmt, rs);
+    }
+  }
+
+  public <T> void readLineHashesStream(DbSession dbSession, String fileUuid, Function<Reader, T> function) {
+    Connection connection = dbSession.getConnection();
+    PreparedStatement pstmt = null;
+    ResultSet rs = null;
+    Reader reader = null;
+    try {
+      pstmt = connection.prepareStatement("SELECT line_hashes FROM file_sources WHERE file_uuid=? AND data_type=?");
+      pstmt.setString(1, fileUuid);
+      pstmt.setString(2, Type.SOURCE);
+      rs = pstmt.executeQuery();
+      if (rs.next()) {
+        reader = rs.getCharacterStream(1);
+        function.apply(reader);
+      }
+    } catch (SQLException e) {
+      throw new IllegalStateException("Fail to read FILE_SOURCES.LINE_HASHES of file " + fileUuid, e);
+    } finally {
+      IOUtils.closeQuietly(reader);
+      DbUtils.closeQuietly(connection, pstmt, rs);
+    }
+  }
+
+  public void insert(FileSourceDto dto) {
+    DbSession session = mybatis.openSession(false);
+    try {
+      insert(session, dto);
+      session.commit();
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public void insert(DbSession session, FileSourceDto dto) {
+    mapper(session).insert(dto);
+  }
+
+  public void update(FileSourceDto dto) {
+    DbSession session = mybatis.openSession(false);
+    try {
+      update(session, dto);
+      session.commit();
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public void update(DbSession session, FileSourceDto dto) {
+    mapper(session).update(dto);
+  }
+
+  public void updateDateWhenUpdatedDateIsZero(DbSession session, String projectUuid, long updateDate) {
+    mapper(session).updateDateWhenUpdatedDateIsZero(projectUuid, updateDate);
+  }
+
+  private FileSourceMapper mapper(DbSession session) {
+    return session.getMapper(FileSourceMapper.class);
+  }
+}
index 5837964ce82cda667ce6dbb04747617ab0b06100..56a4eb312fc331afdc39f96991dae8caec8a13ff 100644 (file)
@@ -27,6 +27,7 @@ import java.util.List;
 import org.apache.ibatis.session.SqlSession;
 import org.sonar.db.Dao;
 import org.sonar.db.DaoUtils;
+import org.sonar.db.DatabaseUtils;
 import org.sonar.db.MyBatis;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ResourceDao;
@@ -112,7 +113,7 @@ public class AuthorDao implements Dao {
   }
 
   public List<String> selectScmAccountsByDeveloperUuids(final SqlSession session, Collection<String> developerUuids) {
-    return DaoUtils.executeLargeInputs(developerUuids, new Function<List<String>, List<String>>() {
+    return DatabaseUtils.executeLargeInputs(developerUuids, new Function<List<String>, List<String>>() {
       @Override
       public List<String> apply(List<String> partition) {
         return session.getMapper(AuthorMapper.class).selectScmAccountsByDeveloperUuids(partition);
index 2a386c1d2b7c3d808c4ad11082cd33b5d37d66c2..c4c8a118dce1c6c03c8e85f9dcb032a8e9f1ad07 100644 (file)
@@ -30,6 +30,7 @@ import org.apache.ibatis.session.SqlSession;
 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.MyBatis;
 
@@ -49,7 +50,7 @@ public class AuthorizationDao implements Dao {
     if (componentIds.isEmpty()) {
       return Collections.emptySet();
     }
-    return DaoUtils.executeLargeInputs(componentIds, new Function<List<Long>, List<Long>>() {
+    return DatabaseUtils.executeLargeInputs(componentIds, new Function<List<Long>, List<Long>>() {
       @Override
       public List<Long> apply(List<Long> partition) {
         if (userId == null) {
index a62609259b8e928a7d5c9f521b8c5aa4b3a338ee..e27e6fe5d98806c258df9ad041ed5709c436ea04 100644 (file)
@@ -34,6 +34,7 @@ import org.apache.ibatis.session.RowBounds;
 import org.apache.ibatis.session.SqlSession;
 import org.sonar.db.Dao;
 import org.sonar.db.DaoUtils;
+import org.sonar.db.DatabaseUtils;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
 
@@ -77,7 +78,7 @@ public class GroupMembershipDao implements Dao {
 
   public Map<String, Integer> countUsersByGroups(final DbSession session, Collection<Long> groupIds) {
     final Map<String, Integer> result = Maps.newHashMap();
-    DaoUtils.executeLargeInputs(groupIds, new Function<List<Long>, List<GroupUserCount>>() {
+    DatabaseUtils.executeLargeInputs(groupIds, new Function<List<Long>, List<GroupUserCount>>() {
       @Override
       public List<GroupUserCount> apply(@Nonnull List<Long> input) {
         List<GroupUserCount> userCounts = mapper(session).countUsersByGroup(input);
@@ -93,7 +94,7 @@ public class GroupMembershipDao implements Dao {
 
   public Multimap<String, String> selectGroupsByLogins(final DbSession session, Collection<String> logins) {
     final Multimap<String, String> result = ArrayListMultimap.create();
-    DaoUtils.executeLargeInputs(logins, new Function<List<String>, List<LoginGroup>>() {
+    DatabaseUtils.executeLargeInputs(logins, new Function<List<String>, List<LoginGroup>>() {
       @Override
       public List<LoginGroup> apply(@Nonnull List<String> input) {
         List<LoginGroup> groupMemberships = mapper(session).selectGroupsByLogins(input);
diff --git a/sonar-db/src/main/java/org/sonar/db/user/UserGroupDao.java b/sonar-db/src/main/java/org/sonar/db/user/UserGroupDao.java
new file mode 100644 (file)
index 0000000..2c5a866
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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.user;
+
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+
+public class UserGroupDao implements Dao {
+
+  public UserGroupDto insert(DbSession session, UserGroupDto dto) {
+    mapper(session).insert(dto);
+    return dto;
+  }
+
+  public void delete(DbSession session, UserGroupDto dto) {
+    mapper(session).delete(dto);
+  }
+
+  public void deleteMembersByGroupId(DbSession session, long groupId) {
+    mapper(session).deleteMembersByGroup(groupId);
+  }
+
+  protected UserGroupMapper mapper(DbSession session) {
+    return session.getMapper(UserGroupMapper.class);
+  }
+}
diff --git a/sonar-db/src/main/resources/org/sonar/db/component/ComponentIndexMapper.xml b/sonar-db/src/main/resources/org/sonar/db/component/ComponentIndexMapper.xml
deleted file mode 100644 (file)
index 2a30878..0000000
+++ /dev/null
@@ -1,16 +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.ComponentIndexMapper">
-
-  <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>
-
-</mapper>
-
index 82afc7fa85d075842a9c00fdb553fdb1375fd994..b9a10673e3ccdd8a46dc69bbf7fd79493459bea4 100644 (file)
@@ -3,6 +3,16 @@
 
 <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
index 24987271dfb875ae2ef09feae90779cc02f602ff..fc7c4b1ef80be75001e84b6528dc6c6a80b98a6d 100644 (file)
  */
 package org.sonar.db;
 
-import com.google.common.base.Function;
-import com.google.common.collect.Iterables;
-import java.util.Collections;
-import java.util.List;
 import org.junit.Test;
 
-import static com.google.common.collect.Lists.newArrayList;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
 
 public class DaoUtilsTest {
 
   @Test
   public void list_all_dao_classes() {
-    List<Class> daoClasses = DaoUtils.getDaoClasses();
-
-    assertThat(daoClasses).isNotEmpty();
-  }
-
-  @Test
-  public void repeatCondition() {
-    assertThat(DaoUtils.repeatCondition("uuid=?", 1, "or")).isEqualTo("uuid=?");
-    assertThat(DaoUtils.repeatCondition("uuid=?", 3, "or")).isEqualTo("uuid=? or uuid=? or uuid=?");
-  }
-
-  @Test
-  public void execute_large_inputs() {
-    List<Integer> inputs = newArrayList();
-    List<String> expectedOutputs = newArrayList();
-    for (int i = 0; i < 2010; i++) {
-      inputs.add(i);
-      expectedOutputs.add(Integer.toString(i));
-    }
-
-    List<String> outputs = DaoUtils.executeLargeInputs(inputs, new Function<List<Integer>, List<String>>() {
-      @Override
-      public List<String> apply(List<Integer> input) {
-        // Check that each partition is only done on 1000 elements max
-        assertThat(input.size()).isLessThanOrEqualTo(1000);
-        return newArrayList(Iterables.transform(input, new Function<Integer, String>() {
-          @Override
-          public String apply(Integer input) {
-            return Integer.toString(input);
-          }
-        }));
-      }
-    });
-
-    assertThat(outputs).isEqualTo(expectedOutputs);
-  }
-
-  @Test
-  public void execute_large_inputs_on_empty_list() {
-    List<String> outputs = DaoUtils.executeLargeInputs(Collections.<Integer>emptyList(), new Function<List<Integer>, List<String>>() {
-      @Override
-      public List<String> apply(List<Integer> input) {
-        fail("No partition should be made on empty list");
-        return Collections.emptyList();
-      }
-    });
-
-    assertThat(outputs).isEmpty();
+    assertThat(DaoUtils.getDaoClasses()).isNotEmpty();
   }
 }
diff --git a/sonar-db/src/test/java/org/sonar/db/DatabaseCheckerTest.java b/sonar-db/src/test/java/org/sonar/db/DatabaseCheckerTest.java
new file mode 100644 (file)
index 0000000..2902ac1
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * 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.sql.SQLException;
+import org.apache.commons.lang.StringUtils;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.sonar.api.utils.MessageException;
+import org.sonar.db.dialect.Dialect;
+import org.sonar.db.dialect.H2;
+import org.sonar.db.dialect.MySql;
+import org.sonar.db.dialect.Oracle;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class DatabaseCheckerTest {
+
+  @Test
+  public void requires_oracle_driver_11_2() throws Exception {
+    Database db = mockDb(new Oracle(), "11.2.1", "11.2.0.0.1");
+    new DatabaseChecker(db).start();
+    // no error
+
+    db = mockDb(new Oracle(), "11.2.1", "11.3.1");
+    new DatabaseChecker(db).start();
+    // no error
+
+    db = mockDb(new Oracle(), "11.2.1", "12.0.2");
+    new DatabaseChecker(db).start();
+    // no error
+
+    db = mockDb(new Oracle(), "11.2.1", "11.1.0.2");
+    try {
+      new DatabaseChecker(db).start();
+      fail();
+    } catch (MessageException e) {
+      assertThat(e).hasMessage("Unsupported Oracle JDBC driver version: 11.1.0.2. Minimal required version is 11.2.");
+    }
+  }
+
+  @Test
+  public void requires_oracle_11g_or_greater() throws Exception {
+    // oracle 11.0 is ok
+    Database db = mockDb(new Oracle(), "11.0.1", "11.2.0.0.1");
+    new DatabaseChecker(db).start();
+
+    // oracle 11.1 is ok
+    db = mockDb(new Oracle(), "11.1.1", "11.2.0.0.1");
+    new DatabaseChecker(db).start();
+
+    // oracle 11.2 is ok
+    db = mockDb(new Oracle(), "11.2.1", "11.2.0.0.1");
+    new DatabaseChecker(db).start();
+
+    // oracle 12 is ok
+    db = mockDb(new Oracle(), "12.0.1", "11.2.0.0.1");
+    new DatabaseChecker(db).start();
+
+    // oracle 10 is not supported
+    db = mockDb(new Oracle(), "10.2.1", "11.2.0.0.1");
+    try {
+      new DatabaseChecker(db).start();
+      fail();
+    } catch (MessageException e) {
+      assertThat(e).hasMessage("Unsupported Oracle version: 10.2.1. Minimal required version is 11.");
+    }
+  }
+
+  @Test
+  public void log_warning_if_h2() throws Exception {
+    Database db = mockDb(new H2(), "13.4", "13.4");
+    DatabaseChecker checker = new DatabaseChecker(db);
+    checker.start();
+    checker.stop();
+    // TODO test log
+  }
+
+  @Test
+  public void do_not_fail_if_mysql() throws Exception {
+    Database db = mockDb(new MySql(), "5.7", "5.7");
+    new DatabaseChecker(db).start();
+    // no error
+  }
+
+  private Database mockDb(Dialect dialect, String dbVersion, String driverVersion) throws SQLException {
+    Database db = mock(Database.class, Mockito.RETURNS_DEEP_STUBS);
+    when(db.getDialect()).thenReturn(dialect);
+    when(db.getDataSource().getConnection().getMetaData().getDatabaseMajorVersion()).thenReturn(Integer.parseInt(StringUtils.substringBefore(dbVersion, ".")));
+    when(db.getDataSource().getConnection().getMetaData().getDatabaseProductVersion()).thenReturn(dbVersion);
+    when(db.getDataSource().getConnection().getMetaData().getDriverVersion()).thenReturn(driverVersion);
+    return db;
+  }
+}
index 933e931ac035227242a29ced1bd660c2d8925ee0..1b6acbb3eb25d2d5e3ff3e5dba698c93f3b3c25a 100644 (file)
  */
 package org.sonar.db;
 
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.util.Collections;
+import java.util.List;
 import org.junit.Test;
 import org.sonar.db.dialect.Oracle;
 
+import static com.google.common.collect.Lists.newArrayList;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
@@ -142,4 +148,49 @@ public class DatabaseUtilsTest extends AbstractDaoTestCase {
     }
     return sql;
   }
+
+  @Test
+  public void repeatCondition() {
+    assertThat(DatabaseUtils.repeatCondition("uuid=?", 1, "or")).isEqualTo("uuid=?");
+    assertThat(DatabaseUtils.repeatCondition("uuid=?", 3, "or")).isEqualTo("uuid=? or uuid=? or uuid=?");
+  }
+
+  @Test
+  public void execute_large_inputs() {
+    List<Integer> inputs = newArrayList();
+    List<String> expectedOutputs = newArrayList();
+    for (int i = 0; i < 2010; i++) {
+      inputs.add(i);
+      expectedOutputs.add(Integer.toString(i));
+    }
+
+    List<String> outputs = DatabaseUtils.executeLargeInputs(inputs, new Function<List<Integer>, List<String>>() {
+      @Override
+      public List<String> apply(List<Integer> input) {
+        // Check that each partition is only done on 1000 elements max
+        assertThat(input.size()).isLessThanOrEqualTo(1000);
+        return newArrayList(Iterables.transform(input, new Function<Integer, String>() {
+          @Override
+          public String apply(Integer input) {
+            return Integer.toString(input);
+          }
+        }));
+      }
+    });
+
+    assertThat(outputs).isEqualTo(expectedOutputs);
+  }
+
+  @Test
+  public void execute_large_inputs_on_empty_list() {
+    List<String> outputs = DatabaseUtils.executeLargeInputs(Collections.<Integer>emptyList(), new Function<List<Integer>, List<String>>() {
+      @Override
+      public List<String> apply(List<Integer> input) {
+        fail("No partition should be made on empty list");
+        return Collections.emptyList();
+      }
+    });
+
+    assertThat(outputs).isEmpty();
+  }
 }
index ba428c5cbe8dbf89701fd839252cbb83aa8c028a..dfa4e9cfef01fe70e1409e6ecab066ed5d6e76c2 100644 (file)
 package org.sonar.db;
 
 import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
-import java.io.File;
-import java.io.IOException;
 import java.io.InputStream;
 import java.math.BigDecimal;
-import java.net.HttpURLConnection;
-import java.net.URI;
-import java.net.URISyntaxException;
 import java.sql.Clob;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
@@ -36,19 +30,13 @@ import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.util.List;
 import java.util.Map;
-import java.util.Properties;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
-import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.dbutils.QueryRunner;
-import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
-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.assertion.DiffCollectingFailureHandler;
 import org.dbunit.assertion.Difference;
 import org.dbunit.database.DatabaseConfig;
@@ -61,13 +49,10 @@ 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.AssumptionViolatedException;
+import org.junit.After;
 import org.junit.rules.ExternalResource;
-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.Dialect;
+import org.picocontainer.containers.TransientPicoContainer;
+import org.sonar.api.utils.System2;
 
 import static com.google.common.collect.Lists.newArrayList;
 import static com.google.common.collect.Maps.newHashMap;
@@ -78,96 +63,77 @@ import static org.junit.Assert.fail;
  * This class should be call using @ClassRule in order to create the schema once (ft @Rule is used
  * the schema will be recreated before each test).
  * Data will be truncated each time you call prepareDbUnit().
- * <p/>
+ * <p>
  * File using {@link DbTester} must be annotated with {@link org.sonar.test.DbTests} so
  * that they can be executed on all supported DBs (Oracle, MySQL, ...).
  */
 public class DbTester extends ExternalResource {
 
-  private static final Logger LOG = LoggerFactory.getLogger(DbTester.class);
+  private final System2 system2;
+  private final TestDb db;
+  private DbClient2 client;
+  private DbSession session = null;
 
-  private Database db;
-  private DatabaseCommands commands;
-  private IDatabaseTester tester;
-  private MyBatis myBatis;
-  private String schemaPath = null;
-
-  public DbTester schema(Class baseClass, String filename) {
-    String path = StringUtils.replaceChars(baseClass.getCanonicalName(), '.', '/');
-    schemaPath = path + "/" + filename;
-    return this;
+  @Deprecated
+  public DbTester() {
+    this.system2 = System2.INSTANCE;
+    this.db = TestDb.create(null);
   }
 
-  @Override
-  protected void before() throws Throwable {
-    Settings settings = new Settings().setProperties(Maps.fromProperties(System.getProperties()));
-    if (settings.hasKey("orchestrator.configUrl")) {
-      loadOrchestratorSettings(settings);
-    }
-    String login = settings.getString("sonar.jdbc.username");
-    for (String key : settings.getKeysStartingWith("sonar.jdbc")) {
-      LOG.info(key + ": " + settings.getString(key));
-    }
-    String dialect = settings.getString("sonar.jdbc.dialect");
-    if (dialect != null && !"h2".equals(dialect)) {
-      db = new DefaultDatabase(settings);
-    } else {
-      db = new H2Database("h2Tests" + DigestUtils.md5Hex(StringUtils.defaultString(schemaPath)), schemaPath == null);
-    }
-    db.start();
-    if (schemaPath != null) {
-      // will fail if not H2
-      if (db.getDialect().getId().equals("h2")) {
-        ((H2Database) db).executeScript(schemaPath);
-      } else {
-        db.stop();
-        throw new AssumptionViolatedException("Test disabled because it supports only H2");
-      }
-    }
-    LOG.info("Test Database: " + db);
-
-    commands = DatabaseCommands.forDialect(db.getDialect());
-    tester = new DataSourceDatabaseTester(db.getDataSource(), commands.useLoginAsSchema() ? login : null);
-
-    myBatis = new MyBatis(db, new NullQueue());
-    myBatis.start();
+  private DbTester(System2 system2, @Nullable String schemaPath) {
+    this.system2 = system2;
+    this.db = TestDb.create(schemaPath);
+  }
 
-    truncateTables();
+  public static DbTester create(System2 system2) {
+    return new DbTester(system2, null);
   }
 
-  public void truncateTables() {
-    try {
-      commands.truncateDatabase(db.getDataSource());
-    } catch (SQLException e) {
-      throw new IllegalStateException("Fail to truncate db tables", e);
-    }
+  public static DbTester createForSchema(System2 system2, Class testClass, String filename) {
+    String path = StringUtils.replaceChars(testClass.getCanonicalName(), '.', '/');
+    String schemaPath = path + "/" + filename;
+    return new DbTester(system2, schemaPath);
   }
 
   @Override
-  protected void after() {
-    db.stop();
-    db = null;
-    myBatis = null;
+  protected void before() throws Throwable {
+    truncateTables();
   }
 
-  public Database database() {
-    return db;
+  @After
+  public void closeSession() throws Exception {
+    if (session != null) {
+      MyBatis.closeQuietly(session);
+    }
   }
 
-  public Dialect dialect() {
-    return db.getDialect();
+  public DbSession getSession() {
+    if (session == null) {
+      session = db.getMyBatis().openSession(false);
+    }
+    return session;
   }
 
-  public MyBatis myBatis() {
-    return myBatis;
+  public void truncateTables() {
+    db.truncateTables();
   }
 
-  public Connection openConnection() throws SQLException {
-    return db.getDataSource().getConnection();
+  public DbClient2 getDbClient() {
+    if (client == null) {
+      TransientPicoContainer ioc = new TransientPicoContainer();
+      ioc.addComponent(db.getMyBatis());
+      ioc.addComponent(system2);
+      for (Class daoClass : DaoUtils.getDaoClasses()) {
+        ioc.addComponent(daoClass);
+      }
+      List<Dao> daos = ioc.getComponents(Dao.class);
+      client = new DbClient2(db.getMyBatis(), daos.toArray(new Dao[daos.size()]));
+    }
+    return client;
   }
 
   public void executeUpdateSql(String sql) {
-    try (Connection connection = openConnection()) {
+    try (Connection connection = db.getDatabase().getDataSource().getConnection()) {
       new QueryRunner().update(connection, sql);
     } catch (Exception e) {
       throw new IllegalStateException("Fail to execute sql: " + sql);
@@ -191,7 +157,7 @@ public class DbTester extends ExternalResource {
     Preconditions.checkArgument(StringUtils.contains(sql, "count("),
       "Parameter must be a SQL request containing 'count(x)' function. Got " + sql);
     try (
-      Connection connection = openConnection();
+      Connection connection = db.getDatabase().getDataSource().getConnection();
       PreparedStatement stmt = connection.prepareStatement(sql);
       ResultSet rs = stmt.executeQuery()) {
       if (rs.next()) {
@@ -206,7 +172,7 @@ public class DbTester extends ExternalResource {
 
   public List<Map<String, Object>> select(String selectSql) {
     try (
-      Connection connection = openConnection();
+      Connection connection = db.getDatabase().getDataSource().getConnection();
       PreparedStatement stmt = connection.prepareStatement(selectSql);
       ResultSet rs = stmt.executeQuery()) {
       return getHashMap(rs);
@@ -259,8 +225,7 @@ public class DbTester extends ExternalResource {
   public void prepareDbUnit(Class testClass, String... testNames) {
     InputStream[] streams = new InputStream[testNames.length];
     try {
-      // Purge previous data
-      commands.truncateDatabase(db.getDataSource());
+      db.truncateTables();
 
       for (int i = 0; i < testNames.length; i++) {
         String path = "/" + testClass.getName().replace('.', '/') + "/" + testNames[i];
@@ -271,7 +236,7 @@ public class DbTester extends ExternalResource {
       }
 
       prepareDbUnit(streams);
-      commands.resetPrimaryKeys(db.getDataSource());
+      db.getCommands().resetPrimaryKeys(db.getDatabase().getDataSource());
     } catch (SQLException e) {
       throw translateException("Could not setup DBUnit data", e);
     } finally {
@@ -288,9 +253,9 @@ public class DbTester extends ExternalResource {
       for (int i = 0; i < dataSetStream.length; i++) {
         dataSets[i] = dbUnitDataSet(dataSetStream[i]);
       }
-      tester.setDataSet(new CompositeDataSet(dataSets));
+      db.getDbUnitTester().setDataSet(new CompositeDataSet(dataSets));
       connection = dbUnitConnection();
-      new InsertIdentityOperation(DatabaseOperation.INSERT).execute(connection, tester.getDataSet());
+      new InsertIdentityOperation(DatabaseOperation.INSERT).execute(connection, db.getDbUnitTester().getDataSet());
     } catch (Exception e) {
       throw translateException("Could not setup DBUnit data", e);
     } finally {
@@ -339,7 +304,7 @@ public class DbTester extends ExternalResource {
   }
 
   public void assertColumnDefinition(String table, String column, int expectedType, @Nullable Integer expectedSize) {
-    try (Connection connection = openConnection();
+    try (Connection connection = db.getDatabase().getDataSource().getConnection();
       PreparedStatement stmt = connection.prepareStatement("select * from " + table);
       ResultSet res = stmt.executeQuery()) {
       Integer columnIndex = getColumnIndex(res, column);
@@ -389,8 +354,8 @@ public class DbTester extends ExternalResource {
 
   private IDatabaseConnection dbUnitConnection() {
     try {
-      IDatabaseConnection connection = tester.getConnection();
-      connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, commands.getDbUnitFactory());
+      IDatabaseConnection connection = db.getDbUnitTester().getConnection();
+      connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, db.getDbUnitFactory());
       return connection;
     } catch (Exception e) {
       throw translateException("Error while getting connection", e);
@@ -413,36 +378,6 @@ public class DbTester extends ExternalResource {
     return runtimeException;
   }
 
-  private 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 void doClobFree(Clob clob) throws SQLException {
     try {
       clob.free();
@@ -450,4 +385,19 @@ public class DbTester extends ExternalResource {
       // JTS driver do not implement free() as it's using JDBC 3.0
     }
   }
+
+  @Deprecated
+  public MyBatis myBatis() {
+    return db.getMyBatis();
+  }
+
+  @Deprecated
+  public Connection openConnection() throws Exception {
+    return db.getDatabase().getDataSource().getConnection();
+  }
+
+  @Deprecated
+  public Database database() {
+    return db.getDatabase();
+  }
 }
index 194346fe0a0dacad616234c04d68b00bb7b87044..87922b13fafa3f68562b462268619b97c88cbe6e 100644 (file)
@@ -63,7 +63,7 @@ public class MyBatisTest {
     MyBatis myBatis = new MyBatis(database, queue);
     myBatis.start();
 
-    SqlSession session = myBatis.openBatchSession();
+    SqlSession session = myBatis.openSession(false);
     try {
       assertThat(session.getConnection(), notNullValue());
       assertThat(session.getMapper(RuleMapper.class), notNullValue());
diff --git a/sonar-db/src/test/java/org/sonar/db/ResultSetIteratorTest.java b/sonar-db/src/test/java/org/sonar/db/ResultSetIteratorTest.java
new file mode 100644 (file)
index 0000000..970f909
--- /dev/null
@@ -0,0 +1,176 @@
+/*
+ * 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.sql.Connection;
+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;
+import org.sonar.api.utils.System2;
+import org.sonar.test.DbTests;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.fail;
+
+@Category(DbTests.class)
+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);
+
+    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);
+
+    // call next() without calling hasNext()
+    assertThat(iterator.next()).isEqualTo(30);
+    assertThat(iterator.hasNext()).isFalse();
+
+    try {
+      iterator.next();
+      fail();
+    } catch (NoSuchElementException e) {
+      // ok
+    }
+
+    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);
+
+    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);
+
+    assertThat(iterator.next()).isEqualTo(10);
+    assertThat(iterator.next()).isEqualTo(20);
+    assertThat(iterator.next()).isEqualTo(30);
+
+    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
+    }
+
+    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);
+    }
+    iterator.close();
+  }
+
+  private static class FirstIntColumnIterator extends ResultSetIterator<Integer> {
+
+    public FirstIntColumnIterator(PreparedStatement stmt) throws SQLException {
+      super(stmt);
+    }
+
+    public FirstIntColumnIterator(ResultSet rs) {
+      super(rs);
+    }
+
+    @Override
+    protected Integer read(ResultSet rs) throws SQLException {
+      return rs.getInt(1);
+    }
+  }
+
+  private static class FailIterator extends ResultSetIterator<Integer> {
+
+    public FailIterator(PreparedStatement stmt) throws SQLException {
+      super(stmt);
+    }
+
+    @Override
+    protected Integer read(ResultSet rs) throws SQLException {
+      // column does not exist
+      return rs.getInt(1234);
+    }
+  }
+}
diff --git a/sonar-db/src/test/java/org/sonar/db/TestDb.java b/sonar-db/src/test/java/org/sonar/db/TestDb.java
new file mode 100644 (file)
index 0000000..715ea17
--- /dev/null
@@ -0,0 +1,175 @@
+/*
+ * 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 com.google.common.collect.Maps;
+import java.io.File;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URI;
+import java.sql.SQLException;
+import java.util.Map;
+import java.util.Properties;
+import javax.annotation.Nullable;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.text.StrSubstitutor;
+import org.dbunit.DataSourceDatabaseTester;
+import org.dbunit.IDatabaseTester;
+import org.dbunit.dataset.datatype.IDataTypeFactory;
+import org.junit.AssumptionViolatedException;
+import org.sonar.api.config.Settings;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.db.deprecated.NullQueue;
+
+/**
+ * This class should be call using @ClassRule in order to create the schema once (ft @Rule is used
+ * the schema will be recreated before each test).
+ * Data will be truncated each time you call prepareDbUnit().
+ * <p/>
+ * File using {@link TestDb} must be annotated with {@link org.sonar.test.DbTests} so
+ * that they can be executed on all supported DBs (Oracle, MySQL, ...).
+ */
+class TestDb {
+
+  private static TestDb DEFAULT;
+
+  private static final Logger LOG = Loggers.get(TestDb.class);
+
+  private Database db;
+  private DatabaseCommands commands;
+  private IDatabaseTester tester;
+  private MyBatis myBatis;
+
+  private TestDb(@Nullable String schemaPath) {
+    if (db == null) {
+      Settings settings = new Settings().setProperties(Maps.fromProperties(System.getProperties()));
+      if (settings.hasKey("orchestrator.configUrl")) {
+        loadOrchestratorSettings(settings);
+      }
+      String login = settings.getString("sonar.jdbc.username");
+      for (String key : settings.getKeysStartingWith("sonar.jdbc")) {
+        LOG.info(key + ": " + settings.getString(key));
+      }
+      String dialect = settings.getString("sonar.jdbc.dialect");
+      if (dialect != null && !"h2".equals(dialect)) {
+        db = new DefaultDatabase(settings);
+      } else {
+        db = new H2Database("h2Tests" + DigestUtils.md5Hex(StringUtils.defaultString(schemaPath)), schemaPath == null);
+      }
+      db.start();
+      if (schemaPath != null) {
+        // will fail if not H2
+        if (db.getDialect().getId().equals("h2")) {
+          ((H2Database) db).executeScript(schemaPath);
+        } else {
+          db.stop();
+          throw new AssumptionViolatedException("Test disabled because it supports only H2");
+        }
+      }
+      LOG.info("Test Database: " + db);
+
+      commands = DatabaseCommands.forDialect(db.getDialect());
+      tester = new DataSourceDatabaseTester(db.getDataSource(), commands.useLoginAsSchema() ? login : null);
+
+      myBatis = new MyBatis(db, new NullQueue());
+      myBatis.start();
+    }
+  }
+
+  void truncateTables() {
+    try {
+      commands.truncateDatabase(db.getDataSource());
+    } catch (SQLException e) {
+      throw new IllegalStateException("Fail to truncate db tables", e);
+    }
+  }
+
+  static TestDb create(@Nullable String schemaPath) {
+    if (schemaPath == null) {
+      if (DEFAULT == null) {
+        DEFAULT = new TestDb(null);
+      }
+      return DEFAULT;
+    }
+    return new TestDb(schemaPath);
+  }
+
+  void stop() {
+    db.stop();
+    db = null;
+    myBatis = null;
+  }
+
+  Database getDatabase() {
+    return db;
+  }
+
+  DatabaseCommands getCommands() {
+    return commands;
+  }
+
+  MyBatis getMyBatis() {
+    return myBatis;
+  }
+
+  IDatabaseTester getDbUnitTester() {
+    return tester;
+  }
+
+  IDataTypeFactory getDbUnitFactory() {
+    return commands.getDbUnitFactory();
+  }
+
+  private void loadOrchestratorSettings(Settings settings) {
+    String url = settings.getString("orchestrator.configUrl");
+    InputStream input = null;
+    try {
+      URI uri = new URI(url);
+      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);
+      }
+    } catch (Exception e) {
+      throw new IllegalStateException(e);
+    } finally {
+      IOUtils.closeQuietly(input);
+    }
+  }
+}
diff --git a/sonar-db/src/test/java/org/sonar/db/activity/ActivityDaoTest.java b/sonar-db/src/test/java/org/sonar/db/activity/ActivityDaoTest.java
new file mode 100644 (file)
index 0000000..c2135f6
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 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.activity;
+
+import java.util.Map;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.sonar.api.utils.System2;
+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;
+
+@Category(DbTests.class)
+public class ActivityDaoTest {
+
+  System2 system = mock(System2.class);
+
+  @Rule
+  public DbTester dbTester = DbTester.create(system);
+
+  ActivityDao sut = dbTester.getDbClient().activityDao();
+
+  @Test
+  public void insert() {
+    when(system.now()).thenReturn(1_500_000_000_000L);
+    ActivityDto dto = new ActivityDto()
+      .setKey("UUID_1").setAction("THE_ACTION").setType("THE_TYPE")
+      .setAuthor("THE_AUTHOR").setData("THE_DATA");
+    sut.insert(dto);
+
+    Map<String, Object> map = dbTester.selectFirst("select created_at as \"createdAt\", log_action as \"action\", data_field as \"data\" from activities where log_key='UUID_1'");
+    assertThat(map.get("action")).isEqualTo("THE_ACTION");
+    // not possible to check exact date yet. dbTester#selectFirst() uses ResultSet#getObject(), which returns
+    // non-JDBC interface in Oracle driver.
+    assertThat(map.get("createdAt")).isNotNull();
+    assertThat(map.get("data")).isEqualTo("THE_DATA");
+  }
+}
diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentLinkDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentLinkDaoTest.java
new file mode 100644 (file)
index 0000000..931d4f0
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * 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.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.test.DbTests;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@Category(DbTests.class)
+public class ComponentLinkDaoTest {
+
+  @ClassRule
+  public static DbTester dbTester = DbTester.create(System2.INSTANCE);
+
+  ComponentLinkDao dao = dbTester.getDbClient().componentLinkDao();
+
+  @Test
+  public void select_by_component_uuid() {
+    dbTester.prepareDbUnit(getClass(), "shared.xml");
+
+    List<ComponentLinkDto> links = dao.selectByComponentUuid(dbTester.getSession(), "ABCD");
+    assertThat(links).hasSize(2);
+
+    links = dao.selectByComponentUuid(dbTester.getSession(), "BCDE");
+    assertThat(links).hasSize(1);
+
+    ComponentLinkDto link = links.get(0);
+    assertThat(link.getId()).isEqualTo(3L);
+    assertThat(link.getComponentUuid()).isEqualTo("BCDE");
+    assertThat(link.getType()).isEqualTo("homepage");
+    assertThat(link.getName()).isEqualTo("Home");
+    assertThat(link.getHref()).isEqualTo("http://www.struts.org");
+  }
+
+  @Test
+  public void insert() {
+    dbTester.prepareDbUnit(getClass(), "empty.xml");
+
+    dao.insert(dbTester.getSession(), new ComponentLinkDto()
+      .setComponentUuid("ABCD")
+      .setType("homepage")
+      .setName("Home")
+      .setHref("http://www.sonarqube.org")
+      );
+    dbTester.getSession().commit();
+
+    dbTester.assertDbUnit(getClass(), "insert-result.xml", new String[] {"id"}, "project_links");
+  }
+
+  @Test
+  public void update() {
+    dbTester.prepareDbUnit(getClass(), "update.xml");
+
+    dao.update(dbTester.getSession(), new ComponentLinkDto()
+      .setId(1L)
+      .setComponentUuid("ABCD")
+      .setType("homepage")
+      .setName("Home")
+      .setHref("http://www.sonarqube.org")
+      );
+    dbTester.getSession().commit();
+
+    dbTester.assertDbUnit(getClass(), "update-result.xml", "project_links");
+  }
+
+  @Test
+  public void delete() {
+    dbTester.prepareDbUnit(getClass(), "delete.xml");
+
+    dao.delete(dbTester.getSession(), 1L);
+    dbTester.getSession().commit();
+
+    assertThat(dbTester.countRowsOfTable("project_links")).isEqualTo(0);
+  }
+
+}
index 90329d5842b358373bf630d32eb81139ee0d9e50..deb992be365896b39ea5124a01f37854bf9255f1 100644 (file)
@@ -22,14 +22,15 @@ package org.sonar.db.component;
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;
-import org.hamcrest.core.Is;
 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.hamcrest.Matchers.greaterThan;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
 
 public class ResourceIndexerDaoTest extends AbstractDaoTestCase {
 
@@ -37,7 +38,7 @@ public class ResourceIndexerDaoTest extends AbstractDaoTestCase {
 
   @Before
   public void createDao() {
-    dao = new ResourceIndexerDao(getMyBatis());
+    dao = new ResourceIndexerDao(getMyBatis(), mock(System2.class));
   }
 
   @Test
@@ -88,17 +89,17 @@ public class ResourceIndexerDaoTest extends AbstractDaoTestCase {
       // project
       rs = connection.createStatement().executeQuery("select count(resource_id) from resource_index where resource_id=1");
       rs.next();
-      assertThat(rs.getInt(1), greaterThan(0));
+      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), Is.is(0));
+      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), greaterThan(0));
+      assertThat(rs.getInt(1)).isGreaterThan(0);
     } finally {
       if (null != rs) {
         rs.close();
@@ -150,4 +151,16 @@ public class ResourceIndexerDaoTest extends AbstractDaoTestCase {
 
     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();
+  }
 }
diff --git a/sonar-db/src/test/java/org/sonar/db/component/SnapshotDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/SnapshotDaoTest.java
new file mode 100644 (file)
index 0000000..21ec3e3
--- /dev/null
@@ -0,0 +1,305 @@
+/*
+ * 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.Date;
+import java.util.List;
+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.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.test.DbTests;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.db.component.SnapshotQuery.SORT_FIELD.BY_DATE;
+import static org.sonar.db.component.SnapshotQuery.SORT_ORDER.ASC;
+import static org.sonar.db.component.SnapshotQuery.SORT_ORDER.DESC;
+
+@Category(DbTests.class)
+public class SnapshotDaoTest {
+
+  @ClassRule
+  public static DbTester db = new DbTester();
+
+  DbSession session;
+
+  SnapshotDao sut;
+
+  @Before
+  public void createDao() {
+    session = db.myBatis().openSession(false);
+    sut = new SnapshotDao();
+  }
+
+  @After
+  public void tearDown() {
+    session.close();
+  }
+
+  @Test
+  public void get_by_key() {
+    db.prepareDbUnit(getClass(), "shared.xml");
+
+    SnapshotDto result = sut.selectNullableById(session, 3L);
+    assertThat(result).isNotNull();
+    assertThat(result.getId()).isEqualTo(3L);
+    assertThat(result.getComponentId()).isEqualTo(3L);
+    assertThat(result.getRootProjectId()).isEqualTo(1L);
+    assertThat(result.getParentId()).isEqualTo(2L);
+    assertThat(result.getRootId()).isEqualTo(1L);
+    assertThat(result.getStatus()).isEqualTo("P");
+    assertThat(result.getLast()).isTrue();
+    assertThat(result.getPurgeStatus()).isEqualTo(1);
+    assertThat(result.getDepth()).isEqualTo(1);
+    assertThat(result.getScope()).isEqualTo("DIR");
+    assertThat(result.getQualifier()).isEqualTo("PAC");
+    assertThat(result.getVersion()).isEqualTo("2.1-SNAPSHOT");
+    assertThat(result.getPath()).isEqualTo("1.2.");
+
+    assertThat(result.getPeriodMode(1)).isEqualTo("days1");
+    assertThat(result.getPeriodModeParameter(1)).isEqualTo("30");
+    assertThat(result.getPeriodDate(1)).isEqualTo(1316815200000L);
+    assertThat(result.getPeriodMode(2)).isEqualTo("days2");
+    assertThat(result.getPeriodModeParameter(2)).isEqualTo("31");
+    assertThat(result.getPeriodDate(2)).isEqualTo(1316901600000L);
+    assertThat(result.getPeriodMode(3)).isEqualTo("days3");
+    assertThat(result.getPeriodModeParameter(3)).isEqualTo("32");
+    assertThat(result.getPeriodDate(3)).isEqualTo(1316988000000L);
+    assertThat(result.getPeriodMode(4)).isEqualTo("days4");
+    assertThat(result.getPeriodModeParameter(4)).isEqualTo("33");
+    assertThat(result.getPeriodDate(4)).isEqualTo(1317074400000L);
+    assertThat(result.getPeriodMode(5)).isEqualTo("days5");
+    assertThat(result.getPeriodModeParameter(5)).isEqualTo("34");
+    assertThat(result.getPeriodDate(5)).isEqualTo(1317160800000L);
+
+    assertThat(result.getCreatedAt()).isEqualTo(1228172400000L);
+    assertThat(result.getBuildDate()).isEqualTo(1317247200000L);
+
+    assertThat(sut.selectNullableById(session, 999L)).isNull();
+  }
+
+  @Test
+  public void lastSnapshot_returns_null_when_no_last_snapshot() {
+    SnapshotDto snapshot = sut.selectLastSnapshotByComponentId(session, 123L);
+
+    assertThat(snapshot).isNull();
+  }
+
+  @Test
+  public void lastSnapshot_from_one_resource() {
+    db.prepareDbUnit(getClass(), "snapshots.xml");
+
+    SnapshotDto snapshot = sut.selectLastSnapshotByComponentId(session, 2L);
+
+    assertThat(snapshot).isNotNull();
+    assertThat(snapshot.getId()).isEqualTo(4L);
+  }
+
+  @Test
+  public void lastSnapshot_from_one_resource_without_last_is_null() {
+    db.prepareDbUnit(getClass(), "snapshots.xml");
+
+    SnapshotDto snapshot = sut.selectLastSnapshotByComponentId(session, 5L);
+
+    assertThat(snapshot).isNull();
+  }
+
+  @Test
+  public void snapshot_and_child_retrieved() {
+    db.prepareDbUnit(getClass(), "snapshots.xml");
+
+    List<SnapshotDto> snapshots = sut.selectSnapshotAndChildrenOfProjectScope(session, 1L);
+
+    assertThat(snapshots).isNotEmpty();
+    assertThat(snapshots).extracting("id").containsOnly(1L, 6L);
+  }
+
+  @Test
+  public void select_snapshots_by_component_id() {
+    db.prepareDbUnit(getClass(), "snapshots.xml");
+
+    List<SnapshotDto> snapshots = sut.selectSnapshotsByComponentId(session, 1L);
+
+    assertThat(snapshots).hasSize(3);
+  }
+
+  @Test
+  public void select_snapshots_by_query() {
+    db.prepareDbUnit(getClass(), "select_snapshots_by_query.xml");
+
+    assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery())).hasSize(6);
+
+    assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L))).hasSize(3);
+
+    assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setVersion("2.2-SNAPSHOT"))).extracting("id").containsOnly(3L);
+
+    assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setIsLast(true))).extracting("id").containsOnly(1L);
+    assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setIsLast(false))).extracting("id").containsOnly(2L, 3L);
+
+    assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setCreatedAfter(1228172400002L))).extracting("id").containsOnly(2L, 3L);
+    assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setCreatedBefore(1228172400002L))).extracting("id").containsOnly(1L);
+
+    assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(2L).setStatus("P"))).hasSize(1);
+    assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(2L).setStatus("U"))).hasSize(1);
+
+    assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setSort(BY_DATE, ASC)).get(0).getId()).isEqualTo(1L);
+    assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setSort(BY_DATE, DESC)).get(0).getId()).isEqualTo(3L);
+  }
+
+  @Test
+  public void select_previous_version_snapshots() throws Exception {
+    db.prepareDbUnit(getClass(), "select_previous_version_snapshots.xml");
+
+    List<SnapshotDto> snapshots = sut.selectPreviousVersionSnapshots(session, 1L, "1.2-SNAPSHOT");
+    assertThat(snapshots).hasSize(2);
+
+    SnapshotDto firstSnapshot = snapshots.get(0);
+    assertThat(firstSnapshot.getVersion()).isEqualTo("1.1");
+
+    // All snapshots are returned on an unknown version
+    assertThat(sut.selectPreviousVersionSnapshots(session, 1L, "UNKNOWN")).hasSize(3);
+  }
+
+  @Test
+  public void insert() {
+    db.prepareDbUnit(getClass(), "empty.xml");
+
+    SnapshotDto dto = defaultSnapshot().setCreatedAt(1403042400000L);
+
+    sut.insert(session, dto);
+    session.commit();
+
+    assertThat(dto.getId()).isNotNull();
+    db.assertDbUnit(getClass(), "insert-result.xml", new String[] {"id"}, "snapshots");
+  }
+
+  @Test
+  public void insert_snapshots() {
+    db.prepareDbUnit(getClass(), "empty.xml");
+
+    sut.insert(session,
+      new SnapshotDto().setComponentId(1L).setLast(false),
+      new SnapshotDto().setComponentId(2L).setLast(false));
+    session.commit();
+
+    assertThat(db.countRowsOfTable("snapshots")).isEqualTo(2);
+  }
+
+  @Test
+  public void set_snapshot_and_children_to_false_and_status_processed() {
+    db.prepareDbUnit(getClass(), "snapshots.xml");
+    SnapshotDto snapshot = defaultSnapshot().setId(1L);
+
+    sut.updateSnapshotAndChildrenLastFlagAndStatus(session, snapshot, false, SnapshotDto.STATUS_PROCESSED);
+    session.commit();
+
+    List<SnapshotDto> snapshots = sut.selectSnapshotAndChildrenOfProjectScope(session, 1L);
+    assertThat(snapshots).hasSize(2);
+    assertThat(snapshots).extracting("id").containsOnly(1L, 6L);
+    assertThat(snapshots).extracting("last").containsOnly(false);
+    assertThat(snapshots).extracting("status").containsOnly(SnapshotDto.STATUS_PROCESSED);
+  }
+
+  @Test
+  public void set_snapshot_and_children_isLast_flag_to_false() {
+    db.prepareDbUnit(getClass(), "snapshots.xml");
+    SnapshotDto snapshot = defaultSnapshot().setId(1L);
+
+    sut.updateSnapshotAndChildrenLastFlag(session, snapshot, false);
+    session.commit();
+
+    List<SnapshotDto> snapshots = sut.selectSnapshotAndChildrenOfProjectScope(session, 1L);
+    assertThat(snapshots).hasSize(2);
+    assertThat(snapshots).extracting("id").containsOnly(1L, 6L);
+    assertThat(snapshots).extracting("last").containsOnly(false);
+  }
+
+  @Test
+  public void is_last_snapshot_when_no_previous_snapshot() {
+    SnapshotDto snapshot = defaultSnapshot();
+
+    boolean isLast = SnapshotDao.isLast(snapshot, null);
+
+    assertThat(isLast).isTrue();
+  }
+
+  @Test
+  public void is_last_snapshot_when_previous_snapshot_is_older() {
+    Date today = new Date();
+    Date yesterday = DateUtils.addDays(today, -1);
+
+    SnapshotDto snapshot = defaultSnapshot().setCreatedAt(today.getTime());
+    SnapshotDto previousLastSnapshot = defaultSnapshot().setCreatedAt(yesterday.getTime());
+
+    boolean isLast = SnapshotDao.isLast(snapshot, previousLastSnapshot);
+
+    assertThat(isLast).isTrue();
+  }
+
+  @Test
+  public void is_not_last_snapshot_when_previous_snapshot_is_newer() {
+    Date today = new Date();
+    Date yesterday = DateUtils.addDays(today, -1);
+
+    SnapshotDto snapshot = defaultSnapshot().setCreatedAt(yesterday.getTime());
+    SnapshotDto previousLastSnapshot = defaultSnapshot().setCreatedAt(today.getTime());
+
+    boolean isLast = SnapshotDao.isLast(snapshot, previousLastSnapshot);
+
+    assertThat(isLast).isFalse();
+  }
+
+  private static SnapshotDto defaultSnapshot() {
+    return new SnapshotDto()
+      .setComponentId(3L)
+      .setRootProjectId(1L)
+      .setParentId(2L)
+      .setRootId(1L)
+      .setStatus("P")
+      .setLast(true)
+      .setPurgeStatus(1)
+      .setDepth(1)
+      .setScope("DIR")
+      .setQualifier("PAC")
+      .setVersion("2.1-SNAPSHOT")
+      .setPath("1.2.")
+      .setPeriodMode(1, "days1")
+      .setPeriodMode(2, "days2")
+      .setPeriodMode(3, "days3")
+      .setPeriodMode(4, "days4")
+      .setPeriodMode(5, "days5")
+      .setPeriodParam(1, "30")
+      .setPeriodParam(2, "31")
+      .setPeriodParam(3, "32")
+      .setPeriodParam(4, "33")
+      .setPeriodParam(5, "34")
+      .setPeriodDate(1, 1_500_000_000_001L)
+      .setPeriodDate(2, 1_500_000_000_002L)
+      .setPeriodDate(3, 1_500_000_000_003L)
+      .setPeriodDate(4, 1_500_000_000_004L)
+      .setPeriodDate(5, 1_500_000_000_005L)
+      .setBuildDate(1_500_000_000_006L);
+  }
+}
diff --git a/sonar-db/src/test/java/org/sonar/db/compute/AnalysisReportDaoTest.java b/sonar-db/src/test/java/org/sonar/db/compute/AnalysisReportDaoTest.java
new file mode 100644 (file)
index 0000000..17bb668
--- /dev/null
@@ -0,0 +1,212 @@
+/*
+ * 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.compute;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
+import org.sonar.api.utils.System2;
+import org.sonar.db.compute.AnalysisReportDao;
+import org.sonar.db.compute.AnalysisReportDto;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.MyBatis;
+import org.sonar.test.DbTests;
+
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.sonar.db.compute.AnalysisReportDto.Status.PENDING;
+import static org.sonar.db.compute.AnalysisReportDto.Status.WORKING;
+
+@Category(DbTests.class)
+public class AnalysisReportDaoTest {
+
+  private static final String DEFAULT_PROJECT_KEY = "123456789-987654321";
+
+  @ClassRule
+  public static DbTester db = new DbTester();
+
+  @Rule
+  public TemporaryFolder temp = new TemporaryFolder();
+
+  AnalysisReportDao sut;
+  DbSession session;
+  System2 system2;
+
+  @Before
+  public void before() {
+    this.session = db.myBatis().openSession(false);
+    this.system2 = mock(System2.class);
+    this.sut = new AnalysisReportDao(system2);
+
+    when(system2.now()).thenReturn(1_500_000_000_000L);
+  }
+
+  @After
+  public void after() {
+    MyBatis.closeQuietly(session);
+  }
+
+  @Test
+  public void insert_multiple_reports() {
+    db.prepareDbUnit(getClass(), "empty.xml");
+
+    AnalysisReportDto report1 = new AnalysisReportDto().setProjectKey("ProjectKey1").setProjectName("Project 1").setUuid("UUID_1").setStatus(PENDING);
+    AnalysisReportDto report2 = new AnalysisReportDto().setProjectKey("ProjectKey2").setProjectName("Project 2").setUuid("UUID_2").setStatus(PENDING);
+
+    sut.insert(session, report1);
+    sut.insert(session, report2);
+    session.commit();
+
+    db.assertDbUnit(getClass(), "insert-result.xml", "analysis_reports");
+  }
+
+  @Test
+  public void resetAllToPendingStatus() {
+    db.prepareDbUnit(getClass(), "update-all-to-status-pending.xml");
+
+    sut.resetAllToPendingStatus(session);
+    session.commit();
+
+    db.assertDbUnit(getClass(), "update-all-to-status-pending-result.xml", "analysis_reports");
+  }
+
+  @Test
+  public void truncate() {
+    db.prepareDbUnit(getClass(), "any-analysis-reports.xml");
+
+    sut.truncate(session);
+    session.commit();
+
+    db.assertDbUnit(getClass(), "truncate-result.xml", "analysis_reports");
+  }
+
+  @Test
+  public void find_one_report_by_project_key() {
+    db.prepareDbUnit(getClass(), "select.xml");
+
+    final String projectKey = "123456789-987654321";
+    List<AnalysisReportDto> reports = sut.selectByProjectKey(session, projectKey);
+    AnalysisReportDto report = reports.get(0);
+
+    assertThat(reports).hasSize(1);
+    assertThat(report.getProjectKey()).isEqualTo(projectKey);
+    assertThat(report.getProjectName()).isEqualTo("Project 1");
+    assertThat(report.getStatus()).isEqualTo(AnalysisReportDto.Status.WORKING);
+    assertThat(report.getId()).isEqualTo(1);
+  }
+
+  @Test
+  public void find_several_reports_by_project_key() {
+    db.prepareDbUnit(getClass(), "select.xml");
+
+    final String projectKey = "987654321-123456789";
+    List<AnalysisReportDto> reports = sut.selectByProjectKey(session, projectKey);
+
+    assertThat(reports).hasSize(2);
+  }
+
+  @Test
+  public void pop_oldest_pending() {
+    db.prepareDbUnit(getClass(), "pop_oldest_pending.xml");
+
+    AnalysisReportDto nextAvailableReport = sut.pop(session);
+
+    assertThat(nextAvailableReport.getId()).isEqualTo(3);
+    assertThat(nextAvailableReport.getProjectKey()).isEqualTo("P2");
+  }
+
+  @Test
+  public void pop_null_if_no_pending_reports() {
+    db.prepareDbUnit(getClass(), "pop_null_if_no_pending_reports.xml");
+
+    AnalysisReportDto nextAvailableReport = sut.pop(session);
+
+    assertThat(nextAvailableReport).isNull();
+  }
+
+  @Test
+  public void getById_maps_all_the_fields_except_the_data() {
+    db.prepareDbUnit(getClass(), "one_analysis_report.xml");
+
+    AnalysisReportDto report = sut.selectById(session, 1L);
+
+    assertThat(report.getProjectKey()).isEqualTo(DEFAULT_PROJECT_KEY);
+    assertThat(report.getCreatedAt()).isEqualTo(1_500_000_000_001L);
+    assertThat(report.getUpdatedAt()).isEqualTo(1_500_000_000_002L);
+    assertThat(report.getStartedAt()).isEqualTo(1_500_000_000_003L);
+    assertThat(report.getFinishedAt()).isEqualTo(1_500_000_000_004L);
+    assertThat(report.getStatus()).isEqualTo(WORKING);
+  }
+
+  @Test
+  public void getById_returns_null_when_id_not_found() {
+    db.prepareDbUnit(getClass(), "select.xml");
+
+    AnalysisReportDto report = sut.selectById(session, 4L);
+
+    assertThat(report).isNull();
+  }
+
+  @Test
+  public void delete_one_analysis_report() {
+    db.prepareDbUnit(getClass(), "one_analysis_report.xml");
+
+    sut.delete(session, 1);
+    session.commit();
+
+    db.assertDbUnit(getClass(), "truncate-result.xml", "analysis_reports");
+  }
+
+  @Test
+  public void findAll_one_analysis_report() {
+    db.prepareDbUnit(getClass(), "one_analysis_report.xml");
+
+    List<AnalysisReportDto> reports = sut.selectAll(session);
+
+    assertThat(reports).hasSize(1);
+  }
+
+  @Test
+  public void findAll_empty_table() {
+    db.prepareDbUnit(getClass(), "empty.xml");
+
+    List<AnalysisReportDto> reports = sut.selectAll(session);
+
+    assertThat(reports).isEmpty();
+  }
+
+  @Test
+  public void findAll_three_analysis_reports() {
+    db.prepareDbUnit(getClass(), "three_analysis_reports.xml");
+
+    List<AnalysisReportDto> reports = sut.selectAll(session);
+
+    assertThat(reports).hasSize(3);
+  }
+}
diff --git a/sonar-db/src/test/java/org/sonar/db/dashboard/WidgetDaoTest.java b/sonar-db/src/test/java/org/sonar/db/dashboard/WidgetDaoTest.java
new file mode 100644 (file)
index 0000000..aa5afd5
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * 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.dashboard;
+
+import java.util.Collection;
+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.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.MyBatis;
+import org.sonar.test.DbTests;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@Category(DbTests.class)
+public class WidgetDaoTest {
+
+  WidgetDao dao;
+
+  @Rule
+  public DbTester dbTester = new DbTester();
+
+  private DbSession session;
+
+  @Before
+  public void setUp() {
+    dao = new WidgetDao(dbTester.myBatis());
+    session = dbTester.myBatis().openSession(false);
+  }
+
+  @After
+  public void tearDown() {
+    MyBatis.closeQuietly(session);
+  }
+
+  @Test
+  public void should_select_all() {
+    dbTester.prepareDbUnit(this.getClass(), "before.xml");
+    session.commit();
+
+    Collection<WidgetDto> widgets = dao.findAll(session);
+    assertThat(widgets).hasSize(5);
+    for (WidgetDto widget : widgets) {
+      assertThat(widget.getId()).isNotNull();
+      assertThat(widget.getName()).isNotNull();
+      assertThat(widget.getDescription()).isNotNull();
+    }
+  }
+}
diff --git a/sonar-db/src/test/java/org/sonar/db/event/EventDaoTest.java b/sonar-db/src/test/java/org/sonar/db/event/EventDaoTest.java
new file mode 100644 (file)
index 0000000..4915c0e
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * 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.event;
+
+import java.util.List;
+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.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.test.DbTests;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@Category(DbTests.class)
+public class EventDaoTest {
+
+  @ClassRule
+  public static DbTester dbTester = new DbTester();
+
+  DbSession session;
+
+  EventDao dao;
+
+  @Before
+  public void setup() {
+    dbTester.truncateTables();
+    session = dbTester.myBatis().openSession(false);
+    dao = new EventDao();
+  }
+
+  @After
+  public void tearDown() {
+    session.close();
+  }
+
+  @Test
+  public void select_by_component_uuid() {
+    dbTester.prepareDbUnit(getClass(), "shared.xml");
+
+    List<EventDto> dtos = dao.selectByComponentUuid(session, "ABCD");
+    assertThat(dtos).hasSize(3);
+
+    dtos = dao.selectByComponentUuid(session, "BCDE");
+    assertThat(dtos).hasSize(1);
+
+    EventDto dto = dtos.get(0);
+    assertThat(dto.getId()).isEqualTo(4L);
+    assertThat(dto.getComponentUuid()).isEqualTo("BCDE");
+    assertThat(dto.getSnapshotId()).isEqualTo(1000L);
+    assertThat(dto.getName()).isEqualTo("1.0");
+    assertThat(dto.getCategory()).isEqualTo("Version");
+    assertThat(dto.getDescription()).isEqualTo("Version 1.0");
+    assertThat(dto.getData()).isEqualTo("some data");
+    assertThat(dto.getDate()).isEqualTo(1413407091086L);
+    assertThat(dto.getCreatedAt()).isEqualTo(1225630680000L);
+  }
+
+  @Test
+  public void return_different_categories() {
+    dbTester.prepareDbUnit(getClass(), "shared.xml");
+
+    List<EventDto> dtos = dao.selectByComponentUuid(session, "ABCD");
+    assertThat(dtos).extracting("category").containsOnly(EventDto.CATEGORY_ALERT, EventDto.CATEGORY_PROFILE, EventDto.CATEGORY_VERSION);
+  }
+
+  @Test
+  public void insert() {
+    dbTester.prepareDbUnit(getClass(), "empty.xml");
+
+    dao.insert(session, new EventDto()
+      .setName("1.0")
+      .setCategory(EventDto.CATEGORY_VERSION)
+      .setDescription("Version 1.0")
+      .setData("some data")
+      .setDate(1413407091086L)
+      .setComponentUuid("ABCD")
+      .setSnapshotId(1000L)
+      .setCreatedAt(1225630680000L)
+      );
+    session.commit();
+
+    dbTester.assertDbUnit(getClass(), "insert-result.xml", new String[] {"id"}, "events");
+  }
+
+  @Test
+  public void delete() {
+    dbTester.prepareDbUnit(getClass(), "delete.xml");
+
+    dao.delete(session, 1L);
+    session.commit();
+
+    assertThat(dbTester.countRowsOfTable("events")).isEqualTo(0);
+  }
+
+}
index a70e1a3d08ef7762371c0ef0ef86fc98b7c5cbe7..9a083137952d0e9407e2aac5a7763f2b81877981 100644 (file)
 package org.sonar.db.issue;
 
 import java.util.Collection;
-import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
-import org.sonar.db.AbstractDaoTestCase;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-public class ActionPlanStatsDaoTest extends AbstractDaoTestCase {
+public class ActionPlanStatsDaoTest {
 
-  ActionPlanStatsDao dao;
+  @Rule
+  public DbTester dbTester = DbTester.create(System2.INSTANCE);
 
-  @Before
-  public void createDao() {
-    dao = new ActionPlanStatsDao(getMyBatis());
-  }
+  ActionPlanStatsDao dao = dbTester.getDbClient().getActionPlanStatsDao();
 
   @Test
   public void should_find_by_project() {
-    setupData("shared", "should_find_by_project");
+    dbTester.prepareDbUnit(getClass(), "shared.xml", "should_find_by_project.xml");
 
     Collection<ActionPlanStatsDto> result = dao.findByProjectId(1l);
     assertThat(result).isNotEmpty();
index 24f556df1e6b1033773dff1dd391e4db368bd594..dc64f45d05de5bdcb9683aa7d46efe4693a3eb5c 100644 (file)
 
 package org.sonar.db.issue;
 
+import java.util.Arrays;
+import java.util.List;
 import org.apache.ibatis.executor.result.DefaultResultHandler;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.sonar.api.rule.RuleKey;
 import org.sonar.db.AbstractDaoTestCase;
 import org.sonar.db.DbSession;
+import org.sonar.db.component.ComponentDto;
+import org.sonar.db.rule.RuleTesting;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -91,4 +96,116 @@ public class IssueDaoTest extends AbstractDaoTestCase {
     assertThat(issue.getComponentKey()).isNotNull();
     assertThat(issue.getProjectKey()).isNull();
   }
+
+  @Test
+  public void get_by_key() {
+    setupData("shared", "get_by_key");
+
+    IssueDto issue = dao.selectByKey(session, "ABCDE");
+    assertThat(issue.getKee()).isEqualTo("ABCDE");
+    assertThat(issue.getId()).isEqualTo(100L);
+    assertThat(issue.getComponentUuid()).isEqualTo("CDEF");
+    assertThat(issue.getProjectUuid()).isEqualTo("ABCD");
+    assertThat(issue.getRuleId()).isEqualTo(500);
+    assertThat(issue.getLanguage()).isEqualTo("java");
+    assertThat(issue.getSeverity()).isEqualTo("BLOCKER");
+    assertThat(issue.isManualSeverity()).isFalse();
+    assertThat(issue.getMessage()).isNull();
+    assertThat(issue.getLine()).isEqualTo(200);
+    assertThat(issue.getEffortToFix()).isEqualTo(4.2);
+    assertThat(issue.getStatus()).isEqualTo("OPEN");
+    assertThat(issue.getResolution()).isEqualTo("FIXED");
+    assertThat(issue.getChecksum()).isEqualTo("XXX");
+    assertThat(issue.getAuthorLogin()).isEqualTo("karadoc");
+    assertThat(issue.getReporter()).isEqualTo("arthur");
+    assertThat(issue.getAssignee()).isEqualTo("perceval");
+    assertThat(issue.getIssueAttributes()).isEqualTo("JIRA=FOO-1234");
+    assertThat(issue.getIssueCreationDate()).isNotNull();
+    assertThat(issue.getIssueUpdateDate()).isNotNull();
+    assertThat(issue.getIssueCloseDate()).isNotNull();
+    assertThat(issue.getCreatedAt()).isEqualTo(1400000000000L);
+    assertThat(issue.getUpdatedAt()).isEqualTo(1450000000000L);
+    assertThat(issue.getRuleRepo()).isEqualTo("squid");
+    assertThat(issue.getRule()).isEqualTo("AvoidCycle");
+    assertThat(issue.getComponentKey()).isEqualTo("Action.java");
+    assertThat(issue.getProjectKey()).isEqualTo("struts");
+  }
+
+  @Test
+  public void get_by_keys() {
+    setupData("shared", "get_by_key");
+
+    List<IssueDto> issues = dao.selectByKeys(session, Arrays.asList("ABCDE"));
+    assertThat(issues).hasSize(1);
+  }
+
+  @Test
+  public void find_by_action_plan() {
+    setupData("shared", "find_by_action_plan");
+
+    List<IssueDto> issues = dao.findByActionPlan(session, "AP-1");
+    assertThat(issues).hasSize(1);
+
+    IssueDto issue = issues.get(0);
+    assertThat(issue.getKee()).isEqualTo("ABCDE");
+    assertThat(issue.getActionPlanKey()).isEqualTo("AP-1");
+    assertThat(issue.getComponentUuid()).isEqualTo("CDEF");
+    assertThat(issue.getProjectUuid()).isEqualTo("ABCD");
+    assertThat(issue.getRuleId()).isEqualTo(500);
+    assertThat(issue.getLanguage()).isEqualTo("java");
+    assertThat(issue.getSeverity()).isEqualTo("BLOCKER");
+    assertThat(issue.isManualSeverity()).isFalse();
+    assertThat(issue.getMessage()).isNull();
+    assertThat(issue.getLine()).isEqualTo(200);
+    assertThat(issue.getEffortToFix()).isEqualTo(4.2);
+    assertThat(issue.getStatus()).isEqualTo("OPEN");
+    assertThat(issue.getResolution()).isEqualTo("FIXED");
+    assertThat(issue.getChecksum()).isEqualTo("XXX");
+    assertThat(issue.getAuthorLogin()).isEqualTo("karadoc");
+    assertThat(issue.getReporter()).isEqualTo("arthur");
+    assertThat(issue.getAssignee()).isEqualTo("perceval");
+    assertThat(issue.getIssueAttributes()).isEqualTo("JIRA=FOO-1234");
+    assertThat(issue.getIssueCreationDate()).isNotNull();
+    assertThat(issue.getIssueUpdateDate()).isNotNull();
+    assertThat(issue.getIssueCloseDate()).isNotNull();
+    assertThat(issue.getCreatedAt()).isNotNull();
+    assertThat(issue.getUpdatedAt()).isNotNull();
+    assertThat(issue.getRuleRepo()).isEqualTo("squid");
+    assertThat(issue.getRule()).isEqualTo("AvoidCycle");
+    assertThat(issue.getComponentKey()).isEqualTo("Action.java");
+    assertThat(issue.getProjectKey()).isEqualTo("struts");
+  }
+
+  @Test
+  public void insert() {
+    IssueDto dto = new IssueDto();
+    dto.setComponent(new ComponentDto().setKey("struts:Action").setId(123L).setUuid("component-uuid"));
+    dto.setProject(new ComponentDto().setKey("struts").setId(100L).setUuid("project-uuid"));
+    dto.setRule(RuleTesting.newDto(RuleKey.of("squid", "S001")).setId(200));
+    dto.setKee("ABCDE");
+    dto.setLine(500);
+    dto.setEffortToFix(3.14);
+    dto.setDebt(10L);
+    dto.setResolution("FIXED");
+    dto.setStatus("RESOLVED");
+    dto.setSeverity("BLOCKER");
+    dto.setReporter("emmerik");
+    dto.setAuthorLogin("morgan");
+    dto.setAssignee("karadoc");
+    dto.setActionPlanKey("current_sprint");
+    dto.setIssueAttributes("JIRA=FOO-1234");
+    dto.setChecksum("123456789");
+    dto.setMessage("the message");
+
+    dto.setIssueCreationTime(1_500_000_000_000L);
+    dto.setIssueUpdateTime(1_500_000_000_001L);
+    dto.setIssueCloseTime(1_500_000_000_002L);
+    dto.setCreatedAt(1_400_000_000_000L);
+    dto.setUpdatedAt(1_450_000_000_000L);
+
+    dao.insert(session, dto);
+    session.commit();
+
+    checkTables("insert", new String[] {"id"}, "issues");
+  }
 }
diff --git a/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java b/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java
new file mode 100644 (file)
index 0000000..9621d6a
--- /dev/null
@@ -0,0 +1,333 @@
+/*
+ * 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.measure;
+
+import com.google.common.base.Function;
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.ImmutableSet;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nullable;
+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.db.measure.MeasureDao;
+import org.sonar.db.measure.MeasureDto;
+import org.sonar.db.measure.PastMeasureDto;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.test.DbTests;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.assertj.core.api.Assertions.assertThat;
+
+@Category(DbTests.class)
+public class MeasureDaoTest {
+
+  @ClassRule
+  public static DbTester db = new DbTester();
+
+  DbSession session;
+  MeasureDao sut;
+
+  @Before
+  public void setUp() {
+    db.truncateTables();
+    session = db.myBatis().openSession(false);
+    sut = new MeasureDao();
+  }
+
+  @After
+  public void tearDown() {
+    session.close();
+  }
+
+  @Test
+  public void get_value_by_key() {
+    db.prepareDbUnit(getClass(), "shared.xml");
+
+    MeasureDto result = sut.findByComponentKeyAndMetricKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "ncloc");
+    assertThat(result.getId()).isEqualTo(22);
+    assertThat(result.getValue()).isEqualTo(10d);
+    assertThat(result.getData()).isNull();
+    assertThat(result.getVariation(1)).isEqualTo(1d);
+    assertThat(result.getVariation(2)).isEqualTo(2d);
+    assertThat(result.getVariation(3)).isEqualTo(3d);
+    assertThat(result.getVariation(4)).isEqualTo(4d);
+    assertThat(result.getVariation(5)).isEqualTo(-5d);
+    assertThat(result.getAlertStatus()).isEqualTo("OK");
+    assertThat(result.getAlertText()).isEqualTo("Green");
+  }
+
+  @Test
+  // TODO the string must be longer than 4000 char to be persisted in the data field
+  public void get_data_by_key() {
+    db.prepareDbUnit(getClass(), "shared.xml");
+
+    MeasureDto result = sut.findByComponentKeyAndMetricKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "authors_by_line");
+    assertThat(result.getId()).isEqualTo(20);
+    assertThat(result.getData()).isEqualTo("0123456789012345678901234567890123456789");
+  }
+
+  @Test
+  public void get_text_value_by_key() {
+    db.prepareDbUnit(getClass(), "shared.xml");
+
+    MeasureDto result = sut.findByComponentKeyAndMetricKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "coverage_line_hits_data");
+    assertThat(result.getId()).isEqualTo(21);
+    assertThat(result.getData()).isEqualTo("36=1;37=1;38=1;39=1;43=1;48=1;53=1");
+  }
+
+  @Test
+  public void find_by_component_key_and_metrics() {
+    db.prepareDbUnit(getClass(), "shared.xml");
+
+    List<MeasureDto> results = sut.findByComponentKeyAndMetricKeys(session, "org.struts:struts-core:src/org/struts/RequestContext.java",
+      newArrayList("ncloc", "authors_by_line"));
+    assertThat(results).hasSize(2);
+
+    results = sut.findByComponentKeyAndMetricKeys(session, "org.struts:struts-core:src/org/struts/RequestContext.java", newArrayList("ncloc"));
+    assertThat(results).hasSize(1);
+
+    MeasureDto result = results.get(0);
+    assertThat(result.getId()).isEqualTo(22);
+    assertThat(result.getValue()).isEqualTo(10d);
+    assertThat(result.getComponentKey()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java");
+    assertThat(result.getMetricKey()).isEqualTo("ncloc");
+    assertThat(result.getVariation(1)).isEqualTo(1d);
+    assertThat(result.getVariation(2)).isEqualTo(2d);
+    assertThat(result.getVariation(3)).isEqualTo(3d);
+    assertThat(result.getVariation(4)).isEqualTo(4d);
+    assertThat(result.getVariation(5)).isEqualTo(-5d);
+  }
+
+  @Test
+  public void find_by_component_key_and_metric() {
+    db.prepareDbUnit(getClass(), "shared.xml");
+
+    MeasureDto result = sut.findByComponentKeyAndMetricKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "ncloc");
+    assertThat(result.getId()).isEqualTo(22);
+    assertThat(result.getValue()).isEqualTo(10d);
+    assertThat(result.getMetricKey()).isEqualTo("ncloc");
+    assertThat(result.getComponentKey()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java");
+    assertThat(result.getVariation(1)).isEqualTo(1d);
+    assertThat(result.getVariation(2)).isEqualTo(2d);
+    assertThat(result.getVariation(3)).isEqualTo(3d);
+    assertThat(result.getVariation(4)).isEqualTo(4d);
+    assertThat(result.getVariation(5)).isEqualTo(-5d);
+
+    assertThat(sut.findByComponentKeyAndMetricKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "unknown")).isNull();
+  }
+
+  @Test
+  public void exists_by_key() {
+    db.prepareDbUnit(getClass(), "shared.xml");
+
+    assertThat(sut.existsByKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "ncloc")).isTrue();
+    assertThat(sut.existsByKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "unknown")).isFalse();
+  }
+
+  @Test
+  public void select_past_measures_by_component_uuid_and_root_snapshot_id_and_metric_keys() {
+    db.prepareDbUnit(getClass(), "past_measures.xml");
+
+    List<PastMeasureDto> fileMeasures = sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "CDEF", 1000L, ImmutableSet.of(1, 2));
+    assertThat(fileMeasures).hasSize(2);
+
+    PastMeasureDto fileMeasure1 = fileMeasures.get(0);
+    assertThat(fileMeasure1.getValue()).isEqualTo(5d);
+    assertThat(fileMeasure1.getMetricId()).isEqualTo(1);
+    assertThat(fileMeasure1.getRuleId()).isNull();
+    assertThat(fileMeasure1.getCharacteristicId()).isNull();
+    assertThat(fileMeasure1.getPersonId()).isNull();
+
+    PastMeasureDto fileMeasure2 = fileMeasures.get(1);
+    assertThat(fileMeasure2.getValue()).isEqualTo(60d);
+    assertThat(fileMeasure2.getMetricId()).isEqualTo(2);
+
+    List<PastMeasureDto> projectMeasures = sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "ABCD", 1000L, ImmutableSet.of(1, 2));
+    assertThat(projectMeasures).hasSize(2);
+
+    PastMeasureDto projectMeasure1 = projectMeasures.get(0);
+    assertThat(projectMeasure1.getValue()).isEqualTo(60d);
+    assertThat(projectMeasure1.getMetricId()).isEqualTo(1);
+
+    PastMeasureDto projectMeasure2 = projectMeasures.get(1);
+    assertThat(projectMeasure2.getValue()).isEqualTo(80d);
+    assertThat(projectMeasure2.getMetricId()).isEqualTo(2);
+
+    assertThat(sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "UNKNOWN", 1000L, ImmutableSet.of(1, 2))).isEmpty();
+    assertThat(sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "CDEF", 987654L, ImmutableSet.of(1, 2))).isEmpty();
+    assertThat(sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "CDEF", 1000L, ImmutableSet.of(123, 456))).isEmpty();
+  }
+
+  @Test
+  public void select_past_measures_on_rule_by_component_uuid_and_root_snapshot_id_and_metric_keys() {
+    db.prepareDbUnit(getClass(), "past_measures_with_rule_id.xml");
+
+    List<PastMeasureDto> measures = sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "ABCD", 1000L, ImmutableSet.of(1));
+    assertThat(measures).hasSize(3);
+
+    Map<Long, PastMeasureDto> pastMeasuresById = pastMeasuresById(measures);
+
+    PastMeasureDto measure1 = pastMeasuresById.get(1L);
+    assertThat(measure1.getValue()).isEqualTo(60d);
+    assertThat(measure1.getMetricId()).isEqualTo(1);
+    assertThat(measure1.getRuleId()).isNull();
+    assertThat(measure1.getCharacteristicId()).isNull();
+    assertThat(measure1.getPersonId()).isNull();
+
+    PastMeasureDto measure2 = pastMeasuresById.get(2L);
+    assertThat(measure2.getValue()).isEqualTo(20d);
+    assertThat(measure2.getMetricId()).isEqualTo(1);
+    assertThat(measure2.getRuleId()).isEqualTo(30);
+    assertThat(measure2.getCharacteristicId()).isNull();
+    assertThat(measure2.getPersonId()).isNull();
+
+    PastMeasureDto measure3 = pastMeasuresById.get(3L);
+    assertThat(measure3.getValue()).isEqualTo(40d);
+    assertThat(measure3.getMetricId()).isEqualTo(1);
+    assertThat(measure3.getRuleId()).isEqualTo(31);
+    assertThat(measure3.getCharacteristicId()).isNull();
+    assertThat(measure3.getPersonId()).isNull();
+  }
+
+  @Test
+  public void select_past_measures_on_characteristic_by_component_uuid_and_root_snapshot_id_and_metric_keys() {
+    db.prepareDbUnit(getClass(), "past_measures_with_characteristic_id.xml");
+
+    List<PastMeasureDto> measures = sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "ABCD", 1000L, ImmutableSet.of(1));
+    assertThat(measures).hasSize(3);
+
+    Map<Long, PastMeasureDto> pastMeasuresById = pastMeasuresById(measures);
+
+    PastMeasureDto measure1 = pastMeasuresById.get(1L);
+    assertThat(measure1.getValue()).isEqualTo(60d);
+    assertThat(measure1.getMetricId()).isEqualTo(1);
+    assertThat(measure1.getRuleId()).isNull();
+    assertThat(measure1.getCharacteristicId()).isNull();
+    assertThat(measure1.getPersonId()).isNull();
+
+    PastMeasureDto measure2 = pastMeasuresById.get(2L);
+    assertThat(measure2.getValue()).isEqualTo(20d);
+    assertThat(measure2.getMetricId()).isEqualTo(1);
+    assertThat(measure2.getRuleId()).isNull();
+    assertThat(measure2.getCharacteristicId()).isEqualTo(10);
+    assertThat(measure2.getPersonId()).isNull();
+
+    PastMeasureDto measure3 = pastMeasuresById.get(3L);
+    assertThat(measure3.getValue()).isEqualTo(40d);
+    assertThat(measure3.getMetricId()).isEqualTo(1);
+    assertThat(measure3.getRuleId()).isNull();
+    assertThat(measure3.getCharacteristicId()).isEqualTo(11);
+    assertThat(measure3.getPersonId()).isNull();
+  }
+
+  @Test
+  public void select_past_measures_on_person_by_component_uuid_and_root_snapshot_id_and_metric_keys() {
+    db.prepareDbUnit(getClass(), "past_measures_with_person_id.xml");
+
+    List<PastMeasureDto> measures = sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "ABCD", 1000L, ImmutableSet.of(1));
+    assertThat(measures).hasSize(3);
+
+    Map<Long, PastMeasureDto> pastMeasuresById = pastMeasuresById(measures);
+
+    PastMeasureDto measure1 = pastMeasuresById.get(1L);
+    assertThat(measure1.getValue()).isEqualTo(60d);
+    assertThat(measure1.getMetricId()).isEqualTo(1);
+    assertThat(measure1.getRuleId()).isNull();
+    assertThat(measure1.getCharacteristicId()).isNull();
+    assertThat(measure1.getPersonId()).isNull();
+
+    PastMeasureDto measure2 = pastMeasuresById.get(2L);
+    assertThat(measure2.getValue()).isEqualTo(20d);
+    assertThat(measure2.getMetricId()).isEqualTo(1);
+    assertThat(measure2.getRuleId()).isNull();
+    assertThat(measure2.getCharacteristicId()).isNull();
+    assertThat(measure2.getPersonId()).isEqualTo(20);
+
+    PastMeasureDto measure3 = pastMeasuresById.get(3L);
+    assertThat(measure3.getValue()).isEqualTo(40d);
+    assertThat(measure3.getMetricId()).isEqualTo(1);
+    assertThat(measure3.getRuleId()).isNull();
+    assertThat(measure3.getCharacteristicId()).isNull();
+    assertThat(measure3.getPersonId()).isEqualTo(21);
+  }
+
+  @Test
+  public void insert() {
+    db.prepareDbUnit(getClass(), "empty.xml");
+
+    sut.insert(session, new MeasureDto()
+      .setSnapshotId(2L)
+      .setMetricId(3)
+      .setCharacteristicId(4)
+      .setPersonId(23)
+      .setRuleId(5)
+      .setComponentId(6L)
+      .setValue(2.0d)
+      .setData("measure-value")
+      .setVariation(1, 1.0d)
+      .setVariation(2, 2.0d)
+      .setVariation(3, 3.0d)
+      .setVariation(4, 4.0d)
+      .setVariation(5, 5.0d)
+      .setAlertStatus("alert")
+      .setAlertText("alert-text")
+      .setDescription("measure-description")
+      );
+    session.commit();
+
+    db.assertDbUnit(getClass(), "insert-result.xml", new String[] {"id"}, "project_measures");
+  }
+
+  @Test
+  public void insert_measures() {
+    db.prepareDbUnit(getClass(), "empty.xml");
+
+    sut.insert(session, new MeasureDto()
+      .setSnapshotId(2L)
+      .setMetricId(3)
+      .setComponentId(6L)
+      .setValue(2.0d),
+      new MeasureDto()
+        .setSnapshotId(3L)
+        .setMetricId(4)
+        .setComponentId(6L)
+        .setValue(4.0d)
+      );
+    session.commit();
+
+    assertThat(db.countRowsOfTable("project_measures")).isEqualTo(2);
+  }
+
+  private static Map<Long, PastMeasureDto> pastMeasuresById(List<PastMeasureDto> pastMeasures) {
+    return FluentIterable.from(pastMeasures).uniqueIndex(new Function<PastMeasureDto, Long>() {
+      @Nullable
+      @Override
+      public Long apply(PastMeasureDto input) {
+        return input.getId();
+      }
+    });
+  }
+}
index 592e42b406e123386cacd5de4347ec9670362e23..11aa33abc18f51d963149e9068334f2040fbfca7 100644 (file)
@@ -55,7 +55,7 @@ public class PurgeDaoTest extends AbstractDaoTestCase {
     when(system2.now()).thenReturn(1450000000000L);
     dbSession = getMyBatis().openSession(false);
 
-    sut = new PurgeDao(getMyBatis(), new ResourceDao(getMyBatis(), system2), new PurgeProfiler(), system2);
+    sut = new PurgeDao(getMyBatis(), new ResourceDao(getMyBatis(), system2), system2);
   }
 
   @After
@@ -66,14 +66,14 @@ public class PurgeDaoTest extends AbstractDaoTestCase {
   @Test
   public void shouldDeleteAbortedBuilds() {
     setupData("shouldDeleteAbortedBuilds");
-    sut.purge(newConfigurationWith30Days(), PurgeListener.EMPTY);
+    sut.purge(newConfigurationWith30Days(), PurgeListener.EMPTY, new PurgeProfiler());
     checkTables("shouldDeleteAbortedBuilds", "snapshots");
   }
 
   @Test
   public void should_purge_project() {
     setupData("shouldPurgeProject");
-    sut.purge(newConfigurationWith30Days(), PurgeListener.EMPTY);
+    sut.purge(newConfigurationWith30Days(), PurgeListener.EMPTY, new PurgeProfiler());
     checkTables("shouldPurgeProject", "projects", "snapshots");
   }
 
@@ -88,28 +88,28 @@ public class PurgeDaoTest extends AbstractDaoTestCase {
   @Test
   public void delete_file_sources_of_disabled_resources() {
     setupData("delete_file_sources_of_disabled_resources");
-    sut.purge(newConfigurationWith30Days(system2), PurgeListener.EMPTY);
+    sut.purge(newConfigurationWith30Days(system2), PurgeListener.EMPTY, new PurgeProfiler());
     checkTables("delete_file_sources_of_disabled_resources", "file_sources");
   }
 
   @Test
   public void shouldDeleteHistoricalDataOfDirectoriesAndFiles() {
     setupData("shouldDeleteHistoricalDataOfDirectoriesAndFiles");
-    sut.purge(new PurgeConfiguration(new IdUuidPair(1L, "1"), new String[] {Scopes.DIRECTORY, Scopes.FILE}, 30), PurgeListener.EMPTY);
+    sut.purge(new PurgeConfiguration(new IdUuidPair(1L, "1"), new String[] {Scopes.DIRECTORY, Scopes.FILE}, 30), PurgeListener.EMPTY, new PurgeProfiler());
     checkTables("shouldDeleteHistoricalDataOfDirectoriesAndFiles", "projects", "snapshots");
   }
 
   @Test
   public void disable_resources_without_last_snapshot() {
     setupData("disable_resources_without_last_snapshot");
-    sut.purge(newConfigurationWith30Days(system2), PurgeListener.EMPTY);
+    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");
   }
 
   @Test
   public void shouldDeleteSnapshots() {
     setupData("shouldDeleteSnapshots");
-    sut.deleteSnapshots(PurgeSnapshotQuery.create().setIslast(false).setResourceId(1L));
+    sut.deleteSnapshots(PurgeSnapshotQuery.create().setIslast(false).setResourceId(1L), new PurgeProfiler());
     checkTables("shouldDeleteSnapshots", "snapshots");
   }
 
@@ -130,21 +130,21 @@ public class PurgeDaoTest extends AbstractDaoTestCase {
   @Test
   public void should_delete_project_and_associated_data() {
     setupData("shouldDeleteProject");
-    sut.deleteResourceTree(new IdUuidPair(1L, "A"));
+    sut.deleteResourceTree(new IdUuidPair(1L, "A"), new PurgeProfiler());
     assertEmptyTables("projects", "snapshots", "action_plans", "issues", "issue_changes", "file_sources");
   }
 
   @Test
   public void should_delete_old_closed_issues() {
     setupData("should_delete_old_closed_issues");
-    sut.purge(newConfigurationWith30Days(), PurgeListener.EMPTY);
+    sut.purge(newConfigurationWith30Days(), PurgeListener.EMPTY, new PurgeProfiler());
     checkTables("should_delete_old_closed_issues", "issues", "issue_changes");
   }
 
   @Test
   public void should_delete_all_closed_issues() {
     setupData("should_delete_all_closed_issues");
-    sut.purge(new PurgeConfiguration(new IdUuidPair(1L, "1"), new String[0], 0), PurgeListener.EMPTY);
+    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");
   }
 
index 1aa9d8aebcb020cd720eff531ba23d646a3aa8ef..857b58ed48a887ba410d84e95b6aa049a6c6d35c 100644 (file)
@@ -30,9 +30,11 @@ import org.mockito.stubbing.Answer;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbSession;
 import org.sonar.db.purge.PurgeDao;
+import org.sonar.db.purge.PurgeProfiler;
 import org.sonar.db.purge.PurgeSnapshotQuery;
 import org.sonar.db.purge.PurgeableSnapshotDto;
 
+import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.anyListOf;
 import static org.mockito.Mockito.argThat;
 import static org.mockito.Mockito.eq;
@@ -52,13 +54,13 @@ public class DefaultPeriodCleanerTest {
     Filter filter1 = newLazyFilter();
     Filter filter2 = newLazyFilter();
 
-    DefaultPeriodCleaner cleaner = new DefaultPeriodCleaner(dao);
+    DefaultPeriodCleaner cleaner = new DefaultPeriodCleaner(dao, new PurgeProfiler());
     cleaner.doClean(123L, Arrays.asList(filter1, filter2), session);
 
     verify(filter1).log();
     verify(filter2).log();
-    verify(dao, times(2)).deleteSnapshots(argThat(newRootSnapshotQuery()), eq(session));
-    verify(dao, times(2)).deleteSnapshots(argThat(newSnapshotIdQuery()), eq(session));
+    verify(dao, times(2)).deleteSnapshots(argThat(newRootSnapshotQuery()), eq(session), any(PurgeProfiler.class));
+    verify(dao, times(2)).deleteSnapshots(argThat(newSnapshotIdQuery()), eq(session), any(PurgeProfiler.class));
   }
 
   private BaseMatcher<PurgeSnapshotQuery> newRootSnapshotQuery() {
diff --git a/sonar-db/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java b/sonar-db/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java
deleted file mode 100644 (file)
index 7c3eeaa..0000000
+++ /dev/null
@@ -1,71 +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.qualityprofile;
-
-import java.util.List;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.db.AbstractDaoTestCase;
-import org.sonar.db.DbSession;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class ActiveRuleDaoTest extends AbstractDaoTestCase {
-
-  ActiveRuleDao dao;
-
-  @Before
-  public void before() {
-    dao = new ActiveRuleDao(getMyBatis());
-  }
-
-  @Test
-  public void select_by_profile() {
-    setupData("shared");
-
-    List<ActiveRuleDto> result = dao.selectByProfileKey("parent");
-    assertThat(result).hasSize(2);
-  }
-
-  @Test
-  public void insert_parameter() {
-    setupData("empty");
-
-    DbSession session = getMyBatis().openSession(false);
-    ActiveRuleParamDto dto = new ActiveRuleParamDto()
-      .setActiveRuleId(1)
-      .setRulesParameterId(1)
-      .setKey("max")
-      .setValue("20");
-    dao.insert(dto, session);
-    session.commit();
-    session.close();
-
-    checkTables("insert_parameter", "active_rule_parameters");
-  }
-
-  @Test
-  public void select_params_by_profile_id() {
-    setupData("shared");
-
-    assertThat(dao.selectParamsByProfileKey("child")).hasSize(2);
-  }
-}
diff --git a/sonar-db/src/test/java/org/sonar/db/rule/RuleTesting.java b/sonar-db/src/test/java/org/sonar/db/rule/RuleTesting.java
new file mode 100644 (file)
index 0000000..1b74488
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * 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.rule;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableSet;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rule.RuleStatus;
+import org.sonar.api.rule.Severity;
+import org.sonar.db.rule.RuleDto.Format;
+
+/**
+ * Utility class for tests involving rules
+ */
+public class RuleTesting {
+
+  public static final RuleKey XOO_X1 = RuleKey.of("xoo", "x1");
+  public static final RuleKey XOO_X2 = RuleKey.of("xoo", "x2");
+  public static final RuleKey XOO_X3 = RuleKey.of("xoo", "x3");
+
+  private RuleTesting() {
+    // only static helpers
+  }
+
+  public static RuleDto newXooX1() {
+    return newDto(XOO_X1).setLanguage("xoo");
+  }
+
+  public static RuleDto newXooX2() {
+    return newDto(XOO_X2).setLanguage("xoo");
+  }
+
+  public static RuleDto newXooX3() {
+    return newDto(XOO_X3).setLanguage("xoo");
+  }
+
+  /**
+   * Full RuleDto used to feed database with fake data. Tests must not rely on the
+   * field contents declared here. They should override the fields they need to test,
+   * for example:
+   * <pre>
+   *   ruleDao.insert(dbSession, RuleTesting.newDto(key).setStatus(RuleStatus.BETA));
+   * </pre>
+   */
+  public static RuleDto newDto(RuleKey ruleKey) {
+    return new RuleDto()
+      .setRuleKey(ruleKey.rule())
+      .setRepositoryKey(ruleKey.repository())
+      .setName("Rule " + ruleKey.rule())
+      .setDescription("Description " + ruleKey.rule())
+      .setDescriptionFormat(Format.HTML)
+      .setStatus(RuleStatus.READY)
+      .setConfigKey("InternalKey" + ruleKey.rule())
+      .setSeverity(Severity.INFO)
+      .setIsTemplate(false)
+      .setTags(ImmutableSet.of("tag1", "tag2"))
+      .setSystemTags(ImmutableSet.of("systag1", "systag2"))
+      .setLanguage("js")
+      .setRemediationFunction("LINEAR")
+      .setDefaultRemediationFunction("LINEAR_OFFSET")
+      .setRemediationCoefficient("1h")
+      .setDefaultRemediationCoefficient("5d")
+      .setRemediationOffset("5min")
+      .setDefaultRemediationOffset("10h")
+      .setEffortToFixDescription(ruleKey.repository() + "." + ruleKey.rule() + ".effortToFix");
+  }
+
+  public static RuleDto newTemplateRule(RuleKey ruleKey) {
+    return newDto(ruleKey)
+      .setIsTemplate(true);
+  }
+
+  public static RuleDto newCustomRule(RuleDto templateRule) {
+    Preconditions.checkNotNull(templateRule.getId(), "The template rule need to be persisted before creating this custom rule.");
+    return newDto(RuleKey.of(templateRule.getRepositoryKey(), templateRule.getRuleKey() + "_" + System.currentTimeMillis()))
+      .setLanguage(templateRule.getLanguage())
+      .setTemplateId(templateRule.getId());
+  }
+
+  public static RuleDto newManualRule(String manualKey) {
+    return new RuleDto().setRuleKey(manualKey)
+      .setName("Name " + manualKey)
+      .setRepositoryKey(RuleKey.MANUAL_REPOSITORY_KEY)
+      .setDescription("Description " + manualKey)
+      .setStatus(RuleStatus.READY);
+  }
+
+}
diff --git a/sonar-db/src/test/java/org/sonar/db/source/FileSourceDaoTest.java b/sonar-db/src/test/java/org/sonar/db/source/FileSourceDaoTest.java
new file mode 100644 (file)
index 0000000..09d7fbc
--- /dev/null
@@ -0,0 +1,175 @@
+/*
+ * 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.source;
+
+import com.google.common.base.Function;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import org.apache.commons.io.IOUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.db.AbstractDaoTestCase;
+import org.sonar.db.DbSession;
+import org.sonar.db.source.FileSourceDto.Type;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class FileSourceDaoTest extends AbstractDaoTestCase {
+
+  DbSession session;
+
+  FileSourceDao sut;
+
+  @Before
+  public void setUpTestData() {
+    session = getMyBatis().openSession(false);
+    sut = new FileSourceDao(getMyBatis());
+  }
+
+  @After
+  public void tearDown() {
+    session.close();
+  }
+
+  @Test
+  public void select() {
+    setupData("shared");
+
+    FileSourceDto fileSourceDto = sut.selectSource("FILE1_UUID");
+
+    assertThat(fileSourceDto.getBinaryData()).isNotEmpty();
+    assertThat(fileSourceDto.getDataHash()).isEqualTo("hash");
+    assertThat(fileSourceDto.getProjectUuid()).isEqualTo("PRJ_UUID");
+    assertThat(fileSourceDto.getFileUuid()).isEqualTo("FILE1_UUID");
+    assertThat(fileSourceDto.getCreatedAt()).isEqualTo(1500000000000L);
+    assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(1500000000000L);
+    assertThat(fileSourceDto.getDataType()).isEqualTo(Type.SOURCE);
+  }
+
+  @Test
+  public void select_line_hashes() {
+    setupData("shared");
+
+    ReaderToStringFunction fn = new ReaderToStringFunction();
+    sut.readLineHashesStream(session, "FILE1_UUID", fn);
+
+    assertThat(fn.result).isEqualTo("ABC\\nDEF\\nGHI");
+  }
+
+  @Test
+  public void no_line_hashes_on_unknown_file() {
+    setupData("shared");
+
+    ReaderToStringFunction fn = new ReaderToStringFunction();
+    sut.readLineHashesStream(session, "unknown", fn);
+
+    assertThat(fn.result).isNull();
+  }
+
+  @Test
+  public void no_line_hashes_when_only_test_data() {
+    setupData("no_line_hashes_when_only_test_data");
+
+    ReaderToStringFunction fn = new ReaderToStringFunction();
+    sut.readLineHashesStream(session, "FILE1_UUID", fn);
+
+    assertThat(fn.result).isNull();
+  }
+
+  @Test
+  public void insert() {
+    setupData("shared");
+
+    sut.insert(new FileSourceDto()
+      .setProjectUuid("PRJ_UUID")
+      .setFileUuid("FILE2_UUID")
+      .setBinaryData("FILE2_BINARY_DATA".getBytes())
+      .setDataHash("FILE2_DATA_HASH")
+      .setLineHashes("LINE1_HASH\\nLINE2_HASH")
+      .setSrcHash("FILE2_HASH")
+      .setDataType(Type.SOURCE)
+      .setCreatedAt(1500000000000L)
+      .setUpdatedAt(1500000000001L));
+
+    checkTable("insert", "file_sources", "project_uuid", "file_uuid", "data_hash", "line_hashes", "src_hash", "created_at", "updated_at", "data_type");
+  }
+
+  @Test
+  public void update() {
+    setupData("shared");
+
+    sut.update(new FileSourceDto()
+      .setId(101L)
+      .setProjectUuid("PRJ_UUID")
+      .setFileUuid("FILE1_UUID")
+      .setBinaryData("updated data".getBytes())
+      .setDataHash("NEW_DATA_HASH")
+      .setSrcHash("NEW_FILE_HASH")
+      .setLineHashes("NEW_LINE_HASHES")
+      .setDataType(Type.SOURCE)
+      .setUpdatedAt(1500000000002L));
+
+    checkTable("update", "file_sources", "project_uuid", "file_uuid", "data_hash", "line_hashes", "src_hash", "created_at", "updated_at", "data_type");
+  }
+
+  @Test
+  public void update_date_when_updated_date_is_zero() {
+    setupData("update_date_when_updated_date_is_zero");
+
+    sut.updateDateWhenUpdatedDateIsZero(session, "ABCD", 1500000000002L);
+    session.commit();
+
+    checkTable("update_date_when_updated_date_is_zero", "file_sources", "project_uuid", "file_uuid", "data_hash", "line_hashes", "src_hash", "created_at", "updated_at",
+      "data_type");
+  }
+
+  private static class ReaderToStringFunction implements Function<Reader, String> {
+
+    String result = null;
+
+    @Override
+    public String apply(Reader input) {
+      try {
+        result = IOUtils.toString(input);
+        return IOUtils.toString(input);
+      } catch (IOException e) {
+        throw new RuntimeException(e);
+      }
+    }
+  }
+
+  private static class InputStreamToStringFunction implements Function<InputStream, String> {
+
+    String result = null;
+
+    @Override
+    public String apply(InputStream input) {
+      try {
+        result = IOUtils.toString(input);
+        return IOUtils.toString(input);
+      } catch (IOException e) {
+        throw new RuntimeException(e);
+      }
+    }
+  }
+}
diff --git a/sonar-db/src/test/java/org/sonar/db/user/UserGroupDaoTest.java b/sonar-db/src/test/java/org/sonar/db/user/UserGroupDaoTest.java
new file mode 100644 (file)
index 0000000..ff1c8cf
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * 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.user;
+
+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.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.test.DbTests;
+
+@Category(DbTests.class)
+public class UserGroupDaoTest {
+
+  @ClassRule
+  public static DbTester db = new DbTester();
+
+  private UserGroupDao dao;
+  private DbSession session;
+
+  @Before
+  public void before() {
+    db.truncateTables();
+    this.session = db.myBatis().openSession(false);
+    this.dao = new UserGroupDao();
+  }
+
+  @After
+  public void after() {
+    this.session.close();
+  }
+
+  @Test
+  public void insert() {
+    UserGroupDto userGroupDto = new UserGroupDto().setUserId(1L).setGroupId(2L);
+    dao.insert(session, userGroupDto);
+    session.commit();
+
+    db.assertDbUnit(getClass(), "insert-result.xml", "groups_users");
+  }
+
+  @Test
+  public void delete_members_by_group_id() {
+    db.prepareDbUnit(getClass(), "delete_members_by_group_id.xml");
+    dao.deleteMembersByGroupId(session, 1L);
+    session.commit();
+    db.assertDbUnit(getClass(), "delete_members_by_group_id-result.xml", "groups_users");
+  }
+}
diff --git a/sonar-db/src/test/java/org/sonar/jpa/test/AbstractDbUnitTestCase.java b/sonar-db/src/test/java/org/sonar/jpa/test/AbstractDbUnitTestCase.java
deleted file mode 100644 (file)
index d4743f5..0000000
+++ /dev/null
@@ -1,229 +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.jpa.test;
-
-import java.io.InputStream;
-import java.sql.SQLException;
-import org.apache.commons.io.IOUtils;
-import org.apache.ibatis.session.SqlSession;
-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.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.operation.DatabaseOperation;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.sonar.db.Database;
-import org.sonar.db.DatabaseCommands;
-import org.sonar.db.H2Database;
-import org.sonar.db.MyBatis;
-import org.sonar.db.deprecated.NullQueue;
-import org.sonar.db.version.DatabaseVersion;
-import org.sonar.db.version.SchemaMigrationMapper;
-
-import static org.junit.Assert.fail;
-
-/**
- * @deprecated this class does not support non-H2 databases
- */
-@Deprecated
-public abstract class AbstractDbUnitTestCase {
-  private static Database database;
-  private static MyBatis myBatis;
-  private static DatabaseCommands databaseCommands;
-  private IDatabaseTester databaseTester;
-
-  @BeforeClass
-  public static void startDatabase() throws SQLException {
-    if (database == null) {
-      database = new H2Database("sonarHibernate", true);
-      database.start();
-
-      databaseCommands = DatabaseCommands.forDialect(database.getDialect());
-
-      myBatis = new MyBatis(database, new NullQueue());
-      myBatis.start();
-      try (SqlSession session = myBatis.openSession(false)) {
-        session.getMapper(SchemaMigrationMapper.class).insert(String.valueOf(DatabaseVersion.LAST_VERSION));
-        session.commit();
-      }
-    }
-  }
-
-  @Before
-  public void startDbUnit() throws Exception {
-    databaseCommands.truncateDatabase(database.getDataSource());
-    databaseTester = new DataSourceDatabaseTester(database.getDataSource());
-  }
-
-  protected MyBatis getMyBatis() {
-    return myBatis;
-  }
-
-  protected Database getDatabase() {
-    return database;
-  }
-
-  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 = null;
-    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));
-
-      connection = createConnection();
-
-      new InsertIdentityOperation(DatabaseOperation.INSERT).execute(connection, databaseTester.getDataSet());
-    } catch (Exception e) {
-      throw translateException("Could not setup DBUnit data", e);
-    } finally {
-      closeQuietly(connection);
-    }
-  }
-
-  private void closeQuietly(IDatabaseConnection connection) {
-    try {
-      if (connection != null) {
-        connection.close();
-      }
-    } catch (SQLException ignored) {
-
-    }
-  }
-
-  protected void checkTables(String testName, String... tables) {
-    checkTables(testName, new String[0], tables);
-  }
-
-  protected void checkTables(String testName, String[] excludedColumnNames, String... tables) {
-    IDatabaseConnection connection = null;
-    try {
-      connection = createConnection();
-
-      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 {
-      closeQuietly(connection);
-    }
-  }
-
-  protected void checkTable(String testName, String table, String... columns) {
-    IDatabaseConnection connection = null;
-    try {
-      connection = createConnection();
-
-      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 {
-      closeQuietly(connection);
-    }
-  }
-
-  private IDatabaseConnection createConnection() {
-    try {
-      IDatabaseConnection connection = databaseTester.getConnection();
-      connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, databaseCommands.getDbUnitFactory());
-      return connection;
-    } catch (Exception e) {
-      throw translateException("Error while getting connection", e);
-    }
-  }
-
-  private IDataSet getExpectedData(String testName) {
-    String className = getClass().getName();
-    className = String.format("/%s/%s-result.xml", className.replace('.', '/'), testName);
-
-    InputStream in = getClass().getResourceAsStream(className);
-    try {
-      return getData(in);
-    } finally {
-      IOUtils.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);
-    }
-  }
-
-  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;
-  }
-}
diff --git a/sonar-db/src/test/resources/org/sonar/api/database/configuration/DatabaseConfigurationTest/some-properties.xml b/sonar-db/src/test/resources/org/sonar/api/database/configuration/DatabaseConfigurationTest/some-properties.xml
deleted file mode 100644 (file)
index 64c38fb..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<dataset>
-
-  <properties prop_key="key1" resource_id="[null]" text_value="value1" user_id="[null]"/>
-  <properties prop_key="key2" resource_id="[null]" text_value="value2" user_id="[null]"/>
-
-</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/ResultSetIteratorTest/feed.xml b/sonar-db/src/test/resources/org/sonar/db/ResultSetIteratorTest/feed.xml
new file mode 100644 (file)
index 0000000..e76d538
--- /dev/null
@@ -0,0 +1,5 @@
+<dataset>
+  <issues id="10" kee="AB" />
+  <issues id="20" kee="CD" />
+  <issues id="30" kee="EF" />
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/ResultSetIteratorTest/schema.sql b/sonar-db/src/test/resources/org/sonar/db/ResultSetIteratorTest/schema.sql
new file mode 100644 (file)
index 0000000..333bb0e
--- /dev/null
@@ -0,0 +1,4 @@
+CREATE TABLE "ISSUES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "KEE" VARCHAR(200) NOT NULL
+);
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/delete.xml b/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/delete.xml
new file mode 100644 (file)
index 0000000..8b89e72
--- /dev/null
@@ -0,0 +1,5 @@
+<dataset>
+
+  <project_links id="1" component_uuid="ABCD" link_type="homepage" name="Home" href="http://www.sonarqube.org"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/empty.xml b/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/empty.xml
new file mode 100644 (file)
index 0000000..871dedc
--- /dev/null
@@ -0,0 +1,3 @@
+<dataset>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/insert-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/insert-result.xml
new file mode 100644 (file)
index 0000000..8b89e72
--- /dev/null
@@ -0,0 +1,5 @@
+<dataset>
+
+  <project_links id="1" component_uuid="ABCD" link_type="homepage" name="Home" href="http://www.sonarqube.org"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/shared.xml b/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/shared.xml
new file mode 100644 (file)
index 0000000..33e9449
--- /dev/null
@@ -0,0 +1,7 @@
+<dataset>
+
+  <project_links id="1" component_uuid="ABCD" link_type="homepage" name="Home" href="http://www.sonarqube.org"/>
+  <project_links id="2" component_uuid="ABCD" link_type="scm" name="Sources" href="https://github.com/SonarSource/sonar"/>
+  <project_links id="3" component_uuid="BCDE" link_type="homepage" name="Home" href="http://www.struts.org"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/update-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/update-result.xml
new file mode 100644 (file)
index 0000000..8b89e72
--- /dev/null
@@ -0,0 +1,5 @@
+<dataset>
+
+  <project_links id="1" component_uuid="ABCD" link_type="homepage" name="Home" href="http://www.sonarqube.org"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/update.xml b/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/update.xml
new file mode 100644 (file)
index 0000000..6b80fc9
--- /dev/null
@@ -0,0 +1,5 @@
+<dataset>
+
+  <project_links id="1" component_uuid="BCDE" link_type="ci" name="CI" href="github"/>
+
+</dataset>
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
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/SnapshotDaoTest/empty.xml b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/empty.xml
new file mode 100644 (file)
index 0000000..871dedc
--- /dev/null
@@ -0,0 +1,3 @@
+<dataset>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/insert-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/insert-result.xml
new file mode 100644 (file)
index 0000000..a138d68
--- /dev/null
@@ -0,0 +1,13 @@
+<dataset>
+
+  <snapshots id="1" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
+             status="P" islast="[true]" purge_status="1"
+             period1_mode="days1" period1_param="30" period1_date="1500000000001"
+             period2_mode="days2" period2_param="31" period2_date="1500000000002"
+             period3_mode="days3" period3_param="32" period3_date="1500000000003"
+             period4_mode="days4" period4_param="33" period4_date="1500000000004"
+             period5_mode="days5" period5_param="34" period5_date="1500000000005"
+             depth="1" scope="DIR" qualifier="PAC" created_at="1403042400000" build_date="1500000000006"
+             version="2.1-SNAPSHOT" path="1.2."/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/modules.xml b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/modules.xml
new file mode 100644 (file)
index 0000000..9ba70be
--- /dev/null
@@ -0,0 +1,90 @@
+<dataset>
+
+  <!-- root project -->
+  <projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
+            uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
+            description="the description" long_name="Apache Struts"
+            enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" path="[null]" authorization_updated_at="[null]" />
+  <snapshots id="1" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+             status="P" islast="[true]" purge_status="[null]"
+             period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+             period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+             period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+             period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+             period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+             depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000"
+             version="[null]" path=""/>
+  <snapshots id="10" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+             status="P" islast="[false]" purge_status="[null]"
+             period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+             period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+             period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+             period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+             period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+             depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228136280000" build_date="1228136280000"
+             version="[null]" path=""/>
+
+  <!-- module -->
+  <projects id="2" root_id="1" kee="org.struts:struts-core" name="Struts Core"
+            uuid="EFGH" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD."
+            scope="PRJ" qualifier="BRC" long_name="Struts Core"
+            description="[null]" enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" authorization_updated_at="[null]" />
+  <snapshots id="2" project_id="2" parent_snapshot_id="1" root_project_id="1" root_snapshot_id="1"
+             status="P" islast="[true]" purge_status="[null]"
+             period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+             period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+             period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+             period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+             period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+             depth="[null]" scope="PRJ" qualifier="BRC" created_at="1228222680000" build_date="1228222680000"
+             version="[null]" path="1."/>
+
+  <!-- sub module -->
+  <projects id="3" root_id="1" kee="org.struts:struts-data" name="Struts Data"
+            uuid="FGHI" project_uuid="ABCD" module_uuid="EFGH" module_uuid_path=".ABCD.EFGH."
+            scope="PRJ" qualifier="BRC" long_name="Struts Data"
+            description="[null]" enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" authorization_updated_at="[null]" />
+  <snapshots id="3" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
+             status="P" islast="[true]" purge_status="[null]"
+             period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+             period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+             period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+             period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+             period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+             depth="[null]" scope="PRJ" qualifier="BRC" created_at="1228222680000" build_date="1228222680000"
+             version="[null]" path="1.2."/>
+
+  <!-- directory -->
+  <projects long_name="org.struts" id="4" scope="DIR" qualifier="DIR" kee="org.struts:struts-core:src/org/struts"
+            uuid="GHIJ" project_uuid="ABCD" module_uuid="FGHI" module_uuid_path=".ABCD.EFGH.FGHI."
+            name="src/org/struts" root_id="3"
+            description="[null]"
+            enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" path="src/org/struts" authorization_updated_at="[null]" />
+  <snapshots id="4" project_id="4" parent_snapshot_id="3" root_project_id="1" root_snapshot_id="1"
+             status="P" islast="[true]" purge_status="[null]"
+             period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+             period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+             period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+             period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+             period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+             depth="[null]" scope="DIR" qualifier="PAC" created_at="1228222680000" build_date="1228222680000"
+             version="[null]" path="1.2.3."/>
+
+  <!-- file -->
+  <projects long_name="org.struts.RequestContext" id="5" scope="FIL" qualifier="FIL" kee="org.struts:struts-core:src/org/struts/RequestContext.java"
+            uuid="HIJK" project_uuid="ABCD" module_uuid="FGHI" module_uuid_path=".ABCD.EFGH.FGHI."
+            name="RequestContext.java" root_id="3"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" path="src/org/struts/RequestContext.java" authorization_updated_at="[null]" />
+
+  <snapshots id="5" project_id="5" parent_snapshot_id="4" root_project_id="1" root_snapshot_id="1"
+             status="P" islast="[true]" purge_status="[null]"
+             period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+             period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+             period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+             period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+             period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+             depth="[null]" scope="FIL" qualifier="CLA" created_at="1228222680000" build_date="1228222680000"
+             version="[null]" path="1.2.3.4."/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/select_previous_version_snapshots.xml b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/select_previous_version_snapshots.xml
new file mode 100644 (file)
index 0000000..3f56960
--- /dev/null
@@ -0,0 +1,48 @@
+<dataset>
+
+  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
+            root_id="[null]" uuid="ABCD"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <!-- version 1.0 -->
+  <snapshots id="1000" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+             period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
+             period5_param="[null]" period5_date="[null]"
+             project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="1225630680000" build_date="1225630680000" version="1.0" path=""
+             status="P" islast="[false]" depth="0"/>
+
+  <!-- version 1.1 -->
+  <snapshots id="1001" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+             period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
+             period5_param="[null]" period5_date="[null]"
+             project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="1225803480000" build_date="1225803480000" version="1.1" path=""
+             status="P" islast="[false]" depth="0"/>
+
+  <!-- version 1.2-SNAPSHOT -->
+  <snapshots id="1002" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+             period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
+             period5_param="[null]" period5_date="[null]"
+             project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="1225976280000" build_date="1225976280000" version="1.2-SNAPSHOT" path=""
+             status="P" islast="[false]" depth="0"/>
+
+  <!-- version 1.2-SNAPSHOT, current analysis -->
+  <snapshots id="1003" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+             period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
+             period5_param="[null]" period5_date="[null]"
+             project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="1226235480000" build_date="1226235480000" version="1.2-SNAPSHOT" path=""
+             status="U" islast="[true]" depth="0"/>
+
+  <events id="1" name="1.0" component_uuid="ABCD" snapshot_id="1000" category="Version" event_date="1225630680000" created_at="1225630680000" description="" event_data="[null]"/>
+  <events id="2" name="Foo" component_uuid="ABCD" snapshot_id="1000" category="Other" event_date="1225717080000" created_at="1225717080000" description="" event_data="[null]"/>
+  <events id="3" name="1.1" component_uuid="ABCD" snapshot_id="1001" category="Version" event_date="1225803480000" created_at="1225803480000" description="" event_data="[null]"/>
+  <events id="4" name="Bar" component_uuid="ABCD" snapshot_id="1001" category="Other" event_date="1225889880000" created_at="1225889880000" description="" event_data="[null]"/>
+  <events id="5" name="Uhh" component_uuid="ABCD" snapshot_id="1002" category="Other" event_date="1226062680000" created_at="1226062680000" description="" event_data="[null]"/>
+  <events id="6" name="1.2-SNAPSHOT" component_uuid="ABCD" snapshot_id="1003" category="Version" event_date="1226235480000" created_at="1226235480000" description=""
+          event_data="[null]"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/select_snapshots_by_query.xml b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/select_snapshots_by_query.xml
new file mode 100644 (file)
index 0000000..1f32010
--- /dev/null
@@ -0,0 +1,64 @@
+<dataset>
+
+  <!-- PROJECT_ID = 1 -->
+  <snapshots id="1" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
+             status="P" islast="[true]" purge_status="1"
+             period1_mode="days1" period1_param="30" period1_date="1316815200000"
+             period2_mode="days2" period2_param="31" period2_date="1316901600000"
+             period3_mode="days3" period3_param="32" period3_date="1316988000000"
+             period4_mode="days4" period4_param="33" period4_date="1317074400000"
+             period5_mode="days5" period5_param="34" period5_date="1317160800000"
+             depth="1" scope="PRJ" qualifier="PAC" created_at="1228172400001" build_date="1317247200000"
+             version="2.0-SNAPSHOT" path="1.2."/>
+  <snapshots id="2" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
+             status="P" islast="[false]" purge_status="1"
+             period1_mode="days1" period1_param="30" period1_date="1316815200000"
+             period2_mode="days2" period2_param="31" period2_date="1316901600000"
+             period3_mode="days3" period3_param="32" period3_date="1316988000000"
+             period4_mode="days4" period4_param="33" period4_date="1317074400000"
+             period5_mode="days5" period5_param="34" period5_date="1317160800000"
+             depth="1" scope="DIR" qualifier="PAC" created_at="1228172400002" build_date="1317247200000"
+             version="2.1-SNAPSHOT" path="1.2."/>
+  <snapshots id="3" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
+             status="P" islast="[false]" purge_status="1"
+             period1_mode="days1" period1_param="30" period1_date="1316815200000"
+             period2_mode="days2" period2_param="31" period2_date="1316901600000"
+             period3_mode="days3" period3_param="32" period3_date="1316988000000"
+             period4_mode="days4" period4_param="33" period4_date="1317074400000"
+             period5_mode="days5" period5_param="34" period5_date="1317160800000"
+             depth="1" scope="DIR" qualifier="PAC" created_at="1228172400003" build_date="1317247200000"
+             version="2.2-SNAPSHOT" path="1.2."/>
+
+  <!-- PROJECT_ID = 2 -->
+  <snapshots id="4" project_id="2" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
+             status="P" islast="[true]" purge_status="1"
+             period1_mode="days1" period1_param="30" period1_date="1316815200000"
+             period2_mode="days2" period2_param="31" period2_date="1316901600000"
+             period3_mode="days3" period3_param="32" period3_date="1316988000000"
+             period4_mode="days4" period4_param="33" period4_date="1317074400000"
+             period5_mode="days5" period5_param="34" period5_date="1317160800000"
+             depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
+             version="2.1-SNAPSHOT" path="1.2."/>
+  <!-- Unprocessed snapshot -->
+  <snapshots id="5" project_id="2" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
+             status="U" islast="[true]" purge_status="1"
+             period1_mode="days1" period1_param="30" period1_date="1316815200000"
+             period2_mode="days2" period2_param="31" period2_date="1316901600000"
+             period3_mode="days3" period3_param="32" period3_date="1316988000000"
+             period4_mode="days4" period4_param="33" period4_date="1317074400000"
+             period5_mode="days5" period5_param="34" period5_date="1317160800000"
+             depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
+             version="2.1-SNAPSHOT" path="1.2."/>
+
+  <!-- PROJECT_ID = 3 - no last snapshot -->
+  <snapshots id="6" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
+             status="P" islast="[false]" purge_status="1"
+             period1_mode="days1" period1_param="30" period1_date="1316815200000"
+             period2_mode="days2" period2_param="31" period2_date="1316901600000"
+             period3_mode="days3" period3_param="32" period3_date="1316988000000"
+             period4_mode="days4" period4_param="33" period4_date="1317074400000"
+             period5_mode="days5" period5_param="34" period5_date="1317160800000"
+             depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
+             version="2.1-SNAPSHOT" path="1.2."/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/shared.xml b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/shared.xml
new file mode 100644 (file)
index 0000000..a52b271
--- /dev/null
@@ -0,0 +1,13 @@
+<dataset>
+
+  <snapshots id="3" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
+             status="P" islast="[true]" purge_status="1"
+             period1_mode="days1" period1_param="30" period1_date="1316815200000"
+             period2_mode="days2" period2_param="31" period2_date="1316901600000"
+             period3_mode="days3" period3_param="32" period3_date="1316988000000"
+             period4_mode="days4" period4_param="33" period4_date="1317074400000"
+             period5_mode="days5" period5_param="34" period5_date="1317160800000"
+             depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
+             version="2.1-SNAPSHOT" path="1.2."/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/snapshots.xml b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/snapshots.xml
new file mode 100644 (file)
index 0000000..4c18e25
--- /dev/null
@@ -0,0 +1,65 @@
+<dataset>
+
+  <!-- PROJECT_ID = 1 -->
+  <snapshots id="1" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
+             status="P" islast="[true]" purge_status="1"
+             period1_mode="days1" period1_param="30" period1_date="1316815200000"
+             period2_mode="days2" period2_param="31" period2_date="1316901600000"
+             period3_mode="days3" period3_param="32" period3_date="1316988000000"
+             period4_mode="days4" period4_param="33" period4_date="1317074400000"
+             period5_mode="days5" period5_param="34" period5_date="1317160800000"
+             depth="1" scope="PRJ" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
+             version="2.1-SNAPSHOT" path="1.2."/>
+  <snapshots id="2" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
+             status="P" islast="[false]" purge_status="1"
+             period1_mode="days1" period1_param="30" period1_date="1316815200000"
+             period2_mode="days2" period2_param="31" period2_date="1316901600000"
+             period3_mode="days3" period3_param="32" period3_date="1316988000000"
+             period4_mode="days4" period4_param="33" period4_date="1317074400000"
+             period5_mode="days5" period5_param="34" period5_date="1317160800000"
+             depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
+             version="2.1-SNAPSHOT" path="1.2."/>
+  <snapshots id="3" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
+             status="P" islast="[false]" purge_status="1"
+             period1_mode="days1" period1_param="30" period1_date="1316815200000"
+             period2_mode="days2" period2_param="31" period2_date="1316901600000"
+             period3_mode="days3" period3_param="32" period3_date="1316988000000"
+             period4_mode="days4" period4_param="33" period4_date="1317074400000"
+             period5_mode="days5" period5_param="34" period5_date="1317160800000"
+             depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
+             version="2.1-SNAPSHOT" path="1.2."/>
+
+
+  <!-- PROJECT_ID = 2 -->
+  <snapshots id="4" project_id="2" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
+             status="P" islast="[true]" purge_status="1"
+             period1_mode="days1" period1_param="30" period1_date="1316815200000"
+             period2_mode="days2" period2_param="31" period2_date="1316901600000"
+             period3_mode="days3" period3_param="32" period3_date="1316988000000"
+             period4_mode="days4" period4_param="33" period4_date="1317074400000"
+             period5_mode="days5" period5_param="34" period5_date="1317160800000"
+             depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
+             version="2.1-SNAPSHOT" path="1.2."/>
+
+  <!-- PROJECT_ID = 3 - no last snapshot -->
+  <snapshots id="5" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
+             status="P" islast="[false]" purge_status="1"
+             period1_mode="days1" period1_param="30" period1_date="1316815200000"
+             period2_mode="days2" period2_param="31" period2_date="1316901600000"
+             period3_mode="days3" period3_param="32" period3_date="1316988000000"
+             period4_mode="days4" period4_param="33" period4_date="1317074400000"
+             period5_mode="days5" period5_param="34" period5_date="1317160800000"
+             depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
+             version="2.1-SNAPSHOT" path="1.2."/>
+
+  <!-- Child of snapshot id=1 -->
+  <snapshots id="6" project_id="55" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
+             status="P" islast="[true]" purge_status="1"
+             period1_mode="days1" period1_param="30" period1_date="1316815200000"
+             period2_mode="days2" period2_param="31" period2_date="1316901600000"
+             period3_mode="days3" period3_param="32" period3_date="1316988000000"
+             period4_mode="days4" period4_param="33" period4_date="1317074400000"
+             period5_mode="days5" period5_param="34" period5_date="1317160800000"
+             depth="1" scope="PRJ" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
+             version="2.1-SNAPSHOT" path="1.2."/>
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/any-analysis-reports.xml b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/any-analysis-reports.xml
new file mode 100644 (file)
index 0000000..dba17d0
--- /dev/null
@@ -0,0 +1,26 @@
+<dataset>
+  <analysis_reports
+      id="1"
+      uuid="REPORT_1"
+      project_key="123456789-987654321"
+      report_status="WORKING"
+      created_at="1411509600000"
+      updated_at="1411509600000"
+      />
+  <analysis_reports
+      id="2"
+      uuid="REPORT_2"
+      project_key="123456789-987654321"
+      report_status="WORKING"
+      created_at="1411596000000"
+      updated_at="1411596000000"
+      />
+  <analysis_reports
+      id="3"
+      uuid="REPORT_3"
+      project_key="123456789-987654321"
+      report_status="PENDING"
+      created_at="1411682400000"
+      updated_at="1411682400000"
+      />
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/book_available_report_analysis_while_having_one_working_on_another_project.xml b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/book_available_report_analysis_while_having_one_working_on_another_project.xml
new file mode 100644 (file)
index 0000000..ae28bef
--- /dev/null
@@ -0,0 +1,18 @@
+<dataset>
+  <analysis_reports
+      id="1"
+      project_key="123456789-987654321"
+      uuid="REPORT_1"
+      report_status="PENDING"
+      created_at="1411509600000"
+      updated_at="1411596000000"
+      />
+  <analysis_reports
+      id="2"
+      project_key="987654321-123456789"
+      uuid="REPORT_2"
+      report_status="WORKING"
+      created_at="1411423200000"
+      updated_at="1411682400000"
+      />
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/empty.xml b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/empty.xml
new file mode 100644 (file)
index 0000000..871dedc
--- /dev/null
@@ -0,0 +1,3 @@
+<dataset>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/insert-result.xml b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/insert-result.xml
new file mode 100644 (file)
index 0000000..d25e364
--- /dev/null
@@ -0,0 +1,24 @@
+<dataset>
+  <analysis_reports
+      id="1"
+      project_key="ProjectKey1"
+      project_name="Project 1"
+      uuid="UUID_1"
+      report_status="PENDING"
+      started_at="[null]"
+      finished_at="[null]"
+      created_at="1500000000000"
+      updated_at="1500000000000"
+      />
+  <analysis_reports
+      id="2"
+      project_key="ProjectKey2"
+      project_name="Project 2"
+      uuid="UUID_2"
+      report_status="PENDING"
+      started_at="[null]"
+      finished_at="[null]"
+      created_at="1500000000000"
+      updated_at="1500000000000"
+      />
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/one_analysis_report.xml b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/one_analysis_report.xml
new file mode 100644 (file)
index 0000000..c38ac12
--- /dev/null
@@ -0,0 +1,12 @@
+<dataset>
+  <analysis_reports
+      id="1"
+      project_key="123456789-987654321"
+      uuid="REPORT_1"
+      report_status="WORKING"
+      created_at="1500000000001"
+      updated_at="1500000000002"
+      started_at="1500000000003"
+      finished_at="1500000000004"
+      />
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/pop_null_if_no_pending_reports.xml b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/pop_null_if_no_pending_reports.xml
new file mode 100644 (file)
index 0000000..82f93e9
--- /dev/null
@@ -0,0 +1,27 @@
+<dataset>
+  <analysis_reports
+      id="1"
+      project_key="111111111-987654321"
+      uuid="UUID_1"
+      report_status="WORKING"
+      created_at="1411596000000"
+      updated_at="1411682400000"
+      />
+  <analysis_reports
+      id="2"
+      project_key="123456789-987654321"
+      uuid="UUID_2"
+      report_status="WORKING"
+      created_at="1411509600000"
+      updated_at="1411682400000"
+      />
+  <!-- not select as the previous report which is working is on the same project -->
+  <analysis_reports
+      id="3"
+      project_key="123456789-987654321"
+      uuid="UUID_3"
+      report_status="PENDING"
+      created_at="1411596000000"
+      updated_at="1411682400000"
+      />
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/pop_oldest_pending.xml b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/pop_oldest_pending.xml
new file mode 100644 (file)
index 0000000..972fde8
--- /dev/null
@@ -0,0 +1,37 @@
+<dataset>
+  <!-- WORKING -->
+  <analysis_reports
+    id="1"
+    project_key="P1"
+    uuid="UUID_1"
+    report_status="WORKING"
+    created_at="1411596000000"
+    updated_at="1411682400000"
+    />
+
+  <!-- PENDING on P1, which is already being WORKING-->
+  <analysis_reports
+    id="2"
+    project_key="P1"
+    uuid="UUID_2"
+    report_status="PENDING"
+    created_at="1411509600000"
+    updated_at="1411682400000"
+    />
+  <analysis_reports
+    id="3"
+    project_key="P2"
+    uuid="UUID_3"
+    report_status="PENDING"
+    created_at="1411596000000"
+    updated_at="1411682400000"
+    />
+  <analysis_reports
+    id="4"
+    project_key="P2"
+    uuid="UUID_4"
+    report_status="PENDING"
+    created_at="1420066800000"
+    updated_at="1420066800000"
+    />
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/select.xml b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/select.xml
new file mode 100644 (file)
index 0000000..de9d5b9
--- /dev/null
@@ -0,0 +1,29 @@
+<dataset>
+  <analysis_reports
+      id="1"
+      project_key="123456789-987654321"
+      project_name="Project 1"
+      uuid="UUID_1"
+      report_status="WORKING"
+      created_at="1411509600000"
+      updated_at="1411596000000"
+      />
+  <analysis_reports
+      id="2"
+      project_key="987654321-123456789"
+      project_name="Project 2"
+      uuid="UUID_2"
+      report_status="WORKING"
+      created_at="1411596000000"
+      updated_at="1411596000000"
+      />
+  <analysis_reports
+      id="3"
+      project_key="987654321-123456789"
+      project_name="Project 2"
+      uuid="UUID_3"
+      report_status="PENDING"
+      created_at="1411682400000"
+      updated_at="1411682400000"
+      />
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/three_analysis_reports.xml b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/three_analysis_reports.xml
new file mode 100644 (file)
index 0000000..c1e3284
--- /dev/null
@@ -0,0 +1,26 @@
+<dataset>
+  <analysis_reports
+      id="1"
+      project_key="123456789-987654321"
+      uuid="UUID_1"
+      report_status="WORKING"
+      created_at="1411509600000"
+      updated_at="1411596000000"
+      />
+  <analysis_reports
+      id="2"
+      project_key="987654321-123456789"
+      uuid="UUID_2"
+      report_status="WORKING"
+      created_at="1411596000000"
+      updated_at="1411596000000"
+      />
+  <analysis_reports
+      id="3"
+      project_key="987654321-123456789"
+      uuid="UUID_3"
+      report_status="PENDING"
+      created_at="1411682400000"
+      updated_at="1411682400000"
+      />
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/truncate-result.xml b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/truncate-result.xml
new file mode 100644 (file)
index 0000000..e573e0c
--- /dev/null
@@ -0,0 +1,3 @@
+<dataset>
+  <analysis_reports/>
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/update-all-to-status-pending-result.xml b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/update-all-to-status-pending-result.xml
new file mode 100644 (file)
index 0000000..16fb8dc
--- /dev/null
@@ -0,0 +1,36 @@
+<dataset>
+    <!-- all rows are PENDING, updated_at is now, started_at is null -->
+    <analysis_reports
+      id="1"
+      project_key="P1"
+      project_name="Project1"
+      uuid="UUID_1"
+      report_status="PENDING"
+      created_at="1411509600000"
+      updated_at="1500000000000"
+      started_at="[null]"
+      finished_at="[null]"
+      />
+    <analysis_reports
+      id="2"
+      project_key="P2"
+      project_name="Project2"
+      uuid="UUID_2"
+      report_status="PENDING"
+      created_at="1411596000000"
+      updated_at="1500000000000"
+      started_at="[null]"
+      finished_at="[null]"
+      />
+    <analysis_reports
+      id="3"
+      project_key="P1"
+      project_name="Project1"
+      uuid="UUID_3"
+      report_status="PENDING"
+      created_at="1411682400000"
+      updated_at="1500000000000"
+      started_at="[null]"
+      finished_at="[null]"
+      />
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/update-all-to-status-pending.xml b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/update-all-to-status-pending.xml
new file mode 100644 (file)
index 0000000..a630cb4
--- /dev/null
@@ -0,0 +1,35 @@
+<dataset>
+  <analysis_reports
+      id="1"
+      project_key="P1"
+      project_name="Project1"
+      uuid="UUID_1"
+      report_status="WORKING"
+      created_at="1411509600000"
+      updated_at="1411509600000"
+      started_at="1411509600000"
+      finished_at="[null]"
+      />
+  <analysis_reports
+      id="2"
+      project_key="P2"
+      project_name="Project2"
+      uuid="UUID_2"
+      report_status="WORKING"
+      created_at="1411596000000"
+      updated_at="1411596000000"
+      started_at="1411509600000"
+      finished_at="[null]"
+      />
+  <analysis_reports
+      id="3"
+      project_key="P1"
+      project_name="Project1"
+      uuid="UUID_3"
+      report_status="PENDING"
+      created_at="1411682400000"
+      updated_at="1411682400000"
+      started_at="[null]"
+      finished_at="[null]"
+      />
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/zip.zip b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/zip.zip
new file mode 100644 (file)
index 0000000..a540bc5
Binary files /dev/null and b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/zip.zip differ
diff --git a/sonar-db/src/test/resources/org/sonar/db/dashboard/WidgetDaoTest/before.xml b/sonar-db/src/test/resources/org/sonar/db/dashboard/WidgetDaoTest/before.xml
new file mode 100644 (file)
index 0000000..a942341
--- /dev/null
@@ -0,0 +1,18 @@
+<dataset>
+
+  <widgets id="1" dashboard_id="1" widget_key="polop" name="Polop" description="Palap"
+     column_index="1" row_index="1" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
+
+  <widgets id="2" dashboard_id="1" widget_key="false_positive_reviews" name="Polop" description="Palap"
+     column_index="1" row_index="2" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
+
+  <widgets id="3" dashboard_id="1" widget_key="my_reviews" name="Polop" description="Palap"
+     column_index="1" row_index="3" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
+
+  <widgets id="4" dashboard_id="1" widget_key="reviews_per_developer" name="Polop" description="Palap"
+     column_index="1" row_index="4" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
+
+  <widgets id="5" dashboard_id="1" widget_key="unresolved_issues_statuses" name="Polop" description="Palap"
+     column_index="1" row_index="5" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/event/EventDaoTest/delete.xml b/sonar-db/src/test/resources/org/sonar/db/event/EventDaoTest/delete.xml
new file mode 100644 (file)
index 0000000..c22a68e
--- /dev/null
@@ -0,0 +1,6 @@
+<dataset>
+
+  <events id="1" name="1.0" category="Version" description="Version 1.0" event_data="some data" event_date="1225630680000"
+          component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/event/EventDaoTest/empty.xml b/sonar-db/src/test/resources/org/sonar/db/event/EventDaoTest/empty.xml
new file mode 100644 (file)
index 0000000..871dedc
--- /dev/null
@@ -0,0 +1,3 @@
+<dataset>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/event/EventDaoTest/insert-result.xml b/sonar-db/src/test/resources/org/sonar/db/event/EventDaoTest/insert-result.xml
new file mode 100644 (file)
index 0000000..27a2a24
--- /dev/null
@@ -0,0 +1,6 @@
+<dataset>
+
+  <events id="1" name="1.0" category="Version" description="Version 1.0" event_data="some data" event_date="1413407091086"
+          component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/event/EventDaoTest/shared.xml b/sonar-db/src/test/resources/org/sonar/db/event/EventDaoTest/shared.xml
new file mode 100644 (file)
index 0000000..0002dee
--- /dev/null
@@ -0,0 +1,13 @@
+<dataset>
+
+  <events id="1" name="1.0" category="Version" description="Version 1.0" event_data="some data" event_date="1413407091086"
+          component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
+  <events id="2" name="Red (was Orange)" category="Alert" description="Critical issues variation > 0 since previous version (1.0 - 2015 Feb 09), Open issues > 0"
+          event_data="[null]" event_date="1413407091086" component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
+  <events id="3" name="Changes in 'Default' (Java)" category="Profile" description="Version 1.0" event_data="from=2014-10-12T08:36:25+0000;key=java-default;to=2014-10-12T10:36:25+0000"
+          event_date="1413407091086" component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
+
+  <events id="4" name="1.0" category="Version" description="Version 1.0" event_data="some data" event_date="1413407091086"
+          component_uuid="BCDE" snapshot_id="1000" created_at="1225630680000" />
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/find_by_action_plan.xml b/sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/find_by_action_plan.xml
new file mode 100644 (file)
index 0000000..a052d42
--- /dev/null
@@ -0,0 +1,29 @@
+<dataset>
+
+  <issues
+      id="100"
+      kee="ABCDE"
+      component_uuid="CDEF"
+      project_uuid="ABCD"
+      rule_id="500"
+      severity="BLOCKER"
+      manual_severity="[false]"
+      message="[null]"
+      line="200"
+      effort_to_fix="4.2"
+      status="OPEN"
+      resolution="FIXED"
+      checksum="XXX"
+      reporter="arthur"
+      assignee="perceval"
+      action_plan_key="AP-1"
+      author_login="karadoc"
+      issue_attributes="JIRA=FOO-1234"
+      issue_creation_date="1366063200000"
+      issue_update_date="1366063200000"
+      issue_close_date="1366063200000"
+      created_at="1400000000000"
+      updated_at="1400000000000"
+      />
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/get_by_key.xml b/sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/get_by_key.xml
new file mode 100644 (file)
index 0000000..154a7a6
--- /dev/null
@@ -0,0 +1,28 @@
+<dataset>
+
+  <issues
+      id="100"
+      kee="ABCDE"
+      component_uuid="CDEF"
+      project_uuid="ABCD"
+      rule_id="500"
+      severity="BLOCKER"
+      manual_severity="[false]"
+      message="[null]"
+      line="200"
+      effort_to_fix="4.2"
+      status="OPEN"
+      resolution="FIXED"
+      checksum="XXX"
+      reporter="arthur"
+      assignee="perceval"
+      author_login="karadoc"
+      issue_attributes="JIRA=FOO-1234"
+      issue_creation_date="1366063200000"
+      issue_update_date="1366063200000"
+      issue_close_date="1366063200000"
+      created_at="1400000000000"
+      updated_at="1450000000000"
+      />
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/insert-result.xml b/sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/insert-result.xml
new file mode 100644 (file)
index 0000000..fc1543c
--- /dev/null
@@ -0,0 +1,29 @@
+<dataset>
+  <issues
+      id="100"
+      kee="ABCDE"
+      component_uuid="component-uuid"
+      project_uuid="project-uuid"
+      rule_id="200"
+      severity="BLOCKER"
+      manual_severity="[false]"
+      message="the message"
+      line="500"
+      effort_to_fix="3.14"
+      technical_debt="10"
+      status="RESOLVED"
+      resolution="FIXED"
+      checksum="123456789"
+      reporter="emmerik"
+      author_login="morgan"
+      assignee="karadoc"
+      issue_attributes="JIRA=FOO-1234"
+      tags="[null]"
+      issue_creation_date="1500000000000"
+      issue_update_date="1500000000001"
+      issue_close_date="1500000000002"
+      created_at="1400000000000"
+      updated_at="1450000000000"
+      action_plan_key="current_sprint"
+      />
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/update-result.xml b/sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/update-result.xml
new file mode 100644 (file)
index 0000000..d5959c6
--- /dev/null
@@ -0,0 +1,29 @@
+<dataset>
+  <issues
+      id="100"
+      kee="ABCDE"
+      component_uuid="123"
+      project_uuid="101"
+      rule_id="200"
+      severity="BLOCKER"
+      manual_severity="[false]"
+      message="the message"
+      line="500"
+      effort_to_fix="3.14"
+      technical_debt="10"
+      status="RESOLVED"
+      resolution="FIXED"
+      checksum="123456789"
+      reporter="emmerik"
+      author_login="morgan"
+      assignee="karadoc"
+      issue_attributes="JIRA=FOO-1234"
+      tags="[null]"
+      issue_creation_date="1368828000000"
+      issue_update_date="1368914400000"
+      issue_close_date="1369000800000"
+      created_at="1400000000000"
+      updated_at="1450000000000"
+      action_plan_key="current_sprint"
+      />
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/update.xml b/sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/update.xml
new file mode 100644 (file)
index 0000000..9c41f19
--- /dev/null
@@ -0,0 +1,28 @@
+<dataset>
+  <issues
+      id="100"
+      kee="ABCDE"
+      component_uuid="123"
+      project_uuid="100"
+      rule_id="200"
+      severity="INFO"
+      manual_severity="[false]"
+      message="old"
+      line="[null]"
+      effort_to_fix="[null]"
+      technical_debt="[null]"
+      status="OPEN"
+      resolution="[null]"
+      checksum="[null]"
+      reporter="[null]"
+      author_login="[null]"
+      assignee="[null]"
+      issue_attributes="[null]"
+      issue_creation_date="[null]"
+      issue_update_date="[null]"
+      issue_close_date="[null]"
+      created_at="1400000000000"
+      updated_at="1400000000000"
+      action_plan_key="[null]"
+      />
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/empty.xml b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/empty.xml
new file mode 100644 (file)
index 0000000..dda1882
--- /dev/null
@@ -0,0 +1,3 @@
+<dataset>
+  <project_measures/>
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/insert-result.xml b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/insert-result.xml
new file mode 100644 (file)
index 0000000..26c55c5
--- /dev/null
@@ -0,0 +1,27 @@
+<dataset>
+  <project_measures
+      id="1"
+      snapshot_id="2"
+      metric_id="3"
+      characteristic_id="4"
+      rule_id="5"
+      project_id="6"
+      person_id="23"
+      value="2.0"
+      text_value="measure-value"
+      tendency="[null]"
+      rule_priority="[null]"
+      measure_date="[null]"
+      measure_data="[null]"
+      variation_value_1="1.0"
+      variation_value_2="2.0"
+      variation_value_3="3.0"
+      variation_value_4="4.0"
+      variation_value_5="5.0"
+      alert_status="alert"
+      alert_text="alert-text"
+      url="[null]"
+      description="measure-description"
+      rules_category_id="[null]"
+      />
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures.xml b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures.xml
new file mode 100644 (file)
index 0000000..1a9eaec
--- /dev/null
@@ -0,0 +1,59 @@
+<dataset>
+
+  <metrics id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]" enabled="[true]"/>
+
+  <metrics id="2" name="coverage" VAL_TYPE="INT" enabled="[true]"/>
+
+
+  <rules tags="[null]" system_tags="[null]" id="30" name="Check Header" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck"
+         plugin_config_key="Checker/Treewalker/HeaderCheck" plugin_name="checkstyle" description="[null]" priority="4" status="READY"
+         is_template="[false]" template_id="[null]"/>
+
+  <rules tags="[null]" system_tags="[null]" id="31" name="Equals Avoid Null" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck"
+         plugin_config_key="Checker/TreeWalker/EqualsAvoidNull" plugin_name="checkstyle" description="[null]" priority="4" status="READY"
+         is_template="[false]" template_id="[null]"/>
+
+  <!-- project -->
+  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
+            root_id="[null]" uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD."
+            enabled="[true]"/>
+
+  <!-- package -->
+  <projects long_name="[null]" id="2" scope="DIR" qualifier="PAC" kee="project:org.foo" name="org.foo"
+            root_id="1" uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
+            enabled="[true]"/>
+
+  <!-- file -->
+  <projects long_name="org.foo.Bar" id="3" scope="FIL" qualifier="CLA" kee="project:org.foo.Bar"
+            name="Bar" root_id="[null]" uuid="CDEF" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
+            enabled="[true]"/>
+
+
+  <!-- snapshots -->
+  <snapshots id="1000" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="1225544280000" build_date="1225544280000" version="[null]" path=""
+             status="P" islast="[false]" depth="0"/>
+  <snapshots id="1001" project_id="2" parent_snapshot_id="1000" root_project_id="1" root_snapshot_id="1000"
+             scope="DIR" qualifier="PAC" created_at="1225544280000" build_date="1225544280000" version="[null]" path="1000."
+             status="P" islast="[false]" depth="1"/>
+  <snapshots id="1002" project_id="3" parent_snapshot_id="1001" root_project_id="1" root_snapshot_id="1000"
+             scope="FIL" qualifier="CLA" created_at="1225544280000" build_date="1225544280000" version="[null]" path="1000.1001."
+             status="P" islast="[false]" depth="2"/>
+
+
+  <!-- project measures -->
+  <project_measures id="1" VALUE="60" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
+
+  <project_measures id="2" VALUE="80" METRIC_ID="2" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
+
+  <!-- package measures -->
+  <project_measures id="3" VALUE="20" METRIC_ID="1" SNAPSHOT_ID="1001" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
+
+  <project_measures id="4" VALUE="70" METRIC_ID="2" SNAPSHOT_ID="1001" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
+
+  <!-- file measures -->
+  <project_measures id="5" VALUE="5" METRIC_ID="1" SNAPSHOT_ID="1002" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
+
+  <project_measures id="6" VALUE="60" METRIC_ID="2" SNAPSHOT_ID="1002" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_characteristic_id.xml b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_characteristic_id.xml
new file mode 100644 (file)
index 0000000..7e06f10
--- /dev/null
@@ -0,0 +1,28 @@
+<dataset>
+
+  <metrics id="1" name="sqale_index" VAL_TYPE="WORK_DUR" DESCRIPTION="[null]" short_name="" enabled="[true]"/>
+
+  <!-- Root characteristic -->
+  <characteristics id="10" kee="PORTABILITY" name="Portability" parent_id="[null]" characteristic_order="1" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+
+  <!-- Characteristic -->
+  <characteristics id="11" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" parent_id="10" characteristic_order="[null]" enabled="[true]"
+                   created_at="2013-11-20" updated_at="2013-11-22"/>
+
+  <!-- project -->
+  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
+            root_id="[null]" uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD." enabled="[true]"/>
+
+  <!-- snapshots -->
+  <snapshots id="1000" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="1225544280000" build_date="1225544280000" version="[null]" path=""
+             status="P" islast="[false]" depth="0"/>
+
+  <!-- project measures -->
+  <project_measures id="1" VALUE="60" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="[null]"/>
+
+  <project_measures id="2" VALUE="20" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="10"/>
+
+  <project_measures id="3" VALUE="40" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="11"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_person_id.xml b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_person_id.xml
new file mode 100644 (file)
index 0000000..47a1c69
--- /dev/null
@@ -0,0 +1,22 @@
+<dataset>
+
+  <metrics delete_historical_data="[null]" id="1" name="sqale_index" VAL_TYPE="INT" DESCRIPTION="[null]" enabled="[true]"/>
+
+  <!-- project -->
+  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
+            root_id="[null]" uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD."
+            enabled="[true]"/>
+
+  <!-- snapshots -->
+  <snapshots id="1000" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="1225544280000" build_date="1225544280000" version="[null]" path=""
+             status="P" islast="[false]" depth="0"/>
+
+  <!-- project measures -->
+  <project_measures id="1" VALUE="60" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" person_id="[null]"/>
+
+  <project_measures id="2" VALUE="20" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" person_id="20"/>
+
+  <project_measures id="3" VALUE="40" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" person_id="21"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_rule_id.xml b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_rule_id.xml
new file mode 100644 (file)
index 0000000..b6ccf49
--- /dev/null
@@ -0,0 +1,32 @@
+<dataset>
+
+  <metrics delete_historical_data="[null]" id="1" name="minor_violations" VAL_TYPE="INT" DESCRIPTION="[null]" enabled="[true]"/>
+
+  <rules tags="[null]" system_tags="[null]" id="30" name="Classes that override clone should be Cloneable and call super.clone()"
+         plugin_rule_key="S1182"
+         plugin_config_key="S1182" plugin_name="squid" description="[null]" priority="4" status="READY"
+         is_template="[false]" template_id="[null]"/>
+
+  <rules tags="[null]" system_tags="[null]" id="31" name="Overriding methods should do more than simply call the same method in the super class"
+         plugin_rule_key="S1185"
+         plugin_config_key="S1185" plugin_name="squid" description="[null]" priority="1" status="READY"
+         is_template="[false]" template_id="[null]"/>
+
+  <!-- project -->
+  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
+            root_id="[null]" uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD."
+            enabled="[true]"/>
+
+  <!-- snapshots -->
+  <snapshots id="1000" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="1225544280000" build_date="1225544280000" version="[null]" path=""
+             status="P" islast="[false]" depth="0"/>
+
+  <!-- project measures -->
+  <project_measures id="1" VALUE="60" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
+
+  <project_measures id="2" VALUE="20" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="30" characteristic_id="[null]" person_id="[null]"/>
+
+  <project_measures id="3" VALUE="40" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="31" characteristic_id="[null]" person_id="[null]"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/shared.xml b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/shared.xml
new file mode 100644 (file)
index 0000000..c27311c
--- /dev/null
@@ -0,0 +1,21 @@
+<dataset>
+
+  <metrics id="10" name="authors_by_line"/>
+  <metrics id="11" name="coverage_line_hits_data"/>
+  <metrics id="12" name="ncloc"/>
+
+  <projects id="1" kee="org.struts:struts-core:src/org/struts/RequestContext.java" enabled="[true]"/>
+
+  <snapshots id="5" project_id="1" islast="[true]" />
+
+  <project_measures id="20" snapshot_id="5" metric_id="10" value="[null]" text_value="0123456789012345678901234567890123456789" measure_data="[null]"
+                    variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
+                    alert_status="[null]" alert_text="[null]" />
+  <project_measures id="21" snapshot_id="5" metric_id="11" value="[null]" text_value="36=1;37=1;38=1;39=1;43=1;48=1;53=1" measure_data="[null]"
+                    variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
+                    alert_status="[null]" alert_text="[null]" />
+  <project_measures id="22" snapshot_id="5" metric_id="12" value="10" text_value="[null]" measure_data="[null]"
+                    variation_value_1="1" variation_value_2="2" variation_value_3="3" variation_value_4="4" variation_value_5="-5"
+                    alert_status="OK" alert_text="Green"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete-result.xml b/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete-result.xml
deleted file mode 100644 (file)
index 2283bba..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<dataset>
-
-  <!--<active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="10" failure_level="2" inheritance="INHERITED"-->
-
-  <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="2" rule_id="10" failure_level="0"
-                inheritance="[null]"/>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="3" profile_id="2" rule_id="11" failure_level="1"
-                inheritance="[null]"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_from_profile-result.xml b/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_from_profile-result.xml
deleted file mode 100644 (file)
index 617cd7e..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-<dataset>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="10" failure_level="2"
-                inheritance="INHERITED"/>
-
-  <!--<active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="2" rule_id="10" failure_level="0" inheritance="[null]"-->
-
-  <!--<active_rules created_at="[null]" updated_at="[null]" id="3" profile_id="2" rule_id="11" failure_level="1" inheritance="[null]"-->
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_from_rule-result.xml b/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_from_rule-result.xml
deleted file mode 100644 (file)
index a06288e..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<dataset>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="10" failure_level="2"
-                inheritance="INHERITED"/>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="2" rule_id="10" failure_level="0"
-                inheritance="[null]"/>
-
-  <!--<active_rules created_at="[null]" updated_at="[null]" id="3" profile_id="2" rule_id="11" failure_level="1" inheritance="[null]"/>-->
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_parameter-result.xml b/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_parameter-result.xml
deleted file mode 100644 (file)
index 900eb2c..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<dataset>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="10" failure_level="2"
-                inheritance="INHERITED"/>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="2" rule_id="10" failure_level="0"
-                inheritance="[null]"/>
-
-  <!--<active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" rules_parameter_key="max" value="20"/>-->
-  <active_rule_parameters id="2" active_rule_id="1" rules_parameter_id="2" rules_parameter_key="format" value="html"/>
-
-  <active_rule_parameters id="3" active_rule_id="2" rules_parameter_id="1" rules_parameter_key="max" value="15"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_parameters-result.xml b/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_parameters-result.xml
deleted file mode 100644 (file)
index b8aba08..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<dataset>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="10" failure_level="2"
-                inheritance="INHERITED"/>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="2" rule_id="10" failure_level="0"
-                inheritance="[null]"/>
-
-  <!--<active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" rules_parameter_key="max" value="20"/>-->
-  <!--<active_rule_parameters id="2" active_rule_id="1" rules_parameter_id="2" rules_parameter_key="format" value="html"/>-->
-
-  <active_rule_parameters id="3" active_rule_id="2" rules_parameter_id="1" rules_parameter_key="max" value="15"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_parameters_from_profile_id-result.xml b/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_parameters_from_profile_id-result.xml
deleted file mode 100644 (file)
index d1bbff5..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-<dataset>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="10" failure_level="2"
-                inheritance="INHERITED"/>
-
-  <!-- Parent of Active rule 1 -->
-  <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="2" rule_id="10" failure_level="0"
-                inheritance="[null]"/>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="3" profile_id="2" rule_id="11" failure_level="1"
-                inheritance="[null]"/>
-
-  <active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" rules_parameter_key="max" value="20"/>
-  <active_rule_parameters id="2" active_rule_id="1" rules_parameter_id="2" rules_parameter_key="format" value="html"/>
-
-  <!--<active_rule_parameters id="3" active_rule_id="2" rules_parameter_id="1" rules_parameter_key="max" value="15"/>-->
-  <!--<active_rule_parameters id="4" active_rule_id="3" rules_parameter_id="2" rules_parameter_key="format" value="text"/>-->
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_parameters_from_profile_id.xml b/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_parameters_from_profile_id.xml
deleted file mode 100644 (file)
index 47c6cee..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-<dataset>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="10" failure_level="2"
-                inheritance="INHERITED"/>
-
-  <!-- Parent of Active rule 1 -->
-  <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="2" rule_id="10" failure_level="0"
-                inheritance="[null]"/>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="3" profile_id="2" rule_id="11" failure_level="1"
-                inheritance="[null]"/>
-
-  <active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" rules_parameter_key="max" value="20"/>
-  <active_rule_parameters id="2" active_rule_id="1" rules_parameter_id="2" rules_parameter_key="format" value="html"/>
-
-  <active_rule_parameters id="3" active_rule_id="2" rules_parameter_id="1" rules_parameter_key="max" value="15"/>
-  <active_rule_parameters id="4" active_rule_id="3" rules_parameter_id="2" rules_parameter_key="format" value="text"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/empty.xml b/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/empty.xml
deleted file mode 100644 (file)
index 871dedc..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<dataset>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/insert-result.xml b/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/insert-result.xml
deleted file mode 100644 (file)
index 574cbab..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<dataset>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="10" failure_level="2"
-                inheritance="INHERITED"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/insert_parameter-result.xml b/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/insert_parameter-result.xml
deleted file mode 100644 (file)
index ed2e17d..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-
-  <active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" rules_parameter_key="max" value="20"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/shared.xml b/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/shared.xml
deleted file mode 100644 (file)
index b6d5461..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-<dataset>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="10" failure_level="2"
-                inheritance="INHERITED"/>
-
-  <!-- Parent of Active rule 1 -->
-  <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="2" rule_id="10" failure_level="0"
-                inheritance="[null]"/>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="3" profile_id="2" rule_id="11" failure_level="1"
-                inheritance="[null]"/>
-
-  <active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" rules_parameter_key="max" value="20"/>
-  <active_rule_parameters id="2" active_rule_id="1" rules_parameter_id="2" rules_parameter_key="format" value="html"/>
-
-  <active_rule_parameters id="3" active_rule_id="2" rules_parameter_id="1" rules_parameter_key="max" value="15"/>
-
-  <rules_profiles id="1" name="Child" language="java" parent_kee="parent" kee="child" is_default="[false]"/>
-
-  <rules_profiles id="2" name="Parent" language="java" parent_kee="[null]" kee="parent" is_default="[false]"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/update-result.xml b/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/update-result.xml
deleted file mode 100644 (file)
index 30111d6..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<dataset>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="10" failure_level="4"
-                inheritance="[null]"/>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="2" rule_id="10" failure_level="0"
-                inheritance="[null]"/>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="3" profile_id="2" rule_id="11" failure_level="1"
-                inheritance="[null]"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/update_parameter-result.xml b/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/update_parameter-result.xml
deleted file mode 100644 (file)
index 289da2f..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<dataset>
-
-  <active_rule_parameters id="1" active_rule_id="2" rules_parameter_id="3" rules_parameter_key="newMax" value="30"/>
-  <active_rule_parameters id="2" active_rule_id="1" rules_parameter_id="2" rules_parameter_key="format" value="html"/>
-
-  <active_rule_parameters id="3" active_rule_id="2" rules_parameter_id="1" rules_parameter_key="max" value="15"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/insert-result.xml b/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/insert-result.xml
new file mode 100644 (file)
index 0000000..4f34778
--- /dev/null
@@ -0,0 +1,17 @@
+<dataset>
+
+  <file_sources id="101" project_uuid="PRJ_UUID" file_uuid="FILE1_UUID"
+                binary_data="abcde" data_hash="hash"
+                line_hashes="ABC\nDEF\nGHI"
+                src_hash="FILE_HASH"
+                created_at="1500000000000" updated_at="1500000000000"  data_type="SOURCE" />
+
+
+  <file_sources id="102" project_uuid="PRJ_UUID" file_uuid="FILE2_UUID"
+                binary_data="[ignore]"
+                data_hash="FILE2_DATA_HASH"
+                line_hashes="LINE1_HASH\nLINE2_HASH"
+                src_hash="FILE2_HASH"
+                created_at="1500000000000" updated_at="1500000000001"  data_type="SOURCE" />
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/no_line_hashes_when_only_test_data.xml b/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/no_line_hashes_when_only_test_data.xml
new file mode 100644 (file)
index 0000000..010394a
--- /dev/null
@@ -0,0 +1,9 @@
+<dataset>
+
+    <file_sources id="101" project_uuid="PRJ_UUID" file_uuid="FILE1_UUID"
+                  binary_data="abcde" data_hash="[null]"
+                  line_hashes="[null]"
+                  src_hash="[null]"
+                  created_at="1500000000000" updated_at="1500000000000"  data_type="TEST" />
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/shared.xml b/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/shared.xml
new file mode 100644 (file)
index 0000000..5187ca2
--- /dev/null
@@ -0,0 +1,9 @@
+<dataset>
+
+    <file_sources id="101" project_uuid="PRJ_UUID" file_uuid="FILE1_UUID"
+                  binary_data="abcde" data_hash="hash"
+                  line_hashes="ABC\nDEF\nGHI"
+                  src_hash="FILE_HASH"
+                  created_at="1500000000000" updated_at="1500000000000"  data_type="SOURCE" />
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update-result.xml b/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update-result.xml
new file mode 100644 (file)
index 0000000..8dbe32d
--- /dev/null
@@ -0,0 +1,11 @@
+<dataset>
+
+  <file_sources id="101" project_uuid="PRJ_UUID" file_uuid="FILE1_UUID"
+                binary_data="[ignore]"
+                data_hash="NEW_DATA_HASH"
+                line_hashes="NEW_LINE_HASHES"
+                src_hash="NEW_FILE_HASH"
+                created_at="1500000000000" updated_at="1500000000002"  data_type="SOURCE" />
+
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update_date_when_updated_date_is_zero-result.xml b/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update_date_when_updated_date_is_zero-result.xml
new file mode 100644 (file)
index 0000000..1ba1fe6
--- /dev/null
@@ -0,0 +1,18 @@
+<dataset>
+
+  <!-- Updated -->
+  <file_sources id="101" project_uuid="ABCD" file_uuid="FILE1_UUID"
+                binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
+                created_at="1500000000000" updated_at="1500000000002" data_type="SOURCE" />
+
+  <!-- Not updated because updated_at is not null -->
+  <file_sources id="102" project_uuid="ABCD" file_uuid="FILE2_UUID"
+                binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
+                created_at="1500000000000" updated_at="1500000000000" data_type="SOURCE" />
+
+  <!-- Not updated because on another project -->
+  <file_sources id="103" project_uuid="BCDE" file_uuid="FILE3_UUID"
+                binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
+                created_at="1500000000000" updated_at="0" data_type="SOURCE" />
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update_date_when_updated_date_is_zero.xml b/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update_date_when_updated_date_is_zero.xml
new file mode 100644 (file)
index 0000000..77a1f85
--- /dev/null
@@ -0,0 +1,16 @@
+<dataset>
+
+  <!-- Only this source should be updated -->
+  <file_sources id="101" project_uuid="ABCD" file_uuid="FILE1_UUID"
+                binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
+                created_at="1500000000000" updated_at="0" data_type="SOURCE" />
+
+  <file_sources id="102" project_uuid="ABCD" file_uuid="FILE2_UUID"
+                binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
+                created_at="1500000000000" updated_at="1500000000000" data_type="SOURCE" />
+
+  <file_sources id="103" project_uuid="BCDE" file_uuid="FILE3_UUID"
+                binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
+                created_at="1500000000000" updated_at="0" data_type="SOURCE" />
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/user/UserGroupDaoTest/delete_members_by_group_id-result.xml b/sonar-db/src/test/resources/org/sonar/db/user/UserGroupDaoTest/delete_members_by_group_id-result.xml
new file mode 100644 (file)
index 0000000..edac414
--- /dev/null
@@ -0,0 +1,6 @@
+<dataset>
+
+  <groups_users user_id="1" group_id="2"/>
+  <groups_users user_id="2" group_id="2"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/user/UserGroupDaoTest/delete_members_by_group_id.xml b/sonar-db/src/test/resources/org/sonar/db/user/UserGroupDaoTest/delete_members_by_group_id.xml
new file mode 100644 (file)
index 0000000..2430e53
--- /dev/null
@@ -0,0 +1,8 @@
+<dataset>
+
+  <groups_users user_id="1" group_id="1"/>
+  <groups_users user_id="2" group_id="1"/>
+  <groups_users user_id="1" group_id="2"/>
+  <groups_users user_id="2" group_id="2"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/user/UserGroupDaoTest/insert-result.xml b/sonar-db/src/test/resources/org/sonar/db/user/UserGroupDaoTest/insert-result.xml
new file mode 100644 (file)
index 0000000..2e5bb1a
--- /dev/null
@@ -0,0 +1,5 @@
+<dataset>
+
+  <groups_users user_id="1" group_id="2"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/jpa/dao/ProfilesDaoTest/shouldGetProfiles.xml b/sonar-db/src/test/resources/org/sonar/jpa/dao/ProfilesDaoTest/shouldGetProfiles.xml
deleted file mode 100644 (file)
index aeb851b..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<dataset>
-
-  <rules_profiles id="1" name="profile one" language="java" is_default="[false]"/>
-  <rules_profiles id="2" name="profile two" language="java" is_default="[false]"/>
-  <rules_profiles id="3" name="profile three" language="plsql" is_default="[false]"/>
-
-</dataset>
\ No newline at end of file