Showing
27 changed files
with
235 additions
and
699 deletions
... | ... | @@ -26,12 +26,12 @@ import org.thingsboard.server.dao.util.SqlTsDao; |
26 | 26 | |
27 | 27 | @Configuration |
28 | 28 | @EnableAutoConfiguration |
29 | -@ComponentScan({"org.thingsboard.server.dao.sqlts.hsql", "org.thingsboard.server.dao.sqlts.latest"}) | |
30 | -@EnableJpaRepositories({"org.thingsboard.server.dao.sqlts.hsql", "org.thingsboard.server.dao.sqlts.latest", "org.thingsboard.server.dao.sqlts.dictionary"}) | |
31 | -@EntityScan({"org.thingsboard.server.dao.model.sqlts.hsql", "org.thingsboard.server.dao.model.sqlts.latest", "org.thingsboard.server.dao.model.sqlts.dictionary"}) | |
29 | +@ComponentScan({"org.thingsboard.server.dao.sqlts.hsql"}) | |
30 | +@EnableJpaRepositories({"org.thingsboard.server.dao.sqlts.ts", "org.thingsboard.server.dao.sqlts.insert.hsql", "org.thingsboard.server.dao.sqlts.insert.latest.hsql", "org.thingsboard.server.dao.sqlts.latest", "org.thingsboard.server.dao.sqlts.dictionary"}) | |
31 | +@EntityScan({"org.thingsboard.server.dao.model.sqlts.ts", "org.thingsboard.server.dao.model.sqlts.latest", "org.thingsboard.server.dao.model.sqlts.dictionary"}) | |
32 | 32 | @EnableTransactionManagement |
33 | 33 | @SqlTsDao |
34 | 34 | @HsqlDao |
35 | 35 | public class HsqlTsDaoConfig { |
36 | 36 | |
37 | -} | |
\ No newline at end of file | ||
37 | +} | ... | ... |
... | ... | @@ -26,12 +26,12 @@ import org.thingsboard.server.dao.util.SqlTsDao; |
26 | 26 | |
27 | 27 | @Configuration |
28 | 28 | @EnableAutoConfiguration |
29 | -@ComponentScan({"org.thingsboard.server.dao.sqlts.psql", "org.thingsboard.server.dao.sqlts.latest"}) | |
30 | -@EnableJpaRepositories({"org.thingsboard.server.dao.sqlts.psql", "org.thingsboard.server.dao.sqlts.latest", "org.thingsboard.server.dao.sqlts.dictionary"}) | |
31 | -@EntityScan({"org.thingsboard.server.dao.model.sqlts.psql", "org.thingsboard.server.dao.model.sqlts.latest", "org.thingsboard.server.dao.model.sqlts.dictionary"}) | |
29 | +@ComponentScan({"org.thingsboard.server.dao.sqlts.psql"}) | |
30 | +@EnableJpaRepositories({"org.thingsboard.server.dao.sqlts.ts", "org.thingsboard.server.dao.sqlts.insert.psql", "org.thingsboard.server.dao.sqlts.insert.latest.psql", "org.thingsboard.server.dao.sqlts.latest", "org.thingsboard.server.dao.sqlts.dictionary"}) | |
31 | +@EntityScan({"org.thingsboard.server.dao.model.sqlts.ts", "org.thingsboard.server.dao.model.sqlts.latest", "org.thingsboard.server.dao.model.sqlts.dictionary"}) | |
32 | 32 | @EnableTransactionManagement |
33 | 33 | @SqlTsDao |
34 | 34 | @PsqlDao |
35 | 35 | public class PsqlTsDaoConfig { |
36 | 36 | |
37 | -} | |
\ No newline at end of file | ||
37 | +} | ... | ... |
... | ... | @@ -26,12 +26,12 @@ import org.thingsboard.server.dao.util.TimescaleDBTsDao; |
26 | 26 | |
27 | 27 | @Configuration |
28 | 28 | @EnableAutoConfiguration |
29 | -@ComponentScan({"org.thingsboard.server.dao.sqlts.timescale", "org.thingsboard.server.dao.sqlts.latest"}) | |
30 | -@EnableJpaRepositories({"org.thingsboard.server.dao.sqlts.timescale", "org.thingsboard.server.dao.sqlts.dictionary", "org.thingsboard.server.dao.sqlts.latest"}) | |
29 | +@ComponentScan({"org.thingsboard.server.dao.sqlts.timescale"}) | |
30 | +@EnableJpaRepositories({"org.thingsboard.server.dao.sqlts.timescale", "org.thingsboard.server.dao.sqlts.insert.latest.psql", "org.thingsboard.server.dao.sqlts.insert.timescale", "org.thingsboard.server.dao.sqlts.dictionary", "org.thingsboard.server.dao.sqlts.latest"}) | |
31 | 31 | @EntityScan({"org.thingsboard.server.dao.model.sqlts.timescale", "org.thingsboard.server.dao.model.sqlts.dictionary", "org.thingsboard.server.dao.model.sqlts.latest"}) |
32 | 32 | @EnableTransactionManagement |
33 | 33 | @TimescaleDBTsDao |
34 | 34 | @PsqlDao |
35 | 35 | public class TimescaleDaoConfig { |
36 | 36 | |
37 | -} | |
\ No newline at end of file | ||
37 | +} | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/model/sqlts/hsql/TsKvCompositeKey.java
deleted
100644 → 0
1 | -/** | |
2 | - * Copyright © 2016-2020 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.model.sqlts.hsql; | |
17 | - | |
18 | -import lombok.AllArgsConstructor; | |
19 | -import lombok.Data; | |
20 | -import lombok.NoArgsConstructor; | |
21 | -import org.thingsboard.server.common.data.EntityType; | |
22 | - | |
23 | -import javax.persistence.Transient; | |
24 | -import java.io.Serializable; | |
25 | -import java.util.UUID; | |
26 | - | |
27 | -@Data | |
28 | -@AllArgsConstructor | |
29 | -@NoArgsConstructor | |
30 | -public class TsKvCompositeKey implements Serializable { | |
31 | - | |
32 | - @Transient | |
33 | - private static final long serialVersionUID = -4089175869616037523L; | |
34 | - | |
35 | - private UUID entityId; | |
36 | - private int key; | |
37 | - private long ts; | |
38 | - | |
39 | -} | |
\ No newline at end of file |
1 | -/** | |
2 | - * Copyright © 2016-2020 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.model.sqlts.hsql; | |
17 | - | |
18 | -import lombok.Data; | |
19 | -import org.thingsboard.server.common.data.kv.TsKvEntry; | |
20 | -import org.thingsboard.server.dao.model.ToData; | |
21 | -import org.thingsboard.server.dao.model.sql.AbstractTsKvEntity; | |
22 | - | |
23 | -import javax.persistence.Column; | |
24 | -import javax.persistence.Entity; | |
25 | -import javax.persistence.Id; | |
26 | -import javax.persistence.IdClass; | |
27 | -import javax.persistence.Table; | |
28 | - | |
29 | -import static org.thingsboard.server.dao.model.ModelConstants.KEY_COLUMN; | |
30 | - | |
31 | -@Data | |
32 | -@Entity | |
33 | -@Table(name = "ts_kv") | |
34 | -@IdClass(TsKvCompositeKey.class) | |
35 | -public final class TsKvEntity extends AbstractTsKvEntity implements ToData<TsKvEntry> { | |
36 | - | |
37 | - @Id | |
38 | - @Column(name = KEY_COLUMN) | |
39 | - private int key; | |
40 | - | |
41 | - public TsKvEntity() { | |
42 | - } | |
43 | - | |
44 | - public TsKvEntity(String strValue) { | |
45 | - this.strValue = strValue; | |
46 | - } | |
47 | - | |
48 | - public TsKvEntity(Long longValue, Double doubleValue, Long longCountValue, Long doubleCountValue, String aggType) { | |
49 | - if (!isAllNull(longValue, doubleValue, longCountValue, doubleCountValue)) { | |
50 | - switch (aggType) { | |
51 | - case AVG: | |
52 | - double sum = 0.0; | |
53 | - if (longValue != null) { | |
54 | - sum += longValue; | |
55 | - } | |
56 | - if (doubleValue != null) { | |
57 | - sum += doubleValue; | |
58 | - } | |
59 | - long totalCount = longCountValue + doubleCountValue; | |
60 | - if (totalCount > 0) { | |
61 | - this.doubleValue = sum / (longCountValue + doubleCountValue); | |
62 | - } else { | |
63 | - this.doubleValue = 0.0; | |
64 | - } | |
65 | - break; | |
66 | - case SUM: | |
67 | - if (doubleCountValue > 0) { | |
68 | - this.doubleValue = doubleValue + (longValue != null ? longValue.doubleValue() : 0.0); | |
69 | - } else { | |
70 | - this.longValue = longValue; | |
71 | - } | |
72 | - break; | |
73 | - case MIN: | |
74 | - case MAX: | |
75 | - if (longCountValue > 0 && doubleCountValue > 0) { | |
76 | - this.doubleValue = MAX.equals(aggType) ? Math.max(doubleValue, longValue.doubleValue()) : Math.min(doubleValue, longValue.doubleValue()); | |
77 | - } else if (doubleCountValue > 0) { | |
78 | - this.doubleValue = doubleValue; | |
79 | - } else if (longCountValue > 0) { | |
80 | - this.longValue = longValue; | |
81 | - } | |
82 | - break; | |
83 | - } | |
84 | - } | |
85 | - } | |
86 | - | |
87 | - public TsKvEntity(Long booleanValueCount, Long strValueCount, Long longValueCount, Long doubleValueCount, Long jsonValueCount) { | |
88 | - if (!isAllNull(booleanValueCount, strValueCount, longValueCount, doubleValueCount)) { | |
89 | - if (booleanValueCount != 0) { | |
90 | - this.longValue = booleanValueCount; | |
91 | - } else if (strValueCount != 0) { | |
92 | - this.longValue = strValueCount; | |
93 | - } else if (jsonValueCount != 0) { | |
94 | - this.longValue = jsonValueCount; | |
95 | - } else { | |
96 | - this.longValue = longValueCount + doubleValueCount; | |
97 | - } | |
98 | - } | |
99 | - } | |
100 | - | |
101 | - @Override | |
102 | - public boolean isNotEmpty() { | |
103 | - return strValue != null || longValue != null || doubleValue != null || booleanValue != null; | |
104 | - } | |
105 | -} | |
\ No newline at end of file |
dao/src/main/java/org/thingsboard/server/dao/model/sqlts/timescale/ts/TimescaleTsKvCompositeKey.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/model/sqlts/timescale/TimescaleTsKvCompositeKey.java
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.dao.model.sqlts.timescale; | |
16 | +package org.thingsboard.server.dao.model.sqlts.timescale.ts; | |
17 | 17 | |
18 | 18 | import lombok.AllArgsConstructor; |
19 | 19 | import lombok.Data; |
... | ... | @@ -35,4 +35,4 @@ public class TimescaleTsKvCompositeKey implements Serializable { |
35 | 35 | private UUID entityId; |
36 | 36 | private int key; |
37 | 37 | private long ts; |
38 | -} | |
\ No newline at end of file | ||
38 | +} | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/model/sqlts/timescale/ts/TimescaleTsKvEntity.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/model/sqlts/timescale/TimescaleTsKvEntity.java
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.dao.model.sqlts.timescale; | |
16 | +package org.thingsboard.server.dao.model.sqlts.timescale.ts; | |
17 | 17 | |
18 | 18 | import lombok.Data; |
19 | 19 | import lombok.EqualsAndHashCode; |
... | ... | @@ -191,4 +191,4 @@ public final class TimescaleTsKvEntity extends AbstractTsKvEntity implements ToD |
191 | 191 | public boolean isNotEmpty() { |
192 | 192 | return ts != null && (strValue != null || longValue != null || doubleValue != null || booleanValue != null || jsonValue != null); |
193 | 193 | } |
194 | -} | |
\ No newline at end of file | ||
194 | +} | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/model/sqlts/ts/TsKvCompositeKey.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/model/sqlts/psql/TsKvCompositeKey.java
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.dao.model.sqlts.psql; | |
16 | +package org.thingsboard.server.dao.model.sqlts.ts; | |
17 | 17 | |
18 | 18 | import lombok.AllArgsConstructor; |
19 | 19 | import lombok.Data; |
... | ... | @@ -34,4 +34,4 @@ public class TsKvCompositeKey implements Serializable { |
34 | 34 | private UUID entityId; |
35 | 35 | private int key; |
36 | 36 | private long ts; |
37 | -} | |
\ No newline at end of file | ||
37 | +} | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/model/sqlts/ts/TsKvEntity.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/model/sqlts/psql/TsKvEntity.java
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.dao.model.sqlts.psql; | |
16 | +package org.thingsboard.server.dao.model.sqlts.ts; | |
17 | 17 | |
18 | 18 | import lombok.Data; |
19 | 19 | import org.thingsboard.server.dao.model.sql.AbstractTsKvEntity; | ... | ... |
... | ... | @@ -15,32 +15,45 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.sqlts; |
17 | 17 | |
18 | +import com.google.common.util.concurrent.Futures; | |
18 | 19 | import com.google.common.util.concurrent.ListenableFuture; |
19 | 20 | import com.google.common.util.concurrent.SettableFuture; |
20 | 21 | import lombok.extern.slf4j.Slf4j; |
21 | 22 | import org.springframework.beans.factory.annotation.Autowired; |
23 | +import org.springframework.data.domain.PageRequest; | |
24 | +import org.springframework.data.domain.Sort; | |
22 | 25 | import org.thingsboard.server.common.data.id.EntityId; |
23 | 26 | import org.thingsboard.server.common.data.id.TenantId; |
24 | 27 | import org.thingsboard.server.common.data.kv.Aggregation; |
28 | +import org.thingsboard.server.common.data.kv.DeleteTsKvQuery; | |
29 | +import org.thingsboard.server.common.data.kv.ReadTsKvQuery; | |
25 | 30 | import org.thingsboard.server.common.data.kv.TsKvEntry; |
26 | -import org.thingsboard.server.dao.model.sql.AbstractTsKvEntity; | |
31 | +import org.thingsboard.server.dao.DaoUtil; | |
32 | +import org.thingsboard.server.dao.model.sqlts.ts.TsKvEntity; | |
27 | 33 | import org.thingsboard.server.dao.sql.TbSqlBlockingQueue; |
28 | 34 | import org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams; |
35 | +import org.thingsboard.server.dao.sqlts.insert.InsertTsRepository; | |
36 | +import org.thingsboard.server.dao.sqlts.ts.TsKvRepository; | |
37 | +import org.thingsboard.server.dao.timeseries.TimeseriesDao; | |
29 | 38 | |
30 | 39 | import javax.annotation.PostConstruct; |
31 | 40 | import javax.annotation.PreDestroy; |
41 | +import java.util.ArrayList; | |
32 | 42 | import java.util.List; |
33 | 43 | import java.util.Optional; |
34 | 44 | import java.util.concurrent.CompletableFuture; |
35 | 45 | import java.util.stream.Collectors; |
36 | 46 | |
37 | 47 | @Slf4j |
38 | -public abstract class AbstractChunkedAggregationTimeseriesDao<T extends AbstractTsKvEntity> extends AbstractSqlTimeseriesDao { | |
48 | +public abstract class AbstractChunkedAggregationTimeseriesDao extends AbstractSqlTimeseriesDao implements TimeseriesDao { | |
39 | 49 | |
40 | 50 | @Autowired |
41 | - protected InsertTsRepository<T> insertRepository; | |
51 | + protected TsKvRepository tsKvRepository; | |
42 | 52 | |
43 | - protected TbSqlBlockingQueue<EntityContainer<T>> tsQueue; | |
53 | + @Autowired | |
54 | + protected InsertTsRepository<TsKvEntity> insertRepository; | |
55 | + | |
56 | + protected TbSqlBlockingQueue<EntityContainer<TsKvEntity>> tsQueue; | |
44 | 57 | |
45 | 58 | @PostConstruct |
46 | 59 | protected void init() { |
... | ... | @@ -63,9 +76,102 @@ public abstract class AbstractChunkedAggregationTimeseriesDao<T extends Abstract |
63 | 76 | } |
64 | 77 | } |
65 | 78 | |
66 | - protected abstract ListenableFuture<Optional<TsKvEntry>> findAndAggregateAsync(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, long ts, Aggregation aggregation); | |
79 | + @Override | |
80 | + public ListenableFuture<Void> remove(TenantId tenantId, EntityId entityId, DeleteTsKvQuery query) { | |
81 | + return service.submit(() -> { | |
82 | + tsKvRepository.delete( | |
83 | + entityId.getId(), | |
84 | + getOrSaveKeyId(query.getKey()), | |
85 | + query.getStartTs(), | |
86 | + query.getEndTs()); | |
87 | + return null; | |
88 | + }); | |
89 | + } | |
90 | + | |
91 | + @Override | |
92 | + public ListenableFuture<Void> saveLatest(TenantId tenantId, EntityId entityId, TsKvEntry tsKvEntry) { | |
93 | + return getSaveLatestFuture(entityId, tsKvEntry); | |
94 | + } | |
95 | + | |
96 | + @Override | |
97 | + public ListenableFuture<Void> removeLatest(TenantId tenantId, EntityId entityId, DeleteTsKvQuery query) { | |
98 | + return getRemoveLatestFuture(tenantId, entityId, query); | |
99 | + } | |
100 | + | |
101 | + @Override | |
102 | + public ListenableFuture<TsKvEntry> findLatest(TenantId tenantId, EntityId entityId, String key) { | |
103 | + return getFindLatestFuture(entityId, key); | |
104 | + } | |
105 | + | |
106 | + @Override | |
107 | + public ListenableFuture<List<TsKvEntry>> findAllLatest(TenantId tenantId, EntityId entityId) { | |
108 | + return getFindAllLatestFuture(entityId); | |
109 | + } | |
110 | + | |
111 | + @Override | |
112 | + public ListenableFuture<Void> savePartition(TenantId tenantId, EntityId entityId, long tsKvEntryTs, String key, long ttl) { | |
113 | + return Futures.immediateFuture(null); | |
114 | + } | |
115 | + | |
116 | + @Override | |
117 | + public ListenableFuture<Void> removePartition(TenantId tenantId, EntityId entityId, DeleteTsKvQuery query) { | |
118 | + return Futures.immediateFuture(null); | |
119 | + } | |
120 | + | |
121 | + @Override | |
122 | + public ListenableFuture<List<TsKvEntry>> findAllAsync(TenantId tenantId, EntityId entityId, List<ReadTsKvQuery> queries) { | |
123 | + return processFindAllAsync(tenantId, entityId, queries); | |
124 | + } | |
125 | + | |
126 | + @Override | |
127 | + protected ListenableFuture<List<TsKvEntry>> findAllAsync(TenantId tenantId, EntityId entityId, ReadTsKvQuery query) { | |
128 | + if (query.getAggregation() == Aggregation.NONE) { | |
129 | + return findAllAsyncWithLimit(tenantId, entityId, query); | |
130 | + } else { | |
131 | + long stepTs = query.getStartTs(); | |
132 | + List<ListenableFuture<Optional<TsKvEntry>>> futures = new ArrayList<>(); | |
133 | + while (stepTs < query.getEndTs()) { | |
134 | + long startTs = stepTs; | |
135 | + long endTs = stepTs + query.getInterval(); | |
136 | + long ts = startTs + (endTs - startTs) / 2; | |
137 | + futures.add(findAndAggregateAsync(tenantId, entityId, query.getKey(), startTs, endTs, ts, query.getAggregation())); | |
138 | + stepTs = endTs; | |
139 | + } | |
140 | + return getTskvEntriesFuture(Futures.allAsList(futures)); | |
141 | + } | |
142 | + } | |
143 | + | |
144 | + @Override | |
145 | + protected ListenableFuture<List<TsKvEntry>> findAllAsyncWithLimit(TenantId tenantId, EntityId entityId, ReadTsKvQuery query) { | |
146 | + Integer keyId = getOrSaveKeyId(query.getKey()); | |
147 | + List<TsKvEntity> tsKvEntities = tsKvRepository.findAllWithLimit( | |
148 | + entityId.getId(), | |
149 | + keyId, | |
150 | + query.getStartTs(), | |
151 | + query.getEndTs(), | |
152 | + new PageRequest(0, query.getLimit(), | |
153 | + new Sort(Sort.Direction.fromString( | |
154 | + query.getOrderBy()), "ts"))); | |
155 | + tsKvEntities.forEach(tsKvEntity -> tsKvEntity.setStrKey(query.getKey())); | |
156 | + return Futures.immediateFuture(DaoUtil.convertDataList(tsKvEntities)); | |
157 | + } | |
67 | 158 | |
68 | - protected void switchAggregation(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, Aggregation aggregation, List<CompletableFuture<T>> entitiesFutures) { | |
159 | + protected ListenableFuture<Optional<TsKvEntry>> findAndAggregateAsync(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, long ts, Aggregation aggregation) { | |
160 | + List<CompletableFuture<TsKvEntity>> entitiesFutures = new ArrayList<>(); | |
161 | + switchAggregation(tenantId, entityId, key, startTs, endTs, aggregation, entitiesFutures); | |
162 | + return Futures.transform(setFutures(entitiesFutures), entity -> { | |
163 | + if (entity != null && entity.isNotEmpty()) { | |
164 | + entity.setEntityId(entityId.getId()); | |
165 | + entity.setStrKey(key); | |
166 | + entity.setTs(ts); | |
167 | + return Optional.of(DaoUtil.getData(entity)); | |
168 | + } else { | |
169 | + return Optional.empty(); | |
170 | + } | |
171 | + }); | |
172 | + } | |
173 | + | |
174 | + protected void switchAggregation(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, Aggregation aggregation, List<CompletableFuture<TsKvEntity>> entitiesFutures) { | |
69 | 175 | switch (aggregation) { |
70 | 176 | case AVG: |
71 | 177 | findAvg(tenantId, entityId, key, startTs, endTs, entitiesFutures); |
... | ... | @@ -87,19 +193,64 @@ public abstract class AbstractChunkedAggregationTimeseriesDao<T extends Abstract |
87 | 193 | } |
88 | 194 | } |
89 | 195 | |
90 | - protected abstract void findCount(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, List<CompletableFuture<T>> entitiesFutures); | |
196 | + protected void findCount(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, List<CompletableFuture<TsKvEntity>> entitiesFutures) { | |
197 | + Integer keyId = getOrSaveKeyId(key); | |
198 | + entitiesFutures.add(tsKvRepository.findCount( | |
199 | + entityId.getId(), | |
200 | + keyId, | |
201 | + startTs, | |
202 | + endTs)); | |
203 | + } | |
91 | 204 | |
92 | - protected abstract void findSum(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, List<CompletableFuture<T>> entitiesFutures); | |
205 | + protected void findSum(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, List<CompletableFuture<TsKvEntity>> entitiesFutures) { | |
206 | + Integer keyId = getOrSaveKeyId(key); | |
207 | + entitiesFutures.add(tsKvRepository.findSum( | |
208 | + entityId.getId(), | |
209 | + keyId, | |
210 | + startTs, | |
211 | + endTs)); | |
212 | + } | |
93 | 213 | |
94 | - protected abstract void findMin(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, List<CompletableFuture<T>> entitiesFutures); | |
214 | + protected void findMin(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, List<CompletableFuture<TsKvEntity>> entitiesFutures) { | |
215 | + Integer keyId = getOrSaveKeyId(key); | |
216 | + entitiesFutures.add(tsKvRepository.findStringMin( | |
217 | + entityId.getId(), | |
218 | + keyId, | |
219 | + startTs, | |
220 | + endTs)); | |
221 | + entitiesFutures.add(tsKvRepository.findNumericMin( | |
222 | + entityId.getId(), | |
223 | + keyId, | |
224 | + startTs, | |
225 | + endTs)); | |
226 | + } | |
95 | 227 | |
96 | - protected abstract void findMax(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, List<CompletableFuture<T>> entitiesFutures); | |
228 | + protected void findMax(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, List<CompletableFuture<TsKvEntity>> entitiesFutures) { | |
229 | + Integer keyId = getOrSaveKeyId(key); | |
230 | + entitiesFutures.add(tsKvRepository.findStringMax( | |
231 | + entityId.getId(), | |
232 | + keyId, | |
233 | + startTs, | |
234 | + endTs)); | |
235 | + entitiesFutures.add(tsKvRepository.findNumericMax( | |
236 | + entityId.getId(), | |
237 | + keyId, | |
238 | + startTs, | |
239 | + endTs)); | |
240 | + } | |
97 | 241 | |
98 | - protected abstract void findAvg(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, List<CompletableFuture<T>> entitiesFutures); | |
242 | + protected void findAvg(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, List<CompletableFuture<TsKvEntity>> entitiesFutures) { | |
243 | + Integer keyId = getOrSaveKeyId(key); | |
244 | + entitiesFutures.add(tsKvRepository.findAvg( | |
245 | + entityId.getId(), | |
246 | + keyId, | |
247 | + startTs, | |
248 | + endTs)); | |
249 | + } | |
99 | 250 | |
100 | - protected SettableFuture<T> setFutures(List<CompletableFuture<T>> entitiesFutures) { | |
101 | - SettableFuture<T> listenableFuture = SettableFuture.create(); | |
102 | - CompletableFuture<List<T>> entities = | |
251 | + protected SettableFuture<TsKvEntity> setFutures(List<CompletableFuture<TsKvEntity>> entitiesFutures) { | |
252 | + SettableFuture<TsKvEntity> listenableFuture = SettableFuture.create(); | |
253 | + CompletableFuture<List<TsKvEntity>> entities = | |
103 | 254 | CompletableFuture.allOf(entitiesFutures.toArray(new CompletableFuture[entitiesFutures.size()])) |
104 | 255 | .thenApply(v -> entitiesFutures.stream() |
105 | 256 | .map(CompletableFuture::join) |
... | ... | @@ -109,8 +260,8 @@ public abstract class AbstractChunkedAggregationTimeseriesDao<T extends Abstract |
109 | 260 | if (throwable != null) { |
110 | 261 | listenableFuture.setException(throwable); |
111 | 262 | } else { |
112 | - T result = null; | |
113 | - for (T entity : tsKvEntities) { | |
263 | + TsKvEntity result = null; | |
264 | + for (TsKvEntity entity : tsKvEntities) { | |
114 | 265 | if (entity.isNotEmpty()) { |
115 | 266 | result = entity; |
116 | 267 | break; | ... | ... |
... | ... | @@ -43,6 +43,7 @@ import org.thingsboard.server.dao.sql.ScheduledLogExecutorComponent; |
43 | 43 | import org.thingsboard.server.dao.sql.TbSqlBlockingQueue; |
44 | 44 | import org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams; |
45 | 45 | import org.thingsboard.server.dao.sqlts.dictionary.TsKvDictionaryRepository; |
46 | +import org.thingsboard.server.dao.sqlts.insert.latest.InsertLatestTsRepository; | |
46 | 47 | import org.thingsboard.server.dao.sqlts.latest.SearchTsKvLatestRepository; |
47 | 48 | import org.thingsboard.server.dao.sqlts.latest.TsKvLatestRepository; |
48 | 49 | import org.thingsboard.server.dao.timeseries.SimpleListenableFuture; | ... | ... |
... | ... | @@ -15,46 +15,25 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.sqlts.hsql; |
17 | 17 | |
18 | -import com.google.common.util.concurrent.Futures; | |
19 | 18 | import com.google.common.util.concurrent.ListenableFuture; |
20 | 19 | import lombok.extern.slf4j.Slf4j; |
21 | -import org.springframework.beans.factory.annotation.Autowired; | |
22 | -import org.springframework.data.domain.PageRequest; | |
23 | -import org.springframework.data.domain.Sort; | |
24 | 20 | import org.springframework.stereotype.Component; |
25 | 21 | import org.thingsboard.server.common.data.id.EntityId; |
26 | 22 | import org.thingsboard.server.common.data.id.TenantId; |
27 | -import org.thingsboard.server.common.data.kv.Aggregation; | |
28 | -import org.thingsboard.server.common.data.kv.DeleteTsKvQuery; | |
29 | -import org.thingsboard.server.common.data.kv.ReadTsKvQuery; | |
30 | 23 | import org.thingsboard.server.common.data.kv.TsKvEntry; |
31 | -import org.thingsboard.server.dao.DaoUtil; | |
32 | -import org.thingsboard.server.dao.model.sqlts.hsql.TsKvEntity; | |
24 | +import org.thingsboard.server.dao.model.sqlts.ts.TsKvEntity; | |
33 | 25 | import org.thingsboard.server.dao.sqlts.AbstractChunkedAggregationTimeseriesDao; |
34 | 26 | import org.thingsboard.server.dao.sqlts.EntityContainer; |
35 | 27 | import org.thingsboard.server.dao.timeseries.TimeseriesDao; |
36 | 28 | import org.thingsboard.server.dao.util.HsqlDao; |
37 | 29 | import org.thingsboard.server.dao.util.SqlTsDao; |
38 | 30 | |
39 | -import java.util.ArrayList; | |
40 | -import java.util.List; | |
41 | -import java.util.Optional; | |
42 | -import java.util.concurrent.CompletableFuture; | |
43 | - | |
44 | 31 | |
45 | 32 | @Component |
46 | 33 | @Slf4j |
47 | 34 | @SqlTsDao |
48 | 35 | @HsqlDao |
49 | -public class JpaHsqlTimeseriesDao extends AbstractChunkedAggregationTimeseriesDao<TsKvEntity> implements TimeseriesDao { | |
50 | - | |
51 | - @Autowired | |
52 | - private TsKvHsqlRepository tsKvRepository; | |
53 | - | |
54 | - @Override | |
55 | - public ListenableFuture<List<TsKvEntry>> findAllAsync(TenantId tenantId, EntityId entityId, List<ReadTsKvQuery> queries) { | |
56 | - return processFindAllAsync(tenantId, entityId, queries); | |
57 | - } | |
36 | +public class JpaHsqlTimeseriesDao extends AbstractChunkedAggregationTimeseriesDao implements TimeseriesDao { | |
58 | 37 | |
59 | 38 | @Override |
60 | 39 | public ListenableFuture<Void> save(TenantId tenantId, EntityId entityId, TsKvEntry tsKvEntry, long ttl) { |
... | ... | @@ -72,154 +51,4 @@ public class JpaHsqlTimeseriesDao extends AbstractChunkedAggregationTimeseriesDa |
72 | 51 | return tsQueue.add(new EntityContainer(entity, null)); |
73 | 52 | } |
74 | 53 | |
75 | - @Override | |
76 | - public ListenableFuture<Void> remove(TenantId tenantId, EntityId entityId, DeleteTsKvQuery query) { | |
77 | - return service.submit(() -> { | |
78 | - tsKvRepository.delete( | |
79 | - entityId.getId(), | |
80 | - getOrSaveKeyId(query.getKey()), | |
81 | - query.getStartTs(), | |
82 | - query.getEndTs()); | |
83 | - return null; | |
84 | - }); | |
85 | - } | |
86 | - | |
87 | - @Override | |
88 | - public ListenableFuture<Void> saveLatest(TenantId tenantId, EntityId entityId, TsKvEntry tsKvEntry) { | |
89 | - return getSaveLatestFuture(entityId, tsKvEntry); | |
90 | - } | |
91 | - | |
92 | - @Override | |
93 | - public ListenableFuture<Void> removeLatest(TenantId tenantId, EntityId entityId, DeleteTsKvQuery query) { | |
94 | - return getRemoveLatestFuture(tenantId, entityId, query); | |
95 | - } | |
96 | - | |
97 | - @Override | |
98 | - public ListenableFuture<TsKvEntry> findLatest(TenantId tenantId, EntityId entityId, String key) { | |
99 | - return getFindLatestFuture(entityId, key); | |
100 | - } | |
101 | - | |
102 | - @Override | |
103 | - public ListenableFuture<List<TsKvEntry>> findAllLatest(TenantId tenantId, EntityId entityId) { | |
104 | - return getFindAllLatestFuture(entityId); | |
105 | - } | |
106 | - | |
107 | - @Override | |
108 | - public ListenableFuture<Void> savePartition(TenantId tenantId, EntityId entityId, long tsKvEntryTs, String key, long ttl) { | |
109 | - return Futures.immediateFuture(null); | |
110 | - } | |
111 | - | |
112 | - @Override | |
113 | - public ListenableFuture<Void> removePartition(TenantId tenantId, EntityId entityId, DeleteTsKvQuery query) { | |
114 | - return Futures.immediateFuture(null); | |
115 | - } | |
116 | - | |
117 | - protected ListenableFuture<List<TsKvEntry>> findAllAsync(TenantId tenantId, EntityId entityId, ReadTsKvQuery query) { | |
118 | - if (query.getAggregation() == Aggregation.NONE) { | |
119 | - return findAllAsyncWithLimit(tenantId, entityId, query); | |
120 | - } else { | |
121 | - long stepTs = query.getStartTs(); | |
122 | - List<ListenableFuture<Optional<TsKvEntry>>> futures = new ArrayList<>(); | |
123 | - while (stepTs < query.getEndTs()) { | |
124 | - long startTs = stepTs; | |
125 | - long endTs = stepTs + query.getInterval(); | |
126 | - long ts = startTs + (endTs - startTs) / 2; | |
127 | - futures.add(findAndAggregateAsync(tenantId, entityId, query.getKey(), startTs, endTs, ts, query.getAggregation())); | |
128 | - stepTs = endTs; | |
129 | - } | |
130 | - return getTskvEntriesFuture(Futures.allAsList(futures)); | |
131 | - } | |
132 | - } | |
133 | - | |
134 | - @Override | |
135 | - protected ListenableFuture<List<TsKvEntry>> findAllAsyncWithLimit(TenantId tenantId, EntityId entityId, ReadTsKvQuery query) { | |
136 | - List<TsKvEntity> tsKvEntities = tsKvRepository.findAllWithLimit( | |
137 | - entityId.getId(), | |
138 | - getOrSaveKeyId(query.getKey()), | |
139 | - query.getStartTs(), | |
140 | - query.getEndTs(), | |
141 | - new PageRequest(0, query.getLimit(), | |
142 | - new Sort(Sort.Direction.fromString( | |
143 | - query.getOrderBy()), "ts"))); | |
144 | - tsKvEntities.forEach(tsKvEntity -> tsKvEntity.setStrKey(query.getKey())); | |
145 | - return Futures.immediateFuture( | |
146 | - DaoUtil.convertDataList( | |
147 | - tsKvEntities)); | |
148 | - } | |
149 | - | |
150 | - @Override | |
151 | - protected ListenableFuture<Optional<TsKvEntry>> findAndAggregateAsync(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, long ts, Aggregation aggregation) { | |
152 | - List<CompletableFuture<TsKvEntity>> entitiesFutures = new ArrayList<>(); | |
153 | - switchAggregation(tenantId, entityId, key, startTs, endTs, aggregation, entitiesFutures); | |
154 | - return Futures.transform(setFutures(entitiesFutures), entity -> { | |
155 | - if (entity != null && entity.isNotEmpty()) { | |
156 | - entity.setEntityId(entityId.getId()); | |
157 | - entity.setKey(getOrSaveKeyId(key)); | |
158 | - entity.setTs(ts); | |
159 | - return Optional.of(DaoUtil.getData(entity)); | |
160 | - } else { | |
161 | - return Optional.empty(); | |
162 | - } | |
163 | - }); | |
164 | - } | |
165 | - | |
166 | - @Override | |
167 | - protected void findCount(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, List<CompletableFuture<TsKvEntity>> entitiesFutures) { | |
168 | - Integer keyId = getOrSaveKeyId(key); | |
169 | - entitiesFutures.add(tsKvRepository.findCount( | |
170 | - entityId.getId(), | |
171 | - keyId, | |
172 | - startTs, | |
173 | - endTs)); | |
174 | - } | |
175 | - | |
176 | - @Override | |
177 | - protected void findSum(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, List<CompletableFuture<TsKvEntity>> entitiesFutures) { | |
178 | - Integer keyId = getOrSaveKeyId(key); | |
179 | - entitiesFutures.add(tsKvRepository.findSum( | |
180 | - entityId.getId(), | |
181 | - keyId, | |
182 | - startTs, | |
183 | - endTs)); | |
184 | - } | |
185 | - | |
186 | - @Override | |
187 | - protected void findMin(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, List<CompletableFuture<TsKvEntity>> entitiesFutures) { | |
188 | - Integer keyId = getOrSaveKeyId(key); | |
189 | - entitiesFutures.add(tsKvRepository.findStringMin( | |
190 | - entityId.getId(), | |
191 | - keyId, | |
192 | - startTs, | |
193 | - endTs)); | |
194 | - entitiesFutures.add(tsKvRepository.findNumericMin( | |
195 | - entityId.getId(), | |
196 | - keyId, | |
197 | - startTs, | |
198 | - endTs)); | |
199 | - } | |
200 | - | |
201 | - @Override | |
202 | - protected void findMax(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, List<CompletableFuture<TsKvEntity>> entitiesFutures) { | |
203 | - Integer keyId = getOrSaveKeyId(key); | |
204 | - entitiesFutures.add(tsKvRepository.findStringMax( | |
205 | - entityId.getId(), | |
206 | - keyId, | |
207 | - startTs, | |
208 | - endTs)); | |
209 | - entitiesFutures.add(tsKvRepository.findNumericMax( | |
210 | - entityId.getId(), | |
211 | - keyId, | |
212 | - startTs, | |
213 | - endTs)); | |
214 | - } | |
215 | - | |
216 | - @Override | |
217 | - protected void findAvg(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, List<CompletableFuture<TsKvEntity>> entitiesFutures) { | |
218 | - Integer keyId = getOrSaveKeyId(key); | |
219 | - entitiesFutures.add(tsKvRepository.findAvg( | |
220 | - entityId.getId(), | |
221 | - keyId, | |
222 | - startTs, | |
223 | - endTs)); | |
224 | - } | |
225 | -} | |
\ No newline at end of file | ||
54 | +} | ... | ... |
1 | -/** | |
2 | - * Copyright © 2016-2020 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.sqlts.hsql; | |
17 | - | |
18 | -import org.springframework.data.domain.Pageable; | |
19 | -import org.springframework.data.jpa.repository.Modifying; | |
20 | -import org.springframework.data.jpa.repository.Query; | |
21 | -import org.springframework.data.repository.CrudRepository; | |
22 | -import org.springframework.data.repository.query.Param; | |
23 | -import org.springframework.scheduling.annotation.Async; | |
24 | -import org.springframework.transaction.annotation.Transactional; | |
25 | -import org.thingsboard.server.dao.model.sqlts.hsql.TsKvCompositeKey; | |
26 | -import org.thingsboard.server.dao.model.sqlts.hsql.TsKvEntity; | |
27 | -import org.thingsboard.server.dao.util.SqlDao; | |
28 | - | |
29 | -import java.util.List; | |
30 | -import java.util.UUID; | |
31 | -import java.util.concurrent.CompletableFuture; | |
32 | - | |
33 | -@SqlDao | |
34 | -public interface TsKvHsqlRepository extends CrudRepository<TsKvEntity, TsKvCompositeKey> { | |
35 | - | |
36 | - @Query("SELECT tskv FROM TsKvEntity tskv WHERE tskv.entityId = :entityId " + | |
37 | - "AND tskv.key = :entityKey AND tskv.ts > :startTs AND tskv.ts <= :endTs") | |
38 | - List<TsKvEntity> findAllWithLimit(@Param("entityId") UUID entityId, | |
39 | - @Param("entityKey") int key, | |
40 | - @Param("startTs") long startTs, | |
41 | - @Param("endTs") long endTs, | |
42 | - Pageable pageable); | |
43 | - | |
44 | - @Transactional | |
45 | - @Modifying | |
46 | - @Query("DELETE FROM TsKvEntity tskv WHERE tskv.entityId = :entityId " + | |
47 | - "AND tskv.key = :entityKey AND tskv.ts > :startTs AND tskv.ts <= :endTs") | |
48 | - void delete(@Param("entityId") UUID entityId, | |
49 | - @Param("entityKey") int key, | |
50 | - @Param("startTs") long startTs, | |
51 | - @Param("endTs") long endTs); | |
52 | - | |
53 | - @Async | |
54 | - @Query("SELECT new TsKvEntity(MAX(tskv.strValue)) FROM TsKvEntity tskv " + | |
55 | - "WHERE tskv.strValue IS NOT NULL AND tskv.entityId = :entityId AND tskv.key = :entityKey" + | |
56 | - " AND tskv.ts > :startTs AND tskv.ts <= :endTs") | |
57 | - CompletableFuture<TsKvEntity> findStringMax(@Param("entityId") UUID entityId, | |
58 | - @Param("entityKey") int entityKey, | |
59 | - @Param("startTs") long startTs, | |
60 | - @Param("endTs") long endTs); | |
61 | - | |
62 | - @Async | |
63 | - @Query("SELECT new TsKvEntity(MAX(COALESCE(tskv.longValue, -9223372036854775807)), " + | |
64 | - "MAX(COALESCE(tskv.doubleValue, -1.79769E+308)), " + | |
65 | - "SUM(CASE WHEN tskv.longValue IS NULL THEN 0 ELSE 1 END), " + | |
66 | - "SUM(CASE WHEN tskv.doubleValue IS NULL THEN 0 ELSE 1 END), " + | |
67 | - "'MAX') FROM TsKvEntity tskv WHERE tskv.entityId = :entityId " + | |
68 | - "AND tskv.key = :entityKey AND tskv.ts > :startTs AND tskv.ts <= :endTs") | |
69 | - CompletableFuture<TsKvEntity> findNumericMax(@Param("entityId") UUID entityId, | |
70 | - @Param("entityKey") int entityKey, | |
71 | - @Param("startTs") long startTs, | |
72 | - @Param("endTs") long endTs); | |
73 | - | |
74 | - | |
75 | - @Async | |
76 | - @Query("SELECT new TsKvEntity(MIN(tskv.strValue)) FROM TsKvEntity tskv " + | |
77 | - "WHERE tskv.strValue IS NOT NULL AND tskv.entityId = :entityId " + | |
78 | - "AND tskv.key = :entityKey AND tskv.ts > :startTs AND tskv.ts <= :endTs") | |
79 | - CompletableFuture<TsKvEntity> findStringMin(@Param("entityId") UUID entityId, | |
80 | - @Param("entityKey") int entityKey, | |
81 | - @Param("startTs") long startTs, | |
82 | - @Param("endTs") long endTs); | |
83 | - | |
84 | - @Async | |
85 | - @Query("SELECT new TsKvEntity(MIN(COALESCE(tskv.longValue, 9223372036854775807)), " + | |
86 | - "MIN(COALESCE(tskv.doubleValue, 1.79769E+308)), " + | |
87 | - "SUM(CASE WHEN tskv.longValue IS NULL THEN 0 ELSE 1 END), " + | |
88 | - "SUM(CASE WHEN tskv.doubleValue IS NULL THEN 0 ELSE 1 END), " + | |
89 | - "'MIN') FROM TsKvEntity tskv WHERE tskv.entityId = :entityId " + | |
90 | - "AND tskv.key = :entityKey AND tskv.ts > :startTs AND tskv.ts <= :endTs") | |
91 | - CompletableFuture<TsKvEntity> findNumericMin(@Param("entityId") UUID entityId, | |
92 | - @Param("entityKey") int entityKey, | |
93 | - @Param("startTs") long startTs, | |
94 | - @Param("endTs") long endTs); | |
95 | - | |
96 | - @Async | |
97 | - @Query("SELECT new TsKvEntity(SUM(CASE WHEN tskv.booleanValue IS NULL THEN 0 ELSE 1 END), " + | |
98 | - "SUM(CASE WHEN tskv.strValue IS NULL THEN 0 ELSE 1 END), " + | |
99 | - "SUM(CASE WHEN tskv.longValue IS NULL THEN 0 ELSE 1 END), " + | |
100 | - "SUM(CASE WHEN tskv.doubleValue IS NULL THEN 0 ELSE 1 END), " + | |
101 | - "SUM(CASE WHEN tskv.jsonValue IS NULL THEN 0 ELSE 1 END)) FROM TsKvEntity tskv " + | |
102 | - "WHERE tskv.entityId = :entityId AND tskv.key = :entityKey AND tskv.ts > :startTs AND tskv.ts <= :endTs") | |
103 | - CompletableFuture<TsKvEntity> findCount(@Param("entityId") UUID entityId, | |
104 | - @Param("entityKey") int entityKey, | |
105 | - @Param("startTs") long startTs, | |
106 | - @Param("endTs") long endTs); | |
107 | - | |
108 | - @Async | |
109 | - @Query("SELECT new TsKvEntity(SUM(COALESCE(tskv.longValue, 0)), " + | |
110 | - "SUM(COALESCE(tskv.doubleValue, 0.0)), " + | |
111 | - "SUM(CASE WHEN tskv.longValue IS NULL THEN 0 ELSE 1 END), " + | |
112 | - "SUM(CASE WHEN tskv.doubleValue IS NULL THEN 0 ELSE 1 END), " + | |
113 | - "'AVG') FROM TsKvEntity tskv WHERE tskv.entityId = :entityId " + | |
114 | - "AND tskv.key = :entityKey AND tskv.ts > :startTs AND tskv.ts <= :endTs") | |
115 | - CompletableFuture<TsKvEntity> findAvg(@Param("entityId") UUID entityId, | |
116 | - @Param("entityKey") int entityKey, | |
117 | - @Param("startTs") long startTs, | |
118 | - @Param("endTs") long endTs); | |
119 | - | |
120 | - @Async | |
121 | - @Query("SELECT new TsKvEntity(SUM(COALESCE(tskv.longValue, 0)), " + | |
122 | - "SUM(COALESCE(tskv.doubleValue, 0.0)), " + | |
123 | - "SUM(CASE WHEN tskv.longValue IS NULL THEN 0 ELSE 1 END), " + | |
124 | - "SUM(CASE WHEN tskv.doubleValue IS NULL THEN 0 ELSE 1 END), " + | |
125 | - "'SUM') FROM TsKvEntity tskv WHERE tskv.entityId = :entityId " + | |
126 | - "AND tskv.key = :entityKey AND tskv.ts > :startTs AND tskv.ts <= :endTs") | |
127 | - CompletableFuture<TsKvEntity> findSum(@Param("entityId") UUID entityId, | |
128 | - @Param("entityKey") int entityKey, | |
129 | - @Param("startTs") long startTs, | |
130 | - @Param("endTs") long endTs); | |
131 | - | |
132 | -} | |
\ No newline at end of file |
dao/src/main/java/org/thingsboard/server/dao/sqlts/insert/AbstractInsertRepository.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/sqlts/AbstractInsertRepository.java
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.dao.sqlts; | |
16 | +package org.thingsboard.server.dao.sqlts.insert; | |
17 | 17 | |
18 | 18 | import org.springframework.beans.factory.annotation.Autowired; |
19 | 19 | import org.springframework.beans.factory.annotation.Value; |
... | ... | @@ -44,4 +44,4 @@ public abstract class AbstractInsertRepository { |
44 | 44 | } |
45 | 45 | return strValue; |
46 | 46 | } |
47 | -} | |
\ No newline at end of file | ||
47 | +} | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/sqlts/insert/InsertTsRepository.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/sqlts/InsertTsRepository.java
... | ... | @@ -13,9 +13,10 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.dao.sqlts; | |
16 | +package org.thingsboard.server.dao.sqlts.insert; | |
17 | 17 | |
18 | 18 | import org.thingsboard.server.dao.model.sql.AbstractTsKvEntity; |
19 | +import org.thingsboard.server.dao.sqlts.EntityContainer; | |
19 | 20 | |
20 | 21 | import java.util.List; |
21 | 22 | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/sqlts/insert/hsql/HsqlInsertTsRepository.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/sqlts/hsql/HsqlInsertTsRepository.java
... | ... | @@ -13,15 +13,15 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.dao.sqlts.hsql; | |
16 | +package org.thingsboard.server.dao.sqlts.insert.hsql; | |
17 | 17 | |
18 | 18 | import org.springframework.jdbc.core.BatchPreparedStatementSetter; |
19 | 19 | import org.springframework.stereotype.Repository; |
20 | 20 | import org.springframework.transaction.annotation.Transactional; |
21 | -import org.thingsboard.server.dao.model.sqlts.hsql.TsKvEntity; | |
22 | -import org.thingsboard.server.dao.sqlts.AbstractInsertRepository; | |
21 | +import org.thingsboard.server.dao.model.sqlts.ts.TsKvEntity; | |
23 | 22 | import org.thingsboard.server.dao.sqlts.EntityContainer; |
24 | -import org.thingsboard.server.dao.sqlts.InsertTsRepository; | |
23 | +import org.thingsboard.server.dao.sqlts.insert.AbstractInsertRepository; | |
24 | +import org.thingsboard.server.dao.sqlts.insert.InsertTsRepository; | |
25 | 25 | import org.thingsboard.server.dao.util.HsqlDao; |
26 | 26 | import org.thingsboard.server.dao.util.SqlTsDao; |
27 | 27 | |
... | ... | @@ -86,4 +86,4 @@ public class HsqlInsertTsRepository extends AbstractInsertRepository implements |
86 | 86 | } |
87 | 87 | }); |
88 | 88 | } |
89 | -} | |
\ No newline at end of file | ||
89 | +} | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/sqlts/insert/latest/InsertLatestTsRepository.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/sqlts/InsertLatestTsRepository.java
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.dao.sqlts; | |
16 | +package org.thingsboard.server.dao.sqlts.insert.latest; | |
17 | 17 | |
18 | 18 | import org.thingsboard.server.dao.model.sqlts.latest.TsKvLatestEntity; |
19 | 19 | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/sqlts/insert/latest/hsql/HsqlLatestInsertTsRepository.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/sqlts/latest/HsqlLatestInsertTsRepository.java
... | ... | @@ -13,14 +13,14 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.dao.sqlts.latest; | |
16 | +package org.thingsboard.server.dao.sqlts.insert.latest.hsql; | |
17 | 17 | |
18 | 18 | import org.springframework.jdbc.core.BatchPreparedStatementSetter; |
19 | 19 | import org.springframework.stereotype.Repository; |
20 | 20 | import org.springframework.transaction.annotation.Transactional; |
21 | 21 | import org.thingsboard.server.dao.model.sqlts.latest.TsKvLatestEntity; |
22 | -import org.thingsboard.server.dao.sqlts.AbstractInsertRepository; | |
23 | -import org.thingsboard.server.dao.sqlts.InsertLatestTsRepository; | |
22 | +import org.thingsboard.server.dao.sqlts.insert.AbstractInsertRepository; | |
23 | +import org.thingsboard.server.dao.sqlts.insert.latest.InsertLatestTsRepository; | |
24 | 24 | import org.thingsboard.server.dao.util.HsqlDao; |
25 | 25 | import org.thingsboard.server.dao.util.SqlTsDao; |
26 | 26 | |
... | ... | @@ -82,4 +82,4 @@ public class HsqlLatestInsertTsRepository extends AbstractInsertRepository imple |
82 | 82 | } |
83 | 83 | }); |
84 | 84 | } |
85 | -} | |
\ No newline at end of file | ||
85 | +} | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/sqlts/insert/latest/psql/PsqlLatestInsertTsRepository.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/sqlts/latest/PsqlLatestInsertTsRepository.java
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.dao.sqlts.latest; | |
16 | +package org.thingsboard.server.dao.sqlts.insert.latest.psql; | |
17 | 17 | |
18 | 18 | import org.springframework.jdbc.core.BatchPreparedStatementSetter; |
19 | 19 | import org.springframework.stereotype.Repository; |
... | ... | @@ -21,8 +21,8 @@ import org.springframework.transaction.TransactionStatus; |
21 | 21 | import org.springframework.transaction.annotation.Transactional; |
22 | 22 | import org.springframework.transaction.support.TransactionCallbackWithoutResult; |
23 | 23 | import org.thingsboard.server.dao.model.sqlts.latest.TsKvLatestEntity; |
24 | -import org.thingsboard.server.dao.sqlts.AbstractInsertRepository; | |
25 | -import org.thingsboard.server.dao.sqlts.InsertLatestTsRepository; | |
24 | +import org.thingsboard.server.dao.sqlts.insert.AbstractInsertRepository; | |
25 | +import org.thingsboard.server.dao.sqlts.insert.latest.InsertLatestTsRepository; | |
26 | 26 | import org.thingsboard.server.dao.util.PsqlTsAnyDao; |
27 | 27 | |
28 | 28 | import java.sql.PreparedStatement; |
... | ... | @@ -151,4 +151,4 @@ public class PsqlLatestInsertTsRepository extends AbstractInsertRepository imple |
151 | 151 | } |
152 | 152 | }); |
153 | 153 | } |
154 | -} | |
\ No newline at end of file | ||
154 | +} | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/sqlts/insert/psql/PsqlInsertTsRepository.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/sqlts/psql/PsqlInsertTsRepository.java
... | ... | @@ -13,15 +13,15 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.dao.sqlts.psql; | |
16 | +package org.thingsboard.server.dao.sqlts.insert.psql; | |
17 | 17 | |
18 | 18 | import org.springframework.jdbc.core.BatchPreparedStatementSetter; |
19 | 19 | import org.springframework.stereotype.Repository; |
20 | 20 | import org.springframework.transaction.annotation.Transactional; |
21 | -import org.thingsboard.server.dao.model.sqlts.psql.TsKvEntity; | |
22 | -import org.thingsboard.server.dao.sqlts.AbstractInsertRepository; | |
21 | +import org.thingsboard.server.dao.model.sqlts.ts.TsKvEntity; | |
22 | +import org.thingsboard.server.dao.sqlts.insert.AbstractInsertRepository; | |
23 | 23 | import org.thingsboard.server.dao.sqlts.EntityContainer; |
24 | -import org.thingsboard.server.dao.sqlts.InsertTsRepository; | |
24 | +import org.thingsboard.server.dao.sqlts.insert.InsertTsRepository; | |
25 | 25 | import org.thingsboard.server.dao.util.PsqlDao; |
26 | 26 | import org.thingsboard.server.dao.util.SqlTsDao; |
27 | 27 | |
... | ... | @@ -101,4 +101,4 @@ public class PsqlInsertTsRepository extends AbstractInsertRepository implements |
101 | 101 | private String getInsertOrUpdateQuery(String partitionDate) { |
102 | 102 | return INSERT_INTO_TS_KV + partitionDate + VALUES_ON_CONFLICT_DO_UPDATE; |
103 | 103 | } |
104 | -} | |
\ No newline at end of file | ||
104 | +} | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/sqlts/insert/psql/PsqlPartitioningRepository.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/sqlts/psql/PsqlPartitioningRepository.java
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.dao.sqlts.psql; | |
16 | +package org.thingsboard.server.dao.sqlts.insert.psql; | |
17 | 17 | |
18 | 18 | import org.springframework.stereotype.Repository; |
19 | 19 | import org.springframework.transaction.annotation.Transactional; |
... | ... | @@ -38,4 +38,4 @@ public class PsqlPartitioningRepository { |
38 | 38 | .executeUpdate(); |
39 | 39 | } |
40 | 40 | |
41 | -} | |
\ No newline at end of file | ||
41 | +} | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/sqlts/insert/timescale/TimescaleInsertTsRepository.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/sqlts/timescale/TimescaleInsertTsRepository.java
... | ... | @@ -13,15 +13,15 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.dao.sqlts.timescale; | |
16 | +package org.thingsboard.server.dao.sqlts.insert.timescale; | |
17 | 17 | |
18 | 18 | import org.springframework.jdbc.core.BatchPreparedStatementSetter; |
19 | 19 | import org.springframework.stereotype.Repository; |
20 | 20 | import org.springframework.transaction.annotation.Transactional; |
21 | -import org.thingsboard.server.dao.model.sqlts.timescale.TimescaleTsKvEntity; | |
22 | -import org.thingsboard.server.dao.sqlts.AbstractInsertRepository; | |
21 | +import org.thingsboard.server.dao.model.sqlts.timescale.ts.TimescaleTsKvEntity; | |
22 | +import org.thingsboard.server.dao.sqlts.insert.AbstractInsertRepository; | |
23 | 23 | import org.thingsboard.server.dao.sqlts.EntityContainer; |
24 | -import org.thingsboard.server.dao.sqlts.InsertTsRepository; | |
24 | +import org.thingsboard.server.dao.sqlts.insert.InsertTsRepository; | |
25 | 25 | import org.thingsboard.server.dao.util.PsqlDao; |
26 | 26 | import org.thingsboard.server.dao.util.TimescaleDBTsDao; |
27 | 27 | |
... | ... | @@ -89,4 +89,4 @@ public class TimescaleInsertTsRepository extends AbstractInsertRepository implem |
89 | 89 | } |
90 | 90 | }); |
91 | 91 | } |
92 | -} | |
\ No newline at end of file | ||
92 | +} | ... | ... |
... | ... | @@ -15,27 +15,20 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.sqlts.psql; |
17 | 17 | |
18 | -import com.google.common.util.concurrent.Futures; | |
19 | 18 | import com.google.common.util.concurrent.ListenableFuture; |
20 | 19 | import lombok.extern.slf4j.Slf4j; |
21 | 20 | import org.springframework.beans.factory.annotation.Autowired; |
22 | 21 | import org.springframework.beans.factory.annotation.Value; |
23 | -import org.springframework.data.domain.PageRequest; | |
24 | -import org.springframework.data.domain.Sort; | |
25 | 22 | import org.springframework.stereotype.Component; |
26 | 23 | import org.thingsboard.server.common.data.id.EntityId; |
27 | 24 | import org.thingsboard.server.common.data.id.TenantId; |
28 | -import org.thingsboard.server.common.data.kv.Aggregation; | |
29 | -import org.thingsboard.server.common.data.kv.DeleteTsKvQuery; | |
30 | -import org.thingsboard.server.common.data.kv.ReadTsKvQuery; | |
31 | 25 | import org.thingsboard.server.common.data.kv.TsKvEntry; |
32 | -import org.thingsboard.server.dao.DaoUtil; | |
33 | -import org.thingsboard.server.dao.model.sqlts.psql.TsKvEntity; | |
26 | +import org.thingsboard.server.dao.model.sqlts.ts.TsKvEntity; | |
34 | 27 | import org.thingsboard.server.dao.sqlts.AbstractChunkedAggregationTimeseriesDao; |
35 | 28 | import org.thingsboard.server.dao.sqlts.EntityContainer; |
29 | +import org.thingsboard.server.dao.sqlts.insert.psql.PsqlPartitioningRepository; | |
36 | 30 | import org.thingsboard.server.dao.timeseries.PsqlPartition; |
37 | 31 | import org.thingsboard.server.dao.timeseries.SqlTsPartitionDate; |
38 | -import org.thingsboard.server.dao.timeseries.TimeseriesDao; | |
39 | 32 | import org.thingsboard.server.dao.util.PsqlDao; |
40 | 33 | import org.thingsboard.server.dao.util.SqlTsDao; |
41 | 34 | |
... | ... | @@ -44,11 +37,8 @@ import java.time.LocalDateTime; |
44 | 37 | import java.time.ZoneOffset; |
45 | 38 | import java.time.ZonedDateTime; |
46 | 39 | import java.time.format.DateTimeFormatter; |
47 | -import java.util.ArrayList; | |
48 | -import java.util.List; | |
49 | 40 | import java.util.Map; |
50 | 41 | import java.util.Optional; |
51 | -import java.util.concurrent.CompletableFuture; | |
52 | 42 | import java.util.concurrent.ConcurrentHashMap; |
53 | 43 | import java.util.concurrent.locks.ReentrantLock; |
54 | 44 | |
... | ... | @@ -59,15 +49,12 @@ import static org.thingsboard.server.dao.timeseries.SqlTsPartitionDate.EPOCH_STA |
59 | 49 | @Slf4j |
60 | 50 | @SqlTsDao |
61 | 51 | @PsqlDao |
62 | -public class JpaPsqlTimeseriesDao extends AbstractChunkedAggregationTimeseriesDao<TsKvEntity> implements TimeseriesDao { | |
52 | +public class JpaPsqlTimeseriesDao extends AbstractChunkedAggregationTimeseriesDao { | |
63 | 53 | |
64 | 54 | private final Map<Long, PsqlPartition> partitions = new ConcurrentHashMap<>(); |
65 | 55 | private static final ReentrantLock partitionCreationLock = new ReentrantLock(); |
66 | 56 | |
67 | 57 | @Autowired |
68 | - private TsKvPsqlRepository tsKvRepository; | |
69 | - | |
70 | - @Autowired | |
71 | 58 | private PsqlPartitioningRepository partitioningRepository; |
72 | 59 | |
73 | 60 | private SqlTsPartitionDate tsFormat; |
... | ... | @@ -110,163 +97,6 @@ public class JpaPsqlTimeseriesDao extends AbstractChunkedAggregationTimeseriesDa |
110 | 97 | return tsQueue.add(new EntityContainer(entity, psqlPartition.getPartitionDate())); |
111 | 98 | } |
112 | 99 | |
113 | - @Override | |
114 | - public ListenableFuture<Void> remove(TenantId tenantId, EntityId entityId, DeleteTsKvQuery query) { | |
115 | - return service.submit(() -> { | |
116 | - String strKey = query.getKey(); | |
117 | - Integer keyId = getOrSaveKeyId(strKey); | |
118 | - tsKvRepository.delete( | |
119 | - entityId.getId(), | |
120 | - keyId, | |
121 | - query.getStartTs(), | |
122 | - query.getEndTs()); | |
123 | - return null; | |
124 | - }); | |
125 | - } | |
126 | - | |
127 | - @Override | |
128 | - public ListenableFuture<Void> removeLatest(TenantId tenantId, EntityId entityId, DeleteTsKvQuery query) { | |
129 | - return getRemoveLatestFuture(tenantId, entityId, query); | |
130 | - } | |
131 | - | |
132 | - @Override | |
133 | - public ListenableFuture<Void> saveLatest(TenantId tenantId, EntityId entityId, TsKvEntry tsKvEntry) { | |
134 | - return getSaveLatestFuture(entityId, tsKvEntry); | |
135 | - } | |
136 | - | |
137 | - @Override | |
138 | - public ListenableFuture<TsKvEntry> findLatest(TenantId tenantId, EntityId entityId, String key) { | |
139 | - return getFindLatestFuture(entityId, key); | |
140 | - } | |
141 | - | |
142 | - @Override | |
143 | - public ListenableFuture<List<TsKvEntry>> findAllLatest(TenantId tenantId, EntityId entityId) { | |
144 | - return getFindAllLatestFuture(entityId); | |
145 | - } | |
146 | - | |
147 | - @Override | |
148 | - public ListenableFuture<Void> savePartition(TenantId tenantId, EntityId entityId, long tsKvEntryTs, String key, long ttl) { | |
149 | - return Futures.immediateFuture(null); | |
150 | - } | |
151 | - | |
152 | - @Override | |
153 | - public ListenableFuture<Void> removePartition(TenantId tenantId, EntityId entityId, DeleteTsKvQuery query) { | |
154 | - return Futures.immediateFuture(null); | |
155 | - } | |
156 | - | |
157 | - protected ListenableFuture<List<TsKvEntry>> findAllAsync(TenantId tenantId, EntityId entityId, ReadTsKvQuery query) { | |
158 | - if (query.getAggregation() == Aggregation.NONE) { | |
159 | - return findAllAsyncWithLimit(tenantId, entityId, query); | |
160 | - } else { | |
161 | - long stepTs = query.getStartTs(); | |
162 | - List<ListenableFuture<Optional<TsKvEntry>>> futures = new ArrayList<>(); | |
163 | - while (stepTs < query.getEndTs()) { | |
164 | - long startTs = stepTs; | |
165 | - long endTs = stepTs + query.getInterval(); | |
166 | - long ts = startTs + (endTs - startTs) / 2; | |
167 | - futures.add(findAndAggregateAsync(tenantId, entityId, query.getKey(), startTs, endTs, ts, query.getAggregation())); | |
168 | - stepTs = endTs; | |
169 | - } | |
170 | - return getTskvEntriesFuture(Futures.allAsList(futures)); | |
171 | - } | |
172 | - } | |
173 | - | |
174 | - @Override | |
175 | - protected ListenableFuture<List<TsKvEntry>> findAllAsyncWithLimit(TenantId tenantId, EntityId entityId, ReadTsKvQuery query) { | |
176 | - Integer keyId = getOrSaveKeyId(query.getKey()); | |
177 | - List<TsKvEntity> tsKvEntities = tsKvRepository.findAllWithLimit( | |
178 | - entityId.getId(), | |
179 | - keyId, | |
180 | - query.getStartTs(), | |
181 | - query.getEndTs(), | |
182 | - new PageRequest(0, query.getLimit(), | |
183 | - new Sort(Sort.Direction.fromString( | |
184 | - query.getOrderBy()), "ts"))); | |
185 | - tsKvEntities.forEach(tsKvEntity -> tsKvEntity.setStrKey(query.getKey())); | |
186 | - return Futures.immediateFuture(DaoUtil.convertDataList(tsKvEntities)); | |
187 | - } | |
188 | - | |
189 | - @Override | |
190 | - protected ListenableFuture<Optional<TsKvEntry>> findAndAggregateAsync(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, long ts, Aggregation aggregation) { | |
191 | - List<CompletableFuture<TsKvEntity>> entitiesFutures = new ArrayList<>(); | |
192 | - switchAggregation(tenantId, entityId, key, startTs, endTs, aggregation, entitiesFutures); | |
193 | - return Futures.transform(setFutures(entitiesFutures), entity -> { | |
194 | - if (entity != null && entity.isNotEmpty()) { | |
195 | - entity.setEntityId(entityId.getId()); | |
196 | - entity.setStrKey(key); | |
197 | - entity.setTs(ts); | |
198 | - return Optional.of(DaoUtil.getData(entity)); | |
199 | - } else { | |
200 | - return Optional.empty(); | |
201 | - } | |
202 | - }); | |
203 | - } | |
204 | - | |
205 | - @Override | |
206 | - protected void findCount(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, List<CompletableFuture<TsKvEntity>> entitiesFutures) { | |
207 | - Integer keyId = getOrSaveKeyId(key); | |
208 | - entitiesFutures.add(tsKvRepository.findCount( | |
209 | - entityId.getId(), | |
210 | - keyId, | |
211 | - startTs, | |
212 | - endTs)); | |
213 | - } | |
214 | - | |
215 | - @Override | |
216 | - protected void findSum(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, List<CompletableFuture<TsKvEntity>> entitiesFutures) { | |
217 | - Integer keyId = getOrSaveKeyId(key); | |
218 | - entitiesFutures.add(tsKvRepository.findSum( | |
219 | - entityId.getId(), | |
220 | - keyId, | |
221 | - startTs, | |
222 | - endTs)); | |
223 | - } | |
224 | - | |
225 | - @Override | |
226 | - protected void findMin(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, List<CompletableFuture<TsKvEntity>> entitiesFutures) { | |
227 | - Integer keyId = getOrSaveKeyId(key); | |
228 | - entitiesFutures.add(tsKvRepository.findStringMin( | |
229 | - entityId.getId(), | |
230 | - keyId, | |
231 | - startTs, | |
232 | - endTs)); | |
233 | - entitiesFutures.add(tsKvRepository.findNumericMin( | |
234 | - entityId.getId(), | |
235 | - keyId, | |
236 | - startTs, | |
237 | - endTs)); | |
238 | - } | |
239 | - | |
240 | - @Override | |
241 | - protected void findMax(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, List<CompletableFuture<TsKvEntity>> entitiesFutures) { | |
242 | - Integer keyId = getOrSaveKeyId(key); | |
243 | - entitiesFutures.add(tsKvRepository.findStringMax( | |
244 | - entityId.getId(), | |
245 | - keyId, | |
246 | - startTs, | |
247 | - endTs)); | |
248 | - entitiesFutures.add(tsKvRepository.findNumericMax( | |
249 | - entityId.getId(), | |
250 | - keyId, | |
251 | - startTs, | |
252 | - endTs)); | |
253 | - } | |
254 | - | |
255 | - @Override | |
256 | - protected void findAvg(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, List<CompletableFuture<TsKvEntity>> entitiesFutures) { | |
257 | - Integer keyId = getOrSaveKeyId(key); | |
258 | - entitiesFutures.add(tsKvRepository.findAvg( | |
259 | - entityId.getId(), | |
260 | - keyId, | |
261 | - startTs, | |
262 | - endTs)); | |
263 | - } | |
264 | - | |
265 | - @Override | |
266 | - public ListenableFuture<List<TsKvEntry>> findAllAsync(TenantId tenantId, EntityId entityId, List<ReadTsKvQuery> queries) { | |
267 | - return processFindAllAsync(tenantId, entityId, queries); | |
268 | - } | |
269 | - | |
270 | 100 | private void savePartition(PsqlPartition psqlPartition) { |
271 | 101 | if (!partitions.containsKey(psqlPartition.getStart())) { |
272 | 102 | partitionCreationLock.lock(); |
... | ... | @@ -306,4 +136,4 @@ public class JpaPsqlTimeseriesDao extends AbstractChunkedAggregationTimeseriesDa |
306 | 136 | private static long toMills(LocalDateTime time) { |
307 | 137 | return time.toInstant(ZoneOffset.UTC).toEpochMilli(); |
308 | 138 | } |
309 | -} | |
\ No newline at end of file | ||
139 | +} | ... | ... |
... | ... | @@ -17,7 +17,7 @@ package org.thingsboard.server.dao.sqlts.timescale; |
17 | 17 | |
18 | 18 | import org.springframework.scheduling.annotation.Async; |
19 | 19 | import org.springframework.stereotype.Repository; |
20 | -import org.thingsboard.server.dao.model.sqlts.timescale.TimescaleTsKvEntity; | |
20 | +import org.thingsboard.server.dao.model.sqlts.timescale.ts.TimescaleTsKvEntity; | |
21 | 21 | import org.thingsboard.server.dao.util.TimescaleDBTsDao; |
22 | 22 | |
23 | 23 | import javax.persistence.EntityManager; |
... | ... | @@ -98,4 +98,4 @@ public class AggregationRepository { |
98 | 98 | } |
99 | 99 | |
100 | 100 | |
101 | -} | |
\ No newline at end of file | ||
101 | +} | ... | ... |
... | ... | @@ -31,12 +31,12 @@ import org.thingsboard.server.common.data.kv.DeleteTsKvQuery; |
31 | 31 | import org.thingsboard.server.common.data.kv.ReadTsKvQuery; |
32 | 32 | import org.thingsboard.server.common.data.kv.TsKvEntry; |
33 | 33 | import org.thingsboard.server.dao.DaoUtil; |
34 | -import org.thingsboard.server.dao.model.sqlts.timescale.TimescaleTsKvEntity; | |
34 | +import org.thingsboard.server.dao.model.sqlts.timescale.ts.TimescaleTsKvEntity; | |
35 | 35 | import org.thingsboard.server.dao.sql.TbSqlBlockingQueue; |
36 | 36 | import org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams; |
37 | 37 | import org.thingsboard.server.dao.sqlts.AbstractSqlTimeseriesDao; |
38 | 38 | import org.thingsboard.server.dao.sqlts.EntityContainer; |
39 | -import org.thingsboard.server.dao.sqlts.InsertTsRepository; | |
39 | +import org.thingsboard.server.dao.sqlts.insert.InsertTsRepository; | |
40 | 40 | import org.thingsboard.server.dao.timeseries.TimeseriesDao; |
41 | 41 | import org.thingsboard.server.dao.util.TimescaleDBTsDao; |
42 | 42 | |
... | ... | @@ -286,4 +286,4 @@ public class TimescaleTimeseriesDao extends AbstractSqlTimeseriesDao implements |
286 | 286 | startTs, |
287 | 287 | endTs); |
288 | 288 | } |
289 | -} | |
\ No newline at end of file | ||
289 | +} | ... | ... |
... | ... | @@ -21,8 +21,8 @@ import org.springframework.data.jpa.repository.Query; |
21 | 21 | import org.springframework.data.repository.CrudRepository; |
22 | 22 | import org.springframework.data.repository.query.Param; |
23 | 23 | import org.springframework.transaction.annotation.Transactional; |
24 | -import org.thingsboard.server.dao.model.sqlts.timescale.TimescaleTsKvCompositeKey; | |
25 | -import org.thingsboard.server.dao.model.sqlts.timescale.TimescaleTsKvEntity; | |
24 | +import org.thingsboard.server.dao.model.sqlts.timescale.ts.TimescaleTsKvCompositeKey; | |
25 | +import org.thingsboard.server.dao.model.sqlts.timescale.ts.TimescaleTsKvEntity; | |
26 | 26 | import org.thingsboard.server.dao.util.TimescaleDBTsDao; |
27 | 27 | |
28 | 28 | import java.util.List; |
... | ... | @@ -54,4 +54,4 @@ public interface TsKvTimescaleRepository extends CrudRepository<TimescaleTsKvEnt |
54 | 54 | @Param("startTs") long startTs, |
55 | 55 | @Param("endTs") long endTs); |
56 | 56 | |
57 | -} | |
\ No newline at end of file | ||
57 | +} | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/sqlts/ts/TsKvRepository.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/sqlts/psql/TsKvPsqlRepository.java
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.dao.sqlts.psql; | |
16 | +package org.thingsboard.server.dao.sqlts.ts; | |
17 | 17 | |
18 | 18 | import org.springframework.data.domain.Pageable; |
19 | 19 | import org.springframework.data.jpa.repository.Modifying; |
... | ... | @@ -22,8 +22,8 @@ import org.springframework.data.repository.CrudRepository; |
22 | 22 | import org.springframework.data.repository.query.Param; |
23 | 23 | import org.springframework.scheduling.annotation.Async; |
24 | 24 | import org.springframework.transaction.annotation.Transactional; |
25 | -import org.thingsboard.server.dao.model.sqlts.psql.TsKvCompositeKey; | |
26 | -import org.thingsboard.server.dao.model.sqlts.psql.TsKvEntity; | |
25 | +import org.thingsboard.server.dao.model.sqlts.ts.TsKvCompositeKey; | |
26 | +import org.thingsboard.server.dao.model.sqlts.ts.TsKvEntity; | |
27 | 27 | import org.thingsboard.server.dao.util.SqlDao; |
28 | 28 | |
29 | 29 | import java.util.List; |
... | ... | @@ -31,7 +31,7 @@ import java.util.UUID; |
31 | 31 | import java.util.concurrent.CompletableFuture; |
32 | 32 | |
33 | 33 | @SqlDao |
34 | -public interface TsKvPsqlRepository extends CrudRepository<TsKvEntity, TsKvCompositeKey> { | |
34 | +public interface TsKvRepository extends CrudRepository<TsKvEntity, TsKvCompositeKey> { | |
35 | 35 | |
36 | 36 | @Query("SELECT tskv FROM TsKvEntity tskv WHERE tskv.entityId = :entityId " + |
37 | 37 | "AND tskv.key = :entityKey AND tskv.ts > :startTs AND tskv.ts <= :endTs") | ... | ... |