Commit ded769a3a7d58d8874fbdf2a6867304bffbaa13f
1 parent
e0f75302
Minor fixes to Attributes and Timeseries DAO
Showing
2 changed files
with
16 additions
and
11 deletions
... | ... | @@ -16,6 +16,7 @@ |
16 | 16 | package org.thingsboard.server.dao.sql.attributes; |
17 | 17 | |
18 | 18 | import com.google.common.collect.Lists; |
19 | +import com.google.common.util.concurrent.Futures; | |
19 | 20 | import com.google.common.util.concurrent.ListenableFuture; |
20 | 21 | import lombok.extern.slf4j.Slf4j; |
21 | 22 | import org.springframework.beans.factory.annotation.Autowired; |
... | ... | @@ -49,8 +50,8 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl |
49 | 50 | public ListenableFuture<Optional<AttributeKvEntry>> find(EntityId entityId, String attributeType, String attributeKey) { |
50 | 51 | AttributeKvCompositeKey compositeKey = |
51 | 52 | getAttributeKvCompositeKey(entityId, attributeType, attributeKey); |
52 | - return service.submit(() -> | |
53 | - Optional.of(DaoUtil.getData(attributeKvRepository.findOne(compositeKey)))); | |
53 | + return Futures.immediateFuture( | |
54 | + Optional.ofNullable(DaoUtil.getData(attributeKvRepository.findOne(compositeKey)))); | |
54 | 55 | } |
55 | 56 | |
56 | 57 | @Override |
... | ... | @@ -61,13 +62,13 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl |
61 | 62 | .map(attributeKey -> |
62 | 63 | getAttributeKvCompositeKey(entityId, attributeType, attributeKey)) |
63 | 64 | .collect(Collectors.toList()); |
64 | - return service.submit(() -> | |
65 | + return Futures.immediateFuture( | |
65 | 66 | DaoUtil.convertDataList(Lists.newArrayList(attributeKvRepository.findAll(compositeKeys)))); |
66 | 67 | } |
67 | 68 | |
68 | 69 | @Override |
69 | 70 | public ListenableFuture<List<AttributeKvEntry>> findAll(EntityId entityId, String attributeType) { |
70 | - return service.submit(() -> | |
71 | + return Futures.immediateFuture( | |
71 | 72 | DaoUtil.convertDataList(Lists.newArrayList( |
72 | 73 | attributeKvRepository.findAllByEntityTypeAndEntityIdAndAttributeType( |
73 | 74 | entityId.getEntityType(), | ... | ... |
... | ... | @@ -26,9 +26,7 @@ import org.springframework.data.domain.PageRequest; |
26 | 26 | import org.springframework.stereotype.Component; |
27 | 27 | import org.thingsboard.server.common.data.UUIDConverter; |
28 | 28 | import org.thingsboard.server.common.data.id.EntityId; |
29 | -import org.thingsboard.server.common.data.kv.Aggregation; | |
30 | -import org.thingsboard.server.common.data.kv.TsKvEntry; | |
31 | -import org.thingsboard.server.common.data.kv.TsKvQuery; | |
29 | +import org.thingsboard.server.common.data.kv.*; | |
32 | 30 | import org.thingsboard.server.dao.DaoUtil; |
33 | 31 | import org.thingsboard.server.dao.model.sql.TsKvEntity; |
34 | 32 | import org.thingsboard.server.dao.model.sql.TsKvLatestCompositeKey; |
... | ... | @@ -187,7 +185,7 @@ public class JpaTimeseriesDao extends JpaAbstractDaoListeningExecutorService imp |
187 | 185 | } |
188 | 186 | |
189 | 187 | private ListenableFuture<List<TsKvEntry>> findAllAsyncWithLimit(EntityId entityId, TsKvQuery query) { |
190 | - return service.submit(() -> | |
188 | + return Futures.immediateFuture( | |
191 | 189 | DaoUtil.convertDataList( |
192 | 190 | tsKvRepository.findAllWithLimit( |
193 | 191 | fromTimeUUID(entityId.getId()), |
... | ... | @@ -205,13 +203,19 @@ public class JpaTimeseriesDao extends JpaAbstractDaoListeningExecutorService imp |
205 | 203 | entityId.getEntityType(), |
206 | 204 | fromTimeUUID(entityId.getId()), |
207 | 205 | key); |
208 | - return service.submit(() -> | |
209 | - DaoUtil.getData(tsKvLatestRepository.findOne(compositeKey))); | |
206 | + TsKvLatestEntity entry = tsKvLatestRepository.findOne(compositeKey); | |
207 | + TsKvEntry result; | |
208 | + if (entry != null) { | |
209 | + result = DaoUtil.getData(entry); | |
210 | + } else { | |
211 | + result = new BasicTsKvEntry(System.currentTimeMillis(), new StringDataEntry(key, null)); | |
212 | + } | |
213 | + return Futures.immediateFuture(result); | |
210 | 214 | } |
211 | 215 | |
212 | 216 | @Override |
213 | 217 | public ListenableFuture<List<TsKvEntry>> findAllLatest(EntityId entityId) { |
214 | - return service.submit(() -> | |
218 | + return Futures.immediateFuture( | |
215 | 219 | DaoUtil.convertDataList(Lists.newArrayList( |
216 | 220 | tsKvLatestRepository.findAllByEntityTypeAndEntityId( |
217 | 221 | entityId.getEntityType(), | ... | ... |