Search in sources :

Example 1 with DbSession

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");
}
Also used : DbSession(org.sonar.db.DbSession) PropertyTesting.newUserPropertyDto(org.sonar.db.property.PropertyTesting.newUserPropertyDto) PropertyTesting.newComponentPropertyDto(org.sonar.db.property.PropertyTesting.newComponentPropertyDto) PropertyTesting.newGlobalPropertyDto(org.sonar.db.property.PropertyTesting.newGlobalPropertyDto)

Example 2 with DbSession

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();
}
Also used : DbSession(org.sonar.db.DbSession)

Example 3 with DbSession

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();
}
Also used : DbSession(org.sonar.db.DbSession) Test(org.junit.Test)

Example 4 with DbSession

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();
}
Also used : DbSession(org.sonar.db.DbSession) Test(org.junit.Test)

Example 5 with DbSession

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;
    }
}
Also used : DbSession(org.sonar.db.DbSession) CeQueueDto(org.sonar.db.ce.CeQueueDto)

Aggregations

DbSession (org.sonar.db.DbSession)628 ComponentDto (org.sonar.db.component.ComponentDto)122 Test (org.junit.Test)87 List (java.util.List)76 DbClient (org.sonar.db.DbClient)70 UserDto (org.sonar.db.user.UserDto)67 Map (java.util.Map)51 ProjectDto (org.sonar.db.project.ProjectDto)50 Set (java.util.Set)43 Collectors (java.util.stream.Collectors)41 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)38 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)35 NotFoundException (org.sonar.server.exceptions.NotFoundException)35 Nullable (javax.annotation.Nullable)33 System2 (org.sonar.api.utils.System2)32 BranchDto (org.sonar.db.component.BranchDto)32 Optional (java.util.Optional)31 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)31 WebService (org.sonar.api.server.ws.WebService)29 ArrayList (java.util.ArrayList)28