public List<LogEvent> findByAppIdAfterDate( String appId, LogEvent lastRow, Date fromDate, int limit, boolean isPrevPaging) { Select sel = QueryBuilder.select().from(table).limit(limit); Where w = sel.where(QueryBuilder.eq(pkCols[0], appId)); if (lastRow != null) { if (isPrevPaging) { w.and(QueryBuilder.gt(timeuuidCol, lastRow.getId().getTimestamp())); } else { w.and(QueryBuilder.lt(timeuuidCol, lastRow.getId().getTimestamp())); w.and(QueryBuilder.gt(timeuuidCol, QueryBuilder.fcall(FN_MAXTIMEUUID, fromDate))); } } else { w.and(QueryBuilder.gt(timeuuidCol, QueryBuilder.fcall(FN_MAXTIMEUUID, fromDate))); } if (isPrevPaging) sel.orderBy(QueryBuilder.asc(timeuuidCol)); log.debug(">>>>>>>>> Firing select query: " + sel.toString()); List<LogEvent> events = cassandraOperations.select(sel, LogEvent.class); if (isPrevPaging) { Collections.sort( events, new Comparator<LogEvent>() { @Override public int compare(LogEvent o1, LogEvent o2) { return o2.getId().getTimestamp().compareTo(o1.getId().getTimestamp()); } }); } return events; }
public List<LogEvent> findByAppIdBeforeDateContains( String appId, String token, LogEvent lastRow, final Date toDate, int limit, boolean isPrevPaging) { Select sel = QueryBuilder.select().from(table).limit(limit); Where w = sel.where(QueryBuilder.eq(pkCols[0], appId)); w.and( QueryBuilder.eq( luceneCol, Builder.search() .filter(Builder.phrase(logTextCol, token)) .sort(SortField.field(timeuuidCol).reverse(isPrevPaging)) .build())); if (lastRow != null) { if (isPrevPaging) { w.and( QueryBuilder.lt( timeuuidCol, QueryBuilder.fcall(FN_MINTIMEUUID, CommonHelper.formatAsCassandraDate(toDate)))); w.and(QueryBuilder.gt(timeuuidCol, lastRow.getId().getTimestamp())); } else { w.and(QueryBuilder.lt(timeuuidCol, lastRow.getId().getTimestamp())); } } else { w.and( QueryBuilder.lt( timeuuidCol, QueryBuilder.fcall(FN_MINTIMEUUID, CommonHelper.formatAsCassandraDate(toDate)))); } log.debug(">>>>>>>>> Firing select query: " + sel.toString()); List<LogEvent> events = cassandraOperations.select(sel, LogEvent.class); if (isPrevPaging) { Collections.sort( events, new Comparator<LogEvent>() { @Override public int compare(LogEvent o1, LogEvent o2) { return o2.getId().getTimestamp().compareTo(o1.getId().getTimestamp()); } }); } return events; }