Search in sources :

Example 11 with DbSession

use of org.sonar.db.DbSession in project sonarqube by SonarSource.

the class RuleRepositoryDaoTest method selectByLanguage.

@Test
public void selectByLanguage() {
    DbSession dbSession = dbTester.getSession();
    RuleRepositoryDto dto1 = new RuleRepositoryDto("findbugs", "java", "Findbugs");
    RuleRepositoryDto dto2 = new RuleRepositoryDto("squid", "java", "Java");
    RuleRepositoryDto dto3 = new RuleRepositoryDto("cobol-lint", "cobol", "Cobol Lint");
    underTest.insert(dbSession, asList(dto1, dto2, dto3));
    assertThat(underTest.selectByLanguage(dbSession, "java")).extracting(RuleRepositoryDto::getKey).containsExactly("findbugs", "squid");
}
Also used : DbSession(org.sonar.db.DbSession) Test(org.junit.Test)

Example 12 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)

Example 13 with DbSession

use of org.sonar.db.DbSession in project sonarqube by SonarSource.

the class SuggestionsAction method getResultsOfAllQualifiers.

private List<Qualifier> getResultsOfAllQualifiers(String query) {
    ComponentIndexQuery componentIndexQuery = new ComponentIndexQuery(query).setQualifiers(Arrays.asList(QUALIFIERS)).setLimit(NUMBER_OF_RESULTS_PER_QUALIFIER);
    List<ComponentsPerQualifier> componentsPerQualifiers = searchInIndex(componentIndexQuery);
    if (componentsPerQualifiers.isEmpty()) {
        return Collections.emptyList();
    }
    try (DbSession dbSession = dbClient.openSession(false)) {
        return componentsPerQualifiers.stream().map(qualifier -> {
            List<String> uuids = qualifier.getComponentUuids();
            List<ComponentDto> componentDtos = dbClient.componentDao().selectByUuids(dbSession, uuids);
            List<ComponentDto> sortedComponentDtos = Ordering.explicit(uuids).onResultOf(ComponentDto::uuid).immutableSortedCopy(componentDtos);
            Map<String, String> organizationKeyByUuids = getOrganizationKeys(dbSession, componentDtos);
            List<Component> results = sortedComponentDtos.stream().map(dto -> dtoToComponent(dto, organizationKeyByUuids)).collect(Collectors.toList());
            return Qualifier.newBuilder().setQ(qualifier.getQualifier()).addAllItems(results).build();
        }).collect(Collectors.toList());
    }
}
Also used : Arrays(java.util.Arrays) Qualifier(org.sonarqube.ws.WsComponents.SuggestionsWsResponse.Qualifier) DbSession(org.sonar.db.DbSession) ACTION_SUGGESTIONS(org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_SUGGESTIONS) Request(org.sonar.api.server.ws.Request) WebService(org.sonar.api.server.ws.WebService) ComponentIndexQuery(org.sonar.server.component.index.ComponentIndexQuery) Map(java.util.Map) Response(org.sonar.api.server.ws.Response) OrganizationDto(org.sonar.db.organization.OrganizationDto) SuggestionsWsResponse(org.sonarqube.ws.WsComponents.SuggestionsWsResponse) Resources(com.google.common.io.Resources) Collectors(org.sonar.core.util.stream.Collectors) Component(org.sonarqube.ws.WsComponents.Component) NewAction(org.sonar.api.server.ws.WebService.NewAction) Preconditions.checkState(com.google.common.base.Preconditions.checkState) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Ordering(com.google.common.collect.Ordering) Qualifiers(org.sonar.api.resources.Qualifiers) ComponentIndex(org.sonar.server.component.index.ComponentIndex) ComponentsPerQualifier(org.sonar.server.component.index.ComponentsPerQualifier) Collections(java.util.Collections) WsUtils.writeProtobuf(org.sonar.server.ws.WsUtils.writeProtobuf) DbSession(org.sonar.db.DbSession) ComponentsPerQualifier(org.sonar.server.component.index.ComponentsPerQualifier) ComponentDto(org.sonar.db.component.ComponentDto) ComponentIndexQuery(org.sonar.server.component.index.ComponentIndexQuery) List(java.util.List) Map(java.util.Map)

Example 14 with DbSession

use of org.sonar.db.DbSession in project sonarqube by SonarSource.

the class InternalCeQueueImpl method remove.

@Override
public void remove(CeTask task, CeActivityDto.Status status, @Nullable CeTaskResult taskResult, @Nullable Throwable error) {
    checkArgument(error == null || status == CeActivityDto.Status.FAILED, "Error can be provided only when status is FAILED");
    try (DbSession dbSession = dbClient.openSession(false)) {
        Optional<CeQueueDto> queueDto = dbClient.ceQueueDao().selectByUuid(dbSession, task.getUuid());
        checkState(queueDto.isPresent(), "Task does not exist anymore: %s", task);
        CeActivityDto activityDto = new CeActivityDto(queueDto.get());
        activityDto.setStatus(status);
        updateQueueStatus(status, activityDto);
        updateTaskResult(activityDto, taskResult);
        updateError(activityDto, error);
        remove(dbSession, queueDto.get(), activityDto);
    }
}
Also used : DbSession(org.sonar.db.DbSession) CeActivityDto(org.sonar.db.ce.CeActivityDto) CeQueueDto(org.sonar.db.ce.CeQueueDto)

Example 15 with DbSession

use of org.sonar.db.DbSession in project sonarqube by SonarSource.

the class InternalCeQueueImpl method peek.

@Override
public Optional<CeTask> peek() {
    if (peekPaused.get()) {
        return Optional.absent();
    }
    try (DbSession dbSession = dbClient.openSession(false)) {
        Optional<CeQueueDto> dto = dbClient.ceQueueDao().peek(dbSession);
        CeTask task = null;
        if (dto.isPresent()) {
            task = loadTask(dbSession, dto.get());
            queueStatus.addInProgress();
        }
        return Optional.fromNullable(task);
    }
}
Also used : DbSession(org.sonar.db.DbSession) CeQueueDto(org.sonar.db.ce.CeQueueDto) CeTask(org.sonar.ce.queue.CeTask)

Aggregations

DbSession (org.sonar.db.DbSession)254 ComponentDto (org.sonar.db.component.ComponentDto)63 OrganizationDto (org.sonar.db.organization.OrganizationDto)30 JsonWriter (org.sonar.api.utils.text.JsonWriter)24 UserDto (org.sonar.db.user.UserDto)20 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)16 Test (org.junit.Test)13 MetricDto (org.sonar.db.metric.MetricDto)13 Paging (org.sonar.api.utils.Paging)12 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)10 CeQueueDto (org.sonar.db.ce.CeQueueDto)8 DepthTraversalTypeAwareCrawler (org.sonar.server.computation.task.projectanalysis.component.DepthTraversalTypeAwareCrawler)8 SearchOptions (org.sonar.server.es.SearchOptions)8 NotFoundException (org.sonar.server.exceptions.NotFoundException)8 List (java.util.List)7 SnapshotDto (org.sonar.db.component.SnapshotDto)7 GroupDto (org.sonar.db.user.GroupDto)7 DbClient (org.sonar.db.DbClient)6 ProjectId (org.sonar.server.permission.ProjectId)6 RuleKey (org.sonar.api.rule.RuleKey)5