use of com.datastax.driver.core.ResultSet in project camel by apache.
the class ResultSetConversionStrategiesTest method testOne.
@Test
public void testOne() {
ResultSetConversionStrategy strategy = ResultSetConversionStrategies.fromName("ONE");
ResultSet resultSet = mock(ResultSet.class);
Row row = mock(Row.class);
when(resultSet.one()).thenReturn(row);
Object body = strategy.getBody(resultSet);
assertTrue(body instanceof Row);
assertSame(row, body);
}
use of com.datastax.driver.core.ResultSet in project storm by apache.
the class AsyncExecutor method execAsync.
/**
* Asynchronously executes the specified batch statement. Inputs will be passed to
* the {@link #handler} once query succeed or failed.
*/
public SettableFuture<T> execAsync(final Statement statement, final T inputs, final AsyncResultHandler<T> handler) {
final SettableFuture<T> settableFuture = SettableFuture.create();
pending.incrementAndGet();
ResultSetFuture future = session.executeAsync(statement);
Futures.addCallback(future, new FutureCallback<ResultSet>() {
public void release() {
pending.decrementAndGet();
}
@Override
public void onSuccess(ResultSet result) {
release();
settableFuture.set(inputs);
handler.success(inputs);
}
@Override
public void onFailure(Throwable t) {
LOG.error(String.format("Failed to execute statement '%s' ", statement), t);
release();
settableFuture.setException(t);
handler.failure(t, inputs);
}
}, executorService);
return settableFuture;
}
use of com.datastax.driver.core.ResultSet in project newts by OpenNMS.
the class CassandraSampleRepository method delete.
@Override
public void delete(Context context, Resource resource) {
/**
* Check for ttl value > 0
*/
if (m_ttl > 0) {
/**
* Delete exactly from (now - ttl) till now
*/
final Timestamp start = Timestamp.now().minus(m_ttl, TimeUnit.SECONDS);
final Timestamp end = Timestamp.now();
final Duration resourceShard = m_contextConfigurations.getResourceShard(context);
final List<Future<ResultSet>> futures = Lists.newArrayList();
for (Timestamp partition : new IntervalGenerator(start.stepFloor(resourceShard), end.stepFloor(resourceShard), resourceShard)) {
BoundStatement bindStatement = m_deleteStatement.bind();
bindStatement.setString(SchemaConstants.F_CONTEXT, context.getId());
bindStatement.setInt(SchemaConstants.F_PARTITION, (int) partition.asSeconds());
bindStatement.setString(SchemaConstants.F_RESOURCE, resource.getId());
futures.add(m_session.executeAsync(bindStatement));
}
for (final Future<ResultSet> future : futures) {
try {
future.get();
} catch (final InterruptedException | ExecutionException e) {
throw Throwables.propagate(e);
}
}
} else {
// Choose (now - one year) till now...
Timestamp end = Timestamp.now();
Timestamp start = end.minus(DELETION_INTERVAL, TimeUnit.DAYS);
// ... and check whether samples exist for this period of time.
while (cassandraSelect(context, resource, start, end).hasNext()) {
// Now delete the samples...
final Duration resourceShard = m_contextConfigurations.getResourceShard(context);
final List<Future<ResultSet>> futures = Lists.newArrayList();
for (Timestamp partition : new IntervalGenerator(start.stepFloor(resourceShard), end.stepFloor(resourceShard), resourceShard)) {
BoundStatement bindStatement = m_deleteStatement.bind();
bindStatement.setString(SchemaConstants.F_CONTEXT, context.getId());
bindStatement.setInt(SchemaConstants.F_PARTITION, (int) partition.asSeconds());
bindStatement.setString(SchemaConstants.F_RESOURCE, resource.getId());
futures.add(m_session.executeAsync(bindStatement));
}
for (final Future<ResultSet> future : futures) {
try {
future.get();
} catch (final InterruptedException | ExecutionException e) {
throw Throwables.propagate(e);
}
}
// ...set end to start and start to (end - one year)
end = start;
start = end.minus(DELETION_INTERVAL, TimeUnit.DAYS);
// and start over again until no more samples are found
}
}
}
use of com.datastax.driver.core.ResultSet in project javaee7-samples by javaee-samples.
the class PersonSessionBean method getPersons.
public List<Person> getPersons() {
List<Person> persons = new ArrayList<>();
ResultSet results = session.execute(selectAllPersons.bind());
for (Row row : results) {
persons.add(new Person(row.getString("name"), row.getInt("age")));
}
return persons;
}
use of com.datastax.driver.core.ResultSet in project zipkin by openzipkin.
the class CassandraSpanStore method getSpanNames.
@Override
public ListenableFuture<List<String>> getSpanNames(String serviceName) {
if (serviceName == null || serviceName.isEmpty())
return EMPTY_LIST;
serviceName = checkNotNull(serviceName, "serviceName").toLowerCase();
int bucket = 0;
try {
BoundStatement bound = CassandraUtil.bindWithName(selectSpanNames, "select-span-names").setString("service_name", serviceName).setInt("bucket", bucket).setInt("limit_", 1000);
return transform(session.executeAsync(bound), new Function<ResultSet, List<String>>() {
@Override
public List<String> apply(ResultSet input) {
Set<String> spanNames = new HashSet<>();
for (Row row : input) {
spanNames.add(row.getString("span_name"));
}
return Ordering.natural().sortedCopy(spanNames);
}
});
} catch (RuntimeException ex) {
return immediateFailedFuture(ex);
}
}
Aggregations