use of com.datastax.oss.driver.api.core.cql.BoundStatement in project trellis-cassandra by ajs6f.
the class CassandraQuery method executeWrite.
/**
* @param statement the CQL statement to execute
* @return when and whether the statement completed
*/
protected CompletionStage<Void> executeWrite(BoundStatement statement) {
String queryString = statement.getPreparedStatement().getQuery();
log.debug("Executing CQL write: {}", queryString);
BoundStatement consistentStatement = statement.setConsistencyLevel(consistency);
return session.executeAsync(consistentStatement).thenAccept(r -> log.debug("Executed CQL write: {}", queryString));
}
use of com.datastax.oss.driver.api.core.cql.BoundStatement in project thingsboard by thingsboard.
the class CassandraBaseTimeseriesDao method deletePartitionAsync.
private void deletePartitionAsync(TenantId tenantId, final QueryCursor cursor, final SimpleListenableFuture<Void> resultFuture) {
if (!cursor.hasNextPartition()) {
resultFuture.set(null);
} else {
PreparedStatement proto = getDeletePartitionStmt();
BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(proto.bind());
stmtBuilder.setString(0, cursor.getEntityType());
stmtBuilder.setUuid(1, cursor.getEntityId());
stmtBuilder.setLong(2, cursor.getNextPartition());
stmtBuilder.setString(3, cursor.getKey());
BoundStatement stmt = stmtBuilder.build();
Futures.addCallback(executeAsyncWrite(tenantId, stmt), new FutureCallback<AsyncResultSet>() {
@Override
public void onSuccess(@Nullable AsyncResultSet result) {
deletePartitionAsync(tenantId, cursor, resultFuture);
}
@Override
public void onFailure(Throwable t) {
log.error("[{}][{}] Failed to delete data for query {}-{}", stmt, t);
}
}, readResultsProcessingExecutor);
}
}
use of com.datastax.oss.driver.api.core.cql.BoundStatement in project thingsboard by thingsboard.
the class CassandraBaseTimeseriesDao method findAllAsyncSequentiallyWithLimit.
private void findAllAsyncSequentiallyWithLimit(TenantId tenantId, final TsKvQueryCursor cursor, final SimpleListenableFuture<List<TsKvEntry>> resultFuture) {
if (cursor.isFull() || !cursor.hasNextPartition()) {
resultFuture.set(cursor.getData());
} else {
PreparedStatement proto = getFetchStmt(Aggregation.NONE, cursor.getOrderBy());
BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(proto.bind());
stmtBuilder.setString(0, cursor.getEntityType());
stmtBuilder.setUuid(1, cursor.getEntityId());
stmtBuilder.setString(2, cursor.getKey());
stmtBuilder.setLong(3, cursor.getNextPartition());
stmtBuilder.setLong(4, cursor.getStartTs());
stmtBuilder.setLong(5, cursor.getEndTs());
stmtBuilder.setInt(6, cursor.getCurrentLimit());
BoundStatement stmt = stmtBuilder.build();
Futures.addCallback(executeAsyncRead(tenantId, stmt), new FutureCallback<TbResultSet>() {
@Override
public void onSuccess(@Nullable TbResultSet result) {
if (result == null) {
cursor.addData(convertResultToTsKvEntryList(Collections.emptyList()));
findAllAsyncSequentiallyWithLimit(tenantId, cursor, resultFuture);
} else {
Futures.addCallback(result.allRows(readResultsProcessingExecutor), new FutureCallback<List<Row>>() {
@Override
public void onSuccess(@Nullable List<Row> result) {
cursor.addData(convertResultToTsKvEntryList(result == null ? Collections.emptyList() : result));
findAllAsyncSequentiallyWithLimit(tenantId, cursor, resultFuture);
}
@Override
public void onFailure(Throwable t) {
log.error("[{}][{}] Failed to fetch data for query {}-{}", stmt, t);
}
}, readResultsProcessingExecutor);
}
}
@Override
public void onFailure(Throwable t) {
log.error("[{}][{}] Failed to fetch data for query {}-{}", stmt, t);
}
}, readResultsProcessingExecutor);
}
}
use of com.datastax.oss.driver.api.core.cql.BoundStatement in project thingsboard by thingsboard.
the class CassandraBaseTimeseriesDao method saveNull.
private ListenableFuture<Void> saveNull(TenantId tenantId, EntityId entityId, TsKvEntry tsKvEntry, long ttl, long partition, DataType type) {
BoundStatementBuilder stmtBuilder = new BoundStatementBuilder((ttl == 0 ? getSaveStmt(type) : getSaveTtlStmt(type)).bind());
stmtBuilder.setString(0, entityId.getEntityType().name()).setUuid(1, entityId.getId()).setString(2, tsKvEntry.getKey()).setLong(3, partition).setLong(4, tsKvEntry.getTs());
stmtBuilder.setToNull(getColumnName(type));
if (ttl > 0) {
stmtBuilder.setInt(6, (int) ttl);
}
BoundStatement stmt = stmtBuilder.build();
return getFuture(executeAsyncWrite(tenantId, stmt), rs -> null);
}
use of com.datastax.oss.driver.api.core.cql.BoundStatement in project thingsboard by thingsboard.
the class CassandraBaseTimeseriesLatestDao method findLatest.
@Override
public ListenableFuture<TsKvEntry> findLatest(TenantId tenantId, EntityId entityId, String key) {
BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(getFindLatestStmt().bind());
stmtBuilder.setString(0, entityId.getEntityType().name());
stmtBuilder.setUuid(1, entityId.getId());
stmtBuilder.setString(2, key);
BoundStatement stmt = stmtBuilder.build();
log.debug(GENERATED_QUERY_FOR_ENTITY_TYPE_AND_ENTITY_ID, stmt, entityId.getEntityType(), entityId.getId());
return getFuture(executeAsyncRead(tenantId, stmt), rs -> convertResultToTsKvEntry(key, rs.one()));
}
Aggregations