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,6 +16,7 @@ | ||
16 | package org.thingsboard.server.dao.sql.attributes; | 16 | package org.thingsboard.server.dao.sql.attributes; |
17 | 17 | ||
18 | import com.google.common.collect.Lists; | 18 | import com.google.common.collect.Lists; |
19 | +import com.google.common.util.concurrent.Futures; | ||
19 | import com.google.common.util.concurrent.ListenableFuture; | 20 | import com.google.common.util.concurrent.ListenableFuture; |
20 | import lombok.extern.slf4j.Slf4j; | 21 | import lombok.extern.slf4j.Slf4j; |
21 | import org.springframework.beans.factory.annotation.Autowired; | 22 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -49,8 +50,8 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl | @@ -49,8 +50,8 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl | ||
49 | public ListenableFuture<Optional<AttributeKvEntry>> find(EntityId entityId, String attributeType, String attributeKey) { | 50 | public ListenableFuture<Optional<AttributeKvEntry>> find(EntityId entityId, String attributeType, String attributeKey) { |
50 | AttributeKvCompositeKey compositeKey = | 51 | AttributeKvCompositeKey compositeKey = |
51 | getAttributeKvCompositeKey(entityId, attributeType, attributeKey); | 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 | @Override | 57 | @Override |
@@ -61,13 +62,13 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl | @@ -61,13 +62,13 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl | ||
61 | .map(attributeKey -> | 62 | .map(attributeKey -> |
62 | getAttributeKvCompositeKey(entityId, attributeType, attributeKey)) | 63 | getAttributeKvCompositeKey(entityId, attributeType, attributeKey)) |
63 | .collect(Collectors.toList()); | 64 | .collect(Collectors.toList()); |
64 | - return service.submit(() -> | 65 | + return Futures.immediateFuture( |
65 | DaoUtil.convertDataList(Lists.newArrayList(attributeKvRepository.findAll(compositeKeys)))); | 66 | DaoUtil.convertDataList(Lists.newArrayList(attributeKvRepository.findAll(compositeKeys)))); |
66 | } | 67 | } |
67 | 68 | ||
68 | @Override | 69 | @Override |
69 | public ListenableFuture<List<AttributeKvEntry>> findAll(EntityId entityId, String attributeType) { | 70 | public ListenableFuture<List<AttributeKvEntry>> findAll(EntityId entityId, String attributeType) { |
70 | - return service.submit(() -> | 71 | + return Futures.immediateFuture( |
71 | DaoUtil.convertDataList(Lists.newArrayList( | 72 | DaoUtil.convertDataList(Lists.newArrayList( |
72 | attributeKvRepository.findAllByEntityTypeAndEntityIdAndAttributeType( | 73 | attributeKvRepository.findAllByEntityTypeAndEntityIdAndAttributeType( |
73 | entityId.getEntityType(), | 74 | entityId.getEntityType(), |
@@ -26,9 +26,7 @@ import org.springframework.data.domain.PageRequest; | @@ -26,9 +26,7 @@ import org.springframework.data.domain.PageRequest; | ||
26 | import org.springframework.stereotype.Component; | 26 | import org.springframework.stereotype.Component; |
27 | import org.thingsboard.server.common.data.UUIDConverter; | 27 | import org.thingsboard.server.common.data.UUIDConverter; |
28 | import org.thingsboard.server.common.data.id.EntityId; | 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 | import org.thingsboard.server.dao.DaoUtil; | 30 | import org.thingsboard.server.dao.DaoUtil; |
33 | import org.thingsboard.server.dao.model.sql.TsKvEntity; | 31 | import org.thingsboard.server.dao.model.sql.TsKvEntity; |
34 | import org.thingsboard.server.dao.model.sql.TsKvLatestCompositeKey; | 32 | import org.thingsboard.server.dao.model.sql.TsKvLatestCompositeKey; |
@@ -187,7 +185,7 @@ public class JpaTimeseriesDao extends JpaAbstractDaoListeningExecutorService imp | @@ -187,7 +185,7 @@ public class JpaTimeseriesDao extends JpaAbstractDaoListeningExecutorService imp | ||
187 | } | 185 | } |
188 | 186 | ||
189 | private ListenableFuture<List<TsKvEntry>> findAllAsyncWithLimit(EntityId entityId, TsKvQuery query) { | 187 | private ListenableFuture<List<TsKvEntry>> findAllAsyncWithLimit(EntityId entityId, TsKvQuery query) { |
190 | - return service.submit(() -> | 188 | + return Futures.immediateFuture( |
191 | DaoUtil.convertDataList( | 189 | DaoUtil.convertDataList( |
192 | tsKvRepository.findAllWithLimit( | 190 | tsKvRepository.findAllWithLimit( |
193 | fromTimeUUID(entityId.getId()), | 191 | fromTimeUUID(entityId.getId()), |
@@ -205,13 +203,19 @@ public class JpaTimeseriesDao extends JpaAbstractDaoListeningExecutorService imp | @@ -205,13 +203,19 @@ public class JpaTimeseriesDao extends JpaAbstractDaoListeningExecutorService imp | ||
205 | entityId.getEntityType(), | 203 | entityId.getEntityType(), |
206 | fromTimeUUID(entityId.getId()), | 204 | fromTimeUUID(entityId.getId()), |
207 | key); | 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 | @Override | 216 | @Override |
213 | public ListenableFuture<List<TsKvEntry>> findAllLatest(EntityId entityId) { | 217 | public ListenableFuture<List<TsKvEntry>> findAllLatest(EntityId entityId) { |
214 | - return service.submit(() -> | 218 | + return Futures.immediateFuture( |
215 | DaoUtil.convertDataList(Lists.newArrayList( | 219 | DaoUtil.convertDataList(Lists.newArrayList( |
216 | tsKvLatestRepository.findAllByEntityTypeAndEntityId( | 220 | tsKvLatestRepository.findAllByEntityTypeAndEntityId( |
217 | entityId.getEntityType(), | 221 | entityId.getEntityType(), |