Minor fixes to Attributes and Timeseries DAO
This commit is contained in:
parent
e0f753025d
commit
ded769a3a7
@ -16,6 +16,7 @@
|
||||
package org.thingsboard.server.dao.sql.attributes;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -49,8 +50,8 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl
|
||||
public ListenableFuture<Optional<AttributeKvEntry>> find(EntityId entityId, String attributeType, String attributeKey) {
|
||||
AttributeKvCompositeKey compositeKey =
|
||||
getAttributeKvCompositeKey(entityId, attributeType, attributeKey);
|
||||
return service.submit(() ->
|
||||
Optional.of(DaoUtil.getData(attributeKvRepository.findOne(compositeKey))));
|
||||
return Futures.immediateFuture(
|
||||
Optional.ofNullable(DaoUtil.getData(attributeKvRepository.findOne(compositeKey))));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -61,13 +62,13 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl
|
||||
.map(attributeKey ->
|
||||
getAttributeKvCompositeKey(entityId, attributeType, attributeKey))
|
||||
.collect(Collectors.toList());
|
||||
return service.submit(() ->
|
||||
return Futures.immediateFuture(
|
||||
DaoUtil.convertDataList(Lists.newArrayList(attributeKvRepository.findAll(compositeKeys))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListenableFuture<List<AttributeKvEntry>> findAll(EntityId entityId, String attributeType) {
|
||||
return service.submit(() ->
|
||||
return Futures.immediateFuture(
|
||||
DaoUtil.convertDataList(Lists.newArrayList(
|
||||
attributeKvRepository.findAllByEntityTypeAndEntityIdAndAttributeType(
|
||||
entityId.getEntityType(),
|
||||
|
||||
@ -26,9 +26,7 @@ import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.thingsboard.server.common.data.UUIDConverter;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.kv.Aggregation;
|
||||
import org.thingsboard.server.common.data.kv.TsKvEntry;
|
||||
import org.thingsboard.server.common.data.kv.TsKvQuery;
|
||||
import org.thingsboard.server.common.data.kv.*;
|
||||
import org.thingsboard.server.dao.DaoUtil;
|
||||
import org.thingsboard.server.dao.model.sql.TsKvEntity;
|
||||
import org.thingsboard.server.dao.model.sql.TsKvLatestCompositeKey;
|
||||
@ -187,7 +185,7 @@ public class JpaTimeseriesDao extends JpaAbstractDaoListeningExecutorService imp
|
||||
}
|
||||
|
||||
private ListenableFuture<List<TsKvEntry>> findAllAsyncWithLimit(EntityId entityId, TsKvQuery query) {
|
||||
return service.submit(() ->
|
||||
return Futures.immediateFuture(
|
||||
DaoUtil.convertDataList(
|
||||
tsKvRepository.findAllWithLimit(
|
||||
fromTimeUUID(entityId.getId()),
|
||||
@ -205,13 +203,19 @@ public class JpaTimeseriesDao extends JpaAbstractDaoListeningExecutorService imp
|
||||
entityId.getEntityType(),
|
||||
fromTimeUUID(entityId.getId()),
|
||||
key);
|
||||
return service.submit(() ->
|
||||
DaoUtil.getData(tsKvLatestRepository.findOne(compositeKey)));
|
||||
TsKvLatestEntity entry = tsKvLatestRepository.findOne(compositeKey);
|
||||
TsKvEntry result;
|
||||
if (entry != null) {
|
||||
result = DaoUtil.getData(entry);
|
||||
} else {
|
||||
result = new BasicTsKvEntry(System.currentTimeMillis(), new StringDataEntry(key, null));
|
||||
}
|
||||
return Futures.immediateFuture(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListenableFuture<List<TsKvEntry>> findAllLatest(EntityId entityId) {
|
||||
return service.submit(() ->
|
||||
return Futures.immediateFuture(
|
||||
DaoUtil.convertDataList(Lists.newArrayList(
|
||||
tsKvLatestRepository.findAllByEntityTypeAndEntityId(
|
||||
entityId.getEntityType(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user