Search in sources :

Example 56 with ResultSetFuture

use of com.datastax.driver.core.ResultSetFuture in project java-driver by datastax.

the class AsynchronousConsumer method handle.

protected void handle(QueryGenerator.Request request) {
    final Reporter.Context ctx = reporter.newRequest();
    ResultSetFuture resultSetFuture = request.executeAsync(session);
    Futures.addCallback(resultSetFuture, new FutureCallback<ResultSet>() {

        @Override
        public void onSuccess(final ResultSet result) {
            ctx.done();
            request();
        }

        @Override
        public void onFailure(final Throwable t) {
            // Could do better I suppose
            System.err.println("Error during request: " + t);
            ctx.done();
            request();
        }
    }, executorService);
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture) ResultSet(com.datastax.driver.core.ResultSet)

Example 57 with ResultSetFuture

use of com.datastax.driver.core.ResultSetFuture in project jnosql-diana-driver by eclipse.

the class CassandraPrepareStatment method executeQueryAsync.

/**
 * Executes and call the callback with the result
 *
 * @param consumer the callback
 * @throws ExecuteAsyncQueryException when has async error
 * @throws NullPointerException       when consumer is null
 */
public void executeQueryAsync(Consumer<List<ColumnEntity>> consumer) throws ExecuteAsyncQueryException, NullPointerException {
    loadBoundStatment();
    ResultSetFuture resultSet = session.executeAsync(boundStatement);
    CassandraReturnQueryAsync executeAsync = new CassandraReturnQueryAsync(resultSet, consumer);
    resultSet.addListener(executeAsync, executor);
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture)

Example 58 with ResultSetFuture

use of com.datastax.driver.core.ResultSetFuture in project jnosql-diana-driver by eclipse.

the class DefaultCassandraColumnFamilyManagerAsync method select.

@Override
public void select(ColumnQuery query, Consumer<List<ColumnEntity>> consumer) throws ExecuteAsyncQueryException, UnsupportedOperationException {
    requireNonNull(query, "query is required");
    requireNonNull(consumer, "consumer is required");
    BuiltStatement select = QueryUtils.select(query, keyspace);
    ResultSetFuture resultSet = session.executeAsync(select);
    CassandraReturnQueryAsync executeAsync = new CassandraReturnQueryAsync(resultSet, consumer);
    resultSet.addListener(executeAsync, executor);
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture) BuiltStatement(com.datastax.driver.core.querybuilder.BuiltStatement)

Example 59 with ResultSetFuture

use of com.datastax.driver.core.ResultSetFuture in project jnosql-diana-driver by eclipse.

the class DefaultCassandraColumnFamilyManagerAsync method insert.

@Override
public void insert(ColumnEntity entity, Duration ttl, Consumer<ColumnEntity> callBack) throws ExecuteAsyncQueryException, UnsupportedOperationException {
    requireNonNull(entity, "entity is required");
    requireNonNull(ttl, "ttl is required");
    requireNonNull(callBack, "callBack is required");
    Insert insert = QueryUtils.insert(entity, keyspace, session);
    insert.using(QueryBuilder.ttl((int) ttl.getSeconds()));
    ResultSetFuture resultSetFuture = session.executeAsync(insert);
    resultSetFuture.addListener(() -> callBack.accept(entity), executor);
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture) Insert(com.datastax.driver.core.querybuilder.Insert)

Example 60 with ResultSetFuture

use of com.datastax.driver.core.ResultSetFuture in project jnosql-diana-driver by eclipse.

the class DefaultCassandraColumnFamilyManagerAsync method execute.

@Override
public void execute(Statement statement, Consumer<List<ColumnEntity>> consumer) throws ExecuteAsyncQueryException, NullPointerException {
    requireNonNull(statement, "statement is required");
    requireNonNull(consumer, "consumer is required");
    ResultSetFuture resultSet = session.executeAsync(statement);
    CassandraReturnQueryAsync executeAsync = new CassandraReturnQueryAsync(resultSet, consumer);
    resultSet.addListener(executeAsync, executor);
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture)

Aggregations

ResultSetFuture (com.datastax.driver.core.ResultSetFuture)78 Test (org.junit.Test)35 UUID (java.util.UUID)26 ResultSet (com.datastax.driver.core.ResultSet)20 EntityWithCollections (com.datastax.driver.mapping.entity.EntityWithCollections)13 BoundStatement (com.datastax.driver.core.BoundStatement)12 PreparedStatement (com.datastax.driver.core.PreparedStatement)10 ArrayList (java.util.ArrayList)8 Date (java.util.Date)8 Row (com.datastax.driver.core.Row)7 Statement (com.datastax.driver.core.Statement)7 List (java.util.List)6 Session (com.datastax.driver.core.Session)5 Simple (com.datastax.driver.mapping.entity.Simple)5 Cell (com.palantir.atlasdb.keyvalue.api.Cell)5 BigDecimal (java.math.BigDecimal)5 HashSet (java.util.HashSet)5 Result (com.datastax.driver.mapping.Result)4 WriteOptions (com.datastax.driver.mapping.option.WriteOptions)4 Nullable (javax.annotation.Nullable)4