use of org.thingsboard.server.dao.model.sqlts.ts.TsKvEntity in project thingsboard by thingsboard.
the class AbstractChunkedAggregationTimeseriesDao method setFutures.
protected SettableFuture<TsKvEntity> setFutures(List<CompletableFuture<TsKvEntity>> entitiesFutures) {
SettableFuture<TsKvEntity> listenableFuture = SettableFuture.create();
CompletableFuture<List<TsKvEntity>> entities = CompletableFuture.allOf(entitiesFutures.toArray(new CompletableFuture[entitiesFutures.size()])).thenApply(v -> entitiesFutures.stream().map(CompletableFuture::join).collect(Collectors.toList()));
entities.whenComplete((tsKvEntities, throwable) -> {
if (throwable != null) {
listenableFuture.setException(throwable);
} else {
TsKvEntity result = null;
for (TsKvEntity entity : tsKvEntities) {
if (entity.isNotEmpty()) {
result = entity;
break;
}
}
listenableFuture.set(result);
}
});
return listenableFuture;
}
use of org.thingsboard.server.dao.model.sqlts.ts.TsKvEntity in project thingsboard by thingsboard.
the class JpaPsqlTimeseriesDao method save.
@Override
public ListenableFuture<Integer> save(TenantId tenantId, EntityId entityId, TsKvEntry tsKvEntry, long ttl) {
int dataPointDays = getDataPointDays(tsKvEntry, computeTtl(ttl));
savePartitionIfNotExist(tsKvEntry.getTs());
String strKey = tsKvEntry.getKey();
Integer keyId = getOrSaveKeyId(strKey);
TsKvEntity entity = new TsKvEntity();
entity.setEntityId(entityId.getId());
entity.setTs(tsKvEntry.getTs());
entity.setKey(keyId);
entity.setStrValue(tsKvEntry.getStrValue().orElse(null));
entity.setDoubleValue(tsKvEntry.getDoubleValue().orElse(null));
entity.setLongValue(tsKvEntry.getLongValue().orElse(null));
entity.setBooleanValue(tsKvEntry.getBooleanValue().orElse(null));
entity.setJsonValue(tsKvEntry.getJsonValue().orElse(null));
log.trace("Saving entity: {}", entity);
return Futures.transform(tsQueue.add(entity), v -> dataPointDays, MoreExecutors.directExecutor());
}
use of org.thingsboard.server.dao.model.sqlts.ts.TsKvEntity in project thingsboard by thingsboard.
the class BaseEntityServiceTest method saveLongTimeseries.
private ListenableFuture<Integer> saveLongTimeseries(EntityId entityId, String key, Double value) {
TsKvEntity tsKv = new TsKvEntity();
tsKv.setStrKey(key);
tsKv.setDoubleValue(value);
KvEntry telemetryValue = new DoubleDataEntry(key, value);
BasicTsKvEntry timeseries = new BasicTsKvEntry(42L, telemetryValue);
return timeseriesService.save(SYSTEM_TENANT_ID, entityId, timeseries);
}
use of org.thingsboard.server.dao.model.sqlts.ts.TsKvEntity in project thingsboard by thingsboard.
the class JpaHsqlTimeseriesDao method save.
@Override
public ListenableFuture<Integer> save(TenantId tenantId, EntityId entityId, TsKvEntry tsKvEntry, long ttl) {
int dataPointDays = getDataPointDays(tsKvEntry, computeTtl(ttl));
String strKey = tsKvEntry.getKey();
Integer keyId = getOrSaveKeyId(strKey);
TsKvEntity entity = new TsKvEntity();
entity.setEntityId(entityId.getId());
entity.setTs(tsKvEntry.getTs());
entity.setKey(keyId);
entity.setStrValue(tsKvEntry.getStrValue().orElse(null));
entity.setDoubleValue(tsKvEntry.getDoubleValue().orElse(null));
entity.setLongValue(tsKvEntry.getLongValue().orElse(null));
entity.setBooleanValue(tsKvEntry.getBooleanValue().orElse(null));
entity.setJsonValue(tsKvEntry.getJsonValue().orElse(null));
log.trace("Saving entity: {}", entity);
return Futures.transform(tsQueue.add(entity), v -> dataPointDays, MoreExecutors.directExecutor());
}
use of org.thingsboard.server.dao.model.sqlts.ts.TsKvEntity in project thingsboard by thingsboard.
the class AbstractChunkedAggregationTimeseriesDao method init.
@PostConstruct
protected void init() {
TbSqlBlockingQueueParams tsParams = TbSqlBlockingQueueParams.builder().logName("TS").batchSize(tsBatchSize).maxDelay(tsMaxDelay).statsPrintIntervalMs(tsStatsPrintIntervalMs).statsNamePrefix("ts").batchSortEnabled(batchSortEnabled).build();
Function<TsKvEntity, Integer> hashcodeFunction = entity -> entity.getEntityId().hashCode();
tsQueue = new TbSqlBlockingQueueWrapper<>(tsParams, hashcodeFunction, tsBatchThreads, statsFactory);
tsQueue.init(logExecutor, v -> insertRepository.saveOrUpdate(v), Comparator.comparing((Function<TsKvEntity, UUID>) AbstractTsKvEntity::getEntityId).thenComparing(AbstractTsKvEntity::getKey).thenComparing(AbstractTsKvEntity::getTs));
}
Aggregations