use of com.datastax.oss.driver.api.core.cql.BoundStatementBuilder in project zipkin by openzipkin.
the class SelectTraceIdsFromSpan method newCompletionStage.
@Override
protected CompletionStage<AsyncResultSet> newCompletionStage() {
BoundStatementBuilder bound = preparedStatement.boundStatementBuilder();
int i = 0;
if (input.l_service() != null)
bound.setString(i++, input.l_service());
if (input.annotation_query() != null) {
bound.setString(i++, input.annotation_query());
} else {
throw new IllegalArgumentException(input.toString());
}
bound.setUuid(i++, input.start_ts()).setUuid(i++, input.end_ts()).setInt(i, input.limit_()).setPageSize(input.limit_());
return factory.session.executeAsync(bound.build());
}
use of com.datastax.oss.driver.api.core.cql.BoundStatementBuilder in project zipkin by openzipkin.
the class SelectTraceIdsFromServiceSpan method newCompletionStage.
@Override
protected CompletionStage<AsyncResultSet> newCompletionStage() {
int i = 0;
BoundStatementBuilder bound = preparedStatement.boundStatementBuilder().setString(i++, input.service()).setString(i++, input.span()).setInt(i++, input.bucket()).setUuid(i++, input.start_ts()).setUuid(i++, input.end_ts());
if (input.start_duration() != null) {
bound.setLong(i++, input.start_duration());
bound.setLong(i++, input.end_duration());
}
bound.setInt(i, input.limit_()).setPageSize(input.limit_());
return factory.session.executeAsync(bound.build());
}
use of com.datastax.oss.driver.api.core.cql.BoundStatementBuilder in project thingsboard by thingsboard.
the class TbSaveToCustomCassandraTableNode method save.
private ListenableFuture<Void> save(TbMsg msg, TbContext ctx) {
JsonElement data = parser.parse(msg.getData());
if (!data.isJsonObject()) {
throw new IllegalStateException("Invalid message structure, it is not a JSON Object:" + data);
} else {
JsonObject dataAsObject = data.getAsJsonObject();
BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(saveStmt.bind());
AtomicInteger i = new AtomicInteger(0);
fieldsMap.forEach((key, value) -> {
if (key.equals(ENTITY_ID)) {
stmtBuilder.setUuid(i.get(), msg.getOriginator().getId());
} else if (dataAsObject.has(key)) {
JsonElement dataKeyElement = dataAsObject.get(key);
if (dataKeyElement.isJsonPrimitive()) {
JsonPrimitive primitive = dataKeyElement.getAsJsonPrimitive();
if (primitive.isNumber()) {
if (primitive.getAsString().contains(".")) {
stmtBuilder.setDouble(i.get(), primitive.getAsDouble());
} else {
stmtBuilder.setLong(i.get(), primitive.getAsLong());
}
} else if (primitive.isBoolean()) {
stmtBuilder.setBoolean(i.get(), primitive.getAsBoolean());
} else if (primitive.isString()) {
stmtBuilder.setString(i.get(), primitive.getAsString());
} else {
stmtBuilder.setToNull(i.get());
}
} else if (dataKeyElement.isJsonObject()) {
stmtBuilder.setString(i.get(), dataKeyElement.getAsJsonObject().toString());
} else {
throw new IllegalStateException("Message data key: '" + key + "' with value: '" + value + "' is not a JSON Object or JSON Primitive!");
}
} else {
throw new RuntimeException("Message data doesn't contain key: " + "'" + key + "'!");
}
i.getAndIncrement();
});
return getFuture(executeAsyncWrite(ctx, stmtBuilder.build()), rs -> null);
}
}
use of com.datastax.oss.driver.api.core.cql.BoundStatementBuilder 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.BoundStatementBuilder 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);
}
}
Aggregations