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