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.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.System2;
import org.sonar.api.utils.internal.Uuids;
import org.sonar.db.DbTester;
import org.sonar.db.source.FileSourceDao;
import org.sonar.db.source.FileSourceDto;
-import org.sonar.server.db.DbClient;
import org.sonar.server.source.db.FileSourceDb;
import org.sonar.server.source.index.FileSourcesUpdaterHelper;
import org.sonar.server.source.index.SourceLineResultSetIterator;
public static final String PROJECT_UUID = Uuids.create();
@Rule
- public DbTester dbTester = new DbTester();
+ public DbTester dbTester = DbTester.create(System2.INSTANCE);
@Rule
public Benchmark benchmark = new Benchmark();
private void scrollRows() throws Exception {
LOGGER.info("Scroll table FILE_SOURCES");
- DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis());
- Connection connection = dbTester.openConnection();
AtomicLong counter = new AtomicLong();
ProgressTask progress = new ProgressTask(LOGGER, "source file", counter);
Timer timer = new Timer("SourceDbScroll");
try {
long start = System.currentTimeMillis();
- SourceLineResultSetIterator it = SourceLineResultSetIterator.create(dbClient, connection, 0L, null);
+ SourceLineResultSetIterator it = SourceLineResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L, null);
while (it.hasNext()) {
FileSourcesUpdaterHelper.Row row = it.next();
assertThat(row.getUpdateRequests().size()).isEqualTo(NUMBER_OF_LINES);
benchmark.expectBetween("Throughput to scroll FILE_SOURCES", throughputPerSecond, 9, 13);
} finally {
- DbUtils.closeQuietly(connection);
timer.cancel();
}
}
*/
package org.sonar.server.activity;
-import org.sonar.api.server.ServerSide;
import org.sonar.api.utils.KeyValueFormat;
import org.sonar.api.utils.internal.Uuids;
import org.sonar.db.activity.ActivityDto;
import org.sonar.server.activity.index.ActivityIndexer;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.user.UserSession;
-@ServerSide
public class ActivityService {
private final DbClient dbClient;
*/
package org.sonar.server.activity.index;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.server.db.DbClient;
import org.sonar.server.es.BaseIndexer;
import org.sonar.server.es.BulkIndexer;
import org.sonar.server.es.EsClient;
-import java.sql.Connection;
-
/**
* Add to Elasticsearch index {@link org.sonar.server.activity.index.ActivityIndexDefinition} the rows of
* db table ACTIVITIES that are not indexed yet
bulk.setLarge(lastUpdatedAt == 0L);
DbSession dbSession = dbClient.openSession(false);
- Connection dbConnection = dbSession.getConnection();
try {
- ActivityResultSetIterator it = ActivityResultSetIterator.create(dbClient, dbConnection, lastUpdatedAt);
+ ActivityResultSetIterator it = ActivityResultSetIterator.create(dbClient, dbSession, lastUpdatedAt);
bulk.start();
while (it.hasNext()) {
bulk.add(it.next());
*/
package org.sonar.server.activity.index;
-import org.apache.commons.lang.StringUtils;
-import org.elasticsearch.action.update.UpdateRequest;
-import org.sonar.api.utils.KeyValueFormat;
-import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.server.db.DbClient;
-import org.sonar.db.ResultSetIterator;
-import org.sonar.server.es.EsUtils;
-import org.sonar.server.util.DateCollector;
-
import java.io.ByteArrayOutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
-import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;
+import org.apache.commons.lang.StringUtils;
+import org.elasticsearch.action.update.UpdateRequest;
+import org.sonar.api.utils.KeyValueFormat;
+import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.ResultSetIterator;
+import org.sonar.server.es.EsUtils;
+import org.sonar.server.util.DateCollector;
/**
* Scrolls over table ACTIVITIES and reads documents to populate
super(stmt);
}
- static ActivityResultSetIterator create(DbClient dbClient, Connection connection, long afterDate) {
+ static ActivityResultSetIterator create(DbClient dbClient, DbSession session, long afterDate) {
try {
String sql = afterDate > 0L ? SQL_AFTER_DATE : SQL_ALL;
- PreparedStatement stmt = dbClient.newScrollingSelectStatement(connection, sql);
+ PreparedStatement stmt = dbClient.getMyBatis().newScrollingSelectStatement(session, sql);
if (afterDate > 0L) {
stmt.setTimestamp(1, new Timestamp(afterDate));
}
import org.sonar.core.component.ComponentKeys;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.DbSession;
-import org.sonar.db.component.ResourceIndexerDao;
+import org.sonar.db.component.ResourceIndexDao;
import org.sonar.db.component.ResourceKeyUpdaterDao;
import org.sonar.server.db.DbClient;
import org.sonar.server.exceptions.BadRequestException;
private final ResourceKeyUpdaterDao resourceKeyUpdaterDao;
private final I18n i18n;
- private final ResourceIndexerDao resourceIndexerDao;
+ private final ResourceIndexDao resourceIndexDao;
private final UserSession userSession;
private final System2 system2;
- public ComponentService(DbClient dbClient, ResourceKeyUpdaterDao resourceKeyUpdaterDao, I18n i18n, ResourceIndexerDao resourceIndexerDao,
+ public ComponentService(DbClient dbClient, ResourceKeyUpdaterDao resourceKeyUpdaterDao, I18n i18n, ResourceIndexDao resourceIndexDao,
UserSession userSession, System2 system2) {
this.dbClient = dbClient;
this.resourceKeyUpdaterDao = resourceKeyUpdaterDao;
this.i18n = i18n;
- this.resourceIndexerDao = resourceIndexerDao;
+ this.resourceIndexDao = resourceIndexDao;
this.userSession = userSession;
this.system2 = system2;
}
.setCreatedAt(new Date(system2.now()))
;
dbClient.componentDao().insert(session, component);
- resourceIndexerDao.indexResource(session, component.getId());
+ resourceIndexDao.indexResource(session, component.getId());
session.commit();
return component.key();
import org.apache.ibatis.session.RowBounds;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Scopes;
-import org.sonar.api.server.ServerSide;
import org.sonar.db.Dao;
-import org.sonar.db.DaoUtils;
import org.sonar.db.DatabaseUtils;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import static com.google.common.collect.Maps.newHashMapWithExpectedSize;
-/**
- * @since 4.3
- */
-@ServerSide
public class ComponentDao implements Dao {
public ComponentDto selectById(long id, DbSession session) {
import org.sonar.db.MyBatis;
import org.sonar.process.ProcessProperties;
import org.sonar.db.compute.AnalysisReportDao;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import static org.sonar.db.compute.AnalysisReportDto.Status.PENDING;
package org.sonar.server.computation.activity;
import javax.annotation.CheckForNull;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.db.compute.AnalysisReportDto;
+import org.sonar.server.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
+import org.sonar.db.component.ComponentDto;
+import org.sonar.db.compute.AnalysisReportDto;
import org.sonar.server.activity.Activity;
import org.sonar.server.activity.ActivityService;
-import org.sonar.server.db.DbClient;
import static org.sonar.api.utils.DateUtils.formatDateTimeNullSafe;
import static org.sonar.api.utils.DateUtils.longToDate;
import org.sonar.db.MyBatis;
import org.sonar.server.computation.batch.BatchReportReader;
import org.sonar.server.computation.component.TreeRootHolder;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import static com.google.common.collect.FluentIterable.from;
import static org.sonar.core.rule.RuleKeyFunctions.stringToRuleKey;
import org.sonar.server.computation.metric.MetricRepository;
import org.sonar.server.computation.period.Period;
import org.sonar.server.computation.period.PeriodsHolder;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
public class NewDebtAggregator extends IssueVisitor {
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
import org.sonar.server.computation.component.Component;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
/**
* Factory of {@link Input} of base data for issue tracking. Data are lazy-loaded.
import org.sonar.server.computation.debt.Characteristic;
import org.sonar.server.computation.metric.Metric;
import org.sonar.server.computation.metric.MetricRepository;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;
import org.sonar.db.MyBatis;
import org.sonar.server.computation.component.DbIdsRepository;
import org.sonar.server.computation.component.TreeRootHolder;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.issue.index.IssueAuthorizationIndexer;
/**
import org.sonar.db.debt.CharacteristicDto;
import org.sonar.server.computation.debt.Characteristic;
import org.sonar.server.computation.debt.MutableDebtModelHolder;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import static com.google.common.base.Predicates.not;
import static com.google.common.collect.FluentIterable.from;
import org.sonar.server.computation.metric.MetricRepository;
import org.sonar.server.computation.period.Period;
import org.sonar.server.computation.period.PeriodsHolder;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import static org.sonar.server.computation.component.ComponentVisitor.Order.PRE_ORDER;
package org.sonar.server.computation.step;
-import org.sonar.db.component.ResourceIndexerDao;
+import org.sonar.db.component.ResourceIndexDao;
import org.sonar.server.computation.component.DbIdsRepository;
import org.sonar.server.computation.component.TreeRootHolder;
*/
public class IndexComponentsStep implements ComputationStep {
- private final ResourceIndexerDao resourceIndexerDao;
+ private final ResourceIndexDao resourceIndexDao;
private final DbIdsRepository dbIdsRepository;
private final TreeRootHolder treeRootHolder;
- public IndexComponentsStep(ResourceIndexerDao resourceIndexerDao, DbIdsRepository dbIdsRepository, TreeRootHolder treeRootHolder) {
- this.resourceIndexerDao = resourceIndexerDao;
+ public IndexComponentsStep(ResourceIndexDao resourceIndexDao, DbIdsRepository dbIdsRepository, TreeRootHolder treeRootHolder) {
+ this.resourceIndexDao = resourceIndexDao;
this.dbIdsRepository = dbIdsRepository;
this.treeRootHolder = treeRootHolder;
}
@Override
public void execute() {
- resourceIndexerDao.indexProject(dbIdsRepository.getComponentId(treeRootHolder.getRoot()));
+ resourceIndexDao.indexProject(dbIdsRepository.getComponentId(treeRootHolder.getRoot()));
}
@Override
import org.sonar.server.computation.component.TreeRootHolder;
import org.sonar.server.computation.event.Event;
import org.sonar.server.computation.event.EventRepository;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import static com.google.common.collect.Iterables.transform;
import org.sonar.server.computation.source.LineReader;
import org.sonar.server.computation.source.ScmLineReader;
import org.sonar.server.computation.source.SymbolsLineReader;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.source.db.FileSourceDb;
import org.sonar.server.util.CloseableIterator;
import org.sonar.db.MyBatis;
import org.sonar.server.computation.issue.IssueCache;
import org.sonar.server.computation.issue.RuleRepository;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.util.CloseableIterator;
public class PersistIssuesStep implements ComputationStep {
import org.sonar.server.computation.measure.MeasureToMeasureDto;
import org.sonar.server.computation.metric.Metric;
import org.sonar.server.computation.metric.MetricRepository;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import static com.google.common.collect.FluentIterable.from;
import static org.sonar.server.computation.component.ComponentVisitor.Order.PRE_ORDER;
import org.sonar.server.computation.component.DepthTraversalTypeAwareVisitor;
import org.sonar.server.computation.component.TreeRootHolder;
import org.sonar.server.computation.metric.MetricRepository;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.source.index.SourceLineIndex;
import static com.google.common.base.Objects.firstNonNull;
import org.sonar.server.computation.component.Component;
import org.sonar.server.computation.component.DepthTraversalTypeAwareVisitor;
import org.sonar.server.computation.component.TreeRootHolder;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import static com.google.common.collect.Sets.newHashSet;
import static org.sonar.server.computation.component.ComponentVisitor.Order.PRE_ORDER;
import org.sonar.server.computation.component.TreeRootHolder;
import org.sonar.server.computation.period.Period;
import org.sonar.server.computation.period.PeriodsHolder;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
/**
* Persist snapshots
import org.sonar.server.computation.component.Component;
import org.sonar.server.computation.component.DepthTraversalTypeAwareVisitor;
import org.sonar.server.computation.component.TreeRootHolder;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.source.db.FileSourceDb;
import org.sonar.server.source.db.FileSourceDb.Test.TestStatus;
import org.sonar.server.util.CloseableIterator;
import org.sonar.server.computation.component.DbIdsRepository;
import org.sonar.server.computation.component.ProjectSettingsRepository;
import org.sonar.server.computation.component.TreeRootHolder;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
public class PurgeDatastoresStep implements ComputationStep {
import org.sonar.server.computation.component.Component;
import org.sonar.server.computation.component.DbIdsRepository;
import org.sonar.server.computation.component.TreeRootHolder;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import static org.sonar.db.component.SnapshotDao.isLast;
*/
package org.sonar.server.db;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.IdentityHashMap;
import java.util.Map;
-import javax.annotation.Nullable;
import org.sonar.db.Dao;
import org.sonar.db.Database;
-import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
-import org.sonar.db.activity.ActivityDao;
-import org.sonar.db.component.ComponentLinkDao;
-import org.sonar.db.component.ResourceDao;
-import org.sonar.db.component.ResourceIndexerDao;
-import org.sonar.db.component.SnapshotDao;
-import org.sonar.db.compute.AnalysisReportDao;
-import org.sonar.db.dashboard.DashboardDao;
-import org.sonar.db.dashboard.WidgetDao;
-import org.sonar.db.dashboard.WidgetPropertyDao;
-import org.sonar.db.debt.CharacteristicDao;
-import org.sonar.db.event.EventDao;
-import org.sonar.db.issue.ActionPlanDao;
-import org.sonar.db.issue.IssueChangeDao;
-import org.sonar.db.issue.IssueDao;
-import org.sonar.db.issue.IssueFilterDao;
-import org.sonar.db.loadedtemplate.LoadedTemplateDao;
-import org.sonar.db.measure.MeasureDao;
-import org.sonar.db.permission.PermissionTemplateDao;
-import org.sonar.db.property.PropertiesDao;
-import org.sonar.db.purge.PurgeDao;
-import org.sonar.db.qualitygate.QualityGateConditionDao;
-import org.sonar.db.qualityprofile.QualityProfileDao;
-import org.sonar.db.source.FileSourceDao;
-import org.sonar.db.user.AuthorDao;
-import org.sonar.db.user.AuthorizationDao;
-import org.sonar.db.user.GroupMembershipDao;
-import org.sonar.db.user.RoleDao;
-import org.sonar.db.user.UserGroupDao;
import org.sonar.server.component.db.ComponentDao;
import org.sonar.server.measure.custom.persistence.CustomMeasureDao;
import org.sonar.server.metric.persistence.MetricDao;
import org.sonar.server.user.db.GroupDao;
import org.sonar.server.user.db.UserDao;
-public class DbClient {
-
- private final Database db;
- private final MyBatis myBatis;
- private final RuleDao ruleDao;
- private final ActiveRuleDao activeRuleDao;
- private final QualityProfileDao qualityProfileDao;
- private final CharacteristicDao debtCharacteristicDao;
- private final LoadedTemplateDao loadedTemplateDao;
- private final PropertiesDao propertiesDao;
- private final ComponentDao componentDao;
- private final SnapshotDao snapshotDao;
- private final ResourceDao resourceDao;
- private final MeasureDao measureDao;
- private final MetricDao metricDao;
- private final ActivityDao activityDao;
- private final AuthorizationDao authorizationDao;
- private final UserDao userDao;
- private final GroupDao groupDao;
- private final UserGroupDao userGroupDao;
- private final GroupMembershipDao groupMembershipDao;
- private final RoleDao roleDao;
- private final PermissionTemplateDao permissionTemplateDao;
- private final IssueDao issueDao;
- private final IssueFilterDao issueFilterDao;
- private final IssueChangeDao issueChangeDao;
- private final ActionPlanDao actionPlanDao;
- private final AnalysisReportDao analysisReportDao;
- private final DashboardDao dashboardDao;
- private final WidgetDao widgetDao;
- private final WidgetPropertyDao widgetPropertyDao;
- private final FileSourceDao fileSourceDao;
- private final AuthorDao authorDao;
- private final ResourceIndexerDao componentIndexDao;
- private final ComponentLinkDao componentLinkDao;
- private final EventDao eventDao;
- private final PurgeDao purgeDao;
- private final CustomMeasureDao customMeasureDao;
- private final QualityGateConditionDao gateConditionDao;
-
- public DbClient(Database db, MyBatis myBatis, Dao... daos) {
- this.db = db;
- this.myBatis = myBatis;
-
- Map<Class, Dao> map = new IdentityHashMap<>();
- for (Dao dao : daos) {
- map.put(dao.getClass(), dao);
- }
- ruleDao = getDao(map, RuleDao.class);
- activeRuleDao = getDao(map, ActiveRuleDao.class);
- debtCharacteristicDao = getDao(map, CharacteristicDao.class);
- qualityProfileDao = getDao(map, QualityProfileDao.class);
- loadedTemplateDao = getDao(map, LoadedTemplateDao.class);
- propertiesDao = getDao(map, PropertiesDao.class);
- componentDao = getDao(map, ComponentDao.class);
- snapshotDao = getDao(map, SnapshotDao.class);
- resourceDao = getDao(map, ResourceDao.class);
- measureDao = getDao(map, MeasureDao.class);
- metricDao = getDao(map, MetricDao.class);
- customMeasureDao = getDao(map, CustomMeasureDao.class);
- activityDao = getDao(map, ActivityDao.class);
- authorizationDao = getDao(map, AuthorizationDao.class);
- userDao = getDao(map, UserDao.class);
- groupDao = getDao(map, GroupDao.class);
- userGroupDao = getDao(map, UserGroupDao.class);
- groupMembershipDao = getDao(map, GroupMembershipDao.class);
- roleDao = getDao(map, RoleDao.class);
- permissionTemplateDao = getDao(map, PermissionTemplateDao.class);
- issueDao = getDao(map, IssueDao.class);
- issueFilterDao = getDao(map, IssueFilterDao.class);
- issueChangeDao = getDao(map, IssueChangeDao.class);
- actionPlanDao = getDao(map, ActionPlanDao.class);
- analysisReportDao = getDao(map, AnalysisReportDao.class);
- dashboardDao = getDao(map, DashboardDao.class);
- widgetDao = getDao(map, WidgetDao.class);
- widgetPropertyDao = getDao(map, WidgetPropertyDao.class);
- fileSourceDao = getDao(map, FileSourceDao.class);
- authorDao = getDao(map, AuthorDao.class);
- componentIndexDao = getDao(map, ResourceIndexerDao.class);
- componentLinkDao = getDao(map, ComponentLinkDao.class);
- eventDao = getDao(map, EventDao.class);
- purgeDao = getDao(map, PurgeDao.class);
- gateConditionDao = getDao(map, QualityGateConditionDao.class);
- }
-
- public Database database() {
- return db;
- }
+/**
+ * Should be replaced by {@link org.sonar.db.DbClient}, but some DAOs
+ * still depend on other sonar-server classes.
+ */
+public class DbClient extends org.sonar.db.DbClient {
- public DbSession openSession(boolean batch) {
- return myBatis.openSession(batch);
- }
+ private ActiveRuleDao activeRuleDao;
+ private ComponentDao componentDao;
+ private CustomMeasureDao customMeasureDao;
+ private GroupDao groupDao;
+ private MetricDao metricDao;
+ private RuleDao ruleDao;
+ private UserDao userDao;
- public void closeSession(@Nullable DbSession session) {
- MyBatis.closeQuietly(session);
+ public DbClient(Database database, MyBatis myBatis, Dao... daos) {
+ super(database, myBatis, daos);
}
- public RuleDao ruleDao() {
- return ruleDao;
+ @Override
+ protected void doOnLoad(Map<Class, Dao> daoByClass) {
+ this.activeRuleDao = (ActiveRuleDao) daoByClass.get(ActiveRuleDao.class);
+ this.componentDao = (ComponentDao) daoByClass.get(ComponentDao.class);
+ this.customMeasureDao = (CustomMeasureDao) daoByClass.get(CustomMeasureDao.class);
+ this.groupDao = (GroupDao) daoByClass.get(GroupDao.class);
+ this.metricDao = (MetricDao) daoByClass.get(MetricDao.class);
+ this.ruleDao = (RuleDao) daoByClass.get(RuleDao.class);
+ this.userDao = (UserDao) daoByClass.get(UserDao.class);
}
public ActiveRuleDao activeRuleDao() {
return activeRuleDao;
}
- public IssueDao issueDao() {
- return issueDao;
- }
-
- public IssueFilterDao issueFilterDao() {
- return issueFilterDao;
- }
-
- public IssueChangeDao issueChangeDao() {
- return issueChangeDao;
- }
-
- public QualityProfileDao qualityProfileDao() {
- return qualityProfileDao;
- }
-
- public CharacteristicDao debtCharacteristicDao() {
- return debtCharacteristicDao;
- }
-
- public LoadedTemplateDao loadedTemplateDao() {
- return loadedTemplateDao;
- }
-
- public PropertiesDao propertiesDao() {
- return propertiesDao;
- }
-
public ComponentDao componentDao() {
return componentDao;
}
- public SnapshotDao snapshotDao() {
- return snapshotDao;
- }
-
- public ResourceDao resourceDao() {
- return resourceDao;
- }
-
- public MeasureDao measureDao() {
- return measureDao;
- }
-
- public MetricDao metricDao() {
- return metricDao;
- }
-
public CustomMeasureDao customMeasureDao() {
return customMeasureDao;
}
- public ActivityDao activityDao() {
- return activityDao;
- }
-
- public AuthorizationDao authorizationDao() {
- return authorizationDao;
- }
-
- public UserDao userDao() {
- return userDao;
- }
-
public GroupDao groupDao() {
return groupDao;
}
- public UserGroupDao userGroupDao() {
- return userGroupDao;
- }
-
- public GroupMembershipDao groupMembershipDao() {
- return groupMembershipDao;
- }
-
- public RoleDao roleDao() {
- return roleDao;
- }
-
- public PermissionTemplateDao permissionTemplateDao() {
- return permissionTemplateDao;
- }
-
- public ActionPlanDao actionPlanDao() {
- return actionPlanDao;
- }
-
- public AnalysisReportDao analysisReportDao() {
- return analysisReportDao;
- }
-
- public DashboardDao dashboardDao() {
- return dashboardDao;
- }
-
- public WidgetDao widgetDao() {
- return widgetDao;
- }
-
- public WidgetPropertyDao widgetPropertyDao() {
- return widgetPropertyDao;
- }
-
- public FileSourceDao fileSourceDao() {
- return fileSourceDao;
- }
-
- public AuthorDao authorDao() {
- return authorDao;
- }
-
- public ResourceIndexerDao componentIndexDao() {
- return componentIndexDao;
- }
-
- public ComponentLinkDao componentLinkDao() {
- return componentLinkDao;
- }
-
- public EventDao eventDao() {
- return eventDao;
- }
-
- public PurgeDao purgeDao() {
- return purgeDao;
- }
-
- public QualityGateConditionDao gateConditionDao() {
- return gateConditionDao;
- }
-
- private <K> K getDao(Map<Class, Dao> map, Class<K> clazz) {
- return (K) map.get(clazz);
- }
-
- /**
- * Create a PreparedStatement for SELECT requests with scrolling of results
- */
- public final PreparedStatement newScrollingSelectStatement(Connection connection, String sql) {
- int fetchSize = database().getDialect().getScrollDefaultFetchSize();
- return newScrollingSelectStatement(connection, sql, fetchSize);
+ public MetricDao metricDao() {
+ return metricDao;
}
- /**
- * Create a PreparedStatement for SELECT requests with scrolling of results row by row (only one row
- * in memory at a time)
- */
- public final PreparedStatement newScrollingSingleRowSelectStatement(Connection connection, String sql) {
- int fetchSize = database().getDialect().getScrollSingleRowFetchSize();
- return newScrollingSelectStatement(connection, sql, fetchSize);
+ public RuleDao ruleDao() {
+ return ruleDao;
}
- private PreparedStatement newScrollingSelectStatement(Connection connection, String sql, int fetchSize) {
- try {
- PreparedStatement stmt = connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
- stmt.setFetchSize(fetchSize);
- return stmt;
- } catch (SQLException e) {
- throw new IllegalStateException("Fail to create SQL statement: " + sql, e);
- }
+ public UserDao userDao() {
+ return userDao;
}
}
package org.sonar.server.db.migrations;
import com.google.common.annotations.VisibleForTesting;
+import java.sql.Connection;
import org.apache.commons.dbutils.DbUtils;
import org.apache.ibatis.session.SqlSession;
import org.picocontainer.Startable;
-import org.sonar.api.server.ServerSide;
import org.sonar.api.platform.ServerUpgradeStatus;
+import org.sonar.api.server.ServerSide;
import org.sonar.api.utils.log.Loggers;
+import org.sonar.db.DbClient;
import org.sonar.db.DdlUtils;
-import org.sonar.server.db.DbClient;
import org.sonar.server.plugins.ServerPluginRepository;
-import java.sql.Connection;
-
/**
* Restore schema by executing DDL scripts. Only H2 database is supported.
* Other databases are created by Ruby on Rails migrations.
*/
@VisibleForTesting
boolean createDatabase() {
- if (DdlUtils.supportsDialect(dbClient.database().getDialect().getId()) && serverUpgradeStatus.isFreshInstall()) {
+ if (DdlUtils.supportsDialect(dbClient.getDatabase().getDialect().getId()) && serverUpgradeStatus.isFreshInstall()) {
Loggers.get(getClass()).info("Create database");
SqlSession session = dbClient.openSession(false);
Connection connection = null;
try {
connection = session.getConnection();
- createSchema(connection, dbClient.database().getDialect().getId());
+ createSchema(connection, dbClient.getDatabase().getDialect().getId());
return true;
} finally {
session.close();
import org.sonar.core.rule.SeverityUtil;
import org.sonar.server.activity.Activity;
import org.sonar.db.activity.ActivityDao;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.db.migrations.MigrationStep;
import org.sonar.server.qualityprofile.ActiveRuleChange;
import org.sonar.db.version.v44.Migration44Mapper;
import org.sonar.db.version.v44.ProfileMeasure;
import org.sonar.db.version.v44.QProfileDto44;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.db.migrations.MigrationStep;
/**
import org.sonar.db.DbSession;
import org.sonar.db.version.v44.Migration44Mapper;
import org.sonar.db.version.v44.QProfileDto44;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.db.migrations.MigrationStep;
/**
import org.sonar.db.DbSession;
import org.sonar.db.version.v44.Migration44Mapper;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.db.migrations.MigrationStep;
import org.sonar.server.db.migrations.v44.ConvertProfileMeasuresMigrationStep;
import org.sonar.db.version.v45.Migration45Mapper;
import org.sonar.db.version.v45.Rule;
import org.sonar.db.version.v45.RuleParameter;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.db.migrations.MigrationStep;
import org.sonar.core.util.ProgressLogger;
import org.sonar.db.DbSession;
import org.sonar.db.version.v50.Component;
import org.sonar.db.version.v50.Migration50Mapper;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.db.migrations.MigrationStep;
import org.sonar.core.util.ProgressLogger;
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
import org.sonar.server.component.db.ComponentDao;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.db.measure.MeasureDao;
import org.sonar.server.user.UserSession;
import org.sonar.core.issue.IssueUpdater;
import org.sonar.db.issue.IssueChangeDto;
import org.sonar.db.DbSession;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.db.DbSession;
import org.sonar.core.rule.RuleKeyFunctions;
+import org.sonar.db.DbSession;
+import org.sonar.db.component.ComponentDto;
import org.sonar.server.component.ComponentService;
import org.sonar.server.db.DbClient;
import org.sonar.server.issue.filter.IssueFilterParameters;
import org.sonar.db.MyBatis;
import org.sonar.db.issue.IssueChangeDto;
import org.sonar.db.issue.IssueChangeMapper;
+import org.sonar.server.db.DbClient;
import static com.google.common.collect.Lists.newArrayList;
*/
public abstract class IssueStorage {
- private final MyBatis mybatis;
private final RuleFinder ruleFinder;
+ private final DbClient dbClient;
- protected IssueStorage(MyBatis mybatis, RuleFinder ruleFinder) {
- this.mybatis = mybatis;
+ protected IssueStorage(DbClient dbClient, RuleFinder ruleFinder) {
+ this.dbClient = dbClient;
this.ruleFinder = ruleFinder;
}
+ protected DbClient getDbClient() {
+ return dbClient;
+ }
+
public void save(DefaultIssue issue) {
save(newArrayList(issue));
}
}
public void save(Iterable<DefaultIssue> issues) {
- DbSession session = mybatis.openSession(true);
+ DbSession session = dbClient.openSession(true);
try {
doSave(session, issues);
} finally {
private void update(List<DefaultIssue> toBeUpdated, long now) {
if (!toBeUpdated.isEmpty()) {
- DbSession session = mybatis.openSession(false);
+ DbSession session = dbClient.openSession(false);
try {
IssueChangeMapper issueChangeMapper = session.getMapper(IssueChangeMapper.class);
for (DefaultIssue issue : toBeUpdated) {
*/
package org.sonar.server.issue;
+import org.sonar.api.rules.RuleFinder;
import org.sonar.api.server.ServerSide;
import org.sonar.core.issue.DefaultIssue;
-import org.sonar.api.rules.RuleFinder;
+import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.issue.IssueDto;
-import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
import org.sonar.server.db.DbClient;
import org.sonar.server.issue.index.IssueIndexer;
@ServerSide
public class ServerIssueStorage extends IssueStorage {
- private final DbClient dbClient;
private final IssueIndexer indexer;
- public ServerIssueStorage(MyBatis mybatis, RuleFinder ruleFinder, DbClient dbClient, IssueIndexer indexer) {
- super(mybatis, ruleFinder);
- this.dbClient = dbClient;
+ public ServerIssueStorage(RuleFinder ruleFinder, DbClient dbClient, IssueIndexer indexer) {
+ super(dbClient, ruleFinder);
this.indexer = indexer;
}
int ruleId = rule(issue).getId();
IssueDto dto = IssueDto.toDtoForServerInsert(issue, component, project, ruleId, now);
- dbClient.issueDao().insert(session, dto);
+ getDbClient().issueDao().insert(session, dto);
}
@Override
protected void doUpdate(DbSession session, long now, DefaultIssue issue) {
IssueDto dto = IssueDto.toDtoForUpdate(issue, now);
- dbClient.issueDao().update(session, dto);
+ getDbClient().issueDao().update(session, dto);
}
@Override
}
protected ComponentDto component(DbSession session, DefaultIssue issue) {
- return dbClient.componentDao().selectByKey(session, issue.componentKey());
+ return getDbClient().componentDao().selectByKey(session, issue.componentKey());
}
protected ComponentDto project(DbSession session, DefaultIssue issue) {
- return dbClient.componentDao().selectByKey(session, issue.projectKey());
+ return getDbClient().componentDao().selectByKey(session, issue.projectKey());
}
}
import org.sonar.db.issue.ActionPlanStatsDao;
import org.sonar.db.issue.ActionPlanStatsDto;
import org.sonar.db.issue.IssueDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.issue.IssueStorage;
import org.sonar.server.user.UserSession;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-import org.apache.commons.dbutils.DbUtils;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.server.db.DbClient;
-
-import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import org.apache.commons.dbutils.DbUtils;
+import org.apache.commons.lang.StringUtils;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
/**
* No streaming because of union of joins -> no need to use ResultSetIterator
" AND group_roles.group_id IS NULL " +
" ) project_authorization";
- Collection<Dto> selectAfterDate(DbClient dbClient, Connection connection, long afterDate) {
+ Collection<Dto> selectAfterDate(DbClient dbClient, DbSession session, long afterDate) {
try {
Map<String, Dto> dtosByProjectUuid = Maps.newHashMap();
PreparedStatement stmt = null;
ResultSet rs = null;
try {
- stmt = createStatement(dbClient, connection, afterDate);
+ stmt = createStatement(dbClient, session, afterDate);
rs = stmt.executeQuery();
while (rs.next()) {
processRow(rs, dtosByProjectUuid);
}
}
- private PreparedStatement createStatement(DbClient dbClient, Connection connection, long afterDate) throws SQLException {
+ private PreparedStatement createStatement(DbClient dbClient, DbSession session, long afterDate) throws SQLException {
String sql;
if (afterDate > 0L) {
sql = StringUtils.replace(SQL_TEMPLATE, "{dateCondition}", " AND projects.authorization_updated_at>? ");
} else {
sql = StringUtils.replace(SQL_TEMPLATE, "{dateCondition}", "");
}
- PreparedStatement stmt = dbClient.newScrollingSelectStatement(connection, sql);
+ PreparedStatement stmt = dbClient.getMyBatis().newScrollingSelectStatement(session, sql);
if (afterDate > 0L) {
for (int i = 1; i <= 4; i++) {
stmt.setLong(i, afterDate);
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.update.UpdateRequest;
import org.sonar.db.DbSession;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.es.BaseIndexer;
import org.sonar.server.es.BulkIndexer;
import org.sonar.server.es.EsClient;
final BulkIndexer bulk = new BulkIndexer(esClient, IssueIndexDefinition.INDEX);
DbSession dbSession = dbClient.openSession(false);
- Connection dbConnection = dbSession.getConnection();
try {
IssueAuthorizationDao dao = new IssueAuthorizationDao();
- Collection<IssueAuthorizationDao.Dto> authorizations = dao.selectAfterDate(dbClient, dbConnection, lastUpdatedAt);
+ Collection<IssueAuthorizationDao.Dto> authorizations = dao.selectAfterDate(dbClient, dbSession, lastUpdatedAt);
return doIndex(bulk, authorizations);
} finally {
- DbUtils.closeQuietly(dbConnection);
dbSession.close();
}
}
*/
package org.sonar.server.issue.index;
-import org.apache.commons.dbutils.DbUtils;
+import java.util.Iterator;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.index.query.FilterBuilders;
import org.elasticsearch.index.query.QueryBuilders;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.server.db.DbClient;
import org.sonar.server.es.BaseIndexer;
import org.sonar.server.es.BulkIndexer;
import org.sonar.server.es.EsClient;
-import java.sql.Connection;
-import java.util.Iterator;
-
public class IssueIndexer extends BaseIndexer {
private final DbClient dbClient;
private long doIndex(BulkIndexer bulk, long lastUpdatedAt) {
DbSession dbSession = dbClient.openSession(false);
- Connection dbConnection = dbSession.getConnection();
long maxDate;
try {
- IssueResultSetIterator rowIt = IssueResultSetIterator.create(dbClient, dbConnection, lastUpdatedAt);
+ IssueResultSetIterator rowIt = IssueResultSetIterator.create(dbClient, dbSession, lastUpdatedAt);
maxDate = doIndex(bulk, rowIt);
rowIt.close();
return maxDate;
-
} finally {
- DbUtils.closeQuietly(dbConnection);
dbSession.close();
}
}
.setQuery(QueryBuilders.filteredQuery(
QueryBuilders.matchAllQuery(),
FilterBuilders.boolFilter().must(FilterBuilders.termsFilter(IssueIndexDefinition.FIELD_ISSUE_PROJECT_UUID, uuid))
- ));
+ ));
bulk.addDeletion(search);
bulk.stop();
}
import org.apache.commons.lang.StringUtils;
import org.sonar.api.resources.Scopes;
import org.sonar.api.rule.RuleKey;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
import org.sonar.db.ResultSetIterator;
import org.sonar.server.db.migrations.SqlUtil;
super(stmt);
}
- static IssueResultSetIterator create(DbClient dbClient, Connection connection, long afterDate) {
+ static IssueResultSetIterator create(DbClient dbClient, DbSession session, long afterDate) {
try {
String sql = afterDate > 0L ? SQL_AFTER_DATE : SQL_ALL;
- PreparedStatement stmt = dbClient.newScrollingSelectStatement(connection, sql);
+ PreparedStatement stmt = dbClient.getMyBatis().newScrollingSelectStatement(session, sql);
if (afterDate > 0L) {
stmt.setLong(1, afterDate);
}
import org.sonar.core.issue.DefaultIssueComment;
import org.sonar.db.DbSession;
import org.sonar.server.component.ws.ComponentJsonWriter;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.es.Facets;
import org.sonar.server.es.SearchOptions;
import org.sonar.server.es.SearchResult;
import org.sonar.api.server.ServerSide;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
@Properties({
@Property(
import org.sonar.db.version.DatabaseVersion;
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
}
private BasicDataSource commonsDbcp() {
- return (BasicDataSource) dbClient.database().getDataSource();
+ return (BasicDataSource) dbClient.getDatabase().getDataSource();
}
private void completeDbAttributes(Map<String, Object> attributes) {
// Elasticsearch
EsSearchModule.class,
- // users
+ // DAOs to be moved to sonar-db
GroupDao.class,
UserDao.class,
+ RuleDao.class,
+ ActiveRuleDao.class,
+ MetricDao.class,
+ CustomMeasureDao.class,
+ ComponentDao.class,
// rules/qprofiles
RuleNormalizer.class,
ActiveRuleNormalizer.class,
RuleIndex.class,
ActiveRuleIndex.class,
- RuleDao.class,
- ActiveRuleDao.class,
// issues
- IssueIndex.class,
-
- // measures
- MetricDao.class,
- CustomMeasureDao.class,
-
- // components
- ComponentDao.class);
+ IssueIndex.class);
addAll(CorePropertyDefinitions.all());
add(MigrationStepModule.class);
addAll(DaoUtils.getDaoClasses());
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.db.DbSession;
import org.sonar.db.IsAliveMapper;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.db.migrations.DatabaseMigration;
import org.sonar.server.platform.Platform;
import org.sonar.api.utils.text.XmlWriter;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
import org.sonar.server.search.IndexClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.core.util.NonNullInputFunction;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import java.util.Collection;
import java.util.Map;
import org.sonar.api.utils.TempFolder;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import java.io.File;
import java.io.IOException;
package org.sonar.server.qualityprofile;
import com.google.common.collect.Lists;
+import java.util.Date;
+import java.util.List;
+import javax.annotation.CheckForNull;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.StringUtils;
-import org.sonar.api.server.ServerSide;
+import org.sonar.core.util.Slug;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.server.db.DbClient;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.Verifications;
-import org.sonar.core.util.Slug;
-
-import javax.annotation.CheckForNull;
-
-import java.util.Date;
-import java.util.List;
/**
* Create, delete, rename and set as default profile.
*/
-@ServerSide
public class QProfileFactory {
private final DbClient db;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
import org.sonar.server.rule.index.RuleIndex;
import org.sonar.server.rule.index.RuleQuery;
import org.sonar.api.server.ServerSide;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import static com.google.common.collect.Lists.newArrayList;
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.user.UserSession;
import com.google.common.collect.Lists;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.loadedtemplate.LoadedTemplateDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.platform.PersistentSettings;
import javax.annotation.Nullable;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.server.ws.WebService.NewAction;
import org.sonar.db.DbSession;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.plugins.MimeTypes;
import org.sonar.server.qualityprofile.QProfileBackuper;
import org.sonar.server.qualityprofile.QProfileFactory;
import org.sonar.api.server.ws.WebService.NewController;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.DbSession;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.qualityprofile.QProfileFactory;
import org.sonar.server.qualityprofile.RuleActivator;
import org.sonar.server.user.UserSession;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.qualityprofile.QProfileExporters;
import org.sonar.server.qualityprofile.QProfileFactory;
import org.sonar.server.qualityprofile.QProfileName;
import org.sonar.api.server.ws.WebService.NewController;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.DbSession;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.qualityprofile.QProfileFactory;
import org.sonar.server.user.UserSession;
import org.sonar.api.server.ws.WebService.NewAction;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.plugins.MimeTypes;
import org.sonar.server.qualityprofile.QProfileBackuper;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.qualityprofile.QProfile;
import org.sonar.server.qualityprofile.QProfileFactory;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ProjectQprofileAssociationDto;
import org.sonar.core.util.NonNullInputFunction;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.user.UserSession;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
-import org.sonar.api.server.ServerSide;
+import java.util.List;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
+import org.sonar.api.server.ServerSide;
import org.sonar.api.server.rule.RuleParamType;
import org.sonar.db.DbSession;
import org.sonar.db.rule.RuleDto;
import org.sonar.server.rule.index.RuleDoc;
import org.sonar.server.util.TypeValidations;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-import java.util.List;
-
import static com.google.common.collect.Lists.newArrayList;
@ServerSide
public static final IndexDefinition RULE = new IndexDefinition("rules", "rule");
public static final IndexDefinition ACTIVE_RULE = new IndexDefinition("rules", "activeRule");
- public static final IndexDefinition ISSUES = new IndexDefinition("issues", "issue");
// Only used for test
static final IndexDefinition TEST = new IndexDefinition("test", "test");
import java.util.List;
import javax.annotation.Nullable;
import org.elasticsearch.action.update.UpdateRequest;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
public class FileSourcesUpdaterHelper {
// only static stuff
}
- public static PreparedStatement preparedStatementToSelectFileSources(DbClient dbClient, Connection connection, String dataType, long afterDate, @Nullable String projectUuid)
+ public static PreparedStatement preparedStatementToSelectFileSources(DbClient dbClient, DbSession session, String dataType, long afterDate, @Nullable String projectUuid)
throws SQLException {
String sql = createSQL(dataType, afterDate, projectUuid);
// rows are big, so they are scrolled once at a time (one row in memory at a time)
- PreparedStatement stmt = dbClient.newScrollingSingleRowSelectStatement(connection, sql);
+ PreparedStatement stmt = dbClient.getMyBatis().newScrollingSingleRowSelectStatement(session, sql);
int index = 1;
if (afterDate > 0L) {
stmt.setLong(index, afterDate);
*/
package org.sonar.server.source.index;
+import java.util.Iterator;
+import javax.annotation.Nullable;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.index.query.FilterBuilders;
import org.elasticsearch.index.query.QueryBuilders;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.server.db.DbClient;
import org.sonar.server.es.BaseIndexer;
import org.sonar.server.es.BulkIndexer;
import org.sonar.server.es.EsClient;
-import javax.annotation.Nullable;
-
-import java.sql.Connection;
-import java.util.Iterator;
-
import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_FILE_UUID;
import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_PROJECT_UUID;
this.dbClient = dbClient;
}
- public void index(final String projectUuid){
+ public void index(final String projectUuid) {
super.index(new IndexerTask() {
@Override
public long index(long lastUpdatedAt) {
bulk.setLarge(lastUpdatedAt == 0L);
DbSession dbSession = dbClient.openSession(false);
- Connection dbConnection = dbSession.getConnection();
try {
- SourceLineResultSetIterator rowIt = SourceLineResultSetIterator.create(dbClient, dbConnection, lastUpdatedAt, projectUuid);
+ SourceLineResultSetIterator rowIt = SourceLineResultSetIterator.create(dbClient, dbSession, lastUpdatedAt, projectUuid);
long maxUpdatedAt = doIndex(bulk, rowIt);
rowIt.close();
return maxUpdatedAt;
.must(FilterBuilders.termFilter(FIELD_FILE_UUID, fileRow.getFileUuid()).cache(false))
.must(FilterBuilders.rangeFilter(SourceLineIndexDefinition.FIELD_LINE).gt(numberOfLines).cache(false))
.cache(false)
- ));
+ ));
bulk.addDeletion(searchRequest);
}
import org.elasticsearch.action.update.UpdateRequest;
import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.db.DbSession;
import org.sonar.db.source.FileSourceDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.db.ResultSetIterator;
import org.sonar.server.es.EsUtils;
import org.sonar.server.source.db.FileSourceDb;
*/
public class SourceLineResultSetIterator extends ResultSetIterator<FileSourcesUpdaterHelper.Row> {
- public static SourceLineResultSetIterator create(DbClient dbClient, Connection connection, long afterDate, @Nullable String projectUuid) {
+ public static SourceLineResultSetIterator create(DbClient dbClient, DbSession session, long afterDate, @Nullable String projectUuid) {
try {
- return new SourceLineResultSetIterator(FileSourcesUpdaterHelper.preparedStatementToSelectFileSources(dbClient, connection, FileSourceDto.Type.SOURCE, afterDate,
+ return new SourceLineResultSetIterator(FileSourcesUpdaterHelper.preparedStatementToSelectFileSources(dbClient, session, FileSourceDto.Type.SOURCE, afterDate,
projectUuid));
} catch (SQLException e) {
throw new IllegalStateException("Fail to prepare SQL request to select all file sources", e);
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.api.utils.log.Profiler;
-import org.sonar.db.metric.MetricDto;
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
+import org.sonar.db.metric.MetricDto;
import org.sonar.server.db.DbClient;
import static com.google.common.collect.FluentIterable.from;
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
import org.sonar.db.loadedtemplate.LoadedTemplateDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.issue.filter.RegisterIssueFilters;
import java.util.Date;
package org.sonar.server.test.index;
+import java.util.Iterator;
+import javax.annotation.Nullable;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.index.query.FilterBuilders;
import org.elasticsearch.index.query.QueryBuilders;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.server.db.DbClient;
import org.sonar.server.es.BaseIndexer;
import org.sonar.server.es.BulkIndexer;
import org.sonar.server.es.EsClient;
import org.sonar.server.source.index.FileSourcesUpdaterHelper;
-import javax.annotation.Nullable;
-import java.sql.Connection;
-import java.util.Iterator;
-
import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_PROJECT_UUID;
-import static org.sonar.server.test.index.TestIndexDefinition.*;
+import static org.sonar.server.test.index.TestIndexDefinition.FIELD_FILE_UUID;
+import static org.sonar.server.test.index.TestIndexDefinition.FIELD_UPDATED_AT;
+import static org.sonar.server.test.index.TestIndexDefinition.INDEX;
+import static org.sonar.server.test.index.TestIndexDefinition.TYPE;
/**
* Add to Elasticsearch index {@link TestIndexDefinition} the rows of
bulk.setLarge(lastUpdatedAt == 0L);
DbSession dbSession = dbClient.openSession(false);
- Connection dbConnection = dbSession.getConnection();
try {
- TestResultSetIterator rowIt = TestResultSetIterator.create(dbClient, dbConnection, lastUpdatedAt, projectUuid);
+ TestResultSetIterator rowIt = TestResultSetIterator.create(dbClient, dbSession, lastUpdatedAt, projectUuid);
long maxUpdatedAt = doIndex(bulk, rowIt);
rowIt.close();
return maxUpdatedAt;
import org.elasticsearch.action.update.UpdateRequest;
import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.db.DbSession;
import org.sonar.db.source.FileSourceDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.db.ResultSetIterator;
import org.sonar.server.source.db.FileSourceDb;
import org.sonar.server.source.index.FileSourcesUpdaterHelper;
*/
public class TestResultSetIterator extends ResultSetIterator<Row> {
- public static TestResultSetIterator create(DbClient dbClient, Connection connection, long afterDate, @Nullable String projectUuid) {
+ public static TestResultSetIterator create(DbClient dbClient, DbSession session, long afterDate, @Nullable String projectUuid) {
try {
- return new TestResultSetIterator(FileSourcesUpdaterHelper.preparedStatementToSelectFileSources(dbClient, connection, FileSourceDto.Type.TEST, afterDate, projectUuid));
+ return new TestResultSetIterator(FileSourcesUpdaterHelper.preparedStatementToSelectFileSources(dbClient, session, FileSourceDto.Type.TEST, afterDate, projectUuid));
} catch (SQLException e) {
throw new IllegalStateException("Fail to prepare SQL request to select all tests", e);
}
import org.sonar.core.platform.ComponentContainer;
import org.sonar.core.platform.PluginInfo;
import org.sonar.core.platform.PluginRepository;
-import org.sonar.db.component.ResourceIndexerDao;
+import org.sonar.db.component.ResourceIndexDao;
import org.sonar.core.timemachine.Periods;
import org.sonar.process.ProcessProperties;
import org.sonar.server.component.ComponentCleanerService;
}
public void indexProjects() {
- get(ResourceIndexerDao.class).indexProjects();
+ get(ResourceIndexDao.class).indexProjects();
}
public void indexResource(long resourceId) {
- get(ResourceIndexerDao.class).indexResource(resourceId);
+ get(ResourceIndexDao.class).indexResource(resourceId);
}
/*
package org.sonar.server.user.index;
-import java.sql.Connection;
import java.util.Iterator;
-import org.apache.commons.dbutils.DbUtils;
import org.elasticsearch.action.update.UpdateRequest;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.server.db.DbClient;
import org.sonar.server.es.BaseIndexer;
import org.sonar.server.es.BulkIndexer;
import org.sonar.server.es.EsClient;
bulk.setLarge(lastUpdatedAt == 0L);
DbSession dbSession = dbClient.openSession(false);
- Connection dbConnection = dbSession.getConnection();
try {
- UserResultSetIterator rowIt = UserResultSetIterator.create(dbClient, dbConnection, lastUpdatedAt);
+ UserResultSetIterator rowIt = UserResultSetIterator.create(dbClient, dbSession, lastUpdatedAt);
long maxUpdatedAt = doIndex(bulk, rowIt);
rowIt.close();
return maxUpdatedAt;
-
} finally {
- DbUtils.closeQuietly(dbConnection);
dbSession.close();
}
}
import com.google.common.collect.Maps;
import org.apache.commons.lang.StringUtils;
+import org.sonar.db.DbSession;
import org.sonar.db.user.UserDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.db.ResultSetIterator;
import java.sql.Connection;
private static final String SQL_AFTER_DATE = SQL_ALL + " where u.updated_at>?";
- static UserResultSetIterator create(DbClient dbClient, Connection connection, long afterDate) {
+ static UserResultSetIterator create(DbClient dbClient, DbSession session, long afterDate) {
try {
String sql = afterDate > 0L ? SQL_AFTER_DATE : SQL_ALL;
- PreparedStatement stmt = dbClient.newScrollingSelectStatement(connection, sql);
+ PreparedStatement stmt = dbClient.getMyBatis().newScrollingSelectStatement(session, sql);
if (afterDate > 0L) {
stmt.setLong(1, afterDate);
}
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.user.UserSession;
import org.sonar.server.user.UserUpdater;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.es.SearchOptions;
import org.sonar.server.es.SearchResult;
import org.sonar.server.user.index.UserDoc;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
-import org.sonar.server.db.DbClient;
+import org.sonar.db.DbClient;
import org.sonar.server.user.UpdateUser;
import org.sonar.server.user.UserSession;
import org.sonar.server.user.UserUpdater;
import org.apache.commons.dbutils.DbUtils;
import org.assertj.core.data.MapEntry;
import org.elasticsearch.action.update.UpdateRequest;
+import org.jruby.RubyProcess;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.sonar.api.utils.DateUtils;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.server.db.DbClient;
import org.sonar.test.DbTests;
public class ActivityResultSetIteratorTest {
@ClassRule
- public static DbTester dbTester = new DbTester();
-
- DbClient client;
- Connection connection;
+ public static DbTester dbTester = DbTester.create(System2.INSTANCE);
@Before
public void setUp() throws Exception {
dbTester.truncateTables();
- client = new DbClient(dbTester.database(), dbTester.myBatis());
- connection = dbTester.openConnection();
- }
-
- @After
- public void tearDown() {
- DbUtils.closeQuietly(connection);
}
/**
@Test
public void traverse() {
dbTester.prepareDbUnit(getClass(), "traverse.xml");
- ActivityResultSetIterator it = ActivityResultSetIterator.create(client, connection, 0L);
+ ActivityResultSetIterator it = ActivityResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L);
assertThat(it.hasNext()).isTrue();
UpdateRequest request = it.next();
@Test
public void traverse_after_date() {
dbTester.prepareDbUnit(getClass(), "traverse.xml");
- ActivityResultSetIterator it = ActivityResultSetIterator.create(client, connection, DateUtils.parseDate("2014-12-01").getTime());
+ ActivityResultSetIterator it = ActivityResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), DateUtils.parseDate("2014-12-01").getTime());
assertThat(it.hasNext()).isTrue();
UpdateRequest request = it.next();
@Test
public void nothing_to_traverse() {
dbTester.prepareDbUnit(getClass(), "traverse.xml");
- ActivityResultSetIterator it = ActivityResultSetIterator.create(client, connection, DateUtils.parseDate("2030-01-01").getTime());
+ ActivityResultSetIterator it = ActivityResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), DateUtils.parseDate("2030-01-01").getTime());
assertThat(it.hasNext()).isFalse();
it.close();
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
-import org.sonar.db.component.ResourceIndexerDao;
+import org.sonar.db.component.ResourceIndexDao;
import org.sonar.db.component.ResourceKeyUpdaterDao;
import org.sonar.server.component.db.ComponentDao;
import org.sonar.server.db.DbClient;
when(i18n.message(Locale.getDefault(), "qualifier.TRK", "Project")).thenReturn("Project");
- service = new ComponentService(dbClient, new ResourceKeyUpdaterDao(dbTester.myBatis()), i18n, new ResourceIndexerDao(dbTester.myBatis(), mock(System2.class)),
+ service = new ComponentService(dbClient, new ResourceKeyUpdaterDao(dbTester.myBatis()), i18n, new ResourceIndexDao(dbTester.myBatis(), mock(System2.class)),
userSessionRule, System2.INSTANCE);
}
import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
import org.sonar.db.DbTester;
-import org.sonar.db.component.ResourceIndexerDao;
+import org.sonar.db.component.ResourceIndexDao;
import org.sonar.db.user.AuthorizationDao;
import org.sonar.server.component.db.ComponentDao;
import org.sonar.server.db.DbClient;
public void setUp() {
dbTester.truncateTables();
DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis(),
- new ComponentDao(), new AuthorizationDao(dbTester.myBatis()), new ResourceIndexerDao(dbTester.myBatis(), mock(System2.class))
+ new ComponentDao(), new AuthorizationDao(dbTester.myBatis()), new ResourceIndexDao(dbTester.myBatis(), mock(System2.class))
);
tester = new WsTester(new ComponentsWs(mock(AppAction.class), new SearchAction(dbClient, userSessionRule)));
}
import java.io.IOException;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.db.component.ResourceIndexerDao;
+import org.sonar.db.component.ResourceIndexDao;
import org.sonar.server.computation.batch.BatchReportReaderRule;
import org.sonar.server.computation.batch.TreeRootHolderRule;
import org.sonar.server.computation.component.Component;
@Rule
public BatchReportReaderRule reportReader = new BatchReportReaderRule();
- ResourceIndexerDao resourceIndexerDao = mock(ResourceIndexerDao.class);
+ ResourceIndexDao resourceIndexDao = mock(ResourceIndexDao.class);
DbIdsRepository dbIdsRepository = new DbIdsRepository();
- IndexComponentsStep sut = new IndexComponentsStep(resourceIndexerDao, dbIdsRepository, treeRootHolder);
+ IndexComponentsStep sut = new IndexComponentsStep(resourceIndexDao, dbIdsRepository, treeRootHolder);
@Test
public void call_indexProject_of_dao() throws IOException {
sut.execute();
- verify(resourceIndexerDao).indexProject(123L);
+ verify(resourceIndexDao).indexProject(123L);
}
@Override
import org.junit.Test;
import org.sonar.api.config.Settings;
import org.sonar.db.DbTester;
+import org.sonar.db.source.FileSourceDao;
import org.sonar.server.computation.batch.TreeRootHolderRule;
import org.sonar.server.computation.component.Component;
import org.sonar.server.computation.component.DumbComponent;
import org.sonar.server.db.DbClient;
import org.sonar.server.es.EsTester;
-import org.sonar.db.source.FileSourceDao;
-import org.sonar.server.source.db.FileSourceTesting;
+import org.sonar.server.source.index.FileSourceTesting;
import org.sonar.server.source.index.SourceLineDoc;
import org.sonar.server.source.index.SourceLineIndexDefinition;
import org.sonar.server.source.index.SourceLineIndexer;
@Test
public void index_source() throws Exception {
dbTester.prepareDbUnit(getClass(), "index_source.xml");
- Connection connection = dbTester.openConnection();
- FileSourceTesting.updateDataColumn(connection, "FILE1_UUID", FileSourceTesting.newRandomData(1).build());
- connection.close();
+ try (Connection connection = dbTester.openConnection()) {
+ FileSourceTesting.updateDataColumn(connection, "FILE1_UUID", FileSourceTesting.newRandomData(1).build());
+ }
treeRootHolder.setRoot(DumbComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey("PROJECT_KEY").build());
package org.sonar.server.computation.step;
-import java.sql.Connection;
import java.util.List;
import org.elasticsearch.search.SearchHit;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.Settings;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
+import org.sonar.db.source.FileSourceDao;
import org.sonar.server.computation.batch.TreeRootHolderRule;
import org.sonar.server.computation.component.Component;
import org.sonar.server.computation.component.DumbComponent;
import org.sonar.server.db.DbClient;
import org.sonar.server.es.EsTester;
-import org.sonar.db.source.FileSourceDao;
import org.sonar.server.test.db.TestTesting;
import org.sonar.server.test.index.TestDoc;
import org.sonar.server.test.index.TestIndexDefinition;
public class IndexTestsStepTest extends BaseStepTest {
@ClassRule
- public static DbTester dbTester = new DbTester();
+ public static DbTester dbTester = DbTester.create(System2.INSTANCE);
@ClassRule
public static EsTester esTester = new EsTester().addDefinitions(new TestIndexDefinition(new Settings()));
@Test
public void index_test() throws Exception {
dbTester.prepareDbUnit(getClass(), "index_source.xml");
- Connection connection = dbTester.openConnection();
- TestTesting.updateDataColumn(connection, "FILE1_UUID", TestTesting.newRandomTests(1));
- connection.close();
+ TestTesting.updateDataColumn(dbTester.getSession(), "FILE1_UUID", TestTesting.newRandomTests(1));
treeRootHolder.setRoot(DumbComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey("PROJECT_KEY").build());
public DbTester db = new DbTester();
@Test
- public void facade() throws Exception {
+ public void get_daos() throws Exception {
MyBatis myBatis = db.myBatis();
RuleDao ruleDao = new RuleDao(System2.INSTANCE);
QualityProfileDao qualityProfileDao = new QualityProfileDao(myBatis, System2.INSTANCE);
DbClient client = new DbClient(db.database(), myBatis, ruleDao, activeRuleDao, qualityProfileDao);
- assertThat(client.database()).isSameAs(db.database());
+ assertThat(client.getDatabase()).isSameAs(db.database());
DbSession dbSession = client.openSession(true);
assertThat(dbSession).isNotNull();
assertThat(dbSession.getConnection().isClosed()).isFalse();
@Test
public void should_support_only_creation_of_h2_database() {
- when(dbClient.database().getDialect()).thenReturn(new MySql());
+ when(dbClient.getDatabase().getDialect()).thenReturn(new MySql());
assertThat(migrator.createDatabase()).isFalse();
verify(dbClient, never()).openSession(anyBoolean());
@Test
public void should_create_schema_on_h2() {
Dialect supportedDialect = new H2();
- when(dbClient.database().getDialect()).thenReturn(supportedDialect);
+ when(dbClient.getDatabase().getDialect()).thenReturn(supportedDialect);
Connection connection = mock(Connection.class);
DbSession session = mock(DbSession.class);
when(session.getConnection()).thenReturn(connection);
package org.sonar.server.db.migrations.v44;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.sonar.db.DbTester;
import org.sonar.server.db.DbClient;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.Statement;
-
import static org.assertj.core.api.Assertions.assertThat;
public class ConvertProfileMeasuresMigrationTest {
migration.execute();
- Connection connection = db.openConnection();
- Statement stmt = connection.createStatement();
- ResultSet rs = stmt.executeQuery("select * from project_measures where id=2");
- try {
- // measure is deleted
- assertThat(rs.next()).isFalse();
- } finally {
- rs.close();
- stmt.close();
- connection.close();
+ try (Connection connection = db.openConnection()) {
+ Statement stmt = connection.createStatement();
+ ResultSet rs = stmt.executeQuery("select * from project_measures where id=2");
+ try {
+ // measure is deleted
+ assertThat(rs.next()).isFalse();
+ } finally {
+ rs.close();
+ stmt.close();
+ }
}
}
}
import org.sonar.core.issue.IssueChangeContext;
import org.sonar.db.AbstractDaoTestCase;
import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.issue.IssueDto;
import org.sonar.db.issue.IssueMapper;
+import org.sonar.server.db.DbClient;
public class IssueStorageTest extends AbstractDaoTestCase {
@Test
public void batch_insert_new_issues() {
- FakeBatchSaver saver = new FakeBatchSaver(getMyBatis(), new FakeRuleFinder());
+ DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis());
+ FakeBatchSaver saver = new FakeBatchSaver(dbClient, new FakeRuleFinder());
DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
// override generated key
@Test
public void batch_insert_new_issues_with_session() {
- FakeBatchSaver saver = new FakeBatchSaver(getMyBatis(), new FakeRuleFinder());
+ DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis());
+ FakeBatchSaver saver = new FakeBatchSaver(dbClient, new FakeRuleFinder());
DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
// override generated key
public void server_insert_new_issues_with_session() {
ComponentDto project = new ComponentDto().setId(10L).setUuid("uuid-10");
ComponentDto component = new ComponentDto().setId(100L).setUuid("uuid-100");
- FakeServerSaver saver = new FakeServerSaver(getMyBatis(), new FakeRuleFinder(), component, project);
+ DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis());
+ FakeServerSaver saver = new FakeServerSaver(dbClient, new FakeRuleFinder(), component, project);
DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
// override generated key
public void batch_update_issues() {
setupData("should_update_issues");
- FakeBatchSaver saver = new FakeBatchSaver(getMyBatis(), new FakeRuleFinder());
+ DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis());
+ FakeBatchSaver saver = new FakeBatchSaver(dbClient, new FakeRuleFinder());
DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
// override generated key
ComponentDto project = new ComponentDto().setId(10L).setUuid("whatever-uuid");
ComponentDto component = new ComponentDto().setId(100L).setUuid("whatever-uuid-2");
- FakeServerSaver saver = new FakeServerSaver(getMyBatis(), new FakeRuleFinder(), component, project);
+ DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis());
+ FakeServerSaver saver = new FakeServerSaver(dbClient, new FakeRuleFinder(), component, project);
DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
// override generated key
static class FakeBatchSaver extends IssueStorage {
- protected FakeBatchSaver(MyBatis mybatis, RuleFinder ruleFinder) {
- super(mybatis, ruleFinder);
+ protected FakeBatchSaver(DbClient dbClient, RuleFinder ruleFinder) {
+ super(dbClient, ruleFinder);
}
@Override
private final ComponentDto component;
private final ComponentDto project;
- protected FakeServerSaver(MyBatis mybatis, RuleFinder ruleFinder, ComponentDto component, ComponentDto project) {
- super(mybatis, ruleFinder);
+ protected FakeServerSaver(DbClient dbClient, RuleFinder ruleFinder, ComponentDto component, ComponentDto project) {
+ super(dbClient, ruleFinder);
this.component = component;
this.project = project;
}
public class ServerIssueStorageTest extends AbstractDaoTestCase {
DbClient dbClient;
- DbSession session;
ServerIssueStorage storage;
public void setupDbClient() {
System2 system = mock(System2.class);
when(system.now()).thenReturn(2000000000L);
- dbClient = new DbClient(getDatabase(), getMyBatis(),
+ dbClient = new DbClient(dbTester.database(), getMyBatis(),
new ComponentDao(),
new IssueDao(getMyBatis()),
new ResourceDao(getMyBatis(), system));
- session = dbClient.openSession(false);
- storage = new ServerIssueStorage(getMyBatis(), new FakeRuleFinder(), dbClient, mock(IssueIndexer.class));
- }
-
- @After
- public void tearDown() {
- session.close();
+ storage = new ServerIssueStorage(new FakeRuleFinder(), dbClient, mock(IssueIndexer.class));
}
@Test
public void load_component_id_from_db() {
setupData("load_component_id_from_db");
- session.commit();
- long componentId = storage.component(session, new DefaultIssue().setComponentKey("struts:Action")).getId();
+ long componentId = storage.component(dbTester.getSession(), new DefaultIssue().setComponentKey("struts:Action")).getId();
assertThat(componentId).isEqualTo(100);
}
@Test
public void load_project_id_from_db() {
setupData("load_project_id_from_db");
- session.commit();
- long projectId = storage.project(session, new DefaultIssue().setProjectKey("struts")).getId();
+ long projectId = storage.project(dbTester.getSession(), new DefaultIssue().setProjectKey("struts")).getId();
assertThat(projectId).isEqualTo(1);
}
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
-import org.apache.commons.dbutils.DbUtils;
-import org.junit.After;
+import java.util.Collection;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
-import org.sonar.server.db.DbClient;
import org.sonar.test.DbTests;
-import java.sql.Connection;
-import java.util.Collection;
-
import static org.assertj.core.api.Assertions.assertThat;
@Category(DbTests.class)
public class IssueAuthorizationDaoTest {
@ClassRule
- public static DbTester dbTester = new DbTester();
+ public static DbTester dbTester = DbTester.create(System2.INSTANCE);
IssueAuthorizationDao dao = new IssueAuthorizationDao();
- DbClient client;
- Connection connection;
@Before
public void setUp() throws Exception {
dbTester.truncateTables();
- client = new DbClient(dbTester.database(), dbTester.myBatis());
- connection = dbTester.openConnection();
- }
-
- @After
- public void tearDown() {
- DbUtils.closeQuietly(connection);
}
@Test
public void select_all() {
dbTester.prepareDbUnit(getClass(), "shared.xml");
- Collection<IssueAuthorizationDao.Dto> dtos = dao.selectAfterDate(client, connection, 0L);
+ Collection<IssueAuthorizationDao.Dto> dtos = dao.selectAfterDate(dbTester.getDbClient(), dbTester.getSession(), 0L);
assertThat(dtos).hasSize(2);
IssueAuthorizationDao.Dto abc = Iterables.find(dtos, new ProjectPredicate("ABC"));
public void select_after_date() {
dbTester.prepareDbUnit(getClass(), "shared.xml");
- Collection<IssueAuthorizationDao.Dto> dtos = dao.selectAfterDate(client, connection, 1500000000L);
+ Collection<IssueAuthorizationDao.Dto> dtos = dao.selectAfterDate(dbTester.getDbClient(), dbTester.getSession(), 1500000000L);
// only project DEF was updated in this period
assertThat(dtos).hasSize(1);
public void no_authorization() {
dbTester.prepareDbUnit(getClass(), "no_authorization.xml");
- Collection<IssueAuthorizationDao.Dto> dtos = dao.selectAfterDate(client, connection, 0L);
+ Collection<IssueAuthorizationDao.Dto> dtos = dao.selectAfterDate(dbTester.getDbClient(), dbTester.getSession(), 0L);
assertThat(dtos).hasSize(1);
IssueAuthorizationDao.Dto abc = Iterables.find(dtos, new ProjectPredicate("ABC"));
import com.google.common.base.Function;
import com.google.common.collect.Maps;
import org.apache.commons.dbutils.DbUtils;
+import org.jruby.RubyProcess;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.sonar.api.rule.RuleKey;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.server.db.DbClient;
import org.sonar.test.DbTests;
public class IssueResultSetIteratorTest {
@ClassRule
- public static DbTester dbTester = new DbTester();
+ public static DbTester dbTester = DbTester.create(System2.INSTANCE);
- DbClient client;
- Connection connection;
@Before
public void setUp() throws Exception {
dbTester.truncateTables();
- client = new DbClient(dbTester.database(), dbTester.myBatis());
- connection = dbTester.openConnection();
- }
-
- @After
- public void tearDown() {
- DbUtils.closeQuietly(connection);
}
@Test
public void iterator_over_one_issue() {
dbTester.prepareDbUnit(getClass(), "one_issue.xml");
- IssueResultSetIterator it = IssueResultSetIterator.create(client, connection, 0L);
+ IssueResultSetIterator it = IssueResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L);
Map<String, IssueDoc> issuesByKey = issuesByKey(it);
it.close();
@Test
public void iterator_over_issues() {
dbTester.prepareDbUnit(getClass(), "shared.xml");
- IssueResultSetIterator it = IssueResultSetIterator.create(client, connection, 0L);
+ IssueResultSetIterator it = IssueResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L);
Map<String, IssueDoc> issuesByKey = issuesByKey(it);
it.close();
@Test
public void extract_directory_path() {
dbTester.prepareDbUnit(getClass(), "extract_directory_path.xml");
- IssueResultSetIterator it = IssueResultSetIterator.create(client, connection, 0L);
+ IssueResultSetIterator it = IssueResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L);
Map<String, IssueDoc> issuesByKey = issuesByKey(it);
it.close();
@Test
public void extract_file_path() {
dbTester.prepareDbUnit(getClass(), "extract_file_path.xml");
- IssueResultSetIterator it = IssueResultSetIterator.create(client, connection, 0L);
+ IssueResultSetIterator it = IssueResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L);
Map<String, IssueDoc> issuesByKey = issuesByKey(it);
it.close();
@Test
public void select_after_date() {
dbTester.prepareDbUnit(getClass(), "shared.xml");
- IssueResultSetIterator it = IssueResultSetIterator.create(client, connection, 1420000000000L);
+ IssueResultSetIterator it = IssueResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 1_420_000_000_000L);
assertThat(it.hasNext()).isTrue();
IssueDoc issue = it.next();
when(system.now()).thenReturn(DATE1.getTime());
RuleDao ruleDao = new RuleDao(system);
ActiveRuleDao activeRuleDao = new ActiveRuleDao(new QualityProfileDao(getMyBatis(), system), ruleDao, system);
- dbClient = new DbClient(getDatabase(), getMyBatis(), ruleDao, activeRuleDao,
+ dbClient = new DbClient(dbTester.database(), getMyBatis(), ruleDao, activeRuleDao,
new QualityProfileDao(getMyBatis(), system), new CharacteristicDao(getMyBatis()));
dbSession = dbClient.openSession(false);
}
+++ /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 java.io.IOException;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.Arrays;
-import org.apache.commons.lang.RandomStringUtils;
-import org.apache.commons.lang.math.RandomUtils;
-import org.sonar.db.source.FileSourceDto;
-
-public class FileSourceTesting {
-
- private FileSourceTesting() {
- // only static stuff
- }
-
- public static void updateDataColumn(Connection connection, String fileUuid, FileSourceDb.Data data) throws SQLException {
- updateDataColumn(connection, fileUuid, FileSourceDto.encodeSourceData(data));
- }
-
- public static void updateDataColumn(Connection connection, String fileUuid, byte[] data) throws SQLException {
- PreparedStatement stmt = connection.prepareStatement("UPDATE file_sources SET binary_data = ? WHERE file_uuid=? AND data_type='" + FileSourceDto.Type.SOURCE + "'");
- stmt.setBytes(1, data);
- stmt.setString(2, fileUuid);
- stmt.executeUpdate();
- stmt.close();
- }
-
- /**
- * Generate predefined fake data. Result is mutable.
- */
- public static FileSourceDb.Data.Builder newFakeData(int numberOfLines) throws IOException {
- FileSourceDb.Data.Builder dataBuilder = FileSourceDb.Data.newBuilder();
- for (int i = 1; i <= numberOfLines; i++) {
- dataBuilder.addLinesBuilder()
- .setLine(i)
- .setScmRevision("REVISION_" + i)
- .setScmAuthor("AUTHOR_" + i)
- .setScmDate(1_500_000_000_00L + i)
- .setSource("SOURCE_" + i)
- .setUtLineHits(i)
- .setUtConditions(i + 1)
- .setUtCoveredConditions(i + 2)
- .setItLineHits(i + 3)
- .setItConditions(i + 4)
- .setItCoveredConditions(i + 5)
- .setOverallLineHits(i + 6)
- .setOverallConditions(i + 7)
- .setOverallCoveredConditions(i + 8)
- .setHighlighting("HIGHLIGHTING_" + i)
- .setSymbols("SYMBOLS_" + i)
- .addAllDuplication(Arrays.asList(i))
- .build();
- }
- return dataBuilder;
- }
-
- /**
- * Generate random data. Result is mutable.
- */
- public static FileSourceDb.Data.Builder newRandomData(int numberOfLines) throws IOException {
- FileSourceDb.Data.Builder dataBuilder = FileSourceDb.Data.newBuilder();
- for (int i = 1; i <= numberOfLines; i++) {
- dataBuilder.addLinesBuilder()
- .setLine(i)
- .setScmRevision(RandomStringUtils.randomAlphanumeric(15))
- .setScmAuthor(RandomStringUtils.randomAlphanumeric(10))
- .setScmDate(RandomUtils.nextLong())
- .setSource(RandomStringUtils.randomAlphanumeric(20))
- .setUtLineHits(RandomUtils.nextInt(4))
- .setUtConditions(RandomUtils.nextInt(4))
- .setUtCoveredConditions(RandomUtils.nextInt(4))
- .setItLineHits(RandomUtils.nextInt(4))
- .setItConditions(RandomUtils.nextInt(4))
- .setItCoveredConditions(RandomUtils.nextInt(4))
- .setOverallLineHits(RandomUtils.nextInt(4))
- .setOverallConditions(RandomUtils.nextInt(4))
- .setOverallCoveredConditions(RandomUtils.nextInt(4))
- .setHighlighting(RandomStringUtils.randomAlphanumeric(40))
- .setSymbols(RandomStringUtils.randomAlphanumeric(30))
- .addAllDuplication(Arrays.asList(RandomUtils.nextInt(200), RandomUtils.nextInt(200)))
- .build();
- }
- return dataBuilder;
- }
-}
--- /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.index;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.Arrays;
+import org.apache.commons.lang.RandomStringUtils;
+import org.apache.commons.lang.math.RandomUtils;
+import org.sonar.db.source.FileSourceDto;
+import org.sonar.server.source.db.FileSourceDb;
+
+public class FileSourceTesting {
+
+ private FileSourceTesting() {
+ // only static stuff
+ }
+
+ public static void updateDataColumn(Connection connection, String fileUuid, FileSourceDb.Data data) throws SQLException {
+ updateDataColumn(connection, fileUuid, FileSourceDto.encodeSourceData(data));
+ }
+
+ public static void updateDataColumn(Connection connection, String fileUuid, byte[] data) throws SQLException {
+ PreparedStatement stmt = connection.prepareStatement("UPDATE file_sources SET binary_data = ? WHERE file_uuid=? AND data_type='" + FileSourceDto.Type.SOURCE + "'");
+ stmt.setBytes(1, data);
+ stmt.setString(2, fileUuid);
+ stmt.executeUpdate();
+ stmt.close();
+ connection.commit();
+ }
+
+ /**
+ * Generate predefined fake data. Result is mutable.
+ */
+ public static FileSourceDb.Data.Builder newFakeData(int numberOfLines) throws IOException {
+ FileSourceDb.Data.Builder dataBuilder = FileSourceDb.Data.newBuilder();
+ for (int i = 1; i <= numberOfLines; i++) {
+ dataBuilder.addLinesBuilder()
+ .setLine(i)
+ .setScmRevision("REVISION_" + i)
+ .setScmAuthor("AUTHOR_" + i)
+ .setScmDate(1_500_000_000_00L + i)
+ .setSource("SOURCE_" + i)
+ .setUtLineHits(i)
+ .setUtConditions(i + 1)
+ .setUtCoveredConditions(i + 2)
+ .setItLineHits(i + 3)
+ .setItConditions(i + 4)
+ .setItCoveredConditions(i + 5)
+ .setOverallLineHits(i + 6)
+ .setOverallConditions(i + 7)
+ .setOverallCoveredConditions(i + 8)
+ .setHighlighting("HIGHLIGHTING_" + i)
+ .setSymbols("SYMBOLS_" + i)
+ .addAllDuplication(Arrays.asList(i))
+ .build();
+ }
+ return dataBuilder;
+ }
+
+ /**
+ * Generate random data. Result is mutable.
+ */
+ public static FileSourceDb.Data.Builder newRandomData(int numberOfLines) throws IOException {
+ FileSourceDb.Data.Builder dataBuilder = FileSourceDb.Data.newBuilder();
+ for (int i = 1; i <= numberOfLines; i++) {
+ dataBuilder.addLinesBuilder()
+ .setLine(i)
+ .setScmRevision(RandomStringUtils.randomAlphanumeric(15))
+ .setScmAuthor(RandomStringUtils.randomAlphanumeric(10))
+ .setScmDate(RandomUtils.nextLong())
+ .setSource(RandomStringUtils.randomAlphanumeric(20))
+ .setUtLineHits(RandomUtils.nextInt(4))
+ .setUtConditions(RandomUtils.nextInt(4))
+ .setUtCoveredConditions(RandomUtils.nextInt(4))
+ .setItLineHits(RandomUtils.nextInt(4))
+ .setItConditions(RandomUtils.nextInt(4))
+ .setItCoveredConditions(RandomUtils.nextInt(4))
+ .setOverallLineHits(RandomUtils.nextInt(4))
+ .setOverallConditions(RandomUtils.nextInt(4))
+ .setOverallCoveredConditions(RandomUtils.nextInt(4))
+ .setHighlighting(RandomStringUtils.randomAlphanumeric(40))
+ .setSymbols(RandomStringUtils.randomAlphanumeric(30))
+ .addAllDuplication(Arrays.asList(RandomUtils.nextInt(200), RandomUtils.nextInt(200)))
+ .build();
+ }
+ return dataBuilder;
+ }
+}
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterators;
+import java.io.IOException;
+import java.sql.Connection;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.sonar.server.db.DbClient;
import org.sonar.server.es.EsTester;
import org.sonar.server.source.db.FileSourceDb;
-import org.sonar.server.source.db.FileSourceTesting;
import org.sonar.test.DbTests;
import org.sonar.test.TestUtils;
-import java.io.IOException;
-import java.sql.Connection;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_DUPLICATIONS;
public void index_source_lines() throws Exception {
db.prepareDbUnit(getClass(), "db.xml");
- Connection connection = db.openConnection();
- FileSourceTesting.updateDataColumn(connection, "FILE_UUID", FileSourceTesting.newRandomData(3).build());
- connection.close();
+ try (Connection connection = db.openConnection()) {
+ FileSourceTesting.updateDataColumn(connection, "FILE_UUID", FileSourceTesting.newRandomData(3).build());
+ }
indexer.index();
assertThat(countDocuments()).isEqualTo(3);
public void index_source_lines_from_project() throws Exception {
db.prepareDbUnit(getClass(), "db.xml");
- Connection connection = db.openConnection();
- FileSourceTesting.updateDataColumn(connection, "FILE_UUID", FileSourceTesting.newRandomData(3).build());
- connection.close();
+ try (Connection connection = db.openConnection()) {
+ FileSourceTesting.updateDataColumn(connection, "FILE_UUID", FileSourceTesting.newRandomData(3).build());
+ }
indexer.index("PROJECT_UUID");
assertThat(countDocuments()).isEqualTo(3);
public void index_nothing_from_unknown_project() throws Exception {
db.prepareDbUnit(getClass(), "db.xml");
- Connection connection = db.openConnection();
- FileSourceTesting.updateDataColumn(connection, "FILE_UUID", FileSourceTesting.newRandomData(3).build());
- connection.close();
+ try (Connection connection = db.openConnection()) {
+ FileSourceTesting.updateDataColumn(connection, "FILE_UUID", FileSourceTesting.newRandomData(3).build());
+ }
indexer.index("UNKNOWN");
assertThat(countDocuments()).isZero();
*/
package org.sonar.server.source.index;
+import java.sql.Connection;
+import java.util.Map;
import org.assertj.core.data.MapEntry;
import org.elasticsearch.action.update.UpdateRequest;
-import org.junit.After;
-import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
-import org.sonar.server.db.DbClient;
import org.sonar.server.source.db.FileSourceDb;
-import org.sonar.server.source.db.FileSourceTesting;
import org.sonar.test.DbTests;
-import java.sql.Connection;
-import java.util.Map;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public class SourceLineResultSetIteratorTest {
@ClassRule
- public static DbTester db = DbTester.createForSchema(System2.INSTANCE, SourceLineResultSetIteratorTest.class, "schema.sql");
-
- DbClient dbClient;
-
- Connection connection;
+ public static DbTester db = DbTester.create(System2.INSTANCE);
SourceLineResultSetIterator iterator;
- @Before
- public void setUp() throws Exception {
- dbClient = new DbClient(db.database(), db.myBatis());
- connection = db.openConnection();
- }
-
- @After
public void after() throws Exception {
if (iterator != null) {
iterator.close();
}
- connection.close();
}
@Test
public void traverse_db() throws Exception {
db.prepareDbUnit(getClass(), "shared.xml");
- FileSourceTesting.updateDataColumn(connection, "F1", FileSourceTesting.newFakeData(3).build());
+ try (Connection connection = db.openConnection()) {
+ FileSourceTesting.updateDataColumn(connection, "F1", FileSourceTesting.newFakeData(3).build());
+ }
- iterator = SourceLineResultSetIterator.create(dbClient, connection, 0L, null);
+ iterator = SourceLineResultSetIterator.create(db.getDbClient(), db.getSession(), 0L, null);
assertThat(iterator.hasNext()).isTrue();
FileSourcesUpdaterHelper.Row row = iterator.next();
assertThat(row.getProjectUuid()).isEqualTo("P1");
MapEntry.entry(SourceLineIndexDefinition.FIELD_OVERALL_LINE_HITS, 7),
MapEntry.entry(SourceLineIndexDefinition.FIELD_OVERALL_CONDITIONS, 8),
MapEntry.entry(SourceLineIndexDefinition.FIELD_OVERALL_COVERED_CONDITIONS, 9)
- );
+ );
}
/**
db.prepareDbUnit(getClass(), "shared.xml");
FileSourceDb.Data.Builder dataBuilder = FileSourceDb.Data.newBuilder();
dataBuilder.addLinesBuilder().setLine(1).build();
- FileSourceTesting.updateDataColumn(connection, "F1", dataBuilder.build());
+ try (Connection connection = db.openConnection()) {
+ FileSourceTesting.updateDataColumn(connection, "F1", dataBuilder.build());
+ }
- iterator = SourceLineResultSetIterator.create(dbClient, connection, 0L, null);
+ iterator = SourceLineResultSetIterator.create(db.getDbClient(), db.getSession(), 0L, null);
FileSourcesUpdaterHelper.Row row = iterator.next();
assertThat(row.getProjectUuid()).isEqualTo("P1");
assertThat(row.getFileUuid()).isEqualTo("F1");
MapEntry.entry(SourceLineIndexDefinition.FIELD_PROJECT_UUID, "P1"),
MapEntry.entry(SourceLineIndexDefinition.FIELD_FILE_UUID, "F1"),
MapEntry.entry(SourceLineIndexDefinition.FIELD_LINE, 1)
- );
+ );
// null values
assertThat(doc).containsKeys(
SourceLineIndexDefinition.FIELD_SCM_REVISION,
SourceLineIndexDefinition.FIELD_OVERALL_LINE_HITS,
SourceLineIndexDefinition.FIELD_OVERALL_CONDITIONS,
SourceLineIndexDefinition.FIELD_OVERALL_COVERED_CONDITIONS
- );
+ );
}
@Test
public void filter_by_date() {
db.prepareDbUnit(getClass(), "shared.xml");
- iterator = SourceLineResultSetIterator.create(dbClient, connection, 2000000000000L, null);
+ iterator = SourceLineResultSetIterator.create(db.getDbClient(), db.getSession(), 2000000000000L, null);
assertThat(iterator.hasNext()).isFalse();
}
db.prepareDbUnit(getClass(), "filter_by_project.xml");
FileSourceDb.Data.Builder dataBuilder = FileSourceDb.Data.newBuilder();
dataBuilder.addLinesBuilder().setLine(1).build();
- FileSourceTesting.updateDataColumn(connection, "F1", dataBuilder.build());
+ try (Connection connection = db.openConnection()) {
+ FileSourceTesting.updateDataColumn(connection, "F1", dataBuilder.build());
+ }
- iterator = SourceLineResultSetIterator.create(dbClient, connection, 0L, "P1");
+ iterator = SourceLineResultSetIterator.create(db.getDbClient(), db.getSession(), 0L, "P1");
FileSourcesUpdaterHelper.Row row = iterator.next();
assertThat(row.getProjectUuid()).isEqualTo("P1");
db.prepareDbUnit(getClass(), "filter_by_project_and_date.xml");
FileSourceDb.Data.Builder dataBuilder = FileSourceDb.Data.newBuilder();
dataBuilder.addLinesBuilder().setLine(1).build();
- FileSourceTesting.updateDataColumn(connection, "F1", dataBuilder.build());
+ try (Connection connection = db.openConnection()) {
+ FileSourceTesting.updateDataColumn(connection, "F1", dataBuilder.build());
+ }
- iterator = SourceLineResultSetIterator.create(dbClient, connection, 1400000000000L, "P1");
+ iterator = SourceLineResultSetIterator.create(db.getDbClient(), db.getSession(), 1400000000000L, "P1");
FileSourcesUpdaterHelper.Row row = iterator.next();
assertThat(row.getProjectUuid()).isEqualTo("P1");
public void fail_on_bad_data_format() throws Exception {
db.prepareDbUnit(getClass(), "shared.xml");
- FileSourceTesting.updateDataColumn(connection, "F1", "THIS_IS_NOT_PROTOBUF".getBytes());
+ try (Connection connection = db.openConnection()) {
+ FileSourceTesting.updateDataColumn(connection, "F1", "THIS_IS_NOT_PROTOBUF".getBytes());
+ }
- iterator = SourceLineResultSetIterator.create(dbClient, connection, 0L, null);
+ iterator = SourceLineResultSetIterator.create(db.getDbClient(), db.getSession(), 0L, null);
try {
assertThat(iterator.hasNext()).isTrue();
iterator.next();
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.math.RandomUtils;
import org.sonar.api.utils.internal.Uuids;
+import org.sonar.db.DbSession;
import org.sonar.db.source.FileSourceDto;
import org.sonar.server.source.db.FileSourceDb;
import org.sonar.server.source.db.FileSourceDb.Test.TestStatus;
// only static stuff
}
- public static void updateDataColumn(Connection connection, String fileUuid, List<FileSourceDb.Test> tests) throws SQLException {
- updateDataColumn(connection, fileUuid, FileSourceDto.encodeTestData(tests));
+ public static void updateDataColumn(DbSession session, String fileUuid, List<FileSourceDb.Test> tests) throws SQLException {
+ updateDataColumn(session, fileUuid, FileSourceDto.encodeTestData(tests));
}
- public static void updateDataColumn(Connection connection, String fileUuid, byte[] data) throws SQLException {
+ public static void updateDataColumn(DbSession session, String fileUuid, byte[] data) throws SQLException {
+ Connection connection = session.getConnection();
PreparedStatement stmt = connection.prepareStatement("UPDATE file_sources SET binary_data = ? WHERE file_uuid=? AND data_type='TEST'");
stmt.setBytes(1, data);
stmt.setString(2, fileUuid);
stmt.executeUpdate();
stmt.close();
+ connection.commit();
}
/**
package org.sonar.server.test.index;
import com.google.common.collect.Iterators;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.sonar.api.config.Settings;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.server.db.DbClient;
import org.sonar.server.es.EsTester;
import org.sonar.test.DbTests;
import org.sonar.test.TestUtils;
-import java.io.IOException;
-import java.sql.Connection;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.sonar.server.test.index.TestIndexDefinition.FIELD_DURATION_IN_MS;
public static EsTester es = new EsTester().addDefinitions(new TestIndexDefinition(new Settings()));
@ClassRule
- public static DbTester db = new DbTester();
+ public static DbTester db = DbTester.create(System2.INSTANCE);
private TestIndexer sut;
@Test
public void index_tests() throws Exception {
db.prepareDbUnit(getClass(), "db.xml");
- Connection connection = db.openConnection();
- TestTesting.updateDataColumn(connection, "FILE_UUID", TestTesting.newRandomTests(3));
- connection.close();
+ TestTesting.updateDataColumn(db.getSession(), "FILE_UUID", TestTesting.newRandomTests(3));
sut.index();
public void index_tests_from_project() throws Exception {
db.prepareDbUnit(getClass(), "db.xml");
- Connection connection = db.openConnection();
- TestTesting.updateDataColumn(connection, "FILE_UUID", TestTesting.newRandomTests(3));
- connection.close();
+ TestTesting.updateDataColumn(db.getSession(), "FILE_UUID", TestTesting.newRandomTests(3));
sut.index("PROJECT_UUID");
assertThat(countDocuments()).isEqualTo(3);
public void index_nothing_from_unknown_project() throws Exception {
db.prepareDbUnit(getClass(), "db.xml");
- Connection connection = db.openConnection();
- TestTesting.updateDataColumn(connection, "FILE_UUID", TestTesting.newRandomTests(3));
- connection.close();
+ TestTesting.updateDataColumn(db.getSession(), "FILE_UUID", TestTesting.newRandomTests(3));
sut.index("UNKNOWN");
assertThat(countDocuments()).isZero();
package org.sonar.server.test.index;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
import org.assertj.core.data.MapEntry;
import org.elasticsearch.action.update.UpdateRequest;
import org.junit.After;
-import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
-import org.sonar.server.db.DbClient;
import org.sonar.server.source.db.FileSourceDb;
import org.sonar.server.source.db.FileSourceDb.Test.TestStatus;
import org.sonar.server.source.index.FileSourcesUpdaterHelper;
-import org.sonar.server.source.index.SourceLineResultSetIteratorTest;
import org.sonar.server.test.db.TestTesting;
import org.sonar.test.DbTests;
-import java.sql.Connection;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
public class TestResultSetIteratorTest {
@ClassRule
- public static DbTester db = DbTester.createForSchema(System2.INSTANCE, SourceLineResultSetIteratorTest.class, "schema.sql");
-
- DbClient dbClient;
-
- Connection connection;
+ public static DbTester dbTester = DbTester.create(System2.INSTANCE);
TestResultSetIterator sut;
- @Before
- public void setUp() throws Exception {
- dbClient = new DbClient(db.database(), db.myBatis());
- connection = db.openConnection();
- }
-
@After
public void after() throws Exception {
if (sut != null) {
sut.close();
}
- connection.close();
}
@Test
public void traverse_db() throws Exception {
- db.prepareDbUnit(getClass(), "shared.xml");
- TestTesting.updateDataColumn(connection, "F1", newFakeTests(3));
- sut = TestResultSetIterator.create(dbClient, connection, 0L, null);
+ dbTester.prepareDbUnit(getClass(), "shared.xml");
+ TestTesting.updateDataColumn(dbTester.getSession(), "F1", newFakeTests(3));
+ sut = TestResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L, null);
FileSourcesUpdaterHelper.Row row = sut.next();
assertThat(row.getProjectUuid()).isEqualTo("P1");
*/
@Test
public void minimal_data() throws Exception {
- db.prepareDbUnit(getClass(), "shared.xml");
+ dbTester.prepareDbUnit(getClass(), "shared.xml");
List<FileSourceDb.Test> tests = Arrays.asList(
FileSourceDb.Test.newBuilder()
.setUuid("U1")
.setName("N1")
.build()
);
- TestTesting.updateDataColumn(connection, "F1", tests);
- sut = TestResultSetIterator.create(dbClient, connection, 0L, null);
+ TestTesting.updateDataColumn(dbTester.getSession(), "F1", tests);
+ sut = TestResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L, null);
FileSourcesUpdaterHelper.Row row = sut.next();
@Test
public void filter_by_date() {
- db.prepareDbUnit(getClass(), "shared.xml");
- sut = TestResultSetIterator.create(dbClient, connection, 2000000000000L, null);
+ dbTester.prepareDbUnit(getClass(), "shared.xml");
+ sut = TestResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 2000000000000L, null);
assertThat(sut.hasNext()).isFalse();
}
@Test
public void filter_by_project() throws Exception {
- db.prepareDbUnit(getClass(), "filter_by_project.xml");
- TestTesting.updateDataColumn(connection, "F1", newFakeTests(1));
+ dbTester.prepareDbUnit(getClass(), "filter_by_project.xml");
+ TestTesting.updateDataColumn(dbTester.getSession(), "F1", newFakeTests(1));
- sut = TestResultSetIterator.create(dbClient, connection, 0L, "P1");
+ sut = TestResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L, "P1");
FileSourcesUpdaterHelper.Row row = sut.next();
assertThat(row.getProjectUuid()).isEqualTo("P1");
@Test
public void filter_by_project_and_date() throws Exception {
- db.prepareDbUnit(getClass(), "filter_by_project_and_date.xml");
- TestTesting.updateDataColumn(connection, "F1", newFakeTests(1));
+ dbTester.prepareDbUnit(getClass(), "filter_by_project_and_date.xml");
+ TestTesting.updateDataColumn(dbTester.getSession(), "F1", newFakeTests(1));
- sut = TestResultSetIterator.create(dbClient, connection, 1400000000000L, "P1");
+ sut = TestResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 1400000000000L, "P1");
FileSourcesUpdaterHelper.Row row = sut.next();
assertThat(row.getProjectUuid()).isEqualTo("P1");
@Test
public void fail_on_bad_data_format() throws Exception {
- db.prepareDbUnit(getClass(), "shared.xml");
+ dbTester.prepareDbUnit(getClass(), "shared.xml");
- TestTesting.updateDataColumn(connection, "F1", "THIS_IS_NOT_PROTOBUF".getBytes());
+ TestTesting.updateDataColumn(dbTester.getSession(), "F1", "THIS_IS_NOT_PROTOBUF".getBytes());
- sut = TestResultSetIterator.create(dbClient, connection, 0L, null);
+ sut = TestResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L, null);
try {
assertThat(sut.hasNext()).isTrue();
sut.next();
import com.google.common.base.Function;
import com.google.common.collect.Maps;
-import org.apache.commons.dbutils.DbUtils;
-import org.junit.After;
+import java.util.Map;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
-import org.sonar.server.db.DbClient;
import org.sonar.test.DbTests;
-import java.sql.Connection;
-import java.util.Map;
-
import static org.assertj.core.api.Assertions.assertThat;
@Category(DbTests.class)
public class UserResultSetIteratorTest {
@ClassRule
- public static DbTester dbTester = new DbTester();
-
- DbClient client;
- Connection connection;
+ public static DbTester dbTester = DbTester.create(System2.INSTANCE);
@Before
public void setUp() throws Exception {
dbTester.truncateTables();
- client = new DbClient(dbTester.database(), dbTester.myBatis());
- connection = dbTester.openConnection();
- }
-
- @After
- public void tearDown() {
- DbUtils.closeQuietly(connection);
}
@Test
public void iterator_over_users() {
dbTester.prepareDbUnit(getClass(), "shared.xml");
- UserResultSetIterator it = UserResultSetIterator.create(client, connection, 0L);
+ UserResultSetIterator it = UserResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L);
Map<String, UserDoc> usersByLogin = Maps.uniqueIndex(it, new Function<UserDoc, String>() {
@Override
public String apply(UserDoc user) {
@Test
public void select_after_date() {
dbTester.prepareDbUnit(getClass(), "shared.xml");
- UserResultSetIterator it = UserResultSetIterator.create(client, connection, 1520000000000L);
+ UserResultSetIterator it = UserResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 1520000000000L);
assertThat(it.hasNext()).isTrue();
UserDoc user = it.next();
import org.sonar.db.activity.ActivityDao;
import org.sonar.db.component.ComponentLinkDao;
import org.sonar.db.component.ResourceDao;
-import org.sonar.db.component.ResourceIndexerDao;
+import org.sonar.db.component.ResourceIndexDao;
import org.sonar.db.component.ResourceKeyUpdaterDao;
import org.sonar.db.component.SnapshotDao;
import org.sonar.db.compute.AnalysisReportDao;
QualityProfileDao.class,
PurgeDao.class,
CharacteristicDao.class,
- ResourceIndexerDao.class,
+ ResourceIndexDao.class,
ResourceDao.class,
ResourceKeyUpdaterDao.class,
RoleDao.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;
+
+import java.util.IdentityHashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.sonar.db.activity.ActivityDao;
+import org.sonar.db.component.ComponentLinkDao;
+import org.sonar.db.component.ResourceDao;
+import org.sonar.db.component.ResourceIndexDao;
+import org.sonar.db.component.SnapshotDao;
+import org.sonar.db.compute.AnalysisReportDao;
+import org.sonar.db.dashboard.DashboardDao;
+import org.sonar.db.dashboard.WidgetDao;
+import org.sonar.db.dashboard.WidgetPropertyDao;
+import org.sonar.db.debt.CharacteristicDao;
+import org.sonar.db.event.EventDao;
+import org.sonar.db.issue.ActionPlanDao;
+import org.sonar.db.issue.ActionPlanStatsDao;
+import org.sonar.db.issue.IssueChangeDao;
+import org.sonar.db.issue.IssueDao;
+import org.sonar.db.issue.IssueFilterDao;
+import org.sonar.db.loadedtemplate.LoadedTemplateDao;
+import org.sonar.db.measure.MeasureDao;
+import org.sonar.db.permission.PermissionTemplateDao;
+import org.sonar.db.property.PropertiesDao;
+import org.sonar.db.purge.PurgeDao;
+import org.sonar.db.qualitygate.QualityGateConditionDao;
+import org.sonar.db.qualityprofile.QualityProfileDao;
+import org.sonar.db.source.FileSourceDao;
+import org.sonar.db.user.AuthorDao;
+import org.sonar.db.user.AuthorizationDao;
+import org.sonar.db.user.GroupMembershipDao;
+import org.sonar.db.user.RoleDao;
+import org.sonar.db.user.UserGroupDao;
+
+public class DbClient {
+
+ private final Database database;
+ private final MyBatis myBatis;
+ private final QualityProfileDao qualityProfileDao;
+ private final CharacteristicDao debtCharacteristicDao;
+ private final LoadedTemplateDao loadedTemplateDao;
+ private final PropertiesDao propertiesDao;
+ private final SnapshotDao snapshotDao;
+ private final ResourceDao resourceDao;
+ private final MeasureDao measureDao;
+ private final ActivityDao activityDao;
+ private final AuthorizationDao authorizationDao;
+ private final UserGroupDao userGroupDao;
+ private final GroupMembershipDao groupMembershipDao;
+ private final RoleDao roleDao;
+ private final PermissionTemplateDao permissionTemplateDao;
+ private final IssueDao issueDao;
+ private final IssueFilterDao issueFilterDao;
+ private final IssueChangeDao issueChangeDao;
+ private final ActionPlanDao actionPlanDao;
+ private final ActionPlanStatsDao actionPlanStatsDao;
+ private final AnalysisReportDao analysisReportDao;
+ private final DashboardDao dashboardDao;
+ private final WidgetDao widgetDao;
+ private final WidgetPropertyDao widgetPropertyDao;
+ private final FileSourceDao fileSourceDao;
+ private final AuthorDao authorDao;
+ private final ResourceIndexDao componentIndexDao;
+ private final ComponentLinkDao componentLinkDao;
+ private final EventDao eventDao;
+ private final PurgeDao purgeDao;
+ private final QualityGateConditionDao gateConditionDao;
+
+ public DbClient(Database database, MyBatis myBatis, Dao[] daos) {
+ this.database = database;
+ this.myBatis = myBatis;
+
+ Map<Class, Dao> map = new IdentityHashMap<>();
+ for (Dao dao : daos) {
+ map.put(dao.getClass(), dao);
+ }
+ debtCharacteristicDao = getDao(map, CharacteristicDao.class);
+ qualityProfileDao = getDao(map, QualityProfileDao.class);
+ loadedTemplateDao = getDao(map, LoadedTemplateDao.class);
+ propertiesDao = getDao(map, PropertiesDao.class);
+ snapshotDao = getDao(map, SnapshotDao.class);
+ resourceDao = getDao(map, ResourceDao.class);
+ measureDao = getDao(map, MeasureDao.class);
+ activityDao = getDao(map, ActivityDao.class);
+ authorizationDao = getDao(map, AuthorizationDao.class);
+ userGroupDao = getDao(map, UserGroupDao.class);
+ groupMembershipDao = getDao(map, GroupMembershipDao.class);
+ roleDao = getDao(map, RoleDao.class);
+ permissionTemplateDao = getDao(map, PermissionTemplateDao.class);
+ issueDao = getDao(map, IssueDao.class);
+ issueFilterDao = getDao(map, IssueFilterDao.class);
+ issueChangeDao = getDao(map, IssueChangeDao.class);
+ actionPlanDao = getDao(map, ActionPlanDao.class);
+ actionPlanStatsDao = getDao(map, ActionPlanStatsDao.class);
+ analysisReportDao = getDao(map, AnalysisReportDao.class);
+ dashboardDao = getDao(map, DashboardDao.class);
+ widgetDao = getDao(map, WidgetDao.class);
+ widgetPropertyDao = getDao(map, WidgetPropertyDao.class);
+ fileSourceDao = getDao(map, FileSourceDao.class);
+ authorDao = getDao(map, AuthorDao.class);
+ componentIndexDao = getDao(map, ResourceIndexDao.class);
+ componentLinkDao = getDao(map, ComponentLinkDao.class);
+ eventDao = getDao(map, EventDao.class);
+ purgeDao = getDao(map, PurgeDao.class);
+ gateConditionDao = getDao(map, QualityGateConditionDao.class);
+ doOnLoad(map);
+ }
+
+ // should be removed, but till used by sonar-server
+ protected void doOnLoad(Map<Class, Dao> daoByClass) {
+
+ }
+
+ public DbSession openSession(boolean batch) {
+ return myBatis.openSession(batch);
+ }
+
+ public void closeSession(@Nullable DbSession session) {
+ MyBatis.closeQuietly(session);
+ }
+
+ public Database getDatabase() {
+ return database;
+ }
+
+ public IssueDao issueDao() {
+ return issueDao;
+ }
+
+ public IssueFilterDao issueFilterDao() {
+ return issueFilterDao;
+ }
+
+ public IssueChangeDao issueChangeDao() {
+ return issueChangeDao;
+ }
+
+ public QualityProfileDao qualityProfileDao() {
+ return qualityProfileDao;
+ }
+
+ public CharacteristicDao debtCharacteristicDao() {
+ return debtCharacteristicDao;
+ }
+
+ public LoadedTemplateDao loadedTemplateDao() {
+ return loadedTemplateDao;
+ }
+
+ public PropertiesDao propertiesDao() {
+ return propertiesDao;
+ }
+
+ public SnapshotDao snapshotDao() {
+ return snapshotDao;
+ }
+
+ public ResourceDao resourceDao() {
+ return resourceDao;
+ }
+
+ public MeasureDao measureDao() {
+ return measureDao;
+ }
+
+ public ActivityDao activityDao() {
+ return activityDao;
+ }
+
+ public AuthorizationDao authorizationDao() {
+ return authorizationDao;
+ }
+
+ public UserGroupDao userGroupDao() {
+ return userGroupDao;
+ }
+
+ public GroupMembershipDao groupMembershipDao() {
+ return groupMembershipDao;
+ }
+
+ public RoleDao roleDao() {
+ return roleDao;
+ }
+
+ public PermissionTemplateDao permissionTemplateDao() {
+ return permissionTemplateDao;
+ }
+
+ public ActionPlanDao actionPlanDao() {
+ return actionPlanDao;
+ }
+
+ public AnalysisReportDao analysisReportDao() {
+ return analysisReportDao;
+ }
+
+ public DashboardDao dashboardDao() {
+ return dashboardDao;
+ }
+
+ public WidgetDao widgetDao() {
+ return widgetDao;
+ }
+
+ public WidgetPropertyDao widgetPropertyDao() {
+ return widgetPropertyDao;
+ }
+
+ public FileSourceDao fileSourceDao() {
+ return fileSourceDao;
+ }
+
+ public AuthorDao authorDao() {
+ return authorDao;
+ }
+
+ public ResourceIndexDao componentIndexDao() {
+ return componentIndexDao;
+ }
+
+ public ComponentLinkDao componentLinkDao() {
+ return componentLinkDao;
+ }
+
+ public EventDao eventDao() {
+ return eventDao;
+ }
+
+ public PurgeDao purgeDao() {
+ return purgeDao;
+ }
+
+ public ActionPlanStatsDao getActionPlanStatsDao() {
+ return actionPlanStatsDao;
+ }
+
+ public QualityGateConditionDao gateConditionDao() {
+ return gateConditionDao;
+ }
+
+ protected <K extends Dao> K getDao(Map<Class, Dao> map, Class<K> clazz) {
+ return (K) map.get(clazz);
+ }
+
+ // should be removed. Still used by some old DAO in sonar-server
+ public MyBatis getMyBatis() {
+ return myBatis;
+ }
+}
+++ /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.sonar.db.component.FilePathWithHashDto;
import org.sonar.db.component.ResourceDto;
import org.sonar.db.component.ResourceIndexDto;
-import org.sonar.db.component.ResourceIndexerMapper;
+import org.sonar.db.component.ResourceIndexMapper;
import org.sonar.db.component.ResourceKeyUpdaterMapper;
import org.sonar.db.component.ResourceMapper;
import org.sonar.db.component.SnapshotDto;
IssueMapper.class, IssueChangeMapper.class, IssueFilterMapper.class, IssueFilterFavouriteMapper.class,
IsAliveMapper.class,
LoadedTemplateMapper.class, MeasureFilterMapper.class, Migration44Mapper.class, PermissionTemplateMapper.class, PropertiesMapper.class, PurgeMapper.class,
- ResourceKeyUpdaterMapper.class, ResourceIndexerMapper.class, RoleMapper.class, RuleMapper.class,
+ ResourceKeyUpdaterMapper.class, ResourceIndexMapper.class, RoleMapper.class, RuleMapper.class,
SchemaMigrationMapper.class, SemaphoreMapper.class, UserMapper.class, GroupMapper.class, UserGroupMapper.class, WidgetMapper.class, WidgetPropertyMapper.class,
FileSourceMapper.class, ActionPlanMapper.class,
ActionPlanStatsMapper.class,
--- /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.commons.lang.StringUtils;
+import org.apache.ibatis.session.ResultContext;
+import org.apache.ibatis.session.ResultHandler;
+import org.apache.ibatis.session.SqlSession;
+import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.resources.Scopes;
+import org.sonar.api.utils.System2;
+import org.sonar.db.AbstractDao;
+import org.sonar.db.DbSession;
+import org.sonar.db.MyBatis;
+
+public class ResourceIndexDao extends AbstractDao {
+
+ private static final String SELECT_RESOURCES = "org.sonar.db.component.ResourceIndexMapper.selectResources";
+ public static final int MINIMUM_KEY_SIZE = 3;
+ public static final int SINGLE_INDEX_SIZE = 2;
+
+ // The scopes and qualifiers that are not in the following constants are not indexed at all.
+ // Directories and packages are explicitly excluded.
+ private static final String[] RENAMABLE_QUALIFIERS = {Qualifiers.PROJECT, Qualifiers.MODULE, Qualifiers.VIEW, Qualifiers.SUBVIEW};
+ private static final String[] RENAMABLE_SCOPES = {Scopes.PROJECT};
+ private static final String[] NOT_RENAMABLE_QUALIFIERS = {Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE, Qualifiers.CLASS};
+ private static final String[] NOT_RENAMABLE_SCOPES = {Scopes.FILE};
+
+ public ResourceIndexDao(MyBatis myBatis, System2 system2) {
+ super(myBatis, system2);
+ }
+
+ public List<Long> selectProjectIdsFromQueryAndViewOrSubViewUuid(DbSession session, String query, String viewOrSubViewUuid) {
+ return session.getMapper(ResourceIndexMapper.class).selectProjectIdsFromQueryAndViewOrSubViewUuid(query + "%", "%." + viewOrSubViewUuid + ".%");
+ }
+
+ /**
+ * This method is reentrant. It can be executed even if the project is already indexed.
+ */
+ public ResourceIndexDao indexProject(final long rootProjectId) {
+ DbSession session = myBatis().openSession(true);
+ try {
+ indexProject(rootProjectId, session);
+ session.commit();
+ return this;
+
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public void indexProject(final long rootProjectId, DbSession session) {
+ ResourceIndexMapper mapper = session.getMapper(ResourceIndexMapper.class);
+ doIndexProject(rootProjectId, session, mapper);
+ }
+
+ /**
+ * This method is reentrant. It can be executed even if some projects are already indexed.
+ */
+ public ResourceIndexDao indexProjects() {
+ final DbSession session = myBatis().openSession(true);
+ try {
+ final ResourceIndexMapper mapper = session.getMapper(ResourceIndexMapper.class);
+ session.select(ResourceIndexMapper.class.getName() + ".selectRootProjectIds", /* workaround to get booleans */ResourceIndexQuery.create(), new ResultHandler() {
+ @Override
+ public void handleResult(ResultContext context) {
+ Integer rootProjectId = (Integer) context.getResultObject();
+ doIndexProject(rootProjectId, session, mapper);
+ session.commit();
+ }
+ });
+ return this;
+
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ private void doIndexProject(long rootProjectId, SqlSession session, final ResourceIndexMapper mapper) {
+ // non indexed resources
+ ResourceIndexQuery query = ResourceIndexQuery.create()
+ .setNonIndexedOnly(true)
+ .setQualifiers(NOT_RENAMABLE_QUALIFIERS)
+ .setScopes(NOT_RENAMABLE_SCOPES)
+ .setRootProjectId(rootProjectId);
+
+ session.select(SELECT_RESOURCES, query, new ResultHandler() {
+ @Override
+ public void handleResult(ResultContext context) {
+ ResourceDto resource = (ResourceDto) context.getResultObject();
+ doIndex(resource, mapper);
+ }
+ });
+
+ // some resources can be renamed, so index must be regenerated
+ // -> delete existing rows and create them again
+ query = ResourceIndexQuery.create()
+ .setNonIndexedOnly(false)
+ .setQualifiers(RENAMABLE_QUALIFIERS)
+ .setScopes(RENAMABLE_SCOPES)
+ .setRootProjectId(rootProjectId);
+
+ session.select(SELECT_RESOURCES, query, new ResultHandler() {
+ @Override
+ public void handleResult(ResultContext context) {
+ ResourceDto resource = (ResourceDto) context.getResultObject();
+
+ mapper.deleteByResourceId(resource.getId());
+ doIndex(resource, mapper);
+ }
+ });
+ }
+
+ void doIndex(ResourceDto resource, ResourceIndexMapper mapper) {
+ String key = nameToKey(resource.getName());
+ if (key.length() >= MINIMUM_KEY_SIZE || key.length() == SINGLE_INDEX_SIZE) {
+ insertIndexEntries(key, resource.getId(), resource.getQualifier(), resource.getRootId(), resource.getName().length(), mapper);
+ }
+ }
+
+ public boolean indexResource(long id) {
+ DbSession session = myBatis().openSession(false);
+ try {
+ return indexResource(session, id);
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public boolean indexResource(DbSession session, long id) {
+ boolean indexed = false;
+ ResourceIndexMapper mapper = session.getMapper(ResourceIndexMapper.class);
+ ResourceDto resource = mapper.selectResourceToIndex(id);
+ if (resource != null) {
+ Long rootId = resource.getRootId();
+ if (rootId == null) {
+ rootId = resource.getId();
+ }
+ indexed = indexResource(resource.getId(), resource.getName(), resource.getQualifier(), rootId, session, mapper);
+ }
+ return indexed;
+ }
+
+ public boolean indexResource(int id, String name, String qualifier, int rootId) {
+ boolean indexed = false;
+ SqlSession session = myBatis().openSession(false);
+ ResourceIndexMapper mapper = session.getMapper(ResourceIndexMapper.class);
+ try {
+ indexed = indexResource(id, name, qualifier, rootId, session, mapper);
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ return indexed;
+ }
+
+ private boolean indexResource(long id, String name, String qualifier, long rootId, SqlSession session, ResourceIndexMapper mapper) {
+ boolean indexed = false;
+ String key = nameToKey(name);
+ if (key.length() >= MINIMUM_KEY_SIZE || key.length() == SINGLE_INDEX_SIZE) {
+ indexed = true;
+ boolean toBeIndexed = sanitizeIndex(id, key, mapper);
+ if (toBeIndexed) {
+ insertIndexEntries(key, id, qualifier, rootId, name.length(), mapper);
+ session.commit();
+ }
+ }
+ return indexed;
+ }
+
+ private void insertIndexEntries(String key, long resourceId, String qualifier, long rootId, int nameLength, ResourceIndexMapper mapper) {
+ ResourceIndexDto dto = new ResourceIndexDto()
+ .setResourceId(resourceId)
+ .setQualifier(qualifier)
+ .setRootProjectId(rootId)
+ .setNameSize(nameLength);
+
+ int maxPosition = key.length() == SINGLE_INDEX_SIZE ? 0 : key.length() - MINIMUM_KEY_SIZE;
+ for (int position = 0; position <= maxPosition; position++) {
+ dto.setPosition(position);
+ dto.setKey(StringUtils.substring(key, position));
+ mapper.insert(dto);
+ }
+ }
+
+ /**
+ * Return true if the resource must be indexed, false if the resource is already indexed.
+ * If the resource is indexed with a different key, then this index is dropped and the
+ * resource must be indexed again.
+ */
+ private boolean sanitizeIndex(long resourceId, String key, ResourceIndexMapper mapper) {
+ ResourceIndexDto masterIndex = mapper.selectMasterIndexByResourceId(resourceId);
+ if (masterIndex != null && !StringUtils.equals(key, masterIndex.getKey())) {
+ // resource has been renamed -> drop existing indexes
+ mapper.deleteByResourceId(resourceId);
+ masterIndex = null;
+ }
+ return masterIndex == null;
+ }
+
+ static String nameToKey(String input) {
+ return StringUtils.lowerCase(StringUtils.trimToEmpty(input));
+ }
+}
--- /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 ResourceIndexMapper {
+
+ List<Long> selectProjectIdsFromQueryAndViewOrSubViewUuid(@Param("query") String query, @Param("viewUuidQuery") String viewUuidQuery);
+
+ ResourceIndexDto selectMasterIndexByResourceId(long resourceId);
+
+ ResourceDto selectResourceToIndex(long resourceId);
+
+ void deleteByResourceId(long resourceId);
+
+ void insert(ResourceIndexDto dto);
+}
--- /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;
+
+final class ResourceIndexQuery {
+ private long rootProjectId;
+ private String[] scopes = null;
+ private String[] qualifiers = null;
+ private boolean nonIndexedOnly = false;
+
+ private ResourceIndexQuery() {
+ }
+
+ public static ResourceIndexQuery create() {
+ return new ResourceIndexQuery();
+ }
+
+ public String[] getScopes() {
+ return scopes;
+ }
+
+ public String[] getQualifiers() {
+ return qualifiers;
+ }
+
+ public ResourceIndexQuery setScopes(String[] scopes) {
+ this.scopes = scopes;
+ return this;
+ }
+
+ public ResourceIndexQuery setQualifiers(String[] qualifiers) {
+ this.qualifiers = qualifiers;
+ return this;
+ }
+
+ public long getRootProjectId() {
+ return rootProjectId;
+ }
+
+ public ResourceIndexQuery setRootProjectId(long i) {
+ this.rootProjectId = i;
+ return this;
+ }
+
+ public boolean isNonIndexedOnly() {
+ return nonIndexedOnly;
+ }
+
+ public ResourceIndexQuery setNonIndexedOnly(boolean b) {
+ this.nonIndexedOnly = b;
+ return this;
+ }
+}
+++ /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.commons.lang.StringUtils;
-import org.apache.ibatis.session.ResultContext;
-import org.apache.ibatis.session.ResultHandler;
-import org.apache.ibatis.session.SqlSession;
-import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.resources.Scopes;
-import org.sonar.api.utils.System2;
-import org.sonar.db.AbstractDao;
-import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
-
-public class ResourceIndexerDao extends AbstractDao {
-
- private static final String SELECT_RESOURCES = "org.sonar.db.component.ResourceIndexerMapper.selectResources";
- public static final int MINIMUM_KEY_SIZE = 3;
- public static final int SINGLE_INDEX_SIZE = 2;
-
- // The scopes and qualifiers that are not in the following constants are not indexed at all.
- // Directories and packages are explicitly excluded.
- private static final String[] RENAMABLE_QUALIFIERS = {Qualifiers.PROJECT, Qualifiers.MODULE, Qualifiers.VIEW, Qualifiers.SUBVIEW};
- private static final String[] RENAMABLE_SCOPES = {Scopes.PROJECT};
- private static final String[] NOT_RENAMABLE_QUALIFIERS = {Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE, Qualifiers.CLASS};
- private static final String[] NOT_RENAMABLE_SCOPES = {Scopes.FILE};
-
- public ResourceIndexerDao(MyBatis myBatis, System2 system2) {
- super(myBatis, system2);
- }
-
- public List<Long> selectProjectIdsFromQueryAndViewOrSubViewUuid(DbSession session, String query, String viewOrSubViewUuid) {
- return session.getMapper(ResourceIndexerMapper.class).selectProjectIdsFromQueryAndViewOrSubViewUuid(query + "%", "%." + viewOrSubViewUuid + ".%");
- }
-
- /**
- * This method is reentrant. It can be executed even if the project is already indexed.
- */
- public ResourceIndexerDao indexProject(final long rootProjectId) {
- DbSession session = myBatis().openSession(true);
- try {
- indexProject(rootProjectId, session);
- session.commit();
- return this;
-
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public void indexProject(final long rootProjectId, DbSession session) {
- ResourceIndexerMapper mapper = session.getMapper(ResourceIndexerMapper.class);
- doIndexProject(rootProjectId, session, mapper);
- }
-
- /**
- * This method is reentrant. It can be executed even if some projects are already indexed.
- */
- public ResourceIndexerDao indexProjects() {
- final DbSession session = myBatis().openSession(true);
- try {
- final ResourceIndexerMapper mapper = session.getMapper(ResourceIndexerMapper.class);
- session.select("org.sonar.db.component.ResourceIndexerMapper.selectRootProjectIds", /* workaround to get booleans */ResourceIndexerQuery.create(), new ResultHandler() {
- @Override
- public void handleResult(ResultContext context) {
- Integer rootProjectId = (Integer) context.getResultObject();
- doIndexProject(rootProjectId, session, mapper);
- session.commit();
- }
- });
- return this;
-
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- private void doIndexProject(long rootProjectId, SqlSession session, final ResourceIndexerMapper mapper) {
- // non indexed resources
- ResourceIndexerQuery query = ResourceIndexerQuery.create()
- .setNonIndexedOnly(true)
- .setQualifiers(NOT_RENAMABLE_QUALIFIERS)
- .setScopes(NOT_RENAMABLE_SCOPES)
- .setRootProjectId(rootProjectId);
-
- session.select(SELECT_RESOURCES, query, new ResultHandler() {
- @Override
- public void handleResult(ResultContext context) {
- ResourceDto resource = (ResourceDto) context.getResultObject();
- doIndex(resource, mapper);
- }
- });
-
- // some resources can be renamed, so index must be regenerated
- // -> delete existing rows and create them again
- query = ResourceIndexerQuery.create()
- .setNonIndexedOnly(false)
- .setQualifiers(RENAMABLE_QUALIFIERS)
- .setScopes(RENAMABLE_SCOPES)
- .setRootProjectId(rootProjectId);
-
- session.select(SELECT_RESOURCES, query, new ResultHandler() {
- @Override
- public void handleResult(ResultContext context) {
- ResourceDto resource = (ResourceDto) context.getResultObject();
-
- mapper.deleteByResourceId(resource.getId());
- doIndex(resource, mapper);
- }
- });
- }
-
- void doIndex(ResourceDto resource, ResourceIndexerMapper mapper) {
- String key = nameToKey(resource.getName());
- if (key.length() >= MINIMUM_KEY_SIZE || key.length() == SINGLE_INDEX_SIZE) {
- insertIndexEntries(key, resource.getId(), resource.getQualifier(), resource.getRootId(), resource.getName().length(), mapper);
- }
- }
-
- public boolean indexResource(long id) {
- DbSession session = myBatis().openSession(false);
- try {
- return indexResource(session, id);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public boolean indexResource(DbSession session, long id) {
- boolean indexed = false;
- ResourceIndexerMapper mapper = session.getMapper(ResourceIndexerMapper.class);
- ResourceDto resource = mapper.selectResourceToIndex(id);
- if (resource != null) {
- Long rootId = resource.getRootId();
- if (rootId == null) {
- rootId = resource.getId();
- }
- indexed = indexResource(resource.getId(), resource.getName(), resource.getQualifier(), rootId, session, mapper);
- }
- return indexed;
- }
-
- public boolean indexResource(int id, String name, String qualifier, int rootId) {
- boolean indexed = false;
- SqlSession session = myBatis().openSession(false);
- ResourceIndexerMapper mapper = session.getMapper(ResourceIndexerMapper.class);
- try {
- indexed = indexResource(id, name, qualifier, rootId, session, mapper);
- } finally {
- MyBatis.closeQuietly(session);
- }
- return indexed;
- }
-
- private boolean indexResource(long id, String name, String qualifier, long rootId, SqlSession session, ResourceIndexerMapper mapper) {
- boolean indexed = false;
- String key = nameToKey(name);
- if (key.length() >= MINIMUM_KEY_SIZE || key.length() == SINGLE_INDEX_SIZE) {
- indexed = true;
- boolean toBeIndexed = sanitizeIndex(id, key, mapper);
- if (toBeIndexed) {
- insertIndexEntries(key, id, qualifier, rootId, name.length(), mapper);
- session.commit();
- }
- }
- return indexed;
- }
-
- private void insertIndexEntries(String key, long resourceId, String qualifier, long rootId, int nameLength, ResourceIndexerMapper mapper) {
- ResourceIndexDto dto = new ResourceIndexDto()
- .setResourceId(resourceId)
- .setQualifier(qualifier)
- .setRootProjectId(rootId)
- .setNameSize(nameLength);
-
- int maxPosition = key.length() == SINGLE_INDEX_SIZE ? 0 : key.length() - MINIMUM_KEY_SIZE;
- for (int position = 0; position <= maxPosition; position++) {
- dto.setPosition(position);
- dto.setKey(StringUtils.substring(key, position));
- mapper.insert(dto);
- }
- }
-
- /**
- * Return true if the resource must be indexed, false if the resource is already indexed.
- * If the resource is indexed with a different key, then this index is dropped and the
- * resource must be indexed again.
- */
- private boolean sanitizeIndex(long resourceId, String key, ResourceIndexerMapper mapper) {
- ResourceIndexDto masterIndex = mapper.selectMasterIndexByResourceId(resourceId);
- if (masterIndex != null && !StringUtils.equals(key, masterIndex.getKey())) {
- // resource has been renamed -> drop existing indexes
- mapper.deleteByResourceId(resourceId);
- masterIndex = null;
- }
- return masterIndex == null;
- }
-
- static String nameToKey(String input) {
- return StringUtils.lowerCase(StringUtils.trimToEmpty(input));
- }
-}
+++ /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 ResourceIndexerMapper {
-
- List<Long> selectProjectIdsFromQueryAndViewOrSubViewUuid(@Param("query") String query, @Param("viewUuidQuery") String viewUuidQuery);
-
- ResourceIndexDto selectMasterIndexByResourceId(long resourceId);
-
- ResourceDto selectResourceToIndex(long resourceId);
-
- void deleteByResourceId(long resourceId);
-
- void insert(ResourceIndexDto dto);
-}
+++ /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;
-
-final class ResourceIndexerQuery {
- private long rootProjectId;
- private String[] scopes = null;
- private String[] qualifiers = null;
- private boolean nonIndexedOnly = false;
-
- private ResourceIndexerQuery() {
- }
-
- public static ResourceIndexerQuery create() {
- return new ResourceIndexerQuery();
- }
-
- public String[] getScopes() {
- return scopes;
- }
-
- public String[] getQualifiers() {
- return qualifiers;
- }
-
- public ResourceIndexerQuery setScopes(String[] scopes) {
- this.scopes = scopes;
- return this;
- }
-
- public ResourceIndexerQuery setQualifiers(String[] qualifiers) {
- this.qualifiers = qualifiers;
- return this;
- }
-
- public long getRootProjectId() {
- return rootProjectId;
- }
-
- public ResourceIndexerQuery setRootProjectId(long i) {
- this.rootProjectId = i;
- return this;
- }
-
- public boolean isNonIndexedOnly() {
- return nonIndexedOnly;
- }
-
- public ResourceIndexerQuery setNonIndexedOnly(boolean b) {
- this.nonIndexedOnly = b;
- return this;
- }
-}
--- /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.ResourceIndexMapper">
+
+ <select id="selectProjectIdsFromQueryAndViewOrSubViewUuid" parameterType="map" resultType="long">
+ SELECT r.resource_id FROM resource_index r
+ INNER JOIN projects copy ON copy.copy_resource_id = r.resource_id
+ <where>
+ AND copy.module_uuid_path LIKE #{viewUuidQuery}
+ AND r.kee LIKE #{query}
+ </where>
+ ORDER BY r.name_size
+ </select>
+
+ <!--
+ The column PROJECTS.ROOT_ID is not exact on multi-modules projects. The root id must
+ be loaded from the table SNAPSHOTS
+ -->
+ <select id="selectResources" parameterType="map" resultType="Resource">
+ select p.name as "name", p.id as "id", p.scope as "scope", p.qualifier as "qualifier", s.root_project_id as "rootId"
+ from projects p, snapshots s
+ <where>
+ p.enabled=${_true}
+ and p.copy_resource_id is null
+ and p.id=s.project_id
+ and s.islast=${_true}
+ <if test="scopes != null">
+ and p.scope in
+ <foreach item="scope" index="index" collection="scopes" open="(" separator="," close=")">#{scope}</foreach>
+ </if>
+ <if test="qualifiers != null">
+ and p.qualifier in
+ <foreach item="qualifier" index="index" collection="qualifiers" open="(" separator="," close=")">#{qualifier}
+ </foreach>
+ </if>
+ <if test="rootProjectId != null">
+ and s.root_project_id=#{rootProjectId}
+ </if>
+ <if test="nonIndexedOnly">
+ and not exists(select * from resource_index ri where ri.resource_id=p.id)
+ </if>
+ </where>
+ order by p.id
+ </select>
+
+ <select id="selectRootProjectIds" parameterType="map" resultType="int">
+ select distinct root_project_id
+ from snapshots
+ where islast=${_true}
+ and scope='PRJ'
+ and qualifier in ('TRK', 'VW', 'SVW')
+ </select>
+
+ <select id="selectMasterIndexByResourceId" parameterType="long" resultType="ResourceIndex">
+ select kee as "key", resource_id as "resourceId"
+ from resource_index
+ where resource_id=#{id} and position=0
+ </select>
+
+ <select id="selectResourceToIndex" parameterType="long" resultType="Resource">
+ select id, name, root_id as "rootId", qualifier
+ from projects
+ where id=#{id} and enabled=${_true}
+ </select>
+
+ <delete id="deleteByResourceId" parameterType="long">
+ delete from resource_index
+ where resource_id=#{id}
+ </delete>
+
+ <insert id="insert" parameterType="ResourceIndex" useGeneratedKeys="false">
+ insert into resource_index (kee, position, name_size, resource_id, root_project_id, qualifier)
+ values (#{key}, #{position}, #{nameSize},
+ #{resourceId}, #{rootProjectId}, #{qualifier})
+ </insert>
+
+</mapper>
+
+++ /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.ResourceIndexerMapper">
-
- <select id="selectProjectIdsFromQueryAndViewOrSubViewUuid" parameterType="map" resultType="long">
- SELECT r.resource_id FROM resource_index r
- INNER JOIN projects copy ON copy.copy_resource_id = r.resource_id
- <where>
- AND copy.module_uuid_path LIKE #{viewUuidQuery}
- AND r.kee LIKE #{query}
- </where>
- ORDER BY r.name_size
- </select>
-
- <!--
- The column PROJECTS.ROOT_ID is not exact on multi-modules projects. The root id must
- be loaded from the table SNAPSHOTS
- -->
- <select id="selectResources" parameterType="map" resultType="Resource">
- select p.name as "name", p.id as "id", p.scope as "scope", p.qualifier as "qualifier", s.root_project_id as "rootId"
- from projects p, snapshots s
- <where>
- p.enabled=${_true}
- and p.copy_resource_id is null
- and p.id=s.project_id
- and s.islast=${_true}
- <if test="scopes != null">
- and p.scope in
- <foreach item="scope" index="index" collection="scopes" open="(" separator="," close=")">#{scope}</foreach>
- </if>
- <if test="qualifiers != null">
- and p.qualifier in
- <foreach item="qualifier" index="index" collection="qualifiers" open="(" separator="," close=")">#{qualifier}
- </foreach>
- </if>
- <if test="rootProjectId != null">
- and s.root_project_id=#{rootProjectId}
- </if>
- <if test="nonIndexedOnly">
- and not exists(select * from resource_index ri where ri.resource_id=p.id)
- </if>
- </where>
- order by p.id
- </select>
-
- <select id="selectRootProjectIds" parameterType="map" resultType="int">
- select distinct root_project_id
- from snapshots
- where islast=${_true}
- and scope='PRJ'
- and qualifier in ('TRK', 'VW', 'SVW')
- </select>
-
- <select id="selectMasterIndexByResourceId" parameterType="long" resultType="ResourceIndex">
- select kee as "key", resource_id as "resourceId"
- from resource_index
- where resource_id=#{id} and position=0
- </select>
-
- <select id="selectResourceToIndex" parameterType="long" resultType="Resource">
- select id, name, root_id as "rootId", qualifier
- from projects
- where id=#{id} and enabled=${_true}
- </select>
-
- <delete id="deleteByResourceId" parameterType="long">
- delete from resource_index
- where resource_id=#{id}
- </delete>
-
- <insert id="insert" parameterType="ResourceIndex" useGeneratedKeys="false">
- insert into resource_index (kee, position, name_size, resource_id, root_project_id, qualifier)
- values (#{key}, #{position}, #{nameSize},
- #{resourceId}, #{rootProjectId}, #{qualifier})
- </insert>
-
-</mapper>
-
*/
package org.sonar.db;
-import com.google.common.collect.Maps;
-import com.google.common.io.Closeables;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.Map;
-import java.util.Properties;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.text.StrSubstitutor;
-import org.dbunit.Assertion;
-import org.dbunit.DataSourceDatabaseTester;
-import org.dbunit.DatabaseUnitException;
-import org.dbunit.IDatabaseTester;
-import org.dbunit.database.DatabaseConfig;
-import org.dbunit.database.IDatabaseConnection;
-import org.dbunit.dataset.CompositeDataSet;
-import org.dbunit.dataset.DataSetException;
-import org.dbunit.dataset.IDataSet;
-import org.dbunit.dataset.ITable;
-import org.dbunit.dataset.ReplacementDataSet;
-import org.dbunit.dataset.filter.DefaultColumnFilter;
-import org.dbunit.dataset.xml.FlatXmlDataSet;
-import org.dbunit.ext.mssql.InsertIdentityOperation;
-import org.dbunit.ext.mysql.MySqlMetadataHandler;
-import org.dbunit.operation.DatabaseOperation;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Rule;
import org.junit.experimental.categories.Category;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.config.Settings;
-import org.sonar.db.deprecated.NullQueue;
-import org.sonar.db.dialect.MySql;
+import org.sonar.api.utils.System2;
import org.sonar.test.DbTests;
-import static org.junit.Assert.fail;
-
/**
* @deprecated use an instance of {@link DbTester instead} instead,
* and do no forget to annotated the test class with {@link org.sonar.test.DbTests}.
@Deprecated
public abstract class AbstractDaoTestCase {
- private static final Logger LOG = LoggerFactory.getLogger(AbstractDaoTestCase.class);
- private static Database database;
- private static DatabaseCommands databaseCommands;
- private static MyBatis myBatis;
- private static String login;
-
- private IDatabaseTester databaseTester;
-
- @BeforeClass
- public static void startDatabase() throws Exception {
- if (database == null) {
- Settings settings = new Settings().setProperties(Maps.fromProperties(System.getProperties()));
- if (settings.hasKey("orchestrator.configUrl")) {
- loadOrchestratorSettings(settings);
- }
- login = settings.getString("sonar.jdbc.username");
- for (String key : settings.getKeysStartingWith("sonar.jdbc")) {
- LOG.info(key + ": " + settings.getString(key));
- }
- boolean hasDialect = settings.hasKey("sonar.jdbc.dialect");
- if (hasDialect) {
- database = new DefaultDatabase(settings);
- } else {
- database = new H2Database("test", true);
- }
- database.start();
- LOG.info("Test Database: " + database);
- databaseCommands = DatabaseCommands.forDialect(database.getDialect());
-
- myBatis = new MyBatis(database, new NullQueue());
- myBatis.start();
- }
- }
-
- /**
- * Orchestrator is the name of a SonarSource close-source library for database and integration testing.
- */
- private static void loadOrchestratorSettings(Settings settings) throws URISyntaxException, IOException {
- String url = settings.getString("orchestrator.configUrl");
- URI uri = new URI(url);
- InputStream input = null;
- try {
- if (url.startsWith("file:")) {
- File file = new File(uri);
- input = FileUtils.openInputStream(file);
- } else {
- HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection();
- int responseCode = connection.getResponseCode();
- if (responseCode >= 400) {
- throw new IllegalStateException("Fail to request: " + uri + ". Status code=" + responseCode);
- }
-
- input = connection.getInputStream();
-
- }
- Properties props = new Properties();
- props.load(input);
- settings.addProperties(props);
- for (Map.Entry<String, String> entry : settings.getProperties().entrySet()) {
- String interpolatedValue = StrSubstitutor.replace(entry.getValue(), System.getenv(), "${", "}");
- settings.setProperty(entry.getKey(), interpolatedValue);
- }
- } finally {
- IOUtils.closeQuietly(input);
- }
- }
-
- private static RuntimeException translateException(String msg, Exception cause) {
- RuntimeException runtimeException = new RuntimeException(String.format("%s: [%s] %s", msg, cause.getClass().getName(), cause.getMessage()));
- runtimeException.setStackTrace(cause.getStackTrace());
- return runtimeException;
- }
-
- @Before
- public void startDbUnit() throws Exception {
- databaseCommands.truncateDatabase(database.getDataSource());
- databaseTester = new DataSourceDatabaseTester(database.getDataSource(), databaseCommands.useLoginAsSchema() ? login : null);
- }
-
- protected MyBatis getMyBatis() {
- return myBatis;
- }
-
- protected Database getDatabase() {
- return database;
- }
+ @Rule
+ public DbTester dbTester = DbTester.create(System2.INSTANCE);
protected void setupData(String... testNames) {
- InputStream[] streams = new InputStream[testNames.length];
- try {
- for (int i = 0; i < testNames.length; i++) {
- String className = getClass().getName();
- className = String.format("/%s/%s.xml", className.replace(".", "/"), testNames[i]);
- streams[i] = getClass().getResourceAsStream(className);
- if (streams[i] == null) {
- throw new RuntimeException("Test not found :" + className);
- }
- }
-
- setupData(streams);
- databaseCommands.resetPrimaryKeys(database.getDataSource());
- } catch (SQLException e) {
- throw translateException("Could not setup DBUnit data", e);
- } finally {
- for (InputStream stream : streams) {
- IOUtils.closeQuietly(stream);
- }
- }
- }
-
- private void setupData(InputStream... dataSetStream) {
- IDatabaseConnection connection = openDbUnitConnection();
- try {
- IDataSet[] dataSets = new IDataSet[dataSetStream.length];
- for (int i = 0; i < dataSetStream.length; i++) {
- dataSets[i] = getData(dataSetStream[i]);
- }
- databaseTester.setDataSet(new CompositeDataSet(dataSets));
- new InsertIdentityOperation(DatabaseOperation.INSERT).execute(connection, databaseTester.getDataSet());
- } catch (Exception e) {
- throw translateException("Could not setup DBUnit data", e);
- } finally {
- closeDbUnitConnection(connection);
+ List<String> filenames = new ArrayList<>();
+ for (String testName : testNames) {
+ filenames.add(testName + (testName.endsWith(".xml") ? "" : ".xml"));
}
+ dbTester.prepareDbUnit(getClass(), filenames.toArray(new String[filenames.size()]));
}
protected void checkTables(String testName, String... tables) {
}
protected void checkTables(String testName, String[] excludedColumnNames, String... tables) {
- IDatabaseConnection connection = openDbUnitConnection();
- try {
- IDataSet dataSet = connection.createDataSet();
- IDataSet expectedDataSet = getExpectedData(testName);
- for (String table : tables) {
- ITable filteredTable = DefaultColumnFilter.excludedColumnsTable(dataSet.getTable(table), excludedColumnNames);
- ITable filteredExpectedTable = DefaultColumnFilter.excludedColumnsTable(expectedDataSet.getTable(table), excludedColumnNames);
- Assertion.assertEquals(filteredExpectedTable, filteredTable);
- }
- } catch (DatabaseUnitException e) {
- fail(e.getMessage());
- } catch (SQLException e) {
- throw translateException("Error while checking results", e);
- } finally {
- closeDbUnitConnection(connection);
- }
+ dbTester.assertDbUnit(getClass(), testName + (testName.endsWith("-result.xml") ? "" : "-result.xml"), excludedColumnNames, tables);
}
protected void checkTable(String testName, String table, String... columns) {
- IDatabaseConnection connection = openDbUnitConnection();
- try {
- IDataSet dataSet = connection.createDataSet();
- IDataSet expectedDataSet = getExpectedData(testName);
- ITable filteredTable = DefaultColumnFilter.includedColumnsTable(dataSet.getTable(table), columns);
- ITable filteredExpectedTable = DefaultColumnFilter.includedColumnsTable(expectedDataSet.getTable(table), columns);
- Assertion.assertEquals(filteredExpectedTable, filteredTable);
- } catch (DatabaseUnitException e) {
- fail(e.getMessage());
- } catch (SQLException e) {
- throw translateException("Error while checking results", e);
- } finally {
- closeDbUnitConnection(connection);
- }
- }
-
- protected void assertEmptyTables(String... emptyTables) {
- IDatabaseConnection connection = openDbUnitConnection();
- try {
- IDataSet dataSet = connection.createDataSet();
- for (String table : emptyTables) {
- try {
- Assert.assertEquals("Table " + table + " not empty.", 0, dataSet.getTable(table).getRowCount());
- } catch (DataSetException e) {
- throw translateException("Error while checking results", e);
- }
- }
- } catch (SQLException e) {
- throw translateException("Error while checking results", e);
- } finally {
- closeDbUnitConnection(connection);
- }
- }
-
- private IDatabaseConnection openDbUnitConnection() {
- try {
- IDatabaseConnection connection = databaseTester.getConnection();
- connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, databaseCommands.getDbUnitFactory());
- connection.getConfig().setFeature(DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES, false);
- connection.getConfig().setFeature(DatabaseConfig.FEATURE_SKIP_ORACLE_RECYCLEBIN_TABLES, true);
- if (MySql.ID.equals(database.getDialect().getId())) {
- connection.getConfig().setProperty(DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES, false);
- connection.getConfig().setProperty(DatabaseConfig.PROPERTY_METADATA_HANDLER, new MySqlMetadataHandler());
- }
- return connection;
- } catch (Exception e) {
- throw new IllegalStateException("Fail to open dbunit connection", e);
- }
+ dbTester.assertDbUnitTable(getClass(), testName + (testName.endsWith("-result.xml") ? "" : "-result.xml"), table, columns);
}
- private void closeDbUnitConnection(IDatabaseConnection c) {
- try {
- c.close();
- } catch (SQLException e) {
- throw new IllegalStateException("Fail to close dbunit connection", e);
- }
- }
-
- private IDataSet getExpectedData(String testName) {
- String className = getClass().getName();
- String fileName = String.format("/%s/%s-result.xml", className.replace('.', '/'), testName);
- InputStream in = getClass().getResourceAsStream(fileName);
- try {
- return getData(in);
- } finally {
- Closeables.closeQuietly(in);
- }
- }
-
- private IDataSet getData(InputStream stream) {
- try {
- ReplacementDataSet dataSet = new ReplacementDataSet(new FlatXmlDataSet(stream));
- dataSet.addReplacementObject("[null]", null);
- dataSet.addReplacementObject("[false]", Boolean.FALSE);
- dataSet.addReplacementObject("[true]", Boolean.TRUE);
- return dataSet;
- } catch (Exception e) {
- throw translateException("Could not read the dataset stream", e);
- }
- }
-
- protected Connection getConnection() throws SQLException {
- return database.getDataSource().getConnection();
+ @Deprecated
+ protected MyBatis getMyBatis() {
+ return dbTester.myBatis();
}
}
public class DatabaseUtilsTest extends AbstractDaoTestCase {
@Test
- public void should_close_connection() throws SQLException {
- Connection connection = getConnection();
+ public void should_close_connection() throws Exception {
+ Connection connection = dbTester.openConnection();
assertThat(isClosed(connection)).isFalse();
DatabaseUtils.closeQuietly(connection);
}
@Test
- public void should_close_statement_and_resultset() throws SQLException {
- Connection connection = getConnection();
+ public void should_close_statement_and_resultset() throws Exception {
+ Connection connection = dbTester.openConnection();
try {
PreparedStatement statement = connection.prepareStatement(selectDual());
ResultSet rs = statement.executeQuery();
private String selectDual() {
String sql = "SELECT 1";
- if (Oracle.ID.equals(getDatabase().getDialect().getId())) {
+ if (Oracle.ID.equals(dbTester.database().getDialect().getId())) {
sql = "SELECT 1 FROM DUAL";
}
return sql;
import org.dbunit.dataset.xml.FlatXmlDataSet;
import org.dbunit.ext.mssql.InsertIdentityOperation;
import org.dbunit.operation.DatabaseOperation;
-import org.junit.After;
import org.junit.rules.ExternalResource;
import org.picocontainer.containers.TransientPicoContainer;
import org.sonar.api.utils.System2;
private final System2 system2;
private final TestDb db;
- private DbClient2 client;
+ private DbClient client;
private DbSession session = null;
@Deprecated
truncateTables();
}
- @After
- public void closeSession() throws Exception {
+ @Override
+ protected void after() {
if (session != null) {
MyBatis.closeQuietly(session);
}
+ db.close();
}
public DbSession getSession() {
db.truncateTables();
}
- public DbClient2 getDbClient() {
+ public DbClient getDbClient() {
if (client == null) {
TransientPicoContainer ioc = new TransientPicoContainer();
ioc.addComponent(db.getMyBatis());
ioc.addComponent(daoClass);
}
List<Dao> daos = ioc.getComponents(Dao.class);
- client = new DbClient2(db.getMyBatis(), daos.toArray(new Dao[daos.size()]));
+ client = new DbClient(db.getDatabase(), db.getMyBatis(), daos.toArray(new Dao[daos.size()]));
}
return client;
}
}
}
+ public void assertDbUnitTable(Class testClass, String filename, String table, String... columns) {
+ IDatabaseConnection connection = dbUnitConnection();
+ try {
+ IDataSet dataSet = connection.createDataSet();
+ String path = "/" + testClass.getName().replace('.', '/') + "/" + filename;
+ IDataSet expectedDataSet = dbUnitDataSet(testClass.getResourceAsStream(path));
+ ITable filteredTable = DefaultColumnFilter.includedColumnsTable(dataSet.getTable(table), columns);
+ ITable filteredExpectedTable = DefaultColumnFilter.includedColumnsTable(expectedDataSet.getTable(table), columns);
+ Assertion.assertEquals(filteredExpectedTable, filteredTable);
+ } catch (DatabaseUnitException e) {
+ fail(e.getMessage());
+ } catch (SQLException e) {
+ throw translateException("Error while checking results", e);
+ } finally {
+ closeQuietly(connection);
+ }
+ }
+
public void assertDbUnit(Class testClass, String filename, String... tables) {
assertDbUnit(testClass, filename, new String[0], tables);
}
}
}
- private static RuntimeException translateException(String msg, Exception cause) {
+ public static RuntimeException translateException(String msg, Exception cause) {
RuntimeException runtimeException = new RuntimeException(String.format("%s: [%s] %s", msg, cause.getClass().getName(), cause.getMessage()));
runtimeException.setStackTrace(cause.getStackTrace());
return runtimeException;
public Database database() {
return db.getDatabase();
}
+
+ public DatabaseCommands getCommands() {
+ return db.getCommands();
+ }
+
}
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;
@ClassRule
public static DbTester dbTester = DbTester.createForSchema(System2.INSTANCE, ResultSetIteratorTest.class, "schema.sql");
- Connection connection = null;
-
- @Before
- public void setUp() throws Exception {
- connection = dbTester.openConnection();
- }
-
- @After
- public void tearDown() {
- DbUtils.closeQuietly(connection);
- }
-
@Test
public void create_iterator_from_statement() throws Exception {
dbTester.prepareDbUnit(getClass(), "feed.xml");
- PreparedStatement stmt = connection.prepareStatement("select * from issues order by id");
- FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt);
+ try (Connection connection = dbTester.openConnection()) {
+ PreparedStatement stmt = connection.prepareStatement("select * from issues order by id");
+ FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt);
- assertThat(iterator.hasNext()).isTrue();
+ assertThat(iterator.hasNext()).isTrue();
- // calling multiple times hasNext() is ok
- assertThat(iterator.hasNext()).isTrue();
+ // calling multiple times hasNext() is ok
+ assertThat(iterator.hasNext()).isTrue();
- assertThat(iterator.next()).isEqualTo(10);
- assertThat(iterator.hasNext()).isTrue();
- assertThat(iterator.next()).isEqualTo(20);
+ assertThat(iterator.next()).isEqualTo(10);
+ assertThat(iterator.hasNext()).isTrue();
+ assertThat(iterator.next()).isEqualTo(20);
- // call next() without calling hasNext()
- assertThat(iterator.next()).isEqualTo(30);
- assertThat(iterator.hasNext()).isFalse();
+ // call next() without calling hasNext()
+ assertThat(iterator.next()).isEqualTo(30);
+ assertThat(iterator.hasNext()).isFalse();
- try {
- iterator.next();
- fail();
- } catch (NoSuchElementException e) {
- // ok
- }
+ try {
+ iterator.next();
+ fail();
+ } catch (NoSuchElementException e) {
+ // ok
+ }
- iterator.close();
- // statement is closed by ResultSetIterator
- assertThat(stmt.isClosed()).isTrue();
+ iterator.close();
+ // statement is closed by ResultSetIterator
+ assertThat(stmt.isClosed()).isTrue();
+ }
}
@Test
public void iterate_empty_list() throws Exception {
dbTester.prepareDbUnit(getClass(), "feed.xml");
- PreparedStatement stmt = connection.prepareStatement("select * from issues where id < 0");
- FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt);
+ try (Connection connection = dbTester.openConnection()) {
+ PreparedStatement stmt = connection.prepareStatement("select * from issues where id < 0");
+ FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt);
- assertThat(iterator.hasNext()).isFalse();
+ assertThat(iterator.hasNext()).isFalse();
+ }
}
@Test
public void create_iterator_from_result_set() throws Exception {
dbTester.prepareDbUnit(getClass(), "feed.xml");
- PreparedStatement stmt = connection.prepareStatement("select * from issues order by id");
- ResultSet rs = stmt.executeQuery();
- FirstIntColumnIterator iterator = new FirstIntColumnIterator(rs);
+ try (Connection connection = dbTester.openConnection()) {
+ PreparedStatement stmt = connection.prepareStatement("select * from issues order by id");
+ ResultSet rs = stmt.executeQuery();
+ FirstIntColumnIterator iterator = new FirstIntColumnIterator(rs);
- assertThat(iterator.next()).isEqualTo(10);
- assertThat(iterator.next()).isEqualTo(20);
- assertThat(iterator.next()).isEqualTo(30);
+ assertThat(iterator.next()).isEqualTo(10);
+ assertThat(iterator.next()).isEqualTo(20);
+ assertThat(iterator.next()).isEqualTo(30);
- iterator.close();
- assertThat(rs.isClosed()).isTrue();
- stmt.close();
+ iterator.close();
+ assertThat(rs.isClosed()).isTrue();
+ stmt.close();
+ }
}
@Test
public void remove_row_is_not_supported() throws Exception {
- PreparedStatement stmt = connection.prepareStatement("select * from issues order by id");
- FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt);
-
- try {
- iterator.remove();
- fail();
- } catch (UnsupportedOperationException ok) {
- // ok
+ try (Connection connection = dbTester.openConnection()) {
+ PreparedStatement stmt = connection.prepareStatement("select * from issues order by id");
+ FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt);
+
+ try {
+ iterator.remove();
+ fail();
+ } catch (UnsupportedOperationException ok) {
+ // ok
+ }
+
+ iterator.close();
}
-
- iterator.close();
}
@Test
public void fail_to_read_row() throws Exception {
dbTester.prepareDbUnit(getClass(), "feed.xml");
- PreparedStatement stmt = connection.prepareStatement("select * from issues order by id");
- FailIterator iterator = new FailIterator(stmt);
-
- assertThat(iterator.hasNext()).isTrue();
- try {
- iterator.next();
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getCause()).isInstanceOf(SQLException.class);
+ try (Connection connection = dbTester.openConnection()) {
+ PreparedStatement stmt = connection.prepareStatement("select * from issues order by id");
+ FailIterator iterator = new FailIterator(stmt);
+
+ assertThat(iterator.hasNext()).isTrue();
+ try {
+ iterator.next();
+ fail();
+ } catch (IllegalStateException e) {
+ assertThat(e.getCause()).isInstanceOf(SQLException.class);
+ }
+ iterator.close();
}
- iterator.close();
}
private static class FirstIntColumnIterator extends ResultSetIterator<Integer> {
private DatabaseCommands commands;
private IDatabaseTester tester;
private MyBatis myBatis;
+ private boolean isDefault;
+
+ static TestDb create(@Nullable String schemaPath) {
+ if (schemaPath == null) {
+ if (DEFAULT == null) {
+ DEFAULT = new TestDb(null);
+ }
+ return DEFAULT;
+ }
+ return new TestDb(schemaPath);
+ }
private TestDb(@Nullable String schemaPath) {
if (db == null) {
throw new AssumptionViolatedException("Test disabled because it supports only H2");
}
}
+ isDefault = (schemaPath == null);
LOG.info("Test Database: " + db);
commands = DatabaseCommands.forDialect(db.getDialect());
}
}
- static TestDb create(@Nullable String schemaPath) {
- if (schemaPath == null) {
- if (DEFAULT == null) {
- DEFAULT = new TestDb(null);
- }
- return DEFAULT;
+ void close() {
+ if (!isDefault) {
+ db.stop();
}
- return new TestDb(schemaPath);
- }
-
- void stop() {
- db.stop();
- db = null;
- myBatis = null;
}
Database getDatabase() {
session.rollback();
- assertEmptyTables("projects");
+ assertThat(dbTester.countRowsOfTable("projects")).isZero();
}
@Test
--- /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.sql.SQLException;
+import org.junit.Test;
+import org.sonar.api.resources.Qualifiers;
+import org.sonar.db.AbstractDaoTestCase;
+import org.sonar.db.DbSession;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ResourceIndexDaoTest extends AbstractDaoTestCase {
+
+ ResourceIndexDao dao = dbTester.getDbClient().componentIndexDao();
+
+ @Test
+ public void shouldIndexResource() {
+ setupData("shouldIndexResource");
+
+ dao.indexResource(10, "ZipUtils", "FIL", 8);
+
+ checkTables("shouldIndexResource", new String[] {"id"}, "resource_index");
+ }
+
+ @Test
+ public void shouldIndexProjects() {
+ setupData("shouldIndexProjects");
+
+ dao.indexProjects();
+
+ checkTables("shouldIndexProjects", new String[] {"id"}, "resource_index");
+ }
+
+ @Test
+ public void shouldIndexMultiModulesProject() {
+ setupData("shouldIndexMultiModulesProject");
+
+ dao.indexProject(1);
+
+ checkTables("shouldIndexMultiModulesProject", new String[] {"id"}, "resource_index");
+ }
+
+ @Test
+ public void shouldReindexProjectAfterRenaming() {
+ setupData("shouldReindexProjectAfterRenaming");
+
+ dao.indexProject(1);
+
+ checkTables("shouldReindexProjectAfterRenaming", new String[] {"id"}, "resource_index");
+ }
+
+ @Test
+ public void shouldNotIndexPackages() throws SQLException {
+ setupData("shouldNotIndexPackages");
+
+ dao.indexProject(1);
+ // project
+ assertThat(dbTester.countSql("select count(resource_id) from resource_index where resource_id=1")).isGreaterThan(0);
+ // directory
+ assertThat(dbTester.countSql("select count(resource_id) from resource_index where resource_id=2")).isEqualTo(0);
+ // file
+ assertThat(dbTester.countSql("select count(resource_id) from resource_index where resource_id=3")).isGreaterThan(0);
+ }
+
+ @Test
+ public void shouldIndexTwoLettersLongResources() {
+ setupData("shouldIndexTwoLettersLongResource");
+
+ dao.indexResource(10, "AB", Qualifiers.PROJECT, 3);
+
+ checkTables("shouldIndexTwoLettersLongResource", new String[] {"id"}, "resource_index");
+ }
+
+ @Test
+ public void shouldReIndexTwoLettersLongResources() {
+ setupData("shouldReIndexTwoLettersLongResource");
+
+ dao.indexResource(1, "AS", Qualifiers.PROJECT, 1);
+
+ checkTables("shouldReIndexTwoLettersLongResource", new String[] {"id"}, "resource_index");
+ }
+
+ @Test
+ public void shouldReIndexNewTwoLettersLongResource() {
+ setupData("shouldReIndexNewTwoLettersLongResource");
+
+ dao.indexResource(1, "AS", Qualifiers.PROJECT, 1);
+
+ checkTables("shouldReIndexNewTwoLettersLongResource", new String[] {"id"}, "resource_index");
+ }
+
+ @Test
+ public void shouldReindexResource() {
+ setupData("shouldReindexResource");
+
+ dao.indexResource(1, "New Struts", Qualifiers.PROJECT, 1);
+
+ checkTables("shouldReindexResource", new String[] {"id"}, "resource_index");
+ }
+
+ @Test
+ public void shouldNotReindexUnchangedResource() {
+ setupData("shouldNotReindexUnchangedResource");
+
+ dao.indexResource(1, "Struts", Qualifiers.PROJECT, 1);
+
+ checkTables("shouldNotReindexUnchangedResource", new String[] {"id"}, "resource_index");
+ }
+
+ @Test
+ public void select_project_ids_from_query_and_view_or_sub_view_uuid() {
+ setupData("select_project_ids_from_query_and_view_or_sub_view_uuid");
+ String viewUuid = "EFGH";
+
+ DbSession session = dbTester.getSession();
+ assertThat(dao.selectProjectIdsFromQueryAndViewOrSubViewUuid(session, "project", viewUuid)).containsOnly(1L, 2L);
+ assertThat(dao.selectProjectIdsFromQueryAndViewOrSubViewUuid(session, "one", viewUuid)).containsOnly(1L);
+ assertThat(dao.selectProjectIdsFromQueryAndViewOrSubViewUuid(session, "two", viewUuid)).containsOnly(2L);
+ assertThat(dao.selectProjectIdsFromQueryAndViewOrSubViewUuid(session, "unknown", viewUuid)).isEmpty();
+ }
+}
+++ /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.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.utils.System2;
-import org.sonar.db.AbstractDaoTestCase;
-import org.sonar.db.DbSession;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-public class ResourceIndexerDaoTest extends AbstractDaoTestCase {
-
- private static ResourceIndexerDao dao;
-
- @Before
- public void createDao() {
- dao = new ResourceIndexerDao(getMyBatis(), mock(System2.class));
- }
-
- @Test
- public void shouldIndexResource() {
- setupData("shouldIndexResource");
-
- dao.indexResource(10, "ZipUtils", "FIL", 8);
-
- checkTables("shouldIndexResource", new String[] {"id"}, "resource_index");
- }
-
- @Test
- public void shouldIndexProjects() {
- setupData("shouldIndexProjects");
-
- dao.indexProjects();
-
- checkTables("shouldIndexProjects", new String[] {"id"}, "resource_index");
- }
-
- @Test
- public void shouldIndexMultiModulesProject() {
- setupData("shouldIndexMultiModulesProject");
-
- dao.indexProject(1);
-
- checkTables("shouldIndexMultiModulesProject", new String[] {"id"}, "resource_index");
- }
-
- @Test
- public void shouldReindexProjectAfterRenaming() {
- setupData("shouldReindexProjectAfterRenaming");
-
- dao.indexProject(1);
-
- checkTables("shouldReindexProjectAfterRenaming", new String[] {"id"}, "resource_index");
- }
-
- @Test
- public void shouldNotIndexPackages() throws SQLException {
- setupData("shouldNotIndexPackages");
-
- dao.indexProject(1);
-
- Connection connection = getConnection();
- ResultSet rs = null;
- try {
- // project
- rs = connection.createStatement().executeQuery("select count(resource_id) from resource_index where resource_id=1");
- rs.next();
- assertThat(rs.getInt(1)).isGreaterThan(0);
-
- // directory
- rs = connection.createStatement().executeQuery("select count(resource_id) from resource_index where resource_id=2");
- rs.next();
- assertThat(rs.getInt(1)).isEqualTo(0);
-
- // file
- rs = connection.createStatement().executeQuery("select count(resource_id) from resource_index where resource_id=3");
- rs.next();
- assertThat(rs.getInt(1)).isGreaterThan(0);
- } finally {
- if (null != rs) {
- rs.close();
- }
- }
- }
-
- @Test
- public void shouldIndexTwoLettersLongResources() {
- setupData("shouldIndexTwoLettersLongResource");
-
- dao.indexResource(10, "AB", Qualifiers.PROJECT, 3);
-
- checkTables("shouldIndexTwoLettersLongResource", new String[] {"id"}, "resource_index");
- }
-
- @Test
- public void shouldReIndexTwoLettersLongResources() {
- setupData("shouldReIndexTwoLettersLongResource");
-
- dao.indexResource(1, "AS", Qualifiers.PROJECT, 1);
-
- checkTables("shouldReIndexTwoLettersLongResource", new String[] {"id"}, "resource_index");
- }
-
- @Test
- public void shouldReIndexNewTwoLettersLongResource() {
- setupData("shouldReIndexNewTwoLettersLongResource");
-
- dao.indexResource(1, "AS", Qualifiers.PROJECT, 1);
-
- checkTables("shouldReIndexNewTwoLettersLongResource", new String[] {"id"}, "resource_index");
- }
-
- @Test
- public void shouldReindexResource() {
- setupData("shouldReindexResource");
-
- dao.indexResource(1, "New Struts", Qualifiers.PROJECT, 1);
-
- checkTables("shouldReindexResource", new String[] {"id"}, "resource_index");
- }
-
- @Test
- public void shouldNotReindexUnchangedResource() {
- setupData("shouldNotReindexUnchangedResource");
-
- dao.indexResource(1, "Struts", Qualifiers.PROJECT, 1);
-
- checkTables("shouldNotReindexUnchangedResource", new String[] {"id"}, "resource_index");
- }
-
- @Test
- public void select_project_ids_from_query_and_view_or_sub_view_uuid() {
- setupData("select_project_ids_from_query_and_view_or_sub_view_uuid");
- String viewUuid = "EFGH";
-
- DbSession session = getMyBatis().openSession(false);
- assertThat(dao.selectProjectIdsFromQueryAndViewOrSubViewUuid(session, "project", viewUuid)).containsOnly(1L, 2L);
- assertThat(dao.selectProjectIdsFromQueryAndViewOrSubViewUuid(session, "one", viewUuid)).containsOnly(1L);
- assertThat(dao.selectProjectIdsFromQueryAndViewOrSubViewUuid(session, "two", viewUuid)).containsOnly(2L);
- assertThat(dao.selectProjectIdsFromQueryAndViewOrSubViewUuid(session, "unknown", viewUuid)).isEmpty();
- }
-}
import java.util.Collection;
import java.util.List;
-import org.apache.ibatis.session.SqlSession;
-import org.junit.Before;
import org.junit.Test;
import org.sonar.db.AbstractDaoTestCase;
-import org.sonar.db.MyBatis;
import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;
public class ActionPlanDaoTest extends AbstractDaoTestCase {
- ActionPlanDao dao;
-
- @Before
- public void createDao() {
- dao = new ActionPlanDao(getMyBatis());
- }
+ ActionPlanDao dao = dbTester.getDbClient().actionPlanDao();
@Test
public void should_insert_new_action_plan() {
public void should_find_by_keys_on_huge_number_of_keys() {
setupData("shared");
- SqlSession session = getMyBatis().openSession();
List<String> hugeNbOKeys = newArrayList();
for (int i = 0; i < 4500; i++) {
hugeNbOKeys.add("ABCD" + i);
}
List<ActionPlanDto> result = dao.findByKeys(hugeNbOKeys);
- MyBatis.closeQuietly(session);
// The goal of this test is only to check that the query do no fail, not to check the number of results
assertThat(result).isEmpty();
import org.sonar.db.MyBatis;
import static com.google.common.collect.Lists.newArrayList;
+import static org.assertj.core.api.Assertions.assertThat;
public class PurgeCommandsTest extends AbstractDaoTestCase {
new PurgeCommands(session, profiler).deleteResources(newArrayList(new IdUuidPair(1L, "1")));
}
- assertEmptyTables("projects", "snapshots", "events", "issues", "issue_changes", "authors");
+ assertThat(dbTester.countRowsOfTable("projects")).isZero();
+ assertThat(dbTester.countRowsOfTable("snapshots")).isZero();
+ assertThat(dbTester.countRowsOfTable("events")).isZero();
+ assertThat(dbTester.countRowsOfTable("issues")).isZero();
+ assertThat(dbTester.countRowsOfTable("issue_changes")).isZero();
+ assertThat(dbTester.countRowsOfTable("authors")).isZero();
}
/**
package org.sonar.db.purge;
import java.util.List;
-import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import org.sonar.api.resources.Scopes;
import org.sonar.api.utils.System2;
-import org.sonar.db.AbstractDaoTestCase;
-import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
-import org.sonar.db.component.ResourceDao;
+import org.sonar.db.DbTester;
+import org.sonar.test.DbTests;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-public class PurgeDaoTest extends AbstractDaoTestCase {
+@Category(DbTests.class)
+public class PurgeDaoTest {
- private PurgeDao sut;
- private System2 system2;
- private DbSession dbSession;
+ System2 system2 = mock(System2.class);
- private static PurgeableSnapshotDto getById(List<PurgeableSnapshotDto> snapshots, long id) {
- for (PurgeableSnapshotDto snapshot : snapshots) {
- if (snapshot.getSnapshotId() == id) {
- return snapshot;
- }
- }
- return null;
- }
+ @Rule
+ public DbTester dbTester = DbTester.create(system2);
+
+ PurgeDao sut = dbTester.getDbClient().purgeDao();
@Before
public void before() {
- system2 = mock(System2.class);
when(system2.now()).thenReturn(1450000000000L);
- dbSession = getMyBatis().openSession(false);
-
- sut = new PurgeDao(getMyBatis(), new ResourceDao(getMyBatis(), system2), system2);
- }
-
- @After
- public void after() {
- MyBatis.closeQuietly(dbSession);
}
@Test
public void shouldDeleteAbortedBuilds() {
- setupData("shouldDeleteAbortedBuilds");
+ dbTester.prepareDbUnit(getClass(), "shouldDeleteAbortedBuilds.xml");
sut.purge(newConfigurationWith30Days(), PurgeListener.EMPTY, new PurgeProfiler());
- checkTables("shouldDeleteAbortedBuilds", "snapshots");
+ dbTester.assertDbUnit(getClass(), "shouldDeleteAbortedBuilds-result.xml", "snapshots");
}
@Test
public void should_purge_project() {
- setupData("shouldPurgeProject");
+ dbTester.prepareDbUnit(getClass(), "shouldPurgeProject.xml");
sut.purge(newConfigurationWith30Days(), PurgeListener.EMPTY, new PurgeProfiler());
- checkTables("shouldPurgeProject", "projects", "snapshots");
+ dbTester.assertDbUnit(getClass(), "shouldPurgeProject-result.xml", "projects", "snapshots");
}
private PurgeConfiguration newConfigurationWith30Days() {
@Test
public void delete_file_sources_of_disabled_resources() {
- setupData("delete_file_sources_of_disabled_resources");
+ dbTester.prepareDbUnit(getClass(), "delete_file_sources_of_disabled_resources.xml");
sut.purge(newConfigurationWith30Days(system2), PurgeListener.EMPTY, new PurgeProfiler());
- checkTables("delete_file_sources_of_disabled_resources", "file_sources");
+ dbTester.assertDbUnit(getClass(), "delete_file_sources_of_disabled_resources-result.xml", "file_sources");
}
@Test
public void shouldDeleteHistoricalDataOfDirectoriesAndFiles() {
- setupData("shouldDeleteHistoricalDataOfDirectoriesAndFiles");
+ dbTester.prepareDbUnit(getClass(), "shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml");
sut.purge(new PurgeConfiguration(new IdUuidPair(1L, "1"), new String[] {Scopes.DIRECTORY, Scopes.FILE}, 30), PurgeListener.EMPTY, new PurgeProfiler());
- checkTables("shouldDeleteHistoricalDataOfDirectoriesAndFiles", "projects", "snapshots");
+ dbTester.assertDbUnit(getClass(), "shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml", "projects", "snapshots");
}
@Test
public void disable_resources_without_last_snapshot() {
- setupData("disable_resources_without_last_snapshot");
+ dbTester.prepareDbUnit(getClass(), "disable_resources_without_last_snapshot.xml");
sut.purge(newConfigurationWith30Days(system2), PurgeListener.EMPTY, new PurgeProfiler());
- checkTables("disable_resources_without_last_snapshot", new String[] {"issue_close_date", "issue_update_date"}, "projects", "snapshots", "issues");
+ dbTester.assertDbUnit(getClass(), "disable_resources_without_last_snapshot-result.xml", new String[]{"issue_close_date", "issue_update_date"}, "projects", "snapshots", "issues");
}
@Test
public void shouldDeleteSnapshots() {
- setupData("shouldDeleteSnapshots");
+ dbTester.prepareDbUnit(getClass(), "shouldDeleteSnapshots.xml");
sut.deleteSnapshots(PurgeSnapshotQuery.create().setIslast(false).setResourceId(1L), new PurgeProfiler());
- checkTables("shouldDeleteSnapshots", "snapshots");
+ dbTester.assertDbUnit(getClass(), "shouldDeleteSnapshots-result.xml", "snapshots");
}
@Test
public void shouldSelectPurgeableSnapshots() {
- setupData("shouldSelectPurgeableSnapshots");
+ dbTester.prepareDbUnit(getClass(), "shouldSelectPurgeableSnapshots.xml");
List<PurgeableSnapshotDto> snapshots = sut.selectPurgeableSnapshots(1L);
assertThat(snapshots).hasSize(3);
@Test
public void should_delete_project_and_associated_data() {
- setupData("shouldDeleteProject");
+ dbTester.prepareDbUnit(getClass(), "shouldDeleteProject.xml");
sut.deleteResourceTree(new IdUuidPair(1L, "A"), new PurgeProfiler());
- assertEmptyTables("projects", "snapshots", "action_plans", "issues", "issue_changes", "file_sources");
+ assertThat(dbTester.countRowsOfTable("projects")).isZero();
+ assertThat(dbTester.countRowsOfTable("snapshots")).isZero();
+ assertThat(dbTester.countRowsOfTable("action_plans")).isZero();
+ assertThat(dbTester.countRowsOfTable("issues")).isZero();
+ assertThat(dbTester.countRowsOfTable("issue_changes")).isZero();
+ assertThat(dbTester.countRowsOfTable("file_sources")).isZero();
}
@Test
public void should_delete_old_closed_issues() {
- setupData("should_delete_old_closed_issues");
+ dbTester.prepareDbUnit(getClass(), "should_delete_old_closed_issues.xml");
sut.purge(newConfigurationWith30Days(), PurgeListener.EMPTY, new PurgeProfiler());
- checkTables("should_delete_old_closed_issues", "issues", "issue_changes");
+ dbTester.assertDbUnit(getClass(), "should_delete_old_closed_issues-result.xml", "issues", "issue_changes");
}
@Test
public void should_delete_all_closed_issues() {
- setupData("should_delete_all_closed_issues");
+ dbTester.prepareDbUnit(getClass(), "should_delete_all_closed_issues.xml");
sut.purge(new PurgeConfiguration(new IdUuidPair(1L, "1"), new String[0], 0), PurgeListener.EMPTY, new PurgeProfiler());
- checkTables("should_delete_all_closed_issues", "issues", "issue_changes");
+ dbTester.assertDbUnit(getClass(), "should_delete_all_closed_issues-result.xml", "issues", "issue_changes");
}
@Test
public void select_purgeable_file_uuids_and_only_them() {
- setupData("select_purgeable_file_uuids");
+ dbTester.prepareDbUnit(getClass(), "select_purgeable_file_uuids.xml");
- List<String> uuids = sut.selectPurgeableFiles(dbSession, 1L);
+ List<String> uuids = sut.selectPurgeableFiles(dbTester.getSession(), 1L);
assertThat(uuids).containsOnly("GHIJ");
}
+
+ private static PurgeableSnapshotDto getById(List<PurgeableSnapshotDto> snapshots, long id) {
+ for (PurgeableSnapshotDto snapshot : snapshots) {
+ if (snapshot.getSnapshotId() == id) {
+ return snapshot;
+ }
+ }
+ return null;
+ }
}
"id", "qgate_id", "metric_id", "operator", "value_warning", "value_error", "period"
};
- private static QualityGateConditionDao dao;
-
- @Before
- public void createDao() {
- dao = new QualityGateConditionDao(getMyBatis());
- }
+ QualityGateConditionDao dao = dbTester.getDbClient().gateConditionDao();
@Test
public void testInsert() throws Exception {
- setupData("insert");
+ setupData("insert.xml");
QualityGateConditionDto newCondition = new QualityGateConditionDto()
.setQualityGateId(1L).setMetricId(2L).setOperator("GT").setWarningThreshold("10").setErrorThreshold("20").setPeriod(3);
dao.insert(newCondition);
@Test
public void testSelectForQualityGate() throws Exception {
- setupData("selectForQualityGate");
+ setupData("selectForQualityGate.xml");
assertThat(dao.selectForQualityGate(1L)).hasSize(3);
assertThat(dao.selectForQualityGate(2L)).hasSize(2);
}
@Test
public void testSelectById() throws Exception {
- setupData("selectForQualityGate");
+ setupData("selectForQualityGate.xml");
QualityGateConditionDto selectById = dao.selectById(1L);
assertThat(selectById).isNotNull();
assertThat(selectById.getId()).isNotNull().isNotEqualTo(0L);
@Test
public void testDelete() throws Exception {
- setupData("selectForQualityGate");
+ setupData("selectForQualityGate.xml");
dao.delete(new QualityGateConditionDto().setId(1L));
checkTable("delete", "quality_gate_conditions", COLUMNS_WITHOUT_TIMESTAMPS);
}
@Test
public void testUpdate() throws Exception {
- setupData("selectForQualityGate");
+ setupData("selectForQualityGate.xml");
dao.update(new QualityGateConditionDto().setId(1L).setMetricId(7L).setOperator(">").setPeriod(1).setWarningThreshold("50").setErrorThreshold("80"));
- checkTable("update", "quality_gate_conditions", COLUMNS_WITHOUT_TIMESTAMPS);
+ checkTable("update-result.xml", "quality_gate_conditions", COLUMNS_WITHOUT_TIMESTAMPS);
}
+ @Test
public void shouldCleanConditions() {
- setupData("shouldCleanConditions");
+ setupData("shouldCleanConditions.xml");
dao.deleteConditionsWithInvalidMetrics();
- checkTables("shouldCleanConditions", "quality_gate_conditions");
+ checkTables("shouldCleanConditions-result.xml", new String[]{"created_at", "updated_at"}, "quality_gate_conditions");
}
}
*/
package org.sonar.db.user;
-import org.junit.Before;
import org.junit.Test;
-import org.sonar.api.utils.System2;
import org.sonar.db.AbstractDaoTestCase;
-import org.sonar.db.component.ResourceDao;
import org.sonar.db.component.ResourceDto;
import static org.assertj.core.api.Assertions.assertThat;
public class AuthorDaoTest extends AbstractDaoTestCase {
- private AuthorDao dao;
-
- @Before
- public void setUp() {
- dao = new AuthorDao(getMyBatis(), new ResourceDao(getMyBatis(), System2.INSTANCE));
- }
+ AuthorDao dao = dbTester.getDbClient().authorDao();
@Test
public void shouldSelectByLogin() {
--- /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 "struts" -> module "struts-core" -> package org.struts -> file "RequestContext" -->
+ <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
+ uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
+ root_id="[null]"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+ <projects long_name="[null]" id="2" scope="PRJ" qualifier="BRC" kee="org.struts:struts-core" name="Struts Core"
+ uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
+ root_id="1"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+ <!-- note that the root_id of package/file is wrong. It references the module but not the root project -->
+ <projects long_name="org.struts" id="3" scope="DIR" qualifier="PAC" kee="org.struts:struts-core:org.struts"
+ uuid="CDEF" project_uuid="ABCD" module_uuid="BCDE" module_uuid_path=".ABCD.BCDE"
+ name="org.struts" root_id="2"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+ <projects long_name="org.struts.RequestContext" id="4" scope="CLA" qualifier="CLA"
+ uuid="DEFG" project_uuid="ABCD" module_uuid="BCDE" module_uuid_path=".ABCD.BCDE"
+ kee="org.struts:struts-core:org.struts.RequestContext"
+ name="RequestContext" root_id="2"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+ <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1"/>
+ <snapshots purge_status="[null]" id="2" islast="[true]" root_project_id="1" project_id="2"/>
+ <snapshots purge_status="[null]" id="3" islast="[true]" root_project_id="1" project_id="3"/>
+ <snapshots purge_status="[null]" id="4" islast="[true]" root_project_id="1" project_id="4"/>
+
+ <!-- The major goal is to test root_project_id -->
+
+ <!-- RequestContext -->
+ <resource_index kee="requestcontext" position="0" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+ <resource_index kee="equestcontext" position="1" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+ <resource_index kee="questcontext" position="2" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+ <resource_index kee="uestcontext" position="3" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+ <resource_index kee="estcontext" position="4" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+ <resource_index kee="stcontext" position="5" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+ <resource_index kee="tcontext" position="6" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+ <resource_index kee="context" position="7" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+ <resource_index kee="ontext" position="8" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+ <resource_index kee="ntext" position="9" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+ <resource_index kee="text" position="10" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+ <resource_index kee="ext" position="11" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
+
+ <!-- Struts -->
+ <resource_index kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+
+ <!-- Struts Core -->
+ <resource_index kee="struts core" position="0" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
+ <resource_index kee="truts core" position="1" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
+ <resource_index kee="ruts core" position="2" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
+ <resource_index kee="uts core" position="3" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
+ <resource_index kee="ts core" position="4" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
+ <resource_index kee="s core" position="5" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
+ <resource_index kee=" core" position="6" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
+ <resource_index kee="core" position="7" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
+ <resource_index kee="ore" position="8" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
+
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <!-- project "struts" -> module "struts-core" -> package org.struts -> file "RequestContext" -->
+ <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
+ uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
+ root_id="[null]"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+ <projects long_name="[null]" id="2" scope="PRJ" qualifier="BRC" kee="org.struts:struts-core" name="Struts Core"
+ uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
+ root_id="1"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+ <!-- note that the root_id of package/file is wrong. It references the module but not the root project -->
+ <projects long_name="org.struts" id="3" scope="DIR" qualifier="PAC" kee="org.struts:struts-core:org.struts"
+ uuid="CDEF" project_uuid="ABCD" module_uuid="BCDE" module_uuid_path=".ABCD.BCDE"
+ name="org.struts" root_id="2"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+ <projects long_name="org.struts.RequestContext" id="4" scope="FIL" qualifier="CLA"
+ uuid="DEFG" project_uuid="ABCD" module_uuid="BCDE" module_uuid_path=".ABCD.BCDE"
+ kee="org.struts:struts-core:org.struts.RequestContext"
+ name="RequestContext" root_id="2"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+ <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1"/>
+ <snapshots purge_status="[null]" id="2" islast="[true]" root_project_id="1" project_id="2"/>
+ <snapshots purge_status="[null]" id="3" islast="[true]" root_project_id="1" project_id="3"/>
+ <snapshots purge_status="[null]" id="4" islast="[true]" root_project_id="1" project_id="4"/>
+</dataset>
--- /dev/null
+<dataset>
+
+ <!-- project -->
+ <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
+ uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
+ root_id="[null]"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+ <!-- directory -->
+ <projects long_name="org.struts" id="2" scope="DIR" qualifier="PAC" kee="org.struts:struts:org.struts"
+ uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
+ name="org.struts" root_id="1"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+ <!-- file -->
+ <projects long_name="org.struts.RequestContext" id="3" scope="CLA" qualifier="CLA"
+ uuid="CDEF" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
+ kee="org.struts:struts:org.struts.RequestContext"
+ name="RequestContext" root_id="1"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+ <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
+ qualifier="TRK"/>
+ <snapshots purge_status="[null]" id="2" islast="[true]" root_project_id="1" project_id="2" scope="DIR"
+ qualifier="PAC"/>
+ <snapshots purge_status="[null]" id="3" islast="[true]" root_project_id="1" project_id="3" scope="CLA"
+ qualifier="CLA"/>
+
+ <!-- RequestContext -->
+ <resource_index kee="requestcontext" position="0" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+ <resource_index kee="equestcontext" position="1" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+ <resource_index kee="questcontext" position="2" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+ <resource_index kee="uestcontext" position="3" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+ <resource_index kee="estcontext" position="4" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+ <resource_index kee="stcontext" position="5" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+ <resource_index kee="tcontext" position="6" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+ <resource_index kee="context" position="7" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+ <resource_index kee="ontext" position="8" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+ <resource_index kee="ntext" position="9" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+ <resource_index kee="text" position="10" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+ <resource_index kee="ext" position="11" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
+
+ <!-- Struts -->
+ <resource_index kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <!-- project -->
+ <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
+ uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
+ root_id="[null]"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+ <!-- directory -->
+ <projects long_name="org.struts" id="2" scope="DIR" qualifier="PAC" kee="org.struts:struts:org.struts"
+ uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
+ name="org.struts" root_id="1"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+ <!-- file -->
+ <projects long_name="org.struts.RequestContext" id="3" scope="FIL" qualifier="CLA"
+ kee="org.struts:struts:org.struts.RequestContext"
+ uuid="CDEF" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
+ name="RequestContext" root_id="1"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+ <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
+ qualifier="TRK"/>
+ <snapshots purge_status="[null]" id="2" islast="[true]" root_project_id="1" project_id="2" scope="DIR"
+ qualifier="PAC"/>
+ <snapshots purge_status="[null]" id="3" islast="[true]" root_project_id="1" project_id="3" scope="FIL"
+ qualifier="CLA"/>
+</dataset>
--- /dev/null
+<dataset>
+ <resource_index kee="ziputils" position="0" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
+ <resource_index kee="iputils" position="1" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
+ <resource_index kee="putils" position="2" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
+ <resource_index kee="utils" position="3" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
+ <resource_index kee="tils" position="4" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
+ <resource_index kee="ils" position="5" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset></dataset>
--- /dev/null
+<dataset>
+ <resource_index kee="ab" position="0" name_size="2" resource_id="10" root_project_id="3" qualifier="TRK"/>
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset></dataset>
--- /dev/null
+<dataset>
+
+ <!-- project -->
+ <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
+ uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
+ root_id="[null]"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+ <!-- directory -->
+ <projects long_name="org.struts" id="2" scope="DIR" qualifier="PAC" kee="org.struts:struts:org.struts"
+ uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
+ name="org.struts" root_id="1"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+ <!-- file -->
+ <projects long_name="org.struts.RequestContext" id="3" scope="FIL" qualifier="CLA"
+ kee="org.struts:struts:org.struts.RequestContext"
+ uuid="CDEF" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
+ name="RequestContext" root_id="1"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+ <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
+ qualifier="TRK"/>
+ <snapshots purge_status="[null]" id="2" islast="[true]" root_project_id="1" project_id="2" scope="DIR"
+ qualifier="PAC"/>
+ <snapshots purge_status="[null]" id="3" islast="[true]" root_project_id="1" project_id="3" scope="FIL"
+ qualifier="CLA"/>
+</dataset>
--- /dev/null
+<dataset>
+ <resource_index kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset>
+ <resource_index id="1" kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index id="2" kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index id="3" kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index id="4" kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset>
+ <resource_index kee="as" position="0" name_size="2" resource_id="1" root_project_id="1" qualifier="TRK"/>
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset>
+
+ <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="AS"
+ uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
+ root_id="[null]"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+ <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
+ qualifier="TRK"/>
+
+ <!-- the index is on the old name "ST" but not on "AS" -->
+ <resource_index id="1" kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index id="2" kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index id="3" kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index id="4" kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+
+</dataset>
--- /dev/null
+<dataset>
+ <resource_index kee="as" position="0" name_size="2" resource_id="1" root_project_id="1" qualifier="TRK"/>
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset>
+
+ <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="AS"
+ uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
+ root_id="[null]"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+ <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
+ qualifier="TRK"/>
+
+ <!-- the index is on the old name "ST" but not on "AS" -->
+ <resource_index id="1" kee="st" position="0" name_size="2" resource_id="1" root_project_id="1" qualifier="TRK"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Apache Struts"
+ uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
+ root_id="[null]"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+ <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
+ qualifier="TRK"/>
+
+ <resource_index kee="apache struts" position="0" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="pache struts" position="1" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="ache struts" position="2" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="che struts" position="3" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="he struts" position="4" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="e struts" position="5" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee=" struts" position="6" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="struts" position="7" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="truts" position="8" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="ruts" position="9" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="uts" position="10" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Apache Struts"
+ uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
+ root_id="[null]"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+ <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
+ qualifier="TRK"/>
+
+ <!-- the index is on the old name "Struts" but not on "Apache Struts -->
+ <resource_index id="1" kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index id="2" kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index id="3" kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index id="4" kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+
+</dataset>
--- /dev/null
+<dataset>
+ <resource_index kee="new struts" position="0" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="ew struts" position="1" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="w struts" position="2" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee=" struts" position="3" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="struts" position="4" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="truts" position="5" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="ruts" position="6" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index kee="uts" position="7" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset>
+ <resource_index id="1" kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index id="2" kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index id="3" kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+ <resource_index id="4" kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
+</dataset>
\ No newline at end of file
+++ /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 "struts" -> module "struts-core" -> package org.struts -> file "RequestContext" -->
- <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
- uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
- root_id="[null]"
- description="[null]"
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
- <projects long_name="[null]" id="2" scope="PRJ" qualifier="BRC" kee="org.struts:struts-core" name="Struts Core"
- uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
- root_id="1"
- description="[null]"
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
- <!-- note that the root_id of package/file is wrong. It references the module but not the root project -->
- <projects long_name="org.struts" id="3" scope="DIR" qualifier="PAC" kee="org.struts:struts-core:org.struts"
- uuid="CDEF" project_uuid="ABCD" module_uuid="BCDE" module_uuid_path=".ABCD.BCDE"
- name="org.struts" root_id="2"
- description="[null]"
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
- <projects long_name="org.struts.RequestContext" id="4" scope="CLA" qualifier="CLA"
- uuid="DEFG" project_uuid="ABCD" module_uuid="BCDE" module_uuid_path=".ABCD.BCDE"
- kee="org.struts:struts-core:org.struts.RequestContext"
- name="RequestContext" root_id="2"
- description="[null]"
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
- <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1"/>
- <snapshots purge_status="[null]" id="2" islast="[true]" root_project_id="1" project_id="2"/>
- <snapshots purge_status="[null]" id="3" islast="[true]" root_project_id="1" project_id="3"/>
- <snapshots purge_status="[null]" id="4" islast="[true]" root_project_id="1" project_id="4"/>
-
- <!-- The major goal is to test root_project_id -->
-
- <!-- RequestContext -->
- <resource_index kee="requestcontext" position="0" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
- <resource_index kee="equestcontext" position="1" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
- <resource_index kee="questcontext" position="2" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
- <resource_index kee="uestcontext" position="3" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
- <resource_index kee="estcontext" position="4" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
- <resource_index kee="stcontext" position="5" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
- <resource_index kee="tcontext" position="6" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
- <resource_index kee="context" position="7" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
- <resource_index kee="ontext" position="8" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
- <resource_index kee="ntext" position="9" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
- <resource_index kee="text" position="10" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
- <resource_index kee="ext" position="11" name_size="14" resource_id="4" root_project_id="1" qualifier="CLA"/>
-
- <!-- Struts -->
- <resource_index kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-
- <!-- Struts Core -->
- <resource_index kee="struts core" position="0" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
- <resource_index kee="truts core" position="1" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
- <resource_index kee="ruts core" position="2" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
- <resource_index kee="uts core" position="3" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
- <resource_index kee="ts core" position="4" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
- <resource_index kee="s core" position="5" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
- <resource_index kee=" core" position="6" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
- <resource_index kee="core" position="7" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
- <resource_index kee="ore" position="8" name_size="11" resource_id="2" root_project_id="1" qualifier="BRC"/>
-
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <!-- project "struts" -> module "struts-core" -> package org.struts -> file "RequestContext" -->
- <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
- uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
- root_id="[null]"
- description="[null]"
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
- <projects long_name="[null]" id="2" scope="PRJ" qualifier="BRC" kee="org.struts:struts-core" name="Struts Core"
- uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
- root_id="1"
- description="[null]"
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
- <!-- note that the root_id of package/file is wrong. It references the module but not the root project -->
- <projects long_name="org.struts" id="3" scope="DIR" qualifier="PAC" kee="org.struts:struts-core:org.struts"
- uuid="CDEF" project_uuid="ABCD" module_uuid="BCDE" module_uuid_path=".ABCD.BCDE"
- name="org.struts" root_id="2"
- description="[null]"
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
- <projects long_name="org.struts.RequestContext" id="4" scope="FIL" qualifier="CLA"
- uuid="DEFG" project_uuid="ABCD" module_uuid="BCDE" module_uuid_path=".ABCD.BCDE"
- kee="org.struts:struts-core:org.struts.RequestContext"
- name="RequestContext" root_id="2"
- description="[null]"
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
- <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1"/>
- <snapshots purge_status="[null]" id="2" islast="[true]" root_project_id="1" project_id="2"/>
- <snapshots purge_status="[null]" id="3" islast="[true]" root_project_id="1" project_id="3"/>
- <snapshots purge_status="[null]" id="4" islast="[true]" root_project_id="1" project_id="4"/>
-</dataset>
+++ /dev/null
-<dataset>
-
- <!-- project -->
- <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
- uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
- root_id="[null]"
- description="[null]"
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
- <!-- directory -->
- <projects long_name="org.struts" id="2" scope="DIR" qualifier="PAC" kee="org.struts:struts:org.struts"
- uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
- name="org.struts" root_id="1"
- description="[null]"
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
- <!-- file -->
- <projects long_name="org.struts.RequestContext" id="3" scope="CLA" qualifier="CLA"
- uuid="CDEF" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
- kee="org.struts:struts:org.struts.RequestContext"
- name="RequestContext" root_id="1"
- description="[null]"
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
- <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
- qualifier="TRK"/>
- <snapshots purge_status="[null]" id="2" islast="[true]" root_project_id="1" project_id="2" scope="DIR"
- qualifier="PAC"/>
- <snapshots purge_status="[null]" id="3" islast="[true]" root_project_id="1" project_id="3" scope="CLA"
- qualifier="CLA"/>
-
- <!-- RequestContext -->
- <resource_index kee="requestcontext" position="0" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
- <resource_index kee="equestcontext" position="1" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
- <resource_index kee="questcontext" position="2" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
- <resource_index kee="uestcontext" position="3" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
- <resource_index kee="estcontext" position="4" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
- <resource_index kee="stcontext" position="5" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
- <resource_index kee="tcontext" position="6" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
- <resource_index kee="context" position="7" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
- <resource_index kee="ontext" position="8" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
- <resource_index kee="ntext" position="9" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
- <resource_index kee="text" position="10" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
- <resource_index kee="ext" position="11" name_size="14" resource_id="3" root_project_id="1" qualifier="CLA"/>
-
- <!-- Struts -->
- <resource_index kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <!-- project -->
- <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
- uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
- root_id="[null]"
- description="[null]"
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
- <!-- directory -->
- <projects long_name="org.struts" id="2" scope="DIR" qualifier="PAC" kee="org.struts:struts:org.struts"
- uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
- name="org.struts" root_id="1"
- description="[null]"
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
- <!-- file -->
- <projects long_name="org.struts.RequestContext" id="3" scope="FIL" qualifier="CLA"
- kee="org.struts:struts:org.struts.RequestContext"
- uuid="CDEF" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
- name="RequestContext" root_id="1"
- description="[null]"
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
- <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
- qualifier="TRK"/>
- <snapshots purge_status="[null]" id="2" islast="[true]" root_project_id="1" project_id="2" scope="DIR"
- qualifier="PAC"/>
- <snapshots purge_status="[null]" id="3" islast="[true]" root_project_id="1" project_id="3" scope="FIL"
- qualifier="CLA"/>
-</dataset>
+++ /dev/null
-<dataset>
- <resource_index kee="ziputils" position="0" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
- <resource_index kee="iputils" position="1" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
- <resource_index kee="putils" position="2" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
- <resource_index kee="utils" position="3" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
- <resource_index kee="tils" position="4" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
- <resource_index kee="ils" position="5" name_size="8" resource_id="10" root_project_id="8" qualifier="FIL"/>
-</dataset>
\ No newline at end of file
+++ /dev/null
-<dataset></dataset>
+++ /dev/null
-<dataset>
- <resource_index kee="ab" position="0" name_size="2" resource_id="10" root_project_id="3" qualifier="TRK"/>
-</dataset>
\ No newline at end of file
+++ /dev/null
-<dataset></dataset>
+++ /dev/null
-<dataset>
-
- <!-- project -->
- <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
- uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
- root_id="[null]"
- description="[null]"
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
- <!-- directory -->
- <projects long_name="org.struts" id="2" scope="DIR" qualifier="PAC" kee="org.struts:struts:org.struts"
- uuid="BCDE" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
- name="org.struts" root_id="1"
- description="[null]"
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
- <!-- file -->
- <projects long_name="org.struts.RequestContext" id="3" scope="FIL" qualifier="CLA"
- kee="org.struts:struts:org.struts.RequestContext"
- uuid="CDEF" project_uuid="ABCD" module_uuid="ABCD" module_uuid_path=".ABCD."
- name="RequestContext" root_id="1"
- description="[null]"
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
- <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
- qualifier="TRK"/>
- <snapshots purge_status="[null]" id="2" islast="[true]" root_project_id="1" project_id="2" scope="DIR"
- qualifier="PAC"/>
- <snapshots purge_status="[null]" id="3" islast="[true]" root_project_id="1" project_id="3" scope="FIL"
- qualifier="CLA"/>
-</dataset>
+++ /dev/null
-<dataset>
- <resource_index kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-</dataset>
\ No newline at end of file
+++ /dev/null
-<dataset>
- <resource_index id="1" kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index id="2" kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index id="3" kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index id="4" kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-</dataset>
\ No newline at end of file
+++ /dev/null
-<dataset>
- <resource_index kee="as" position="0" name_size="2" resource_id="1" root_project_id="1" qualifier="TRK"/>
-</dataset>
\ No newline at end of file
+++ /dev/null
-<dataset>
-
- <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="AS"
- uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
- root_id="[null]"
- description="[null]"
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
- <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
- qualifier="TRK"/>
-
- <!-- the index is on the old name "ST" but not on "AS" -->
- <resource_index id="1" kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index id="2" kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index id="3" kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index id="4" kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-
-</dataset>
+++ /dev/null
-<dataset>
- <resource_index kee="as" position="0" name_size="2" resource_id="1" root_project_id="1" qualifier="TRK"/>
-</dataset>
\ No newline at end of file
+++ /dev/null
-<dataset>
-
- <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="AS"
- uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
- root_id="[null]"
- description="[null]"
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
- <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
- qualifier="TRK"/>
-
- <!-- the index is on the old name "ST" but not on "AS" -->
- <resource_index id="1" kee="st" position="0" name_size="2" resource_id="1" root_project_id="1" qualifier="TRK"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Apache Struts"
- uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
- root_id="[null]"
- description="[null]"
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
- <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
- qualifier="TRK"/>
-
- <resource_index kee="apache struts" position="0" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="pache struts" position="1" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="ache struts" position="2" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="che struts" position="3" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="he struts" position="4" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="e struts" position="5" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee=" struts" position="6" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="struts" position="7" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="truts" position="8" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="ruts" position="9" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="uts" position="10" name_size="13" resource_id="1" root_project_id="1" qualifier="TRK"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Apache Struts"
- uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."
- root_id="[null]"
- description="[null]"
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
- <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ"
- qualifier="TRK"/>
-
- <!-- the index is on the old name "Struts" but not on "Apache Struts -->
- <resource_index id="1" kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index id="2" kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index id="3" kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index id="4" kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-
-</dataset>
+++ /dev/null
-<dataset>
- <resource_index kee="new struts" position="0" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="ew struts" position="1" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="w struts" position="2" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee=" struts" position="3" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="struts" position="4" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="truts" position="5" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="ruts" position="6" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index kee="uts" position="7" name_size="10" resource_id="1" root_project_id="1" qualifier="TRK"/>
-</dataset>
\ No newline at end of file
+++ /dev/null
-<dataset>
- <resource_index id="1" kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index id="2" kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index id="3" kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
- <resource_index id="4" kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1" qualifier="TRK"/>
-</dataset>
\ No newline at end of file