use of com.datastax.oss.driver.api.core.cql.BoundStatement in project thingsboard by thingsboard.
the class AbstractBufferedRateExecutor method queryToString.
private String queryToString(AsyncTaskContext<T, V> taskCtx) {
CassandraStatementTask cassStmtTask = (CassandraStatementTask) taskCtx.getTask();
if (cassStmtTask.getStatement() instanceof BoundStatement) {
BoundStatement stmt = (BoundStatement) cassStmtTask.getStatement();
String query = stmt.getPreparedStatement().getQuery();
try {
query = toStringWithValues(stmt, ProtocolVersion.V5);
} catch (Exception e) {
log.warn("Can't convert to query with values", e);
}
return query;
} else {
return "Not Cassandra Statement Task";
}
}
use of com.datastax.oss.driver.api.core.cql.BoundStatement in project trellis-cassandra by ajs6f.
the class Mementoize method execute.
/**
* Store a Memento. Note that the value for {@code modified} is truncated to seconds because Memento requires HTTP
* time management.
*
* @param ixnModel an {@link IRI} for the interaction model for this resource
* @param mimeType if this resource has a binary, the mimeType therefor
* @param container if this resource has a container, the {@link IRI} therefor
* @param data RDF for this resource
* @param modified the time at which this resource was last modified
* @param binaryIdentifier if this resource has a binary, the identifier therefor
* @param creation a time-based (version 1) UUID for the moment this resource is created
* @param id an {@link IRI} that identifies this resource
* @return whether and when it has been inserted
*/
public CompletionStage<Void> execute(IRI ixnModel, String mimeType, IRI container, Dataset data, Instant modified, IRI binaryIdentifier, UUID creation, IRI id) {
Instant mementoModified = modified.truncatedTo(SECONDS);
BoundStatement statement = preparedStatement().bind(ixnModel, mimeType, container, data, modified, binaryIdentifier, creation, id, mementoModified);
return executeWrite(statement);
}
use of com.datastax.oss.driver.api.core.cql.BoundStatement in project thingsboard by thingsboard.
the class CassandraBaseTimeseriesDao method doSavePartition.
private ListenableFuture<Integer> doSavePartition(TenantId tenantId, EntityId entityId, String key, long ttl, long partition) {
log.debug("Saving partition {} for the entity [{}-{}] and key {}", partition, entityId.getEntityType(), entityId.getId(), key);
PreparedStatement preparedStatement = ttl == 0 ? getPartitionInsertStmt() : getPartitionInsertTtlStmt();
BoundStatement stmt = preparedStatement.bind();
stmt = stmt.setString(0, entityId.getEntityType().name()).setUuid(1, entityId.getId()).setLong(2, partition).setString(3, key);
if (ttl > 0) {
stmt = stmt.setInt(4, (int) ttl);
}
return getFuture(executeAsyncWrite(tenantId, stmt), rs -> 0);
}
use of com.datastax.oss.driver.api.core.cql.BoundStatement in project thingsboard by thingsboard.
the class CassandraBaseTimeseriesDao method save.
@Override
public ListenableFuture<Integer> save(TenantId tenantId, EntityId entityId, TsKvEntry tsKvEntry, long ttl) {
List<ListenableFuture<Void>> futures = new ArrayList<>();
ttl = computeTtl(ttl);
int dataPointDays = tsKvEntry.getDataPoints() * Math.max(1, (int) (ttl / SECONDS_IN_DAY));
long partition = toPartitionTs(tsKvEntry.getTs());
DataType type = tsKvEntry.getDataType();
if (setNullValuesEnabled) {
processSetNullValues(tenantId, entityId, tsKvEntry, ttl, futures, partition, 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());
addValue(tsKvEntry, stmtBuilder, 5);
if (ttl > 0) {
stmtBuilder.setInt(6, (int) ttl);
}
BoundStatement stmt = stmtBuilder.build();
futures.add(getFuture(executeAsyncWrite(tenantId, stmt), rs -> null));
return Futures.transform(Futures.allAsList(futures), result -> dataPointDays, MoreExecutors.directExecutor());
}
use of com.datastax.oss.driver.api.core.cql.BoundStatement in project thingsboard by thingsboard.
the class CassandraBaseTimeseriesDao method deleteAsync.
private void deleteAsync(TenantId tenantId, final QueryCursor cursor, final SimpleListenableFuture<Void> resultFuture) {
if (!cursor.hasNextPartition()) {
resultFuture.set(null);
} else {
PreparedStatement proto = getDeleteStmt();
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());
BoundStatement stmt = stmtBuilder.build();
Futures.addCallback(executeAsyncWrite(tenantId, stmt), new FutureCallback<AsyncResultSet>() {
@Override
public void onSuccess(@Nullable AsyncResultSet result) {
deleteAsync(tenantId, cursor, resultFuture);
}
@Override
public void onFailure(Throwable t) {
log.error("[{}][{}] Failed to delete data for query {}-{}", stmt, t);
}
}, readResultsProcessingExecutor);
}
}
Aggregations