public List<LogEvent> findByAppIdContains( final String appId, String token, LogEvent lastRow, 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) { w.and( isPrevPaging ? QueryBuilder.gt(timeuuidCol, lastRow.getId().getTimestamp()) : QueryBuilder.lt(timeuuidCol, lastRow.getId().getTimestamp())); } 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> findByAppId( final String appId, LogEvent lastRow, int limit, boolean isPrevPaging) { Select sel = QueryBuilder.select().from(table).limit(limit); Where w = sel.where(QueryBuilder.eq(pkCols[0], appId)); if (lastRow != null) { w.and( isPrevPaging ? QueryBuilder.gt(timeuuidCol, lastRow.getId().getTimestamp()) : QueryBuilder.lt(timeuuidCol, lastRow.getId().getTimestamp())); } 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 UserSelection retrieveUserSelectionForEmail(String email) { Select select = QueryBuilder.select().from("user_selection"); select.where(QueryBuilder.eq("email", email)); return this.cassandraOperations.selectOne(select, UserSelection.class); }
public Collection<PlayerMention> retrievePlayerMentionsForPlayer(String player) { Select select = QueryBuilder.select().from("player_mention"); select.where(QueryBuilder.eq("player", player)); return this.cassandraOperations.select(select, PlayerMention.class); }
@Override public List<DocumentMetadata> searchByUploader(String uploader) { Select select = QueryBuilder.select().from("documents"); select.where(QueryBuilder.eq("uploaded_by", uploader)); return DocumentMetadataMapping.unwrapList( cassandraOperations.select(select, DocumentMetadataMapping.class)); }
@Override public List<DocumentMetadata> searchByUploadTime(long from, long to) { Select select = QueryBuilder.select().from("documents"); select.where(QueryBuilder.gte("upload_time", from)).and(QueryBuilder.lte("upload_time", to)); select.allowFiltering(); return DocumentMetadataMapping.unwrapList( cassandraOperations.select(select, DocumentMetadataMapping.class)); }
public PlayerMention retrievePlayerMentionForPlayerAndSelectioner( String player, String selectioner) { Select select = QueryBuilder.select().from("player_mention"); select.where(QueryBuilder.eq("player", player)); select.where(QueryBuilder.eq("selectioner_email", selectioner)); return this.cassandraOperations.selectOne(select, PlayerMention.class); }
@Override public void processMessage(Message message) throws MessageProcessingException { String payload = message.getPayload(); String dttm = message.getHeader().getDttm(); try { Map<String, String> payloadMap = mapper.readValue(payload, Map.class); Integer userId = Integer.valueOf(payloadMap.get("UserId")); String tracker = payloadMap.get("Tracker"); HeartTracker heartTracker = null; Select select = QueryBuilder.select().from("heart_tracker"); select.where(QueryBuilder.eq("user_id", userId)); select.where(QueryBuilder.eq("httr_tracker", tracker)); select.allowFiltering(); List<HeartTracker> heartTrackers = cassandraTemplate.select(select, HeartTracker.class); if (heartTrackers.size() == 0) { heartTracker = new HeartTracker(); heartTracker.setHttrId(UUID.randomUUID()); heartTracker.setUserId(userId); heartTracker.setHttrTracker(tracker); heartTracker.setCreatedDttm(new Date()); heartTracker.setDeleteFl(Boolean.FALSE); heartTracker.setPtnId(1); cassandraTemplate.insert(heartTracker); } else { heartTracker = heartTrackers.get(0); } HeartRate heartRate = new HeartRate(); heartRate.setHtrtId(UUID.randomUUID()); heartRate.setHttrId(heartTracker.getHttrId()); heartRate.setHtrtDttm(formatter.parse(dttm)); heartRate.setHtrtValue(Integer.valueOf(payloadMap.get("Value"))); heartRate.setUserId(userId); heartRate.setCreatedDttm(new Date()); heartRate.setDeleteFl(Boolean.FALSE); heartRate.setPtnId(1); cassandraTemplate.insert(heartRate); } catch (IOException e) { logger.error("Exception occured in Heart Rate Message Processing. ", e); throw new MessageProcessingException(e); } catch (ParseException e) { logger.error("Exception occured in Date Conversion. Invalid Date. " + dttm, e); throw new MessageProcessingException(e); } }
private void controlCassandra() { Insert insert = QueryBuilder.insertInto("usuario"); insert.setConsistencyLevel(ConsistencyLevel.ONE); insert.value("id", UUID.randomUUID()); insert.value("nombre", "Alison"); insert.value("email", "gmailalgo"); cassandraOperations.execute(insert); Select select = QueryBuilder.select().from("demo", "usuario"); select.limit(100); List<usuario> results = cassandraOperations.select(select, usuario.class); results.forEach(r -> System.out.println(r)); Map<String, String> p = new HashMap<String, String>(); p.putIfAbsent("hola", "caracola"); Insert insertSample = QueryBuilder.insertInto("sample"); insertSample.setConsistencyLevel(ConsistencyLevel.ONE); insertSample.value("userid", UUID.randomUUID().toString()); insertSample.value("todo", p); cassandraOperations.execute(insertSample); Select selectSample = QueryBuilder.select().from("demo", "sample"); selectSample.limit(100); List<sample> resultsSample = cassandraOperations.select(selectSample, sample.class); for (sample s : resultsSample) { System.out.println(s); s.getTodo().entrySet().forEach(e -> System.out.println(" " + e)); } }
@SuppressWarnings("unchecked") protected <T extends Entity> T findEntity(T entity) { Select selection = select().all().from(tableName(entity)); selection.where(eq("id", entity.getId())); return (T) template.selectOne(selection, entity.getClass()); }