Example usage for org.springframework.data.cassandra.core CassandraOperations select

List of usage examples for org.springframework.data.cassandra.core CassandraOperations select

Introduction

In this page you can find the example usage for org.springframework.data.cassandra.core CassandraOperations select.

Prototype

<T> List<T> select(Query query, Class<T> entityClass) throws DataAccessException;

Source Link

Document

Execute a SELECT query and convert the resulting items to a List of entities.

Usage

From source file:edu.elka.peakadvisor.model.CassandraDao.java

public List<Latest> readAll() {

    CassandraOperations template = this.cassandraTemplate;
    Select selectStatement = QueryBuilder.select().from("Latest").allowFiltering();

    List<Latest> result = template.select(selectStatement, Latest.class);

    return result;
}

From source file:edu.elka.peakadvisor.model.CassandraDao.java

public List<Pair<Double, Integer>> getPricesWithTimestampRange(String name, int timestampStart,
        int timestampEnd) {

    CassandraOperations template = this.cassandraTemplate;
    Select selectStatement = QueryBuilder.select() //znowu nie dziala bez cydzyslowow, trzeba wszystko wybierac
            .from("Latest").allowFiltering();

    selectStatement.where(QueryBuilder.gte("timestamp", timestampStart));
    selectStatement.where(QueryBuilder.lte("timestamp", timestampEnd));
    List<Latest> queryResult = template.select(selectStatement, Latest.class);

    queryResult.sort(new Comparator<Latest>() {
        @Override/*from   ww  w  . j a v  a 2s  .  c o  m*/
        public int compare(Latest o1, Latest o2) {
            if (o1.getTimestamp() > o2.getTimestamp())
                return 1;
            else if (o1.getTimestamp() < o2.getTimestamp())
                return -1;
            else
                return 0;
        }
    });

    List<Pair<Number, Integer>> list = new ArrayList<>();
    queryResult.stream().map((l) -> {

        try {
            return new Pair(
                    ((l.getRates().getClass().getMethod("get" + name.toUpperCase()).invoke(l.getRates()))),
                    l.getTimestamp());
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        return null;
    }).forEach(p -> list.add(p));

    List<Pair<Double, Integer>> result2 = new ArrayList<>();

    //        for(Pair p:list){
    //            result2.add(new Pair<Double, Integer>((Double) p.getKey(),(Integer) p.getValue()));
    //        }

    list.stream().map((r) ->

    new Pair(((Double) r.getKey()).doubleValue(), ((Integer) r.getValue()).intValue()))

            .forEach(p -> result2.add(p));

    return result2;
}