Search in sources :

Example 1 with TimescaleTsKvEntity

use of org.thingsboard.server.dao.model.sqlts.timescale.ts.TimescaleTsKvEntity in project thingsboard by thingsboard.

the class TimescaleTimeseriesDao method init.

@PostConstruct
protected void init() {
    TbSqlBlockingQueueParams tsParams = TbSqlBlockingQueueParams.builder().logName("TS Timescale").batchSize(tsBatchSize).maxDelay(tsMaxDelay).statsPrintIntervalMs(tsStatsPrintIntervalMs).statsNamePrefix("ts.timescale").batchSortEnabled(batchSortEnabled).build();
    Function<TimescaleTsKvEntity, Integer> hashcodeFunction = entity -> entity.getEntityId().hashCode();
    tsQueue = new TbSqlBlockingQueueWrapper<>(tsParams, hashcodeFunction, timescaleBatchThreads, statsFactory);
    tsQueue.init(logExecutor, v -> insertRepository.saveOrUpdate(v), Comparator.comparing((Function<TimescaleTsKvEntity, UUID>) AbstractTsKvEntity::getEntityId).thenComparing(AbstractTsKvEntity::getKey).thenComparing(AbstractTsKvEntity::getTs));
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) java.util(java.util) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TbSqlBlockingQueueWrapper(org.thingsboard.server.dao.sql.TbSqlBlockingQueueWrapper) Autowired(org.springframework.beans.factory.annotation.Autowired) CompletableFuture(java.util.concurrent.CompletableFuture) SettableFuture(com.google.common.util.concurrent.SettableFuture) StatsFactory(org.thingsboard.server.common.stats.StatsFactory) Function(java.util.function.Function) TenantId(org.thingsboard.server.common.data.id.TenantId) Value(org.springframework.beans.factory.annotation.Value) PreDestroy(javax.annotation.PreDestroy) SQLException(java.sql.SQLException) AbstractTsKvEntity(org.thingsboard.server.dao.model.sql.AbstractTsKvEntity) AbstractSqlTimeseriesDao(org.thingsboard.server.dao.sqlts.AbstractSqlTimeseriesDao) TimescaleTsKvEntity(org.thingsboard.server.dao.model.sqlts.timescale.ts.TimescaleTsKvEntity) TbSqlBlockingQueueParams(org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams) EntityId(org.thingsboard.server.common.data.id.EntityId) Sort(org.springframework.data.domain.Sort) InsertTsRepository(org.thingsboard.server.dao.sqlts.insert.InsertTsRepository) TimescaleDBTsDao(org.thingsboard.server.dao.util.TimescaleDBTsDao) Aggregation(org.thingsboard.server.common.data.kv.Aggregation) PageRequest(org.springframework.data.domain.PageRequest) DeleteTsKvQuery(org.thingsboard.server.common.data.kv.DeleteTsKvQuery) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) Futures(com.google.common.util.concurrent.Futures) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) CollectionUtils(org.springframework.util.CollectionUtils) TimeseriesDao(org.thingsboard.server.dao.timeseries.TimeseriesDao) PostConstruct(javax.annotation.PostConstruct) DaoUtil(org.thingsboard.server.dao.DaoUtil) CallableStatement(java.sql.CallableStatement) ReadTsKvQuery(org.thingsboard.server.common.data.kv.ReadTsKvQuery) ModelConstants(org.thingsboard.server.dao.model.ModelConstants) Types(java.sql.Types) Function(java.util.function.Function) TimescaleTsKvEntity(org.thingsboard.server.dao.model.sqlts.timescale.ts.TimescaleTsKvEntity) AbstractTsKvEntity(org.thingsboard.server.dao.model.sql.AbstractTsKvEntity) TbSqlBlockingQueueParams(org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams) PostConstruct(javax.annotation.PostConstruct)

Example 2 with TimescaleTsKvEntity

use of org.thingsboard.server.dao.model.sqlts.timescale.ts.TimescaleTsKvEntity in project thingsboard by thingsboard.

the class TimescaleTimeseriesDao 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);
    TimescaleTsKvEntity entity = new TimescaleTsKvEntity();
    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 to timescale db: {}", entity);
    return Futures.transform(tsQueue.add(entity), v -> dataPointDays, MoreExecutors.directExecutor());
}
Also used : TimescaleTsKvEntity(org.thingsboard.server.dao.model.sqlts.timescale.ts.TimescaleTsKvEntity)

Aggregations

TimescaleTsKvEntity (org.thingsboard.server.dao.model.sqlts.timescale.ts.TimescaleTsKvEntity)2 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 CallableStatement (java.sql.CallableStatement)1 SQLException (java.sql.SQLException)1 Types (java.sql.Types)1 java.util (java.util)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Function (java.util.function.Function)1 PostConstruct (javax.annotation.PostConstruct)1 PreDestroy (javax.annotation.PreDestroy)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Value (org.springframework.beans.factory.annotation.Value)1 PageRequest (org.springframework.data.domain.PageRequest)1 Sort (org.springframework.data.domain.Sort)1 Component (org.springframework.stereotype.Component)1 CollectionUtils (org.springframework.util.CollectionUtils)1