Search in sources :

Example 11 with BoundStatement

use of com.datastax.oss.driver.api.core.cql.BoundStatement 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 12 with BoundStatement

use of com.datastax.oss.driver.api.core.cql.BoundStatement 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

BoundStatement (com.datastax.oss.driver.api.core.cql.BoundStatement)12 BoundStatementBuilder (com.datastax.oss.driver.api.core.cql.BoundStatementBuilder)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 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Nullable (javax.annotation.Nullable)2 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 LocalDateTime (java.time.LocalDateTime)1 ZoneOffset (java.time.ZoneOffset)1