use of com.datastax.driver.core.BoundStatement 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.BoundStatement in project lagom-java-chirper-example by lagom.
the class FriendEventProcessor method processFriendChanged.
private CompletionStage<List<BoundStatement>> processFriendChanged(FriendAdded event) {
BoundStatement bindWriteFollowers = writeFollowers.bind();
bindWriteFollowers.setString("userId", event.friendId);
bindWriteFollowers.setString("followedBy", event.userId);
return completedStatement(bindWriteFollowers);
}
use of com.datastax.driver.core.BoundStatement in project apex-malhar by apache.
the class CassandraTransactionalStore method storeCommittedWindowId.
@Override
public void storeCommittedWindowId(String appId, int operatorId, long windowId) {
try {
BoundStatement boundStatement = new BoundStatement(lastWindowUpdateCommand);
lastWindowUpdateStatement = boundStatement.bind(windowId, appId, operatorId);
batchCommand.add(lastWindowUpdateStatement);
} catch (DriverException e) {
throw new RuntimeException(e);
}
}
use of com.datastax.driver.core.BoundStatement in project cassandra-driver-mapping by valchkou.
the class MappingSession method remove.
/**
* Remove an item or items from the Set or List.
*
* @param id Primary Key
* @param class Entity.class
* @param propertyName property of Entity to modify
* @param item can be single value, a List or a Set of values to remove.
*/
public void remove(Object id, Class<?> clazz, String propertyName, Object item) {
maybeSync(clazz);
BoundStatement bs = MappingBuilder.prepareRemoveItemsFromSetOrList(id, clazz, propertyName, item, keyspace, session);
execute(bs);
}
use of com.datastax.driver.core.BoundStatement in project cassandra-driver-mapping by valchkou.
the class MappingSession method replaceAt.
/**
* Replace item at the specified position in the List.
*
* @param id Primary Key
* @param class Entity.class
* @param propertyName Entity property
* @param item
* @param idx index of the item to replace. Starts from 0.
* @param options WriteOptions
*/
public void replaceAt(Object id, Class<?> clazz, String propertyName, Object item, int idx, WriteOptions options) {
maybeSync(clazz);
BoundStatement bs = MappingBuilder.prepareReplaceAt(id, clazz, propertyName, item, idx, options, keyspace, session);
execute(bs);
}
Aggregations