Search in sources :

Example 1 with TsKvLatestCompositeKey

use of org.thingsboard.server.dao.model.sqlts.latest.TsKvLatestCompositeKey in project thingsboard by thingsboard.

the class SqlTimeseriesLatestDao method getFindLatestFuture.

protected ListenableFuture<TsKvEntry> getFindLatestFuture(EntityId entityId, String key) {
    TsKvLatestCompositeKey compositeKey = new TsKvLatestCompositeKey(entityId.getId(), getOrSaveKeyId(key));
    Optional<TsKvLatestEntity> entry = tsKvLatestRepository.findById(compositeKey);
    TsKvEntry result;
    if (entry.isPresent()) {
        TsKvLatestEntity tsKvLatestEntity = entry.get();
        tsKvLatestEntity.setStrKey(key);
        result = DaoUtil.getData(tsKvLatestEntity);
    } else {
        result = new BasicTsKvEntry(System.currentTimeMillis(), new StringDataEntry(key, null));
    }
    return Futures.immediateFuture(result);
}
Also used : TsKvLatestEntity(org.thingsboard.server.dao.model.sqlts.latest.TsKvLatestEntity) TsKvLatestCompositeKey(org.thingsboard.server.dao.model.sqlts.latest.TsKvLatestCompositeKey) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) StringDataEntry(org.thingsboard.server.common.data.kv.StringDataEntry)

Aggregations

BasicTsKvEntry (org.thingsboard.server.common.data.kv.BasicTsKvEntry)1 StringDataEntry (org.thingsboard.server.common.data.kv.StringDataEntry)1 TsKvEntry (org.thingsboard.server.common.data.kv.TsKvEntry)1 TsKvLatestCompositeKey (org.thingsboard.server.dao.model.sqlts.latest.TsKvLatestCompositeKey)1 TsKvLatestEntity (org.thingsboard.server.dao.model.sqlts.latest.TsKvLatestEntity)1