use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class PropertiesDaoTest method insertProperty.
private long insertProperty(String key, @Nullable String value, @Nullable Long resourceId, @Nullable Integer userId) throws SQLException {
DbSession session = dbTester.getSession();
PropertyDto dto = new PropertyDto().setKey(key).setResourceId(resourceId == null ? null : resourceId.longValue()).setUserId(userId == null ? null : userId).setValue(value);
dbTester.getDbClient().propertiesDao().saveProperty(session, dto);
session.commit();
return (long) dbTester.selectFirst(session, "select id as \"id\" from properties" + " where prop_key='" + key + "'" + " and user_id" + (userId == null ? " is null" : "='" + userId + "'") + " and resource_id" + (resourceId == null ? " is null" : "='" + resourceId + "'")).get("id");
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class QualityProfileTesting method insert.
public static void insert(DbTester dbTester, QProfileChangeDto... dtos) {
// do not use QProfileChangeDao so that generated fields key and creation date
// can be defined by tests
DbSession dbSession = dbTester.getSession();
QProfileChangeMapper mapper = dbSession.getMapper(QProfileChangeMapper.class);
stream(dtos).forEach(dto -> mapper.insert(dto));
dbSession.commit();
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class RuleRepositoryDaoTest method truncate.
@Test
public void truncate() {
DbSession dbSession = dbTester.getSession();
RuleRepositoryDto dto1 = new RuleRepositoryDto("findbugs", "java", "Findbugs");
RuleRepositoryDto dto2 = new RuleRepositoryDto("squid", "java", "Java");
underTest.insert(dbSession, asList(dto1, dto2));
underTest.truncate(dbSession);
assertThat(underTest.selectAll(dbSession)).isEmpty();
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class RuleRepositoryDaoTest method selectByKey.
@Test
public void selectByKey() {
DbSession dbSession = dbTester.getSession();
RuleRepositoryDto dto1 = new RuleRepositoryDto("findbugs", "java", "Findbugs");
underTest.insert(dbSession, asList(dto1));
assertThat(underTest.selectByKey(dbSession, "findbugs").get().getKey()).isEqualTo("findbugs");
assertThat(underTest.selectByKey(dbSession, "missing")).isNotPresent();
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class CeQueueImpl method massSubmit.
@Override
public List<CeTask> massSubmit(Collection<CeTaskSubmit> submissions) {
checkState(!submitPaused.get(), "Compute Engine does not currently accept new tasks");
if (submissions.isEmpty()) {
return Collections.emptyList();
}
try (DbSession dbSession = dbClient.openSession(true)) {
List<CeQueueDto> ceQueueDtos = from(submissions).transform(new CeTaskSubmitToInsertedCeQueueDto(dbSession, dbClient)).toList();
List<CeTask> tasks = loadTasks(dbSession, ceQueueDtos);
dbSession.commit();
return tasks;
}
}
Aggregations