@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()); }
@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 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; }
@Override public Worklog getById(final Long id) { if (id == null) { return null; } final Tuple worklogTuple = dbConnectionManager.executeQuery(dc -> dc.newSqlQuery() .from(WORKLOG) .leftJoin(QProjectRole.PROJECT_ROLE) .on(QProjectRole.PROJECT_ROLE.id.eq(WORKLOG.rolelevel)) .where(WORKLOG.id.eq(id)) .singleResult(WORKLOG_ALIASED_PROJECT_ROLE_TUPLE)); return queryDSLWorklogFactory.createWorklogWithAliasedIdColumn(worklogTuple); }
@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())); }