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");
}
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;
}
}
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());
}
}
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);
}
}
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);
}
}
Aggregations