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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations