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;
*/
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;
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 {
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();
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;
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);
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.activity.db;
-
-import org.sonar.api.server.ServerSide;
-import org.sonar.api.utils.System2;
-import org.sonar.db.activity.ActivityDto;
-import org.sonar.db.activity.ActivityMapper;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
-
-import java.util.Date;
-
-@ServerSide
-public class ActivityDao implements Dao {
-
- private final MyBatis mybatis;
- private final System2 system;
-
- public ActivityDao(MyBatis mybatis, System2 system) {
- this.mybatis = mybatis;
- this.system = system;
- }
-
- public void insert(ActivityDto dto) {
- DbSession session = mybatis.openSession(false);
- try {
- insert(session, dto);
- session.commit();
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public void insert(DbSession session, ActivityDto dto) {
- dto.setCreatedAt(new Date(system.now()));
- session.getMapper(ActivityMapper.class).insert(dto);
- }
-
-}
+++ /dev/null
-/*
- * 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;
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;
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 {
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());
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;
@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);
}
}
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);
}
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);
}
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);
+++ /dev/null
-/*
- * 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 + ".%");
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.component.db;
-
-import org.sonar.api.server.ServerSide;
-import org.sonar.db.component.ComponentLinkDto;
-import org.sonar.db.component.ComponentLinkMapper;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-
-import java.util.List;
-
-@ServerSide
-public class ComponentLinkDao implements Dao {
-
- public List<ComponentLinkDto> selectByComponentUuid(DbSession session, String componentUuid) {
- return session.getMapper(ComponentLinkMapper.class).selectByComponentUuid(componentUuid);
- }
-
- public void insert(DbSession session, ComponentLinkDto item) {
- session.getMapper(ComponentLinkMapper.class).insert(item);
- }
-
- public void update(DbSession session, ComponentLinkDto item) {
- session.getMapper(ComponentLinkMapper.class).update(item);
- }
-
- public void delete(DbSession session, long id) {
- session.getMapper(ComponentLinkMapper.class).delete(id);
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.component.db;
-
-import com.google.common.base.Strings;
-import com.google.common.collect.Lists;
-import java.util.Collection;
-import java.util.List;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import org.sonar.api.resources.Scopes;
-import org.sonar.db.component.SnapshotDto;
-import org.sonar.db.component.SnapshotMapper;
-import org.sonar.db.component.SnapshotQuery;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-import org.sonar.server.exceptions.NotFoundException;
-
-public class SnapshotDao implements Dao {
-
- @CheckForNull
- public SnapshotDto selectNullableById(DbSession session, Long id) {
- return mapper(session).selectByKey(id);
- }
-
- public SnapshotDto selectById(DbSession session, Long key) {
- SnapshotDto value = selectNullableById(session, key);
- if (value == null) {
- throw new NotFoundException(String.format("Key '%s' not found", key));
- }
- return value;
- }
-
- @CheckForNull
- public SnapshotDto selectLastSnapshotByComponentId(DbSession session, long componentId) {
- return mapper(session).selectLastSnapshot(componentId);
- }
-
- public List<SnapshotDto> selectSnapshotsByComponentId(DbSession session, long componentId) {
- return mapper(session).selectSnapshotsByQuery(new SnapshotQuery().setComponentId(componentId));
- }
-
- public List<SnapshotDto> selectSnapshotsByQuery(DbSession session, SnapshotQuery query) {
- return mapper(session).selectSnapshotsByQuery(query);
- }
-
- public List<SnapshotDto> selectPreviousVersionSnapshots(DbSession session, long componentId, String lastVersion) {
- return mapper(session).selectPreviousVersionSnapshots(componentId, lastVersion);
- }
-
- public List<SnapshotDto> selectSnapshotAndChildrenOfProjectScope(DbSession session, long snapshotId) {
- return mapper(session).selectSnapshotAndChildrenOfScope(snapshotId, Scopes.PROJECT);
- }
-
- public int updateSnapshotAndChildrenLastFlagAndStatus(DbSession session, SnapshotDto snapshot, boolean isLast, String status) {
- Long rootId = snapshot.getId();
- String path = Strings.nullToEmpty(snapshot.getPath()) + snapshot.getId() + ".%";
- Long pathRootId = snapshot.getRootIdOrSelf();
-
- return mapper(session).updateSnapshotAndChildrenLastFlagAndStatus(rootId, pathRootId, path, isLast, status);
- }
-
- public int updateSnapshotAndChildrenLastFlag(DbSession session, SnapshotDto snapshot, boolean isLast) {
- Long rootId = snapshot.getId();
- String path = Strings.nullToEmpty(snapshot.getPath()) + snapshot.getId() + ".%";
- Long pathRootId = snapshot.getRootIdOrSelf();
-
- return mapper(session).updateSnapshotAndChildrenLastFlag(rootId, pathRootId, path, isLast);
- }
-
- public static boolean isLast(SnapshotDto snapshotTested, @Nullable SnapshotDto previousLastSnapshot) {
- return previousLastSnapshot == null || previousLastSnapshot.getCreatedAt() < snapshotTested.getCreatedAt();
- }
-
- public SnapshotDto insert(DbSession session, SnapshotDto item) {
- mapper(session).insert(item);
- return item;
- }
-
- public void insert(DbSession session, Collection<SnapshotDto> items) {
- for (SnapshotDto item : items) {
- insert(session, item);
- }
- }
-
- public void insert(DbSession session, SnapshotDto item, SnapshotDto... others) {
- insert(session, Lists.asList(item, others));
- }
-
- private SnapshotMapper mapper(DbSession session) {
- return session.getMapper(SnapshotMapper.class);
- }
-}
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;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.computation.db;
-
-import com.google.common.annotations.VisibleForTesting;
-import org.sonar.api.utils.System2;
-import org.sonar.db.compute.AnalysisReportDto;
-import org.sonar.db.compute.AnalysisReportMapper;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-
-import javax.annotation.CheckForNull;
-
-import java.util.List;
-
-import static org.sonar.db.compute.AnalysisReportDto.Status.PENDING;
-import static org.sonar.db.compute.AnalysisReportDto.Status.WORKING;
-
-public class AnalysisReportDao implements Dao {
-
- private System2 system2;
-
- public AnalysisReportDao(System2 system2) {
- this.system2 = system2;
- }
-
- /**
- * Update all rows with: STATUS='PENDING', STARTED_AT=NULL, UPDATED_AT={now}
- */
- public void resetAllToPendingStatus(DbSession session) {
- mapper(session).resetAllToPendingStatus(system2.now());
- }
-
- public void truncate(DbSession session) {
- mapper(session).truncate();
- }
-
- public List<AnalysisReportDto> selectByProjectKey(DbSession session, String projectKey) {
- return mapper(session).selectByProjectKey(projectKey);
- }
-
- @VisibleForTesting
- AnalysisReportDto selectById(DbSession session, long id) {
- return mapper(session).selectById(id);
- }
-
- @CheckForNull
- public AnalysisReportDto pop(DbSession session) {
- List<Long> reportIds = mapper(session).selectAvailables(PENDING, WORKING);
- if (reportIds.isEmpty()) {
- return null;
- }
-
- long reportId = reportIds.get(0);
- return tryToPop(session, reportId);
- }
-
- @VisibleForTesting
- AnalysisReportDto tryToPop(DbSession session, long reportId) {
- AnalysisReportMapper mapper = mapper(session);
- int nbOfReportBooked = mapper.updateWithBookingReport(reportId, system2.now(), PENDING, WORKING);
- if (nbOfReportBooked == 0) {
- return null;
- }
-
- AnalysisReportDto result = mapper.selectById(reportId);
- session.commit();
- return result;
- }
-
- public List<AnalysisReportDto> selectAll(DbSession session) {
- return mapper(session).selectAll();
- }
-
- public AnalysisReportDto insert(DbSession session, AnalysisReportDto report) {
- report.setCreatedAt(system2.now());
- report.setUpdatedAt(system2.now());
- mapper(session).insert(report);
- return report;
- }
-
- public void delete(DbSession session, long id) {
- mapper(session).delete(id);
- }
-
- private AnalysisReportMapper mapper(DbSession session) {
- return session.getMapper(AnalysisReportMapper.class);
- }
-}
+++ /dev/null
-/*
- * 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;
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 {
+++ /dev/null
-/*
- * 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);
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.dashboard.db;
-
-import java.util.Collection;
-import org.sonar.db.dashboard.WidgetDto;
-import org.sonar.db.dashboard.WidgetMapper;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
-
-public class WidgetDao implements Dao {
-
- private MyBatis myBatis;
-
- public WidgetDao(MyBatis myBatis) {
- this.myBatis = myBatis;
- }
-
- public WidgetDto getNullableByKey(Long widgetId) {
- DbSession session = myBatis.openSession(false);
- try {
- return getNullableByKey(session, widgetId);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public WidgetDto getNullableByKey(DbSession session, Long widgetId) {
- return mapper(session).selectById(widgetId);
- }
-
- public WidgetDto update(WidgetDto item) {
- DbSession session = myBatis.openSession(false);
- try {
- return update(session, item);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public WidgetDto update(DbSession session, WidgetDto item) {
- mapper(session).update(item);
- return item;
- }
-
- public Collection<WidgetDto> findByDashboard(DbSession session, long dashboardKey) {
- return mapper(session).selectByDashboard(dashboardKey);
- }
-
- public Collection<WidgetDto> findAll(DbSession session) {
- return mapper(session).selectAll();
- }
-
- private WidgetMapper mapper(DbSession session) {
- return session.getMapper(WidgetMapper.class);
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.dashboard.db;
-
-import com.google.common.base.Function;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import org.sonar.db.dashboard.WidgetPropertyDto;
-import org.sonar.db.dashboard.WidgetPropertyMapper;
-import org.sonar.db.Dao;
-import org.sonar.db.DaoUtils;
-import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
-
-public class WidgetPropertyDao implements Dao {
-
- private final MyBatis myBatis;
-
- public WidgetPropertyDao(MyBatis myBatis) {
- this.myBatis = myBatis;
- }
-
- public WidgetPropertyDto insert(WidgetPropertyDto item) {
- DbSession session = myBatis.openSession(false);
- try {
- return insert(session, item);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public WidgetPropertyDto insert(DbSession session, WidgetPropertyDto item) {
- mapper(session).insert(item);
- return item;
- }
-
- public void insert(DbSession session, Collection<WidgetPropertyDto> items) {
- for (WidgetPropertyDto item : items) {
- insert(session, item);
- }
- }
-
- public WidgetPropertyDto getNullableByKey(Long propertyId) {
- DbSession session = myBatis.openSession(false);
- try {
- return getNullableByKey(session, propertyId);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public WidgetPropertyDto getNullableByKey(DbSession session, Long propertyId) {
- return mapper(session).selectById(propertyId);
- }
-
- public Collection<WidgetPropertyDto> findByDashboard(DbSession session, long dashboardKey) {
- return mapper(session).selectByDashboard(dashboardKey);
- }
-
- public void deleteByWidgetIds(final DbSession session, List<Long> widgetIdsWithPropertiesToDelete) {
- DaoUtils.executeLargeInputs(widgetIdsWithPropertiesToDelete, new Function<List<Long>, List<Void>>() {
- @Override
- public List<Void> apply(List<Long> input) {
- mapper(session).deleteByWidgetIds(input);
- return Arrays.asList();
- }
- });
- }
-
- private WidgetPropertyMapper mapper(DbSession session) {
- return session.getMapper(WidgetPropertyMapper.class);
- }
-}
+++ /dev/null
-/*
- * 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;
-
*/
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;
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;
/**
* @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);
this.system2 = system2;
}
- protected BaseDao(Class<MAPPER> mapperClass, System2 system2) {
- this(null, mapperClass, system2);
- }
-
public String getIndexType() {
return indexDefinition != null ? this.indexDefinition.getIndexType() : null;
}
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());
@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;
}
}
}
- @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) {
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.db;
-
-import com.google.common.base.Throwables;
-import org.apache.commons.dbutils.DbUtils;
-import org.apache.commons.lang.StringUtils;
-import org.picocontainer.Startable;
-import org.sonar.api.server.ServerSide;
-import org.sonar.api.utils.MessageException;
-import org.sonar.api.utils.log.Loggers;
-import org.sonar.db.Database;
-import org.sonar.db.dialect.H2;
-import org.sonar.db.dialect.Oracle;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-
-@ServerSide
-public class DatabaseChecker implements Startable {
-
- public static final int ORACLE_MIN_MAJOR_VERSION = 11;
-
- private final Database db;
-
- public DatabaseChecker(Database db) {
- this.db = db;
- }
-
- @Override
- public void start() {
- try {
- if (H2.ID.equals(db.getDialect().getId())) {
- Loggers.get(DatabaseChecker.class).warn("H2 database should be used for evaluation purpose only");
- } else if (Oracle.ID.equals(db.getDialect().getId())) {
- checkOracleVersion();
- }
- } catch (Exception e) {
- Throwables.propagate(e);
- }
- }
-
- @Override
- public void stop() {
- // nothing to do
- }
-
- private void checkOracleVersion() throws SQLException {
- Connection connection = db.getDataSource().getConnection();
- try {
- // check version of db
- // See http://jira.sonarsource.com/browse/SONAR-6434
- int majorVersion = connection.getMetaData().getDatabaseMajorVersion();
- if (majorVersion < ORACLE_MIN_MAJOR_VERSION) {
- throw MessageException.of(String.format(
- "Unsupported Oracle version: %s. Minimal required version is %d.", connection.getMetaData().getDatabaseProductVersion(), ORACLE_MIN_MAJOR_VERSION));
- }
-
- // check version of driver
- String driverVersion = connection.getMetaData().getDriverVersion();
- String[] parts = StringUtils.split(driverVersion, ".");
- int intVersion = Integer.parseInt(parts[0]) * 100 + Integer.parseInt(parts[1]);
- if (intVersion < 1102) {
- throw MessageException.of(String.format(
- "Unsupported Oracle JDBC driver version: %s. Minimal required version is 11.2.", driverVersion));
- }
-
- } finally {
- DbUtils.closeQuietly(connection);
- }
- }
-
-}
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;
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;
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);
return myBatis.openSession(batch);
}
+ public void closeSession(@Nullable DbSession session) {
+ MyBatis.closeQuietly(session);
+ }
+
public RuleDao ruleDao() {
return ruleDao;
}
return authorDao;
}
- public ComponentIndexDao componentIndexDao() {
+ public ResourceIndexerDao componentIndexDao() {
return componentIndexDao;
}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.db;
-
-import org.apache.commons.dbutils.DbUtils;
-
-import java.io.Closeable;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-/**
- * Forward-only {@link java.util.Iterator} over a {@link java.sql.ResultSet}. Rows are
- * lazily loaded. The underlying ResultSet must be closed by calling the method
- * {@link #close()}
- * <p/>
- * As a safeguard, the ResultSet is automatically closed after the last element has
- * been retrieved via {@link #next()} or {@link #hasNext()} is called (which will return false).
- * This automagic behavior is not enough to remove explicit calls to {@link #close()}
- * from caller methods. Errors raised before end of traversal must still be handled.
- */
-public abstract class ResultSetIterator<E> implements Iterator<E>, Closeable {
-
- private final ResultSet rs;
- private final PreparedStatement stmt;
-
- private volatile boolean didNext = false;
- private volatile boolean hasNext = false;
- private volatile boolean closed = false;
-
- public ResultSetIterator(PreparedStatement stmt) throws SQLException {
- this.stmt = stmt;
- this.rs = stmt.executeQuery();
- }
-
- protected ResultSetIterator(ResultSet rs) {
- this.stmt = null;
- this.rs = rs;
- }
-
- @Override
- public boolean hasNext() {
- if (closed) {
- return false;
- }
- if (!didNext) {
- hasNext = doNextQuietly();
- if (hasNext) {
- didNext = true;
- } else {
- close();
- }
- }
- return hasNext;
- }
-
- @Override
- public E next() {
- if (!hasNext()) {
- close();
- throw new NoSuchElementException();
- }
- try {
- return read(rs);
- } catch (SQLException e) {
- throw new IllegalStateException("Fail to read result set row", e);
- } finally {
- hasNext = doNextQuietly();
- if (!hasNext) {
- close();
- }
- }
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void close() {
- closed = true;
- DbUtils.closeQuietly(rs);
- DbUtils.closeQuietly(stmt);
- }
-
- protected abstract E read(ResultSet rs) throws SQLException;
-
- private boolean doNextQuietly() {
- try {
- return rs.next();
- } catch (SQLException e) {
- throw new IllegalStateException("Fail to read row of JDBC result set", e);
- }
- }
-}
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 {
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;
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.
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
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;
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;
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;
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;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.event.db;
-
-import org.sonar.api.server.ServerSide;
-import org.sonar.db.event.EventDto;
-import org.sonar.db.event.EventMapper;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-
-import java.util.List;
-
-@ServerSide
-public class EventDao implements Dao {
-
- public List<EventDto> selectByComponentUuid(DbSession session, String componentUuid) {
- return session.getMapper(EventMapper.class).selectByComponentUuid(componentUuid);
- }
-
- public void insert(DbSession session, EventDto dto) {
- session.getMapper(EventMapper.class).insert(dto);
- }
-
- public void delete(DbSession session, Long id) {
- session.getMapper(EventMapper.class).delete(id);
- }
-
-}
+++ /dev/null
-/*
- * 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;
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;
+++ /dev/null
-/*
- * 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);
- }
-}
+++ /dev/null
-/*
- * 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;
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;
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;
}
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);
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.measure.persistence;
-
-import com.google.common.base.Function;
-import com.google.common.collect.Lists;
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-import javax.annotation.CheckForNull;
-import org.sonar.api.server.ServerSide;
-import org.sonar.db.component.SnapshotDto;
-import org.sonar.db.measure.MeasureDto;
-import org.sonar.db.measure.MeasureMapper;
-import org.sonar.db.measure.PastMeasureDto;
-import org.sonar.db.Dao;
-import org.sonar.db.DaoUtils;
-import org.sonar.db.DbSession;
-
-@ServerSide
-public class MeasureDao implements Dao {
-
- public boolean existsByKey(DbSession session, String componentKey, String metricKey) {
- return mapper(session).countByComponentAndMetric(componentKey, metricKey) > 0;
- }
-
- @CheckForNull
- public MeasureDto findByComponentKeyAndMetricKey(DbSession session, String componentKey, String metricKey) {
- return mapper(session).selectByComponentAndMetric(componentKey, metricKey);
- }
-
- public List<MeasureDto> findByComponentKeyAndMetricKeys(final DbSession session, final String componentKey, List<String> metricKeys) {
- return DaoUtils.executeLargeInputs(metricKeys, new Function<List<String>, List<MeasureDto>>() {
- @Override
- public List<MeasureDto> apply(List<String> keys) {
- return mapper(session).selectByComponentAndMetrics(componentKey, keys);
- }
- });
- }
-
- public List<PastMeasureDto> selectByComponentUuidAndProjectSnapshotIdAndMetricIds(final DbSession session, final String componentUuid, final long projectSnapshotId,
- Set<Integer> metricIds) {
- return DaoUtils.executeLargeInputs(metricIds, new Function<List<Integer>, List<PastMeasureDto>>() {
- @Override
- public List<PastMeasureDto> apply(List<Integer> ids) {
- return mapper(session).selectByComponentUuidAndProjectSnapshotIdAndStatusAndMetricIds(componentUuid, projectSnapshotId, ids,
- SnapshotDto.STATUS_PROCESSED);
- }
- });
- }
-
- public void insert(DbSession session, MeasureDto measureDto) {
- mapper(session).insert(measureDto);
- }
-
- public void insert(DbSession session, Collection<MeasureDto> items) {
- for (MeasureDto item : items) {
- insert(session, item);
- }
- }
-
- public void insert(DbSession session, MeasureDto item, MeasureDto... others) {
- insert(session, Lists.asList(item, others));
- }
-
- public List<String> selectMetricKeysForSnapshot(DbSession session, long snapshotId) {
- return mapper(session).selectMetricKeysForSnapshot(snapshotId);
- }
-
- private MeasureMapper mapper(DbSession session) {
- return session.getMapper(MeasureMapper.class);
- }
-}
+++ /dev/null
-/*
- * 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;
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
}
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);
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);
}
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);
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;
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;
// users
GroupDao.class,
UserDao.class,
- UserGroupDao.class,
-
- // dashboards
- DashboardDao.class,
- WidgetDao.class,
- WidgetPropertyDao.class,
// rules/qprofiles
RuleNormalizer.class,
// 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());
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;
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;
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;
/**
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.source.db;
-
-import com.google.common.base.Function;
-import com.google.common.base.Splitter;
-import java.io.Reader;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.List;
-import javax.annotation.CheckForNull;
-import org.apache.commons.dbutils.DbUtils;
-import org.apache.commons.io.IOUtils;
-import org.sonar.api.server.ServerSide;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
-import org.sonar.db.source.FileSourceDto;
-import org.sonar.db.source.FileSourceDto.Type;
-import org.sonar.db.source.FileSourceMapper;
-
-@ServerSide
-public class FileSourceDao implements Dao {
-
- private static final Splitter END_OF_LINE_SPLITTER = Splitter.on('\n');
- private final MyBatis mybatis;
-
- public FileSourceDao(MyBatis myBatis) {
- this.mybatis = myBatis;
- }
-
- @CheckForNull
- public FileSourceDto selectSource(String fileUuid) {
- DbSession session = mybatis.openSession(false);
- try {
- return mapper(session).select(fileUuid, Type.SOURCE);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- @CheckForNull
- public FileSourceDto selectTest(String fileUuid) {
- DbSession session = mybatis.openSession(false);
- try {
- return mapper(session).select(fileUuid, Type.TEST);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- @CheckForNull
- public List<String> selectLineHashes(DbSession dbSession, String fileUuid) {
- Connection connection = dbSession.getConnection();
- PreparedStatement pstmt = null;
- ResultSet rs = null;
- try {
- pstmt = connection.prepareStatement("SELECT line_hashes FROM file_sources WHERE file_uuid=? AND data_type=?");
- pstmt.setString(1, fileUuid);
- pstmt.setString(2, Type.SOURCE);
- rs = pstmt.executeQuery();
- if (rs.next()) {
- return END_OF_LINE_SPLITTER.splitToList(rs.getString(1));
- }
- return null;
- } catch (SQLException e) {
- throw new IllegalStateException("Fail to read FILE_SOURCES.LINE_HASHES of file " + fileUuid, e);
- } finally {
- DbUtils.closeQuietly(connection, pstmt, rs);
- }
- }
-
- public <T> void readLineHashesStream(DbSession dbSession, String fileUuid, Function<Reader, T> function) {
- Connection connection = dbSession.getConnection();
- PreparedStatement pstmt = null;
- ResultSet rs = null;
- Reader reader = null;
- try {
- pstmt = connection.prepareStatement("SELECT line_hashes FROM file_sources WHERE file_uuid=? AND data_type=?");
- pstmt.setString(1, fileUuid);
- pstmt.setString(2, Type.SOURCE);
- rs = pstmt.executeQuery();
- if (rs.next()) {
- reader = rs.getCharacterStream(1);
- function.apply(reader);
- }
- } catch (SQLException e) {
- throw new IllegalStateException("Fail to read FILE_SOURCES.LINE_HASHES of file " + fileUuid, e);
- } finally {
- IOUtils.closeQuietly(reader);
- DbUtils.closeQuietly(connection, pstmt, rs);
- }
- }
-
- public void insert(FileSourceDto dto) {
- DbSession session = mybatis.openSession(false);
- try {
- insert(session, dto);
- session.commit();
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public void insert(DbSession session, FileSourceDto dto) {
- mapper(session).insert(dto);
- }
-
- public void update(FileSourceDto dto) {
- DbSession session = mybatis.openSession(false);
- try {
- update(session, dto);
- session.commit();
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public void update(DbSession session, FileSourceDto dto) {
- mapper(session).update(dto);
- }
-
- public void updateDateWhenUpdatedDateIsZero(DbSession session, String projectUuid, long updateDate) {
- mapper(session).updateDateWhenUpdatedDateIsZero(projectUuid, updateDate);
- }
-
- private FileSourceMapper mapper(DbSession session) {
- return session.getMapper(FileSourceMapper.class);
- }
-}
+++ /dev/null
-/*
- * 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;
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;
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
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;
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 = "%";
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.user.db;
-
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-import org.sonar.db.user.UserGroupDto;
-import org.sonar.db.user.UserGroupMapper;
-
-public class UserGroupDao implements Dao {
-
- public UserGroupDto insert(DbSession session, UserGroupDto dto) {
- mapper(session).insert(dto);
- return dto;
- }
-
- public void delete(DbSession session, UserGroupDto dto) {
- mapper(session).delete(dto);
- }
-
- public void deleteMembersByGroupId(DbSession session, long groupId) {
- mapper(session).deleteMembersByGroup(groupId);
- }
-
- protected UserGroupMapper mapper(DbSession session) {
- return session.getMapper(UserGroupMapper.class);
- }
-}
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;
+++ /dev/null
-/*
- * 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;
-
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.util;
-
-
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
-
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.concurrent.atomic.AtomicLong;
-
-/**
- * Background thread that logs the state of a counter at fixed intervals.
- */
-public class ProgressLogger {
-
- public static final long DEFAULT_PERIOD_MS = 60000L;
-
- private final Timer timer;
- private final LoggerTimerTask task;
- private long periodMs = DEFAULT_PERIOD_MS;
-
- public ProgressLogger(String threadName, AtomicLong counter, Logger logger) {
- this.timer = new Timer(threadName);
- this.task = new LoggerTimerTask(counter, logger);
- }
-
- public static ProgressLogger create(Class clazz, AtomicLong counter) {
- String threadName = String.format("ProgressLogger[%s]", clazz.getSimpleName());
- Logger logger = Loggers.get(clazz);
- return new ProgressLogger(threadName, counter, logger);
- }
-
- /**
- * Warning, does not check if already started.
- */
- public void start() {
- // first log after {periodMs} milliseconds
- timer.schedule(task, periodMs, periodMs);
- }
-
- public void stop() {
- timer.cancel();
- timer.purge();
- }
-
- /**
- * Default is 1 minute
- */
- public ProgressLogger setPeriodMs(long l) {
- this.periodMs = l;
- return this;
- }
-
- public long getPeriodMs() {
- return periodMs;
- }
-
- /**
- * For example "issues", "measures", ... Default is "rows".
- */
- public ProgressLogger setPluralLabel(String s) {
- task.pluralLabel = s;
- return this;
- }
-
- public String getPluralLabel() {
- return task.pluralLabel;
- }
-
- public void log() {
- task.log();
- }
-
- private class LoggerTimerTask extends TimerTask {
- private final AtomicLong counter;
- private final Logger logger;
- private String pluralLabel = "rows";
- private long previousCounter = 0L;
-
- private LoggerTimerTask(AtomicLong counter, Logger logger) {
- this.counter = counter;
- this.logger = logger;
- }
-
- @Override
- public void run() {
- log();
- }
-
- private void log() {
- long current = counter.get();
- logger.info(String.format("%d %s processed (%d items/sec)", current, pluralLabel, 1000 * (current-previousCounter) / periodMs));
- previousCounter = current;
- }
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.util;
-
-import java.text.Normalizer;
-import java.util.Locale;
-
-public class Slug {
-
- private Slug() {
- }
-
- public static String slugify(String s) {
- return Normalizer.normalize(s, Normalizer.Form.NFD)
- .replaceAll("[^\\p{ASCII}]", "")
- .replaceAll("[^\\w+]", "-")
- .replaceAll("\\s+", "-")
- .replaceAll("[-]+", "-")
- .replaceAll("^-", "")
- .replaceAll("-$", "").toLowerCase(Locale.ENGLISH);
- }
-}
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 {
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
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;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.activity.db;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.sonar.api.utils.System2;
-import org.sonar.db.activity.ActivityDto;
-import org.sonar.db.DbTester;
-import org.sonar.test.DbTests;
-
-import java.util.Map;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-@Category(DbTests.class)
-public class ActivityDaoTest {
-
- @Rule
- public DbTester dbTester = new DbTester();
-
- System2 system = mock(System2.class);
- ActivityDao sut;
-
- @Before
- public void before() {
- sut = new ActivityDao(dbTester.myBatis(), system);
- }
-
- @Test
- public void insert() {
- when(system.now()).thenReturn(1_500_000_000_000L);
- ActivityDto dto = new ActivityDto()
- .setKey("UUID_1").setAction("THE_ACTION").setType("THE_TYPE")
- .setAuthor("THE_AUTHOR").setData("THE_DATA");
- sut.insert(dto);
-
- Map<String, Object> map = dbTester.selectFirst("select created_at as \"createdAt\", log_action as \"action\", data_field as \"data\" from activities where log_key='UUID_1'");
- assertThat(map.get("action")).isEqualTo("THE_ACTION");
- // not possible to check exact date yet. dbTester#selectFirst() uses ResultSet#getObject(), which returns
- // non-JDBC interface in Oracle driver.
- assertThat(map.get("createdAt")).isNotNull();
- assertThat(map.get("data")).isEqualTo("THE_DATA");
- }
-}
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;
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;
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);
}
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;
assertThat(result.isEnabled()).isFalse();
}
- @Test(expected = NotFoundException.class)
+ @Test(expected = IllegalArgumentException.class)
public void fail_to_get_by_id_when_project_not_found() {
loadBasicDataInDatabase();
+++ /dev/null
-/*
- * 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();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.component.db;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.sonar.db.component.ComponentLinkDto;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.test.DbTests;
-
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-@Category(DbTests.class)
-public class ComponentLinkDaoTest {
-
- @ClassRule
- public static DbTester dbTester = new DbTester();
-
- DbSession session;
-
- ComponentLinkDao dao;
-
- @Before
- public void createDao() {
- session = dbTester.myBatis().openSession(false);
- dao = new ComponentLinkDao();
- }
-
- @After
- public void tearDown() {
- session.close();
- }
-
- @Test
- public void select_by_component_uuid() {
- dbTester.prepareDbUnit(getClass(), "shared.xml");
-
- List<ComponentLinkDto> links = dao.selectByComponentUuid(session, "ABCD");
- assertThat(links).hasSize(2);
-
- links = dao.selectByComponentUuid(session, "BCDE");
- assertThat(links).hasSize(1);
-
- ComponentLinkDto link = links.get(0);
- assertThat(link.getId()).isEqualTo(3L);
- assertThat(link.getComponentUuid()).isEqualTo("BCDE");
- assertThat(link.getType()).isEqualTo("homepage");
- assertThat(link.getName()).isEqualTo("Home");
- assertThat(link.getHref()).isEqualTo("http://www.struts.org");
- }
-
- @Test
- public void insert() {
- dbTester.prepareDbUnit(getClass(), "empty.xml");
-
- dao.insert(session, new ComponentLinkDto()
- .setComponentUuid("ABCD")
- .setType("homepage")
- .setName("Home")
- .setHref("http://www.sonarqube.org")
- );
- session.commit();
-
- dbTester.assertDbUnit(getClass(), "insert-result.xml", new String[]{"id"}, "project_links");
- }
-
- @Test
- public void update() {
- dbTester.prepareDbUnit(getClass(), "update.xml");
-
- dao.update(session, new ComponentLinkDto()
- .setId(1L)
- .setComponentUuid("ABCD")
- .setType("homepage")
- .setName("Home")
- .setHref("http://www.sonarqube.org")
- );
- session.commit();
-
- dbTester.assertDbUnit(getClass(), "update-result.xml", "project_links");
- }
-
- @Test
- public void delete() {
- dbTester.prepareDbUnit(getClass(), "delete.xml");
-
- dao.delete(session, 1L);
- session.commit();
-
- assertThat(dbTester.countRowsOfTable("project_links")).isEqualTo(0);
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.component.db;
-
-import java.util.Date;
-import java.util.List;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.sonar.api.utils.DateUtils;
-import org.sonar.db.component.SnapshotDto;
-import org.sonar.db.component.SnapshotQuery;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.test.DbTests;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.component.SnapshotQuery.SORT_FIELD.BY_DATE;
-import static org.sonar.db.component.SnapshotQuery.SORT_ORDER.ASC;
-import static org.sonar.db.component.SnapshotQuery.SORT_ORDER.DESC;
-
-@Category(DbTests.class)
-public class SnapshotDaoTest {
-
- @ClassRule
- public static DbTester db = new DbTester();
-
- DbSession session;
-
- SnapshotDao sut;
-
- @Before
- public void createDao() {
- session = db.myBatis().openSession(false);
- sut = new SnapshotDao();
- }
-
- @After
- public void tearDown() {
- session.close();
- }
-
- @Test
- public void get_by_key() {
- db.prepareDbUnit(getClass(), "shared.xml");
-
- SnapshotDto result = sut.selectNullableById(session, 3L);
- assertThat(result).isNotNull();
- assertThat(result.getId()).isEqualTo(3L);
- assertThat(result.getComponentId()).isEqualTo(3L);
- assertThat(result.getRootProjectId()).isEqualTo(1L);
- assertThat(result.getParentId()).isEqualTo(2L);
- assertThat(result.getRootId()).isEqualTo(1L);
- assertThat(result.getStatus()).isEqualTo("P");
- assertThat(result.getLast()).isTrue();
- assertThat(result.getPurgeStatus()).isEqualTo(1);
- assertThat(result.getDepth()).isEqualTo(1);
- assertThat(result.getScope()).isEqualTo("DIR");
- assertThat(result.getQualifier()).isEqualTo("PAC");
- assertThat(result.getVersion()).isEqualTo("2.1-SNAPSHOT");
- assertThat(result.getPath()).isEqualTo("1.2.");
-
- assertThat(result.getPeriodMode(1)).isEqualTo("days1");
- assertThat(result.getPeriodModeParameter(1)).isEqualTo("30");
- assertThat(result.getPeriodDate(1)).isEqualTo(1316815200000L);
- assertThat(result.getPeriodMode(2)).isEqualTo("days2");
- assertThat(result.getPeriodModeParameter(2)).isEqualTo("31");
- assertThat(result.getPeriodDate(2)).isEqualTo(1316901600000L);
- assertThat(result.getPeriodMode(3)).isEqualTo("days3");
- assertThat(result.getPeriodModeParameter(3)).isEqualTo("32");
- assertThat(result.getPeriodDate(3)).isEqualTo(1316988000000L);
- assertThat(result.getPeriodMode(4)).isEqualTo("days4");
- assertThat(result.getPeriodModeParameter(4)).isEqualTo("33");
- assertThat(result.getPeriodDate(4)).isEqualTo(1317074400000L);
- assertThat(result.getPeriodMode(5)).isEqualTo("days5");
- assertThat(result.getPeriodModeParameter(5)).isEqualTo("34");
- assertThat(result.getPeriodDate(5)).isEqualTo(1317160800000L);
-
- assertThat(result.getCreatedAt()).isEqualTo(1228172400000L);
- assertThat(result.getBuildDate()).isEqualTo(1317247200000L);
-
- assertThat(sut.selectNullableById(session, 999L)).isNull();
- }
-
- @Test
- public void lastSnapshot_returns_null_when_no_last_snapshot() {
- SnapshotDto snapshot = sut.selectLastSnapshotByComponentId(session, 123L);
-
- assertThat(snapshot).isNull();
- }
-
- @Test
- public void lastSnapshot_from_one_resource() {
- db.prepareDbUnit(getClass(), "snapshots.xml");
-
- SnapshotDto snapshot = sut.selectLastSnapshotByComponentId(session, 2L);
-
- assertThat(snapshot).isNotNull();
- assertThat(snapshot.getId()).isEqualTo(4L);
- }
-
- @Test
- public void lastSnapshot_from_one_resource_without_last_is_null() {
- db.prepareDbUnit(getClass(), "snapshots.xml");
-
- SnapshotDto snapshot = sut.selectLastSnapshotByComponentId(session, 5L);
-
- assertThat(snapshot).isNull();
- }
-
- @Test
- public void snapshot_and_child_retrieved() {
- db.prepareDbUnit(getClass(), "snapshots.xml");
-
- List<SnapshotDto> snapshots = sut.selectSnapshotAndChildrenOfProjectScope(session, 1L);
-
- assertThat(snapshots).isNotEmpty();
- assertThat(snapshots).extracting("id").containsOnly(1L, 6L);
- }
-
- @Test
- public void select_snapshots_by_component_id() {
- db.prepareDbUnit(getClass(), "snapshots.xml");
-
- List<SnapshotDto> snapshots = sut.selectSnapshotsByComponentId(session, 1L);
-
- assertThat(snapshots).hasSize(3);
- }
-
- @Test
- public void select_snapshots_by_query() {
- db.prepareDbUnit(getClass(), "select_snapshots_by_query.xml");
-
- assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery())).hasSize(6);
-
- assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L))).hasSize(3);
-
- assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setVersion("2.2-SNAPSHOT"))).extracting("id").containsOnly(3L);
-
- assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setIsLast(true))).extracting("id").containsOnly(1L);
- assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setIsLast(false))).extracting("id").containsOnly(2L, 3L);
-
- assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setCreatedAfter(1228172400002L))).extracting("id").containsOnly(2L, 3L);
- assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setCreatedBefore(1228172400002L))).extracting("id").containsOnly(1L);
-
- assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(2L).setStatus("P"))).hasSize(1);
- assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(2L).setStatus("U"))).hasSize(1);
-
- assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setSort(BY_DATE, ASC)).get(0).getId()).isEqualTo(1L);
- assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setSort(BY_DATE, DESC)).get(0).getId()).isEqualTo(3L);
- }
-
- @Test
- public void select_previous_version_snapshots() throws Exception {
- db.prepareDbUnit(getClass(), "select_previous_version_snapshots.xml");
-
- List<SnapshotDto> snapshots = sut.selectPreviousVersionSnapshots(session, 1L, "1.2-SNAPSHOT");
- assertThat(snapshots).hasSize(2);
-
- SnapshotDto firstSnapshot = snapshots.get(0);
- assertThat(firstSnapshot.getVersion()).isEqualTo("1.1");
-
- // All snapshots are returned on an unknown version
- assertThat(sut.selectPreviousVersionSnapshots(session, 1L, "UNKNOWN")).hasSize(3);
- }
-
- @Test
- public void insert() {
- db.prepareDbUnit(getClass(), "empty.xml");
-
- SnapshotDto dto = defaultSnapshot().setCreatedAt(1403042400000L);
-
- sut.insert(session, dto);
- session.commit();
-
- assertThat(dto.getId()).isNotNull();
- db.assertDbUnit(getClass(), "insert-result.xml", new String[] {"id"}, "snapshots");
- }
-
- @Test
- public void insert_snapshots() {
- db.prepareDbUnit(getClass(), "empty.xml");
-
- sut.insert(session,
- new SnapshotDto().setComponentId(1L).setLast(false),
- new SnapshotDto().setComponentId(2L).setLast(false));
- session.commit();
-
- assertThat(db.countRowsOfTable("snapshots")).isEqualTo(2);
- }
-
- @Test
- public void set_snapshot_and_children_to_false_and_status_processed() {
- db.prepareDbUnit(getClass(), "snapshots.xml");
- SnapshotDto snapshot = defaultSnapshot().setId(1L);
-
- sut.updateSnapshotAndChildrenLastFlagAndStatus(session, snapshot, false, SnapshotDto.STATUS_PROCESSED);
- session.commit();
-
- List<SnapshotDto> snapshots = sut.selectSnapshotAndChildrenOfProjectScope(session, 1L);
- assertThat(snapshots).hasSize(2);
- assertThat(snapshots).extracting("id").containsOnly(1L, 6L);
- assertThat(snapshots).extracting("last").containsOnly(false);
- assertThat(snapshots).extracting("status").containsOnly(SnapshotDto.STATUS_PROCESSED);
- }
-
- @Test
- public void set_snapshot_and_children_isLast_flag_to_false() {
- db.prepareDbUnit(getClass(), "snapshots.xml");
- SnapshotDto snapshot = defaultSnapshot().setId(1L);
-
- sut.updateSnapshotAndChildrenLastFlag(session, snapshot, false);
- session.commit();
-
- List<SnapshotDto> snapshots = sut.selectSnapshotAndChildrenOfProjectScope(session, 1L);
- assertThat(snapshots).hasSize(2);
- assertThat(snapshots).extracting("id").containsOnly(1L, 6L);
- assertThat(snapshots).extracting("last").containsOnly(false);
- }
-
- @Test
- public void is_last_snapshot_when_no_previous_snapshot() {
- SnapshotDto snapshot = defaultSnapshot();
-
- boolean isLast = SnapshotDao.isLast(snapshot, null);
-
- assertThat(isLast).isTrue();
- }
-
- @Test
- public void is_last_snapshot_when_previous_snapshot_is_older() {
- Date today = new Date();
- Date yesterday = DateUtils.addDays(today, -1);
-
- SnapshotDto snapshot = defaultSnapshot().setCreatedAt(today.getTime());
- SnapshotDto previousLastSnapshot = defaultSnapshot().setCreatedAt(yesterday.getTime());
-
- boolean isLast = SnapshotDao.isLast(snapshot, previousLastSnapshot);
-
- assertThat(isLast).isTrue();
- }
-
- @Test
- public void is_not_last_snapshot_when_previous_snapshot_is_newer() {
- Date today = new Date();
- Date yesterday = DateUtils.addDays(today, -1);
-
- SnapshotDto snapshot = defaultSnapshot().setCreatedAt(yesterday.getTime());
- SnapshotDto previousLastSnapshot = defaultSnapshot().setCreatedAt(today.getTime());
-
- boolean isLast = SnapshotDao.isLast(snapshot, previousLastSnapshot);
-
- assertThat(isLast).isFalse();
- }
-
- private static SnapshotDto defaultSnapshot() {
- return new SnapshotDto()
- .setComponentId(3L)
- .setRootProjectId(1L)
- .setParentId(2L)
- .setRootId(1L)
- .setStatus("P")
- .setLast(true)
- .setPurgeStatus(1)
- .setDepth(1)
- .setScope("DIR")
- .setQualifier("PAC")
- .setVersion("2.1-SNAPSHOT")
- .setPath("1.2.")
- .setPeriodMode(1, "days1")
- .setPeriodMode(2, "days2")
- .setPeriodMode(3, "days3")
- .setPeriodMode(4, "days4")
- .setPeriodMode(5, "days5")
- .setPeriodParam(1, "30")
- .setPeriodParam(2, "31")
- .setPeriodParam(3, "32")
- .setPeriodParam(4, "33")
- .setPeriodParam(5, "34")
- .setPeriodDate(1, 1_500_000_000_001L)
- .setPeriodDate(2, 1_500_000_000_002L)
- .setPeriodDate(3, 1_500_000_000_003L)
- .setPeriodDate(4, 1_500_000_000_004L)
- .setPeriodDate(5, 1_500_000_000_005L)
- .setBuildDate(1_500_000_000_006L);
- }
-}
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;
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;
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)));
}
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;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.computation.db;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.api.utils.System2;
-import org.sonar.db.compute.AnalysisReportDto;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.db.MyBatis;
-import org.sonar.test.DbTests;
-
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.sonar.db.compute.AnalysisReportDto.Status.PENDING;
-import static org.sonar.db.compute.AnalysisReportDto.Status.WORKING;
-
-@Category(DbTests.class)
-public class AnalysisReportDaoTest {
-
- private static final String DEFAULT_PROJECT_KEY = "123456789-987654321";
-
- @ClassRule
- public static DbTester db = new DbTester();
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- AnalysisReportDao sut;
- DbSession session;
- System2 system2;
-
- @Before
- public void before() {
- this.session = db.myBatis().openSession(false);
- this.system2 = mock(System2.class);
- this.sut = new AnalysisReportDao(system2);
-
- when(system2.now()).thenReturn(1_500_000_000_000L);
- }
-
- @After
- public void after() {
- MyBatis.closeQuietly(session);
- }
-
- @Test
- public void insert_multiple_reports() {
- db.prepareDbUnit(getClass(), "empty.xml");
-
- AnalysisReportDto report1 = new AnalysisReportDto().setProjectKey("ProjectKey1").setProjectName("Project 1").setUuid("UUID_1").setStatus(PENDING);
- AnalysisReportDto report2 = new AnalysisReportDto().setProjectKey("ProjectKey2").setProjectName("Project 2").setUuid("UUID_2").setStatus(PENDING);
-
- sut.insert(session, report1);
- sut.insert(session, report2);
- session.commit();
-
- db.assertDbUnit(getClass(), "insert-result.xml", "analysis_reports");
- }
-
- @Test
- public void resetAllToPendingStatus() {
- db.prepareDbUnit(getClass(), "update-all-to-status-pending.xml");
-
- sut.resetAllToPendingStatus(session);
- session.commit();
-
- db.assertDbUnit(getClass(), "update-all-to-status-pending-result.xml", "analysis_reports");
- }
-
- @Test
- public void truncate() {
- db.prepareDbUnit(getClass(), "any-analysis-reports.xml");
-
- sut.truncate(session);
- session.commit();
-
- db.assertDbUnit(getClass(), "truncate-result.xml", "analysis_reports");
- }
-
- @Test
- public void find_one_report_by_project_key() {
- db.prepareDbUnit(getClass(), "select.xml");
-
- final String projectKey = "123456789-987654321";
- List<AnalysisReportDto> reports = sut.selectByProjectKey(session, projectKey);
- AnalysisReportDto report = reports.get(0);
-
- assertThat(reports).hasSize(1);
- assertThat(report.getProjectKey()).isEqualTo(projectKey);
- assertThat(report.getProjectName()).isEqualTo("Project 1");
- assertThat(report.getStatus()).isEqualTo(AnalysisReportDto.Status.WORKING);
- assertThat(report.getId()).isEqualTo(1);
- }
-
- @Test
- public void find_several_reports_by_project_key() {
- db.prepareDbUnit(getClass(), "select.xml");
-
- final String projectKey = "987654321-123456789";
- List<AnalysisReportDto> reports = sut.selectByProjectKey(session, projectKey);
-
- assertThat(reports).hasSize(2);
- }
-
- @Test
- public void pop_oldest_pending() {
- db.prepareDbUnit(getClass(), "pop_oldest_pending.xml");
-
- AnalysisReportDto nextAvailableReport = sut.pop(session);
-
- assertThat(nextAvailableReport.getId()).isEqualTo(3);
- assertThat(nextAvailableReport.getProjectKey()).isEqualTo("P2");
- }
-
- @Test
- public void pop_null_if_no_pending_reports() {
- db.prepareDbUnit(getClass(), "pop_null_if_no_pending_reports.xml");
-
- AnalysisReportDto nextAvailableReport = sut.pop(session);
-
- assertThat(nextAvailableReport).isNull();
- }
-
- @Test
- public void getById_maps_all_the_fields_except_the_data() {
- db.prepareDbUnit(getClass(), "one_analysis_report.xml");
-
- AnalysisReportDto report = sut.selectById(session, 1L);
-
- assertThat(report.getProjectKey()).isEqualTo(DEFAULT_PROJECT_KEY);
- assertThat(report.getCreatedAt()).isEqualTo(1_500_000_000_001L);
- assertThat(report.getUpdatedAt()).isEqualTo(1_500_000_000_002L);
- assertThat(report.getStartedAt()).isEqualTo(1_500_000_000_003L);
- assertThat(report.getFinishedAt()).isEqualTo(1_500_000_000_004L);
- assertThat(report.getStatus()).isEqualTo(WORKING);
- }
-
- @Test
- public void getById_returns_null_when_id_not_found() {
- db.prepareDbUnit(getClass(), "select.xml");
-
- AnalysisReportDto report = sut.selectById(session, 4L);
-
- assertThat(report).isNull();
- }
-
- @Test
- public void delete_one_analysis_report() {
- db.prepareDbUnit(getClass(), "one_analysis_report.xml");
-
- sut.delete(session, 1);
- session.commit();
-
- db.assertDbUnit(getClass(), "truncate-result.xml", "analysis_reports");
- }
-
- @Test
- public void findAll_one_analysis_report() {
- db.prepareDbUnit(getClass(), "one_analysis_report.xml");
-
- List<AnalysisReportDto> reports = sut.selectAll(session);
-
- assertThat(reports).hasSize(1);
- }
-
- @Test
- public void findAll_empty_table() {
- db.prepareDbUnit(getClass(), "empty.xml");
-
- List<AnalysisReportDto> reports = sut.selectAll(session);
-
- assertThat(reports).isEmpty();
- }
-
- @Test
- public void findAll_three_analysis_reports() {
- db.prepareDbUnit(getClass(), "three_analysis_reports.xml");
-
- List<AnalysisReportDto> reports = sut.selectAll(session);
-
- assertThat(reports).hasSize(3);
- }
-}
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;
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;
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;
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;
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 {
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 {
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.dashboard.db;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.sonar.db.dashboard.WidgetDto;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.db.MyBatis;
-import org.sonar.test.DbTests;
-
-import java.util.Collection;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-@Category(DbTests.class)
-public class WidgetDaoTest {
-
- WidgetDao dao;
-
- @Rule
- public DbTester dbTester = new DbTester();
-
- private DbSession session;
-
- @Before
- public void setUp() {
- dao = new WidgetDao(dbTester.myBatis());
- session = dbTester.myBatis().openSession(false);
- }
-
- @After
- public void tearDown() {
- MyBatis.closeQuietly(session);
- }
-
- @Test
- public void should_select_all() {
- dbTester.prepareDbUnit(this.getClass(), "before.xml");
- session.commit();
-
- Collection<WidgetDto> widgets = dao.findAll(session);
- assertThat(widgets).hasSize(5);
- for (WidgetDto widget : widgets) {
- assertThat(widget.getId()).isNotNull();
- assertThat(widget.getName()).isNotNull();
- assertThat(widget.getDescription()).isNotNull();
- }
- }
-}
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";
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.db;
-
-import org.apache.commons.lang.StringUtils;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.sonar.api.utils.MessageException;
-import org.sonar.db.Database;
-import org.sonar.db.dialect.Dialect;
-import org.sonar.db.dialect.H2;
-import org.sonar.db.dialect.MySql;
-import org.sonar.db.dialect.Oracle;
-
-import java.sql.SQLException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class DatabaseCheckerTest {
-
- @Test
- public void requires_oracle_driver_11_2() throws Exception {
- Database db = mockDb(new Oracle(), "11.2.1", "11.2.0.0.1");
- new DatabaseChecker(db).start();
- // no error
-
- db = mockDb(new Oracle(), "11.2.1", "11.3.1");
- new DatabaseChecker(db).start();
- // no error
-
- db = mockDb(new Oracle(), "11.2.1", "12.0.2");
- new DatabaseChecker(db).start();
- // no error
-
- db = mockDb(new Oracle(), "11.2.1", "11.1.0.2");
- try {
- new DatabaseChecker(db).start();
- fail();
- } catch (MessageException e) {
- assertThat(e).hasMessage("Unsupported Oracle JDBC driver version: 11.1.0.2. Minimal required version is 11.2.");
- }
- }
-
- @Test
- public void requires_oracle_11g_or_greater() throws Exception {
- // oracle 11.0 is ok
- Database db = mockDb(new Oracle(), "11.0.1", "11.2.0.0.1");
- new DatabaseChecker(db).start();
-
- // oracle 11.1 is ok
- db = mockDb(new Oracle(), "11.1.1", "11.2.0.0.1");
- new DatabaseChecker(db).start();
-
- // oracle 11.2 is ok
- db = mockDb(new Oracle(), "11.2.1", "11.2.0.0.1");
- new DatabaseChecker(db).start();
-
- // oracle 12 is ok
- db = mockDb(new Oracle(), "12.0.1", "11.2.0.0.1");
- new DatabaseChecker(db).start();
-
- // oracle 10 is not supported
- db = mockDb(new Oracle(), "10.2.1", "11.2.0.0.1");
- try {
- new DatabaseChecker(db).start();
- fail();
- } catch (MessageException e) {
- assertThat(e).hasMessage("Unsupported Oracle version: 10.2.1. Minimal required version is 11.");
- }
- }
-
- @Test
- public void log_warning_if_h2() throws Exception {
- Database db = mockDb(new H2(), "13.4", "13.4");
- DatabaseChecker checker = new DatabaseChecker(db);
- checker.start();
- checker.stop();
- // TODO test log
- }
-
- @Test
- public void do_not_fail_if_mysql() throws Exception {
- Database db = mockDb(new MySql(), "5.7", "5.7");
- new DatabaseChecker(db).start();
- // no error
- }
-
- private Database mockDb(Dialect dialect, String dbVersion, String driverVersion) throws SQLException {
- Database db = mock(Database.class, Mockito.RETURNS_DEEP_STUBS);
- when(db.getDialect()).thenReturn(dialect);
- when(db.getDataSource().getConnection().getMetaData().getDatabaseMajorVersion()).thenReturn(Integer.parseInt(StringUtils.substringBefore(dbVersion, ".")));
- when(db.getDataSource().getConnection().getMetaData().getDatabaseProductVersion()).thenReturn(dbVersion);
- when(db.getDataSource().getConnection().getMetaData().getDriverVersion()).thenReturn(driverVersion);
- return db;
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.db;
-
-import org.apache.commons.dbutils.DbUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.sonar.db.DbTester;
-import org.sonar.test.DbTests;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.NoSuchElementException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.fail;
-
-@Category(DbTests.class)
-public class ResultSetIteratorTest {
-
- @Rule
- public DbTester dbTester = new DbTester().schema(ResultSetIteratorTest.class, "schema.sql");
-
- Connection connection = null;
-
- @Before
- public void setUp() throws Exception {
- connection = dbTester.openConnection();
- }
-
- @After
- public void tearDown() {
- DbUtils.closeQuietly(connection);
- }
-
- @Test
- public void create_iterator_from_statement() throws Exception {
- dbTester.prepareDbUnit(getClass(), "feed.xml");
-
- PreparedStatement stmt = connection.prepareStatement("select * from fake order by id");
- FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt);
-
- assertThat(iterator.hasNext()).isTrue();
-
- // calling multiple times hasNext() is ok
- assertThat(iterator.hasNext()).isTrue();
-
- assertThat(iterator.next()).isEqualTo(10);
- assertThat(iterator.hasNext()).isTrue();
- assertThat(iterator.next()).isEqualTo(20);
-
- // call next() without calling hasNext()
- assertThat(iterator.next()).isEqualTo(30);
- assertThat(iterator.hasNext()).isFalse();
-
- try {
- iterator.next();
- fail();
- } catch (NoSuchElementException e) {
- // ok
- }
-
- iterator.close();
- // statement is closed by ResultSetIterator
- assertThat(stmt.isClosed()).isTrue();
- }
-
- @Test
- public void iterate_empty_list() throws Exception {
- dbTester.prepareDbUnit(getClass(), "feed.xml");
-
- PreparedStatement stmt = connection.prepareStatement("select * from fake where id < 0");
- FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt);
-
- assertThat(iterator.hasNext()).isFalse();
- }
-
- @Test
- public void create_iterator_from_result_set() throws Exception {
- dbTester.prepareDbUnit(getClass(), "feed.xml");
-
- PreparedStatement stmt = connection.prepareStatement("select * from fake order by id");
- ResultSet rs = stmt.executeQuery();
- FirstIntColumnIterator iterator = new FirstIntColumnIterator(rs);
-
- assertThat(iterator.next()).isEqualTo(10);
- assertThat(iterator.next()).isEqualTo(20);
- assertThat(iterator.next()).isEqualTo(30);
-
- iterator.close();
- assertThat(rs.isClosed()).isTrue();
- stmt.close();
- }
-
- @Test
- public void remove_row_is_not_supported() throws Exception {
- PreparedStatement stmt = connection.prepareStatement("select * from fake order by id");
- FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt);
-
- try {
- iterator.remove();
- fail();
- } catch (UnsupportedOperationException ok) {
- // ok
- }
-
- iterator.close();
- }
-
- @Test
- public void fail_to_read_row() throws Exception {
- dbTester.prepareDbUnit(getClass(), "feed.xml");
-
- PreparedStatement stmt = connection.prepareStatement("select * from fake order by id");
- FailIterator iterator = new FailIterator(stmt);
-
- assertThat(iterator.hasNext()).isTrue();
- try {
- iterator.next();
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getCause()).isInstanceOf(SQLException.class);
- }
- iterator.close();
- }
-
- private static class FirstIntColumnIterator extends ResultSetIterator<Integer> {
-
- public FirstIntColumnIterator(PreparedStatement stmt) throws SQLException {
- super(stmt);
- }
-
- public FirstIntColumnIterator(ResultSet rs) {
- super(rs);
- }
-
- @Override
- protected Integer read(ResultSet rs) throws SQLException {
- return rs.getInt(1);
- }
- }
-
- private static class FailIterator extends ResultSetIterator<Integer> {
-
- public FailIterator(PreparedStatement stmt) throws SQLException {
- super(stmt);
- }
-
- @Override
- protected Integer read(ResultSet rs) throws SQLException {
- // column does not exist
- return rs.getInt(1234);
- }
- }
-}
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;
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();
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;
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() {
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());
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());
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;
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;
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;
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;
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
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;
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;
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;
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;
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;
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;
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;
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;
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;
import org.junit.ClassRule;
import org.junit.Test;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import java.util.List;
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 {
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;
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;
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);
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;
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;
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);
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 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;
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;
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 {
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);
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;
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;
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);
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);
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 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;
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;
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);
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 {
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() {
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;
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 {
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 {
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;
*/
package org.sonar.server.db.migrations.v51;
+import java.util.Date;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
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;
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 {
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() {
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() {
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 {
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 {
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;
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);
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.event.db;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.sonar.db.event.EventDto;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.test.DbTests;
-
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-@Category(DbTests.class)
-public class EventDaoTest {
-
- @ClassRule
- public static DbTester dbTester = new DbTester();
-
- DbSession session;
-
- EventDao dao;
-
- @Before
- public void setup() {
- dbTester.truncateTables();
- session = dbTester.myBatis().openSession(false);
- dao = new EventDao();
- }
-
- @After
- public void tearDown() {
- session.close();
- }
-
- @Test
- public void select_by_component_uuid() {
- dbTester.prepareDbUnit(getClass(), "shared.xml");
-
- List<EventDto> dtos = dao.selectByComponentUuid(session, "ABCD");
- assertThat(dtos).hasSize(3);
-
- dtos = dao.selectByComponentUuid(session, "BCDE");
- assertThat(dtos).hasSize(1);
-
- EventDto dto = dtos.get(0);
- assertThat(dto.getId()).isEqualTo(4L);
- assertThat(dto.getComponentUuid()).isEqualTo("BCDE");
- assertThat(dto.getSnapshotId()).isEqualTo(1000L);
- assertThat(dto.getName()).isEqualTo("1.0");
- assertThat(dto.getCategory()).isEqualTo("Version");
- assertThat(dto.getDescription()).isEqualTo("Version 1.0");
- assertThat(dto.getData()).isEqualTo("some data");
- assertThat(dto.getDate()).isEqualTo(1413407091086L);
- assertThat(dto.getCreatedAt()).isEqualTo(1225630680000L);
- }
-
- @Test
- public void return_different_categories() {
- dbTester.prepareDbUnit(getClass(), "shared.xml");
-
- List<EventDto> dtos = dao.selectByComponentUuid(session, "ABCD");
- assertThat(dtos).extracting("category").containsOnly(EventDto.CATEGORY_ALERT, EventDto.CATEGORY_PROFILE, EventDto.CATEGORY_VERSION);
- }
-
- @Test
- public void insert() {
- dbTester.prepareDbUnit(getClass(), "empty.xml");
-
- dao.insert(session, new EventDto()
- .setName("1.0")
- .setCategory(EventDto.CATEGORY_VERSION)
- .setDescription("Version 1.0")
- .setData("some data")
- .setDate(1413407091086L)
- .setComponentUuid("ABCD")
- .setSnapshotId(1000L)
- .setCreatedAt(1225630680000L)
- );
- session.commit();
-
- dbTester.assertDbUnit(getClass(), "insert-result.xml", new String[]{"id"}, "events");
- }
-
- @Test
- public void delete() {
- dbTester.prepareDbUnit(getClass(), "delete.xml");
-
- dao.delete(session, 1L);
- session.commit();
-
- assertThat(dbTester.countRowsOfTable("events")).isEqualTo(0);
- }
-
-}
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;
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;
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;
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;
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;
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;
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;
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;
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 {
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;
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;
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;
ResourceDao resourceDao;
@Mock
- org.sonar.server.issue.db.IssueDao issueDao;
+ IssueDao issueDao;
@Mock
IssueUpdater issueUpdater;
+++ /dev/null
-/*
- * 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");
- }
-}
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;
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;
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;
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;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.measure.persistence;
-
-import com.google.common.base.Function;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.ImmutableSet;
-import java.util.List;
-import java.util.Map;
-import javax.annotation.Nullable;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.sonar.db.measure.MeasureDto;
-import org.sonar.db.measure.PastMeasureDto;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.test.DbTests;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static org.assertj.core.api.Assertions.assertThat;
-
-@Category(DbTests.class)
-public class MeasureDaoTest {
-
- @ClassRule
- public static DbTester db = new DbTester();
-
- DbSession session;
- MeasureDao sut;
-
- @Before
- public void setUp() {
- db.truncateTables();
- session = db.myBatis().openSession(false);
- sut = new MeasureDao();
- }
-
- @After
- public void tearDown() {
- session.close();
- }
-
- @Test
- public void get_value_by_key() {
- db.prepareDbUnit(getClass(), "shared.xml");
-
- MeasureDto result = sut.findByComponentKeyAndMetricKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "ncloc");
- assertThat(result.getId()).isEqualTo(22);
- assertThat(result.getValue()).isEqualTo(10d);
- assertThat(result.getData()).isNull();
- assertThat(result.getVariation(1)).isEqualTo(1d);
- assertThat(result.getVariation(2)).isEqualTo(2d);
- assertThat(result.getVariation(3)).isEqualTo(3d);
- assertThat(result.getVariation(4)).isEqualTo(4d);
- assertThat(result.getVariation(5)).isEqualTo(-5d);
- assertThat(result.getAlertStatus()).isEqualTo("OK");
- assertThat(result.getAlertText()).isEqualTo("Green");
- }
-
- @Test
- // TODO the string must be longer than 4000 char to be persisted in the data field
- public void get_data_by_key() {
- db.prepareDbUnit(getClass(), "shared.xml");
-
- MeasureDto result = sut.findByComponentKeyAndMetricKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "authors_by_line");
- assertThat(result.getId()).isEqualTo(20);
- assertThat(result.getData()).isEqualTo("0123456789012345678901234567890123456789");
- }
-
- @Test
- public void get_text_value_by_key() {
- db.prepareDbUnit(getClass(), "shared.xml");
-
- MeasureDto result = sut.findByComponentKeyAndMetricKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "coverage_line_hits_data");
- assertThat(result.getId()).isEqualTo(21);
- assertThat(result.getData()).isEqualTo("36=1;37=1;38=1;39=1;43=1;48=1;53=1");
- }
-
- @Test
- public void find_by_component_key_and_metrics() {
- db.prepareDbUnit(getClass(), "shared.xml");
-
- List<MeasureDto> results = sut.findByComponentKeyAndMetricKeys(session, "org.struts:struts-core:src/org/struts/RequestContext.java",
- newArrayList("ncloc", "authors_by_line"));
- assertThat(results).hasSize(2);
-
- results = sut.findByComponentKeyAndMetricKeys(session, "org.struts:struts-core:src/org/struts/RequestContext.java", newArrayList("ncloc"));
- assertThat(results).hasSize(1);
-
- MeasureDto result = results.get(0);
- assertThat(result.getId()).isEqualTo(22);
- assertThat(result.getValue()).isEqualTo(10d);
- assertThat(result.getComponentKey()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java");
- assertThat(result.getMetricKey()).isEqualTo("ncloc");
- assertThat(result.getVariation(1)).isEqualTo(1d);
- assertThat(result.getVariation(2)).isEqualTo(2d);
- assertThat(result.getVariation(3)).isEqualTo(3d);
- assertThat(result.getVariation(4)).isEqualTo(4d);
- assertThat(result.getVariation(5)).isEqualTo(-5d);
- }
-
- @Test
- public void find_by_component_key_and_metric() {
- db.prepareDbUnit(getClass(), "shared.xml");
-
- MeasureDto result = sut.findByComponentKeyAndMetricKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "ncloc");
- assertThat(result.getId()).isEqualTo(22);
- assertThat(result.getValue()).isEqualTo(10d);
- assertThat(result.getMetricKey()).isEqualTo("ncloc");
- assertThat(result.getComponentKey()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java");
- assertThat(result.getVariation(1)).isEqualTo(1d);
- assertThat(result.getVariation(2)).isEqualTo(2d);
- assertThat(result.getVariation(3)).isEqualTo(3d);
- assertThat(result.getVariation(4)).isEqualTo(4d);
- assertThat(result.getVariation(5)).isEqualTo(-5d);
-
- assertThat(sut.findByComponentKeyAndMetricKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "unknown")).isNull();
- }
-
- @Test
- public void exists_by_key() {
- db.prepareDbUnit(getClass(), "shared.xml");
-
- assertThat(sut.existsByKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "ncloc")).isTrue();
- assertThat(sut.existsByKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "unknown")).isFalse();
- }
-
- @Test
- public void select_past_measures_by_component_uuid_and_root_snapshot_id_and_metric_keys() {
- db.prepareDbUnit(getClass(), "past_measures.xml");
-
- List<PastMeasureDto> fileMeasures = sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "CDEF", 1000L, ImmutableSet.of(1, 2));
- assertThat(fileMeasures).hasSize(2);
-
- PastMeasureDto fileMeasure1 = fileMeasures.get(0);
- assertThat(fileMeasure1.getValue()).isEqualTo(5d);
- assertThat(fileMeasure1.getMetricId()).isEqualTo(1);
- assertThat(fileMeasure1.getRuleId()).isNull();
- assertThat(fileMeasure1.getCharacteristicId()).isNull();
- assertThat(fileMeasure1.getPersonId()).isNull();
-
- PastMeasureDto fileMeasure2 = fileMeasures.get(1);
- assertThat(fileMeasure2.getValue()).isEqualTo(60d);
- assertThat(fileMeasure2.getMetricId()).isEqualTo(2);
-
- List<PastMeasureDto> projectMeasures = sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "ABCD", 1000L, ImmutableSet.of(1, 2));
- assertThat(projectMeasures).hasSize(2);
-
- PastMeasureDto projectMeasure1 = projectMeasures.get(0);
- assertThat(projectMeasure1.getValue()).isEqualTo(60d);
- assertThat(projectMeasure1.getMetricId()).isEqualTo(1);
-
- PastMeasureDto projectMeasure2 = projectMeasures.get(1);
- assertThat(projectMeasure2.getValue()).isEqualTo(80d);
- assertThat(projectMeasure2.getMetricId()).isEqualTo(2);
-
- assertThat(sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "UNKNOWN", 1000L, ImmutableSet.of(1, 2))).isEmpty();
- assertThat(sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "CDEF", 987654L, ImmutableSet.of(1, 2))).isEmpty();
- assertThat(sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "CDEF", 1000L, ImmutableSet.of(123, 456))).isEmpty();
- }
-
- @Test
- public void select_past_measures_on_rule_by_component_uuid_and_root_snapshot_id_and_metric_keys() {
- db.prepareDbUnit(getClass(), "past_measures_with_rule_id.xml");
-
- List<PastMeasureDto> measures = sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "ABCD", 1000L, ImmutableSet.of(1));
- assertThat(measures).hasSize(3);
-
- Map<Long, PastMeasureDto> pastMeasuresById = pastMeasuresById(measures);
-
- PastMeasureDto measure1 = pastMeasuresById.get(1L);
- assertThat(measure1.getValue()).isEqualTo(60d);
- assertThat(measure1.getMetricId()).isEqualTo(1);
- assertThat(measure1.getRuleId()).isNull();
- assertThat(measure1.getCharacteristicId()).isNull();
- assertThat(measure1.getPersonId()).isNull();
-
- PastMeasureDto measure2 = pastMeasuresById.get(2L);
- assertThat(measure2.getValue()).isEqualTo(20d);
- assertThat(measure2.getMetricId()).isEqualTo(1);
- assertThat(measure2.getRuleId()).isEqualTo(30);
- assertThat(measure2.getCharacteristicId()).isNull();
- assertThat(measure2.getPersonId()).isNull();
-
- PastMeasureDto measure3 = pastMeasuresById.get(3L);
- assertThat(measure3.getValue()).isEqualTo(40d);
- assertThat(measure3.getMetricId()).isEqualTo(1);
- assertThat(measure3.getRuleId()).isEqualTo(31);
- assertThat(measure3.getCharacteristicId()).isNull();
- assertThat(measure3.getPersonId()).isNull();
- }
-
- @Test
- public void select_past_measures_on_characteristic_by_component_uuid_and_root_snapshot_id_and_metric_keys() {
- db.prepareDbUnit(getClass(), "past_measures_with_characteristic_id.xml");
-
- List<PastMeasureDto> measures = sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "ABCD", 1000L, ImmutableSet.of(1));
- assertThat(measures).hasSize(3);
-
- Map<Long, PastMeasureDto> pastMeasuresById = pastMeasuresById(measures);
-
- PastMeasureDto measure1 = pastMeasuresById.get(1L);
- assertThat(measure1.getValue()).isEqualTo(60d);
- assertThat(measure1.getMetricId()).isEqualTo(1);
- assertThat(measure1.getRuleId()).isNull();
- assertThat(measure1.getCharacteristicId()).isNull();
- assertThat(measure1.getPersonId()).isNull();
-
- PastMeasureDto measure2 = pastMeasuresById.get(2L);
- assertThat(measure2.getValue()).isEqualTo(20d);
- assertThat(measure2.getMetricId()).isEqualTo(1);
- assertThat(measure2.getRuleId()).isNull();
- assertThat(measure2.getCharacteristicId()).isEqualTo(10);
- assertThat(measure2.getPersonId()).isNull();
-
- PastMeasureDto measure3 = pastMeasuresById.get(3L);
- assertThat(measure3.getValue()).isEqualTo(40d);
- assertThat(measure3.getMetricId()).isEqualTo(1);
- assertThat(measure3.getRuleId()).isNull();
- assertThat(measure3.getCharacteristicId()).isEqualTo(11);
- assertThat(measure3.getPersonId()).isNull();
- }
-
- @Test
- public void select_past_measures_on_person_by_component_uuid_and_root_snapshot_id_and_metric_keys() {
- db.prepareDbUnit(getClass(), "past_measures_with_person_id.xml");
-
- List<PastMeasureDto> measures = sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "ABCD", 1000L, ImmutableSet.of(1));
- assertThat(measures).hasSize(3);
-
- Map<Long, PastMeasureDto> pastMeasuresById = pastMeasuresById(measures);
-
- PastMeasureDto measure1 = pastMeasuresById.get(1L);
- assertThat(measure1.getValue()).isEqualTo(60d);
- assertThat(measure1.getMetricId()).isEqualTo(1);
- assertThat(measure1.getRuleId()).isNull();
- assertThat(measure1.getCharacteristicId()).isNull();
- assertThat(measure1.getPersonId()).isNull();
-
- PastMeasureDto measure2 = pastMeasuresById.get(2L);
- assertThat(measure2.getValue()).isEqualTo(20d);
- assertThat(measure2.getMetricId()).isEqualTo(1);
- assertThat(measure2.getRuleId()).isNull();
- assertThat(measure2.getCharacteristicId()).isNull();
- assertThat(measure2.getPersonId()).isEqualTo(20);
-
- PastMeasureDto measure3 = pastMeasuresById.get(3L);
- assertThat(measure3.getValue()).isEqualTo(40d);
- assertThat(measure3.getMetricId()).isEqualTo(1);
- assertThat(measure3.getRuleId()).isNull();
- assertThat(measure3.getCharacteristicId()).isNull();
- assertThat(measure3.getPersonId()).isEqualTo(21);
- }
-
- @Test
- public void insert() {
- db.prepareDbUnit(getClass(), "empty.xml");
-
- sut.insert(session, new MeasureDto()
- .setSnapshotId(2L)
- .setMetricId(3)
- .setCharacteristicId(4)
- .setPersonId(23)
- .setRuleId(5)
- .setComponentId(6L)
- .setValue(2.0d)
- .setData("measure-value")
- .setVariation(1, 1.0d)
- .setVariation(2, 2.0d)
- .setVariation(3, 3.0d)
- .setVariation(4, 4.0d)
- .setVariation(5, 5.0d)
- .setAlertStatus("alert")
- .setAlertText("alert-text")
- .setDescription("measure-description")
- );
- session.commit();
-
- db.assertDbUnit(getClass(), "insert-result.xml", new String[] {"id"}, "project_measures");
- }
-
- @Test
- public void insert_measures() {
- db.prepareDbUnit(getClass(), "empty.xml");
-
- sut.insert(session, new MeasureDto()
- .setSnapshotId(2L)
- .setMetricId(3)
- .setComponentId(6L)
- .setValue(2.0d),
- new MeasureDto()
- .setSnapshotId(3L)
- .setMetricId(4)
- .setComponentId(6L)
- .setValue(4.0d)
- );
- session.commit();
-
- assertThat(db.countRowsOfTable("project_measures")).isEqualTo(2);
- }
-
- private static Map<Long, PastMeasureDto> pastMeasuresById(List<PastMeasureDto> pastMeasures) {
- return FluentIterable.from(pastMeasures).uniqueIndex(new Function<PastMeasureDto, Long>() {
- @Nullable
- @Override
- public Long apply(PastMeasureDto input) {
- return input.getId();
- }
- });
- }
-}
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;
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;
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);
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;
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);
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.rule;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableSet;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.rule.RuleStatus;
-import org.sonar.api.rule.Severity;
-import org.sonar.api.server.debt.DebtRemediationFunction;
-import org.sonar.db.rule.RuleDto;
-import org.sonar.db.rule.RuleDto.Format;
-
-/**
- * Utility class for tests involving rules
- */
-public class RuleTesting {
-
- public static final RuleKey XOO_X1 = RuleKey.of("xoo", "x1");
- public static final RuleKey XOO_X2 = RuleKey.of("xoo", "x2");
- public static final RuleKey XOO_X3 = RuleKey.of("xoo", "x3");
-
- private RuleTesting() {
- // only static helpers
- }
-
- public static RuleDto newXooX1() {
- return newDto(XOO_X1).setLanguage("xoo");
- }
-
- public static RuleDto newXooX2() {
- return newDto(XOO_X2).setLanguage("xoo");
- }
-
- public static RuleDto newXooX3() {
- return newDto(XOO_X3).setLanguage("xoo");
- }
-
- /**
- * Full RuleDto used to feed database with fake data. Tests must not rely on the
- * field contents declared here. They should override the fields they need to test,
- * for example:
- * <pre>
- * ruleDao.insert(dbSession, RuleTesting.newDto(key).setStatus(RuleStatus.BETA));
- * </pre>
- */
- public static RuleDto newDto(RuleKey ruleKey) {
- return new RuleDto()
- .setRuleKey(ruleKey.rule())
- .setRepositoryKey(ruleKey.repository())
- .setName("Rule " + ruleKey.rule())
- .setDescription("Description " + ruleKey.rule())
- .setDescriptionFormat(Format.HTML)
- .setStatus(RuleStatus.READY)
- .setConfigKey("InternalKey" + ruleKey.rule())
- .setSeverity(Severity.INFO)
- .setIsTemplate(false)
- .setTags(ImmutableSet.of("tag1", "tag2"))
- .setSystemTags(ImmutableSet.of("systag1", "systag2"))
- .setLanguage("js")
- .setRemediationFunction(DebtRemediationFunction.Type.LINEAR.toString())
- .setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.toString())
- .setRemediationCoefficient("1h")
- .setDefaultRemediationCoefficient("5d")
- .setRemediationOffset("5min")
- .setDefaultRemediationOffset("10h")
- .setEffortToFixDescription(ruleKey.repository() + "." + ruleKey.rule() + ".effortToFix");
- }
-
- public static RuleDto newTemplateRule(RuleKey ruleKey){
- return newDto(ruleKey)
- .setIsTemplate(true);
- }
-
- public static RuleDto newCustomRule(RuleDto templateRule){
- Preconditions.checkNotNull(templateRule.getId(), "The template rule need to be persisted before creating this custom rule.");
- return newDto(RuleKey.of(templateRule.getRepositoryKey(), templateRule.getRuleKey() + "_" + System.currentTimeMillis()))
- .setLanguage(templateRule.getLanguage())
- .setTemplateId(templateRule.getId());
- }
-
- public static RuleDto newManualRule(String manualKey){
- return new RuleDto().setRuleKey(manualKey)
- .setName("Name " + manualKey)
- .setRepositoryKey(RuleKey.MANUAL_REPOSITORY_KEY)
- .setDescription("Description " + manualKey)
- .setStatus(RuleStatus.READY);
- }
-
-}
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;
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;
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;
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;
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;
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;
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;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.source.db;
-
-import com.google.common.base.Function;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import org.apache.commons.io.IOUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.db.AbstractDaoTestCase;
-import org.sonar.db.DbSession;
-import org.sonar.db.source.FileSourceDto;
-import org.sonar.db.source.FileSourceDto.Type;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class FileSourceDaoTest extends AbstractDaoTestCase {
-
- DbSession session;
-
- FileSourceDao sut;
-
- @Before
- public void setUpTestData() {
- session = getMyBatis().openSession(false);
- sut = new FileSourceDao(getMyBatis());
- }
-
- @After
- public void tearDown() {
- session.close();
- }
-
- @Test
- public void select() {
- setupData("shared");
-
- FileSourceDto fileSourceDto = sut.selectSource("FILE1_UUID");
-
- assertThat(fileSourceDto.getBinaryData()).isNotEmpty();
- assertThat(fileSourceDto.getDataHash()).isEqualTo("hash");
- assertThat(fileSourceDto.getProjectUuid()).isEqualTo("PRJ_UUID");
- assertThat(fileSourceDto.getFileUuid()).isEqualTo("FILE1_UUID");
- assertThat(fileSourceDto.getCreatedAt()).isEqualTo(1500000000000L);
- assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(1500000000000L);
- assertThat(fileSourceDto.getDataType()).isEqualTo(Type.SOURCE);
- }
-
- @Test
- public void select_line_hashes() {
- setupData("shared");
-
- ReaderToStringFunction fn = new ReaderToStringFunction();
- sut.readLineHashesStream(session, "FILE1_UUID", fn);
-
- assertThat(fn.result).isEqualTo("ABC\\nDEF\\nGHI");
- }
-
- @Test
- public void no_line_hashes_on_unknown_file() {
- setupData("shared");
-
- ReaderToStringFunction fn = new ReaderToStringFunction();
- sut.readLineHashesStream(session, "unknown", fn);
-
- assertThat(fn.result).isNull();
- }
-
- @Test
- public void no_line_hashes_when_only_test_data() {
- setupData("no_line_hashes_when_only_test_data");
-
- ReaderToStringFunction fn = new ReaderToStringFunction();
- sut.readLineHashesStream(session, "FILE1_UUID", fn);
-
- assertThat(fn.result).isNull();
- }
-
- @Test
- public void insert() {
- setupData("shared");
-
- sut.insert(new FileSourceDto()
- .setProjectUuid("PRJ_UUID")
- .setFileUuid("FILE2_UUID")
- .setBinaryData("FILE2_BINARY_DATA".getBytes())
- .setDataHash("FILE2_DATA_HASH")
- .setLineHashes("LINE1_HASH\\nLINE2_HASH")
- .setSrcHash("FILE2_HASH")
- .setDataType(Type.SOURCE)
- .setCreatedAt(1500000000000L)
- .setUpdatedAt(1500000000001L));
-
- checkTable("insert", "file_sources", "project_uuid", "file_uuid", "data_hash", "line_hashes", "src_hash", "created_at", "updated_at", "data_type");
- }
-
- @Test
- public void update() {
- setupData("shared");
-
- sut.update(new FileSourceDto()
- .setId(101L)
- .setProjectUuid("PRJ_UUID")
- .setFileUuid("FILE1_UUID")
- .setBinaryData("updated data".getBytes())
- .setDataHash("NEW_DATA_HASH")
- .setSrcHash("NEW_FILE_HASH")
- .setLineHashes("NEW_LINE_HASHES")
- .setDataType(Type.SOURCE)
- .setUpdatedAt(1500000000002L));
-
- checkTable("update", "file_sources", "project_uuid", "file_uuid", "data_hash", "line_hashes", "src_hash", "created_at", "updated_at", "data_type");
- }
-
- @Test
- public void update_date_when_updated_date_is_zero() {
- setupData("update_date_when_updated_date_is_zero");
-
- sut.updateDateWhenUpdatedDateIsZero(session, "ABCD", 1500000000002L);
- session.commit();
-
- checkTable("update_date_when_updated_date_is_zero", "file_sources", "project_uuid", "file_uuid", "data_hash", "line_hashes", "src_hash", "created_at", "updated_at",
- "data_type");
- }
-
- private static class ReaderToStringFunction implements Function<Reader, String> {
-
- String result = null;
-
- @Override
- public String apply(Reader input) {
- try {
- result = IOUtils.toString(input);
- return IOUtils.toString(input);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- }
-
- private static class InputStreamToStringFunction implements Function<InputStream, String> {
-
- String result = null;
-
- @Override
- public String apply(InputStream input) {
- try {
- result = IOUtils.toString(input);
- return IOUtils.toString(input);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- }
-}
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;
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;
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;
*/
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;
new WidgetPropertyDao(dbTester.myBatis()),
new IssueFilterDao(dbTester.myBatis()),
new LoadedTemplateDao(dbTester.myBatis()),
- new DashboardDao()
+ new DashboardDao(dbTester.myBatis())
),
system2,
null);
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;
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;
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;
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;
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;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.user.db;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.db.user.UserGroupDto;
-import org.sonar.test.DbTests;
-
-@Category(DbTests.class)
-public class UserGroupDaoTest {
-
- @ClassRule
- public static DbTester db = new DbTester();
-
- private UserGroupDao dao;
- private DbSession session;
-
- @Before
- public void before() {
- db.truncateTables();
- this.session = db.myBatis().openSession(false);
- this.dao = new UserGroupDao();
- }
-
- @After
- public void after() {
- this.session.close();
- }
-
- @Test
- public void insert() {
- UserGroupDto userGroupDto = new UserGroupDto().setUserId(1L).setGroupId(2L);
- dao.insert(session, userGroupDto);
- session.commit();
-
- db.assertDbUnit(getClass(), "insert-result.xml", "groups_users");
- }
-
- @Test
- public void delete_members_by_group_id() {
- db.prepareDbUnit(getClass(), "delete_members_by_group_id.xml");
- dao.deleteMembersByGroupId(session, 1L);
- session.commit();
- db.assertDbUnit(getClass(), "delete_members_by_group_id-result.xml", "groups_users");
- }
-}
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;
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;
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 {
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;
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;
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;
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;
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;
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;
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;
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;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.util;
-
-import org.junit.Test;
-import org.sonar.api.utils.log.Logger;
-
-import java.util.concurrent.atomic.AtomicLong;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.*;
-
-public class ProgressLoggerTest {
-
- @Test(timeout = 1000L)
- public void log_at_fixed_intervals() throws Exception {
- Logger logger = mock(Logger.class);
- AtomicLong counter = new AtomicLong(42L);
- ProgressLogger progress = new ProgressLogger("ProgressLoggerTest", counter, logger);
- progress.setPeriodMs(1L);
- progress.start();
- Thread.sleep(80L);
- progress.stop();
- verify(logger, atLeast(1)).info(startsWith("42 rows processed"));
-
- // ability to manual log, generally final status
- counter.incrementAndGet();
- progress.log();
- verify(logger).info(startsWith("43 rows processed"));
- }
-
- @Test
- public void create() {
- ProgressLogger progress = ProgressLogger.create(getClass(), new AtomicLong());
-
- // default values
- assertThat(progress.getPeriodMs()).isEqualTo(60000L);
- assertThat(progress.getPluralLabel()).isEqualTo("rows");
-
- // override values
- progress.setPeriodMs(10L);
- progress.setPluralLabel("issues");
- assertThat(progress.getPeriodMs()).isEqualTo(10L);
- assertThat(progress.getPluralLabel()).isEqualTo("issues");
-
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.util;
-
-import org.junit.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class SlugTest {
-
- @Test
- public void slugify() {
- assertThat(Slug.slugify("foo")).isEqualTo("foo");
- assertThat(Slug.slugify(" FOO ")).isEqualTo("foo");
- assertThat(Slug.slugify("he's here")).isEqualTo("he-s-here");
- assertThat(Slug.slugify("foo-bar")).isEqualTo("foo-bar");
- assertThat(Slug.slugify("foo_bar")).isEqualTo("foo_bar");
- assertThat(Slug.slugify("accents éà ")).isEqualTo("accents-ea");
- assertThat(Slug.slugify("<foo>")).isEqualTo("foo");
- assertThat(Slug.slugify("<\"foo:\">")).isEqualTo("foo");
- }
-}
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;
+++ /dev/null
-<dataset>
-
- <!-- Real projects -->
- <projects id="1" uuid="ABCD" project_uuid="ABCD" module_uuid_path=".ABCD." copy_resource_id="[null]" name="Project One" qualifier="TRK" scope="PRJ"/>
- <projects id="2" uuid="BCDE" project_uuid="BCDE" module_uuid_path=".BCDE." copy_resource_id="[null]" name="Project Two" qualifier="TRK" scope="PRJ"/>
-
- <!-- Copy projects -->
- <projects id="3" uuid="CDEF" project_uuid="EFGH" module_uuid_path=".EFGH." copy_resource_id="1" name="Copy Project One" qualifier="TRK" scope="FIL"/>
- <projects id="4" uuid="DEFG" project_uuid="EFGH" module_uuid_path=".EFGH." copy_resource_id="2" name="Copy Project One" qualifier="TRK" scope="FIL"/>
-
- <!-- View containing all projects -->
- <projects id="5" uuid="EFGH" project_uuid="EFGH" module_uuid_path=".EFGH." copy_resource_id="[null]" name="All projects" qualifier="VW" scope="PRJ"/>
-
- <resource_index id="1" kee="project one" resource_id="1" root_project_id="1" position="0" name_size="11" qualifier="TRK"/>
- <resource_index id="2" kee="roject one" resource_id="1" root_project_id="1" position="1" name_size="11" qualifier="TRK"/>
- <resource_index id="3" kee="oject one" resource_id="1" root_project_id="1" position="2" name_size="11" qualifier="TRK"/>
- <resource_index id="4" kee="ject one" resource_id="1" root_project_id="1" position="3" name_size="11" qualifier="TRK"/>
- <resource_index id="5" kee="ect one" resource_id="1" root_project_id="1" position="4" name_size="11" qualifier="TRK"/>
- <resource_index id="6" kee="ct one" resource_id="1" root_project_id="1" position="5" name_size="11" qualifier="TRK"/>
- <resource_index id="7" kee="t one" resource_id="1" root_project_id="1" position="6" name_size="11" qualifier="TRK"/>
- <resource_index id="8" kee=" one" resource_id="1" root_project_id="1" position="7" name_size="11" qualifier="TRK"/>
- <resource_index id="9" kee="one" resource_id="1" root_project_id="1" position="8" name_size="11" qualifier="TRK"/>
- <resource_index id="10" kee="project two" resource_id="2" root_project_id="2" position="0" name_size="11" qualifier="TRK"/>
- <resource_index id="11" kee="roject two" resource_id="2" root_project_id="2" position="1" name_size="11" qualifier="TRK"/>
- <resource_index id="12" kee="oject two" resource_id="2" root_project_id="2" position="2" name_size="11" qualifier="TRK"/>
- <resource_index id="13" kee="ject two" resource_id="2" root_project_id="2" position="3" name_size="11" qualifier="TRK"/>
- <resource_index id="14" kee="ect two" resource_id="2" root_project_id="2" position="4" name_size="11" qualifier="TRK"/>
- <resource_index id="15" kee="ct two" resource_id="2" root_project_id="2" position="5" name_size="11" qualifier="TRK"/>
- <resource_index id="16" kee="t two" resource_id="2" root_project_id="2" position="6" name_size="11" qualifier="TRK"/>
- <resource_index id="17" kee="two" resource_id="2" root_project_id="2" position="7" name_size="11" qualifier="TRK"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <project_links id="1" component_uuid="ABCD" link_type="homepage" name="Home" href="http://www.sonarqube.org"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <project_links id="1" component_uuid="ABCD" link_type="homepage" name="Home" href="http://www.sonarqube.org"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <project_links id="1" component_uuid="ABCD" link_type="homepage" name="Home" href="http://www.sonarqube.org"/>
- <project_links id="2" component_uuid="ABCD" link_type="scm" name="Sources" href="https://github.com/SonarSource/sonar"/>
- <project_links id="3" component_uuid="BCDE" link_type="homepage" name="Home" href="http://www.struts.org"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <project_links id="1" component_uuid="ABCD" link_type="homepage" name="Home" href="http://www.sonarqube.org"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <project_links id="1" component_uuid="BCDE" link_type="ci" name="CI" href="github"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <snapshots id="1" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
- status="P" islast="[true]" purge_status="1"
- period1_mode="days1" period1_param="30" period1_date="1500000000001"
- period2_mode="days2" period2_param="31" period2_date="1500000000002"
- period3_mode="days3" period3_param="32" period3_date="1500000000003"
- period4_mode="days4" period4_param="33" period4_date="1500000000004"
- period5_mode="days5" period5_param="34" period5_date="1500000000005"
- depth="1" scope="DIR" qualifier="PAC" created_at="1403042400000" build_date="1500000000006"
- version="2.1-SNAPSHOT" path="1.2."/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <!-- root project -->
- <projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
- uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
- description="the description" long_name="Apache Struts"
- enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" path="[null]" authorization_updated_at="[null]" />
- <snapshots id="1" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- status="P" islast="[true]" purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000"
- version="[null]" path=""/>
- <snapshots id="10" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- status="P" islast="[false]" purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228136280000" build_date="1228136280000"
- version="[null]" path=""/>
-
- <!-- module -->
- <projects id="2" root_id="1" kee="org.struts:struts-core" name="Struts Core"
- uuid="EFGH" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD."
- scope="PRJ" qualifier="BRC" long_name="Struts Core"
- description="[null]" enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" authorization_updated_at="[null]" />
- <snapshots id="2" project_id="2" parent_snapshot_id="1" root_project_id="1" root_snapshot_id="1"
- status="P" islast="[true]" purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- depth="[null]" scope="PRJ" qualifier="BRC" created_at="1228222680000" build_date="1228222680000"
- version="[null]" path="1."/>
-
- <!-- sub module -->
- <projects id="3" root_id="1" kee="org.struts:struts-data" name="Struts Data"
- uuid="FGHI" project_uuid="ABCD" module_uuid="EFGH" module_uuid_path=".ABCD.EFGH."
- scope="PRJ" qualifier="BRC" long_name="Struts Data"
- description="[null]" enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" authorization_updated_at="[null]" />
- <snapshots id="3" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
- status="P" islast="[true]" purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- depth="[null]" scope="PRJ" qualifier="BRC" created_at="1228222680000" build_date="1228222680000"
- version="[null]" path="1.2."/>
-
- <!-- directory -->
- <projects long_name="org.struts" id="4" scope="DIR" qualifier="DIR" kee="org.struts:struts-core:src/org/struts"
- uuid="GHIJ" project_uuid="ABCD" module_uuid="FGHI" module_uuid_path=".ABCD.EFGH.FGHI."
- name="src/org/struts" root_id="3"
- description="[null]"
- enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" path="src/org/struts" authorization_updated_at="[null]" />
- <snapshots id="4" project_id="4" parent_snapshot_id="3" root_project_id="1" root_snapshot_id="1"
- status="P" islast="[true]" purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- depth="[null]" scope="DIR" qualifier="PAC" created_at="1228222680000" build_date="1228222680000"
- version="[null]" path="1.2.3."/>
-
- <!-- file -->
- <projects long_name="org.struts.RequestContext" id="5" scope="FIL" qualifier="FIL" kee="org.struts:struts-core:src/org/struts/RequestContext.java"
- uuid="HIJK" project_uuid="ABCD" module_uuid="FGHI" module_uuid_path=".ABCD.EFGH.FGHI."
- name="RequestContext.java" root_id="3"
- description="[null]"
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" path="src/org/struts/RequestContext.java" authorization_updated_at="[null]" />
-
- <snapshots id="5" project_id="5" parent_snapshot_id="4" root_project_id="1" root_snapshot_id="1"
- status="P" islast="[true]" purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- depth="[null]" scope="FIL" qualifier="CLA" created_at="1228222680000" build_date="1228222680000"
- version="[null]" path="1.2.3.4."/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
- root_id="[null]" uuid="ABCD"
- description="[null]"
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
- <!-- version 1.0 -->
- <snapshots id="1000" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
- period5_param="[null]" period5_date="[null]"
- project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1225630680000" build_date="1225630680000" version="1.0" path=""
- status="P" islast="[false]" depth="0"/>
-
- <!-- version 1.1 -->
- <snapshots id="1001" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
- period5_param="[null]" period5_date="[null]"
- project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1225803480000" build_date="1225803480000" version="1.1" path=""
- status="P" islast="[false]" depth="0"/>
-
- <!-- version 1.2-SNAPSHOT -->
- <snapshots id="1002" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
- period5_param="[null]" period5_date="[null]"
- project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1225976280000" build_date="1225976280000" version="1.2-SNAPSHOT" path=""
- status="P" islast="[false]" depth="0"/>
-
- <!-- version 1.2-SNAPSHOT, current analysis -->
- <snapshots id="1003" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
- period5_param="[null]" period5_date="[null]"
- project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1226235480000" build_date="1226235480000" version="1.2-SNAPSHOT" path=""
- status="U" islast="[true]" depth="0"/>
-
- <events id="1" name="1.0" component_uuid="ABCD" snapshot_id="1000" category="Version" event_date="1225630680000" created_at="1225630680000" description="" event_data="[null]"/>
- <events id="2" name="Foo" component_uuid="ABCD" snapshot_id="1000" category="Other" event_date="1225717080000" created_at="1225717080000" description="" event_data="[null]"/>
- <events id="3" name="1.1" component_uuid="ABCD" snapshot_id="1001" category="Version" event_date="1225803480000" created_at="1225803480000" description="" event_data="[null]"/>
- <events id="4" name="Bar" component_uuid="ABCD" snapshot_id="1001" category="Other" event_date="1225889880000" created_at="1225889880000" description="" event_data="[null]"/>
- <events id="5" name="Uhh" component_uuid="ABCD" snapshot_id="1002" category="Other" event_date="1226062680000" created_at="1226062680000" description="" event_data="[null]"/>
- <events id="6" name="1.2-SNAPSHOT" component_uuid="ABCD" snapshot_id="1003" category="Version" event_date="1226235480000" created_at="1226235480000" description=""
- event_data="[null]"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <!-- PROJECT_ID = 1 -->
- <snapshots id="1" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
- status="P" islast="[true]" purge_status="1"
- period1_mode="days1" period1_param="30" period1_date="1316815200000"
- period2_mode="days2" period2_param="31" period2_date="1316901600000"
- period3_mode="days3" period3_param="32" period3_date="1316988000000"
- period4_mode="days4" period4_param="33" period4_date="1317074400000"
- period5_mode="days5" period5_param="34" period5_date="1317160800000"
- depth="1" scope="PRJ" qualifier="PAC" created_at="1228172400001" build_date="1317247200000"
- version="2.0-SNAPSHOT" path="1.2."/>
- <snapshots id="2" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
- status="P" islast="[false]" purge_status="1"
- period1_mode="days1" period1_param="30" period1_date="1316815200000"
- period2_mode="days2" period2_param="31" period2_date="1316901600000"
- period3_mode="days3" period3_param="32" period3_date="1316988000000"
- period4_mode="days4" period4_param="33" period4_date="1317074400000"
- period5_mode="days5" period5_param="34" period5_date="1317160800000"
- depth="1" scope="DIR" qualifier="PAC" created_at="1228172400002" build_date="1317247200000"
- version="2.1-SNAPSHOT" path="1.2."/>
- <snapshots id="3" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
- status="P" islast="[false]" purge_status="1"
- period1_mode="days1" period1_param="30" period1_date="1316815200000"
- period2_mode="days2" period2_param="31" period2_date="1316901600000"
- period3_mode="days3" period3_param="32" period3_date="1316988000000"
- period4_mode="days4" period4_param="33" period4_date="1317074400000"
- period5_mode="days5" period5_param="34" period5_date="1317160800000"
- depth="1" scope="DIR" qualifier="PAC" created_at="1228172400003" build_date="1317247200000"
- version="2.2-SNAPSHOT" path="1.2."/>
-
- <!-- PROJECT_ID = 2 -->
- <snapshots id="4" project_id="2" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
- status="P" islast="[true]" purge_status="1"
- period1_mode="days1" period1_param="30" period1_date="1316815200000"
- period2_mode="days2" period2_param="31" period2_date="1316901600000"
- period3_mode="days3" period3_param="32" period3_date="1316988000000"
- period4_mode="days4" period4_param="33" period4_date="1317074400000"
- period5_mode="days5" period5_param="34" period5_date="1317160800000"
- depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
- version="2.1-SNAPSHOT" path="1.2."/>
- <!-- Unprocessed snapshot -->
- <snapshots id="5" project_id="2" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
- status="U" islast="[true]" purge_status="1"
- period1_mode="days1" period1_param="30" period1_date="1316815200000"
- period2_mode="days2" period2_param="31" period2_date="1316901600000"
- period3_mode="days3" period3_param="32" period3_date="1316988000000"
- period4_mode="days4" period4_param="33" period4_date="1317074400000"
- period5_mode="days5" period5_param="34" period5_date="1317160800000"
- depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
- version="2.1-SNAPSHOT" path="1.2."/>
-
- <!-- PROJECT_ID = 3 - no last snapshot -->
- <snapshots id="6" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
- status="P" islast="[false]" purge_status="1"
- period1_mode="days1" period1_param="30" period1_date="1316815200000"
- period2_mode="days2" period2_param="31" period2_date="1316901600000"
- period3_mode="days3" period3_param="32" period3_date="1316988000000"
- period4_mode="days4" period4_param="33" period4_date="1317074400000"
- period5_mode="days5" period5_param="34" period5_date="1317160800000"
- depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
- version="2.1-SNAPSHOT" path="1.2."/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <snapshots id="3" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
- status="P" islast="[true]" purge_status="1"
- period1_mode="days1" period1_param="30" period1_date="1316815200000"
- period2_mode="days2" period2_param="31" period2_date="1316901600000"
- period3_mode="days3" period3_param="32" period3_date="1316988000000"
- period4_mode="days4" period4_param="33" period4_date="1317074400000"
- period5_mode="days5" period5_param="34" period5_date="1317160800000"
- depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
- version="2.1-SNAPSHOT" path="1.2."/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <!-- PROJECT_ID = 1 -->
- <snapshots id="1" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
- status="P" islast="[true]" purge_status="1"
- period1_mode="days1" period1_param="30" period1_date="1316815200000"
- period2_mode="days2" period2_param="31" period2_date="1316901600000"
- period3_mode="days3" period3_param="32" period3_date="1316988000000"
- period4_mode="days4" period4_param="33" period4_date="1317074400000"
- period5_mode="days5" period5_param="34" period5_date="1317160800000"
- depth="1" scope="PRJ" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
- version="2.1-SNAPSHOT" path="1.2."/>
- <snapshots id="2" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
- status="P" islast="[false]" purge_status="1"
- period1_mode="days1" period1_param="30" period1_date="1316815200000"
- period2_mode="days2" period2_param="31" period2_date="1316901600000"
- period3_mode="days3" period3_param="32" period3_date="1316988000000"
- period4_mode="days4" period4_param="33" period4_date="1317074400000"
- period5_mode="days5" period5_param="34" period5_date="1317160800000"
- depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
- version="2.1-SNAPSHOT" path="1.2."/>
- <snapshots id="3" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
- status="P" islast="[false]" purge_status="1"
- period1_mode="days1" period1_param="30" period1_date="1316815200000"
- period2_mode="days2" period2_param="31" period2_date="1316901600000"
- period3_mode="days3" period3_param="32" period3_date="1316988000000"
- period4_mode="days4" period4_param="33" period4_date="1317074400000"
- period5_mode="days5" period5_param="34" period5_date="1317160800000"
- depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
- version="2.1-SNAPSHOT" path="1.2."/>
-
-
- <!-- PROJECT_ID = 2 -->
- <snapshots id="4" project_id="2" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
- status="P" islast="[true]" purge_status="1"
- period1_mode="days1" period1_param="30" period1_date="1316815200000"
- period2_mode="days2" period2_param="31" period2_date="1316901600000"
- period3_mode="days3" period3_param="32" period3_date="1316988000000"
- period4_mode="days4" period4_param="33" period4_date="1317074400000"
- period5_mode="days5" period5_param="34" period5_date="1317160800000"
- depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
- version="2.1-SNAPSHOT" path="1.2."/>
-
- <!-- PROJECT_ID = 3 - no last snapshot -->
- <snapshots id="5" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
- status="P" islast="[false]" purge_status="1"
- period1_mode="days1" period1_param="30" period1_date="1316815200000"
- period2_mode="days2" period2_param="31" period2_date="1316901600000"
- period3_mode="days3" period3_param="32" period3_date="1316988000000"
- period4_mode="days4" period4_param="33" period4_date="1317074400000"
- period5_mode="days5" period5_param="34" period5_date="1317160800000"
- depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
- version="2.1-SNAPSHOT" path="1.2."/>
-
- <!-- Child of snapshot id=1 -->
- <snapshots id="6" project_id="55" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
- status="P" islast="[true]" purge_status="1"
- period1_mode="days1" period1_param="30" period1_date="1316815200000"
- period2_mode="days2" period2_param="31" period2_date="1316901600000"
- period3_mode="days3" period3_param="32" period3_date="1316988000000"
- period4_mode="days4" period4_param="33" period4_date="1317074400000"
- period5_mode="days5" period5_param="34" period5_date="1317160800000"
- depth="1" scope="PRJ" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
- version="2.1-SNAPSHOT" path="1.2."/>
-</dataset>
+++ /dev/null
-<dataset>
- <analysis_reports
- id="1"
- uuid="REPORT_1"
- project_key="123456789-987654321"
- report_status="WORKING"
- created_at="1411509600000"
- updated_at="1411509600000"
- />
- <analysis_reports
- id="2"
- uuid="REPORT_2"
- project_key="123456789-987654321"
- report_status="WORKING"
- created_at="1411596000000"
- updated_at="1411596000000"
- />
- <analysis_reports
- id="3"
- uuid="REPORT_3"
- project_key="123456789-987654321"
- report_status="PENDING"
- created_at="1411682400000"
- updated_at="1411682400000"
- />
-</dataset>
+++ /dev/null
-<dataset>
- <analysis_reports
- id="1"
- project_key="123456789-987654321"
- uuid="REPORT_1"
- report_status="PENDING"
- created_at="1411509600000"
- updated_at="1411596000000"
- />
- <analysis_reports
- id="2"
- project_key="987654321-123456789"
- uuid="REPORT_2"
- report_status="WORKING"
- created_at="1411423200000"
- updated_at="1411682400000"
- />
-</dataset>
+++ /dev/null
-<dataset>
-
-</dataset>
+++ /dev/null
-<dataset>
- <analysis_reports
- id="1"
- project_key="ProjectKey1"
- project_name="Project 1"
- uuid="UUID_1"
- report_status="PENDING"
- started_at="[null]"
- finished_at="[null]"
- created_at="1500000000000"
- updated_at="1500000000000"
- />
- <analysis_reports
- id="2"
- project_key="ProjectKey2"
- project_name="Project 2"
- uuid="UUID_2"
- report_status="PENDING"
- started_at="[null]"
- finished_at="[null]"
- created_at="1500000000000"
- updated_at="1500000000000"
- />
-</dataset>
+++ /dev/null
-<dataset>
- <analysis_reports
- id="1"
- project_key="123456789-987654321"
- uuid="REPORT_1"
- report_status="WORKING"
- created_at="1500000000001"
- updated_at="1500000000002"
- started_at="1500000000003"
- finished_at="1500000000004"
- />
-</dataset>
+++ /dev/null
-<dataset>
- <analysis_reports
- id="1"
- project_key="111111111-987654321"
- uuid="UUID_1"
- report_status="WORKING"
- created_at="1411596000000"
- updated_at="1411682400000"
- />
- <analysis_reports
- id="2"
- project_key="123456789-987654321"
- uuid="UUID_2"
- report_status="WORKING"
- created_at="1411509600000"
- updated_at="1411682400000"
- />
- <!-- not select as the previous report which is working is on the same project -->
- <analysis_reports
- id="3"
- project_key="123456789-987654321"
- uuid="UUID_3"
- report_status="PENDING"
- created_at="1411596000000"
- updated_at="1411682400000"
- />
-</dataset>
+++ /dev/null
-<dataset>
- <!-- WORKING -->
- <analysis_reports
- id="1"
- project_key="P1"
- uuid="UUID_1"
- report_status="WORKING"
- created_at="1411596000000"
- updated_at="1411682400000"
- />
-
- <!-- PENDING on P1, which is already being WORKING-->
- <analysis_reports
- id="2"
- project_key="P1"
- uuid="UUID_2"
- report_status="PENDING"
- created_at="1411509600000"
- updated_at="1411682400000"
- />
- <analysis_reports
- id="3"
- project_key="P2"
- uuid="UUID_3"
- report_status="PENDING"
- created_at="1411596000000"
- updated_at="1411682400000"
- />
- <analysis_reports
- id="4"
- project_key="P2"
- uuid="UUID_4"
- report_status="PENDING"
- created_at="1420066800000"
- updated_at="1420066800000"
- />
-</dataset>
+++ /dev/null
-<dataset>
- <analysis_reports
- id="1"
- project_key="123456789-987654321"
- project_name="Project 1"
- uuid="UUID_1"
- report_status="WORKING"
- created_at="1411509600000"
- updated_at="1411596000000"
- />
- <analysis_reports
- id="2"
- project_key="987654321-123456789"
- project_name="Project 2"
- uuid="UUID_2"
- report_status="WORKING"
- created_at="1411596000000"
- updated_at="1411596000000"
- />
- <analysis_reports
- id="3"
- project_key="987654321-123456789"
- project_name="Project 2"
- uuid="UUID_3"
- report_status="PENDING"
- created_at="1411682400000"
- updated_at="1411682400000"
- />
-</dataset>
+++ /dev/null
-<dataset>
- <analysis_reports
- id="1"
- project_key="123456789-987654321"
- uuid="UUID_1"
- report_status="WORKING"
- created_at="1411509600000"
- updated_at="1411596000000"
- />
- <analysis_reports
- id="2"
- project_key="987654321-123456789"
- uuid="UUID_2"
- report_status="WORKING"
- created_at="1411596000000"
- updated_at="1411596000000"
- />
- <analysis_reports
- id="3"
- project_key="987654321-123456789"
- uuid="UUID_3"
- report_status="PENDING"
- created_at="1411682400000"
- updated_at="1411682400000"
- />
-</dataset>
+++ /dev/null
-<dataset>
- <analysis_reports/>
-</dataset>
+++ /dev/null
-<dataset>
- <!-- all rows are PENDING, updated_at is now, started_at is null -->
- <analysis_reports
- id="1"
- project_key="P1"
- project_name="Project1"
- uuid="UUID_1"
- report_status="PENDING"
- created_at="1411509600000"
- updated_at="1500000000000"
- started_at="[null]"
- finished_at="[null]"
- />
- <analysis_reports
- id="2"
- project_key="P2"
- project_name="Project2"
- uuid="UUID_2"
- report_status="PENDING"
- created_at="1411596000000"
- updated_at="1500000000000"
- started_at="[null]"
- finished_at="[null]"
- />
- <analysis_reports
- id="3"
- project_key="P1"
- project_name="Project1"
- uuid="UUID_3"
- report_status="PENDING"
- created_at="1411682400000"
- updated_at="1500000000000"
- started_at="[null]"
- finished_at="[null]"
- />
-</dataset>
+++ /dev/null
-<dataset>
- <analysis_reports
- id="1"
- project_key="P1"
- project_name="Project1"
- uuid="UUID_1"
- report_status="WORKING"
- created_at="1411509600000"
- updated_at="1411509600000"
- started_at="1411509600000"
- finished_at="[null]"
- />
- <analysis_reports
- id="2"
- project_key="P2"
- project_name="Project2"
- uuid="UUID_2"
- report_status="WORKING"
- created_at="1411596000000"
- updated_at="1411596000000"
- started_at="1411509600000"
- finished_at="[null]"
- />
- <analysis_reports
- id="3"
- project_key="P1"
- project_name="Project1"
- uuid="UUID_3"
- report_status="PENDING"
- created_at="1411682400000"
- updated_at="1411682400000"
- started_at="[null]"
- finished_at="[null]"
- />
-</dataset>
+++ /dev/null
-<dataset>
-
- <widgets id="1" dashboard_id="1" widget_key="polop" name="Polop" description="Palap"
- column_index="1" row_index="1" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
-
- <widgets id="2" dashboard_id="1" widget_key="false_positive_reviews" name="Polop" description="Palap"
- column_index="1" row_index="2" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
-
- <widgets id="3" dashboard_id="1" widget_key="my_reviews" name="Polop" description="Palap"
- column_index="1" row_index="3" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
-
- <widgets id="4" dashboard_id="1" widget_key="reviews_per_developer" name="Polop" description="Palap"
- column_index="1" row_index="4" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
-
- <widgets id="5" dashboard_id="1" widget_key="unresolved_issues_statuses" name="Polop" description="Palap"
- column_index="1" row_index="5" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
-
-</dataset>
+++ /dev/null
-<dataset>
- <fake id="10" kee="AB" />
- <fake id="20" kee="CD" />
- <fake id="30" kee="EF" />
-</dataset>
+++ /dev/null
-CREATE TABLE "FAKE" (
- "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
- "KEE" VARCHAR(200) NOT NULL
-);
+++ /dev/null
-<dataset>
-
- <events id="1" name="1.0" category="Version" description="Version 1.0" event_data="some data" event_date="1225630680000"
- component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
-
-</dataset>
+++ /dev/null
-<dataset>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <events id="1" name="1.0" category="Version" description="Version 1.0" event_data="some data" event_date="1413407091086"
- component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <events id="1" name="1.0" category="Version" description="Version 1.0" event_data="some data" event_date="1413407091086"
- component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
- <events id="2" name="Red (was Orange)" category="Alert" description="Critical issues variation > 0 since previous version (1.0 - 2015 Feb 09), Open issues > 0"
- event_data="[null]" event_date="1413407091086" component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
- <events id="3" name="Changes in 'Default' (Java)" category="Profile" description="Version 1.0" event_data="from=2014-10-12T08:36:25+0000;key=java-default;to=2014-10-12T10:36:25+0000"
- event_date="1413407091086" component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
-
- <events id="4" name="1.0" category="Version" description="Version 1.0" event_data="some data" event_date="1413407091086"
- component_uuid="BCDE" snapshot_id="1000" created_at="1225630680000" />
-
-</dataset>
+++ /dev/null
-<dataset>
- <project_measures/>
-</dataset>
+++ /dev/null
-<dataset>
- <project_measures
- id="1"
- snapshot_id="2"
- metric_id="3"
- characteristic_id="4"
- rule_id="5"
- project_id="6"
- person_id="23"
- value="2.0"
- text_value="measure-value"
- tendency="[null]"
- rule_priority="[null]"
- measure_date="[null]"
- measure_data="[null]"
- variation_value_1="1.0"
- variation_value_2="2.0"
- variation_value_3="3.0"
- variation_value_4="4.0"
- variation_value_5="5.0"
- alert_status="alert"
- alert_text="alert-text"
- url="[null]"
- description="measure-description"
- rules_category_id="[null]"
- />
-</dataset>
+++ /dev/null
-<dataset>
-
- <metrics id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]" enabled="[true]"/>
-
- <metrics id="2" name="coverage" VAL_TYPE="INT" enabled="[true]"/>
-
-
- <rules tags="[null]" system_tags="[null]" id="30" name="Check Header" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck"
- plugin_config_key="Checker/Treewalker/HeaderCheck" plugin_name="checkstyle" description="[null]" priority="4" status="READY"
- is_template="[false]" template_id="[null]"/>
-
- <rules tags="[null]" system_tags="[null]" id="31" name="Equals Avoid Null" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck"
- plugin_config_key="Checker/TreeWalker/EqualsAvoidNull" plugin_name="checkstyle" description="[null]" priority="4" status="READY"
- is_template="[false]" template_id="[null]"/>
-
- <!-- project -->
- <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
- root_id="[null]" uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD."
- enabled="[true]"/>
-
- <!-- package -->
- <projects long_name="[null]" id="2" scope="DIR" qualifier="PAC" kee="project:org.foo" name="org.foo"
- root_id="1" uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
- enabled="[true]"/>
-
- <!-- file -->
- <projects long_name="org.foo.Bar" id="3" scope="FIL" qualifier="CLA" kee="project:org.foo.Bar"
- name="Bar" root_id="[null]" uuid="CDEF" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
- enabled="[true]"/>
-
-
- <!-- snapshots -->
- <snapshots id="1000" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1225544280000" build_date="1225544280000" version="[null]" path=""
- status="P" islast="[false]" depth="0"/>
- <snapshots id="1001" project_id="2" parent_snapshot_id="1000" root_project_id="1" root_snapshot_id="1000"
- scope="DIR" qualifier="PAC" created_at="1225544280000" build_date="1225544280000" version="[null]" path="1000."
- status="P" islast="[false]" depth="1"/>
- <snapshots id="1002" project_id="3" parent_snapshot_id="1001" root_project_id="1" root_snapshot_id="1000"
- scope="FIL" qualifier="CLA" created_at="1225544280000" build_date="1225544280000" version="[null]" path="1000.1001."
- status="P" islast="[false]" depth="2"/>
-
-
- <!-- project measures -->
- <project_measures id="1" VALUE="60" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
-
- <project_measures id="2" VALUE="80" METRIC_ID="2" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
-
- <!-- package measures -->
- <project_measures id="3" VALUE="20" METRIC_ID="1" SNAPSHOT_ID="1001" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
-
- <project_measures id="4" VALUE="70" METRIC_ID="2" SNAPSHOT_ID="1001" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
-
- <!-- file measures -->
- <project_measures id="5" VALUE="5" METRIC_ID="1" SNAPSHOT_ID="1002" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
-
- <project_measures id="6" VALUE="60" METRIC_ID="2" SNAPSHOT_ID="1002" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <metrics id="1" name="sqale_index" VAL_TYPE="WORK_DUR" DESCRIPTION="[null]" short_name="" enabled="[true]"/>
-
- <!-- Root characteristic -->
- <characteristics id="10" kee="PORTABILITY" name="Portability" parent_id="[null]" characteristic_order="1" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
-
- <!-- Characteristic -->
- <characteristics id="11" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" parent_id="10" characteristic_order="[null]" enabled="[true]"
- created_at="2013-11-20" updated_at="2013-11-22"/>
-
- <!-- project -->
- <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
- root_id="[null]" uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD." enabled="[true]"/>
-
- <!-- snapshots -->
- <snapshots id="1000" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1225544280000" build_date="1225544280000" version="[null]" path=""
- status="P" islast="[false]" depth="0"/>
-
- <!-- project measures -->
- <project_measures id="1" VALUE="60" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="[null]"/>
-
- <project_measures id="2" VALUE="20" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="10"/>
-
- <project_measures id="3" VALUE="40" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="11"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <metrics delete_historical_data="[null]" id="1" name="sqale_index" VAL_TYPE="INT" DESCRIPTION="[null]" enabled="[true]"/>
-
- <!-- project -->
- <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
- root_id="[null]" uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD."
- enabled="[true]"/>
-
- <!-- snapshots -->
- <snapshots id="1000" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1225544280000" build_date="1225544280000" version="[null]" path=""
- status="P" islast="[false]" depth="0"/>
-
- <!-- project measures -->
- <project_measures id="1" VALUE="60" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" person_id="[null]"/>
-
- <project_measures id="2" VALUE="20" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" person_id="20"/>
-
- <project_measures id="3" VALUE="40" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" person_id="21"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <metrics delete_historical_data="[null]" id="1" name="minor_violations" VAL_TYPE="INT" DESCRIPTION="[null]" enabled="[true]"/>
-
- <rules tags="[null]" system_tags="[null]" id="30" name="Classes that override clone should be Cloneable and call super.clone()"
- plugin_rule_key="S1182"
- plugin_config_key="S1182" plugin_name="squid" description="[null]" priority="4" status="READY"
- is_template="[false]" template_id="[null]"/>
-
- <rules tags="[null]" system_tags="[null]" id="31" name="Overriding methods should do more than simply call the same method in the super class"
- plugin_rule_key="S1185"
- plugin_config_key="S1185" plugin_name="squid" description="[null]" priority="1" status="READY"
- is_template="[false]" template_id="[null]"/>
-
- <!-- project -->
- <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
- root_id="[null]" uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD."
- enabled="[true]"/>
-
- <!-- snapshots -->
- <snapshots id="1000" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1225544280000" build_date="1225544280000" version="[null]" path=""
- status="P" islast="[false]" depth="0"/>
-
- <!-- project measures -->
- <project_measures id="1" VALUE="60" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
-
- <project_measures id="2" VALUE="20" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="30" characteristic_id="[null]" person_id="[null]"/>
-
- <project_measures id="3" VALUE="40" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="31" characteristic_id="[null]" person_id="[null]"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <metrics id="10" name="authors_by_line"/>
- <metrics id="11" name="coverage_line_hits_data"/>
- <metrics id="12" name="ncloc"/>
-
- <projects id="1" kee="org.struts:struts-core:src/org/struts/RequestContext.java" enabled="[true]"/>
-
- <snapshots id="5" project_id="1" islast="[true]" />
-
- <project_measures id="20" snapshot_id="5" metric_id="10" value="[null]" text_value="0123456789012345678901234567890123456789" measure_data="[null]"
- variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
- alert_status="[null]" alert_text="[null]" />
- <project_measures id="21" snapshot_id="5" metric_id="11" value="[null]" text_value="36=1;37=1;38=1;39=1;43=1;48=1;53=1" measure_data="[null]"
- variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
- alert_status="[null]" alert_text="[null]" />
- <project_measures id="22" snapshot_id="5" metric_id="12" value="10" text_value="[null]" measure_data="[null]"
- variation_value_1="1" variation_value_2="2" variation_value_3="3" variation_value_4="4" variation_value_5="-5"
- alert_status="OK" alert_text="Green"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <file_sources id="101" project_uuid="PRJ_UUID" file_uuid="FILE1_UUID"
- binary_data="abcde" data_hash="hash"
- line_hashes="ABC\nDEF\nGHI"
- src_hash="FILE_HASH"
- created_at="1500000000000" updated_at="1500000000000" data_type="SOURCE" />
-
-
- <file_sources id="102" project_uuid="PRJ_UUID" file_uuid="FILE2_UUID"
- binary_data="[ignore]"
- data_hash="FILE2_DATA_HASH"
- line_hashes="LINE1_HASH\nLINE2_HASH"
- src_hash="FILE2_HASH"
- created_at="1500000000000" updated_at="1500000000001" data_type="SOURCE" />
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <file_sources id="101" project_uuid="PRJ_UUID" file_uuid="FILE1_UUID"
- binary_data="abcde" data_hash="[null]"
- line_hashes="[null]"
- src_hash="[null]"
- created_at="1500000000000" updated_at="1500000000000" data_type="TEST" />
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <file_sources id="101" project_uuid="PRJ_UUID" file_uuid="FILE1_UUID"
- binary_data="abcde" data_hash="hash"
- line_hashes="ABC\nDEF\nGHI"
- src_hash="FILE_HASH"
- created_at="1500000000000" updated_at="1500000000000" data_type="SOURCE" />
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <file_sources id="101" project_uuid="PRJ_UUID" file_uuid="FILE1_UUID"
- binary_data="[ignore]"
- data_hash="NEW_DATA_HASH"
- line_hashes="NEW_LINE_HASHES"
- src_hash="NEW_FILE_HASH"
- created_at="1500000000000" updated_at="1500000000002" data_type="SOURCE" />
-
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <!-- Updated -->
- <file_sources id="101" project_uuid="ABCD" file_uuid="FILE1_UUID"
- binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
- created_at="1500000000000" updated_at="1500000000002" data_type="SOURCE" />
-
- <!-- Not updated because updated_at is not null -->
- <file_sources id="102" project_uuid="ABCD" file_uuid="FILE2_UUID"
- binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
- created_at="1500000000000" updated_at="1500000000000" data_type="SOURCE" />
-
- <!-- Not updated because on another project -->
- <file_sources id="103" project_uuid="BCDE" file_uuid="FILE3_UUID"
- binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
- created_at="1500000000000" updated_at="0" data_type="SOURCE" />
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <!-- Only this source should be updated -->
- <file_sources id="101" project_uuid="ABCD" file_uuid="FILE1_UUID"
- binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
- created_at="1500000000000" updated_at="0" data_type="SOURCE" />
-
- <file_sources id="102" project_uuid="ABCD" file_uuid="FILE2_UUID"
- binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
- created_at="1500000000000" updated_at="1500000000000" data_type="SOURCE" />
-
- <file_sources id="103" project_uuid="BCDE" file_uuid="FILE3_UUID"
- binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
- created_at="1500000000000" updated_at="0" data_type="SOURCE" />
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <groups_users user_id="1" group_id="2"/>
- <groups_users user_id="2" group_id="2"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <groups_users user_id="1" group_id="1"/>
- <groups_users user_id="2" group_id="1"/>
- <groups_users user_id="1" group_id="2"/>
- <groups_users user_id="2" group_id="2"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <groups_users user_id="1" group_id="2"/>
-
-</dataset>
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.core.util;
+
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.atomic.AtomicLong;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+
+/**
+ * Background thread that logs the state of a counter at fixed intervals.
+ */
+public class ProgressLogger {
+
+ public static final long DEFAULT_PERIOD_MS = 60000L;
+
+ private final Timer timer;
+ private final LoggerTimerTask task;
+ private long periodMs = DEFAULT_PERIOD_MS;
+
+ public ProgressLogger(String threadName, AtomicLong counter, Logger logger) {
+ this.timer = new Timer(threadName);
+ this.task = new LoggerTimerTask(counter, logger);
+ }
+
+ public static ProgressLogger create(Class clazz, AtomicLong counter) {
+ String threadName = String.format("ProgressLogger[%s]", clazz.getSimpleName());
+ Logger logger = Loggers.get(clazz);
+ return new ProgressLogger(threadName, counter, logger);
+ }
+
+ /**
+ * Warning, does not check if already started.
+ */
+ public void start() {
+ // first log after {periodMs} milliseconds
+ timer.schedule(task, periodMs, periodMs);
+ }
+
+ public void stop() {
+ timer.cancel();
+ timer.purge();
+ }
+
+ /**
+ * Default is 1 minute
+ */
+ public ProgressLogger setPeriodMs(long l) {
+ this.periodMs = l;
+ return this;
+ }
+
+ public long getPeriodMs() {
+ return periodMs;
+ }
+
+ /**
+ * For example "issues", "measures", ... Default is "rows".
+ */
+ public ProgressLogger setPluralLabel(String s) {
+ task.pluralLabel = s;
+ return this;
+ }
+
+ public String getPluralLabel() {
+ return task.pluralLabel;
+ }
+
+ public void log() {
+ task.log();
+ }
+
+ private class LoggerTimerTask extends TimerTask {
+ private final AtomicLong counter;
+ private final Logger logger;
+ private String pluralLabel = "rows";
+ private long previousCounter = 0L;
+
+ private LoggerTimerTask(AtomicLong counter, Logger logger) {
+ this.counter = counter;
+ this.logger = logger;
+ }
+
+ @Override
+ public void run() {
+ log();
+ }
+
+ private void log() {
+ long current = counter.get();
+ logger.info(String.format("%d %s processed (%d items/sec)", current, pluralLabel, 1000 * (current - previousCounter) / periodMs));
+ previousCounter = current;
+ }
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.core.util;
+
+import java.text.Normalizer;
+import java.util.Locale;
+
+public class Slug {
+
+ private Slug() {
+ }
+
+ public static String slugify(String s) {
+ return Normalizer.normalize(s, Normalizer.Form.NFD)
+ .replaceAll("[^\\p{ASCII}]", "")
+ .replaceAll("[^\\w+]", "-")
+ .replaceAll("\\s+", "-")
+ .replaceAll("[-]+", "-")
+ .replaceAll("^-", "")
+ .replaceAll("-$", "").toLowerCase(Locale.ENGLISH);
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.core.util;
+
+import java.util.concurrent.atomic.AtomicLong;
+import org.junit.Test;
+import org.sonar.api.utils.log.Logger;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.atLeast;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.startsWith;
+import static org.mockito.Mockito.verify;
+
+public class ProgressLoggerTest {
+
+ @Test(timeout = 1000L)
+ public void log_at_fixed_intervals() throws Exception {
+ Logger logger = mock(Logger.class);
+ AtomicLong counter = new AtomicLong(42L);
+ ProgressLogger progress = new ProgressLogger("ProgressLoggerTest", counter, logger);
+ progress.setPeriodMs(1L);
+ progress.start();
+ Thread.sleep(80L);
+ progress.stop();
+ verify(logger, atLeast(1)).info(startsWith("42 rows processed"));
+
+ // ability to manual log, generally final status
+ counter.incrementAndGet();
+ progress.log();
+ verify(logger).info(startsWith("43 rows processed"));
+ }
+
+ @Test
+ public void create() {
+ ProgressLogger progress = ProgressLogger.create(getClass(), new AtomicLong());
+
+ // default values
+ assertThat(progress.getPeriodMs()).isEqualTo(60000L);
+ assertThat(progress.getPluralLabel()).isEqualTo("rows");
+
+ // override values
+ progress.setPeriodMs(10L);
+ progress.setPluralLabel("issues");
+ assertThat(progress.getPeriodMs()).isEqualTo(10L);
+ assertThat(progress.getPluralLabel()).isEqualTo("issues");
+
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.core.util;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class SlugTest {
+
+ @Test
+ public void slugify() {
+ assertThat(Slug.slugify("foo")).isEqualTo("foo");
+ assertThat(Slug.slugify(" FOO ")).isEqualTo("foo");
+ assertThat(Slug.slugify("he's here")).isEqualTo("he-s-here");
+ assertThat(Slug.slugify("foo-bar")).isEqualTo("foo-bar");
+ assertThat(Slug.slugify("foo_bar")).isEqualTo("foo_bar");
+ assertThat(Slug.slugify("accents éà ")).isEqualTo("accents-ea");
+ assertThat(Slug.slugify("<foo>")).isEqualTo("foo");
+ assertThat(Slug.slugify("<\"foo:\">")).isEqualTo("foo");
+ }
+}
+++ /dev/null
-/*
- * 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();
-
-}
+++ /dev/null
-/*
- * 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;
-
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;
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db;
+
+import org.sonar.api.utils.System2;
+
+public abstract class AbstractDao implements Dao {
+
+ private final MyBatis myBatis;
+ private final System2 system2;
+
+ public AbstractDao(MyBatis myBatis, System2 system2) {
+ this.myBatis = myBatis;
+ this.system2 = system2;
+ }
+
+ protected MyBatis myBatis() {
+ return myBatis;
+ }
+
+ protected long now() {
+ return system2.now();
+ }
+}
*/
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;
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,
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();
- }
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db;
+
+import com.google.common.base.Throwables;
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.apache.commons.dbutils.DbUtils;
+import org.apache.commons.lang.StringUtils;
+import org.picocontainer.Startable;
+import org.sonar.api.utils.MessageException;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.db.dialect.H2;
+import org.sonar.db.dialect.Oracle;
+
+public class DatabaseChecker implements Startable {
+
+ public static final int ORACLE_MIN_MAJOR_VERSION = 11;
+
+ private final Database db;
+
+ public DatabaseChecker(Database db) {
+ this.db = db;
+ }
+
+ @Override
+ public void start() {
+ try {
+ if (H2.ID.equals(db.getDialect().getId())) {
+ Loggers.get(DatabaseChecker.class).warn("H2 database should be used for evaluation purpose only");
+ } else if (Oracle.ID.equals(db.getDialect().getId())) {
+ checkOracleVersion();
+ }
+ } catch (Exception e) {
+ Throwables.propagate(e);
+ }
+ }
+
+ @Override
+ public void stop() {
+ // nothing to do
+ }
+
+ private void checkOracleVersion() throws SQLException {
+ Connection connection = db.getDataSource().getConnection();
+ try {
+ // check version of db
+ // See http://jira.sonarsource.com/browse/SONAR-6434
+ int majorVersion = connection.getMetaData().getDatabaseMajorVersion();
+ if (majorVersion < ORACLE_MIN_MAJOR_VERSION) {
+ throw MessageException.of(String.format(
+ "Unsupported Oracle version: %s. Minimal required version is %d.", connection.getMetaData().getDatabaseProductVersion(), ORACLE_MIN_MAJOR_VERSION));
+ }
+
+ // check version of driver
+ String driverVersion = connection.getMetaData().getDriverVersion();
+ String[] parts = StringUtils.split(driverVersion, ".");
+ int intVersion = Integer.parseInt(parts[0]) * 100 + Integer.parseInt(parts[1]);
+ if (intVersion < 1102) {
+ throw MessageException.of(String.format(
+ "Unsupported Oracle JDBC driver version: %s. Minimal required version is 11.2.", driverVersion));
+ }
+
+ } finally {
+ DbUtils.closeQuietly(connection);
+ }
+ }
+
+}
*/
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
}
}
}
}
+
+ /**
+ * 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();
+ }
}
--- /dev/null
+/*
+ * 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);
+ }
+}
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;
*/
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.";
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();
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);
}
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);
}
}
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;
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;
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) {
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
}
}
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);
return openSession(false);
}
- /**
- * @deprecated since 4.4. Replaced by <code>openSession(true)</code>.
- */
- @Deprecated
- public BatchSession openBatchSession() {
- return (BatchSession) openSession(true);
- }
-
/**
* @since 4.4
*/
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);
+ }
+ }
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db;
+
+import org.apache.commons.dbutils.DbUtils;
+
+import java.io.Closeable;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/**
+ * Forward-only {@link java.util.Iterator} over a {@link java.sql.ResultSet}. Rows are
+ * lazily loaded. The underlying ResultSet must be closed by calling the method
+ * {@link #close()}
+ * <p/>
+ * As a safeguard, the ResultSet is automatically closed after the last element has
+ * been retrieved via {@link #next()} or {@link #hasNext()} is called (which will return false).
+ * This automagic behavior is not enough to remove explicit calls to {@link #close()}
+ * from caller methods. Errors raised before end of traversal must still be handled.
+ */
+public abstract class ResultSetIterator<E> implements Iterator<E>, Closeable {
+
+ private final ResultSet rs;
+ private final PreparedStatement stmt;
+
+ private volatile boolean didNext = false;
+ private volatile boolean hasNext = false;
+ private volatile boolean closed = false;
+
+ public ResultSetIterator(PreparedStatement stmt) throws SQLException {
+ this.stmt = stmt;
+ this.rs = stmt.executeQuery();
+ }
+
+ protected ResultSetIterator(ResultSet rs) {
+ this.stmt = null;
+ this.rs = rs;
+ }
+
+ @Override
+ public boolean hasNext() {
+ if (closed) {
+ return false;
+ }
+ if (!didNext) {
+ hasNext = doNextQuietly();
+ if (hasNext) {
+ didNext = true;
+ } else {
+ close();
+ }
+ }
+ return hasNext;
+ }
+
+ @Override
+ public E next() {
+ if (!hasNext()) {
+ close();
+ throw new NoSuchElementException();
+ }
+ try {
+ return read(rs);
+ } catch (SQLException e) {
+ throw new IllegalStateException("Fail to read result set row", e);
+ } finally {
+ hasNext = doNextQuietly();
+ if (!hasNext) {
+ close();
+ }
+ }
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void close() {
+ closed = true;
+ DbUtils.closeQuietly(rs);
+ DbUtils.closeQuietly(stmt);
+ }
+
+ protected abstract E read(ResultSet rs) throws SQLException;
+
+ private boolean doNextQuietly() {
+ try {
+ return rs.next();
+ } catch (SQLException e) {
+ throw new IllegalStateException("Fail to read row of JDBC result set", e);
+ }
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.activity;
+
+import java.util.Date;
+import org.sonar.api.utils.System2;
+import org.sonar.db.AbstractDao;
+import org.sonar.db.DbSession;
+import org.sonar.db.MyBatis;
+
+public class ActivityDao extends AbstractDao {
+
+ public ActivityDao(MyBatis mybatis, System2 system) {
+ super(mybatis, system);
+ }
+
+ public void insert(ActivityDto dto) {
+ DbSession session = myBatis().openSession(false);
+ try {
+ insert(session, dto);
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public void insert(DbSession session, ActivityDto dto) {
+ dto.setCreatedAt(new Date(now()));
+ session.getMapper(ActivityMapper.class).insert(dto);
+ }
+
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.db.component;
-
-import java.util.List;
-import org.apache.ibatis.annotations.Param;
-
-public interface ComponentIndexMapper {
-
- List<Long> selectProjectIdsFromQueryAndViewOrSubViewUuid(@Param("query") String query, @Param("viewUuidQuery") String viewUuidQuery);
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.db.component;
+
+import java.util.List;
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+
+public class ComponentLinkDao implements Dao {
+
+ public List<ComponentLinkDto> selectByComponentUuid(DbSession session, String componentUuid) {
+ return session.getMapper(ComponentLinkMapper.class).selectByComponentUuid(componentUuid);
+ }
+
+ public void insert(DbSession session, ComponentLinkDto dto) {
+ session.getMapper(ComponentLinkMapper.class).insert(dto);
+ }
+
+ public void update(DbSession session, ComponentLinkDto dto) {
+ session.getMapper(ComponentLinkMapper.class).update(dto);
+ }
+
+ public void delete(DbSession session, long id) {
+ session.getMapper(ComponentLinkMapper.class).delete(id);
+ }
+
+}
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);
}
}
*/
@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);
}
}
}
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);
}
}
}
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);
}
}
* 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) {
}
session.commit();
} finally {
- MyBatis.closeQuietly(session);
+ myBatis().closeQuietly(session);
}
return this;
}
* 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
@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);
}
}
*/
@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;
return component;
}
} finally {
- MyBatis.closeQuietly(session);
+ myBatis().closeQuietly(session);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
}
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);
}
}
*/
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;
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();
* 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() {
}
public boolean indexResource(long id) {
- DbSession session = mybatis.openSession(false);
+ DbSession session = myBatis().openSession(false);
try {
return indexResource(session, id);
} finally {
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);
*/
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);
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;
*
* @since 3.2
*/
-public class ResourceKeyUpdaterDao {
+public class ResourceKeyUpdaterDao implements Dao {
private MyBatis mybatis;
public ResourceKeyUpdaterDao(MyBatis mybatis) {
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.db.component;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
+import java.util.Collection;
+import java.util.List;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.sonar.api.resources.Scopes;
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+
+public class SnapshotDao implements Dao {
+
+ @CheckForNull
+ public SnapshotDto selectNullableById(DbSession session, long id) {
+ return mapper(session).selectByKey(id);
+ }
+
+ public SnapshotDto selectById(DbSession session, long id) {
+ SnapshotDto value = selectNullableById(session, id);
+ if (value == null) {
+ throw new IllegalArgumentException(String.format("Snapshot id does not exist: %d", id));
+ }
+ return value;
+ }
+
+ @CheckForNull
+ public SnapshotDto selectLastSnapshotByComponentId(DbSession session, long componentId) {
+ return mapper(session).selectLastSnapshot(componentId);
+ }
+
+ public List<SnapshotDto> selectSnapshotsByComponentId(DbSession session, long componentId) {
+ return mapper(session).selectSnapshotsByQuery(new SnapshotQuery().setComponentId(componentId));
+ }
+
+ public List<SnapshotDto> selectSnapshotsByQuery(DbSession session, SnapshotQuery query) {
+ return mapper(session).selectSnapshotsByQuery(query);
+ }
+
+ public List<SnapshotDto> selectPreviousVersionSnapshots(DbSession session, long componentId, String lastVersion) {
+ return mapper(session).selectPreviousVersionSnapshots(componentId, lastVersion);
+ }
+
+ public List<SnapshotDto> selectSnapshotAndChildrenOfProjectScope(DbSession session, long snapshotId) {
+ return mapper(session).selectSnapshotAndChildrenOfScope(snapshotId, Scopes.PROJECT);
+ }
+
+ public int updateSnapshotAndChildrenLastFlagAndStatus(DbSession session, SnapshotDto snapshot, boolean isLast, String status) {
+ Long rootId = snapshot.getId();
+ String path = Strings.nullToEmpty(snapshot.getPath()) + snapshot.getId() + ".%";
+ Long pathRootId = snapshot.getRootIdOrSelf();
+
+ return mapper(session).updateSnapshotAndChildrenLastFlagAndStatus(rootId, pathRootId, path, isLast, status);
+ }
+
+ public int updateSnapshotAndChildrenLastFlag(DbSession session, SnapshotDto snapshot, boolean isLast) {
+ Long rootId = snapshot.getId();
+ String path = Strings.nullToEmpty(snapshot.getPath()) + snapshot.getId() + ".%";
+ Long pathRootId = snapshot.getRootIdOrSelf();
+
+ return mapper(session).updateSnapshotAndChildrenLastFlag(rootId, pathRootId, path, isLast);
+ }
+
+ public static boolean isLast(SnapshotDto snapshotTested, @Nullable SnapshotDto previousLastSnapshot) {
+ return previousLastSnapshot == null || previousLastSnapshot.getCreatedAt() < snapshotTested.getCreatedAt();
+ }
+
+ public SnapshotDto insert(DbSession session, SnapshotDto item) {
+ mapper(session).insert(item);
+ return item;
+ }
+
+ public void insert(DbSession session, Collection<SnapshotDto> items) {
+ for (SnapshotDto item : items) {
+ insert(session, item);
+ }
+ }
+
+ public void insert(DbSession session, SnapshotDto item, SnapshotDto... others) {
+ insert(session, Lists.asList(item, others));
+ }
+
+ private SnapshotMapper mapper(DbSession session) {
+ return session.getMapper(SnapshotMapper.class);
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.db.compute;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.sonar.api.utils.System2;
+import org.sonar.db.compute.AnalysisReportDto;
+import org.sonar.db.compute.AnalysisReportMapper;
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+
+import javax.annotation.CheckForNull;
+
+import java.util.List;
+
+import static org.sonar.db.compute.AnalysisReportDto.Status.PENDING;
+import static org.sonar.db.compute.AnalysisReportDto.Status.WORKING;
+
+public class AnalysisReportDao implements Dao {
+
+ private System2 system2;
+
+ public AnalysisReportDao(System2 system2) {
+ this.system2 = system2;
+ }
+
+ /**
+ * Update all rows with: STATUS='PENDING', STARTED_AT=NULL, UPDATED_AT={now}
+ */
+ public void resetAllToPendingStatus(DbSession session) {
+ mapper(session).resetAllToPendingStatus(system2.now());
+ }
+
+ public void truncate(DbSession session) {
+ mapper(session).truncate();
+ }
+
+ public List<AnalysisReportDto> selectByProjectKey(DbSession session, String projectKey) {
+ return mapper(session).selectByProjectKey(projectKey);
+ }
+
+ @VisibleForTesting
+ AnalysisReportDto selectById(DbSession session, long id) {
+ return mapper(session).selectById(id);
+ }
+
+ @CheckForNull
+ public AnalysisReportDto pop(DbSession session) {
+ List<Long> reportIds = mapper(session).selectAvailables(PENDING, WORKING);
+ if (reportIds.isEmpty()) {
+ return null;
+ }
+
+ long reportId = reportIds.get(0);
+ return tryToPop(session, reportId);
+ }
+
+ @VisibleForTesting
+ AnalysisReportDto tryToPop(DbSession session, long reportId) {
+ AnalysisReportMapper mapper = mapper(session);
+ int nbOfReportBooked = mapper.updateWithBookingReport(reportId, system2.now(), PENDING, WORKING);
+ if (nbOfReportBooked == 0) {
+ return null;
+ }
+
+ AnalysisReportDto result = mapper.selectById(reportId);
+ session.commit();
+ return result;
+ }
+
+ public List<AnalysisReportDto> selectAll(DbSession session) {
+ return mapper(session).selectAll();
+ }
+
+ public AnalysisReportDto insert(DbSession session, AnalysisReportDto report) {
+ report.setCreatedAt(system2.now());
+ report.setUpdatedAt(system2.now());
+ mapper(session).insert(report);
+ return report;
+ }
+
+ public void delete(DbSession session, long id) {
+ mapper(session).delete(id);
+ }
+
+ private AnalysisReportMapper mapper(DbSession session) {
+ return session.getMapper(AnalysisReportMapper.class);
+ }
+}
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;
*/
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 {
}
}
+ @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);
+ }
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.dashboard;
+
+import java.util.Collection;
+import org.sonar.db.dashboard.WidgetDto;
+import org.sonar.db.dashboard.WidgetMapper;
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+import org.sonar.db.MyBatis;
+
+public class WidgetDao implements Dao {
+
+ private MyBatis myBatis;
+
+ public WidgetDao(MyBatis myBatis) {
+ this.myBatis = myBatis;
+ }
+
+ public WidgetDto getNullableByKey(Long widgetId) {
+ DbSession session = myBatis.openSession(false);
+ try {
+ return getNullableByKey(session, widgetId);
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public WidgetDto getNullableByKey(DbSession session, Long widgetId) {
+ return mapper(session).selectById(widgetId);
+ }
+
+ public WidgetDto update(WidgetDto item) {
+ DbSession session = myBatis.openSession(false);
+ try {
+ return update(session, item);
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public WidgetDto update(DbSession session, WidgetDto item) {
+ mapper(session).update(item);
+ return item;
+ }
+
+ public Collection<WidgetDto> findByDashboard(DbSession session, long dashboardKey) {
+ return mapper(session).selectByDashboard(dashboardKey);
+ }
+
+ public Collection<WidgetDto> findAll(DbSession session) {
+ return mapper(session).selectAll();
+ }
+
+ private WidgetMapper mapper(DbSession session) {
+ return session.getMapper(WidgetMapper.class);
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.dashboard;
+
+import com.google.common.base.Function;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import org.sonar.db.Dao;
+import org.sonar.db.DaoUtils;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.db.DbSession;
+import org.sonar.db.MyBatis;
+
+public class WidgetPropertyDao implements Dao {
+
+ private final MyBatis myBatis;
+
+ public WidgetPropertyDao(MyBatis myBatis) {
+ this.myBatis = myBatis;
+ }
+
+ public WidgetPropertyDto insert(WidgetPropertyDto item) {
+ DbSession session = myBatis.openSession(false);
+ try {
+ return insert(session, item);
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public WidgetPropertyDto insert(DbSession session, WidgetPropertyDto item) {
+ mapper(session).insert(item);
+ return item;
+ }
+
+ public void insert(DbSession session, Collection<WidgetPropertyDto> items) {
+ for (WidgetPropertyDto item : items) {
+ insert(session, item);
+ }
+ }
+
+ public WidgetPropertyDto getNullableByKey(Long propertyId) {
+ DbSession session = myBatis.openSession(false);
+ try {
+ return getNullableByKey(session, propertyId);
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public WidgetPropertyDto getNullableByKey(DbSession session, Long propertyId) {
+ return mapper(session).selectById(propertyId);
+ }
+
+ public Collection<WidgetPropertyDto> findByDashboard(DbSession session, long dashboardKey) {
+ return mapper(session).selectByDashboard(dashboardKey);
+ }
+
+ public void deleteByWidgetIds(final DbSession session, List<Long> widgetIdsWithPropertiesToDelete) {
+ DatabaseUtils.executeLargeInputs(widgetIdsWithPropertiesToDelete, new Function<List<Long>, List<Void>>() {
+ @Override
+ public List<Void> apply(List<Long> input) {
+ mapper(session).deleteByWidgetIds(input);
+ return Arrays.asList();
+ }
+ });
+ }
+
+ private WidgetPropertyMapper mapper(DbSession session) {
+ return session.getMapper(WidgetPropertyMapper.class);
+ }
+}
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;
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.db.event;
+
+import java.util.List;
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+
+public class EventDao implements Dao {
+
+ public List<EventDto> selectByComponentUuid(DbSession session, String componentUuid) {
+ return session.getMapper(EventMapper.class).selectByComponentUuid(componentUuid);
+ }
+
+ public void insert(DbSession session, EventDto dto) {
+ session.getMapper(EventMapper.class).insert(dto);
+ }
+
+ public void delete(DbSession session, Long id) {
+ session.getMapper(EventMapper.class).delete(id);
+ }
+
+}
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;
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 {
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;
}
}
- 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);
}
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;
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.db.measure;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Lists;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+import javax.annotation.CheckForNull;
+import org.sonar.db.Dao;
+import org.sonar.db.DaoUtils;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.db.DbSession;
+import org.sonar.db.component.SnapshotDto;
+
+public class MeasureDao implements Dao {
+
+ public boolean existsByKey(DbSession session, String componentKey, String metricKey) {
+ return mapper(session).countByComponentAndMetric(componentKey, metricKey) > 0;
+ }
+
+ @CheckForNull
+ public MeasureDto findByComponentKeyAndMetricKey(DbSession session, String componentKey, String metricKey) {
+ return mapper(session).selectByComponentAndMetric(componentKey, metricKey);
+ }
+
+ public List<MeasureDto> findByComponentKeyAndMetricKeys(final DbSession session, final String componentKey, List<String> metricKeys) {
+ return DatabaseUtils.executeLargeInputs(metricKeys, new Function<List<String>, List<MeasureDto>>() {
+ @Override
+ public List<MeasureDto> apply(List<String> keys) {
+ return mapper(session).selectByComponentAndMetrics(componentKey, keys);
+ }
+ });
+ }
+
+ public List<PastMeasureDto> selectByComponentUuidAndProjectSnapshotIdAndMetricIds(final DbSession session, final String componentUuid, final long projectSnapshotId,
+ Set<Integer> metricIds) {
+ return DatabaseUtils.executeLargeInputs(metricIds, new Function<List<Integer>, List<PastMeasureDto>>() {
+ @Override
+ public List<PastMeasureDto> apply(List<Integer> ids) {
+ return mapper(session).selectByComponentUuidAndProjectSnapshotIdAndStatusAndMetricIds(componentUuid, projectSnapshotId, ids,
+ SnapshotDto.STATUS_PROCESSED);
+ }
+ });
+ }
+
+ public void insert(DbSession session, MeasureDto measureDto) {
+ mapper(session).insert(measureDto);
+ }
+
+ public void insert(DbSession session, Collection<MeasureDto> items) {
+ for (MeasureDto item : items) {
+ insert(session, item);
+ }
+ }
+
+ public void insert(DbSession session, MeasureDto item, MeasureDto... others) {
+ insert(session, Lists.asList(item, others));
+ }
+
+ public List<String> selectMetricKeysForSnapshot(DbSession session, long snapshotId) {
+ return mapper(session).selectMetricKeysForSnapshot(snapshotId);
+ }
+
+ private MeasureMapper mapper(DbSession session) {
+ return session.getMapper(MeasureMapper.class);
+ }
+}
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) {
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;
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";
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;
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);
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);
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);
purge(project, conf.scopesWithoutHistoricalData(), commands);
}
for (ResourceDto project : projects) {
- disableOrphanResources(project, session, mapper, purgeListener);
+ disableOrphanResources(project, session, mapper, listener);
}
deleteOldClosedIssues(conf, mapper);
}
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;
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;
}
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;
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) {
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);
}
}
+++ /dev/null
-/*
- * 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();
- }
- }
-}
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;
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;
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.db.source;
+
+import com.google.common.base.Function;
+import com.google.common.base.Splitter;
+import java.io.Reader;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+import javax.annotation.CheckForNull;
+import org.apache.commons.dbutils.DbUtils;
+import org.apache.commons.io.IOUtils;
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+import org.sonar.db.MyBatis;
+import org.sonar.db.source.FileSourceDto.Type;
+
+public class FileSourceDao implements Dao {
+
+ private static final Splitter END_OF_LINE_SPLITTER = Splitter.on('\n');
+ private final MyBatis mybatis;
+
+ public FileSourceDao(MyBatis myBatis) {
+ this.mybatis = myBatis;
+ }
+
+ @CheckForNull
+ public FileSourceDto selectSource(String fileUuid) {
+ DbSession session = mybatis.openSession(false);
+ try {
+ return mapper(session).select(fileUuid, Type.SOURCE);
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ @CheckForNull
+ public FileSourceDto selectTest(String fileUuid) {
+ DbSession session = mybatis.openSession(false);
+ try {
+ return mapper(session).select(fileUuid, Type.TEST);
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ @CheckForNull
+ public List<String> selectLineHashes(DbSession dbSession, String fileUuid) {
+ Connection connection = dbSession.getConnection();
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
+ try {
+ pstmt = connection.prepareStatement("SELECT line_hashes FROM file_sources WHERE file_uuid=? AND data_type=?");
+ pstmt.setString(1, fileUuid);
+ pstmt.setString(2, Type.SOURCE);
+ rs = pstmt.executeQuery();
+ if (rs.next()) {
+ return END_OF_LINE_SPLITTER.splitToList(rs.getString(1));
+ }
+ return null;
+ } catch (SQLException e) {
+ throw new IllegalStateException("Fail to read FILE_SOURCES.LINE_HASHES of file " + fileUuid, e);
+ } finally {
+ DbUtils.closeQuietly(connection, pstmt, rs);
+ }
+ }
+
+ public <T> void readLineHashesStream(DbSession dbSession, String fileUuid, Function<Reader, T> function) {
+ Connection connection = dbSession.getConnection();
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
+ Reader reader = null;
+ try {
+ pstmt = connection.prepareStatement("SELECT line_hashes FROM file_sources WHERE file_uuid=? AND data_type=?");
+ pstmt.setString(1, fileUuid);
+ pstmt.setString(2, Type.SOURCE);
+ rs = pstmt.executeQuery();
+ if (rs.next()) {
+ reader = rs.getCharacterStream(1);
+ function.apply(reader);
+ }
+ } catch (SQLException e) {
+ throw new IllegalStateException("Fail to read FILE_SOURCES.LINE_HASHES of file " + fileUuid, e);
+ } finally {
+ IOUtils.closeQuietly(reader);
+ DbUtils.closeQuietly(connection, pstmt, rs);
+ }
+ }
+
+ public void insert(FileSourceDto dto) {
+ DbSession session = mybatis.openSession(false);
+ try {
+ insert(session, dto);
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public void insert(DbSession session, FileSourceDto dto) {
+ mapper(session).insert(dto);
+ }
+
+ public void update(FileSourceDto dto) {
+ DbSession session = mybatis.openSession(false);
+ try {
+ update(session, dto);
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public void update(DbSession session, FileSourceDto dto) {
+ mapper(session).update(dto);
+ }
+
+ public void updateDateWhenUpdatedDateIsZero(DbSession session, String projectUuid, long updateDate) {
+ mapper(session).updateDateWhenUpdatedDateIsZero(projectUuid, updateDate);
+ }
+
+ private FileSourceMapper mapper(DbSession session) {
+ return session.getMapper(FileSourceMapper.class);
+ }
+}
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;
}
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);
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;
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) {
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;
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);
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);
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.db.user;
+
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+
+public class UserGroupDao implements Dao {
+
+ public UserGroupDto insert(DbSession session, UserGroupDto dto) {
+ mapper(session).insert(dto);
+ return dto;
+ }
+
+ public void delete(DbSession session, UserGroupDto dto) {
+ mapper(session).delete(dto);
+ }
+
+ public void deleteMembersByGroupId(DbSession session, long groupId) {
+ mapper(session).deleteMembersByGroup(groupId);
+ }
+
+ protected UserGroupMapper mapper(DbSession session) {
+ return session.getMapper(UserGroupMapper.class);
+ }
+}
+++ /dev/null
-<?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>
-
<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
*/
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();
}
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db;
+
+import java.sql.SQLException;
+import org.apache.commons.lang.StringUtils;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.sonar.api.utils.MessageException;
+import org.sonar.db.dialect.Dialect;
+import org.sonar.db.dialect.H2;
+import org.sonar.db.dialect.MySql;
+import org.sonar.db.dialect.Oracle;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class DatabaseCheckerTest {
+
+ @Test
+ public void requires_oracle_driver_11_2() throws Exception {
+ Database db = mockDb(new Oracle(), "11.2.1", "11.2.0.0.1");
+ new DatabaseChecker(db).start();
+ // no error
+
+ db = mockDb(new Oracle(), "11.2.1", "11.3.1");
+ new DatabaseChecker(db).start();
+ // no error
+
+ db = mockDb(new Oracle(), "11.2.1", "12.0.2");
+ new DatabaseChecker(db).start();
+ // no error
+
+ db = mockDb(new Oracle(), "11.2.1", "11.1.0.2");
+ try {
+ new DatabaseChecker(db).start();
+ fail();
+ } catch (MessageException e) {
+ assertThat(e).hasMessage("Unsupported Oracle JDBC driver version: 11.1.0.2. Minimal required version is 11.2.");
+ }
+ }
+
+ @Test
+ public void requires_oracle_11g_or_greater() throws Exception {
+ // oracle 11.0 is ok
+ Database db = mockDb(new Oracle(), "11.0.1", "11.2.0.0.1");
+ new DatabaseChecker(db).start();
+
+ // oracle 11.1 is ok
+ db = mockDb(new Oracle(), "11.1.1", "11.2.0.0.1");
+ new DatabaseChecker(db).start();
+
+ // oracle 11.2 is ok
+ db = mockDb(new Oracle(), "11.2.1", "11.2.0.0.1");
+ new DatabaseChecker(db).start();
+
+ // oracle 12 is ok
+ db = mockDb(new Oracle(), "12.0.1", "11.2.0.0.1");
+ new DatabaseChecker(db).start();
+
+ // oracle 10 is not supported
+ db = mockDb(new Oracle(), "10.2.1", "11.2.0.0.1");
+ try {
+ new DatabaseChecker(db).start();
+ fail();
+ } catch (MessageException e) {
+ assertThat(e).hasMessage("Unsupported Oracle version: 10.2.1. Minimal required version is 11.");
+ }
+ }
+
+ @Test
+ public void log_warning_if_h2() throws Exception {
+ Database db = mockDb(new H2(), "13.4", "13.4");
+ DatabaseChecker checker = new DatabaseChecker(db);
+ checker.start();
+ checker.stop();
+ // TODO test log
+ }
+
+ @Test
+ public void do_not_fail_if_mysql() throws Exception {
+ Database db = mockDb(new MySql(), "5.7", "5.7");
+ new DatabaseChecker(db).start();
+ // no error
+ }
+
+ private Database mockDb(Dialect dialect, String dbVersion, String driverVersion) throws SQLException {
+ Database db = mock(Database.class, Mockito.RETURNS_DEEP_STUBS);
+ when(db.getDialect()).thenReturn(dialect);
+ when(db.getDataSource().getConnection().getMetaData().getDatabaseMajorVersion()).thenReturn(Integer.parseInt(StringUtils.substringBefore(dbVersion, ".")));
+ when(db.getDataSource().getConnection().getMetaData().getDatabaseProductVersion()).thenReturn(dbVersion);
+ when(db.getDataSource().getConnection().getMetaData().getDriverVersion()).thenReturn(driverVersion);
+ return db;
+ }
+}
*/
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;
}
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();
+ }
}
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;
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;
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;
* 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);
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()) {
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);
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];
}
prepareDbUnit(streams);
- commands.resetPrimaryKeys(db.getDataSource());
+ db.getCommands().resetPrimaryKeys(db.getDatabase().getDataSource());
} catch (SQLException e) {
throw translateException("Could not setup DBUnit data", e);
} finally {
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 {
}
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);
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);
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();
// 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();
+ }
}
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());
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.NoSuchElementException;
+import org.apache.commons.dbutils.DbUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.sonar.api.utils.System2;
+import org.sonar.test.DbTests;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.fail;
+
+@Category(DbTests.class)
+public class ResultSetIteratorTest {
+
+ @ClassRule
+ public static DbTester dbTester = DbTester.createForSchema(System2.INSTANCE, ResultSetIteratorTest.class, "schema.sql");
+
+ Connection connection = null;
+
+ @Before
+ public void setUp() throws Exception {
+ connection = dbTester.openConnection();
+ }
+
+ @After
+ public void tearDown() {
+ DbUtils.closeQuietly(connection);
+ }
+
+ @Test
+ public void create_iterator_from_statement() throws Exception {
+ dbTester.prepareDbUnit(getClass(), "feed.xml");
+
+ PreparedStatement stmt = connection.prepareStatement("select * from issues order by id");
+ FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt);
+
+ assertThat(iterator.hasNext()).isTrue();
+
+ // calling multiple times hasNext() is ok
+ assertThat(iterator.hasNext()).isTrue();
+
+ assertThat(iterator.next()).isEqualTo(10);
+ assertThat(iterator.hasNext()).isTrue();
+ assertThat(iterator.next()).isEqualTo(20);
+
+ // call next() without calling hasNext()
+ assertThat(iterator.next()).isEqualTo(30);
+ assertThat(iterator.hasNext()).isFalse();
+
+ try {
+ iterator.next();
+ fail();
+ } catch (NoSuchElementException e) {
+ // ok
+ }
+
+ iterator.close();
+ // statement is closed by ResultSetIterator
+ assertThat(stmt.isClosed()).isTrue();
+ }
+
+ @Test
+ public void iterate_empty_list() throws Exception {
+ dbTester.prepareDbUnit(getClass(), "feed.xml");
+
+ PreparedStatement stmt = connection.prepareStatement("select * from issues where id < 0");
+ FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt);
+
+ assertThat(iterator.hasNext()).isFalse();
+ }
+
+ @Test
+ public void create_iterator_from_result_set() throws Exception {
+ dbTester.prepareDbUnit(getClass(), "feed.xml");
+
+ PreparedStatement stmt = connection.prepareStatement("select * from issues order by id");
+ ResultSet rs = stmt.executeQuery();
+ FirstIntColumnIterator iterator = new FirstIntColumnIterator(rs);
+
+ assertThat(iterator.next()).isEqualTo(10);
+ assertThat(iterator.next()).isEqualTo(20);
+ assertThat(iterator.next()).isEqualTo(30);
+
+ iterator.close();
+ assertThat(rs.isClosed()).isTrue();
+ stmt.close();
+ }
+
+ @Test
+ public void remove_row_is_not_supported() throws Exception {
+ PreparedStatement stmt = connection.prepareStatement("select * from issues order by id");
+ FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt);
+
+ try {
+ iterator.remove();
+ fail();
+ } catch (UnsupportedOperationException ok) {
+ // ok
+ }
+
+ iterator.close();
+ }
+
+ @Test
+ public void fail_to_read_row() throws Exception {
+ dbTester.prepareDbUnit(getClass(), "feed.xml");
+
+ PreparedStatement stmt = connection.prepareStatement("select * from issues order by id");
+ FailIterator iterator = new FailIterator(stmt);
+
+ assertThat(iterator.hasNext()).isTrue();
+ try {
+ iterator.next();
+ fail();
+ } catch (IllegalStateException e) {
+ assertThat(e.getCause()).isInstanceOf(SQLException.class);
+ }
+ iterator.close();
+ }
+
+ private static class FirstIntColumnIterator extends ResultSetIterator<Integer> {
+
+ public FirstIntColumnIterator(PreparedStatement stmt) throws SQLException {
+ super(stmt);
+ }
+
+ public FirstIntColumnIterator(ResultSet rs) {
+ super(rs);
+ }
+
+ @Override
+ protected Integer read(ResultSet rs) throws SQLException {
+ return rs.getInt(1);
+ }
+ }
+
+ private static class FailIterator extends ResultSetIterator<Integer> {
+
+ public FailIterator(PreparedStatement stmt) throws SQLException {
+ super(stmt);
+ }
+
+ @Override
+ protected Integer read(ResultSet rs) throws SQLException {
+ // column does not exist
+ return rs.getInt(1234);
+ }
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.activity;
+
+import java.util.Map;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+import org.sonar.test.DbTests;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@Category(DbTests.class)
+public class ActivityDaoTest {
+
+ System2 system = mock(System2.class);
+
+ @Rule
+ public DbTester dbTester = DbTester.create(system);
+
+ ActivityDao sut = dbTester.getDbClient().activityDao();
+
+ @Test
+ public void insert() {
+ when(system.now()).thenReturn(1_500_000_000_000L);
+ ActivityDto dto = new ActivityDto()
+ .setKey("UUID_1").setAction("THE_ACTION").setType("THE_TYPE")
+ .setAuthor("THE_AUTHOR").setData("THE_DATA");
+ sut.insert(dto);
+
+ Map<String, Object> map = dbTester.selectFirst("select created_at as \"createdAt\", log_action as \"action\", data_field as \"data\" from activities where log_key='UUID_1'");
+ assertThat(map.get("action")).isEqualTo("THE_ACTION");
+ // not possible to check exact date yet. dbTester#selectFirst() uses ResultSet#getObject(), which returns
+ // non-JDBC interface in Oracle driver.
+ assertThat(map.get("createdAt")).isNotNull();
+ assertThat(map.get("data")).isEqualTo("THE_DATA");
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.db.component;
+
+import java.util.List;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+import org.sonar.test.DbTests;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@Category(DbTests.class)
+public class ComponentLinkDaoTest {
+
+ @ClassRule
+ public static DbTester dbTester = DbTester.create(System2.INSTANCE);
+
+ ComponentLinkDao dao = dbTester.getDbClient().componentLinkDao();
+
+ @Test
+ public void select_by_component_uuid() {
+ dbTester.prepareDbUnit(getClass(), "shared.xml");
+
+ List<ComponentLinkDto> links = dao.selectByComponentUuid(dbTester.getSession(), "ABCD");
+ assertThat(links).hasSize(2);
+
+ links = dao.selectByComponentUuid(dbTester.getSession(), "BCDE");
+ assertThat(links).hasSize(1);
+
+ ComponentLinkDto link = links.get(0);
+ assertThat(link.getId()).isEqualTo(3L);
+ assertThat(link.getComponentUuid()).isEqualTo("BCDE");
+ assertThat(link.getType()).isEqualTo("homepage");
+ assertThat(link.getName()).isEqualTo("Home");
+ assertThat(link.getHref()).isEqualTo("http://www.struts.org");
+ }
+
+ @Test
+ public void insert() {
+ dbTester.prepareDbUnit(getClass(), "empty.xml");
+
+ dao.insert(dbTester.getSession(), new ComponentLinkDto()
+ .setComponentUuid("ABCD")
+ .setType("homepage")
+ .setName("Home")
+ .setHref("http://www.sonarqube.org")
+ );
+ dbTester.getSession().commit();
+
+ dbTester.assertDbUnit(getClass(), "insert-result.xml", new String[] {"id"}, "project_links");
+ }
+
+ @Test
+ public void update() {
+ dbTester.prepareDbUnit(getClass(), "update.xml");
+
+ dao.update(dbTester.getSession(), new ComponentLinkDto()
+ .setId(1L)
+ .setComponentUuid("ABCD")
+ .setType("homepage")
+ .setName("Home")
+ .setHref("http://www.sonarqube.org")
+ );
+ dbTester.getSession().commit();
+
+ dbTester.assertDbUnit(getClass(), "update-result.xml", "project_links");
+ }
+
+ @Test
+ public void delete() {
+ dbTester.prepareDbUnit(getClass(), "delete.xml");
+
+ dao.delete(dbTester.getSession(), 1L);
+ dbTester.getSession().commit();
+
+ assertThat(dbTester.countRowsOfTable("project_links")).isEqualTo(0);
+ }
+
+}
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 {
@Before
public void createDao() {
- dao = new ResourceIndexerDao(getMyBatis());
+ dao = new ResourceIndexerDao(getMyBatis(), mock(System2.class));
}
@Test
// 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();
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();
+ }
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.db.component;
+
+import java.util.Date;
+import java.util.List;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.sonar.api.utils.DateUtils;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.test.DbTests;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.db.component.SnapshotQuery.SORT_FIELD.BY_DATE;
+import static org.sonar.db.component.SnapshotQuery.SORT_ORDER.ASC;
+import static org.sonar.db.component.SnapshotQuery.SORT_ORDER.DESC;
+
+@Category(DbTests.class)
+public class SnapshotDaoTest {
+
+ @ClassRule
+ public static DbTester db = new DbTester();
+
+ DbSession session;
+
+ SnapshotDao sut;
+
+ @Before
+ public void createDao() {
+ session = db.myBatis().openSession(false);
+ sut = new SnapshotDao();
+ }
+
+ @After
+ public void tearDown() {
+ session.close();
+ }
+
+ @Test
+ public void get_by_key() {
+ db.prepareDbUnit(getClass(), "shared.xml");
+
+ SnapshotDto result = sut.selectNullableById(session, 3L);
+ assertThat(result).isNotNull();
+ assertThat(result.getId()).isEqualTo(3L);
+ assertThat(result.getComponentId()).isEqualTo(3L);
+ assertThat(result.getRootProjectId()).isEqualTo(1L);
+ assertThat(result.getParentId()).isEqualTo(2L);
+ assertThat(result.getRootId()).isEqualTo(1L);
+ assertThat(result.getStatus()).isEqualTo("P");
+ assertThat(result.getLast()).isTrue();
+ assertThat(result.getPurgeStatus()).isEqualTo(1);
+ assertThat(result.getDepth()).isEqualTo(1);
+ assertThat(result.getScope()).isEqualTo("DIR");
+ assertThat(result.getQualifier()).isEqualTo("PAC");
+ assertThat(result.getVersion()).isEqualTo("2.1-SNAPSHOT");
+ assertThat(result.getPath()).isEqualTo("1.2.");
+
+ assertThat(result.getPeriodMode(1)).isEqualTo("days1");
+ assertThat(result.getPeriodModeParameter(1)).isEqualTo("30");
+ assertThat(result.getPeriodDate(1)).isEqualTo(1316815200000L);
+ assertThat(result.getPeriodMode(2)).isEqualTo("days2");
+ assertThat(result.getPeriodModeParameter(2)).isEqualTo("31");
+ assertThat(result.getPeriodDate(2)).isEqualTo(1316901600000L);
+ assertThat(result.getPeriodMode(3)).isEqualTo("days3");
+ assertThat(result.getPeriodModeParameter(3)).isEqualTo("32");
+ assertThat(result.getPeriodDate(3)).isEqualTo(1316988000000L);
+ assertThat(result.getPeriodMode(4)).isEqualTo("days4");
+ assertThat(result.getPeriodModeParameter(4)).isEqualTo("33");
+ assertThat(result.getPeriodDate(4)).isEqualTo(1317074400000L);
+ assertThat(result.getPeriodMode(5)).isEqualTo("days5");
+ assertThat(result.getPeriodModeParameter(5)).isEqualTo("34");
+ assertThat(result.getPeriodDate(5)).isEqualTo(1317160800000L);
+
+ assertThat(result.getCreatedAt()).isEqualTo(1228172400000L);
+ assertThat(result.getBuildDate()).isEqualTo(1317247200000L);
+
+ assertThat(sut.selectNullableById(session, 999L)).isNull();
+ }
+
+ @Test
+ public void lastSnapshot_returns_null_when_no_last_snapshot() {
+ SnapshotDto snapshot = sut.selectLastSnapshotByComponentId(session, 123L);
+
+ assertThat(snapshot).isNull();
+ }
+
+ @Test
+ public void lastSnapshot_from_one_resource() {
+ db.prepareDbUnit(getClass(), "snapshots.xml");
+
+ SnapshotDto snapshot = sut.selectLastSnapshotByComponentId(session, 2L);
+
+ assertThat(snapshot).isNotNull();
+ assertThat(snapshot.getId()).isEqualTo(4L);
+ }
+
+ @Test
+ public void lastSnapshot_from_one_resource_without_last_is_null() {
+ db.prepareDbUnit(getClass(), "snapshots.xml");
+
+ SnapshotDto snapshot = sut.selectLastSnapshotByComponentId(session, 5L);
+
+ assertThat(snapshot).isNull();
+ }
+
+ @Test
+ public void snapshot_and_child_retrieved() {
+ db.prepareDbUnit(getClass(), "snapshots.xml");
+
+ List<SnapshotDto> snapshots = sut.selectSnapshotAndChildrenOfProjectScope(session, 1L);
+
+ assertThat(snapshots).isNotEmpty();
+ assertThat(snapshots).extracting("id").containsOnly(1L, 6L);
+ }
+
+ @Test
+ public void select_snapshots_by_component_id() {
+ db.prepareDbUnit(getClass(), "snapshots.xml");
+
+ List<SnapshotDto> snapshots = sut.selectSnapshotsByComponentId(session, 1L);
+
+ assertThat(snapshots).hasSize(3);
+ }
+
+ @Test
+ public void select_snapshots_by_query() {
+ db.prepareDbUnit(getClass(), "select_snapshots_by_query.xml");
+
+ assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery())).hasSize(6);
+
+ assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L))).hasSize(3);
+
+ assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setVersion("2.2-SNAPSHOT"))).extracting("id").containsOnly(3L);
+
+ assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setIsLast(true))).extracting("id").containsOnly(1L);
+ assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setIsLast(false))).extracting("id").containsOnly(2L, 3L);
+
+ assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setCreatedAfter(1228172400002L))).extracting("id").containsOnly(2L, 3L);
+ assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setCreatedBefore(1228172400002L))).extracting("id").containsOnly(1L);
+
+ assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(2L).setStatus("P"))).hasSize(1);
+ assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(2L).setStatus("U"))).hasSize(1);
+
+ assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setSort(BY_DATE, ASC)).get(0).getId()).isEqualTo(1L);
+ assertThat(sut.selectSnapshotsByQuery(session, new SnapshotQuery().setComponentId(1L).setSort(BY_DATE, DESC)).get(0).getId()).isEqualTo(3L);
+ }
+
+ @Test
+ public void select_previous_version_snapshots() throws Exception {
+ db.prepareDbUnit(getClass(), "select_previous_version_snapshots.xml");
+
+ List<SnapshotDto> snapshots = sut.selectPreviousVersionSnapshots(session, 1L, "1.2-SNAPSHOT");
+ assertThat(snapshots).hasSize(2);
+
+ SnapshotDto firstSnapshot = snapshots.get(0);
+ assertThat(firstSnapshot.getVersion()).isEqualTo("1.1");
+
+ // All snapshots are returned on an unknown version
+ assertThat(sut.selectPreviousVersionSnapshots(session, 1L, "UNKNOWN")).hasSize(3);
+ }
+
+ @Test
+ public void insert() {
+ db.prepareDbUnit(getClass(), "empty.xml");
+
+ SnapshotDto dto = defaultSnapshot().setCreatedAt(1403042400000L);
+
+ sut.insert(session, dto);
+ session.commit();
+
+ assertThat(dto.getId()).isNotNull();
+ db.assertDbUnit(getClass(), "insert-result.xml", new String[] {"id"}, "snapshots");
+ }
+
+ @Test
+ public void insert_snapshots() {
+ db.prepareDbUnit(getClass(), "empty.xml");
+
+ sut.insert(session,
+ new SnapshotDto().setComponentId(1L).setLast(false),
+ new SnapshotDto().setComponentId(2L).setLast(false));
+ session.commit();
+
+ assertThat(db.countRowsOfTable("snapshots")).isEqualTo(2);
+ }
+
+ @Test
+ public void set_snapshot_and_children_to_false_and_status_processed() {
+ db.prepareDbUnit(getClass(), "snapshots.xml");
+ SnapshotDto snapshot = defaultSnapshot().setId(1L);
+
+ sut.updateSnapshotAndChildrenLastFlagAndStatus(session, snapshot, false, SnapshotDto.STATUS_PROCESSED);
+ session.commit();
+
+ List<SnapshotDto> snapshots = sut.selectSnapshotAndChildrenOfProjectScope(session, 1L);
+ assertThat(snapshots).hasSize(2);
+ assertThat(snapshots).extracting("id").containsOnly(1L, 6L);
+ assertThat(snapshots).extracting("last").containsOnly(false);
+ assertThat(snapshots).extracting("status").containsOnly(SnapshotDto.STATUS_PROCESSED);
+ }
+
+ @Test
+ public void set_snapshot_and_children_isLast_flag_to_false() {
+ db.prepareDbUnit(getClass(), "snapshots.xml");
+ SnapshotDto snapshot = defaultSnapshot().setId(1L);
+
+ sut.updateSnapshotAndChildrenLastFlag(session, snapshot, false);
+ session.commit();
+
+ List<SnapshotDto> snapshots = sut.selectSnapshotAndChildrenOfProjectScope(session, 1L);
+ assertThat(snapshots).hasSize(2);
+ assertThat(snapshots).extracting("id").containsOnly(1L, 6L);
+ assertThat(snapshots).extracting("last").containsOnly(false);
+ }
+
+ @Test
+ public void is_last_snapshot_when_no_previous_snapshot() {
+ SnapshotDto snapshot = defaultSnapshot();
+
+ boolean isLast = SnapshotDao.isLast(snapshot, null);
+
+ assertThat(isLast).isTrue();
+ }
+
+ @Test
+ public void is_last_snapshot_when_previous_snapshot_is_older() {
+ Date today = new Date();
+ Date yesterday = DateUtils.addDays(today, -1);
+
+ SnapshotDto snapshot = defaultSnapshot().setCreatedAt(today.getTime());
+ SnapshotDto previousLastSnapshot = defaultSnapshot().setCreatedAt(yesterday.getTime());
+
+ boolean isLast = SnapshotDao.isLast(snapshot, previousLastSnapshot);
+
+ assertThat(isLast).isTrue();
+ }
+
+ @Test
+ public void is_not_last_snapshot_when_previous_snapshot_is_newer() {
+ Date today = new Date();
+ Date yesterday = DateUtils.addDays(today, -1);
+
+ SnapshotDto snapshot = defaultSnapshot().setCreatedAt(yesterday.getTime());
+ SnapshotDto previousLastSnapshot = defaultSnapshot().setCreatedAt(today.getTime());
+
+ boolean isLast = SnapshotDao.isLast(snapshot, previousLastSnapshot);
+
+ assertThat(isLast).isFalse();
+ }
+
+ private static SnapshotDto defaultSnapshot() {
+ return new SnapshotDto()
+ .setComponentId(3L)
+ .setRootProjectId(1L)
+ .setParentId(2L)
+ .setRootId(1L)
+ .setStatus("P")
+ .setLast(true)
+ .setPurgeStatus(1)
+ .setDepth(1)
+ .setScope("DIR")
+ .setQualifier("PAC")
+ .setVersion("2.1-SNAPSHOT")
+ .setPath("1.2.")
+ .setPeriodMode(1, "days1")
+ .setPeriodMode(2, "days2")
+ .setPeriodMode(3, "days3")
+ .setPeriodMode(4, "days4")
+ .setPeriodMode(5, "days5")
+ .setPeriodParam(1, "30")
+ .setPeriodParam(2, "31")
+ .setPeriodParam(3, "32")
+ .setPeriodParam(4, "33")
+ .setPeriodParam(5, "34")
+ .setPeriodDate(1, 1_500_000_000_001L)
+ .setPeriodDate(2, 1_500_000_000_002L)
+ .setPeriodDate(3, 1_500_000_000_003L)
+ .setPeriodDate(4, 1_500_000_000_004L)
+ .setPeriodDate(5, 1_500_000_000_005L)
+ .setBuildDate(1_500_000_000_006L);
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.db.compute;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
+import org.sonar.api.utils.System2;
+import org.sonar.db.compute.AnalysisReportDao;
+import org.sonar.db.compute.AnalysisReportDto;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.MyBatis;
+import org.sonar.test.DbTests;
+
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.sonar.db.compute.AnalysisReportDto.Status.PENDING;
+import static org.sonar.db.compute.AnalysisReportDto.Status.WORKING;
+
+@Category(DbTests.class)
+public class AnalysisReportDaoTest {
+
+ private static final String DEFAULT_PROJECT_KEY = "123456789-987654321";
+
+ @ClassRule
+ public static DbTester db = new DbTester();
+
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
+ AnalysisReportDao sut;
+ DbSession session;
+ System2 system2;
+
+ @Before
+ public void before() {
+ this.session = db.myBatis().openSession(false);
+ this.system2 = mock(System2.class);
+ this.sut = new AnalysisReportDao(system2);
+
+ when(system2.now()).thenReturn(1_500_000_000_000L);
+ }
+
+ @After
+ public void after() {
+ MyBatis.closeQuietly(session);
+ }
+
+ @Test
+ public void insert_multiple_reports() {
+ db.prepareDbUnit(getClass(), "empty.xml");
+
+ AnalysisReportDto report1 = new AnalysisReportDto().setProjectKey("ProjectKey1").setProjectName("Project 1").setUuid("UUID_1").setStatus(PENDING);
+ AnalysisReportDto report2 = new AnalysisReportDto().setProjectKey("ProjectKey2").setProjectName("Project 2").setUuid("UUID_2").setStatus(PENDING);
+
+ sut.insert(session, report1);
+ sut.insert(session, report2);
+ session.commit();
+
+ db.assertDbUnit(getClass(), "insert-result.xml", "analysis_reports");
+ }
+
+ @Test
+ public void resetAllToPendingStatus() {
+ db.prepareDbUnit(getClass(), "update-all-to-status-pending.xml");
+
+ sut.resetAllToPendingStatus(session);
+ session.commit();
+
+ db.assertDbUnit(getClass(), "update-all-to-status-pending-result.xml", "analysis_reports");
+ }
+
+ @Test
+ public void truncate() {
+ db.prepareDbUnit(getClass(), "any-analysis-reports.xml");
+
+ sut.truncate(session);
+ session.commit();
+
+ db.assertDbUnit(getClass(), "truncate-result.xml", "analysis_reports");
+ }
+
+ @Test
+ public void find_one_report_by_project_key() {
+ db.prepareDbUnit(getClass(), "select.xml");
+
+ final String projectKey = "123456789-987654321";
+ List<AnalysisReportDto> reports = sut.selectByProjectKey(session, projectKey);
+ AnalysisReportDto report = reports.get(0);
+
+ assertThat(reports).hasSize(1);
+ assertThat(report.getProjectKey()).isEqualTo(projectKey);
+ assertThat(report.getProjectName()).isEqualTo("Project 1");
+ assertThat(report.getStatus()).isEqualTo(AnalysisReportDto.Status.WORKING);
+ assertThat(report.getId()).isEqualTo(1);
+ }
+
+ @Test
+ public void find_several_reports_by_project_key() {
+ db.prepareDbUnit(getClass(), "select.xml");
+
+ final String projectKey = "987654321-123456789";
+ List<AnalysisReportDto> reports = sut.selectByProjectKey(session, projectKey);
+
+ assertThat(reports).hasSize(2);
+ }
+
+ @Test
+ public void pop_oldest_pending() {
+ db.prepareDbUnit(getClass(), "pop_oldest_pending.xml");
+
+ AnalysisReportDto nextAvailableReport = sut.pop(session);
+
+ assertThat(nextAvailableReport.getId()).isEqualTo(3);
+ assertThat(nextAvailableReport.getProjectKey()).isEqualTo("P2");
+ }
+
+ @Test
+ public void pop_null_if_no_pending_reports() {
+ db.prepareDbUnit(getClass(), "pop_null_if_no_pending_reports.xml");
+
+ AnalysisReportDto nextAvailableReport = sut.pop(session);
+
+ assertThat(nextAvailableReport).isNull();
+ }
+
+ @Test
+ public void getById_maps_all_the_fields_except_the_data() {
+ db.prepareDbUnit(getClass(), "one_analysis_report.xml");
+
+ AnalysisReportDto report = sut.selectById(session, 1L);
+
+ assertThat(report.getProjectKey()).isEqualTo(DEFAULT_PROJECT_KEY);
+ assertThat(report.getCreatedAt()).isEqualTo(1_500_000_000_001L);
+ assertThat(report.getUpdatedAt()).isEqualTo(1_500_000_000_002L);
+ assertThat(report.getStartedAt()).isEqualTo(1_500_000_000_003L);
+ assertThat(report.getFinishedAt()).isEqualTo(1_500_000_000_004L);
+ assertThat(report.getStatus()).isEqualTo(WORKING);
+ }
+
+ @Test
+ public void getById_returns_null_when_id_not_found() {
+ db.prepareDbUnit(getClass(), "select.xml");
+
+ AnalysisReportDto report = sut.selectById(session, 4L);
+
+ assertThat(report).isNull();
+ }
+
+ @Test
+ public void delete_one_analysis_report() {
+ db.prepareDbUnit(getClass(), "one_analysis_report.xml");
+
+ sut.delete(session, 1);
+ session.commit();
+
+ db.assertDbUnit(getClass(), "truncate-result.xml", "analysis_reports");
+ }
+
+ @Test
+ public void findAll_one_analysis_report() {
+ db.prepareDbUnit(getClass(), "one_analysis_report.xml");
+
+ List<AnalysisReportDto> reports = sut.selectAll(session);
+
+ assertThat(reports).hasSize(1);
+ }
+
+ @Test
+ public void findAll_empty_table() {
+ db.prepareDbUnit(getClass(), "empty.xml");
+
+ List<AnalysisReportDto> reports = sut.selectAll(session);
+
+ assertThat(reports).isEmpty();
+ }
+
+ @Test
+ public void findAll_three_analysis_reports() {
+ db.prepareDbUnit(getClass(), "three_analysis_reports.xml");
+
+ List<AnalysisReportDto> reports = sut.selectAll(session);
+
+ assertThat(reports).hasSize(3);
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.dashboard;
+
+import java.util.Collection;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.MyBatis;
+import org.sonar.test.DbTests;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@Category(DbTests.class)
+public class WidgetDaoTest {
+
+ WidgetDao dao;
+
+ @Rule
+ public DbTester dbTester = new DbTester();
+
+ private DbSession session;
+
+ @Before
+ public void setUp() {
+ dao = new WidgetDao(dbTester.myBatis());
+ session = dbTester.myBatis().openSession(false);
+ }
+
+ @After
+ public void tearDown() {
+ MyBatis.closeQuietly(session);
+ }
+
+ @Test
+ public void should_select_all() {
+ dbTester.prepareDbUnit(this.getClass(), "before.xml");
+ session.commit();
+
+ Collection<WidgetDto> widgets = dao.findAll(session);
+ assertThat(widgets).hasSize(5);
+ for (WidgetDto widget : widgets) {
+ assertThat(widget.getId()).isNotNull();
+ assertThat(widget.getName()).isNotNull();
+ assertThat(widget.getDescription()).isNotNull();
+ }
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.db.event;
+
+import java.util.List;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.test.DbTests;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@Category(DbTests.class)
+public class EventDaoTest {
+
+ @ClassRule
+ public static DbTester dbTester = new DbTester();
+
+ DbSession session;
+
+ EventDao dao;
+
+ @Before
+ public void setup() {
+ dbTester.truncateTables();
+ session = dbTester.myBatis().openSession(false);
+ dao = new EventDao();
+ }
+
+ @After
+ public void tearDown() {
+ session.close();
+ }
+
+ @Test
+ public void select_by_component_uuid() {
+ dbTester.prepareDbUnit(getClass(), "shared.xml");
+
+ List<EventDto> dtos = dao.selectByComponentUuid(session, "ABCD");
+ assertThat(dtos).hasSize(3);
+
+ dtos = dao.selectByComponentUuid(session, "BCDE");
+ assertThat(dtos).hasSize(1);
+
+ EventDto dto = dtos.get(0);
+ assertThat(dto.getId()).isEqualTo(4L);
+ assertThat(dto.getComponentUuid()).isEqualTo("BCDE");
+ assertThat(dto.getSnapshotId()).isEqualTo(1000L);
+ assertThat(dto.getName()).isEqualTo("1.0");
+ assertThat(dto.getCategory()).isEqualTo("Version");
+ assertThat(dto.getDescription()).isEqualTo("Version 1.0");
+ assertThat(dto.getData()).isEqualTo("some data");
+ assertThat(dto.getDate()).isEqualTo(1413407091086L);
+ assertThat(dto.getCreatedAt()).isEqualTo(1225630680000L);
+ }
+
+ @Test
+ public void return_different_categories() {
+ dbTester.prepareDbUnit(getClass(), "shared.xml");
+
+ List<EventDto> dtos = dao.selectByComponentUuid(session, "ABCD");
+ assertThat(dtos).extracting("category").containsOnly(EventDto.CATEGORY_ALERT, EventDto.CATEGORY_PROFILE, EventDto.CATEGORY_VERSION);
+ }
+
+ @Test
+ public void insert() {
+ dbTester.prepareDbUnit(getClass(), "empty.xml");
+
+ dao.insert(session, new EventDto()
+ .setName("1.0")
+ .setCategory(EventDto.CATEGORY_VERSION)
+ .setDescription("Version 1.0")
+ .setData("some data")
+ .setDate(1413407091086L)
+ .setComponentUuid("ABCD")
+ .setSnapshotId(1000L)
+ .setCreatedAt(1225630680000L)
+ );
+ session.commit();
+
+ dbTester.assertDbUnit(getClass(), "insert-result.xml", new String[] {"id"}, "events");
+ }
+
+ @Test
+ public void delete() {
+ dbTester.prepareDbUnit(getClass(), "delete.xml");
+
+ dao.delete(session, 1L);
+ session.commit();
+
+ assertThat(dbTester.countRowsOfTable("events")).isEqualTo(0);
+ }
+
+}
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();
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;
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");
+ }
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.db.measure;
+
+import com.google.common.base.Function;
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.ImmutableSet;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.sonar.db.measure.MeasureDao;
+import org.sonar.db.measure.MeasureDto;
+import org.sonar.db.measure.PastMeasureDto;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.test.DbTests;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.assertj.core.api.Assertions.assertThat;
+
+@Category(DbTests.class)
+public class MeasureDaoTest {
+
+ @ClassRule
+ public static DbTester db = new DbTester();
+
+ DbSession session;
+ MeasureDao sut;
+
+ @Before
+ public void setUp() {
+ db.truncateTables();
+ session = db.myBatis().openSession(false);
+ sut = new MeasureDao();
+ }
+
+ @After
+ public void tearDown() {
+ session.close();
+ }
+
+ @Test
+ public void get_value_by_key() {
+ db.prepareDbUnit(getClass(), "shared.xml");
+
+ MeasureDto result = sut.findByComponentKeyAndMetricKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "ncloc");
+ assertThat(result.getId()).isEqualTo(22);
+ assertThat(result.getValue()).isEqualTo(10d);
+ assertThat(result.getData()).isNull();
+ assertThat(result.getVariation(1)).isEqualTo(1d);
+ assertThat(result.getVariation(2)).isEqualTo(2d);
+ assertThat(result.getVariation(3)).isEqualTo(3d);
+ assertThat(result.getVariation(4)).isEqualTo(4d);
+ assertThat(result.getVariation(5)).isEqualTo(-5d);
+ assertThat(result.getAlertStatus()).isEqualTo("OK");
+ assertThat(result.getAlertText()).isEqualTo("Green");
+ }
+
+ @Test
+ // TODO the string must be longer than 4000 char to be persisted in the data field
+ public void get_data_by_key() {
+ db.prepareDbUnit(getClass(), "shared.xml");
+
+ MeasureDto result = sut.findByComponentKeyAndMetricKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "authors_by_line");
+ assertThat(result.getId()).isEqualTo(20);
+ assertThat(result.getData()).isEqualTo("0123456789012345678901234567890123456789");
+ }
+
+ @Test
+ public void get_text_value_by_key() {
+ db.prepareDbUnit(getClass(), "shared.xml");
+
+ MeasureDto result = sut.findByComponentKeyAndMetricKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "coverage_line_hits_data");
+ assertThat(result.getId()).isEqualTo(21);
+ assertThat(result.getData()).isEqualTo("36=1;37=1;38=1;39=1;43=1;48=1;53=1");
+ }
+
+ @Test
+ public void find_by_component_key_and_metrics() {
+ db.prepareDbUnit(getClass(), "shared.xml");
+
+ List<MeasureDto> results = sut.findByComponentKeyAndMetricKeys(session, "org.struts:struts-core:src/org/struts/RequestContext.java",
+ newArrayList("ncloc", "authors_by_line"));
+ assertThat(results).hasSize(2);
+
+ results = sut.findByComponentKeyAndMetricKeys(session, "org.struts:struts-core:src/org/struts/RequestContext.java", newArrayList("ncloc"));
+ assertThat(results).hasSize(1);
+
+ MeasureDto result = results.get(0);
+ assertThat(result.getId()).isEqualTo(22);
+ assertThat(result.getValue()).isEqualTo(10d);
+ assertThat(result.getComponentKey()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java");
+ assertThat(result.getMetricKey()).isEqualTo("ncloc");
+ assertThat(result.getVariation(1)).isEqualTo(1d);
+ assertThat(result.getVariation(2)).isEqualTo(2d);
+ assertThat(result.getVariation(3)).isEqualTo(3d);
+ assertThat(result.getVariation(4)).isEqualTo(4d);
+ assertThat(result.getVariation(5)).isEqualTo(-5d);
+ }
+
+ @Test
+ public void find_by_component_key_and_metric() {
+ db.prepareDbUnit(getClass(), "shared.xml");
+
+ MeasureDto result = sut.findByComponentKeyAndMetricKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "ncloc");
+ assertThat(result.getId()).isEqualTo(22);
+ assertThat(result.getValue()).isEqualTo(10d);
+ assertThat(result.getMetricKey()).isEqualTo("ncloc");
+ assertThat(result.getComponentKey()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java");
+ assertThat(result.getVariation(1)).isEqualTo(1d);
+ assertThat(result.getVariation(2)).isEqualTo(2d);
+ assertThat(result.getVariation(3)).isEqualTo(3d);
+ assertThat(result.getVariation(4)).isEqualTo(4d);
+ assertThat(result.getVariation(5)).isEqualTo(-5d);
+
+ assertThat(sut.findByComponentKeyAndMetricKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "unknown")).isNull();
+ }
+
+ @Test
+ public void exists_by_key() {
+ db.prepareDbUnit(getClass(), "shared.xml");
+
+ assertThat(sut.existsByKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "ncloc")).isTrue();
+ assertThat(sut.existsByKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java", "unknown")).isFalse();
+ }
+
+ @Test
+ public void select_past_measures_by_component_uuid_and_root_snapshot_id_and_metric_keys() {
+ db.prepareDbUnit(getClass(), "past_measures.xml");
+
+ List<PastMeasureDto> fileMeasures = sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "CDEF", 1000L, ImmutableSet.of(1, 2));
+ assertThat(fileMeasures).hasSize(2);
+
+ PastMeasureDto fileMeasure1 = fileMeasures.get(0);
+ assertThat(fileMeasure1.getValue()).isEqualTo(5d);
+ assertThat(fileMeasure1.getMetricId()).isEqualTo(1);
+ assertThat(fileMeasure1.getRuleId()).isNull();
+ assertThat(fileMeasure1.getCharacteristicId()).isNull();
+ assertThat(fileMeasure1.getPersonId()).isNull();
+
+ PastMeasureDto fileMeasure2 = fileMeasures.get(1);
+ assertThat(fileMeasure2.getValue()).isEqualTo(60d);
+ assertThat(fileMeasure2.getMetricId()).isEqualTo(2);
+
+ List<PastMeasureDto> projectMeasures = sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "ABCD", 1000L, ImmutableSet.of(1, 2));
+ assertThat(projectMeasures).hasSize(2);
+
+ PastMeasureDto projectMeasure1 = projectMeasures.get(0);
+ assertThat(projectMeasure1.getValue()).isEqualTo(60d);
+ assertThat(projectMeasure1.getMetricId()).isEqualTo(1);
+
+ PastMeasureDto projectMeasure2 = projectMeasures.get(1);
+ assertThat(projectMeasure2.getValue()).isEqualTo(80d);
+ assertThat(projectMeasure2.getMetricId()).isEqualTo(2);
+
+ assertThat(sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "UNKNOWN", 1000L, ImmutableSet.of(1, 2))).isEmpty();
+ assertThat(sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "CDEF", 987654L, ImmutableSet.of(1, 2))).isEmpty();
+ assertThat(sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "CDEF", 1000L, ImmutableSet.of(123, 456))).isEmpty();
+ }
+
+ @Test
+ public void select_past_measures_on_rule_by_component_uuid_and_root_snapshot_id_and_metric_keys() {
+ db.prepareDbUnit(getClass(), "past_measures_with_rule_id.xml");
+
+ List<PastMeasureDto> measures = sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "ABCD", 1000L, ImmutableSet.of(1));
+ assertThat(measures).hasSize(3);
+
+ Map<Long, PastMeasureDto> pastMeasuresById = pastMeasuresById(measures);
+
+ PastMeasureDto measure1 = pastMeasuresById.get(1L);
+ assertThat(measure1.getValue()).isEqualTo(60d);
+ assertThat(measure1.getMetricId()).isEqualTo(1);
+ assertThat(measure1.getRuleId()).isNull();
+ assertThat(measure1.getCharacteristicId()).isNull();
+ assertThat(measure1.getPersonId()).isNull();
+
+ PastMeasureDto measure2 = pastMeasuresById.get(2L);
+ assertThat(measure2.getValue()).isEqualTo(20d);
+ assertThat(measure2.getMetricId()).isEqualTo(1);
+ assertThat(measure2.getRuleId()).isEqualTo(30);
+ assertThat(measure2.getCharacteristicId()).isNull();
+ assertThat(measure2.getPersonId()).isNull();
+
+ PastMeasureDto measure3 = pastMeasuresById.get(3L);
+ assertThat(measure3.getValue()).isEqualTo(40d);
+ assertThat(measure3.getMetricId()).isEqualTo(1);
+ assertThat(measure3.getRuleId()).isEqualTo(31);
+ assertThat(measure3.getCharacteristicId()).isNull();
+ assertThat(measure3.getPersonId()).isNull();
+ }
+
+ @Test
+ public void select_past_measures_on_characteristic_by_component_uuid_and_root_snapshot_id_and_metric_keys() {
+ db.prepareDbUnit(getClass(), "past_measures_with_characteristic_id.xml");
+
+ List<PastMeasureDto> measures = sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "ABCD", 1000L, ImmutableSet.of(1));
+ assertThat(measures).hasSize(3);
+
+ Map<Long, PastMeasureDto> pastMeasuresById = pastMeasuresById(measures);
+
+ PastMeasureDto measure1 = pastMeasuresById.get(1L);
+ assertThat(measure1.getValue()).isEqualTo(60d);
+ assertThat(measure1.getMetricId()).isEqualTo(1);
+ assertThat(measure1.getRuleId()).isNull();
+ assertThat(measure1.getCharacteristicId()).isNull();
+ assertThat(measure1.getPersonId()).isNull();
+
+ PastMeasureDto measure2 = pastMeasuresById.get(2L);
+ assertThat(measure2.getValue()).isEqualTo(20d);
+ assertThat(measure2.getMetricId()).isEqualTo(1);
+ assertThat(measure2.getRuleId()).isNull();
+ assertThat(measure2.getCharacteristicId()).isEqualTo(10);
+ assertThat(measure2.getPersonId()).isNull();
+
+ PastMeasureDto measure3 = pastMeasuresById.get(3L);
+ assertThat(measure3.getValue()).isEqualTo(40d);
+ assertThat(measure3.getMetricId()).isEqualTo(1);
+ assertThat(measure3.getRuleId()).isNull();
+ assertThat(measure3.getCharacteristicId()).isEqualTo(11);
+ assertThat(measure3.getPersonId()).isNull();
+ }
+
+ @Test
+ public void select_past_measures_on_person_by_component_uuid_and_root_snapshot_id_and_metric_keys() {
+ db.prepareDbUnit(getClass(), "past_measures_with_person_id.xml");
+
+ List<PastMeasureDto> measures = sut.selectByComponentUuidAndProjectSnapshotIdAndMetricIds(session, "ABCD", 1000L, ImmutableSet.of(1));
+ assertThat(measures).hasSize(3);
+
+ Map<Long, PastMeasureDto> pastMeasuresById = pastMeasuresById(measures);
+
+ PastMeasureDto measure1 = pastMeasuresById.get(1L);
+ assertThat(measure1.getValue()).isEqualTo(60d);
+ assertThat(measure1.getMetricId()).isEqualTo(1);
+ assertThat(measure1.getRuleId()).isNull();
+ assertThat(measure1.getCharacteristicId()).isNull();
+ assertThat(measure1.getPersonId()).isNull();
+
+ PastMeasureDto measure2 = pastMeasuresById.get(2L);
+ assertThat(measure2.getValue()).isEqualTo(20d);
+ assertThat(measure2.getMetricId()).isEqualTo(1);
+ assertThat(measure2.getRuleId()).isNull();
+ assertThat(measure2.getCharacteristicId()).isNull();
+ assertThat(measure2.getPersonId()).isEqualTo(20);
+
+ PastMeasureDto measure3 = pastMeasuresById.get(3L);
+ assertThat(measure3.getValue()).isEqualTo(40d);
+ assertThat(measure3.getMetricId()).isEqualTo(1);
+ assertThat(measure3.getRuleId()).isNull();
+ assertThat(measure3.getCharacteristicId()).isNull();
+ assertThat(measure3.getPersonId()).isEqualTo(21);
+ }
+
+ @Test
+ public void insert() {
+ db.prepareDbUnit(getClass(), "empty.xml");
+
+ sut.insert(session, new MeasureDto()
+ .setSnapshotId(2L)
+ .setMetricId(3)
+ .setCharacteristicId(4)
+ .setPersonId(23)
+ .setRuleId(5)
+ .setComponentId(6L)
+ .setValue(2.0d)
+ .setData("measure-value")
+ .setVariation(1, 1.0d)
+ .setVariation(2, 2.0d)
+ .setVariation(3, 3.0d)
+ .setVariation(4, 4.0d)
+ .setVariation(5, 5.0d)
+ .setAlertStatus("alert")
+ .setAlertText("alert-text")
+ .setDescription("measure-description")
+ );
+ session.commit();
+
+ db.assertDbUnit(getClass(), "insert-result.xml", new String[] {"id"}, "project_measures");
+ }
+
+ @Test
+ public void insert_measures() {
+ db.prepareDbUnit(getClass(), "empty.xml");
+
+ sut.insert(session, new MeasureDto()
+ .setSnapshotId(2L)
+ .setMetricId(3)
+ .setComponentId(6L)
+ .setValue(2.0d),
+ new MeasureDto()
+ .setSnapshotId(3L)
+ .setMetricId(4)
+ .setComponentId(6L)
+ .setValue(4.0d)
+ );
+ session.commit();
+
+ assertThat(db.countRowsOfTable("project_measures")).isEqualTo(2);
+ }
+
+ private static Map<Long, PastMeasureDto> pastMeasuresById(List<PastMeasureDto> pastMeasures) {
+ return FluentIterable.from(pastMeasures).uniqueIndex(new Function<PastMeasureDto, Long>() {
+ @Nullable
+ @Override
+ public Long apply(PastMeasureDto input) {
+ return input.getId();
+ }
+ });
+ }
+}
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
@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");
}
@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");
}
@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");
}
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;
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() {
+++ /dev/null
-/*
- * 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);
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.rule;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableSet;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rule.RuleStatus;
+import org.sonar.api.rule.Severity;
+import org.sonar.db.rule.RuleDto.Format;
+
+/**
+ * Utility class for tests involving rules
+ */
+public class RuleTesting {
+
+ public static final RuleKey XOO_X1 = RuleKey.of("xoo", "x1");
+ public static final RuleKey XOO_X2 = RuleKey.of("xoo", "x2");
+ public static final RuleKey XOO_X3 = RuleKey.of("xoo", "x3");
+
+ private RuleTesting() {
+ // only static helpers
+ }
+
+ public static RuleDto newXooX1() {
+ return newDto(XOO_X1).setLanguage("xoo");
+ }
+
+ public static RuleDto newXooX2() {
+ return newDto(XOO_X2).setLanguage("xoo");
+ }
+
+ public static RuleDto newXooX3() {
+ return newDto(XOO_X3).setLanguage("xoo");
+ }
+
+ /**
+ * Full RuleDto used to feed database with fake data. Tests must not rely on the
+ * field contents declared here. They should override the fields they need to test,
+ * for example:
+ * <pre>
+ * ruleDao.insert(dbSession, RuleTesting.newDto(key).setStatus(RuleStatus.BETA));
+ * </pre>
+ */
+ public static RuleDto newDto(RuleKey ruleKey) {
+ return new RuleDto()
+ .setRuleKey(ruleKey.rule())
+ .setRepositoryKey(ruleKey.repository())
+ .setName("Rule " + ruleKey.rule())
+ .setDescription("Description " + ruleKey.rule())
+ .setDescriptionFormat(Format.HTML)
+ .setStatus(RuleStatus.READY)
+ .setConfigKey("InternalKey" + ruleKey.rule())
+ .setSeverity(Severity.INFO)
+ .setIsTemplate(false)
+ .setTags(ImmutableSet.of("tag1", "tag2"))
+ .setSystemTags(ImmutableSet.of("systag1", "systag2"))
+ .setLanguage("js")
+ .setRemediationFunction("LINEAR")
+ .setDefaultRemediationFunction("LINEAR_OFFSET")
+ .setRemediationCoefficient("1h")
+ .setDefaultRemediationCoefficient("5d")
+ .setRemediationOffset("5min")
+ .setDefaultRemediationOffset("10h")
+ .setEffortToFixDescription(ruleKey.repository() + "." + ruleKey.rule() + ".effortToFix");
+ }
+
+ public static RuleDto newTemplateRule(RuleKey ruleKey) {
+ return newDto(ruleKey)
+ .setIsTemplate(true);
+ }
+
+ public static RuleDto newCustomRule(RuleDto templateRule) {
+ Preconditions.checkNotNull(templateRule.getId(), "The template rule need to be persisted before creating this custom rule.");
+ return newDto(RuleKey.of(templateRule.getRepositoryKey(), templateRule.getRuleKey() + "_" + System.currentTimeMillis()))
+ .setLanguage(templateRule.getLanguage())
+ .setTemplateId(templateRule.getId());
+ }
+
+ public static RuleDto newManualRule(String manualKey) {
+ return new RuleDto().setRuleKey(manualKey)
+ .setName("Name " + manualKey)
+ .setRepositoryKey(RuleKey.MANUAL_REPOSITORY_KEY)
+ .setDescription("Description " + manualKey)
+ .setStatus(RuleStatus.READY);
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.db.source;
+
+import com.google.common.base.Function;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import org.apache.commons.io.IOUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.db.AbstractDaoTestCase;
+import org.sonar.db.DbSession;
+import org.sonar.db.source.FileSourceDto.Type;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class FileSourceDaoTest extends AbstractDaoTestCase {
+
+ DbSession session;
+
+ FileSourceDao sut;
+
+ @Before
+ public void setUpTestData() {
+ session = getMyBatis().openSession(false);
+ sut = new FileSourceDao(getMyBatis());
+ }
+
+ @After
+ public void tearDown() {
+ session.close();
+ }
+
+ @Test
+ public void select() {
+ setupData("shared");
+
+ FileSourceDto fileSourceDto = sut.selectSource("FILE1_UUID");
+
+ assertThat(fileSourceDto.getBinaryData()).isNotEmpty();
+ assertThat(fileSourceDto.getDataHash()).isEqualTo("hash");
+ assertThat(fileSourceDto.getProjectUuid()).isEqualTo("PRJ_UUID");
+ assertThat(fileSourceDto.getFileUuid()).isEqualTo("FILE1_UUID");
+ assertThat(fileSourceDto.getCreatedAt()).isEqualTo(1500000000000L);
+ assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(1500000000000L);
+ assertThat(fileSourceDto.getDataType()).isEqualTo(Type.SOURCE);
+ }
+
+ @Test
+ public void select_line_hashes() {
+ setupData("shared");
+
+ ReaderToStringFunction fn = new ReaderToStringFunction();
+ sut.readLineHashesStream(session, "FILE1_UUID", fn);
+
+ assertThat(fn.result).isEqualTo("ABC\\nDEF\\nGHI");
+ }
+
+ @Test
+ public void no_line_hashes_on_unknown_file() {
+ setupData("shared");
+
+ ReaderToStringFunction fn = new ReaderToStringFunction();
+ sut.readLineHashesStream(session, "unknown", fn);
+
+ assertThat(fn.result).isNull();
+ }
+
+ @Test
+ public void no_line_hashes_when_only_test_data() {
+ setupData("no_line_hashes_when_only_test_data");
+
+ ReaderToStringFunction fn = new ReaderToStringFunction();
+ sut.readLineHashesStream(session, "FILE1_UUID", fn);
+
+ assertThat(fn.result).isNull();
+ }
+
+ @Test
+ public void insert() {
+ setupData("shared");
+
+ sut.insert(new FileSourceDto()
+ .setProjectUuid("PRJ_UUID")
+ .setFileUuid("FILE2_UUID")
+ .setBinaryData("FILE2_BINARY_DATA".getBytes())
+ .setDataHash("FILE2_DATA_HASH")
+ .setLineHashes("LINE1_HASH\\nLINE2_HASH")
+ .setSrcHash("FILE2_HASH")
+ .setDataType(Type.SOURCE)
+ .setCreatedAt(1500000000000L)
+ .setUpdatedAt(1500000000001L));
+
+ checkTable("insert", "file_sources", "project_uuid", "file_uuid", "data_hash", "line_hashes", "src_hash", "created_at", "updated_at", "data_type");
+ }
+
+ @Test
+ public void update() {
+ setupData("shared");
+
+ sut.update(new FileSourceDto()
+ .setId(101L)
+ .setProjectUuid("PRJ_UUID")
+ .setFileUuid("FILE1_UUID")
+ .setBinaryData("updated data".getBytes())
+ .setDataHash("NEW_DATA_HASH")
+ .setSrcHash("NEW_FILE_HASH")
+ .setLineHashes("NEW_LINE_HASHES")
+ .setDataType(Type.SOURCE)
+ .setUpdatedAt(1500000000002L));
+
+ checkTable("update", "file_sources", "project_uuid", "file_uuid", "data_hash", "line_hashes", "src_hash", "created_at", "updated_at", "data_type");
+ }
+
+ @Test
+ public void update_date_when_updated_date_is_zero() {
+ setupData("update_date_when_updated_date_is_zero");
+
+ sut.updateDateWhenUpdatedDateIsZero(session, "ABCD", 1500000000002L);
+ session.commit();
+
+ checkTable("update_date_when_updated_date_is_zero", "file_sources", "project_uuid", "file_uuid", "data_hash", "line_hashes", "src_hash", "created_at", "updated_at",
+ "data_type");
+ }
+
+ private static class ReaderToStringFunction implements Function<Reader, String> {
+
+ String result = null;
+
+ @Override
+ public String apply(Reader input) {
+ try {
+ result = IOUtils.toString(input);
+ return IOUtils.toString(input);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ private static class InputStreamToStringFunction implements Function<InputStream, String> {
+
+ String result = null;
+
+ @Override
+ public String apply(InputStream input) {
+ try {
+ result = IOUtils.toString(input);
+ return IOUtils.toString(input);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.db.user;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.test.DbTests;
+
+@Category(DbTests.class)
+public class UserGroupDaoTest {
+
+ @ClassRule
+ public static DbTester db = new DbTester();
+
+ private UserGroupDao dao;
+ private DbSession session;
+
+ @Before
+ public void before() {
+ db.truncateTables();
+ this.session = db.myBatis().openSession(false);
+ this.dao = new UserGroupDao();
+ }
+
+ @After
+ public void after() {
+ this.session.close();
+ }
+
+ @Test
+ public void insert() {
+ UserGroupDto userGroupDto = new UserGroupDto().setUserId(1L).setGroupId(2L);
+ dao.insert(session, userGroupDto);
+ session.commit();
+
+ db.assertDbUnit(getClass(), "insert-result.xml", "groups_users");
+ }
+
+ @Test
+ public void delete_members_by_group_id() {
+ db.prepareDbUnit(getClass(), "delete_members_by_group_id.xml");
+ dao.deleteMembersByGroupId(session, 1L);
+ session.commit();
+ db.assertDbUnit(getClass(), "delete_members_by_group_id-result.xml", "groups_users");
+ }
+}
+++ /dev/null
-/*
- * 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;
- }
-}
+++ /dev/null
-<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
--- /dev/null
+<dataset>
+ <issues id="10" kee="AB" />
+ <issues id="20" kee="CD" />
+ <issues id="30" kee="EF" />
+</dataset>
--- /dev/null
+CREATE TABLE "ISSUES" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "KEE" VARCHAR(200) NOT NULL
+);
--- /dev/null
+<dataset>
+
+ <project_links id="1" component_uuid="ABCD" link_type="homepage" name="Home" href="http://www.sonarqube.org"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <project_links id="1" component_uuid="ABCD" link_type="homepage" name="Home" href="http://www.sonarqube.org"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <project_links id="1" component_uuid="ABCD" link_type="homepage" name="Home" href="http://www.sonarqube.org"/>
+ <project_links id="2" component_uuid="ABCD" link_type="scm" name="Sources" href="https://github.com/SonarSource/sonar"/>
+ <project_links id="3" component_uuid="BCDE" link_type="homepage" name="Home" href="http://www.struts.org"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <project_links id="1" component_uuid="ABCD" link_type="homepage" name="Home" href="http://www.sonarqube.org"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <project_links id="1" component_uuid="BCDE" link_type="ci" name="CI" href="github"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <!-- Real projects -->
+ <projects id="1" uuid="ABCD" project_uuid="ABCD" module_uuid_path=".ABCD." copy_resource_id="[null]" name="Project One" qualifier="TRK" scope="PRJ"/>
+ <projects id="2" uuid="BCDE" project_uuid="BCDE" module_uuid_path=".BCDE." copy_resource_id="[null]" name="Project Two" qualifier="TRK" scope="PRJ"/>
+
+ <!-- Copy projects -->
+ <projects id="3" uuid="CDEF" project_uuid="EFGH" module_uuid_path=".EFGH." copy_resource_id="1" name="Copy Project One" qualifier="TRK" scope="FIL"/>
+ <projects id="4" uuid="DEFG" project_uuid="EFGH" module_uuid_path=".EFGH." copy_resource_id="2" name="Copy Project One" qualifier="TRK" scope="FIL"/>
+
+ <!-- View containing all projects -->
+ <projects id="5" uuid="EFGH" project_uuid="EFGH" module_uuid_path=".EFGH." copy_resource_id="[null]" name="All projects" qualifier="VW" scope="PRJ"/>
+
+ <resource_index id="1" kee="project one" resource_id="1" root_project_id="1" position="0" name_size="11" qualifier="TRK"/>
+ <resource_index id="2" kee="roject one" resource_id="1" root_project_id="1" position="1" name_size="11" qualifier="TRK"/>
+ <resource_index id="3" kee="oject one" resource_id="1" root_project_id="1" position="2" name_size="11" qualifier="TRK"/>
+ <resource_index id="4" kee="ject one" resource_id="1" root_project_id="1" position="3" name_size="11" qualifier="TRK"/>
+ <resource_index id="5" kee="ect one" resource_id="1" root_project_id="1" position="4" name_size="11" qualifier="TRK"/>
+ <resource_index id="6" kee="ct one" resource_id="1" root_project_id="1" position="5" name_size="11" qualifier="TRK"/>
+ <resource_index id="7" kee="t one" resource_id="1" root_project_id="1" position="6" name_size="11" qualifier="TRK"/>
+ <resource_index id="8" kee=" one" resource_id="1" root_project_id="1" position="7" name_size="11" qualifier="TRK"/>
+ <resource_index id="9" kee="one" resource_id="1" root_project_id="1" position="8" name_size="11" qualifier="TRK"/>
+ <resource_index id="10" kee="project two" resource_id="2" root_project_id="2" position="0" name_size="11" qualifier="TRK"/>
+ <resource_index id="11" kee="roject two" resource_id="2" root_project_id="2" position="1" name_size="11" qualifier="TRK"/>
+ <resource_index id="12" kee="oject two" resource_id="2" root_project_id="2" position="2" name_size="11" qualifier="TRK"/>
+ <resource_index id="13" kee="ject two" resource_id="2" root_project_id="2" position="3" name_size="11" qualifier="TRK"/>
+ <resource_index id="14" kee="ect two" resource_id="2" root_project_id="2" position="4" name_size="11" qualifier="TRK"/>
+ <resource_index id="15" kee="ct two" resource_id="2" root_project_id="2" position="5" name_size="11" qualifier="TRK"/>
+ <resource_index id="16" kee="t two" resource_id="2" root_project_id="2" position="6" name_size="11" qualifier="TRK"/>
+ <resource_index id="17" kee="two" resource_id="2" root_project_id="2" position="7" name_size="11" qualifier="TRK"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <snapshots id="1" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
+ status="P" islast="[true]" purge_status="1"
+ period1_mode="days1" period1_param="30" period1_date="1500000000001"
+ period2_mode="days2" period2_param="31" period2_date="1500000000002"
+ period3_mode="days3" period3_param="32" period3_date="1500000000003"
+ period4_mode="days4" period4_param="33" period4_date="1500000000004"
+ period5_mode="days5" period5_param="34" period5_date="1500000000005"
+ depth="1" scope="DIR" qualifier="PAC" created_at="1403042400000" build_date="1500000000006"
+ version="2.1-SNAPSHOT" path="1.2."/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <!-- root project -->
+ <projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
+ uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
+ description="the description" long_name="Apache Struts"
+ enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" path="[null]" authorization_updated_at="[null]" />
+ <snapshots id="1" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ status="P" islast="[true]" purge_status="[null]"
+ period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+ period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+ period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+ period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+ depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000"
+ version="[null]" path=""/>
+ <snapshots id="10" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ status="P" islast="[false]" purge_status="[null]"
+ period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+ period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+ period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+ period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+ depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228136280000" build_date="1228136280000"
+ version="[null]" path=""/>
+
+ <!-- module -->
+ <projects id="2" root_id="1" kee="org.struts:struts-core" name="Struts Core"
+ uuid="EFGH" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD."
+ scope="PRJ" qualifier="BRC" long_name="Struts Core"
+ description="[null]" enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" authorization_updated_at="[null]" />
+ <snapshots id="2" project_id="2" parent_snapshot_id="1" root_project_id="1" root_snapshot_id="1"
+ status="P" islast="[true]" purge_status="[null]"
+ period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+ period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+ period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+ period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+ depth="[null]" scope="PRJ" qualifier="BRC" created_at="1228222680000" build_date="1228222680000"
+ version="[null]" path="1."/>
+
+ <!-- sub module -->
+ <projects id="3" root_id="1" kee="org.struts:struts-data" name="Struts Data"
+ uuid="FGHI" project_uuid="ABCD" module_uuid="EFGH" module_uuid_path=".ABCD.EFGH."
+ scope="PRJ" qualifier="BRC" long_name="Struts Data"
+ description="[null]" enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" authorization_updated_at="[null]" />
+ <snapshots id="3" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
+ status="P" islast="[true]" purge_status="[null]"
+ period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+ period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+ period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+ period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+ depth="[null]" scope="PRJ" qualifier="BRC" created_at="1228222680000" build_date="1228222680000"
+ version="[null]" path="1.2."/>
+
+ <!-- directory -->
+ <projects long_name="org.struts" id="4" scope="DIR" qualifier="DIR" kee="org.struts:struts-core:src/org/struts"
+ uuid="GHIJ" project_uuid="ABCD" module_uuid="FGHI" module_uuid_path=".ABCD.EFGH.FGHI."
+ name="src/org/struts" root_id="3"
+ description="[null]"
+ enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" path="src/org/struts" authorization_updated_at="[null]" />
+ <snapshots id="4" project_id="4" parent_snapshot_id="3" root_project_id="1" root_snapshot_id="1"
+ status="P" islast="[true]" purge_status="[null]"
+ period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+ period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+ period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+ period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+ depth="[null]" scope="DIR" qualifier="PAC" created_at="1228222680000" build_date="1228222680000"
+ version="[null]" path="1.2.3."/>
+
+ <!-- file -->
+ <projects long_name="org.struts.RequestContext" id="5" scope="FIL" qualifier="FIL" kee="org.struts:struts-core:src/org/struts/RequestContext.java"
+ uuid="HIJK" project_uuid="ABCD" module_uuid="FGHI" module_uuid_path=".ABCD.EFGH.FGHI."
+ name="RequestContext.java" root_id="3"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" path="src/org/struts/RequestContext.java" authorization_updated_at="[null]" />
+
+ <snapshots id="5" project_id="5" parent_snapshot_id="4" root_project_id="1" root_snapshot_id="1"
+ status="P" islast="[true]" purge_status="[null]"
+ period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+ period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+ period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+ period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+ depth="[null]" scope="FIL" qualifier="CLA" created_at="1228222680000" build_date="1228222680000"
+ version="[null]" path="1.2.3.4."/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
+ root_id="[null]" uuid="ABCD"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+ <!-- version 1.0 -->
+ <snapshots id="1000" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
+ period5_param="[null]" period5_date="[null]"
+ project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="1225630680000" build_date="1225630680000" version="1.0" path=""
+ status="P" islast="[false]" depth="0"/>
+
+ <!-- version 1.1 -->
+ <snapshots id="1001" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
+ period5_param="[null]" period5_date="[null]"
+ project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="1225803480000" build_date="1225803480000" version="1.1" path=""
+ status="P" islast="[false]" depth="0"/>
+
+ <!-- version 1.2-SNAPSHOT -->
+ <snapshots id="1002" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
+ period5_param="[null]" period5_date="[null]"
+ project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="1225976280000" build_date="1225976280000" version="1.2-SNAPSHOT" path=""
+ status="P" islast="[false]" depth="0"/>
+
+ <!-- version 1.2-SNAPSHOT, current analysis -->
+ <snapshots id="1003" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
+ period5_param="[null]" period5_date="[null]"
+ project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="1226235480000" build_date="1226235480000" version="1.2-SNAPSHOT" path=""
+ status="U" islast="[true]" depth="0"/>
+
+ <events id="1" name="1.0" component_uuid="ABCD" snapshot_id="1000" category="Version" event_date="1225630680000" created_at="1225630680000" description="" event_data="[null]"/>
+ <events id="2" name="Foo" component_uuid="ABCD" snapshot_id="1000" category="Other" event_date="1225717080000" created_at="1225717080000" description="" event_data="[null]"/>
+ <events id="3" name="1.1" component_uuid="ABCD" snapshot_id="1001" category="Version" event_date="1225803480000" created_at="1225803480000" description="" event_data="[null]"/>
+ <events id="4" name="Bar" component_uuid="ABCD" snapshot_id="1001" category="Other" event_date="1225889880000" created_at="1225889880000" description="" event_data="[null]"/>
+ <events id="5" name="Uhh" component_uuid="ABCD" snapshot_id="1002" category="Other" event_date="1226062680000" created_at="1226062680000" description="" event_data="[null]"/>
+ <events id="6" name="1.2-SNAPSHOT" component_uuid="ABCD" snapshot_id="1003" category="Version" event_date="1226235480000" created_at="1226235480000" description=""
+ event_data="[null]"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <!-- PROJECT_ID = 1 -->
+ <snapshots id="1" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
+ status="P" islast="[true]" purge_status="1"
+ period1_mode="days1" period1_param="30" period1_date="1316815200000"
+ period2_mode="days2" period2_param="31" period2_date="1316901600000"
+ period3_mode="days3" period3_param="32" period3_date="1316988000000"
+ period4_mode="days4" period4_param="33" period4_date="1317074400000"
+ period5_mode="days5" period5_param="34" period5_date="1317160800000"
+ depth="1" scope="PRJ" qualifier="PAC" created_at="1228172400001" build_date="1317247200000"
+ version="2.0-SNAPSHOT" path="1.2."/>
+ <snapshots id="2" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
+ status="P" islast="[false]" purge_status="1"
+ period1_mode="days1" period1_param="30" period1_date="1316815200000"
+ period2_mode="days2" period2_param="31" period2_date="1316901600000"
+ period3_mode="days3" period3_param="32" period3_date="1316988000000"
+ period4_mode="days4" period4_param="33" period4_date="1317074400000"
+ period5_mode="days5" period5_param="34" period5_date="1317160800000"
+ depth="1" scope="DIR" qualifier="PAC" created_at="1228172400002" build_date="1317247200000"
+ version="2.1-SNAPSHOT" path="1.2."/>
+ <snapshots id="3" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
+ status="P" islast="[false]" purge_status="1"
+ period1_mode="days1" period1_param="30" period1_date="1316815200000"
+ period2_mode="days2" period2_param="31" period2_date="1316901600000"
+ period3_mode="days3" period3_param="32" period3_date="1316988000000"
+ period4_mode="days4" period4_param="33" period4_date="1317074400000"
+ period5_mode="days5" period5_param="34" period5_date="1317160800000"
+ depth="1" scope="DIR" qualifier="PAC" created_at="1228172400003" build_date="1317247200000"
+ version="2.2-SNAPSHOT" path="1.2."/>
+
+ <!-- PROJECT_ID = 2 -->
+ <snapshots id="4" project_id="2" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
+ status="P" islast="[true]" purge_status="1"
+ period1_mode="days1" period1_param="30" period1_date="1316815200000"
+ period2_mode="days2" period2_param="31" period2_date="1316901600000"
+ period3_mode="days3" period3_param="32" period3_date="1316988000000"
+ period4_mode="days4" period4_param="33" period4_date="1317074400000"
+ period5_mode="days5" period5_param="34" period5_date="1317160800000"
+ depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
+ version="2.1-SNAPSHOT" path="1.2."/>
+ <!-- Unprocessed snapshot -->
+ <snapshots id="5" project_id="2" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
+ status="U" islast="[true]" purge_status="1"
+ period1_mode="days1" period1_param="30" period1_date="1316815200000"
+ period2_mode="days2" period2_param="31" period2_date="1316901600000"
+ period3_mode="days3" period3_param="32" period3_date="1316988000000"
+ period4_mode="days4" period4_param="33" period4_date="1317074400000"
+ period5_mode="days5" period5_param="34" period5_date="1317160800000"
+ depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
+ version="2.1-SNAPSHOT" path="1.2."/>
+
+ <!-- PROJECT_ID = 3 - no last snapshot -->
+ <snapshots id="6" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
+ status="P" islast="[false]" purge_status="1"
+ period1_mode="days1" period1_param="30" period1_date="1316815200000"
+ period2_mode="days2" period2_param="31" period2_date="1316901600000"
+ period3_mode="days3" period3_param="32" period3_date="1316988000000"
+ period4_mode="days4" period4_param="33" period4_date="1317074400000"
+ period5_mode="days5" period5_param="34" period5_date="1317160800000"
+ depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
+ version="2.1-SNAPSHOT" path="1.2."/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <snapshots id="3" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
+ status="P" islast="[true]" purge_status="1"
+ period1_mode="days1" period1_param="30" period1_date="1316815200000"
+ period2_mode="days2" period2_param="31" period2_date="1316901600000"
+ period3_mode="days3" period3_param="32" period3_date="1316988000000"
+ period4_mode="days4" period4_param="33" period4_date="1317074400000"
+ period5_mode="days5" period5_param="34" period5_date="1317160800000"
+ depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
+ version="2.1-SNAPSHOT" path="1.2."/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <!-- PROJECT_ID = 1 -->
+ <snapshots id="1" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
+ status="P" islast="[true]" purge_status="1"
+ period1_mode="days1" period1_param="30" period1_date="1316815200000"
+ period2_mode="days2" period2_param="31" period2_date="1316901600000"
+ period3_mode="days3" period3_param="32" period3_date="1316988000000"
+ period4_mode="days4" period4_param="33" period4_date="1317074400000"
+ period5_mode="days5" period5_param="34" period5_date="1317160800000"
+ depth="1" scope="PRJ" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
+ version="2.1-SNAPSHOT" path="1.2."/>
+ <snapshots id="2" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
+ status="P" islast="[false]" purge_status="1"
+ period1_mode="days1" period1_param="30" period1_date="1316815200000"
+ period2_mode="days2" period2_param="31" period2_date="1316901600000"
+ period3_mode="days3" period3_param="32" period3_date="1316988000000"
+ period4_mode="days4" period4_param="33" period4_date="1317074400000"
+ period5_mode="days5" period5_param="34" period5_date="1317160800000"
+ depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
+ version="2.1-SNAPSHOT" path="1.2."/>
+ <snapshots id="3" project_id="1" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
+ status="P" islast="[false]" purge_status="1"
+ period1_mode="days1" period1_param="30" period1_date="1316815200000"
+ period2_mode="days2" period2_param="31" period2_date="1316901600000"
+ period3_mode="days3" period3_param="32" period3_date="1316988000000"
+ period4_mode="days4" period4_param="33" period4_date="1317074400000"
+ period5_mode="days5" period5_param="34" period5_date="1317160800000"
+ depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
+ version="2.1-SNAPSHOT" path="1.2."/>
+
+
+ <!-- PROJECT_ID = 2 -->
+ <snapshots id="4" project_id="2" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
+ status="P" islast="[true]" purge_status="1"
+ period1_mode="days1" period1_param="30" period1_date="1316815200000"
+ period2_mode="days2" period2_param="31" period2_date="1316901600000"
+ period3_mode="days3" period3_param="32" period3_date="1316988000000"
+ period4_mode="days4" period4_param="33" period4_date="1317074400000"
+ period5_mode="days5" period5_param="34" period5_date="1317160800000"
+ depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
+ version="2.1-SNAPSHOT" path="1.2."/>
+
+ <!-- PROJECT_ID = 3 - no last snapshot -->
+ <snapshots id="5" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
+ status="P" islast="[false]" purge_status="1"
+ period1_mode="days1" period1_param="30" period1_date="1316815200000"
+ period2_mode="days2" period2_param="31" period2_date="1316901600000"
+ period3_mode="days3" period3_param="32" period3_date="1316988000000"
+ period4_mode="days4" period4_param="33" period4_date="1317074400000"
+ period5_mode="days5" period5_param="34" period5_date="1317160800000"
+ depth="1" scope="DIR" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
+ version="2.1-SNAPSHOT" path="1.2."/>
+
+ <!-- Child of snapshot id=1 -->
+ <snapshots id="6" project_id="55" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
+ status="P" islast="[true]" purge_status="1"
+ period1_mode="days1" period1_param="30" period1_date="1316815200000"
+ period2_mode="days2" period2_param="31" period2_date="1316901600000"
+ period3_mode="days3" period3_param="32" period3_date="1316988000000"
+ period4_mode="days4" period4_param="33" period4_date="1317074400000"
+ period5_mode="days5" period5_param="34" period5_date="1317160800000"
+ depth="1" scope="PRJ" qualifier="PAC" created_at="1228172400000" build_date="1317247200000"
+ version="2.1-SNAPSHOT" path="1.2."/>
+</dataset>
--- /dev/null
+<dataset>
+ <analysis_reports
+ id="1"
+ uuid="REPORT_1"
+ project_key="123456789-987654321"
+ report_status="WORKING"
+ created_at="1411509600000"
+ updated_at="1411509600000"
+ />
+ <analysis_reports
+ id="2"
+ uuid="REPORT_2"
+ project_key="123456789-987654321"
+ report_status="WORKING"
+ created_at="1411596000000"
+ updated_at="1411596000000"
+ />
+ <analysis_reports
+ id="3"
+ uuid="REPORT_3"
+ project_key="123456789-987654321"
+ report_status="PENDING"
+ created_at="1411682400000"
+ updated_at="1411682400000"
+ />
+</dataset>
--- /dev/null
+<dataset>
+ <analysis_reports
+ id="1"
+ project_key="123456789-987654321"
+ uuid="REPORT_1"
+ report_status="PENDING"
+ created_at="1411509600000"
+ updated_at="1411596000000"
+ />
+ <analysis_reports
+ id="2"
+ project_key="987654321-123456789"
+ uuid="REPORT_2"
+ report_status="WORKING"
+ created_at="1411423200000"
+ updated_at="1411682400000"
+ />
+</dataset>
--- /dev/null
+<dataset>
+
+</dataset>
--- /dev/null
+<dataset>
+ <analysis_reports
+ id="1"
+ project_key="ProjectKey1"
+ project_name="Project 1"
+ uuid="UUID_1"
+ report_status="PENDING"
+ started_at="[null]"
+ finished_at="[null]"
+ created_at="1500000000000"
+ updated_at="1500000000000"
+ />
+ <analysis_reports
+ id="2"
+ project_key="ProjectKey2"
+ project_name="Project 2"
+ uuid="UUID_2"
+ report_status="PENDING"
+ started_at="[null]"
+ finished_at="[null]"
+ created_at="1500000000000"
+ updated_at="1500000000000"
+ />
+</dataset>
--- /dev/null
+<dataset>
+ <analysis_reports
+ id="1"
+ project_key="123456789-987654321"
+ uuid="REPORT_1"
+ report_status="WORKING"
+ created_at="1500000000001"
+ updated_at="1500000000002"
+ started_at="1500000000003"
+ finished_at="1500000000004"
+ />
+</dataset>
--- /dev/null
+<dataset>
+ <analysis_reports
+ id="1"
+ project_key="111111111-987654321"
+ uuid="UUID_1"
+ report_status="WORKING"
+ created_at="1411596000000"
+ updated_at="1411682400000"
+ />
+ <analysis_reports
+ id="2"
+ project_key="123456789-987654321"
+ uuid="UUID_2"
+ report_status="WORKING"
+ created_at="1411509600000"
+ updated_at="1411682400000"
+ />
+ <!-- not select as the previous report which is working is on the same project -->
+ <analysis_reports
+ id="3"
+ project_key="123456789-987654321"
+ uuid="UUID_3"
+ report_status="PENDING"
+ created_at="1411596000000"
+ updated_at="1411682400000"
+ />
+</dataset>
--- /dev/null
+<dataset>
+ <!-- WORKING -->
+ <analysis_reports
+ id="1"
+ project_key="P1"
+ uuid="UUID_1"
+ report_status="WORKING"
+ created_at="1411596000000"
+ updated_at="1411682400000"
+ />
+
+ <!-- PENDING on P1, which is already being WORKING-->
+ <analysis_reports
+ id="2"
+ project_key="P1"
+ uuid="UUID_2"
+ report_status="PENDING"
+ created_at="1411509600000"
+ updated_at="1411682400000"
+ />
+ <analysis_reports
+ id="3"
+ project_key="P2"
+ uuid="UUID_3"
+ report_status="PENDING"
+ created_at="1411596000000"
+ updated_at="1411682400000"
+ />
+ <analysis_reports
+ id="4"
+ project_key="P2"
+ uuid="UUID_4"
+ report_status="PENDING"
+ created_at="1420066800000"
+ updated_at="1420066800000"
+ />
+</dataset>
--- /dev/null
+<dataset>
+ <analysis_reports
+ id="1"
+ project_key="123456789-987654321"
+ project_name="Project 1"
+ uuid="UUID_1"
+ report_status="WORKING"
+ created_at="1411509600000"
+ updated_at="1411596000000"
+ />
+ <analysis_reports
+ id="2"
+ project_key="987654321-123456789"
+ project_name="Project 2"
+ uuid="UUID_2"
+ report_status="WORKING"
+ created_at="1411596000000"
+ updated_at="1411596000000"
+ />
+ <analysis_reports
+ id="3"
+ project_key="987654321-123456789"
+ project_name="Project 2"
+ uuid="UUID_3"
+ report_status="PENDING"
+ created_at="1411682400000"
+ updated_at="1411682400000"
+ />
+</dataset>
--- /dev/null
+<dataset>
+ <analysis_reports
+ id="1"
+ project_key="123456789-987654321"
+ uuid="UUID_1"
+ report_status="WORKING"
+ created_at="1411509600000"
+ updated_at="1411596000000"
+ />
+ <analysis_reports
+ id="2"
+ project_key="987654321-123456789"
+ uuid="UUID_2"
+ report_status="WORKING"
+ created_at="1411596000000"
+ updated_at="1411596000000"
+ />
+ <analysis_reports
+ id="3"
+ project_key="987654321-123456789"
+ uuid="UUID_3"
+ report_status="PENDING"
+ created_at="1411682400000"
+ updated_at="1411682400000"
+ />
+</dataset>
--- /dev/null
+<dataset>
+ <analysis_reports/>
+</dataset>
--- /dev/null
+<dataset>
+ <!-- all rows are PENDING, updated_at is now, started_at is null -->
+ <analysis_reports
+ id="1"
+ project_key="P1"
+ project_name="Project1"
+ uuid="UUID_1"
+ report_status="PENDING"
+ created_at="1411509600000"
+ updated_at="1500000000000"
+ started_at="[null]"
+ finished_at="[null]"
+ />
+ <analysis_reports
+ id="2"
+ project_key="P2"
+ project_name="Project2"
+ uuid="UUID_2"
+ report_status="PENDING"
+ created_at="1411596000000"
+ updated_at="1500000000000"
+ started_at="[null]"
+ finished_at="[null]"
+ />
+ <analysis_reports
+ id="3"
+ project_key="P1"
+ project_name="Project1"
+ uuid="UUID_3"
+ report_status="PENDING"
+ created_at="1411682400000"
+ updated_at="1500000000000"
+ started_at="[null]"
+ finished_at="[null]"
+ />
+</dataset>
--- /dev/null
+<dataset>
+ <analysis_reports
+ id="1"
+ project_key="P1"
+ project_name="Project1"
+ uuid="UUID_1"
+ report_status="WORKING"
+ created_at="1411509600000"
+ updated_at="1411509600000"
+ started_at="1411509600000"
+ finished_at="[null]"
+ />
+ <analysis_reports
+ id="2"
+ project_key="P2"
+ project_name="Project2"
+ uuid="UUID_2"
+ report_status="WORKING"
+ created_at="1411596000000"
+ updated_at="1411596000000"
+ started_at="1411509600000"
+ finished_at="[null]"
+ />
+ <analysis_reports
+ id="3"
+ project_key="P1"
+ project_name="Project1"
+ uuid="UUID_3"
+ report_status="PENDING"
+ created_at="1411682400000"
+ updated_at="1411682400000"
+ started_at="[null]"
+ finished_at="[null]"
+ />
+</dataset>
--- /dev/null
+<dataset>
+
+ <widgets id="1" dashboard_id="1" widget_key="polop" name="Polop" description="Palap"
+ column_index="1" row_index="1" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
+
+ <widgets id="2" dashboard_id="1" widget_key="false_positive_reviews" name="Polop" description="Palap"
+ column_index="1" row_index="2" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
+
+ <widgets id="3" dashboard_id="1" widget_key="my_reviews" name="Polop" description="Palap"
+ column_index="1" row_index="3" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
+
+ <widgets id="4" dashboard_id="1" widget_key="reviews_per_developer" name="Polop" description="Palap"
+ column_index="1" row_index="4" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
+
+ <widgets id="5" dashboard_id="1" widget_key="unresolved_issues_statuses" name="Polop" description="Palap"
+ column_index="1" row_index="5" configured="[true]" created_at="[null]" updated_at="[null]" resource_id="[null]"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <events id="1" name="1.0" category="Version" description="Version 1.0" event_data="some data" event_date="1225630680000"
+ component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
+
+</dataset>
--- /dev/null
+<dataset>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <events id="1" name="1.0" category="Version" description="Version 1.0" event_data="some data" event_date="1413407091086"
+ component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <events id="1" name="1.0" category="Version" description="Version 1.0" event_data="some data" event_date="1413407091086"
+ component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
+ <events id="2" name="Red (was Orange)" category="Alert" description="Critical issues variation > 0 since previous version (1.0 - 2015 Feb 09), Open issues > 0"
+ event_data="[null]" event_date="1413407091086" component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
+ <events id="3" name="Changes in 'Default' (Java)" category="Profile" description="Version 1.0" event_data="from=2014-10-12T08:36:25+0000;key=java-default;to=2014-10-12T10:36:25+0000"
+ event_date="1413407091086" component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
+
+ <events id="4" name="1.0" category="Version" description="Version 1.0" event_data="some data" event_date="1413407091086"
+ component_uuid="BCDE" snapshot_id="1000" created_at="1225630680000" />
+
+</dataset>
--- /dev/null
+<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>
--- /dev/null
+<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>
--- /dev/null
+<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>
--- /dev/null
+<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>
--- /dev/null
+<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>
--- /dev/null
+<dataset>
+ <project_measures/>
+</dataset>
--- /dev/null
+<dataset>
+ <project_measures
+ id="1"
+ snapshot_id="2"
+ metric_id="3"
+ characteristic_id="4"
+ rule_id="5"
+ project_id="6"
+ person_id="23"
+ value="2.0"
+ text_value="measure-value"
+ tendency="[null]"
+ rule_priority="[null]"
+ measure_date="[null]"
+ measure_data="[null]"
+ variation_value_1="1.0"
+ variation_value_2="2.0"
+ variation_value_3="3.0"
+ variation_value_4="4.0"
+ variation_value_5="5.0"
+ alert_status="alert"
+ alert_text="alert-text"
+ url="[null]"
+ description="measure-description"
+ rules_category_id="[null]"
+ />
+</dataset>
--- /dev/null
+<dataset>
+
+ <metrics id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]" enabled="[true]"/>
+
+ <metrics id="2" name="coverage" VAL_TYPE="INT" enabled="[true]"/>
+
+
+ <rules tags="[null]" system_tags="[null]" id="30" name="Check Header" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck"
+ plugin_config_key="Checker/Treewalker/HeaderCheck" plugin_name="checkstyle" description="[null]" priority="4" status="READY"
+ is_template="[false]" template_id="[null]"/>
+
+ <rules tags="[null]" system_tags="[null]" id="31" name="Equals Avoid Null" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck"
+ plugin_config_key="Checker/TreeWalker/EqualsAvoidNull" plugin_name="checkstyle" description="[null]" priority="4" status="READY"
+ is_template="[false]" template_id="[null]"/>
+
+ <!-- project -->
+ <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
+ root_id="[null]" uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD."
+ enabled="[true]"/>
+
+ <!-- package -->
+ <projects long_name="[null]" id="2" scope="DIR" qualifier="PAC" kee="project:org.foo" name="org.foo"
+ root_id="1" uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
+ enabled="[true]"/>
+
+ <!-- file -->
+ <projects long_name="org.foo.Bar" id="3" scope="FIL" qualifier="CLA" kee="project:org.foo.Bar"
+ name="Bar" root_id="[null]" uuid="CDEF" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
+ enabled="[true]"/>
+
+
+ <!-- snapshots -->
+ <snapshots id="1000" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="1225544280000" build_date="1225544280000" version="[null]" path=""
+ status="P" islast="[false]" depth="0"/>
+ <snapshots id="1001" project_id="2" parent_snapshot_id="1000" root_project_id="1" root_snapshot_id="1000"
+ scope="DIR" qualifier="PAC" created_at="1225544280000" build_date="1225544280000" version="[null]" path="1000."
+ status="P" islast="[false]" depth="1"/>
+ <snapshots id="1002" project_id="3" parent_snapshot_id="1001" root_project_id="1" root_snapshot_id="1000"
+ scope="FIL" qualifier="CLA" created_at="1225544280000" build_date="1225544280000" version="[null]" path="1000.1001."
+ status="P" islast="[false]" depth="2"/>
+
+
+ <!-- project measures -->
+ <project_measures id="1" VALUE="60" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
+
+ <project_measures id="2" VALUE="80" METRIC_ID="2" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
+
+ <!-- package measures -->
+ <project_measures id="3" VALUE="20" METRIC_ID="1" SNAPSHOT_ID="1001" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
+
+ <project_measures id="4" VALUE="70" METRIC_ID="2" SNAPSHOT_ID="1001" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
+
+ <!-- file measures -->
+ <project_measures id="5" VALUE="5" METRIC_ID="1" SNAPSHOT_ID="1002" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
+
+ <project_measures id="6" VALUE="60" METRIC_ID="2" SNAPSHOT_ID="1002" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <metrics id="1" name="sqale_index" VAL_TYPE="WORK_DUR" DESCRIPTION="[null]" short_name="" enabled="[true]"/>
+
+ <!-- Root characteristic -->
+ <characteristics id="10" kee="PORTABILITY" name="Portability" parent_id="[null]" characteristic_order="1" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/>
+
+ <!-- Characteristic -->
+ <characteristics id="11" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" parent_id="10" characteristic_order="[null]" enabled="[true]"
+ created_at="2013-11-20" updated_at="2013-11-22"/>
+
+ <!-- project -->
+ <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
+ root_id="[null]" uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD." enabled="[true]"/>
+
+ <!-- snapshots -->
+ <snapshots id="1000" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="1225544280000" build_date="1225544280000" version="[null]" path=""
+ status="P" islast="[false]" depth="0"/>
+
+ <!-- project measures -->
+ <project_measures id="1" VALUE="60" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="[null]"/>
+
+ <project_measures id="2" VALUE="20" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="10"/>
+
+ <project_measures id="3" VALUE="40" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="11"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <metrics delete_historical_data="[null]" id="1" name="sqale_index" VAL_TYPE="INT" DESCRIPTION="[null]" enabled="[true]"/>
+
+ <!-- project -->
+ <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
+ root_id="[null]" uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD."
+ enabled="[true]"/>
+
+ <!-- snapshots -->
+ <snapshots id="1000" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="1225544280000" build_date="1225544280000" version="[null]" path=""
+ status="P" islast="[false]" depth="0"/>
+
+ <!-- project measures -->
+ <project_measures id="1" VALUE="60" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" person_id="[null]"/>
+
+ <project_measures id="2" VALUE="20" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" person_id="20"/>
+
+ <project_measures id="3" VALUE="40" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" person_id="21"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <metrics delete_historical_data="[null]" id="1" name="minor_violations" VAL_TYPE="INT" DESCRIPTION="[null]" enabled="[true]"/>
+
+ <rules tags="[null]" system_tags="[null]" id="30" name="Classes that override clone should be Cloneable and call super.clone()"
+ plugin_rule_key="S1182"
+ plugin_config_key="S1182" plugin_name="squid" description="[null]" priority="4" status="READY"
+ is_template="[false]" template_id="[null]"/>
+
+ <rules tags="[null]" system_tags="[null]" id="31" name="Overriding methods should do more than simply call the same method in the super class"
+ plugin_rule_key="S1185"
+ plugin_config_key="S1185" plugin_name="squid" description="[null]" priority="1" status="READY"
+ is_template="[false]" template_id="[null]"/>
+
+ <!-- project -->
+ <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
+ root_id="[null]" uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD."
+ enabled="[true]"/>
+
+ <!-- snapshots -->
+ <snapshots id="1000" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="1225544280000" build_date="1225544280000" version="[null]" path=""
+ status="P" islast="[false]" depth="0"/>
+
+ <!-- project measures -->
+ <project_measures id="1" VALUE="60" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="[null]" characteristic_id="[null]" person_id="[null]"/>
+
+ <project_measures id="2" VALUE="20" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="30" characteristic_id="[null]" person_id="[null]"/>
+
+ <project_measures id="3" VALUE="40" METRIC_ID="1" SNAPSHOT_ID="1000" RULE_ID="31" characteristic_id="[null]" person_id="[null]"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <metrics id="10" name="authors_by_line"/>
+ <metrics id="11" name="coverage_line_hits_data"/>
+ <metrics id="12" name="ncloc"/>
+
+ <projects id="1" kee="org.struts:struts-core:src/org/struts/RequestContext.java" enabled="[true]"/>
+
+ <snapshots id="5" project_id="1" islast="[true]" />
+
+ <project_measures id="20" snapshot_id="5" metric_id="10" value="[null]" text_value="0123456789012345678901234567890123456789" measure_data="[null]"
+ variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
+ alert_status="[null]" alert_text="[null]" />
+ <project_measures id="21" snapshot_id="5" metric_id="11" value="[null]" text_value="36=1;37=1;38=1;39=1;43=1;48=1;53=1" measure_data="[null]"
+ variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"
+ alert_status="[null]" alert_text="[null]" />
+ <project_measures id="22" snapshot_id="5" metric_id="12" value="10" text_value="[null]" measure_data="[null]"
+ variation_value_1="1" variation_value_2="2" variation_value_3="3" variation_value_4="4" variation_value_5="-5"
+ alert_status="OK" alert_text="Green"/>
+
+</dataset>
+++ /dev/null
-<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>
+++ /dev/null
-<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>
+++ /dev/null
-<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>
+++ /dev/null
-<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>
+++ /dev/null
-<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>
+++ /dev/null
-<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>
+++ /dev/null
-<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>
+++ /dev/null
-<dataset>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="10" failure_level="2"
- inheritance="INHERITED"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" rules_parameter_key="max" value="20"/>
-
-</dataset>
+++ /dev/null
-<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>
+++ /dev/null
-<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>
+++ /dev/null
-<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>
--- /dev/null
+<dataset>
+
+ <file_sources id="101" project_uuid="PRJ_UUID" file_uuid="FILE1_UUID"
+ binary_data="abcde" data_hash="hash"
+ line_hashes="ABC\nDEF\nGHI"
+ src_hash="FILE_HASH"
+ created_at="1500000000000" updated_at="1500000000000" data_type="SOURCE" />
+
+
+ <file_sources id="102" project_uuid="PRJ_UUID" file_uuid="FILE2_UUID"
+ binary_data="[ignore]"
+ data_hash="FILE2_DATA_HASH"
+ line_hashes="LINE1_HASH\nLINE2_HASH"
+ src_hash="FILE2_HASH"
+ created_at="1500000000000" updated_at="1500000000001" data_type="SOURCE" />
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <file_sources id="101" project_uuid="PRJ_UUID" file_uuid="FILE1_UUID"
+ binary_data="abcde" data_hash="[null]"
+ line_hashes="[null]"
+ src_hash="[null]"
+ created_at="1500000000000" updated_at="1500000000000" data_type="TEST" />
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <file_sources id="101" project_uuid="PRJ_UUID" file_uuid="FILE1_UUID"
+ binary_data="abcde" data_hash="hash"
+ line_hashes="ABC\nDEF\nGHI"
+ src_hash="FILE_HASH"
+ created_at="1500000000000" updated_at="1500000000000" data_type="SOURCE" />
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <file_sources id="101" project_uuid="PRJ_UUID" file_uuid="FILE1_UUID"
+ binary_data="[ignore]"
+ data_hash="NEW_DATA_HASH"
+ line_hashes="NEW_LINE_HASHES"
+ src_hash="NEW_FILE_HASH"
+ created_at="1500000000000" updated_at="1500000000002" data_type="SOURCE" />
+
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <!-- Updated -->
+ <file_sources id="101" project_uuid="ABCD" file_uuid="FILE1_UUID"
+ binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
+ created_at="1500000000000" updated_at="1500000000002" data_type="SOURCE" />
+
+ <!-- Not updated because updated_at is not null -->
+ <file_sources id="102" project_uuid="ABCD" file_uuid="FILE2_UUID"
+ binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
+ created_at="1500000000000" updated_at="1500000000000" data_type="SOURCE" />
+
+ <!-- Not updated because on another project -->
+ <file_sources id="103" project_uuid="BCDE" file_uuid="FILE3_UUID"
+ binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
+ created_at="1500000000000" updated_at="0" data_type="SOURCE" />
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <!-- Only this source should be updated -->
+ <file_sources id="101" project_uuid="ABCD" file_uuid="FILE1_UUID"
+ binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
+ created_at="1500000000000" updated_at="0" data_type="SOURCE" />
+
+ <file_sources id="102" project_uuid="ABCD" file_uuid="FILE2_UUID"
+ binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
+ created_at="1500000000000" updated_at="1500000000000" data_type="SOURCE" />
+
+ <file_sources id="103" project_uuid="BCDE" file_uuid="FILE3_UUID"
+ binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
+ created_at="1500000000000" updated_at="0" data_type="SOURCE" />
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <groups_users user_id="1" group_id="2"/>
+ <groups_users user_id="2" group_id="2"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <groups_users user_id="1" group_id="1"/>
+ <groups_users user_id="2" group_id="1"/>
+ <groups_users user_id="1" group_id="2"/>
+ <groups_users user_id="2" group_id="2"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <groups_users user_id="1" group_id="2"/>
+
+</dataset>
+++ /dev/null
-<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