use of com.datastax.oss.driver.api.core.cql.BoundStatementBuilder 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.BoundStatementBuilder 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()));
}
use of com.datastax.oss.driver.api.core.cql.BoundStatementBuilder in project janusgraph by JanusGraph.
the class CQLKeyColumnValueStore method insertColumn.
public BatchableStatement<BoundStatement> insertColumn(final StaticBuffer key, final Entry entry, final Long timestamp) {
final Integer ttl = (Integer) entry.getMetaData().get(EntryMetaData.TTL);
BoundStatementBuilder builder = ttl != null ? insertColumnWithTTL.boundStatementBuilder() : insertColumn.boundStatementBuilder();
builder = builder.setByteBuffer(KEY_BINDING, key.asByteBuffer()).setByteBuffer(COLUMN_BINDING, entry.getColumn().asByteBuffer()).setByteBuffer(VALUE_BINDING, entry.getValue().asByteBuffer());
if (ttl != null) {
builder = builder.setInt(TTL_BINDING, ttl);
}
if (timestamp != null) {
builder = builder.setLong(TIMESTAMP_BINDING, timestamp);
}
return builder.build();
}
use of com.datastax.oss.driver.api.core.cql.BoundStatementBuilder in project thingsboard by thingsboard.
the class CassandraDbHelper method loadCf.
public static void loadCf(KeyspaceMetadata ks, GuavaSession session, String cfName, String[] columns, Path sourceFile, boolean parseHeader) throws Exception {
TableMetadata tableMetadata = ks.getTable(cfName).get();
PreparedStatement prepared = session.prepare(createInsertStatement(cfName, columns));
CSVFormat csvFormat = CSV_DUMP_FORMAT;
if (parseHeader) {
csvFormat = csvFormat.withFirstRecordAsHeader();
} else {
csvFormat = CSV_DUMP_FORMAT.withHeader(columns);
}
try (CSVParser csvParser = new CSVParser(Files.newBufferedReader(sourceFile), csvFormat)) {
csvParser.forEach(record -> {
BoundStatementBuilder boundStatementBuilder = new BoundStatementBuilder(prepared.bind());
for (String column : columns) {
setColumnValue(tableMetadata, column, record, boundStatementBuilder);
}
session.execute(boundStatementBuilder.build());
});
}
}
use of com.datastax.oss.driver.api.core.cql.BoundStatementBuilder 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());
}
Aggregations