public ConstantsCache<Resolution> get() { final List<ResolutionDTO> resolutionList = dbConnectionManager.executeQuery(dbConnection -> dbConnection.newSqlQuery().from(RESOLUTION) .orderBy(RESOLUTION.sequence.asc()).list(RESOLUTION)); final ImmutableMap.Builder<String, Resolution> builder = ImmutableMap.builder(); resolutionList.stream().map(issueConstantFactory::createResolution).forEach(r -> builder.put(r.getId(), r)); return new ConstantsCache<>(builder.build()); } }
public List<IssueType> getEditableSubTaskIssueTypes() { final List<String> ids = dbConnectionManager.executeQuery(dbConnection -> dbConnection.newSqlQuery() .from(ISSUE_TYPE) .where(ISSUE_TYPE.style.eq(SubTaskManager.SUB_TASK_ISSUE_TYPE_STYLE)) .list(bean(ISSUE_TYPE.id))); final ImmutableList.Builder<IssueType> listBuilder = ImmutableList.builder(); ids.stream().map(this::getIssueType).forEach(listBuilder::add); return listBuilder.build(); }
public ConstantsCache<Priority> get() { final List<PriorityDTO> priorityList = dbConnectionManager.executeQuery(dbConnection -> dbConnection.newSqlQuery().from(PRIORITY) .orderBy(PRIORITY.sequence.asc()).list(PRIORITY)); final ImmutableMap.Builder<String, Priority> builder = ImmutableMap.builder(); priorityList.stream().map(issueConstantFactory::createPriority).forEach(p -> builder.put(p.getId(), p)); return new ConstantsCache<>(builder.build()); } }
public ConstantsCache<Status> get() { final List<StatusDTO> statusList = dbConnectionManager.executeQuery(dbConnection -> dbConnection.newSqlQuery().from(STATUS) .orderBy(STATUS.sequence.asc()).list(STATUS)); final ImmutableMap.Builder<String, Status> builder = ImmutableMap.builder(); statusList.stream().map(issueConstantFactory::createStatus).forEach(r -> builder.put(r.getId(), r)); return new ConstantsCache<>(builder.build()); } }
private List<String> getConfigurationGroupIds(int startIndex, int pageSize) { final Connection connection = connectionProvider.borrowConnection(); try{ final SQLQuery select = queryFactory.select(connection); final QProjectConfiguration PROJECT_CONFIG = QProjectConfiguration.withSchema(schemaProvider); // We are grabbing all the ids cause SQL Server has bugs with the offset too... final List<String> list = select.from(PROJECT_CONFIG).distinct() .list(PROJECT_CONFIG.CONFIGURATION_GROUP_ID); if(startIndex > list.size()){ logger.warn(" The startIndex [{}] asked for HipChat configurations is more than the list itself [{}].", startIndex, list.size()); return ImmutableList.<String>of(); } //Fixing the overflow int currentPageSize = Math.min(startIndex + pageSize, list.size()) - startIndex; return list.subList(startIndex, currentPageSize); }finally{ connectionProvider.returnConnection(connection); } }
@Override public String getProperty(final String key) { String cacheValue = cache.get(key); if (cacheValue != null) { return cacheValue; } else { try (Connection connection = dataSource.getConnection()) { SQLQuery sqlQuery = new SQLQuery(connection, sqlTemplates); QProperties prop = QProperties.propProperties; List<String> values = sqlQuery.from(prop).where(prop.key.eq(key)).list(prop.value); if (values.isEmpty()) { return null; } else { return values.get(0); } } catch (SQLException e) { throw new PropertyServiceDataSourceConnectionException("Cannot connect to DataSource.", e); } } }
@Override public Set<Worklog> getWorklogsForIds(final Set<Long> worklogIds, final int maxResults) { return dbConnectionManager.executeQuery(dbConnection -> dbConnection.newSqlQuery() .from(WORKLOG) .leftJoin(QProjectRole.PROJECT_ROLE) .on(QProjectRole.PROJECT_ROLE.id.eq(WORKLOG.rolelevel)) .where(WORKLOG.id.in(worklogIds)) .limit(maxResults) .list(WORKLOG_ALIASED_PROJECT_ROLE_TUPLE) ).stream() .map(queryDSLWorklogFactory::createWorklogWithAliasedIdColumn) .collect(Collectors.toSet()); }
public IssueTypeCache get() { final List<IssueTypeDTO> issueTypeList = dbConnectionManager.executeQuery(dbConnection -> dbConnection.newSqlQuery().from(ISSUE_TYPE) .orderBy(ISSUE_TYPE.style.asc()).orderBy(ISSUE_TYPE.sequence.asc()).list(ISSUE_TYPE)); final ImmutableMap.Builder<String, IssueType> builder = ImmutableMap.builder(); final ImmutableList.Builder<IssueType> regularIssueTypesBuilder = ImmutableList.builder(); final ImmutableList.Builder<IssueType> subTaskIssueTypesBuilder = ImmutableList.builder(); issueTypeList.stream().map(issueConstantFactory::createIssueType).forEach(new Consumer<IssueType>() { @Override public void accept(final IssueType issueType) { if (issueType.isSubTask()) { subTaskIssueTypesBuilder.add(issueType); } else { regularIssueTypesBuilder.add(issueType); } builder.put(issueType.getId(), issueType); } }); return new IssueTypeCache(builder.build(), regularIssueTypesBuilder.build(), subTaskIssueTypesBuilder.build()); } }
@VisibleForTesting List<Integer> findDowngradeTasksToRun() throws DowngradeException { // Get all upgrade tasks that have run from the UpgradeHistory table in the DB final List<UpgradeHistoryDTO> upgradeHistoryItems = dbConnectionManager.executeQuery( dbConnection -> dbConnection.newSqlQuery() .from(QUpgradeHistory.UPGRADE_HISTORY) .list(QUpgradeHistory.UPGRADE_HISTORY) ); return DowngradeUtil.findDowngradeTasksToRun(upgradeHistoryItems, buildUtilsInfo.getApplicationBuildNumber()); }
private boolean lockOnResource(final Connection connection, final Configuration configuration, final long resourceId) { SQLQuery query = new SQLQuery(connection, configuration); QResource resource = QResource.resource; List<Long> results = query.from(resource).where(resource.resourceId.eq(resourceId)).forUpdate() .list(resource.resourceId); return !(results.size() == 0); }
@Override @Nonnull public Set<ProjectRoleActor> getAllRoleActorsForUser(@Nullable final ApplicationUser user) { if (user == null) { return ImmutableSet.of(); } final String userKey = user.getKey(); final ImmutableSet.Builder<ProjectRoleActor> resultsBuilder = ImmutableSet.builder(); dbConnectionManager.execute(dbConnection -> { final QProjectRoleActor pra = new QProjectRoleActor("pra"); final List<Tuple> roleActorTuples = dbConnection.newSqlQuery(). from(pra). where(pra.roletype.eq(USER_ROLE_ACTOR_TYPE). and(pra.roletypeparameter.eq(user.getKey())). and(pra.pid.isNotNull())). list(Projections.tuple(pra.id, pra.pid, pra.projectroleid, pra.roletype, pra.roletypeparameter)); roleActorTuples.stream().map(tuple -> new UserRoleActor(tuple, pra, userKey)).forEach(resultsBuilder::add); }); return resultsBuilder.build(); }
@Override public List<Worklog> getWorklogsUpdateSince(final Long sinceInMiliseconds, final int maxResults) { return dbConnectionManager.executeQuery(dbConnection -> dbConnection.newSqlQuery() .from(WORKLOG) .leftJoin(QProjectRole.PROJECT_ROLE) .on(QProjectRole.PROJECT_ROLE.id.eq(WORKLOG.rolelevel)) .where(WORKLOG.updated.goe(new Timestamp(sinceInMiliseconds)) .and(WORKLOG.updated.loe(new Timestamp(minuteAgo())))) .orderBy(WORKLOG.updated.asc()) .limit(maxResults) .list(WORKLOG_ALIASED_PROJECT_ROLE_TUPLE) ).stream() .map(queryDSLWorklogFactory::createWorklogWithAliasedIdColumn) .collect(Collectors.toList()); }
@Override public List<Worklog> getByIssue(final Issue issue) { checkArgument(issue != null, "Cannot resolve worklogs for null issue."); final BooleanExpression query = issue.getId() != null ? WORKLOG.issue.eq(issue.getId()) : WORKLOG.issue.isNull(); return dbConnectionManager.executeQuery(dc -> dc.newSqlQuery() .from(WORKLOG) .leftJoin(QProjectRole.PROJECT_ROLE) .on(QProjectRole.PROJECT_ROLE.id.eq(WORKLOG.rolelevel)) .where(query) .orderBy(WORKLOG.created.asc()) .list(WORKLOG_PROJECT_ROLE_TUPLE) ).stream() .map(t -> queryDSLWorklogFactory.createWorklog(issue, t)) .collect(Collectors.toList()); }
private long[] readParentResourceIdsFromDatabase(final long resourceId) { return querydslSupport.execute((connection, configuration) -> { SQLQuery query = new SQLQuery(connection, configuration); QPermissionInheritance permissioninheritance = QPermissionInheritance.permissionInheritance; List<Long> result = query.from(permissioninheritance) .where(permissioninheritance.childResourceId.eq(resourceId)) .list(permissioninheritance.parentResourceId); return AuthorizationImpl.convertCollectionToLongArray(result); }); }
private List<AuditEventType> selectAuditEventTypes(final String applicationName, final List<String> eventTypeNames) { return querydslSupport.execute((connection, configuration) -> { QEventType qEventType = QEventType.eventType; QApplication qApplication = QApplication.application; List<AuditEventType> rval = new ArrayList<>(); int numberOfEventTypeNames = eventTypeNames.size(); for (int fromIndex = 0; fromIndex < numberOfEventTypeNames; fromIndex = fromIndex + SELECT_AUDIT_EVENT_TYPES_PAGE_SIZE) { int toIndex = fromIndex + SELECT_AUDIT_EVENT_TYPES_PAGE_SIZE; if (toIndex > numberOfEventTypeNames) { toIndex = numberOfEventTypeNames; } List<String> actualEventTypeNames = new ArrayList<>(eventTypeNames.subList(fromIndex, toIndex)); List<AuditEventType> auditEventTypes = new SQLQuery(connection, configuration) .from(qEventType) .innerJoin(qApplication).on(qEventType.applicationId.eq(qApplication.applicationId)) .where(qApplication.applicationName.eq(applicationName) .and(qEventType.eventTypeName.in(actualEventTypeNames))) .list(Projections.fields(AuditEventType.class, qEventType.eventTypeId, qEventType.eventTypeName, qEventType.resourceId)); rval.addAll(auditEventTypes); } return rval; }); }
private List<Long> getMinusOneUserLocalePropertyIds(DbConnection dbConnection) { QOSPropertyEntry propertyEntry = QOSPropertyEntry.O_S_PROPERTY_ENTRY; QOSPropertyString propertyString = QOSPropertyString.O_S_PROPERTY_STRING; // MSSQL meet incompatible data type problem when we use equal operator (IN, EQUALS) so we have to use LIKE instead List<Long> propertyIds = dbConnection.newSqlQuery().from(propertyEntry).join(propertyString) .on(propertyEntry.id.eq(propertyString.id)) .where(propertyEntry.propertyKey.eq("jira.user.locale").and(propertyString.value.like("-1"))) .list(propertyString.id); return propertyIds; }
private List<QueuedEmailDTO> selectQueuedEmailForUpdate(final int limit) { return querydslSupport.execute((connection, configuration) -> { QEmailQueue qEmailQueue = QEmailQueue.emailQueue; return new SQLQuery(connection, configuration) .from(qEmailQueue) .orderBy(qEmailQueue.timestamp_.asc(), qEmailQueue.queuedEmailId.asc()) .limit(limit) .forUpdate() .list(Projections.fields(QueuedEmailDTO.class, qEmailQueue.queuedEmailId, qEmailQueue.storedEmailId)); }); }
@Override public void run(final DbConnection dbConnection) { final List<? extends ProjectComponent> results = dbConnection.newSqlQuery().from(na) .join(c).on(c.id.eq(na.sinkNodeId)) .where(na.sourceNodeEntity.eq("Issue") .and(na.sourceNodeId.eq(issue.getId())) .and(na.sinkNodeEntity.eq("Component")) .and(na.associationType.eq("IssueComponent"))) .list(Projections.constructor(ProjectComponentImpl.class, c.id, c.name, c.description, c.lead, c.assigneetype, c.project)); components.addAll(results); } });
private List<Tuple> getRemovedWorklogs(final Long sinceInMilliseconds, final int maxResults, final QChangeItem ci, final QChangeGroup cg, final QWorklog w, final NumberExpression<Long> oldValueExpression) { return dbConnectionManager.executeQuery(dbConnection -> dbConnection.newSqlQuery() .from(ci) .leftJoin(cg) .on(ci.group.eq(cg.id)) .where(ci.field.eq(IssueFieldConstants.WORKLOG_ID) .and(cg.created.goe(new Timestamp(sinceInMilliseconds)) .and(cg.created.loe(new Timestamp(minuteAgo())))) .and(oldValueExpression.notIn(new SQLSubQuery() .from(w) .list(w.id)) ) ) .groupBy(oldValueExpression) .orderBy(cg.created.max().asc()) .limit(maxResults) .list(oldValueExpression, cg.created.max())); }