@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()); }
public Optional<Date> getLatestSnaphotDateBefore(final String organization, final Date snapshot) { QStatistics statistics = QStatistics.statistics; List<Statistics> statisticList = new JPAQuery(entityManager).from(statistics) .where((statistics.key.snapshotDate.before(snapshot) .or(statistics.key.snapshotDate.eq(snapshot)) .and(statistics.organizationName.eq(organization)))) // .where(statistics.organizationName.eq(organization)) .orderBy(statistics.key.snapshotDate.desc()).limit(1).list(statistics); return statisticList.isEmpty() ? Optional.empty() : Optional.ofNullable(statisticList.get(0).getSnapshotDate()); }
@Override public List<DeletedWorklog> getWorklogsDeletedSince(final Long sinceInMilliseconds, final int maxResults) { final QChangeItem ci = QChangeItem.CHANGE_ITEM; final QChangeGroup cg = QChangeGroup.CHANGE_GROUP; final QWorklog w = WORKLOG; NumberExpression<Long> oldValueExpression = isOracle() ? convertToNumber(ci.oldvalue) : ci.oldvalue.castToNum(Long.class); List<Tuple> removedWorklogs = getRemovedWorklogs(sinceInMilliseconds, maxResults, ci, cg, w, oldValueExpression); return removedWorklogs .stream() .map(t -> new DeletedWorklog(t.get(oldValueExpression), new Date(t.get(cg.created.max()).getTime()))) .collect(Collectors.toList()); }
@Test public void DayOfMonth2() { assertToString("day(date)", new DateTimePath<Date>(Date.class, "date").dayOfMonth()); }
@Test public void Date() { query().from(cat).list(cat.birthdate.year()); query().from(cat).list(cat.birthdate.yearMonth()); query().from(cat).list(cat.birthdate.month()); //query().from(cat).list(cat.birthdate.week()); query().from(cat).list(cat.birthdate.dayOfMonth()); query().from(cat).list(cat.birthdate.hour()); query().from(cat).list(cat.birthdate.minute()); query().from(cat).list(cat.birthdate.second()); }
public Optional<Date> getEarliestSnaphotDate(final String organization) { QStatistics statistics = QStatistics.statistics; List<Statistics> statisticList = new JPAQuery(entityManager).from(statistics) .where(statistics.organizationName.eq(organization)) .orderBy(statistics.key.snapshotDate.asc()).limit(1).list( statistics); return statisticList.isEmpty() ? Optional.empty() : Optional.ofNullable(statisticList.get(0).getSnapshotDate()); } }
@Override public List<Project> findProjects(String organization, Optional<String> query, Optional<String> language) { DateTimeSubQuery<Date> lastSnapshot = new JPASubQuery().from(project) .where(project.organizationName.eq(organization)) .unique(project.snapshotDate.max()); BooleanBuilder q = new BooleanBuilder() .and(project.organizationName.eq(organization)) .and(project.snapshotDate.eq(lastSnapshot)); if (query.isPresent()) { q.and(project.name.startsWith(query.get())); } if (language.isPresent()) { q.and(project.primaryLanguage.eq(language.get())); } return queryProject().where(q).list(project); }
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())); }
@Override public List<Project> findProjects(String organization, Date snapshotDate, Optional<String> query, Optional<String> language) { BooleanBuilder q = new BooleanBuilder(project.organizationName.eq(organization)); Optional<Date> snapshotDateMatch = getSnapshotDateMatch(snapshotDate, organization); if (!snapshotDateMatch.isPresent()) { return Collections.emptyList(); } q.and(project.snapshotDate.eq(snapshotDateMatch.get())); if (query.isPresent()) { q.and(project.name.startsWith(query.get())); } if (language.isPresent()) { q.and(project.primaryLanguage.eq(language.get())); } return queryProject().where(q).list(project); }
/** * @param snapshot * * @return date that is closest in the past. If there is no earlier date in * the past, nothing is returned */ private Optional<Date> getSnapshotDateMatch(Date snapshot, String organization) { return queryProject() .where( project.organizationName.eq(organization) .and(project.snapshotDate.loe(snapshot)) ) .orderBy(project.snapshotDate.desc()) .limit(1) .list(project) .stream() .findFirst() .map(Project::getSnapshotDate); }
@Override public <T extends Comparable<?>> Path<T> createDateTimePath(Class<T> type, PathMetadata<?> metadata) { return new DateTimePath<T>(type, metadata); }
@Test public void List_Non_Path() { assertEquals(6, query().from(cat).where(cat.dtype.eq("C")).list( cat.birthdate.year(), cat.birthdate.month(), cat.birthdate.dayOfMonth()).size()); }
@Test @NoBatooJPA @NoHibernate public void Count_Distinct2() { QCat cat = QCat.cat; query().from(cat) .groupBy(cat.id) .list(cat.id, cat.birthdate.dayOfMonth().countDistinct()); }
@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()); }
@Test public void DocoExamples98_9() throws Exception { query().from(person, calendar).select(person).where( calendar.holidays("national holiday").eq(person.birthDay), person.nationality.calendar.eq(calendar)).parse(); }
/** * Create a new Path expression * * @param type * @param parent * @param property * @return */ public static <T extends Comparable<?>> DateTimePath<T> dateTimePath(Class<T> type, Path<?> parent, String property) { return new DateTimePath<T>(type, PathMetadataFactory.forProperty(parent, property)); }
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)); }); }
assertEquals(literals.date, session.from($(l)).where($(l.getDate()).eq(literals.date)).uniqueResult($(l.getDate()))); assertEquals(literals.date2, session.from($(l)).where($(l.getDate2()).eq(literals.date2)).uniqueResult($(l.getDate2()))); assertEquals(literals.dateTime.getMillis(), session.from($(l)).where($(l.getDateTime()).eq(literals.dateTime)).uniqueResult($(l.getDateTime())).getMillis()); assertEquals(literals.localTime, session.from($(l)).where($(l.getLocalTime()).eq(literals.localTime)).uniqueResult($(l.getLocalTime()))); assertEquals(literals.time, session.from($(l)).where($(l.getTime()).eq(literals.time)).uniqueResult($(l.getTime()))); assertEquals(literals.timestamp, session.from($(l)).where($(l.getTimestamp()).eq(literals.timestamp)).uniqueResult($(l.getTimestamp()))); assertEquals(1, session.from($(l)).where($(l.getDate()).eq(literals.date)).count()); assertEquals(1, session.from($(l)).where($(l.getDate2()).eq(literals.date2)).count()); assertEquals(1, session.from($(l)).where($(l.getDateTime()).eq(literals.dateTime)).count()); assertEquals(1, session.from($(l)).where($(l.getLocalTime()).eq(literals.localTime)).count()); assertEquals(1, session.from($(l)).where($(l.getTime()).eq(literals.time)).count()); assertEquals(1, session.from($(l)).where($(l.getTimestamp()).eq(literals.timestamp)).count());
@Test @Ignore // FIXME public void test() { QCat cat = QCat.cat; SubQueryExpression<?> subQuery = subQuery().from(cat) .where(subQuery() .from(cat) .groupBy(cat.mate) .list(new QTuple(cat.mate, cat.birthdate.max())) .contains(new QTuple(cat.mate, cat.birthdate))) .list(new QTuple(cat.birthdate, cat.name, cat.mate)); assertToString( "(select cat.birthdate, cat.name, cat.mate from Cat cat " + "where (cat.mate, cat.birthdate) in " + "(select cat.mate, max(cat.birthdate) from Cat cat group by cat.mate))", subQuery); }
/** * Create a new Path expression * * @param type * @param variable * @return */ public static <T extends Comparable<?>> DateTimePath<T> dateTimePath(Class<T> type, String variable) { return new DateTimePath<T>(type, PathMetadataFactory.forVariable(variable)); }