Showing
13 changed files
with
147 additions
and
56 deletions
@@ -36,5 +36,5 @@ public interface AttributesDao { | @@ -36,5 +36,5 @@ public interface AttributesDao { | ||
36 | 36 | ||
37 | ListenableFuture<Void> save(EntityId entityId, String attributeType, AttributeKvEntry attribute); | 37 | ListenableFuture<Void> save(EntityId entityId, String attributeType, AttributeKvEntry attribute); |
38 | 38 | ||
39 | - ListenableFuture<List<Void>> removeAll(EntityId entityId, String scope, List<String> keys); | 39 | + ListenableFuture<List<Void>> removeAll(EntityId entityId, String attributeType, List<String> keys); |
40 | } | 40 | } |
dao/src/main/java/org/thingsboard/server/dao/model/sql/AttributeKvCompositeKey.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/model/sql/AttributesKvCompositeKey.java
@@ -15,13 +15,17 @@ | @@ -15,13 +15,17 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.sql; | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | ||
18 | +import lombok.AllArgsConstructor; | ||
18 | import lombok.Data; | 19 | import lombok.Data; |
20 | +import lombok.NoArgsConstructor; | ||
19 | 21 | ||
20 | import java.io.Serializable; | 22 | import java.io.Serializable; |
21 | import java.util.UUID; | 23 | import java.util.UUID; |
22 | 24 | ||
23 | @Data | 25 | @Data |
24 | -public class AttributesKvCompositeKey implements Serializable { | 26 | +@AllArgsConstructor |
27 | +@NoArgsConstructor | ||
28 | +public class AttributeKvCompositeKey implements Serializable { | ||
25 | private String entityType; | 29 | private String entityType; |
26 | private UUID entityId; | 30 | private UUID entityId; |
27 | private String attributeType; | 31 | private String attributeType; |
@@ -16,21 +16,20 @@ | @@ -16,21 +16,20 @@ | ||
16 | package org.thingsboard.server.dao.model.sql; | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | -import org.thingsboard.server.common.data.kv.AttributeKvEntry; | 19 | +import org.thingsboard.server.common.data.kv.*; |
20 | import org.thingsboard.server.dao.model.ToData; | 20 | import org.thingsboard.server.dao.model.ToData; |
21 | 21 | ||
22 | -import javax.persistence.Column; | ||
23 | -import javax.persistence.Entity; | ||
24 | -import javax.persistence.Id; | ||
25 | -import javax.persistence.Table; | 22 | +import javax.persistence.*; |
23 | +import java.io.Serializable; | ||
26 | import java.util.UUID; | 24 | import java.util.UUID; |
27 | 25 | ||
28 | import static org.thingsboard.server.dao.model.ModelConstants.*; | 26 | import static org.thingsboard.server.dao.model.ModelConstants.*; |
29 | 27 | ||
30 | @Data | 28 | @Data |
31 | @Entity | 29 | @Entity |
32 | -@Table(name = "attributes_kv") | ||
33 | -public class AttributeKvEntity implements ToData<AttributeKvEntry> { | 30 | +@Table(name = "attribute_kv") |
31 | +@IdClass(AttributeKvCompositeKey.class) | ||
32 | +public class AttributeKvEntity implements ToData<AttributeKvEntry>, Serializable { | ||
34 | 33 | ||
35 | @Id | 34 | @Id |
36 | @Column(name = ENTITY_TYPE_COLUMN) | 35 | @Column(name = ENTITY_TYPE_COLUMN) |
@@ -65,7 +64,16 @@ public class AttributeKvEntity implements ToData<AttributeKvEntry> { | @@ -65,7 +64,16 @@ public class AttributeKvEntity implements ToData<AttributeKvEntry> { | ||
65 | 64 | ||
66 | @Override | 65 | @Override |
67 | public AttributeKvEntry toData() { | 66 | public AttributeKvEntry toData() { |
68 | - // TODO - add implementation | ||
69 | - return null; | 67 | + KvEntry kvEntry = null; |
68 | + if (strValue != null) { | ||
69 | + kvEntry = new StringDataEntry(attributeKey, strValue); | ||
70 | + } else if (booleanValue != null) { | ||
71 | + kvEntry = new BooleanDataEntry(attributeKey, booleanValue); | ||
72 | + } else if (doubleValue != null) { | ||
73 | + kvEntry = new DoubleDataEntry(attributeKey, doubleValue); | ||
74 | + } else if (longValue != null) { | ||
75 | + kvEntry = new LongDataEntry(attributeKey, longValue); | ||
76 | + } | ||
77 | + return new BaseAttributeKvEntry(kvEntry, lastUpdateTs); | ||
70 | } | 78 | } |
71 | } | 79 | } |
@@ -38,7 +38,9 @@ import static org.springframework.transaction.annotation.Propagation.REQUIRES_NE | @@ -38,7 +38,9 @@ import static org.springframework.transaction.annotation.Propagation.REQUIRES_NE | ||
38 | * @author Valerii Sosliuk | 38 | * @author Valerii Sosliuk |
39 | */ | 39 | */ |
40 | @Slf4j | 40 | @Slf4j |
41 | -public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> implements Dao<D> { | 41 | +public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> |
42 | + extends JpaAbstractDaoListeningExecutorService | ||
43 | + implements Dao<D> { | ||
42 | 44 | ||
43 | protected abstract Class<E> getEntityClass(); | 45 | protected abstract Class<E> getEntityClass(); |
44 | 46 | ||
@@ -48,8 +50,6 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> implements Dao< | @@ -48,8 +50,6 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> implements Dao< | ||
48 | return false; | 50 | return false; |
49 | } | 51 | } |
50 | 52 | ||
51 | - protected ListeningExecutorService service = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10)); | ||
52 | - | ||
53 | @Override | 53 | @Override |
54 | @Transactional(propagation = REQUIRES_NEW) | 54 | @Transactional(propagation = REQUIRES_NEW) |
55 | public D save(D domain) { | 55 | public D save(D domain) { |
dao/src/main/java/org/thingsboard/server/dao/sql/JpaAbstractDaoListeningExecutorService.java
0 → 100644
1 | +/** | ||
2 | + * Copyright © 2016-2017 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.dao.sql; | ||
17 | + | ||
18 | +import com.google.common.util.concurrent.ListeningExecutorService; | ||
19 | +import com.google.common.util.concurrent.MoreExecutors; | ||
20 | + | ||
21 | +import java.util.concurrent.Executors; | ||
22 | + | ||
23 | +public abstract class JpaAbstractDaoListeningExecutorService { | ||
24 | + protected ListeningExecutorService service = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10)); | ||
25 | +} |
@@ -17,9 +17,17 @@ package org.thingsboard.server.dao.sql.attributes; | @@ -17,9 +17,17 @@ package org.thingsboard.server.dao.sql.attributes; | ||
17 | 17 | ||
18 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | 18 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
19 | import org.springframework.data.repository.CrudRepository; | 19 | import org.springframework.data.repository.CrudRepository; |
20 | +import org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey; | ||
20 | import org.thingsboard.server.dao.model.sql.AttributeKvEntity; | 21 | import org.thingsboard.server.dao.model.sql.AttributeKvEntity; |
21 | -import org.thingsboard.server.dao.model.sql.AttributesKvCompositeKey; | 22 | + |
23 | +import java.util.List; | ||
24 | +import java.util.UUID; | ||
22 | 25 | ||
23 | @ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true") | 26 | @ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true") |
24 | -public interface AttributeKvRepository extends CrudRepository<AttributeKvEntity, AttributesKvCompositeKey> { | 27 | +public interface AttributeKvRepository extends CrudRepository<AttributeKvEntity, AttributeKvCompositeKey> { |
28 | + | ||
29 | + List<AttributeKvEntity> findAllByEntityTypeAndEntityIdAndAttributeType(String entityType, | ||
30 | + UUID entityId, | ||
31 | + String attributeType); | ||
25 | } | 32 | } |
33 | + |
@@ -15,6 +15,7 @@ | @@ -15,6 +15,7 @@ | ||
15 | */ | 15 | */ |
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.util.concurrent.ListenableFuture; | 19 | import com.google.common.util.concurrent.ListenableFuture; |
19 | import lombok.extern.slf4j.Slf4j; | 20 | import lombok.extern.slf4j.Slf4j; |
20 | import org.springframework.beans.factory.annotation.Autowired; | 21 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -22,42 +23,97 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | @@ -22,42 +23,97 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
22 | import org.springframework.stereotype.Component; | 23 | import org.springframework.stereotype.Component; |
23 | import org.thingsboard.server.common.data.id.EntityId; | 24 | import org.thingsboard.server.common.data.id.EntityId; |
24 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; | 25 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
26 | +import org.thingsboard.server.dao.DaoUtil; | ||
25 | import org.thingsboard.server.dao.attributes.AttributesDao; | 27 | import org.thingsboard.server.dao.attributes.AttributesDao; |
28 | +import org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey; | ||
29 | +import org.thingsboard.server.dao.model.sql.AttributeKvEntity; | ||
30 | +import org.thingsboard.server.dao.sql.JpaAbstractDaoListeningExecutorService; | ||
26 | 31 | ||
27 | import java.util.Collection; | 32 | import java.util.Collection; |
28 | import java.util.List; | 33 | import java.util.List; |
29 | import java.util.Optional; | 34 | import java.util.Optional; |
35 | +import java.util.stream.Collectors; | ||
30 | 36 | ||
31 | @Component | 37 | @Component |
32 | @Slf4j | 38 | @Slf4j |
33 | @ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true") | 39 | @ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true") |
34 | -public class JpaAttributeDao implements AttributesDao { | 40 | +public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService implements AttributesDao { |
35 | 41 | ||
36 | @Autowired | 42 | @Autowired |
37 | private AttributeKvRepository attributeKvRepository; | 43 | private AttributeKvRepository attributeKvRepository; |
38 | 44 | ||
39 | @Override | 45 | @Override |
40 | public ListenableFuture<Optional<AttributeKvEntry>> find(EntityId entityId, String attributeType, String attributeKey) { | 46 | public ListenableFuture<Optional<AttributeKvEntry>> find(EntityId entityId, String attributeType, String attributeKey) { |
41 | - return null; | 47 | + AttributeKvCompositeKey compositeKey = |
48 | + new AttributeKvCompositeKey( | ||
49 | + entityId.getEntityType().name(), | ||
50 | + entityId.getId(), | ||
51 | + attributeType, | ||
52 | + attributeKey); | ||
53 | + return service.submit(() -> | ||
54 | + Optional.of(DaoUtil.getData(attributeKvRepository.findOne(compositeKey)))); | ||
42 | } | 55 | } |
43 | 56 | ||
44 | @Override | 57 | @Override |
45 | - public ListenableFuture<List<AttributeKvEntry>> find(EntityId entityId, String attributeType, Collection<String> attributeKey) { | ||
46 | - return null; | 58 | + public ListenableFuture<List<AttributeKvEntry>> find(EntityId entityId, String attributeType, Collection<String> attributeKeys) { |
59 | + List<AttributeKvCompositeKey> compositeKeys = | ||
60 | + attributeKeys | ||
61 | + .stream() | ||
62 | + .map(attributeKey -> | ||
63 | + new AttributeKvCompositeKey( | ||
64 | + entityId.getEntityType().name(), | ||
65 | + entityId.getId(), | ||
66 | + attributeType, | ||
67 | + attributeKey)) | ||
68 | + .collect(Collectors.toList()); | ||
69 | + return service.submit(() -> | ||
70 | + DaoUtil.convertDataList(Lists.newArrayList(attributeKvRepository.findAll(compositeKeys)))); | ||
47 | } | 71 | } |
48 | 72 | ||
49 | @Override | 73 | @Override |
50 | public ListenableFuture<List<AttributeKvEntry>> findAll(EntityId entityId, String attributeType) { | 74 | public ListenableFuture<List<AttributeKvEntry>> findAll(EntityId entityId, String attributeType) { |
51 | - return null; | 75 | + return service.submit(() -> |
76 | + DaoUtil.convertDataList(Lists.newArrayList( | ||
77 | + attributeKvRepository.findAllByEntityTypeAndEntityIdAndAttributeType( | ||
78 | + entityId.getEntityType().name(), | ||
79 | + entityId.getId(), | ||
80 | + attributeType)))); | ||
52 | } | 81 | } |
53 | 82 | ||
54 | @Override | 83 | @Override |
55 | public ListenableFuture<Void> save(EntityId entityId, String attributeType, AttributeKvEntry attribute) { | 84 | public ListenableFuture<Void> save(EntityId entityId, String attributeType, AttributeKvEntry attribute) { |
56 | - return null; | 85 | + AttributeKvEntity entity = new AttributeKvEntity(); |
86 | + entity.setEntityType(entityId.getEntityType().name()); | ||
87 | + entity.setEntityId(entityId.getId()); | ||
88 | + entity.setAttributeType(attributeType); | ||
89 | + entity.setAttributeKey(attribute.getKey()); | ||
90 | + entity.setLastUpdateTs(attribute.getLastUpdateTs()); | ||
91 | + entity.setStrValue(attribute.getStrValue().orElse(null)); | ||
92 | + entity.setDoubleValue(attribute.getDoubleValue().orElse(null)); | ||
93 | + entity.setLongValue(attribute.getLongValue().orElse(null)); | ||
94 | + entity.setBooleanValue(attribute.getBooleanValue().orElse(null)); | ||
95 | + return service.submit(() -> { | ||
96 | + attributeKvRepository.save(entity); | ||
97 | + return null; | ||
98 | + }); | ||
57 | } | 99 | } |
58 | 100 | ||
59 | @Override | 101 | @Override |
60 | - public ListenableFuture<List<Void>> removeAll(EntityId entityId, String scope, List<String> keys) { | ||
61 | - return null; | 102 | + public ListenableFuture<List<Void>> removeAll(EntityId entityId, String attributeType, List<String> keys) { |
103 | + List<AttributeKvEntity> entitiesToDelete = keys | ||
104 | + .stream() | ||
105 | + .map(key -> { | ||
106 | + AttributeKvEntity entityToDelete = new AttributeKvEntity(); | ||
107 | + entityToDelete.setEntityType(entityId.getEntityType().name()); | ||
108 | + entityToDelete.setEntityId(entityId.getId()); | ||
109 | + entityToDelete.setAttributeType(attributeType); | ||
110 | + entityToDelete.setAttributeKey(key); | ||
111 | + return entityToDelete; | ||
112 | + }).collect(Collectors.toList()); | ||
113 | + | ||
114 | + return service.submit(() -> { | ||
115 | + attributeKvRepository.delete(entitiesToDelete); | ||
116 | + return null; | ||
117 | + }); | ||
62 | } | 118 | } |
63 | } | 119 | } |
@@ -16,8 +16,6 @@ | @@ -16,8 +16,6 @@ | ||
16 | package org.thingsboard.server.dao.sql.relation; | 16 | package org.thingsboard.server.dao.sql.relation; |
17 | 17 | ||
18 | import com.google.common.util.concurrent.ListenableFuture; | 18 | import com.google.common.util.concurrent.ListenableFuture; |
19 | -import com.google.common.util.concurrent.ListeningExecutorService; | ||
20 | -import com.google.common.util.concurrent.MoreExecutors; | ||
21 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
22 | import org.springframework.beans.factory.annotation.Autowired; | 20 | import org.springframework.beans.factory.annotation.Autowired; |
23 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | 21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
@@ -36,6 +34,7 @@ import org.thingsboard.server.dao.DaoUtil; | @@ -36,6 +34,7 @@ import org.thingsboard.server.dao.DaoUtil; | ||
36 | import org.thingsboard.server.dao.model.sql.RelationCompositeKey; | 34 | import org.thingsboard.server.dao.model.sql.RelationCompositeKey; |
37 | import org.thingsboard.server.dao.model.sql.RelationEntity; | 35 | import org.thingsboard.server.dao.model.sql.RelationEntity; |
38 | import org.thingsboard.server.dao.relation.RelationDao; | 36 | import org.thingsboard.server.dao.relation.RelationDao; |
37 | +import org.thingsboard.server.dao.sql.JpaAbstractDaoListeningExecutorService; | ||
39 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTimeDao; | 38 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTimeDao; |
40 | 39 | ||
41 | import javax.persistence.criteria.CriteriaBuilder; | 40 | import javax.persistence.criteria.CriteriaBuilder; |
@@ -44,7 +43,6 @@ import javax.persistence.criteria.Predicate; | @@ -44,7 +43,6 @@ import javax.persistence.criteria.Predicate; | ||
44 | import javax.persistence.criteria.Root; | 43 | import javax.persistence.criteria.Root; |
45 | import java.util.ArrayList; | 44 | import java.util.ArrayList; |
46 | import java.util.List; | 45 | import java.util.List; |
47 | -import java.util.concurrent.Executors; | ||
48 | 46 | ||
49 | import static org.springframework.data.domain.Sort.Direction.ASC; | 47 | import static org.springframework.data.domain.Sort.Direction.ASC; |
50 | import static org.springframework.data.jpa.domain.Specifications.where; | 48 | import static org.springframework.data.jpa.domain.Specifications.where; |
@@ -56,16 +54,14 @@ import static org.thingsboard.server.dao.model.ModelConstants.*; | @@ -56,16 +54,14 @@ import static org.thingsboard.server.dao.model.ModelConstants.*; | ||
56 | @Slf4j | 54 | @Slf4j |
57 | @Component | 55 | @Component |
58 | @ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false) | 56 | @ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false) |
59 | -public class JpaRelationDao implements RelationDao { | 57 | +public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService implements RelationDao { |
60 | 58 | ||
61 | @Autowired | 59 | @Autowired |
62 | private RelationRepository relationRepository; | 60 | private RelationRepository relationRepository; |
63 | 61 | ||
64 | - private ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10)); | ||
65 | - | ||
66 | @Override | 62 | @Override |
67 | public ListenableFuture<List<EntityRelation>> findAllByFrom(EntityId from, RelationTypeGroup typeGroup) { | 63 | public ListenableFuture<List<EntityRelation>> findAllByFrom(EntityId from, RelationTypeGroup typeGroup) { |
68 | - return executorService.submit(() -> DaoUtil.convertDataList( | 64 | + return service.submit(() -> DaoUtil.convertDataList( |
69 | relationRepository.findAllByFromIdAndFromTypeAndRelationTypeGroup( | 65 | relationRepository.findAllByFromIdAndFromTypeAndRelationTypeGroup( |
70 | from.getId(), | 66 | from.getId(), |
71 | from.getEntityType().name(), | 67 | from.getEntityType().name(), |
@@ -74,7 +70,7 @@ public class JpaRelationDao implements RelationDao { | @@ -74,7 +70,7 @@ public class JpaRelationDao implements RelationDao { | ||
74 | 70 | ||
75 | @Override | 71 | @Override |
76 | public ListenableFuture<List<EntityRelation>> findAllByFromAndType(EntityId from, String relationType, RelationTypeGroup typeGroup) { | 72 | public ListenableFuture<List<EntityRelation>> findAllByFromAndType(EntityId from, String relationType, RelationTypeGroup typeGroup) { |
77 | - return executorService.submit(() -> DaoUtil.convertDataList( | 73 | + return service.submit(() -> DaoUtil.convertDataList( |
78 | relationRepository.findAllByFromIdAndFromTypeAndRelationTypeAndRelationTypeGroup( | 74 | relationRepository.findAllByFromIdAndFromTypeAndRelationTypeAndRelationTypeGroup( |
79 | from.getId(), | 75 | from.getId(), |
80 | from.getEntityType().name(), | 76 | from.getEntityType().name(), |
@@ -84,7 +80,7 @@ public class JpaRelationDao implements RelationDao { | @@ -84,7 +80,7 @@ public class JpaRelationDao implements RelationDao { | ||
84 | 80 | ||
85 | @Override | 81 | @Override |
86 | public ListenableFuture<List<EntityRelation>> findAllByTo(EntityId to, RelationTypeGroup typeGroup) { | 82 | public ListenableFuture<List<EntityRelation>> findAllByTo(EntityId to, RelationTypeGroup typeGroup) { |
87 | - return executorService.submit(() -> DaoUtil.convertDataList( | 83 | + return service.submit(() -> DaoUtil.convertDataList( |
88 | relationRepository.findAllByToIdAndToTypeAndRelationTypeGroup( | 84 | relationRepository.findAllByToIdAndToTypeAndRelationTypeGroup( |
89 | to.getId(), | 85 | to.getId(), |
90 | to.getEntityType().name(), | 86 | to.getEntityType().name(), |
@@ -93,7 +89,7 @@ public class JpaRelationDao implements RelationDao { | @@ -93,7 +89,7 @@ public class JpaRelationDao implements RelationDao { | ||
93 | 89 | ||
94 | @Override | 90 | @Override |
95 | public ListenableFuture<List<EntityRelation>> findAllByToAndType(EntityId to, String relationType, RelationTypeGroup typeGroup) { | 91 | public ListenableFuture<List<EntityRelation>> findAllByToAndType(EntityId to, String relationType, RelationTypeGroup typeGroup) { |
96 | - return executorService.submit(() -> DaoUtil.convertDataList( | 92 | + return service.submit(() -> DaoUtil.convertDataList( |
97 | relationRepository.findAllByToIdAndToTypeAndRelationTypeAndRelationTypeGroup( | 93 | relationRepository.findAllByToIdAndToTypeAndRelationTypeAndRelationTypeGroup( |
98 | to.getId(), | 94 | to.getId(), |
99 | to.getEntityType().name(), | 95 | to.getEntityType().name(), |
@@ -110,18 +106,18 @@ public class JpaRelationDao implements RelationDao { | @@ -110,18 +106,18 @@ public class JpaRelationDao implements RelationDao { | ||
110 | to.getEntityType().name(), | 106 | to.getEntityType().name(), |
111 | relationType, | 107 | relationType, |
112 | typeGroup.name()); | 108 | typeGroup.name()); |
113 | - return executorService.submit(() -> relationRepository.findOne(key) != null); | 109 | + return service.submit(() -> relationRepository.findOne(key) != null); |
114 | } | 110 | } |
115 | 111 | ||
116 | @Override | 112 | @Override |
117 | public ListenableFuture<Boolean> saveRelation(EntityRelation relation) { | 113 | public ListenableFuture<Boolean> saveRelation(EntityRelation relation) { |
118 | - return executorService.submit(() -> relationRepository.save(new RelationEntity(relation)) != null); | 114 | + return service.submit(() -> relationRepository.save(new RelationEntity(relation)) != null); |
119 | } | 115 | } |
120 | 116 | ||
121 | @Override | 117 | @Override |
122 | public ListenableFuture<Boolean> deleteRelation(EntityRelation relation) { | 118 | public ListenableFuture<Boolean> deleteRelation(EntityRelation relation) { |
123 | RelationCompositeKey key = new RelationCompositeKey(relation); | 119 | RelationCompositeKey key = new RelationCompositeKey(relation); |
124 | - return executorService.submit( | 120 | + return service.submit( |
125 | () -> { | 121 | () -> { |
126 | boolean relationExistsBeforeDelete = relationRepository.exists(key); | 122 | boolean relationExistsBeforeDelete = relationRepository.exists(key); |
127 | relationRepository.delete(key); | 123 | relationRepository.delete(key); |
@@ -138,7 +134,7 @@ public class JpaRelationDao implements RelationDao { | @@ -138,7 +134,7 @@ public class JpaRelationDao implements RelationDao { | ||
138 | to.getEntityType().name(), | 134 | to.getEntityType().name(), |
139 | relationType, | 135 | relationType, |
140 | typeGroup.name()); | 136 | typeGroup.name()); |
141 | - return executorService.submit( | 137 | + return service.submit( |
142 | () -> { | 138 | () -> { |
143 | boolean relationExistsBeforeDelete = relationRepository.exists(key); | 139 | boolean relationExistsBeforeDelete = relationRepository.exists(key); |
144 | relationRepository.delete(key); | 140 | relationRepository.delete(key); |
@@ -152,7 +148,7 @@ public class JpaRelationDao implements RelationDao { | @@ -152,7 +148,7 @@ public class JpaRelationDao implements RelationDao { | ||
152 | relationEntity.setFromId(entity.getId()); | 148 | relationEntity.setFromId(entity.getId()); |
153 | relationEntity.setFromType(entity.getEntityType().name()); | 149 | relationEntity.setFromType(entity.getEntityType().name()); |
154 | 150 | ||
155 | - return executorService.submit( | 151 | + return service.submit( |
156 | () -> { | 152 | () -> { |
157 | boolean relationExistsBeforeDelete = relationRepository | 153 | boolean relationExistsBeforeDelete = relationRepository |
158 | .findAllByFromIdAndFromType(relationEntity.getFromId(), relationEntity.getFromType()) | 154 | .findAllByFromIdAndFromType(relationEntity.getFromId(), relationEntity.getFromType()) |
@@ -172,7 +168,7 @@ public class JpaRelationDao implements RelationDao { | @@ -172,7 +168,7 @@ public class JpaRelationDao implements RelationDao { | ||
172 | new Order(ASC, RELATION_TYPE_PROPERTY), | 168 | new Order(ASC, RELATION_TYPE_PROPERTY), |
173 | new Order(ASC, RELATION_TO_TYPE_PROPERTY)) | 169 | new Order(ASC, RELATION_TO_TYPE_PROPERTY)) |
174 | ); | 170 | ); |
175 | - return executorService.submit(() -> | 171 | + return service.submit(() -> |
176 | DaoUtil.convertDataList(relationRepository.findAll(where(timeSearchSpec).and(fieldsSpec), pageable).getContent())); | 172 | DaoUtil.convertDataList(relationRepository.findAll(where(timeSearchSpec).and(fieldsSpec), pageable).getContent())); |
177 | } | 173 | } |
178 | 174 |
@@ -23,7 +23,7 @@ import java.util.Properties; | @@ -23,7 +23,7 @@ import java.util.Properties; | ||
23 | /** | 23 | /** |
24 | * Created by Valerii Sosliuk on 5/12/2017. | 24 | * Created by Valerii Sosliuk on 5/12/2017. |
25 | */ | 25 | */ |
26 | -public class JsonBinaryType extends AbstractSingleColumnStandardBasicType<Object> | 26 | +public class JsonBinaryType extends AbstractSingleColumnStandardBasicType<Object> |
27 | implements DynamicParameterizedType { | 27 | implements DynamicParameterizedType { |
28 | 28 | ||
29 | public JsonBinaryType() { | 29 | public JsonBinaryType() { |
@@ -74,7 +74,7 @@ CREATE TABLE IF NOT EXISTS asset ( | @@ -74,7 +74,7 @@ CREATE TABLE IF NOT EXISTS asset ( | ||
74 | ); | 74 | ); |
75 | ALTER TABLE asset OWNER TO postgres; | 75 | ALTER TABLE asset OWNER TO postgres; |
76 | 76 | ||
77 | -CREATE TABLE IF NOT EXISTS attributes_kv ( | 77 | +CREATE TABLE IF NOT EXISTS attribute_kv ( |
78 | entity_type character varying(255), | 78 | entity_type character varying(255), |
79 | entity_id uuid, | 79 | entity_id uuid, |
80 | attribute_type character varying(255), | 80 | attribute_type character varying(255), |
@@ -84,7 +84,7 @@ CREATE TABLE IF NOT EXISTS attributes_kv ( | @@ -84,7 +84,7 @@ CREATE TABLE IF NOT EXISTS attributes_kv ( | ||
84 | long_v bigint, | 84 | long_v bigint, |
85 | dbl_v double precision, | 85 | dbl_v double precision, |
86 | last_update_ts bigint, | 86 | last_update_ts bigint, |
87 | - CONSTRAINT attributes_kv_unq_key UNIQUE (entity_type, entity_id, attribute_type, attribute_key) | 87 | + CONSTRAINT attribute_kv_unq_key UNIQUE (entity_type, entity_id, attribute_type, attribute_key) |
88 | ); | 88 | ); |
89 | ALTER TABLE relation OWNER TO postgres; | 89 | ALTER TABLE relation OWNER TO postgres; |
90 | 90 |
@@ -37,6 +37,6 @@ import org.springframework.test.context.support.DirtiesContextTestExecutionListe | @@ -37,6 +37,6 @@ import org.springframework.test.context.support.DirtiesContextTestExecutionListe | ||
37 | DirtiesContextTestExecutionListener.class, | 37 | DirtiesContextTestExecutionListener.class, |
38 | DbUnitTestExecutionListener.class }) | 38 | DbUnitTestExecutionListener.class }) |
39 | @DbUnitConfiguration(databaseConnection = "dbUnitDatabaseConnection") | 39 | @DbUnitConfiguration(databaseConnection = "dbUnitDatabaseConnection") |
40 | -public class AbstractJpaDaoTest extends AbstractTransactionalJUnit4SpringContextTests { | 40 | +public abstract class AbstractJpaDaoTest extends AbstractTransactionalJUnit4SpringContextTests { |
41 | 41 | ||
42 | } | 42 | } |
@@ -38,8 +38,7 @@ public class DaoTestSuite { | @@ -38,8 +38,7 @@ public class DaoTestSuite { | ||
38 | public static CustomCassandraCQLUnit cassandraUnit = | 38 | public static CustomCassandraCQLUnit cassandraUnit = |
39 | new CustomCassandraCQLUnit( | 39 | new CustomCassandraCQLUnit( |
40 | Arrays.asList(new ClassPathCQLDataSet("cassandra/schema.cql", false, false), | 40 | Arrays.asList(new ClassPathCQLDataSet("cassandra/schema.cql", false, false), |
41 | - new ClassPathCQLDataSet("cassandra/system-data.cql", false, false), | ||
42 | - new ClassPathCQLDataSet("system-test.cql", false, false)), | 41 | + new ClassPathCQLDataSet("cassandra/system-data.cql", false, false), |
42 | + new ClassPathCQLDataSet("system-test.cql", false, false)), | ||
43 | "cassandra-test.yaml", 30000l); | 43 | "cassandra-test.yaml", 30000l); |
44 | - | ||
45 | } | 44 | } |
@@ -16,6 +16,10 @@ | @@ -16,6 +16,10 @@ | ||
16 | package org.thingsboard.server.dao.attributes; | 16 | package org.thingsboard.server.dao.attributes; |
17 | 17 | ||
18 | import com.datastax.driver.core.utils.UUIDs; | 18 | import com.datastax.driver.core.utils.UUIDs; |
19 | +import org.junit.Assert; | ||
20 | +import org.junit.Before; | ||
21 | +import org.junit.Test; | ||
22 | +import org.springframework.beans.factory.annotation.Autowired; | ||
19 | import org.thingsboard.server.common.data.DataConstants; | 23 | import org.thingsboard.server.common.data.DataConstants; |
20 | import org.thingsboard.server.common.data.id.DeviceId; | 24 | import org.thingsboard.server.common.data.id.DeviceId; |
21 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; | 25 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
@@ -23,20 +27,11 @@ import org.thingsboard.server.common.data.kv.BaseAttributeKvEntry; | @@ -23,20 +27,11 @@ import org.thingsboard.server.common.data.kv.BaseAttributeKvEntry; | ||
23 | import org.thingsboard.server.common.data.kv.KvEntry; | 27 | import org.thingsboard.server.common.data.kv.KvEntry; |
24 | import org.thingsboard.server.common.data.kv.StringDataEntry; | 28 | import org.thingsboard.server.common.data.kv.StringDataEntry; |
25 | import org.thingsboard.server.dao.service.AbstractServiceTest; | 29 | import org.thingsboard.server.dao.service.AbstractServiceTest; |
26 | -import org.junit.Assert; | ||
27 | -import org.junit.Before; | ||
28 | -import org.junit.Test; | ||
29 | -import org.slf4j.Logger; | ||
30 | -import org.slf4j.LoggerFactory; | ||
31 | -import org.springframework.beans.factory.annotation.Autowired; | ||
32 | 30 | ||
33 | import java.util.Collections; | 31 | import java.util.Collections; |
34 | import java.util.List; | 32 | import java.util.List; |
35 | import java.util.Optional; | 33 | import java.util.Optional; |
36 | 34 | ||
37 | -import static org.thingsboard.server.common.data.DataConstants.CLIENT_SCOPE; | ||
38 | -import static org.thingsboard.server.common.data.DataConstants.DEVICE; | ||
39 | - | ||
40 | /** | 35 | /** |
41 | * @author Andrew Shvayka | 36 | * @author Andrew Shvayka |
42 | */ | 37 | */ |