Search in sources :

Example 11 with BoundStatementBuilder

use of com.datastax.oss.driver.api.core.cql.BoundStatementBuilder 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);
    }
}
Also used : BoundStatementBuilder(com.datastax.oss.driver.api.core.cql.BoundStatementBuilder) AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) BoundStatement(com.datastax.oss.driver.api.core.cql.BoundStatement)

Example 12 with BoundStatementBuilder

use of com.datastax.oss.driver.api.core.cql.BoundStatementBuilder in project thingsboard by thingsboard.

the class CassandraBaseTimeseriesLatestDao method findAllLatest.

@Override
public ListenableFuture<List<TsKvEntry>> findAllLatest(TenantId tenantId, EntityId entityId) {
    BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(getFindAllLatestStmt().bind());
    stmtBuilder.setString(0, entityId.getEntityType().name());
    stmtBuilder.setUuid(1, entityId.getId());
    BoundStatement stmt = stmtBuilder.build();
    log.debug(GENERATED_QUERY_FOR_ENTITY_TYPE_AND_ENTITY_ID, stmt, entityId.getEntityType(), entityId.getId());
    return getFutureAsync(executeAsyncRead(tenantId, stmt), rs -> convertAsyncResultSetToTsKvEntryList(rs));
}
Also used : BoundStatementBuilder(com.datastax.oss.driver.api.core.cql.BoundStatementBuilder) BoundStatement(com.datastax.oss.driver.api.core.cql.BoundStatement)

Example 13 with BoundStatementBuilder

use of com.datastax.oss.driver.api.core.cql.BoundStatementBuilder in project thingsboard by thingsboard.

the class CassandraBaseTimeseriesLatestDao method saveLatest.

@Override
public ListenableFuture<Void> saveLatest(TenantId tenantId, EntityId entityId, TsKvEntry tsKvEntry) {
    BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(getLatestStmt().bind());
    stmtBuilder.setString(0, entityId.getEntityType().name()).setUuid(1, entityId.getId()).setString(2, tsKvEntry.getKey()).setLong(3, tsKvEntry.getTs()).set(4, tsKvEntry.getBooleanValue().orElse(null), Boolean.class).set(5, tsKvEntry.getStrValue().orElse(null), String.class).set(6, tsKvEntry.getLongValue().orElse(null), Long.class).set(7, tsKvEntry.getDoubleValue().orElse(null), Double.class);
    Optional<String> jsonV = tsKvEntry.getJsonValue();
    if (jsonV.isPresent()) {
        stmtBuilder.setString(8, tsKvEntry.getJsonValue().get());
    } else {
        stmtBuilder.setToNull(8);
    }
    BoundStatement stmt = stmtBuilder.build();
    return getFuture(executeAsyncWrite(tenantId, stmt), rs -> null);
}
Also used : BoundStatementBuilder(com.datastax.oss.driver.api.core.cql.BoundStatementBuilder) BoundStatement(com.datastax.oss.driver.api.core.cql.BoundStatement)

Aggregations

BoundStatementBuilder (com.datastax.oss.driver.api.core.cql.BoundStatementBuilder)13 BoundStatement (com.datastax.oss.driver.api.core.cql.BoundStatement)8 PreparedStatement (com.datastax.oss.driver.api.core.cql.PreparedStatement)5 AsyncResultSet (com.datastax.oss.driver.api.core.cql.AsyncResultSet)3 Row (com.datastax.oss.driver.api.core.cql.Row)2 FutureCallback (com.google.common.util.concurrent.FutureCallback)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Nullable (javax.annotation.Nullable)2 TableMetadata (com.datastax.oss.driver.api.core.metadata.schema.TableMetadata)1 QueryBuilder (com.datastax.oss.driver.api.querybuilder.QueryBuilder)1 QueryBuilder.literal (com.datastax.oss.driver.api.querybuilder.QueryBuilder.literal)1 Select (com.datastax.oss.driver.api.querybuilder.select.Select)1 Function (com.google.common.base.Function)1 AsyncFunction (com.google.common.util.concurrent.AsyncFunction)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1