diff options
331 files changed, 1612 insertions, 2142 deletions
diff --git a/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/PersistFileSourcesStepTest.java b/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/PersistFileSourcesStepTest.java index d520fba19e0..f9ecc562ee9 100644 --- a/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/PersistFileSourcesStepTest.java +++ b/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/PersistFileSourcesStepTest.java @@ -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; diff --git a/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/SourceDbBenchmarkTest.java b/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/SourceDbBenchmarkTest.java index 1bef6b936d8..9fd6dceb0cc 100644 --- a/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/SourceDbBenchmarkTest.java +++ b/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/SourceDbBenchmarkTest.java @@ -19,6 +19,11 @@ */ 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(); diff --git a/server/sonar-server/src/main/java/org/sonar/core/computation/dbcleaner/ProjectCleaner.java b/server/sonar-server/src/main/java/org/sonar/core/computation/dbcleaner/ProjectCleaner.java index b8dc2920284..0c756dcf18e 100644 --- a/server/sonar-server/src/main/java/org/sonar/core/computation/dbcleaner/ProjectCleaner.java +++ b/server/sonar-server/src/main/java/org/sonar/core/computation/dbcleaner/ProjectCleaner.java @@ -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/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/activity/db/package-info.java deleted file mode 100644 index 302c555ca29..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/activity/db/package-info.java +++ /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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityResultSetIterator.java b/server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityResultSetIterator.java index df6fbf59c8a..afef3531195 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityResultSetIterator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityResultSetIterator.java @@ -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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentCleanerService.java b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentCleanerService.java index b318762647f..44550420d40 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentCleanerService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentCleanerService.java @@ -20,22 +20,22 @@ 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()); diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentDao.java b/server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentDao.java index 85d7feccbc1..b0aa30c56a2 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentDao.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentDao.java @@ -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 index 0ec4e5f9703..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentIndexDao.java +++ /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/computation/ReportQueue.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ReportQueue.java index cb08dcf7b24..b644aa490bb 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/ReportQueue.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/ReportQueue.java @@ -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/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/computation/db/package-info.java deleted file mode 100644 index d34d4927eb3..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/db/package-info.java +++ /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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/SwitchSnapshotStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/SwitchSnapshotStep.java index 659577bb868..6e74b092366 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/SwitchSnapshotStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/SwitchSnapshotStep.java @@ -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 index 760d27657e2..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/dashboard/db/DashboardDao.java +++ /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/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/dashboard/db/package-info.java deleted file mode 100644 index ab56dedec78..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/dashboard/db/package-info.java +++ /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; - diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java b/server/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java index df21adcba65..80c2173af2c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java @@ -19,16 +19,13 @@ */ 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/DbClient.java b/server/sonar-server/src/main/java/org/sonar/server/db/DbClient.java index 9ff76871231..b89b0aa6d67 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/DbClient.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/DbClient.java @@ -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/migrations/MassUpdate.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdate.java index 39793966f9e..725600feff9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdate.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdate.java @@ -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 { diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/ChangeLogMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/ChangeLogMigrationStep.java index 8193233b43d..6d6d82f9e52 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/ChangeLogMigrationStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/ChangeLogMigrationStep.java @@ -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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/FeedQProfileKeysMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/FeedQProfileKeysMigrationStep.java index b9dc3245c7f..cfd0b2532e7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/FeedQProfileKeysMigrationStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/FeedQProfileKeysMigrationStep.java @@ -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. diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationStep.java index 046a8d8d761..394c659fc6b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationStep.java @@ -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 diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationStep.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationStep.java index 441f370a544..63bbbdc43fb 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationStep.java @@ -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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/CopyScmAccountsFromAuthorsToUsers.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/CopyScmAccountsFromAuthorsToUsers.java index f5679a9eef3..751339a6e39 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/CopyScmAccountsFromAuthorsToUsers.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/CopyScmAccountsFromAuthorsToUsers.java @@ -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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/duplication/ws/ShowAction.java b/server/sonar-server/src/main/java/org/sonar/server/duplication/ws/ShowAction.java index 87b696a98b4..ac65f661afe 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/duplication/ws/ShowAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/duplication/ws/ShowAction.java @@ -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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/BulkIndexer.java b/server/sonar-server/src/main/java/org/sonar/server/es/BulkIndexer.java index aaf7c746f40..56352214b12 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/es/BulkIndexer.java +++ b/server/sonar-server/src/main/java/org/sonar/server/es/BulkIndexer.java @@ -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/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/event/db/package-info.java deleted file mode 100644 index b0e26025947..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/event/db/package-info.java +++ /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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/actionplan/ActionPlanService.java b/server/sonar-server/src/main/java/org/sonar/server/issue/actionplan/ActionPlanService.java index 81ad2decc9b..5b065874d05 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/actionplan/ActionPlanService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/actionplan/ActionPlanService.java @@ -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 index 3033fc3de39..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/db/IssueDao.java +++ /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 index 9d25d51cf30..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/db/package-info.java +++ /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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueResultSetIterator.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueResultSetIterator.java index 76de0d82363..6876a231265 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueResultSetIterator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueResultSetIterator.java @@ -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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/persistence/CustomMeasureDao.java b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/persistence/CustomMeasureDao.java index a818880acad..90da55fd8b7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/persistence/CustomMeasureDao.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/persistence/CustomMeasureDao.java @@ -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/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/measure/persistence/package-info.java deleted file mode 100644 index e4c4083d798..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/persistence/package-info.java +++ /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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/metric/persistence/MetricDao.java b/server/sonar-server/src/main/java/org/sonar/server/metric/persistence/MetricDao.java index 01340086029..2fe2cd21c9f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/metric/persistence/MetricDao.java +++ b/server/sonar-server/src/main/java/org/sonar/server/metric/persistence/MetricDao.java @@ -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); diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java index a4f2ab62212..69ca28e06ca 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java @@ -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()); diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java index b6664b71e46..fd526765be7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java @@ -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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java index a5bbb935230..3926fbf095e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java @@ -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/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/source/db/package-info.java deleted file mode 100644 index 83a499f6401..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/source/db/package-info.java +++ /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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineResultSetIterator.java b/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineResultSetIterator.java index cfe8967a8c6..b899a5fa0b7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineResultSetIterator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineResultSetIterator.java @@ -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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/test/CoverageService.java b/server/sonar-server/src/main/java/org/sonar/server/test/CoverageService.java index b454c0bcb77..1c8d1e0b3ec 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/test/CoverageService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/test/CoverageService.java @@ -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 diff --git a/server/sonar-server/src/main/java/org/sonar/server/test/index/TestResultSetIterator.java b/server/sonar-server/src/main/java/org/sonar/server/test/index/TestResultSetIterator.java index c0117b7526e..61af8323129 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/test/index/TestResultSetIterator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/test/index/TestResultSetIterator.java @@ -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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/db/GroupDao.java b/server/sonar-server/src/main/java/org/sonar/server/user/db/GroupDao.java index 5556381a2bd..acedc2aa42c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/db/GroupDao.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/db/GroupDao.java @@ -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/index/UserResultSetIterator.java b/server/sonar-server/src/main/java/org/sonar/server/user/index/UserResultSetIterator.java index c7e834d0e76..22d1111613b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/index/UserResultSetIterator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/index/UserResultSetIterator.java @@ -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 index d8a077df2fa..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/usergroups/package-info.java +++ /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/test/java/org/sonar/core/computation/dbcleaner/ProjectCleanerTest.java b/server/sonar-server/src/test/java/org/sonar/core/computation/dbcleaner/ProjectCleanerTest.java index bf85d76c00b..df018db96bd 100644 --- a/server/sonar-server/src/test/java/org/sonar/core/computation/dbcleaner/ProjectCleanerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/core/computation/dbcleaner/ProjectCleanerTest.java @@ -20,24 +20,29 @@ 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 diff --git a/server/sonar-server/src/test/java/org/sonar/server/activity/ActivityServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/activity/ActivityServiceTest.java index 487c3abcca0..76722086d5f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/activity/ActivityServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/activity/ActivityServiceTest.java @@ -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/batch/IssuesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java index 6a106265a18..fd29bbc3439 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectRepositoryLoaderMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectRepositoryLoaderMediumTest.java index 01c98a28d01..c8cd38afac7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectRepositoryLoaderMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectRepositoryLoaderMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceTest.java index 838ab5af06f..ae711a2e0d1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceTest.java @@ -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); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentDaoTest.java index c0efcd49313..32ed4afe0fe 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentDaoTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentDaoTest.java @@ -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 index c14695e3238..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentIndexDaoTest.java +++ /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/ws/AppActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java index 354b7890351..a12152dd953 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java index 32caf954616..1d5069f921b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java @@ -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))); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/ReportQueueTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/ReportQueueTest.java index b2156df45fa..137eb422086 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/ReportQueueTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/ReportQueueTest.java @@ -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/issue/DebtAggregatorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/issue/DebtAggregatorTest.java index 44af4c3436e..9470ff27082 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/issue/DebtAggregatorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/issue/DebtAggregatorTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/issue/DebtCalculatorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/issue/DebtCalculatorTest.java index cf57d9aa682..db2bd4d1327 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/issue/DebtCalculatorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/issue/DebtCalculatorTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/issue/IssueCounterTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/issue/IssueCounterTest.java index d4f2994eda1..4b957ccceac 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/issue/IssueCounterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/issue/IssueCounterTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/issue/RuleRepositoryImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/issue/RuleRepositoryImplTest.java index a7f5c5fba82..5084e420e1c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/issue/RuleRepositoryImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/issue/RuleRepositoryImplTest.java @@ -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 { diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/issue/RuleTagsCopierTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/issue/RuleTagsCopierTest.java index df0a3d4c9d9..becc308bc91 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/issue/RuleTagsCopierTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/issue/RuleTagsCopierTest.java @@ -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 { diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryImplTest.java index 15c46891992..5d7f8309e1f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryImplTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedPeriodsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedPeriodsStepTest.java index 632569fa956..943f6a67596 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedPeriodsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedPeriodsStepTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/FillMeasuresWithVariationsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/FillMeasuresWithVariationsStepTest.java index 1cdc8389733..79fced156a8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/FillMeasuresWithVariationsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/FillMeasuresWithVariationsStepTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexSourceLinesStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexSourceLinesStepTest.java index 1203f3a8ac2..61384933f6b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexSourceLinesStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexSourceLinesStepTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexTestsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexTestsStepTest.java index ba2491deaa8..a4b020c034a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexTestsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexTestsStepTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistComponentsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistComponentsStepTest.java index abf452c57a4..82c34394825 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistComponentsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistComponentsStepTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationsStepTest.java index 47676ecf0c7..ff2e82e08d7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationsStepTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistEventsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistEventsStepTest.java index a2294bb1530..00b3962dd90 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistEventsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistEventsStepTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java index a425810a066..cb22b25f35e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistIssuesStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistIssuesStepTest.java index 07fea4201d7..eb09904d24c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistIssuesStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistIssuesStepTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java index 7d3ad333d7f..0380c1a868c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest.java index 28a82331bc3..bd95ab9ec83 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistProjectLinksStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistProjectLinksStepTest.java index 5996fc35d22..3c23953d7fa 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistProjectLinksStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistProjectLinksStepTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistSnapshotsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistSnapshotsStepTest.java index d4c583cc739..24a4526ef5c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistSnapshotsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistSnapshotsStepTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistTestsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistTestsStepTest.java index cf96586ebe9..29a9cd66134 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistTestsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistTestsStepTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/SwitchSnapshotStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/SwitchSnapshotStepTest.java index 0e6362328d4..eae3c53a99e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/SwitchSnapshotStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/SwitchSnapshotStepTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ValidateProjectStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ValidateProjectStepTest.java index 6c9d67d28c8..baa9bbd924e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ValidateProjectStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ValidateProjectStepTest.java @@ -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/db/BaseDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/BaseDaoTest.java index 59d860f1dc9..afd5995cef8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/BaseDaoTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/BaseDaoTest.java @@ -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/migrations/BaseDataChangeTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/BaseDataChangeTest.java index 5ae0b495006..49e5bf4a3ff 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/BaseDataChangeTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/BaseDataChangeTest.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v36/ViolationMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v36/ViolationMigrationTest.java index 5d377c2c6fc..0f355a3e7ee 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v36/ViolationMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v36/ViolationMigrationTest.java @@ -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() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v42/CompleteIssueMessageMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v42/CompleteIssueMessageMigrationTest.java index a98a6615f94..c6ee1dfb608 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v42/CompleteIssueMessageMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v42/CompleteIssueMessageMigrationTest.java @@ -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()); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v42/PackageKeysMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v42/PackageKeysMigrationTest.java index 8fa88c87fd2..bb1daab2e9b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v42/PackageKeysMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v42/PackageKeysMigrationTest.java @@ -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()); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigrationStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigrationStepTest.java index be103757c15..58b65c0e626 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigrationStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigrationStepTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigrationStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigrationStepTest.java index f6440896649..0fd6e8ae4aa 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigrationStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/DevelopmentCostMeasuresMigrationStepTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/IssueChangelogMigrationStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/IssueChangelogMigrationStepTest.java index ef4a0d175af..0e6d06c1fe8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/IssueChangelogMigrationStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/IssueChangelogMigrationStepTest.java @@ -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 diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/NotResolvedIssuesOnRemovedComponentsMigrationStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/NotResolvedIssuesOnRemovedComponentsMigrationStepTest.java index 9c2098288fe..9df9e8c62a6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/NotResolvedIssuesOnRemovedComponentsMigrationStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/NotResolvedIssuesOnRemovedComponentsMigrationStepTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/RequirementMeasuresMigrationStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/RequirementMeasuresMigrationStepTest.java index 2a95d9aff1d..faf17f4dd38 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/RequirementMeasuresMigrationStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/RequirementMeasuresMigrationStepTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigrationStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigrationStepTest.java index b50adc14f4d..63f0d0df7f8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigrationStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/TechnicalDebtMeasuresMigrationStepTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/ChangeLogMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/ChangeLogMigrationTest.java index c48f20771e4..0f312ca080e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/ChangeLogMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/ChangeLogMigrationTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/ConvertProfileMeasuresMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/ConvertProfileMeasuresMigrationTest.java index c9823f04f56..7b83ac06d5c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/ConvertProfileMeasuresMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/ConvertProfileMeasuresMigrationTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationTest.java index aca0c351dcb..93a25de9a56 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/FeedQProfileKeysMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/FeedQProfileKeysMigrationTest.java index 770fb78dd87..f54e91d7649 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/FeedQProfileKeysMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/FeedQProfileKeysMigrationTest.java @@ -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 { diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/IssueActionPlanKeyMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/IssueActionPlanKeyMigrationTest.java index 5c0e4ac744a..cc1b1697192 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/IssueActionPlanKeyMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/IssueActionPlanKeyMigrationTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/MeasureDataMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/MeasureDataMigrationTest.java index b863f7fb2d8..315bc16133c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/MeasureDataMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/MeasureDataMigrationTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v45/AddMissingRuleParameterDefaultValuesMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v45/AddMissingRuleParameterDefaultValuesMigrationTest.java index b58f35660f7..fd993bff0bd 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v45/AddMissingRuleParameterDefaultValuesMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v45/AddMissingRuleParameterDefaultValuesMigrationTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v45/DeleteMeasuresOnDeletedProfilesMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v45/DeleteMeasuresOnDeletedProfilesMigrationTest.java index d5455854200..a82f93792fc 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v45/DeleteMeasuresOnDeletedProfilesMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v45/DeleteMeasuresOnDeletedProfilesMigrationTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest.java index f8e732e4346..ef738d505ea 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest.java index cd4c5c60cc1..b9dae4d600b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedFileSourcesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedFileSourcesTest.java index 9460abe4a4a..9abd9a89484 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedFileSourcesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedFileSourcesTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedIssueLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedIssueLongDatesTest.java index 9b2d4983017..889512860f1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedIssueLongDatesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedIssueLongDatesTest.java @@ -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 { diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/InsertProjectsAuthorizationUpdatedAtMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/InsertProjectsAuthorizationUpdatedAtMigrationTest.java index 78e4b4fcb26..760fd7e7058 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/InsertProjectsAuthorizationUpdatedAtMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/InsertProjectsAuthorizationUpdatedAtMigrationTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest.java index 7548811cf62..e5b2cb634b5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/PopulateProjectsUuidColumnsMigrationTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/RemoveSortFieldFromIssueFiltersMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/RemoveSortFieldFromIssueFiltersMigrationTest.java index 50e117e9a3c..fee6b50959a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/RemoveSortFieldFromIssueFiltersMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/RemoveSortFieldFromIssueFiltersMigrationTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest.java index 11f82c5557f..964eac8bba2 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/ReplaceIssueFiltersProjectKeyByUuidTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddIssuesColumnsTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddIssuesColumnsTest.java index 1d275951535..547350d0dc4 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddIssuesColumnsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddIssuesColumnsTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest.java index 611b36302a8..ab3ff130e90 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/AddNewCharacteristicsTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/CopyScmAccountsFromAuthorsToUsersTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/CopyScmAccountsFromAuthorsToUsersTest.java index 425ebef8ddf..794dfd2321c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/CopyScmAccountsFromAuthorsToUsersTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/CopyScmAccountsFromAuthorsToUsersTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedAnalysisReportsLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedAnalysisReportsLongDatesTest.java index c60ff98f2a5..518d9a94818 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedAnalysisReportsLongDatesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedAnalysisReportsLongDatesTest.java @@ -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 { diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedEventsLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedEventsLongDatesTest.java index 996f5541efd..b1356459047 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedEventsLongDatesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedEventsLongDatesTest.java @@ -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() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedFileSourcesBinaryDataTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedFileSourcesBinaryDataTest.java index 050bcd4acb9..fd8f492e278 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedFileSourcesBinaryDataTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedFileSourcesBinaryDataTest.java @@ -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 { diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDatesTest.java index 3dcb9dbd0b3..3d1d9b2ecea 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDatesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDatesTest.java @@ -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 { diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssueComponentUuidsTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssueComponentUuidsTest.java index c7cb885211c..a74873863d6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssueComponentUuidsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssueComponentUuidsTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssueTagsTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssueTagsTest.java index 9ca104a837b..613591cd576 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssueTagsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssueTagsTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssuesLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssuesLongDatesTest.java index cc818e5b5ee..b323eab7401 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssuesLongDatesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssuesLongDatesTest.java @@ -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 { diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedManualMeasuresLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedManualMeasuresLongDatesTest.java index 01007f370f2..66d2dd201f2 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedManualMeasuresLongDatesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedManualMeasuresLongDatesTest.java @@ -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() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSemaphoresLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSemaphoresLongDatesTest.java index 172ea26ba2a..1b16d9ebc93 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSemaphoresLongDatesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSemaphoresLongDatesTest.java @@ -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() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDatesTest.java index bcdeaa85757..0638f9a0f9b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDatesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDatesTest.java @@ -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 { diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedUsersLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedUsersLongDatesTest.java index 25b2d3551c3..4ddebaec50d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedUsersLongDatesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedUsersLongDatesTest.java @@ -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 { diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/RemovePermissionsOnModulesMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/RemovePermissionsOnModulesMigrationTest.java index e004d2c4b7e..9d019b9be00 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/RemovePermissionsOnModulesMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/RemovePermissionsOnModulesMigrationTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/RenameComponentRelatedParamsInIssueFiltersMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/RenameComponentRelatedParamsInIssueFiltersMigrationTest.java index dc27518622e..38993ee081e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/RenameComponentRelatedParamsInIssueFiltersMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/RenameComponentRelatedParamsInIssueFiltersMigrationTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/UpdateProjectsModuleUuidPathTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/UpdateProjectsModuleUuidPathTest.java index 541ee1faf30..d780cf31b98 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/UpdateProjectsModuleUuidPathTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/UpdateProjectsModuleUuidPathTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/AddManualMeasuresComponentUuidColumnTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/AddManualMeasuresComponentUuidColumnTest.java index 03eca8a0adf..3711965faf4 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/AddManualMeasuresComponentUuidColumnTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/AddManualMeasuresComponentUuidColumnTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest.java index d733f25596a..b556338893b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedFileSourcesDataTypeTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedFileSourcesDataTypeTest.java index f39d1e0c688..1f368e5ca3a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedFileSourcesDataTypeTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedFileSourcesDataTypeTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedManualMeasuresComponentUuidTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedManualMeasuresComponentUuidTest.java index ff79022f42a..bb392df7ac8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedManualMeasuresComponentUuidTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedManualMeasuresComponentUuidTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedMetricsBooleansTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedMetricsBooleansTest.java index 078ed7b348d..63c680b6dd8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedMetricsBooleansTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedMetricsBooleansTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest.java index cea982f96ed..b2fcb227d5e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociationTest.java index 75fff962568..0fb93eb8a5c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociationTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/RemoveComponentLibrariesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/RemoveComponentLibrariesTest.java index f6bdb94d675..21b9eab4107 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/RemoveComponentLibrariesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/RemoveComponentLibrariesTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/RemoveSnapshotLibrariesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/RemoveSnapshotLibrariesTest.java index 96bdf99c7fa..51cd6cad239 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/RemoveSnapshotLibrariesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/RemoveSnapshotLibrariesTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/DuplicationsWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/DuplicationsWsTest.java index 6dd6ad0f873..31b90bb972f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/DuplicationsWsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/DuplicationsWsTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java index 0786e0bf6fa..449adfdc1d8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java @@ -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/issue/ActionServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ActionServiceTest.java index 0334d107abc..472ee85a006 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ActionServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ActionServiceTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceMediumTest.java index 9500605c7ef..36d27f3c457 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceMediumTest.java index 99f0bde1609..2b6ea403633 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceTest.java index 808b900ca0e..c4be0fa051c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java index 3f7085ff1a1..b6b3a65ccc6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueTesting.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueTesting.java index e3311a9110a..c2eb0018e3c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueTesting.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueTesting.java @@ -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 { diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/RulesAggregationTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/RulesAggregationTest.java index 2714599bb2c..3eb034fc6af 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/RulesAggregationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/RulesAggregationTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueStorageTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueStorageTest.java index 09c84f75816..5b2b9d9c675 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueStorageTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueStorageTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/actionplan/ActionPlanServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/actionplan/ActionPlanServiceTest.java index c05dfceaa14..81a7ff83114 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/actionplan/ActionPlanServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/actionplan/ActionPlanServiceTest.java @@ -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 index 580336a0833..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/db/IssueDaoTest.java +++ /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"); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java index 1d249d407b2..5da4dd01c17 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java index 05088a66e48..b6daf433d8c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java index 504e22ca63a..c8518c406cd 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java @@ -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/platform/BackendCleanupMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupMediumTest.java index 413da3ae015..6a25d8d283c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java index b4313c5a144..afbb161a5ae 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java index 6d24ca4ee06..4e277b951e5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/GhostsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/GhostsActionTest.java index ab55f9bd35c..ec4712b59e8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/GhostsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/GhostsActionTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/ProvisionedActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/ProvisionedActionTest.java index ed5f5fe242c..8bb35266ebc 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/ProvisionedActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/ProvisionedActionTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleBackendMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleBackendMediumTest.java index 7ec9a26b61c..8cc6afdc0c9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleBackendMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleBackendMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java index 39a914313ce..041eac72829 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonMediumTest.java index c133a198f26..0662f249453 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java index 1fe25bf4f5e..0ca036e8e3d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java index cbf48ac91be..fb36be893ea 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileServiceMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileServiceMediumTest.java index 549328c7e63..51f79e99c98 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileServiceMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileServiceMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java index 1aeeeee45d0..5b2d52de134 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java index c145248e8cf..1378b15e00a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderMediumTest.java index 727a15dae87..c512eda67be 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java index 0ee1ca13275..6a0ade0a893 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleBackendMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleBackendMediumTest.java index c93de49e8cb..d2e8b506936 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleBackendMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleBackendMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleCreatorMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleCreatorMediumTest.java index c0622369a39..19abfcac3d2 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleCreatorMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleCreatorMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleDeleterMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleDeleterMediumTest.java index 7c618e5f3f1..d9831030d9e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleDeleterMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleDeleterMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleServiceMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleServiceMediumTest.java index 290b86d2f21..e540087388a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleServiceMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleServiceMediumTest.java @@ -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/RuleUpdaterMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterMediumTest.java index 5c5d2b9e40e..7e8de30fc8a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexMediumTest.java index d4d85f431ba..688f5967297 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java index be4ad2c558a..4145b41208c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsMediumTest.java index bbdb3340c0a..9cc24440ba4 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java index 1798f42cb9a..3717910d88d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java index aefeea4bd49..35229551239 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/SourceServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/source/SourceServiceTest.java index 256f2206e3b..ace7b68352c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/source/SourceServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/source/SourceServiceTest.java @@ -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/index/SourceLineResultSetIteratorTest.java b/server/sonar-server/src/test/java/org/sonar/server/source/index/SourceLineResultSetIteratorTest.java index ea481ab7f11..8d927b7b7be 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/source/index/SourceLineResultSetIteratorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/source/index/SourceLineResultSetIteratorTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/ws/HashActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/source/ws/HashActionTest.java index 85bb53dacd8..8e848028297 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/source/ws/HashActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/source/ws/HashActionTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/startup/RenameIssueWidgetsTest.java b/server/sonar-server/src/test/java/org/sonar/server/startup/RenameIssueWidgetsTest.java index 6eb2e705d6c..dc5e60c7c0b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/startup/RenameIssueWidgetsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/startup/RenameIssueWidgetsTest.java @@ -19,24 +19,23 @@ */ 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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/test/CoverageServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/test/CoverageServiceTest.java index 3a10470bd05..447158852ba 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/test/CoverageServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/test/CoverageServiceTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/test/index/TestResultSetIteratorTest.java b/server/sonar-server/src/test/java/org/sonar/server/test/index/TestResultSetIteratorTest.java index 7e6e9e9bac8..b144a107620 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/test/index/TestResultSetIteratorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/test/index/TestResultSetIteratorTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java index 7a29f2c9916..55332a06cc2 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java index 531c7454b98..129b04fbd31 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java @@ -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/ws/ChangePasswordActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java index fb7d43a9ba7..799f08c055b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java index 8f2dec21f98..ba7b24895e9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/GroupsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/GroupsActionTest.java index fcebfae115f..a9706d90a29 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/GroupsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/GroupsActionTest.java @@ -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 { diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java index 167d9104766..9ff7ac2f9b1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java index f8b8dc24c94..a69e8f94612 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/AddUserActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/AddUserActionTest.java index 8c485f96142..bda2bf1b2ad 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/AddUserActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/AddUserActionTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java index 9a968201f4e..1d081d61fc3 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/RemoveUserActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/RemoveUserActionTest.java index 4ea662d56ff..e247b1c638a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/RemoveUserActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/RemoveUserActionTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/SearchActionTest.java index 1b0c32aa153..c4652ddb63c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/SearchActionTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UpdateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UpdateActionTest.java index ddf0684c8ec..b1a19799695 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UpdateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UpdateActionTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UsersActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UsersActionTest.java index 3f0e123f116..0976291ae78 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UsersActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UsersActionTest.java @@ -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/view/index/ViewIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java index a8fe4fd41c0..848293f400c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java @@ -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/db/ResultSetIteratorTest/feed.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/ResultSetIteratorTest/feed.xml deleted file mode 100644 index f072b93cb9d..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/ResultSetIteratorTest/feed.xml +++ /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/main/java/org/sonar/server/util/ProgressLogger.java b/sonar-core/src/main/java/org/sonar/core/util/ProgressLogger.java index a159389a22b..c77da8eefc9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/util/ProgressLogger.java +++ b/sonar-core/src/main/java/org/sonar/core/util/ProgressLogger.java @@ -17,15 +17,13 @@ * 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; +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. @@ -108,7 +106,7 @@ public class ProgressLogger { private void log() { long current = counter.get(); - logger.info(String.format("%d %s processed (%d items/sec)", current, pluralLabel, 1000 * (current-previousCounter) / periodMs)); + 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/sonar-core/src/main/java/org/sonar/core/util/Slug.java index 60b89d5f3e5..47e820d98f5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/util/Slug.java +++ b/sonar-core/src/main/java/org/sonar/core/util/Slug.java @@ -17,7 +17,7 @@ * 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; +package org.sonar.core.util; import java.text.Normalizer; import java.util.Locale; diff --git a/server/sonar-server/src/test/java/org/sonar/server/util/ProgressLoggerTest.java b/sonar-core/src/test/java/org/sonar/core/util/ProgressLoggerTest.java index 2ffd1a93d64..ecbaee63bef 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/util/ProgressLoggerTest.java +++ b/sonar-core/src/test/java/org/sonar/core/util/ProgressLoggerTest.java @@ -17,15 +17,17 @@ * 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; +package org.sonar.core.util; +import java.util.concurrent.atomic.AtomicLong; 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.*; +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 { diff --git a/server/sonar-server/src/test/java/org/sonar/server/util/SlugTest.java b/sonar-core/src/test/java/org/sonar/core/util/SlugTest.java index c2fe1f333b1..5e45bb86112 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/util/SlugTest.java +++ b/sonar-core/src/test/java/org/sonar/core/util/SlugTest.java @@ -17,7 +17,7 @@ * 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; +package org.sonar.core.util; import org.junit.Test; 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 index 6a3ccd83029..00000000000 --- a/sonar-db/src/main/java/org/sonar/batch/index/ResourceCopy.java +++ /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 index 55dc4912649..00000000000 --- a/sonar-db/src/main/java/org/sonar/core/issue/db/package-info.java +++ /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; - diff --git a/sonar-db/src/main/java/org/sonar/core/timemachine/Periods.java b/sonar-db/src/main/java/org/sonar/core/timemachine/Periods.java index 2d16c7137d0..9a70977c140 100644 --- a/sonar-db/src/main/java/org/sonar/core/timemachine/Periods.java +++ b/sonar-db/src/main/java/org/sonar/core/timemachine/Periods.java @@ -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/component/ComponentIndexMapper.java b/sonar-db/src/main/java/org/sonar/db/AbstractDao.java index 44eafac3a24..245f0e87ec9 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ComponentIndexMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/AbstractDao.java @@ -17,13 +17,25 @@ * 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; -package org.sonar.db.component; +import org.sonar.api.utils.System2; -import java.util.List; -import org.apache.ibatis.annotations.Param; +public abstract class AbstractDao implements Dao { -public interface ComponentIndexMapper { + private final MyBatis myBatis; + private final System2 system2; - List<Long> selectProjectIdsFromQueryAndViewOrSubViewUuid(@Param("query") String query, @Param("viewUuidQuery") String viewUuidQuery); + public AbstractDao(MyBatis myBatis, System2 system2) { + this.myBatis = myBatis; + this.system2 = system2; + } + + protected MyBatis myBatis() { + return myBatis; + } + + protected long now() { + return system2.now(); + } } diff --git a/sonar-db/src/main/java/org/sonar/db/DaoUtils.java b/sonar-db/src/main/java/org/sonar/db/DaoUtils.java index 5c0d3269e3c..7e3773f2b0d 100644 --- a/sonar-db/src/main/java/org/sonar/db/DaoUtils.java +++ b/sonar-db/src/main/java/org/sonar/db/DaoUtils.java @@ -19,19 +19,22 @@ */ 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/server/sonar-server/src/main/java/org/sonar/server/db/DatabaseChecker.java b/sonar-db/src/main/java/org/sonar/db/DatabaseChecker.java index 61659ffe74c..31dc571008f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/DatabaseChecker.java +++ b/sonar-db/src/main/java/org/sonar/db/DatabaseChecker.java @@ -17,23 +17,19 @@ * 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; +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.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; diff --git a/sonar-db/src/main/java/org/sonar/db/DatabaseUtils.java b/sonar-db/src/main/java/org/sonar/db/DatabaseUtils.java index 28ac5923b72..6d74d2474cc 100644 --- a/sonar-db/src/main/java/org/sonar/db/DatabaseUtils.java +++ b/sonar-db/src/main/java/org/sonar/db/DatabaseUtils.java @@ -19,17 +19,24 @@ */ 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 index 00000000000..92cbd39c2c5 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/DbClient2.java @@ -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); + } +} diff --git a/sonar-db/src/main/java/org/sonar/db/DefaultDatabase.java b/sonar-db/src/main/java/org/sonar/db/DefaultDatabase.java index c5e5e1c12b8..47db0259f00 100644 --- a/sonar-db/src/main/java/org/sonar/db/DefaultDatabase.java +++ b/sonar-db/src/main/java/org/sonar/db/DefaultDatabase.java @@ -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); } } diff --git a/sonar-db/src/main/java/org/sonar/db/MyBatis.java b/sonar-db/src/main/java/org/sonar/db/MyBatis.java index a6aa01cbc4f..5926def8753 100644 --- a/sonar-db/src/main/java/org/sonar/db/MyBatis.java +++ b/sonar-db/src/main/java/org/sonar/db/MyBatis.java @@ -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); @@ -277,14 +279,6 @@ public class MyBatis { } /** - * @deprecated since 4.4. Replaced by <code>openSession(true)</code>. - */ - @Deprecated - public BatchSession openBatchSession() { - return (BatchSession) openSession(true); - } - - /** * @since 4.4 */ public DbSession openSession(boolean batch) { @@ -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/server/sonar-server/src/main/java/org/sonar/server/db/ResultSetIterator.java b/sonar-db/src/main/java/org/sonar/db/ResultSetIterator.java index ec5fa2a5299..e96a9577141 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/ResultSetIterator.java +++ b/sonar-db/src/main/java/org/sonar/db/ResultSetIterator.java @@ -17,7 +17,7 @@ * 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; +package org.sonar.db; import org.apache.commons.dbutils.DbUtils; diff --git a/server/sonar-server/src/main/java/org/sonar/server/activity/db/ActivityDao.java b/sonar-db/src/main/java/org/sonar/db/activity/ActivityDao.java index c2043ce16ba..25b7539beba 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/activity/db/ActivityDao.java +++ b/sonar-db/src/main/java/org/sonar/db/activity/ActivityDao.java @@ -17,31 +17,22 @@ * 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; +package org.sonar.db.activity; -import org.sonar.api.server.ServerSide; +import java.util.Date; 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.AbstractDao; 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 class ActivityDao extends AbstractDao { public ActivityDao(MyBatis mybatis, System2 system) { - this.mybatis = mybatis; - this.system = system; + super(mybatis, system); } public void insert(ActivityDto dto) { - DbSession session = mybatis.openSession(false); + DbSession session = myBatis().openSession(false); try { insert(session, dto); session.commit(); @@ -51,7 +42,7 @@ public class ActivityDao implements Dao { } public void insert(DbSession session, ActivityDto dto) { - dto.setCreatedAt(new Date(system.now())); + dto.setCreatedAt(new Date(now())); session.getMapper(ActivityMapper.class).insert(dto); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentLinkDao.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentLinkDao.java index 18662e8d9c2..9c4f2940936 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentLinkDao.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentLinkDao.java @@ -18,29 +18,24 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.component.db; +package org.sonar.db.component; -import org.sonar.api.server.ServerSide; -import org.sonar.db.component.ComponentLinkDto; -import org.sonar.db.component.ComponentLinkMapper; +import java.util.List; 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 insert(DbSession session, ComponentLinkDto dto) { + session.getMapper(ComponentLinkMapper.class).insert(dto); } - public void update(DbSession session, ComponentLinkDto item) { - session.getMapper(ComponentLinkMapper.class).update(item); + public void update(DbSession session, ComponentLinkDto dto) { + session.getMapper(ComponentLinkMapper.class).update(dto); } public void delete(DbSession session, long id) { diff --git a/sonar-db/src/main/java/org/sonar/db/component/ResourceDao.java b/sonar-db/src/main/java/org/sonar/db/component/ResourceDao.java index 2ebd03ec015..80addc6dd54 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ResourceDao.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ResourceDao.java @@ -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); } } diff --git a/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerDao.java b/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerDao.java index 6a61ef714e6..827ece8fd1b 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerDao.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerDao.java @@ -19,16 +19,19 @@ */ 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); diff --git a/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerMapper.java b/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerMapper.java index ecbacc7da82..a0cb17b2ccf 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerMapper.java @@ -19,8 +19,13 @@ */ 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); diff --git a/sonar-db/src/main/java/org/sonar/db/component/ResourceKeyUpdaterDao.java b/sonar-db/src/main/java/org/sonar/db/component/ResourceKeyUpdaterDao.java index 6441c88df37..78217f48edd 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ResourceKeyUpdaterDao.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ResourceKeyUpdaterDao.java @@ -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/server/sonar-server/src/main/java/org/sonar/server/component/db/SnapshotDao.java b/sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java index 4be141c5a03..d23eeb5a934 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/db/SnapshotDao.java +++ b/sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java @@ -18,7 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.component.db; +package org.sonar.db.component; import com.google.common.base.Strings; import com.google.common.collect.Lists; @@ -27,24 +27,20 @@ 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) { + public SnapshotDto selectNullableById(DbSession session, long id) { return mapper(session).selectByKey(id); } - public SnapshotDto selectById(DbSession session, Long key) { - SnapshotDto value = selectNullableById(session, key); + public SnapshotDto selectById(DbSession session, long id) { + SnapshotDto value = selectNullableById(session, id); if (value == null) { - throw new NotFoundException(String.format("Key '%s' not found", key)); + throw new IllegalArgumentException(String.format("Snapshot id does not exist: %d", id)); } return value; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/db/AnalysisReportDao.java b/sonar-db/src/main/java/org/sonar/db/compute/AnalysisReportDao.java index 6bb723732c6..d805044aae6 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/db/AnalysisReportDao.java +++ b/sonar-db/src/main/java/org/sonar/db/compute/AnalysisReportDao.java @@ -18,7 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.computation.db; +package org.sonar.db.compute; import com.google.common.annotations.VisibleForTesting; import org.sonar.api.utils.System2; diff --git a/sonar-db/src/main/java/org/sonar/db/dashboard/ActiveDashboardDao.java b/sonar-db/src/main/java/org/sonar/db/dashboard/ActiveDashboardDao.java index 8463da58cfa..c29f495047e 100644 --- a/sonar-db/src/main/java/org/sonar/db/dashboard/ActiveDashboardDao.java +++ b/sonar-db/src/main/java/org/sonar/db/dashboard/ActiveDashboardDao.java @@ -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; diff --git a/sonar-db/src/main/java/org/sonar/db/dashboard/DashboardDao.java b/sonar-db/src/main/java/org/sonar/db/dashboard/DashboardDao.java index 40b151e7ec9..4462c1c24c8 100644 --- a/sonar-db/src/main/java/org/sonar/db/dashboard/DashboardDao.java +++ b/sonar-db/src/main/java/org/sonar/db/dashboard/DashboardDao.java @@ -19,8 +19,11 @@ */ 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/server/sonar-server/src/main/java/org/sonar/server/dashboard/db/WidgetDao.java b/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetDao.java index b44bb15dd75..dec981655e0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/dashboard/db/WidgetDao.java +++ b/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetDao.java @@ -17,7 +17,7 @@ * 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; +package org.sonar.db.dashboard; import java.util.Collection; import org.sonar.db.dashboard.WidgetDto; diff --git a/server/sonar-server/src/main/java/org/sonar/server/dashboard/db/WidgetPropertyDao.java b/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetPropertyDao.java index 5aad93e8aad..0102d3338a0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/dashboard/db/WidgetPropertyDao.java +++ b/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetPropertyDao.java @@ -17,16 +17,15 @@ * 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; +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.dashboard.WidgetPropertyDto; -import org.sonar.db.dashboard.WidgetPropertyMapper; 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; @@ -76,7 +75,7 @@ public class WidgetPropertyDao implements Dao { } public void deleteByWidgetIds(final DbSession session, List<Long> widgetIdsWithPropertiesToDelete) { - DaoUtils.executeLargeInputs(widgetIdsWithPropertiesToDelete, new Function<List<Long>, List<Void>>() { + DatabaseUtils.executeLargeInputs(widgetIdsWithPropertiesToDelete, new Function<List<Long>, List<Void>>() { @Override public List<Void> apply(List<Long> input) { mapper(session).deleteByWidgetIds(input); diff --git a/sonar-db/src/main/java/org/sonar/db/duplication/DuplicationDao.java b/sonar-db/src/main/java/org/sonar/db/duplication/DuplicationDao.java index 25690f35569..94d7ef81c73 100644 --- a/sonar-db/src/main/java/org/sonar/db/duplication/DuplicationDao.java +++ b/sonar-db/src/main/java/org/sonar/db/duplication/DuplicationDao.java @@ -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/server/sonar-server/src/main/java/org/sonar/server/event/db/EventDao.java b/sonar-db/src/main/java/org/sonar/db/event/EventDao.java index ede3edb2483..0f58097ab35 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/event/db/EventDao.java +++ b/sonar-db/src/main/java/org/sonar/db/event/EventDao.java @@ -18,17 +18,12 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.event.db; +package org.sonar.db.event; -import org.sonar.api.server.ServerSide; -import org.sonar.db.event.EventDto; -import org.sonar.db.event.EventMapper; +import java.util.List; 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) { diff --git a/sonar-db/src/main/java/org/sonar/db/issue/ActionPlanDao.java b/sonar-db/src/main/java/org/sonar/db/issue/ActionPlanDao.java index bb63a3c9b90..5c061ad2407 100644 --- a/sonar-db/src/main/java/org/sonar/db/issue/ActionPlanDao.java +++ b/sonar-db/src/main/java/org/sonar/db/issue/ActionPlanDao.java @@ -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; diff --git a/sonar-db/src/main/java/org/sonar/db/issue/ActionPlanStatsDao.java b/sonar-db/src/main/java/org/sonar/db/issue/ActionPlanStatsDao.java index dfd4192922b..4d653374b5c 100644 --- a/sonar-db/src/main/java/org/sonar/db/issue/ActionPlanStatsDao.java +++ b/sonar-db/src/main/java/org/sonar/db/issue/ActionPlanStatsDao.java @@ -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 { diff --git a/sonar-db/src/main/java/org/sonar/db/issue/IssueDao.java b/sonar-db/src/main/java/org/sonar/db/issue/IssueDao.java index edc89f9c267..cecd0fe0f08 100644 --- a/sonar-db/src/main/java/org/sonar/db/issue/IssueDao.java +++ b/sonar-db/src/main/java/org/sonar/db/issue/IssueDao.java @@ -20,12 +20,16 @@ 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); } diff --git a/sonar-db/src/main/java/org/sonar/db/issue/IssueFilterFavouriteDao.java b/sonar-db/src/main/java/org/sonar/db/issue/IssueFilterFavouriteDao.java index f9de1a19963..7f1f06ce324 100644 --- a/sonar-db/src/main/java/org/sonar/db/issue/IssueFilterFavouriteDao.java +++ b/sonar-db/src/main/java/org/sonar/db/issue/IssueFilterFavouriteDao.java @@ -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/server/sonar-server/src/main/java/org/sonar/server/measure/persistence/MeasureDao.java b/sonar-db/src/main/java/org/sonar/db/measure/MeasureDao.java index 5f0660b7dd5..ff4b710d9ca 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/persistence/MeasureDao.java +++ b/sonar-db/src/main/java/org/sonar/db/measure/MeasureDao.java @@ -18,7 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.measure.persistence; +package org.sonar.db.measure; import com.google.common.base.Function; import com.google.common.collect.Lists; @@ -26,16 +26,12 @@ 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.DatabaseUtils; import org.sonar.db.DbSession; +import org.sonar.db.component.SnapshotDto; -@ServerSide public class MeasureDao implements Dao { public boolean existsByKey(DbSession session, String componentKey, String metricKey) { @@ -48,7 +44,7 @@ public class MeasureDao implements Dao { } public List<MeasureDto> findByComponentKeyAndMetricKeys(final DbSession session, final String componentKey, List<String> metricKeys) { - return DaoUtils.executeLargeInputs(metricKeys, new Function<List<String>, List<MeasureDto>>() { + return DatabaseUtils.executeLargeInputs(metricKeys, new Function<List<String>, List<MeasureDto>>() { @Override public List<MeasureDto> apply(List<String> keys) { return mapper(session).selectByComponentAndMetrics(componentKey, keys); @@ -58,7 +54,7 @@ public class MeasureDao implements Dao { 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>>() { + 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, diff --git a/sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterDao.java b/sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterDao.java index 50d0bad2f53..8b5981caa45 100644 --- a/sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterDao.java +++ b/sonar-db/src/main/java/org/sonar/db/measure/MeasureFilterDao.java @@ -20,9 +20,10 @@ 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) { diff --git a/sonar-db/src/main/java/org/sonar/db/notification/NotificationQueueDao.java b/sonar-db/src/main/java/org/sonar/db/notification/NotificationQueueDao.java index b82ba01dd09..6fc69f7818e 100644 --- a/sonar-db/src/main/java/org/sonar/db/notification/NotificationQueueDao.java +++ b/sonar-db/src/main/java/org/sonar/db/notification/NotificationQueueDao.java @@ -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; diff --git a/sonar-db/src/main/java/org/sonar/db/permission/PermissionDao.java b/sonar-db/src/main/java/org/sonar/db/permission/PermissionDao.java index e6a1508e222..e18bdbbcb57 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/PermissionDao.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/PermissionDao.java @@ -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"; diff --git a/sonar-db/src/main/java/org/sonar/db/property/PropertiesDao.java b/sonar-db/src/main/java/org/sonar/db/property/PropertiesDao.java index cb1a63adbe3..c69532dc8ea 100644 --- a/sonar-db/src/main/java/org/sonar/db/property/PropertiesDao.java +++ b/sonar-db/src/main/java/org/sonar/db/property/PropertiesDao.java @@ -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); diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java index a06767ab51c..f4ddf2478b6 100644 --- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java +++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java @@ -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; } diff --git a/sonar-db/src/main/java/org/sonar/db/purge/period/DefaultPeriodCleaner.java b/sonar-db/src/main/java/org/sonar/db/purge/period/DefaultPeriodCleaner.java index ac7bad54d1a..35c03578122 100644 --- a/sonar-db/src/main/java/org/sonar/db/purge/period/DefaultPeriodCleaner.java +++ b/sonar-db/src/main/java/org/sonar/db/purge/period/DefaultPeriodCleaner.java @@ -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 index 24efe187dd7..00000000000 --- a/sonar-db/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java +++ /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(); - } - } -} diff --git a/sonar-db/src/main/java/org/sonar/db/rule/RuleDao.java b/sonar-db/src/main/java/org/sonar/db/rule/RuleDao.java index 25236bc2bcb..8991c688db6 100644 --- a/sonar-db/src/main/java/org/sonar/db/rule/RuleDao.java +++ b/sonar-db/src/main/java/org/sonar/db/rule/RuleDao.java @@ -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; diff --git a/sonar-db/src/main/java/org/sonar/db/semaphore/SemaphoreDao.java b/sonar-db/src/main/java/org/sonar/db/semaphore/SemaphoreDao.java index c34a9b89542..59c89c738b1 100644 --- a/sonar-db/src/main/java/org/sonar/db/semaphore/SemaphoreDao.java +++ b/sonar-db/src/main/java/org/sonar/db/semaphore/SemaphoreDao.java @@ -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/server/sonar-server/src/main/java/org/sonar/server/source/db/FileSourceDao.java b/sonar-db/src/main/java/org/sonar/db/source/FileSourceDao.java index ba1eb205f45..6aeb7d0742b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/source/db/FileSourceDao.java +++ b/sonar-db/src/main/java/org/sonar/db/source/FileSourceDao.java @@ -18,7 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.source.db; +package org.sonar.db.source; import com.google.common.base.Function; import com.google.common.base.Splitter; @@ -31,15 +31,11 @@ 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'); diff --git a/sonar-db/src/main/java/org/sonar/db/user/AuthorDao.java b/sonar-db/src/main/java/org/sonar/db/user/AuthorDao.java index 5837964ce82..56a4eb312fc 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/AuthorDao.java +++ b/sonar-db/src/main/java/org/sonar/db/user/AuthorDao.java @@ -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); diff --git a/sonar-db/src/main/java/org/sonar/db/user/AuthorizationDao.java b/sonar-db/src/main/java/org/sonar/db/user/AuthorizationDao.java index 2a386c1d2b7..c4c8a118dce 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/AuthorizationDao.java +++ b/sonar-db/src/main/java/org/sonar/db/user/AuthorizationDao.java @@ -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) { diff --git a/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDao.java b/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDao.java index a62609259b8..e27e6fe5d98 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDao.java +++ b/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDao.java @@ -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/server/sonar-server/src/main/java/org/sonar/server/user/db/UserGroupDao.java b/sonar-db/src/main/java/org/sonar/db/user/UserGroupDao.java index 413378e86b2..2c5a8665ee6 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/db/UserGroupDao.java +++ b/sonar-db/src/main/java/org/sonar/db/user/UserGroupDao.java @@ -18,12 +18,10 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.user.db; +package org.sonar.db.user; 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 { 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 index 2a308781795..00000000000 --- a/sonar-db/src/main/resources/org/sonar/db/component/ComponentIndexMapper.xml +++ /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> - diff --git a/sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexerMapper.xml b/sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexerMapper.xml index 82afc7fa85d..b9a10673e3c 100644 --- a/sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexerMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexerMapper.xml @@ -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 diff --git a/sonar-db/src/test/java/org/sonar/db/DaoUtilsTest.java b/sonar-db/src/test/java/org/sonar/db/DaoUtilsTest.java index 24987271dfb..fc7c4b1ef80 100644 --- a/sonar-db/src/test/java/org/sonar/db/DaoUtilsTest.java +++ b/sonar-db/src/test/java/org/sonar/db/DaoUtilsTest.java @@ -19,67 +19,14 @@ */ 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/server/sonar-server/src/test/java/org/sonar/server/db/DatabaseCheckerTest.java b/sonar-db/src/test/java/org/sonar/db/DatabaseCheckerTest.java index da0e53d6808..2902ac122f9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/DatabaseCheckerTest.java +++ b/sonar-db/src/test/java/org/sonar/db/DatabaseCheckerTest.java @@ -17,20 +17,18 @@ * 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; +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.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; @@ -80,7 +78,7 @@ public class DatabaseCheckerTest { new DatabaseChecker(db).start(); // oracle 10 is not supported - db = mockDb(new Oracle(), "10.2.1", "11.2.0.0.1"); + db = mockDb(new Oracle(), "10.2.1", "11.2.0.0.1"); try { new DatabaseChecker(db).start(); fail(); diff --git a/sonar-db/src/test/java/org/sonar/db/DatabaseUtilsTest.java b/sonar-db/src/test/java/org/sonar/db/DatabaseUtilsTest.java index 933e931ac03..1b6acbb3eb2 100644 --- a/sonar-db/src/test/java/org/sonar/db/DatabaseUtilsTest.java +++ b/sonar-db/src/test/java/org/sonar/db/DatabaseUtilsTest.java @@ -19,15 +19,21 @@ */ 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(); + } } diff --git a/sonar-db/src/test/java/org/sonar/db/DbTester.java b/sonar-db/src/test/java/org/sonar/db/DbTester.java index ba428c5cbe8..dfa4e9cfef0 100644 --- a/sonar-db/src/test/java/org/sonar/db/DbTester.java +++ b/sonar-db/src/test/java/org/sonar/db/DbTester.java @@ -20,14 +20,8 @@ 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(); + } } diff --git a/sonar-db/src/test/java/org/sonar/db/MyBatisTest.java b/sonar-db/src/test/java/org/sonar/db/MyBatisTest.java index 194346fe0a0..87922b13faf 100644 --- a/sonar-db/src/test/java/org/sonar/db/MyBatisTest.java +++ b/sonar-db/src/test/java/org/sonar/db/MyBatisTest.java @@ -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/server/sonar-server/src/test/java/org/sonar/server/db/ResultSetIteratorTest.java b/sonar-db/src/test/java/org/sonar/db/ResultSetIteratorTest.java index 3aa7f6a5b73..970f9090fd1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/ResultSetIteratorTest.java +++ b/sonar-db/src/test/java/org/sonar/db/ResultSetIteratorTest.java @@ -17,31 +17,30 @@ * 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; +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.Rule; +import org.junit.ClassRule; import org.junit.Test; import org.junit.experimental.categories.Category; -import org.sonar.db.DbTester; +import org.sonar.api.utils.System2; 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"); + @ClassRule + public static DbTester dbTester = DbTester.createForSchema(System2.INSTANCE, ResultSetIteratorTest.class, "schema.sql"); Connection connection = null; @@ -59,7 +58,7 @@ public class ResultSetIteratorTest { public void create_iterator_from_statement() throws Exception { dbTester.prepareDbUnit(getClass(), "feed.xml"); - PreparedStatement stmt = connection.prepareStatement("select * from fake order by id"); + PreparedStatement stmt = connection.prepareStatement("select * from issues order by id"); FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt); assertThat(iterator.hasNext()).isTrue(); @@ -91,7 +90,7 @@ public class ResultSetIteratorTest { public void iterate_empty_list() throws Exception { dbTester.prepareDbUnit(getClass(), "feed.xml"); - PreparedStatement stmt = connection.prepareStatement("select * from fake where id < 0"); + PreparedStatement stmt = connection.prepareStatement("select * from issues where id < 0"); FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt); assertThat(iterator.hasNext()).isFalse(); @@ -101,7 +100,7 @@ public class ResultSetIteratorTest { public void create_iterator_from_result_set() throws Exception { dbTester.prepareDbUnit(getClass(), "feed.xml"); - PreparedStatement stmt = connection.prepareStatement("select * from fake order by id"); + PreparedStatement stmt = connection.prepareStatement("select * from issues order by id"); ResultSet rs = stmt.executeQuery(); FirstIntColumnIterator iterator = new FirstIntColumnIterator(rs); @@ -116,7 +115,7 @@ public class ResultSetIteratorTest { @Test public void remove_row_is_not_supported() throws Exception { - PreparedStatement stmt = connection.prepareStatement("select * from fake order by id"); + PreparedStatement stmt = connection.prepareStatement("select * from issues order by id"); FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt); try { @@ -133,7 +132,7 @@ public class ResultSetIteratorTest { public void fail_to_read_row() throws Exception { dbTester.prepareDbUnit(getClass(), "feed.xml"); - PreparedStatement stmt = connection.prepareStatement("select * from fake order by id"); + PreparedStatement stmt = connection.prepareStatement("select * from issues order by id"); FailIterator iterator = new FailIterator(stmt); assertThat(iterator.hasNext()).isTrue(); 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 index 00000000000..715ea17af6d --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/TestDb.java @@ -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/server/sonar-server/src/test/java/org/sonar/server/activity/db/ActivityDaoTest.java b/sonar-db/src/test/java/org/sonar/db/activity/ActivityDaoTest.java index bfdf049d5e3..c2135f6e3ac 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/activity/db/ActivityDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/activity/ActivityDaoTest.java @@ -17,19 +17,16 @@ * 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; +package org.sonar.db.activity; -import org.junit.Before; +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.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; @@ -37,16 +34,12 @@ 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); - } + @Rule + public DbTester dbTester = DbTester.create(system); + + ActivityDao sut = dbTester.getDbClient().activityDao(); @Test public void insert() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentLinkDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentLinkDaoTest.java index 68b86c320db..931d4f0c508 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentLinkDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentLinkDaoTest.java @@ -18,51 +18,34 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.component.db; +package org.sonar.db.component; -import org.junit.After; -import org.junit.Before; +import java.util.List; 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.api.utils.System2; 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(); - } + public static DbTester dbTester = DbTester.create(System2.INSTANCE); - @After - public void tearDown() { - session.close(); - } + ComponentLinkDao dao = dbTester.getDbClient().componentLinkDao(); @Test public void select_by_component_uuid() { dbTester.prepareDbUnit(getClass(), "shared.xml"); - List<ComponentLinkDto> links = dao.selectByComponentUuid(session, "ABCD"); + List<ComponentLinkDto> links = dao.selectByComponentUuid(dbTester.getSession(), "ABCD"); assertThat(links).hasSize(2); - links = dao.selectByComponentUuid(session, "BCDE"); + links = dao.selectByComponentUuid(dbTester.getSession(), "BCDE"); assertThat(links).hasSize(1); ComponentLinkDto link = links.get(0); @@ -77,29 +60,29 @@ public class ComponentLinkDaoTest { public void insert() { dbTester.prepareDbUnit(getClass(), "empty.xml"); - dao.insert(session, new ComponentLinkDto() - .setComponentUuid("ABCD") - .setType("homepage") - .setName("Home") - .setHref("http://www.sonarqube.org") + dao.insert(dbTester.getSession(), new ComponentLinkDto() + .setComponentUuid("ABCD") + .setType("homepage") + .setName("Home") + .setHref("http://www.sonarqube.org") ); - session.commit(); + dbTester.getSession().commit(); - dbTester.assertDbUnit(getClass(), "insert-result.xml", new String[]{"id"}, "project_links"); + 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() + dao.update(dbTester.getSession(), new ComponentLinkDto() .setId(1L) .setComponentUuid("ABCD") .setType("homepage") .setName("Home") .setHref("http://www.sonarqube.org") ); - session.commit(); + dbTester.getSession().commit(); dbTester.assertDbUnit(getClass(), "update-result.xml", "project_links"); } @@ -108,8 +91,8 @@ public class ComponentLinkDaoTest { public void delete() { dbTester.prepareDbUnit(getClass(), "delete.xml"); - dao.delete(session, 1L); - session.commit(); + dao.delete(dbTester.getSession(), 1L); + dbTester.getSession().commit(); assertThat(dbTester.countRowsOfTable("project_links")).isEqualTo(0); } diff --git a/sonar-db/src/test/java/org/sonar/db/component/ResourceIndexerDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ResourceIndexerDaoTest.java index 90329d5842b..deb992be365 100644 --- a/sonar-db/src/test/java/org/sonar/db/component/ResourceIndexerDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/component/ResourceIndexerDaoTest.java @@ -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/server/sonar-server/src/test/java/org/sonar/server/component/db/SnapshotDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/SnapshotDaoTest.java index 730542712db..21ec3e349a9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/db/SnapshotDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/component/SnapshotDaoTest.java @@ -18,7 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.component.db; +package org.sonar.db.component; import java.util.Date; import java.util.List; @@ -28,8 +28,6 @@ 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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java b/sonar-db/src/test/java/org/sonar/db/compute/AnalysisReportDaoTest.java index 17480756c21..17bb66813b7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/compute/AnalysisReportDaoTest.java @@ -18,7 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.computation.db; +package org.sonar.db.compute; import org.junit.After; import org.junit.Before; @@ -28,6 +28,7 @@ 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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/dashboard/db/WidgetDaoTest.java b/sonar-db/src/test/java/org/sonar/db/dashboard/WidgetDaoTest.java index 7d8d0595ec4..aa5afd5af14 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/dashboard/db/WidgetDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/dashboard/WidgetDaoTest.java @@ -17,21 +17,19 @@ * 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; +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.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) diff --git a/server/sonar-server/src/test/java/org/sonar/server/event/db/EventDaoTest.java b/sonar-db/src/test/java/org/sonar/db/event/EventDaoTest.java index f30b437f38c..4915c0e2291 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/event/db/EventDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/event/EventDaoTest.java @@ -18,20 +18,18 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.event.db; +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.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) @@ -102,7 +100,7 @@ public class EventDaoTest { ); session.commit(); - dbTester.assertDbUnit(getClass(), "insert-result.xml", new String[]{"id"}, "events"); + dbTester.assertDbUnit(getClass(), "insert-result.xml", new String[] {"id"}, "events"); } @Test diff --git a/sonar-db/src/test/java/org/sonar/db/issue/ActionPlanStatsDaoTest.java b/sonar-db/src/test/java/org/sonar/db/issue/ActionPlanStatsDaoTest.java index a70e1a3d08e..9a083137952 100644 --- a/sonar-db/src/test/java/org/sonar/db/issue/ActionPlanStatsDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/issue/ActionPlanStatsDaoTest.java @@ -21,24 +21,23 @@ 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(); diff --git a/sonar-db/src/test/java/org/sonar/db/issue/IssueDaoTest.java b/sonar-db/src/test/java/org/sonar/db/issue/IssueDaoTest.java index 24f556df1e6..dc64f45d05d 100644 --- a/sonar-db/src/test/java/org/sonar/db/issue/IssueDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/issue/IssueDaoTest.java @@ -20,12 +20,17 @@ 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/server/sonar-server/src/test/java/org/sonar/server/measure/persistence/MeasureDaoTest.java b/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java index 1a797609ef0..9621d6aa945 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/persistence/MeasureDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java @@ -18,7 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.measure.persistence; +package org.sonar.db.measure; import com.google.common.base.Function; import com.google.common.collect.FluentIterable; @@ -31,6 +31,7 @@ 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; diff --git a/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java b/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java index 592e42b406e..11aa33abc18 100644 --- a/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java @@ -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"); } diff --git a/sonar-db/src/test/java/org/sonar/db/purge/period/DefaultPeriodCleanerTest.java b/sonar-db/src/test/java/org/sonar/db/purge/period/DefaultPeriodCleanerTest.java index 1aa9d8aebcb..857b58ed48a 100644 --- a/sonar-db/src/test/java/org/sonar/db/purge/period/DefaultPeriodCleanerTest.java +++ b/sonar-db/src/test/java/org/sonar/db/purge/period/DefaultPeriodCleanerTest.java @@ -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 index 7c3eeaa1d08..00000000000 --- a/sonar-db/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java +++ /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/server/sonar-server/src/test/java/org/sonar/server/rule/RuleTesting.java b/sonar-db/src/test/java/org/sonar/db/rule/RuleTesting.java index d521ead8bb9..1b744886d6f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleTesting.java +++ b/sonar-db/src/test/java/org/sonar/db/rule/RuleTesting.java @@ -17,15 +17,13 @@ * 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; +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.api.server.debt.DebtRemediationFunction; -import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleDto.Format; /** @@ -75,8 +73,8 @@ public class RuleTesting { .setTags(ImmutableSet.of("tag1", "tag2")) .setSystemTags(ImmutableSet.of("systag1", "systag2")) .setLanguage("js") - .setRemediationFunction(DebtRemediationFunction.Type.LINEAR.toString()) - .setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.toString()) + .setRemediationFunction("LINEAR") + .setDefaultRemediationFunction("LINEAR_OFFSET") .setRemediationCoefficient("1h") .setDefaultRemediationCoefficient("5d") .setRemediationOffset("5min") @@ -84,19 +82,19 @@ public class RuleTesting { .setEffortToFixDescription(ruleKey.repository() + "." + ruleKey.rule() + ".effortToFix"); } - public static RuleDto newTemplateRule(RuleKey ruleKey){ + public static RuleDto newTemplateRule(RuleKey ruleKey) { return newDto(ruleKey) .setIsTemplate(true); } - public static RuleDto newCustomRule(RuleDto templateRule){ + 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){ + public static RuleDto newManualRule(String manualKey) { return new RuleDto().setRuleKey(manualKey) .setName("Name " + manualKey) .setRepositoryKey(RuleKey.MANUAL_REPOSITORY_KEY) diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/db/FileSourceDaoTest.java b/sonar-db/src/test/java/org/sonar/db/source/FileSourceDaoTest.java index 2c3e2abcd50..09d7fbcff1b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/source/db/FileSourceDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/source/FileSourceDaoTest.java @@ -18,7 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.source.db; +package org.sonar.db.source; import com.google.common.base.Function; import java.io.IOException; @@ -30,7 +30,6 @@ 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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/db/UserGroupDaoTest.java b/sonar-db/src/test/java/org/sonar/db/user/UserGroupDaoTest.java index a1a6b3d15ef..ff1c8cfecef 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/db/UserGroupDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/user/UserGroupDaoTest.java @@ -18,7 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.user.db; +package org.sonar.db.user; import org.junit.After; import org.junit.Before; @@ -27,7 +27,6 @@ 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) 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 index d4743f578cc..00000000000 --- a/sonar-db/src/test/java/org/sonar/jpa/test/AbstractDbUnitTestCase.java +++ /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 index 64c38fb55ea..00000000000 --- a/sonar-db/src/test/resources/org/sonar/api/database/configuration/DatabaseConfigurationTest/some-properties.xml +++ /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 index 00000000000..e76d538413e --- /dev/null +++ b/sonar-db/src/test/resources/org/sonar/db/ResultSetIteratorTest/feed.xml @@ -0,0 +1,5 @@ +<dataset> + <issues id="10" kee="AB" /> + <issues id="20" kee="CD" /> + <issues id="30" kee="EF" /> +</dataset> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/ResultSetIteratorTest/schema.sql b/sonar-db/src/test/resources/org/sonar/db/ResultSetIteratorTest/schema.sql index 09a292231eb..333bb0e193e 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/ResultSetIteratorTest/schema.sql +++ b/sonar-db/src/test/resources/org/sonar/db/ResultSetIteratorTest/schema.sql @@ -1,4 +1,4 @@ -CREATE TABLE "FAKE" ( +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/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/delete.xml b/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/delete.xml index 8b89e7223ec..8b89e7223ec 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/delete.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/delete.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/empty.xml b/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/empty.xml index 871dedcb5e9..871dedcb5e9 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/empty.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/empty.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/insert-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/insert-result.xml index 8b89e7223ec..8b89e7223ec 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/insert-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/insert-result.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/shared.xml b/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/shared.xml index 33e9449d1dd..33e9449d1dd 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/shared.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/shared.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/update-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/update-result.xml index 8b89e7223ec..8b89e7223ec 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/update-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/update-result.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/update.xml b/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/update.xml index 6b80fc9d01c..6b80fc9d01c 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentLinkDaoTest/update.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ComponentLinkDaoTest/update.xml 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/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/select_project_ids_from_query_and_view_or_sub_view_uuid.xml index aff69473ce1..aff69473ce1 100644 --- 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/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/select_project_ids_from_query_and_view_or_sub_view_uuid.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/empty.xml b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/empty.xml index 871dedcb5e9..871dedcb5e9 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/empty.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/empty.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/insert-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/insert-result.xml index a138d68b188..a138d68b188 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/insert-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/insert-result.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/modules.xml b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/modules.xml index 9ba70bee6f4..9ba70bee6f4 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/modules.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/modules.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/select_previous_version_snapshots.xml b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/select_previous_version_snapshots.xml index 3f56960cd92..3f56960cd92 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/select_previous_version_snapshots.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/select_previous_version_snapshots.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/select_snapshots_by_query.xml b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/select_snapshots_by_query.xml index 1f32010f385..1f32010f385 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/select_snapshots_by_query.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/select_snapshots_by_query.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/shared.xml b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/shared.xml index a52b271da32..a52b271da32 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/shared.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/shared.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/snapshots.xml b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/snapshots.xml index 4c18e257396..4c18e257396 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/snapshots.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/snapshots.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/any-analysis-reports.xml b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/any-analysis-reports.xml index dba17d047a4..dba17d047a4 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/any-analysis-reports.xml +++ b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/any-analysis-reports.xml 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/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/book_available_report_analysis_while_having_one_working_on_another_project.xml index ae28befd603..ae28befd603 100644 --- 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/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/book_available_report_analysis_while_having_one_working_on_another_project.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/empty.xml b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/empty.xml index 871dedcb5e9..871dedcb5e9 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/empty.xml +++ b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/empty.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/insert-result.xml index d25e3641ce9..d25e3641ce9 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/insert-result.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/one_analysis_report.xml b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/one_analysis_report.xml index c38ac125e00..c38ac125e00 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/one_analysis_report.xml +++ b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/one_analysis_report.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/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 index 82f93e9fec5..82f93e9fec5 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/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 diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/pop_oldest_pending.xml b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/pop_oldest_pending.xml index 972fde88fd7..972fde88fd7 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/pop_oldest_pending.xml +++ b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/pop_oldest_pending.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/select.xml b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/select.xml index de9d5b9f330..de9d5b9f330 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/select.xml +++ b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/select.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/three_analysis_reports.xml b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/three_analysis_reports.xml index c1e3284f108..c1e3284f108 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/three_analysis_reports.xml +++ b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/three_analysis_reports.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/truncate-result.xml b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/truncate-result.xml index e573e0c5b06..e573e0c5b06 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/truncate-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/truncate-result.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/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 index 16fb8dc0895..16fb8dc0895 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/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 diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/update-all-to-status-pending.xml b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/update-all-to-status-pending.xml index a630cb4ec4b..a630cb4ec4b 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/update-all-to-status-pending.xml +++ b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/update-all-to-status-pending.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/zip.zip b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/zip.zip Binary files differindex a540bc5b5ca..a540bc5b5ca 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/zip.zip +++ b/sonar-db/src/test/resources/org/sonar/db/compute/AnalysisReportDaoTest/zip.zip diff --git a/server/sonar-server/src/test/resources/org/sonar/server/dashboard/db/WidgetDaoTest/before.xml b/sonar-db/src/test/resources/org/sonar/db/dashboard/WidgetDaoTest/before.xml index a942341e3d4..a942341e3d4 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/dashboard/db/WidgetDaoTest/before.xml +++ b/sonar-db/src/test/resources/org/sonar/db/dashboard/WidgetDaoTest/before.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/delete.xml b/sonar-db/src/test/resources/org/sonar/db/event/EventDaoTest/delete.xml index c22a68ed8e0..c22a68ed8e0 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/delete.xml +++ b/sonar-db/src/test/resources/org/sonar/db/event/EventDaoTest/delete.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/empty.xml b/sonar-db/src/test/resources/org/sonar/db/event/EventDaoTest/empty.xml index 871dedcb5e9..871dedcb5e9 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/empty.xml +++ b/sonar-db/src/test/resources/org/sonar/db/event/EventDaoTest/empty.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/insert-result.xml b/sonar-db/src/test/resources/org/sonar/db/event/EventDaoTest/insert-result.xml index 27a2a24e080..27a2a24e080 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/insert-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/event/EventDaoTest/insert-result.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/shared.xml b/sonar-db/src/test/resources/org/sonar/db/event/EventDaoTest/shared.xml index 0002deec3c2..0002deec3c2 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/shared.xml +++ b/sonar-db/src/test/resources/org/sonar/db/event/EventDaoTest/shared.xml 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 index 00000000000..a052d421f66 --- /dev/null +++ b/sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/find_by_action_plan.xml @@ -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 index 00000000000..154a7a67883 --- /dev/null +++ b/sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/get_by_key.xml @@ -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 index 00000000000..fc1543cb2b9 --- /dev/null +++ b/sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/insert-result.xml @@ -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 index 00000000000..d5959c63659 --- /dev/null +++ b/sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/update-result.xml @@ -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 index 00000000000..9c41f1922cc --- /dev/null +++ b/sonar-db/src/test/resources/org/sonar/db/issue/IssueDaoTest/update.xml @@ -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/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/empty.xml b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/empty.xml index dda18829567..dda18829567 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/empty.xml +++ b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/empty.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/insert-result.xml b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/insert-result.xml index 26c55c5d3c4..26c55c5d3c4 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/insert-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/insert-result.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/past_measures.xml b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures.xml index 1a9eaecf522..1a9eaecf522 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/past_measures.xml +++ b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/past_measures_with_characteristic_id.xml b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_characteristic_id.xml index 7e06f10c94c..7e06f10c94c 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/past_measures_with_characteristic_id.xml +++ b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_characteristic_id.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/past_measures_with_person_id.xml b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_person_id.xml index 47a1c6933e4..47a1c6933e4 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/past_measures_with_person_id.xml +++ b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_person_id.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/past_measures_with_rule_id.xml b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_rule_id.xml index b6ccf49fca2..b6ccf49fca2 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/past_measures_with_rule_id.xml +++ b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_rule_id.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/shared.xml b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/shared.xml index c27311c8d38..c27311c8d38 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MeasureDaoTest/shared.xml +++ b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/shared.xml 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 index 2283bba7d52..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete-result.xml +++ /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 index 617cd7e08b0..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_from_profile-result.xml +++ /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 index a06288e57b6..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_from_rule-result.xml +++ /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 index 900eb2c2874..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_parameter-result.xml +++ /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 index b8aba08833d..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_parameters-result.xml +++ /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 index d1bbff5912e..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_parameters_from_profile_id-result.xml +++ /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 index 47c6ceeac24..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/delete_parameters_from_profile_id.xml +++ /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 index 871dedcb5e9..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/empty.xml +++ /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 index 574cbabdd56..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/insert-result.xml +++ /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 index ed2e17d48d3..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/insert_parameter-result.xml +++ /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 index b6d5461c10d..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/shared.xml +++ /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 index 30111d636a7..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/update-result.xml +++ /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 index 289da2f39f2..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/qualityprofile/ActiveRuleDaoTest/update_parameter-result.xml +++ /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/server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/insert-result.xml b/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/insert-result.xml index 4f347782dca..4f347782dca 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/insert-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/insert-result.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/source/db/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 index 010394a156e..010394a156e 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/source/db/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 diff --git a/server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/shared.xml b/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/shared.xml index 5187ca217af..5187ca217af 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/shared.xml +++ b/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/shared.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/update-result.xml b/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update-result.xml index 8dbe32d946d..8dbe32d946d 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/source/db/FileSourceDaoTest/update-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update-result.xml 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/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update_date_when_updated_date_is_zero-result.xml index 1ba1fe63a55..1ba1fe63a55 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/source/db/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 diff --git a/server/sonar-server/src/test/resources/org/sonar/server/source/db/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 index 77a1f85b06a..77a1f85b06a 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/source/db/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 diff --git a/server/sonar-server/src/test/resources/org/sonar/server/user/db/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 index edac414e636..edac414e636 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/user/db/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 diff --git a/server/sonar-server/src/test/resources/org/sonar/server/user/db/UserGroupDaoTest/delete_members_by_group_id.xml b/sonar-db/src/test/resources/org/sonar/db/user/UserGroupDaoTest/delete_members_by_group_id.xml index 2430e53dd8e..2430e53dd8e 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/user/db/UserGroupDaoTest/delete_members_by_group_id.xml +++ b/sonar-db/src/test/resources/org/sonar/db/user/UserGroupDaoTest/delete_members_by_group_id.xml diff --git a/server/sonar-server/src/test/resources/org/sonar/server/user/db/UserGroupDaoTest/insert-result.xml b/sonar-db/src/test/resources/org/sonar/db/user/UserGroupDaoTest/insert-result.xml index 2e5bb1ada57..2e5bb1ada57 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/user/db/UserGroupDaoTest/insert-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/user/UserGroupDaoTest/insert-result.xml 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 index aeb851beb8e..00000000000 --- a/sonar-db/src/test/resources/org/sonar/jpa/dao/ProfilesDaoTest/shouldGetProfiles.xml +++ /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 |