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;
  }
Ejemplo n.º 2
0
 public LogEvent(LogRequest req) {
   this();
   getId().setAppId(req.getApplicationId());
   setLevel(req.getLevel());
   setLogText(req.getLogText());
   setExecId(req.getExecutionId());
   getId().setTimestamp(CommonHelper.makeTimeUuid(req.getTimestamp()));
   Assert.isTrue(
       req.getTimestamp() == getId().getTimestampAsLong(),
       "Timestamp -> TimeUUID conversion incorrect");
 }