Showing
98 changed files
with
1060 additions
and
660 deletions
Too many changes to show.
To preserve performance only 98 of 130 files are displayed.
@@ -22,37 +22,37 @@ BEGIN | @@ -22,37 +22,37 @@ BEGIN | ||
22 | END; | 22 | END; |
23 | $$ LANGUAGE plpgsql; | 23 | $$ LANGUAGE plpgsql; |
24 | 24 | ||
25 | -CREATE OR REPLACE FUNCTION delete_device_records_from_ts_kv(tenant_id varchar, customer_id varchar, ttl bigint, | 25 | +CREATE OR REPLACE FUNCTION delete_device_records_from_ts_kv(tenant_id uuid, customer_id uuid, ttl bigint, |
26 | OUT deleted bigint) AS | 26 | OUT deleted bigint) AS |
27 | $$ | 27 | $$ |
28 | BEGIN | 28 | BEGIN |
29 | EXECUTE format( | 29 | EXECUTE format( |
30 | - 'WITH deleted AS (DELETE FROM ts_kv WHERE entity_id IN (SELECT to_uuid(device.id) as entity_id FROM device WHERE tenant_id = %L and customer_id = %L) AND ts < %L::bigint RETURNING *) SELECT count(*) FROM deleted', | 30 | + 'WITH deleted AS (DELETE FROM ts_kv WHERE entity_id IN (SELECT device.id as entity_id FROM device WHERE tenant_id = %L and customer_id = %L) AND ts < %L::bigint RETURNING *) SELECT count(*) FROM deleted', |
31 | tenant_id, customer_id, ttl) into deleted; | 31 | tenant_id, customer_id, ttl) into deleted; |
32 | END; | 32 | END; |
33 | $$ LANGUAGE plpgsql; | 33 | $$ LANGUAGE plpgsql; |
34 | 34 | ||
35 | -CREATE OR REPLACE FUNCTION delete_asset_records_from_ts_kv(tenant_id varchar, customer_id varchar, ttl bigint, | 35 | +CREATE OR REPLACE FUNCTION delete_asset_records_from_ts_kv(tenant_id uuid, customer_id uuid, ttl bigint, |
36 | OUT deleted bigint) AS | 36 | OUT deleted bigint) AS |
37 | $$ | 37 | $$ |
38 | BEGIN | 38 | BEGIN |
39 | EXECUTE format( | 39 | EXECUTE format( |
40 | - 'WITH deleted AS (DELETE FROM ts_kv WHERE entity_id IN (SELECT to_uuid(asset.id) as entity_id FROM asset WHERE tenant_id = %L and customer_id = %L) AND ts < %L::bigint RETURNING *) SELECT count(*) FROM deleted', | 40 | + 'WITH deleted AS (DELETE FROM ts_kv WHERE entity_id IN (SELECT asset.id as entity_id FROM asset WHERE tenant_id = %L and customer_id = %L) AND ts < %L::bigint RETURNING *) SELECT count(*) FROM deleted', |
41 | tenant_id, customer_id, ttl) into deleted; | 41 | tenant_id, customer_id, ttl) into deleted; |
42 | END; | 42 | END; |
43 | $$ LANGUAGE plpgsql; | 43 | $$ LANGUAGE plpgsql; |
44 | 44 | ||
45 | -CREATE OR REPLACE FUNCTION delete_customer_records_from_ts_kv(tenant_id varchar, customer_id varchar, ttl bigint, | 45 | +CREATE OR REPLACE FUNCTION delete_customer_records_from_ts_kv(tenant_id uuid, customer_id uuid, ttl bigint, |
46 | OUT deleted bigint) AS | 46 | OUT deleted bigint) AS |
47 | $$ | 47 | $$ |
48 | BEGIN | 48 | BEGIN |
49 | EXECUTE format( | 49 | EXECUTE format( |
50 | - 'WITH deleted AS (DELETE FROM ts_kv WHERE entity_id IN (SELECT to_uuid(customer.id) as entity_id FROM customer WHERE tenant_id = %L and id = %L) AND ts < %L::bigint RETURNING *) SELECT count(*) FROM deleted', | 50 | + 'WITH deleted AS (DELETE FROM ts_kv WHERE entity_id IN (SELECT customer.id as entity_id FROM customer WHERE tenant_id = %L and id = %L) AND ts < %L::bigint RETURNING *) SELECT count(*) FROM deleted', |
51 | tenant_id, customer_id, ttl) into deleted; | 51 | tenant_id, customer_id, ttl) into deleted; |
52 | END; | 52 | END; |
53 | $$ LANGUAGE plpgsql; | 53 | $$ LANGUAGE plpgsql; |
54 | 54 | ||
55 | -CREATE OR REPLACE PROCEDURE cleanup_timeseries_by_ttl(IN null_uuid varchar(31), | 55 | +CREATE OR REPLACE PROCEDURE cleanup_timeseries_by_ttl(IN null_uuid uuid, |
56 | IN system_ttl bigint, INOUT deleted bigint) | 56 | IN system_ttl bigint, INOUT deleted bigint) |
57 | LANGUAGE plpgsql AS | 57 | LANGUAGE plpgsql AS |
58 | $$ | 58 | $$ |
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 | + | ||
17 | +CREATE OR REPLACE FUNCTION extract_ts(uuid UUID) RETURNS BIGINT AS | ||
18 | +$$ | ||
19 | +DECLARE | ||
20 | + bytes bytea; | ||
21 | +BEGIN | ||
22 | + bytes := uuid_send(uuid); | ||
23 | + RETURN | ||
24 | + ( | ||
25 | + ( | ||
26 | + (get_byte(bytes, 0)::bigint << 24) | | ||
27 | + (get_byte(bytes, 1)::bigint << 16) | | ||
28 | + (get_byte(bytes, 2)::bigint << 8) | | ||
29 | + (get_byte(bytes, 3)::bigint << 0) | ||
30 | + ) + ( | ||
31 | + ((get_byte(bytes, 4)::bigint << 8 | | ||
32 | + get_byte(bytes, 5)::bigint)) << 32 | ||
33 | + ) + ( | ||
34 | + (((get_byte(bytes, 6)::bigint & 15) << 8 | get_byte(bytes, 7)::bigint) & 4095) << 48 | ||
35 | + ) - 122192928000000000 | ||
36 | + ) / 10000::double precision | ||
37 | + ; | ||
38 | +END | ||
39 | +$$ LANGUAGE plpgsql | ||
40 | + IMMUTABLE PARALLEL SAFE | ||
41 | + RETURNS NULL ON NULL INPUT; |
@@ -15,10 +15,14 @@ | @@ -15,10 +15,14 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.service.subscription; | 16 | package org.thingsboard.server.service.subscription; |
17 | 17 | ||
18 | +import com.google.common.util.concurrent.FutureCallback; | ||
18 | import com.google.common.util.concurrent.Futures; | 19 | import com.google.common.util.concurrent.Futures; |
19 | import com.google.common.util.concurrent.ListenableFuture; | 20 | import com.google.common.util.concurrent.ListenableFuture; |
21 | +import com.google.common.util.concurrent.MoreExecutors; | ||
20 | import lombok.extern.slf4j.Slf4j; | 22 | import lombok.extern.slf4j.Slf4j; |
23 | +import org.checkerframework.checker.nullness.qual.Nullable; | ||
21 | import org.springframework.beans.factory.annotation.Autowired; | 24 | import org.springframework.beans.factory.annotation.Autowired; |
25 | +import org.springframework.beans.factory.annotation.Value; | ||
22 | import org.springframework.context.annotation.Lazy; | 26 | import org.springframework.context.annotation.Lazy; |
23 | import org.springframework.context.event.EventListener; | 27 | import org.springframework.context.event.EventListener; |
24 | import org.springframework.stereotype.Service; | 28 | import org.springframework.stereotype.Service; |
@@ -33,6 +37,8 @@ import org.thingsboard.server.common.data.kv.TsKvEntry; | @@ -33,6 +37,8 @@ import org.thingsboard.server.common.data.kv.TsKvEntry; | ||
33 | import org.thingsboard.server.common.data.page.PageData; | 37 | import org.thingsboard.server.common.data.page.PageData; |
34 | import org.thingsboard.server.common.data.query.EntityData; | 38 | import org.thingsboard.server.common.data.query.EntityData; |
35 | import org.thingsboard.server.common.data.query.EntityDataQuery; | 39 | import org.thingsboard.server.common.data.query.EntityDataQuery; |
40 | +import org.thingsboard.server.common.data.query.EntityKey; | ||
41 | +import org.thingsboard.server.common.data.query.EntityKeyType; | ||
36 | import org.thingsboard.server.common.data.query.TsValue; | 42 | import org.thingsboard.server.common.data.query.TsValue; |
37 | import org.thingsboard.server.common.msg.queue.ServiceType; | 43 | import org.thingsboard.server.common.msg.queue.ServiceType; |
38 | import org.thingsboard.server.common.msg.queue.TbCallback; | 44 | import org.thingsboard.server.common.msg.queue.TbCallback; |
@@ -53,6 +59,7 @@ import org.thingsboard.server.service.telemetry.cmd.v2.EntityDataUpdate; | @@ -53,6 +59,7 @@ import org.thingsboard.server.service.telemetry.cmd.v2.EntityDataUpdate; | ||
53 | import org.thingsboard.server.service.telemetry.cmd.v2.EntityHistoryCmd; | 59 | import org.thingsboard.server.service.telemetry.cmd.v2.EntityHistoryCmd; |
54 | import org.thingsboard.server.service.telemetry.cmd.v2.LatestValueCmd; | 60 | import org.thingsboard.server.service.telemetry.cmd.v2.LatestValueCmd; |
55 | import org.thingsboard.server.service.telemetry.cmd.v2.TimeSeriesCmd; | 61 | import org.thingsboard.server.service.telemetry.cmd.v2.TimeSeriesCmd; |
62 | +import org.thingsboard.server.service.telemetry.sub.SubscriptionErrorCode; | ||
56 | import org.thingsboard.server.service.telemetry.sub.SubscriptionUpdate; | 63 | import org.thingsboard.server.service.telemetry.sub.SubscriptionUpdate; |
57 | 64 | ||
58 | import javax.annotation.PostConstruct; | 65 | import javax.annotation.PostConstruct; |
@@ -60,6 +67,7 @@ import javax.annotation.PreDestroy; | @@ -60,6 +67,7 @@ import javax.annotation.PreDestroy; | ||
60 | import java.util.ArrayList; | 67 | import java.util.ArrayList; |
61 | import java.util.HashMap; | 68 | import java.util.HashMap; |
62 | import java.util.LinkedHashMap; | 69 | import java.util.LinkedHashMap; |
70 | +import java.util.LinkedHashSet; | ||
63 | import java.util.List; | 71 | import java.util.List; |
64 | import java.util.Map; | 72 | import java.util.Map; |
65 | import java.util.Set; | 73 | import java.util.Set; |
@@ -67,7 +75,6 @@ import java.util.concurrent.ConcurrentHashMap; | @@ -67,7 +75,6 @@ import java.util.concurrent.ConcurrentHashMap; | ||
67 | import java.util.concurrent.ExecutionException; | 75 | import java.util.concurrent.ExecutionException; |
68 | import java.util.concurrent.ExecutorService; | 76 | import java.util.concurrent.ExecutorService; |
69 | import java.util.concurrent.Executors; | 77 | import java.util.concurrent.Executors; |
70 | -import java.util.function.Function; | ||
71 | import java.util.stream.Collectors; | 78 | import java.util.stream.Collectors; |
72 | 79 | ||
73 | @Slf4j | 80 | @Slf4j |
@@ -101,11 +108,16 @@ public class DefaultTbEntityDataSubscriptionService implements TbEntityDataSubsc | @@ -101,11 +108,16 @@ public class DefaultTbEntityDataSubscriptionService implements TbEntityDataSubsc | ||
101 | @Autowired | 108 | @Autowired |
102 | private TimeseriesService tsService; | 109 | private TimeseriesService tsService; |
103 | 110 | ||
111 | + @Value("${database.ts.type}") | ||
112 | + private String databaseTsType; | ||
113 | + | ||
104 | private ExecutorService wsCallBackExecutor; | 114 | private ExecutorService wsCallBackExecutor; |
115 | + private boolean tsInSqlDB; | ||
105 | 116 | ||
106 | @PostConstruct | 117 | @PostConstruct |
107 | public void initExecutor() { | 118 | public void initExecutor() { |
108 | wsCallBackExecutor = Executors.newSingleThreadExecutor(ThingsBoardThreadFactory.forName("ws-entity-sub-callback")); | 119 | wsCallBackExecutor = Executors.newSingleThreadExecutor(ThingsBoardThreadFactory.forName("ws-entity-sub-callback")); |
120 | + tsInSqlDB = databaseTsType.equalsIgnoreCase("sql") || databaseTsType.equalsIgnoreCase("timescale"); | ||
109 | } | 121 | } |
110 | 122 | ||
111 | @PreDestroy | 123 | @PreDestroy |
@@ -156,7 +168,70 @@ public class DefaultTbEntityDataSubscriptionService implements TbEntityDataSubsc | @@ -156,7 +168,70 @@ public class DefaultTbEntityDataSubscriptionService implements TbEntityDataSubsc | ||
156 | } | 168 | } |
157 | 169 | ||
158 | private void handleLatestCmd(TelemetryWebSocketSessionRef session, int cmdId, EntityDataQuery query, LatestValueCmd latestCmd) { | 170 | private void handleLatestCmd(TelemetryWebSocketSessionRef session, int cmdId, EntityDataQuery query, LatestValueCmd latestCmd) { |
171 | + TenantId tenantId = session.getSecurityCtx().getTenantId(); | ||
172 | + CustomerId customerId = session.getSecurityCtx().getCustomerId(); | ||
173 | + //Step 1. Update existing query with the contents of LatestValueCmd | ||
174 | + latestCmd.getKeys().forEach(key -> { | ||
175 | + if (!query.getLatestValues().contains(key)) { | ||
176 | + query.getLatestValues().add(key); | ||
177 | + } | ||
178 | + }); | ||
179 | + | ||
180 | + //Step 2. Fetch the initial data | ||
181 | + PageData<EntityData> data = entityService.findEntityDataByQuery(tenantId, customerId, query); | ||
182 | + | ||
183 | + //Step 3. Fetch the latest values for telemetry keys (in case they are not copied from NoSQL to SQL DB in hybrid mode. | ||
184 | + if (!tsInSqlDB) { | ||
185 | + List<String> allTsKeys = latestCmd.getKeys().stream() | ||
186 | + .filter(key -> key.getType().equals(EntityKeyType.TIME_SERIES)) | ||
187 | + .map(EntityKey::getKey).collect(Collectors.toList()); | ||
188 | + | ||
189 | + Map<EntityData, ListenableFuture<Map<String, TsValue>>> missingTelemetryFurutes = new HashMap<>(); | ||
190 | + for (EntityData entityData : data.getData()) { | ||
191 | + Map<EntityKeyType, Map<String, TsValue>> latestEntityData = entityData.getLatest(); | ||
192 | + Map<String, TsValue> tsEntityData = latestEntityData.get(EntityKeyType.TIME_SERIES); | ||
193 | + Set<String> missingTsKeys = new LinkedHashSet<>(allTsKeys); | ||
194 | + if (tsEntityData != null) { | ||
195 | + missingTsKeys.removeAll(tsEntityData.keySet()); | ||
196 | + } else { | ||
197 | + tsEntityData = new HashMap<>(); | ||
198 | + latestEntityData.put(EntityKeyType.TIME_SERIES, tsEntityData); | ||
199 | + } | ||
200 | + | ||
201 | + ListenableFuture<List<TsKvEntry>> missingTsData = tsService.findLatest(tenantId, entityData.getEntityId(), missingTsKeys); | ||
202 | + missingTelemetryFurutes.put(entityData, Futures.transform(missingTsData, this::toTsValue, MoreExecutors.directExecutor())); | ||
203 | + } | ||
204 | + Futures.addCallback(Futures.allAsList(missingTelemetryFurutes.values()), new FutureCallback<List<Map<String, TsValue>>>() { | ||
205 | + @Override | ||
206 | + public void onSuccess(@Nullable List<Map<String, TsValue>> result) { | ||
207 | + missingTelemetryFurutes.forEach((key, value) -> { | ||
208 | + try { | ||
209 | + key.getLatest().get(EntityKeyType.TIME_SERIES).putAll(value.get()); | ||
210 | + } catch (InterruptedException | ExecutionException e) { | ||
211 | + log.warn("[{}][{}] Failed to lookup latest telemetry: {}:{}", session.getSessionId(), cmdId, key.getEntityId(), allTsKeys, e); | ||
212 | + } | ||
213 | + }); | ||
214 | + EntityDataUpdate update = new EntityDataUpdate(cmdId, data, null); | ||
215 | + wsService.sendWsMsg(session.getSessionId(), update); | ||
216 | + //TODO: create context for this (session, cmdId) that contains query, latestCmd and update. Subscribe + periodic updates. | ||
217 | + } | ||
218 | + | ||
219 | + @Override | ||
220 | + public void onFailure(Throwable t) { | ||
221 | + log.warn("[{}][{}] Failed to process websocket command: {}:{}", session.getSessionId(), cmdId, query, latestCmd, t); | ||
222 | + wsService.sendWsMsg(session.getSessionId(), | ||
223 | + new EntityDataUpdate(cmdId, SubscriptionErrorCode.INTERNAL_ERROR.getCode(), "Failed to process websocket command!")); | ||
224 | + } | ||
225 | + }, wsCallBackExecutor); | ||
226 | + } else { | ||
227 | + EntityDataUpdate update = new EntityDataUpdate(cmdId, data, null); | ||
228 | + wsService.sendWsMsg(session.getSessionId(), update); | ||
229 | + //TODO: create context for this (session, cmdId) that contains query, latestCmd and update. Subscribe + periodic updates. | ||
230 | + } | ||
231 | + } | ||
159 | 232 | ||
233 | + private Map<String, TsValue> toTsValue(List<TsKvEntry> data) { | ||
234 | + return data.stream().collect(Collectors.toMap(TsKvEntry::getKey, value -> new TsValue(value.getTs(), value.getValueAsString()))); | ||
160 | } | 235 | } |
161 | 236 | ||
162 | private void handleHistoryCmd(TelemetryWebSocketSessionRef session, int cmdId, EntityDataQuery query, EntityHistoryCmd historyCmd) { | 237 | private void handleHistoryCmd(TelemetryWebSocketSessionRef session, int cmdId, EntityDataQuery query, EntityHistoryCmd historyCmd) { |
@@ -181,6 +256,8 @@ public class DefaultTbEntityDataSubscriptionService implements TbEntityDataSubsc | @@ -181,6 +256,8 @@ public class DefaultTbEntityDataSubscriptionService implements TbEntityDataSubsc | ||
181 | keyData.forEach((k, v) -> entityData.getTimeseries().put(k, v.toArray(new TsValue[v.size()]))); | 256 | keyData.forEach((k, v) -> entityData.getTimeseries().put(k, v.toArray(new TsValue[v.size()]))); |
182 | } catch (InterruptedException | ExecutionException e) { | 257 | } catch (InterruptedException | ExecutionException e) { |
183 | log.warn("[{}][{}][{}] Failed to fetch historical data", session.getSessionId(), cmdId, entityData.getEntityId(), e); | 258 | log.warn("[{}][{}][{}] Failed to fetch historical data", session.getSessionId(), cmdId, entityData.getEntityId(), e); |
259 | + wsService.sendWsMsg(session.getSessionId(), | ||
260 | + new EntityDataUpdate(cmdId, SubscriptionErrorCode.INTERNAL_ERROR.getCode(), "Failed to fetch historical data!")); | ||
184 | } | 261 | } |
185 | }); | 262 | }); |
186 | EntityDataUpdate update = new EntityDataUpdate(cmdId, data, null); | 263 | EntityDataUpdate update = new EntityDataUpdate(cmdId, data, null); |
@@ -15,18 +15,30 @@ | @@ -15,18 +15,30 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.service.telemetry.cmd.v2; | 16 | package org.thingsboard.server.service.telemetry.cmd.v2; |
17 | 17 | ||
18 | +import lombok.AllArgsConstructor; | ||
18 | import lombok.Data; | 19 | import lombok.Data; |
19 | import org.thingsboard.server.common.data.page.PageData; | 20 | import org.thingsboard.server.common.data.page.PageData; |
20 | import org.thingsboard.server.common.data.query.EntityData; | 21 | import org.thingsboard.server.common.data.query.EntityData; |
22 | +import org.thingsboard.server.service.telemetry.sub.SubscriptionErrorCode; | ||
21 | 23 | ||
22 | import java.util.List; | 24 | import java.util.List; |
23 | 25 | ||
24 | @Data | 26 | @Data |
27 | +@AllArgsConstructor | ||
25 | public class EntityDataUpdate { | 28 | public class EntityDataUpdate { |
26 | 29 | ||
27 | private final int cmdId; | 30 | private final int cmdId; |
28 | private final PageData<EntityData> data; | 31 | private final PageData<EntityData> data; |
29 | private final List<EntityData> update; | 32 | private final List<EntityData> update; |
30 | - private int errorCode; | ||
31 | - private String errorMsg; | 33 | + private final int errorCode; |
34 | + private final String errorMsg; | ||
35 | + | ||
36 | + public EntityDataUpdate(int cmdId, PageData<EntityData> data, List<EntityData> update) { | ||
37 | + this(cmdId, data, update, SubscriptionErrorCode.NO_ERROR.getCode(), null); | ||
38 | + } | ||
39 | + | ||
40 | + public EntityDataUpdate(int cmdId, int errorCode, String errorMsg) { | ||
41 | + this(cmdId, null, null, errorCode, errorMsg); | ||
42 | + } | ||
43 | + | ||
32 | } | 44 | } |
@@ -35,7 +35,7 @@ public class PsqlTimeseriesCleanUpService extends AbstractTimeseriesCleanUpServi | @@ -35,7 +35,7 @@ public class PsqlTimeseriesCleanUpService extends AbstractTimeseriesCleanUpServi | ||
35 | protected void doCleanUp(Connection connection) { | 35 | protected void doCleanUp(Connection connection) { |
36 | long totalPartitionsRemoved = executeQuery(connection, "call drop_partitions_by_max_ttl('" + partitionType + "'," + systemTtl + ", 0);"); | 36 | long totalPartitionsRemoved = executeQuery(connection, "call drop_partitions_by_max_ttl('" + partitionType + "'," + systemTtl + ", 0);"); |
37 | log.info("Total partitions removed by TTL: [{}]", totalPartitionsRemoved); | 37 | log.info("Total partitions removed by TTL: [{}]", totalPartitionsRemoved); |
38 | - long totalEntitiesTelemetryRemoved = executeQuery(connection, "call cleanup_timeseries_by_ttl('" + ModelConstants.NULL_UUID_STR + "'," + systemTtl + ", 0);"); | 38 | + long totalEntitiesTelemetryRemoved = executeQuery(connection, "call cleanup_timeseries_by_ttl('" + ModelConstants.NULL_UUID + "'," + systemTtl + ", 0);"); |
39 | log.info("Total telemetry removed stats by TTL for entities: [{}]", totalEntitiesTelemetryRemoved); | 39 | log.info("Total telemetry removed stats by TTL for entities: [{}]", totalEntitiesTelemetryRemoved); |
40 | } | 40 | } |
41 | } | 41 | } |
@@ -29,7 +29,7 @@ public class TimescaleTimeseriesCleanUpService extends AbstractTimeseriesCleanUp | @@ -29,7 +29,7 @@ public class TimescaleTimeseriesCleanUpService extends AbstractTimeseriesCleanUp | ||
29 | 29 | ||
30 | @Override | 30 | @Override |
31 | protected void doCleanUp(Connection connection) { | 31 | protected void doCleanUp(Connection connection) { |
32 | - long totalEntitiesTelemetryRemoved = executeQuery(connection, "call cleanup_timeseries_by_ttl('" + ModelConstants.NULL_UUID_STR + "'," + systemTtl + ", 0);"); | 32 | + long totalEntitiesTelemetryRemoved = executeQuery(connection, "call cleanup_timeseries_by_ttl('" + ModelConstants.NULL_UUID + "'," + systemTtl + ", 0);"); |
33 | log.info("Total telemetry removed stats by TTL for entities: [{}]", totalEntitiesTelemetryRemoved); | 33 | log.info("Total telemetry removed stats by TTL for entities: [{}]", totalEntitiesTelemetryRemoved); |
34 | } | 34 | } |
35 | } | 35 | } |
@@ -18,6 +18,7 @@ package org.thingsboard.server.controller; | @@ -18,6 +18,7 @@ package org.thingsboard.server.controller; | ||
18 | import org.junit.After; | 18 | import org.junit.After; |
19 | import org.junit.Assert; | 19 | import org.junit.Assert; |
20 | import org.junit.Before; | 20 | import org.junit.Before; |
21 | +import org.junit.Ignore; | ||
21 | import org.junit.Test; | 22 | import org.junit.Test; |
22 | import org.springframework.beans.factory.annotation.Autowired; | 23 | import org.springframework.beans.factory.annotation.Autowired; |
23 | import org.thingsboard.server.common.data.Device; | 24 | import org.thingsboard.server.common.data.Device; |
@@ -32,6 +33,8 @@ import org.thingsboard.server.common.data.query.DeviceTypeFilter; | @@ -32,6 +33,8 @@ import org.thingsboard.server.common.data.query.DeviceTypeFilter; | ||
32 | import org.thingsboard.server.common.data.query.EntityData; | 33 | import org.thingsboard.server.common.data.query.EntityData; |
33 | import org.thingsboard.server.common.data.query.EntityDataPageLink; | 34 | import org.thingsboard.server.common.data.query.EntityDataPageLink; |
34 | import org.thingsboard.server.common.data.query.EntityDataQuery; | 35 | import org.thingsboard.server.common.data.query.EntityDataQuery; |
36 | +import org.thingsboard.server.common.data.query.EntityKey; | ||
37 | +import org.thingsboard.server.common.data.query.EntityKeyType; | ||
35 | import org.thingsboard.server.common.data.query.TsValue; | 38 | import org.thingsboard.server.common.data.query.TsValue; |
36 | import org.thingsboard.server.common.data.security.Authority; | 39 | import org.thingsboard.server.common.data.security.Authority; |
37 | import org.thingsboard.server.dao.timeseries.TimeseriesService; | 40 | import org.thingsboard.server.dao.timeseries.TimeseriesService; |
@@ -39,6 +42,7 @@ import org.thingsboard.server.service.telemetry.cmd.TelemetryPluginCmdsWrapper; | @@ -39,6 +42,7 @@ import org.thingsboard.server.service.telemetry.cmd.TelemetryPluginCmdsWrapper; | ||
39 | import org.thingsboard.server.service.telemetry.cmd.v2.EntityDataCmd; | 42 | import org.thingsboard.server.service.telemetry.cmd.v2.EntityDataCmd; |
40 | import org.thingsboard.server.service.telemetry.cmd.v2.EntityDataUpdate; | 43 | import org.thingsboard.server.service.telemetry.cmd.v2.EntityDataUpdate; |
41 | import org.thingsboard.server.service.telemetry.cmd.v2.EntityHistoryCmd; | 44 | import org.thingsboard.server.service.telemetry.cmd.v2.EntityHistoryCmd; |
45 | +import org.thingsboard.server.service.telemetry.cmd.v2.LatestValueCmd; | ||
42 | 46 | ||
43 | import java.util.Arrays; | 47 | import java.util.Arrays; |
44 | import java.util.Collections; | 48 | import java.util.Collections; |
@@ -142,4 +146,58 @@ public class BaseWebsocketApiTest extends AbstractWebsocketTest { | @@ -142,4 +146,58 @@ public class BaseWebsocketApiTest extends AbstractWebsocketTest { | ||
142 | Assert.assertEquals(new TsValue(dataPoint3.getTs(), dataPoint3.getValueAsString()), tsArray[2]); | 146 | Assert.assertEquals(new TsValue(dataPoint3.getTs(), dataPoint3.getValueAsString()), tsArray[2]); |
143 | } | 147 | } |
144 | 148 | ||
149 | + @Test | ||
150 | + @Ignore | ||
151 | + public void testEntityDataLatestWsCmd() throws Exception { | ||
152 | + Device device = new Device(); | ||
153 | + device.setName("Device"); | ||
154 | + device.setType("default"); | ||
155 | + device.setLabel("testLabel" + (int) (Math.random() * 1000)); | ||
156 | + device = doPost("/api/device", device, Device.class); | ||
157 | + | ||
158 | + long now = System.currentTimeMillis(); | ||
159 | + | ||
160 | + DeviceTypeFilter dtf = new DeviceTypeFilter(); | ||
161 | + dtf.setDeviceNameFilter("D"); | ||
162 | + dtf.setDeviceType("default"); | ||
163 | + EntityDataQuery edq = new EntityDataQuery(dtf, new EntityDataPageLink(1, 0, null, null), Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); | ||
164 | + | ||
165 | + LatestValueCmd latestCmd = new LatestValueCmd(); | ||
166 | + latestCmd.setKeys(Collections.singletonList(new EntityKey(EntityKeyType.TIME_SERIES, "temperature"))); | ||
167 | + EntityDataCmd cmd = new EntityDataCmd(1, edq, null, latestCmd, null); | ||
168 | + | ||
169 | + TelemetryPluginCmdsWrapper wrapper = new TelemetryPluginCmdsWrapper(); | ||
170 | + wrapper.setEntityDataCmds(Collections.singletonList(cmd)); | ||
171 | + | ||
172 | + wsClient.send(mapper.writeValueAsString(wrapper)); | ||
173 | + String msg = wsClient.waitForReply(); | ||
174 | + EntityDataUpdate update = mapper.readValue(msg, EntityDataUpdate.class); | ||
175 | + Assert.assertEquals(1, update.getCmdId()); | ||
176 | + PageData<EntityData> pageData = update.getData(); | ||
177 | + Assert.assertNotNull(pageData); | ||
178 | + Assert.assertEquals(1, pageData.getData().size()); | ||
179 | + Assert.assertEquals(device.getId(), pageData.getData().get(0).getEntityId()); | ||
180 | + Assert.assertNull(pageData.getData().get(0).getLatest().get(EntityKeyType.TIME_SERIES).get("temperature")); | ||
181 | + | ||
182 | + TsKvEntry dataPoint1 = new BasicTsKvEntry(now - TimeUnit.MINUTES.toMillis(1), new LongDataEntry("temperature", 42L)); | ||
183 | + tsService.save(device.getTenantId(), device.getId(), Arrays.asList(dataPoint1), 0).get(); | ||
184 | + | ||
185 | + cmd = new EntityDataCmd(2, edq, null, latestCmd, null); | ||
186 | + | ||
187 | + wrapper = new TelemetryPluginCmdsWrapper(); | ||
188 | + wrapper.setEntityDataCmds(Collections.singletonList(cmd)); | ||
189 | + | ||
190 | + wsClient.send(mapper.writeValueAsString(wrapper)); | ||
191 | + msg = wsClient.waitForReply(); | ||
192 | + update = mapper.readValue(msg, EntityDataUpdate.class); | ||
193 | + Assert.assertEquals(2, update.getCmdId()); | ||
194 | + pageData = update.getData(); | ||
195 | + Assert.assertNotNull(pageData); | ||
196 | + Assert.assertEquals(1, pageData.getData().size()); | ||
197 | + Assert.assertEquals(device.getId(), pageData.getData().get(0).getEntityId()); | ||
198 | + Assert.assertNotNull(pageData.getData().get(0).getLatest().get(EntityKeyType.TIME_SERIES)); | ||
199 | + TsValue tsValue = pageData.getData().get(0).getLatest().get(EntityKeyType.TIME_SERIES).get("temperature"); | ||
200 | + Assert.assertEquals(new TsValue(dataPoint1.getTs(), dataPoint1.getValueAsString()), tsValue); | ||
201 | + } | ||
202 | + | ||
145 | } | 203 | } |
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.controller.sql; | 16 | package org.thingsboard.server.controller.sql; |
17 | 17 | ||
18 | -import org.thingsboard.server.controller.BaseEntityQueryControllerTest; | ||
19 | import org.thingsboard.server.controller.BaseWebsocketApiTest; | 18 | import org.thingsboard.server.controller.BaseWebsocketApiTest; |
20 | import org.thingsboard.server.dao.service.DaoSqlTest; | 19 | import org.thingsboard.server.dao.service.DaoSqlTest; |
21 | 20 |
@@ -15,16 +15,8 @@ | @@ -15,16 +15,8 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.common.data.page; | 16 | package org.thingsboard.server.common.data.page; |
17 | 17 | ||
18 | -import com.fasterxml.jackson.annotation.JsonCreator; | ||
19 | import com.fasterxml.jackson.annotation.JsonIgnore; | 18 | import com.fasterxml.jackson.annotation.JsonIgnore; |
20 | -import com.fasterxml.jackson.annotation.JsonProperty; | ||
21 | import lombok.Data; | 19 | import lombok.Data; |
22 | -import lombok.Getter; | ||
23 | -import lombok.ToString; | ||
24 | - | ||
25 | -import java.io.Serializable; | ||
26 | -import java.util.Arrays; | ||
27 | -import java.util.UUID; | ||
28 | 20 | ||
29 | @Data | 21 | @Data |
30 | public class TimePageLink extends PageLink { | 22 | public class TimePageLink extends PageLink { |
@@ -21,8 +21,11 @@ import org.junit.Test; | @@ -21,8 +21,11 @@ import org.junit.Test; | ||
21 | import org.junit.runner.RunWith; | 21 | import org.junit.runner.RunWith; |
22 | import org.mockito.runners.MockitoJUnitRunner; | 22 | import org.mockito.runners.MockitoJUnitRunner; |
23 | 23 | ||
24 | +import java.util.ArrayList; | ||
25 | +import java.util.Arrays; | ||
24 | import java.util.Random; | 26 | import java.util.Random; |
25 | import java.util.UUID; | 27 | import java.util.UUID; |
28 | +import java.util.stream.Collectors; | ||
26 | 29 | ||
27 | /** | 30 | /** |
28 | * Created by ashvayka on 14.07.17. | 31 | * Created by ashvayka on 14.07.17. |
@@ -37,6 +40,18 @@ public class UUIDConverterTest { | @@ -37,6 +40,18 @@ public class UUIDConverterTest { | ||
37 | Assert.assertEquals("1d8eebc58e0a7d796690800200c9a66", result); | 40 | Assert.assertEquals("1d8eebc58e0a7d796690800200c9a66", result); |
38 | } | 41 | } |
39 | 42 | ||
43 | + | ||
44 | + @Test | ||
45 | + public void basicUuid() { | ||
46 | + System.out.println(UUIDConverter.fromString("1e746126eaaefa6a91992ebcb67fe33")); | ||
47 | + } | ||
48 | + | ||
49 | + @Test | ||
50 | + public void basicUuidConversion() { | ||
51 | + UUID original = UUID.fromString("3dd11790-abf2-11ea-b151-83a091b9d4cc"); | ||
52 | + Assert.assertEquals(Uuids.unixTimestamp(original), 1591886749577L); | ||
53 | + } | ||
54 | + | ||
40 | @Test | 55 | @Test |
41 | public void basicStringToUUIDTest() { | 56 | public void basicStringToUUIDTest() { |
42 | UUID result = UUIDConverter.fromString("1d8eebc58e0a7d796690800200c9a66"); | 57 | UUID result = UUIDConverter.fromString("1d8eebc58e0a7d796690800200c9a66"); |
@@ -27,7 +27,13 @@ import org.thingsboard.server.common.data.page.PageLink; | @@ -27,7 +27,13 @@ import org.thingsboard.server.common.data.page.PageLink; | ||
27 | import org.thingsboard.server.common.data.page.SortOrder; | 27 | import org.thingsboard.server.common.data.page.SortOrder; |
28 | import org.thingsboard.server.dao.model.ToData; | 28 | import org.thingsboard.server.dao.model.ToData; |
29 | 29 | ||
30 | -import java.util.*; | 30 | +import java.util.ArrayList; |
31 | +import java.util.Collection; | ||
32 | +import java.util.Collections; | ||
33 | +import java.util.List; | ||
34 | +import java.util.Map; | ||
35 | +import java.util.Optional; | ||
36 | +import java.util.UUID; | ||
31 | 37 | ||
32 | public abstract class DaoUtil { | 38 | public abstract class DaoUtil { |
33 | 39 | ||
@@ -77,9 +83,6 @@ public abstract class DaoUtil { | @@ -77,9 +83,6 @@ public abstract class DaoUtil { | ||
77 | if (columnMap.containsKey(property)) { | 83 | if (columnMap.containsKey(property)) { |
78 | property = columnMap.get(property); | 84 | property = columnMap.get(property); |
79 | } | 85 | } |
80 | - if (property.equals("createdTime")) { | ||
81 | - property = "id"; | ||
82 | - } | ||
83 | return Sort.by(Sort.Direction.fromString(sortOrder.getDirection().name()), property); | 86 | return Sort.by(Sort.Direction.fromString(sortOrder.getDirection().name()), property); |
84 | } | 87 | } |
85 | } | 88 | } |
@@ -24,7 +24,6 @@ import org.thingsboard.server.common.data.id.TenantId; | @@ -24,7 +24,6 @@ import org.thingsboard.server.common.data.id.TenantId; | ||
24 | import org.thingsboard.server.common.data.page.PageData; | 24 | import org.thingsboard.server.common.data.page.PageData; |
25 | import org.thingsboard.server.dao.Dao; | 25 | import org.thingsboard.server.dao.Dao; |
26 | 26 | ||
27 | -import java.util.List; | ||
28 | import java.util.UUID; | 27 | import java.util.UUID; |
29 | 28 | ||
30 | /** | 29 | /** |
@@ -29,12 +29,12 @@ import org.springframework.util.StringUtils; | @@ -29,12 +29,12 @@ import org.springframework.util.StringUtils; | ||
29 | import org.thingsboard.common.util.ThingsBoardThreadFactory; | 29 | import org.thingsboard.common.util.ThingsBoardThreadFactory; |
30 | import org.thingsboard.server.common.data.Tenant; | 30 | import org.thingsboard.server.common.data.Tenant; |
31 | import org.thingsboard.server.common.data.alarm.Alarm; | 31 | import org.thingsboard.server.common.data.alarm.Alarm; |
32 | -import org.thingsboard.server.common.data.id.AlarmId; | ||
33 | import org.thingsboard.server.common.data.alarm.AlarmInfo; | 32 | import org.thingsboard.server.common.data.alarm.AlarmInfo; |
34 | import org.thingsboard.server.common.data.alarm.AlarmQuery; | 33 | import org.thingsboard.server.common.data.alarm.AlarmQuery; |
35 | import org.thingsboard.server.common.data.alarm.AlarmSearchStatus; | 34 | import org.thingsboard.server.common.data.alarm.AlarmSearchStatus; |
36 | import org.thingsboard.server.common.data.alarm.AlarmSeverity; | 35 | import org.thingsboard.server.common.data.alarm.AlarmSeverity; |
37 | import org.thingsboard.server.common.data.alarm.AlarmStatus; | 36 | import org.thingsboard.server.common.data.alarm.AlarmStatus; |
37 | +import org.thingsboard.server.common.data.id.AlarmId; | ||
38 | import org.thingsboard.server.common.data.id.EntityId; | 38 | import org.thingsboard.server.common.data.id.EntityId; |
39 | import org.thingsboard.server.common.data.id.TenantId; | 39 | import org.thingsboard.server.common.data.id.TenantId; |
40 | import org.thingsboard.server.common.data.page.PageData; | 40 | import org.thingsboard.server.common.data.page.PageData; |
@@ -28,7 +28,6 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -28,7 +28,6 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
28 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | 28 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
29 | import org.springframework.stereotype.Service; | 29 | import org.springframework.stereotype.Service; |
30 | import org.springframework.util.StringUtils; | 30 | import org.springframework.util.StringUtils; |
31 | -import org.thingsboard.server.common.data.BaseData; | ||
32 | import org.thingsboard.server.common.data.EntityType; | 31 | import org.thingsboard.server.common.data.EntityType; |
33 | import org.thingsboard.server.common.data.HasName; | 32 | import org.thingsboard.server.common.data.HasName; |
34 | import org.thingsboard.server.common.data.audit.ActionStatus; | 33 | import org.thingsboard.server.common.data.audit.ActionStatus; |
@@ -38,7 +37,6 @@ import org.thingsboard.server.common.data.id.AuditLogId; | @@ -38,7 +37,6 @@ import org.thingsboard.server.common.data.id.AuditLogId; | ||
38 | import org.thingsboard.server.common.data.id.CustomerId; | 37 | import org.thingsboard.server.common.data.id.CustomerId; |
39 | import org.thingsboard.server.common.data.id.EntityId; | 38 | import org.thingsboard.server.common.data.id.EntityId; |
40 | import org.thingsboard.server.common.data.id.TenantId; | 39 | import org.thingsboard.server.common.data.id.TenantId; |
41 | -import org.thingsboard.server.common.data.id.UUIDBased; | ||
42 | import org.thingsboard.server.common.data.id.UserId; | 40 | import org.thingsboard.server.common.data.id.UserId; |
43 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; | 41 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
44 | import org.thingsboard.server.common.data.page.PageData; | 42 | import org.thingsboard.server.common.data.page.PageData; |
@@ -18,14 +18,12 @@ package org.thingsboard.server.dao.audit; | @@ -18,14 +18,12 @@ package org.thingsboard.server.dao.audit; | ||
18 | import com.google.common.util.concurrent.ListenableFuture; | 18 | import com.google.common.util.concurrent.ListenableFuture; |
19 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | 19 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
20 | import org.springframework.stereotype.Service; | 20 | import org.springframework.stereotype.Service; |
21 | -import org.thingsboard.server.common.data.BaseData; | ||
22 | import org.thingsboard.server.common.data.HasName; | 21 | import org.thingsboard.server.common.data.HasName; |
23 | import org.thingsboard.server.common.data.audit.ActionType; | 22 | import org.thingsboard.server.common.data.audit.ActionType; |
24 | import org.thingsboard.server.common.data.audit.AuditLog; | 23 | import org.thingsboard.server.common.data.audit.AuditLog; |
25 | import org.thingsboard.server.common.data.id.CustomerId; | 24 | import org.thingsboard.server.common.data.id.CustomerId; |
26 | import org.thingsboard.server.common.data.id.EntityId; | 25 | import org.thingsboard.server.common.data.id.EntityId; |
27 | import org.thingsboard.server.common.data.id.TenantId; | 26 | import org.thingsboard.server.common.data.id.TenantId; |
28 | -import org.thingsboard.server.common.data.id.UUIDBased; | ||
29 | import org.thingsboard.server.common.data.id.UserId; | 27 | import org.thingsboard.server.common.data.id.UserId; |
30 | import org.thingsboard.server.common.data.page.PageData; | 28 | import org.thingsboard.server.common.data.page.PageData; |
31 | import org.thingsboard.server.common.data.page.TimePageLink; | 29 | import org.thingsboard.server.common.data.page.TimePageLink; |
@@ -37,7 +37,6 @@ import org.thingsboard.server.dao.exception.IncorrectParameterException; | @@ -37,7 +37,6 @@ import org.thingsboard.server.dao.exception.IncorrectParameterException; | ||
37 | import org.thingsboard.server.dao.service.DataValidator; | 37 | import org.thingsboard.server.dao.service.DataValidator; |
38 | import org.thingsboard.server.dao.service.Validator; | 38 | import org.thingsboard.server.dao.service.Validator; |
39 | 39 | ||
40 | -import java.util.List; | ||
41 | import java.util.Optional; | 40 | import java.util.Optional; |
42 | 41 | ||
43 | /** | 42 | /** |
@@ -24,7 +24,6 @@ import org.thingsboard.server.common.data.plugin.ComponentScope; | @@ -24,7 +24,6 @@ import org.thingsboard.server.common.data.plugin.ComponentScope; | ||
24 | import org.thingsboard.server.common.data.plugin.ComponentType; | 24 | import org.thingsboard.server.common.data.plugin.ComponentType; |
25 | import org.thingsboard.server.dao.Dao; | 25 | import org.thingsboard.server.dao.Dao; |
26 | 26 | ||
27 | -import java.util.List; | ||
28 | import java.util.Optional; | 27 | import java.util.Optional; |
29 | 28 | ||
30 | /** | 29 | /** |
@@ -21,7 +21,6 @@ import org.thingsboard.server.common.data.page.PageData; | @@ -21,7 +21,6 @@ import org.thingsboard.server.common.data.page.PageData; | ||
21 | import org.thingsboard.server.common.data.page.PageLink; | 21 | import org.thingsboard.server.common.data.page.PageLink; |
22 | import org.thingsboard.server.dao.Dao; | 22 | import org.thingsboard.server.dao.Dao; |
23 | 23 | ||
24 | -import java.util.List; | ||
25 | import java.util.Optional; | 24 | import java.util.Optional; |
26 | import java.util.UUID; | 25 | import java.util.UUID; |
27 | 26 |
@@ -42,7 +42,6 @@ import org.thingsboard.server.dao.tenant.TenantDao; | @@ -42,7 +42,6 @@ import org.thingsboard.server.dao.tenant.TenantDao; | ||
42 | import org.thingsboard.server.dao.user.UserService; | 42 | import org.thingsboard.server.dao.user.UserService; |
43 | 43 | ||
44 | import java.io.IOException; | 44 | import java.io.IOException; |
45 | -import java.util.List; | ||
46 | import java.util.Optional; | 45 | import java.util.Optional; |
47 | 46 | ||
48 | import static org.thingsboard.server.dao.service.Validator.validateId; | 47 | import static org.thingsboard.server.dao.service.Validator.validateId; |
@@ -15,14 +15,11 @@ | @@ -15,14 +15,11 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.dashboard; | 16 | package org.thingsboard.server.dao.dashboard; |
17 | 17 | ||
18 | -import com.google.common.util.concurrent.ListenableFuture; | ||
19 | import org.thingsboard.server.common.data.DashboardInfo; | 18 | import org.thingsboard.server.common.data.DashboardInfo; |
20 | import org.thingsboard.server.common.data.page.PageData; | 19 | import org.thingsboard.server.common.data.page.PageData; |
21 | import org.thingsboard.server.common.data.page.PageLink; | 20 | import org.thingsboard.server.common.data.page.PageLink; |
22 | -import org.thingsboard.server.common.data.page.TimePageLink; | ||
23 | import org.thingsboard.server.dao.Dao; | 21 | import org.thingsboard.server.dao.Dao; |
24 | 22 | ||
25 | -import java.util.List; | ||
26 | import java.util.UUID; | 23 | import java.util.UUID; |
27 | 24 | ||
28 | /** | 25 | /** |
@@ -29,7 +29,12 @@ import org.springframework.cache.annotation.CacheEvict; | @@ -29,7 +29,12 @@ import org.springframework.cache.annotation.CacheEvict; | ||
29 | import org.springframework.cache.annotation.Cacheable; | 29 | import org.springframework.cache.annotation.Cacheable; |
30 | import org.springframework.cache.annotation.Caching; | 30 | import org.springframework.cache.annotation.Caching; |
31 | import org.springframework.stereotype.Service; | 31 | import org.springframework.stereotype.Service; |
32 | -import org.thingsboard.server.common.data.*; | 32 | +import org.thingsboard.server.common.data.Customer; |
33 | +import org.thingsboard.server.common.data.EntitySubtype; | ||
34 | +import org.thingsboard.server.common.data.EntityType; | ||
35 | +import org.thingsboard.server.common.data.EntityView; | ||
36 | +import org.thingsboard.server.common.data.EntityViewInfo; | ||
37 | +import org.thingsboard.server.common.data.Tenant; | ||
33 | import org.thingsboard.server.common.data.entityview.EntityViewSearchQuery; | 38 | import org.thingsboard.server.common.data.entityview.EntityViewSearchQuery; |
34 | import org.thingsboard.server.common.data.id.CustomerId; | 39 | import org.thingsboard.server.common.data.id.CustomerId; |
35 | import org.thingsboard.server.common.data.id.EntityId; | 40 | import org.thingsboard.server.common.data.id.EntityId; |
@@ -16,7 +16,6 @@ | @@ -16,7 +16,6 @@ | ||
16 | package org.thingsboard.server.dao.model; | 16 | package org.thingsboard.server.dao.model; |
17 | 17 | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | -import org.thingsboard.server.common.data.UUIDConverter; | ||
20 | 19 | ||
21 | import javax.persistence.Column; | 20 | import javax.persistence.Column; |
22 | import javax.persistence.Id; | 21 | import javax.persistence.Id; |
@@ -31,28 +30,30 @@ import java.util.UUID; | @@ -31,28 +30,30 @@ import java.util.UUID; | ||
31 | public abstract class BaseSqlEntity<D> implements BaseEntity<D> { | 30 | public abstract class BaseSqlEntity<D> implements BaseEntity<D> { |
32 | 31 | ||
33 | @Id | 32 | @Id |
34 | - @Column(name = ModelConstants.ID_PROPERTY) | ||
35 | - protected String id; | 33 | + @Column(name = ModelConstants.ID_PROPERTY, columnDefinition = "uuid") |
34 | + protected UUID id; | ||
35 | + | ||
36 | + @Column(name = ModelConstants.CREATED_TIME_PROPERTY) | ||
37 | + protected long createdTime; | ||
36 | 38 | ||
37 | @Override | 39 | @Override |
38 | public UUID getUuid() { | 40 | public UUID getUuid() { |
39 | - if (id == null) { | ||
40 | - return null; | ||
41 | - } | ||
42 | - return UUIDConverter.fromString(id); | 41 | + return id; |
43 | } | 42 | } |
44 | 43 | ||
45 | @Override | 44 | @Override |
46 | public void setUuid(UUID id) { | 45 | public void setUuid(UUID id) { |
47 | - this.id = UUIDConverter.fromTimeUUID(id); | 46 | + this.id = id; |
48 | } | 47 | } |
49 | 48 | ||
50 | - protected UUID toUUID(String src){ | ||
51 | - return UUIDConverter.fromString(src); | 49 | + @Override |
50 | + public long getCreatedTime() { | ||
51 | + return createdTime; | ||
52 | } | 52 | } |
53 | 53 | ||
54 | - protected String toString(UUID timeUUID){ | ||
55 | - return UUIDConverter.fromTimeUUID(timeUUID); | 54 | + public void setCreatedTime(long createdTime) { |
55 | + if (createdTime > 0) { | ||
56 | + this.createdTime = createdTime; | ||
57 | + } | ||
56 | } | 58 | } |
57 | - | ||
58 | } | 59 | } |
@@ -17,7 +17,6 @@ package org.thingsboard.server.dao.model; | @@ -17,7 +17,6 @@ package org.thingsboard.server.dao.model; | ||
17 | 17 | ||
18 | import com.datastax.oss.driver.api.core.uuid.Uuids; | 18 | import com.datastax.oss.driver.api.core.uuid.Uuids; |
19 | import org.apache.commons.lang3.ArrayUtils; | 19 | import org.apache.commons.lang3.ArrayUtils; |
20 | -import org.thingsboard.server.common.data.UUIDConverter; | ||
21 | import org.thingsboard.server.common.data.id.TenantId; | 20 | import org.thingsboard.server.common.data.id.TenantId; |
22 | import org.thingsboard.server.common.data.kv.Aggregation; | 21 | import org.thingsboard.server.common.data.kv.Aggregation; |
23 | 22 | ||
@@ -29,7 +28,6 @@ public class ModelConstants { | @@ -29,7 +28,6 @@ public class ModelConstants { | ||
29 | } | 28 | } |
30 | 29 | ||
31 | public static final UUID NULL_UUID = Uuids.startOf(0); | 30 | public static final UUID NULL_UUID = Uuids.startOf(0); |
32 | - public static final String NULL_UUID_STR = UUIDConverter.fromTimeUUID(NULL_UUID); | ||
33 | public static final TenantId SYSTEM_TENANT = new TenantId(ModelConstants.NULL_UUID); | 31 | public static final TenantId SYSTEM_TENANT = new TenantId(ModelConstants.NULL_UUID); |
34 | 32 | ||
35 | // this is the difference between midnight October 15, 1582 UTC and midnight January 1, 1970 UTC as 100 nanosecond units | 33 | // this is the difference between midnight October 15, 1582 UTC and midnight January 1, 1970 UTC as 100 nanosecond units |
@@ -39,6 +37,7 @@ public class ModelConstants { | @@ -39,6 +37,7 @@ public class ModelConstants { | ||
39 | * Generic constants. | 37 | * Generic constants. |
40 | */ | 38 | */ |
41 | public static final String ID_PROPERTY = "id"; | 39 | public static final String ID_PROPERTY = "id"; |
40 | + public static final String CREATED_TIME_PROPERTY = "created_time"; | ||
42 | public static final String USER_ID_PROPERTY = "user_id"; | 41 | public static final String USER_ID_PROPERTY = "user_id"; |
43 | public static final String TENANT_ID_PROPERTY = "tenant_id"; | 42 | public static final String TENANT_ID_PROPERTY = "tenant_id"; |
44 | public static final String CUSTOMER_ID_PROPERTY = "customer_id"; | 43 | public static final String CUSTOMER_ID_PROPERTY = "customer_id"; |
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.sql; | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | ||
18 | -import com.datastax.oss.driver.api.core.uuid.Uuids; | ||
19 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 19 | import lombok.Data; |
21 | import lombok.EqualsAndHashCode; | 20 | import lombok.EqualsAndHashCode; |
@@ -24,11 +23,10 @@ import org.hibernate.annotations.TypeDef; | @@ -24,11 +23,10 @@ import org.hibernate.annotations.TypeDef; | ||
24 | import org.springframework.util.CollectionUtils; | 23 | import org.springframework.util.CollectionUtils; |
25 | import org.springframework.util.StringUtils; | 24 | import org.springframework.util.StringUtils; |
26 | import org.thingsboard.server.common.data.EntityType; | 25 | import org.thingsboard.server.common.data.EntityType; |
27 | -import org.thingsboard.server.common.data.UUIDConverter; | ||
28 | import org.thingsboard.server.common.data.alarm.Alarm; | 26 | import org.thingsboard.server.common.data.alarm.Alarm; |
29 | -import org.thingsboard.server.common.data.id.AlarmId; | ||
30 | import org.thingsboard.server.common.data.alarm.AlarmSeverity; | 27 | import org.thingsboard.server.common.data.alarm.AlarmSeverity; |
31 | import org.thingsboard.server.common.data.alarm.AlarmStatus; | 28 | import org.thingsboard.server.common.data.alarm.AlarmStatus; |
29 | +import org.thingsboard.server.common.data.id.AlarmId; | ||
32 | import org.thingsboard.server.common.data.id.EntityIdFactory; | 30 | import org.thingsboard.server.common.data.id.EntityIdFactory; |
33 | import org.thingsboard.server.common.data.id.TenantId; | 31 | import org.thingsboard.server.common.data.id.TenantId; |
34 | import org.thingsboard.server.dao.model.BaseEntity; | 32 | import org.thingsboard.server.dao.model.BaseEntity; |
@@ -42,6 +40,7 @@ import javax.persistence.Enumerated; | @@ -42,6 +40,7 @@ import javax.persistence.Enumerated; | ||
42 | import javax.persistence.MappedSuperclass; | 40 | import javax.persistence.MappedSuperclass; |
43 | import java.util.Arrays; | 41 | import java.util.Arrays; |
44 | import java.util.Collections; | 42 | import java.util.Collections; |
43 | +import java.util.UUID; | ||
45 | 44 | ||
46 | import static org.thingsboard.server.dao.model.ModelConstants.ALARM_ACK_TS_PROPERTY; | 45 | import static org.thingsboard.server.dao.model.ModelConstants.ALARM_ACK_TS_PROPERTY; |
47 | import static org.thingsboard.server.dao.model.ModelConstants.ALARM_CLEAR_TS_PROPERTY; | 46 | import static org.thingsboard.server.dao.model.ModelConstants.ALARM_CLEAR_TS_PROPERTY; |
@@ -63,10 +62,10 @@ import static org.thingsboard.server.dao.model.ModelConstants.ALARM_TYPE_PROPERT | @@ -63,10 +62,10 @@ import static org.thingsboard.server.dao.model.ModelConstants.ALARM_TYPE_PROPERT | ||
63 | public abstract class AbstractAlarmEntity<T extends Alarm> extends BaseSqlEntity<T> implements BaseEntity<T> { | 62 | public abstract class AbstractAlarmEntity<T extends Alarm> extends BaseSqlEntity<T> implements BaseEntity<T> { |
64 | 63 | ||
65 | @Column(name = ALARM_TENANT_ID_PROPERTY) | 64 | @Column(name = ALARM_TENANT_ID_PROPERTY) |
66 | - private String tenantId; | 65 | + private UUID tenantId; |
67 | 66 | ||
68 | @Column(name = ALARM_ORIGINATOR_ID_PROPERTY) | 67 | @Column(name = ALARM_ORIGINATOR_ID_PROPERTY) |
69 | - private String originatorId; | 68 | + private UUID originatorId; |
70 | 69 | ||
71 | @Column(name = ALARM_ORIGINATOR_TYPE_PROPERTY) | 70 | @Column(name = ALARM_ORIGINATOR_TYPE_PROPERTY) |
72 | private EntityType originatorType; | 71 | private EntityType originatorType; |
@@ -110,13 +109,14 @@ public abstract class AbstractAlarmEntity<T extends Alarm> extends BaseSqlEntity | @@ -110,13 +109,14 @@ public abstract class AbstractAlarmEntity<T extends Alarm> extends BaseSqlEntity | ||
110 | 109 | ||
111 | public AbstractAlarmEntity(Alarm alarm) { | 110 | public AbstractAlarmEntity(Alarm alarm) { |
112 | if (alarm.getId() != null) { | 111 | if (alarm.getId() != null) { |
113 | - this.setUuid(alarm.getId().getId()); | 112 | + this.setUuid(alarm.getUuidId()); |
114 | } | 113 | } |
114 | + this.setCreatedTime(alarm.getCreatedTime()); | ||
115 | if (alarm.getTenantId() != null) { | 115 | if (alarm.getTenantId() != null) { |
116 | - this.tenantId = UUIDConverter.fromTimeUUID(alarm.getTenantId().getId()); | 116 | + this.tenantId = alarm.getTenantId().getId(); |
117 | } | 117 | } |
118 | this.type = alarm.getType(); | 118 | this.type = alarm.getType(); |
119 | - this.originatorId = UUIDConverter.fromTimeUUID(alarm.getOriginator().getId()); | 119 | + this.originatorId = alarm.getOriginator().getId(); |
120 | this.originatorType = alarm.getOriginator().getEntityType(); | 120 | this.originatorType = alarm.getOriginator().getEntityType(); |
121 | this.type = alarm.getType(); | 121 | this.type = alarm.getType(); |
122 | this.severity = alarm.getSeverity(); | 122 | this.severity = alarm.getSeverity(); |
@@ -153,12 +153,12 @@ public abstract class AbstractAlarmEntity<T extends Alarm> extends BaseSqlEntity | @@ -153,12 +153,12 @@ public abstract class AbstractAlarmEntity<T extends Alarm> extends BaseSqlEntity | ||
153 | } | 153 | } |
154 | 154 | ||
155 | protected Alarm toAlarm() { | 155 | protected Alarm toAlarm() { |
156 | - Alarm alarm = new Alarm(new AlarmId(UUIDConverter.fromString(id))); | ||
157 | - alarm.setCreatedTime(Uuids.unixTimestamp(UUIDConverter.fromString(id))); | 156 | + Alarm alarm = new Alarm(new AlarmId(id)); |
157 | + alarm.setCreatedTime(createdTime); | ||
158 | if (tenantId != null) { | 158 | if (tenantId != null) { |
159 | - alarm.setTenantId(new TenantId(UUIDConverter.fromString(tenantId))); | 159 | + alarm.setTenantId(new TenantId(tenantId)); |
160 | } | 160 | } |
161 | - alarm.setOriginator(EntityIdFactory.getByTypeAndUuid(originatorType, UUIDConverter.fromString(originatorId))); | 161 | + alarm.setOriginator(EntityIdFactory.getByTypeAndUuid(originatorType, originatorId)); |
162 | alarm.setType(type); | 162 | alarm.setType(type); |
163 | alarm.setSeverity(severity); | 163 | alarm.setSeverity(severity); |
164 | alarm.setStatus(status); | 164 | alarm.setStatus(status); |
@@ -15,13 +15,11 @@ | @@ -15,13 +15,11 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.sql; | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | ||
18 | -import com.datastax.oss.driver.api.core.uuid.Uuids; | ||
19 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 19 | import lombok.Data; |
21 | import lombok.EqualsAndHashCode; | 20 | import lombok.EqualsAndHashCode; |
22 | import org.hibernate.annotations.Type; | 21 | import org.hibernate.annotations.Type; |
23 | import org.hibernate.annotations.TypeDef; | 22 | import org.hibernate.annotations.TypeDef; |
24 | -import org.thingsboard.server.common.data.UUIDConverter; | ||
25 | import org.thingsboard.server.common.data.asset.Asset; | 23 | import org.thingsboard.server.common.data.asset.Asset; |
26 | import org.thingsboard.server.common.data.id.AssetId; | 24 | import org.thingsboard.server.common.data.id.AssetId; |
27 | import org.thingsboard.server.common.data.id.CustomerId; | 25 | import org.thingsboard.server.common.data.id.CustomerId; |
@@ -33,6 +31,7 @@ import org.thingsboard.server.dao.util.mapping.JsonStringType; | @@ -33,6 +31,7 @@ import org.thingsboard.server.dao.util.mapping.JsonStringType; | ||
33 | 31 | ||
34 | import javax.persistence.Column; | 32 | import javax.persistence.Column; |
35 | import javax.persistence.MappedSuperclass; | 33 | import javax.persistence.MappedSuperclass; |
34 | +import java.util.UUID; | ||
36 | 35 | ||
37 | import static org.thingsboard.server.dao.model.ModelConstants.ASSET_CUSTOMER_ID_PROPERTY; | 36 | import static org.thingsboard.server.dao.model.ModelConstants.ASSET_CUSTOMER_ID_PROPERTY; |
38 | import static org.thingsboard.server.dao.model.ModelConstants.ASSET_LABEL_PROPERTY; | 37 | import static org.thingsboard.server.dao.model.ModelConstants.ASSET_LABEL_PROPERTY; |
@@ -48,10 +47,10 @@ import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPER | @@ -48,10 +47,10 @@ import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPER | ||
48 | public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity<T> implements SearchTextEntity<T> { | 47 | public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity<T> implements SearchTextEntity<T> { |
49 | 48 | ||
50 | @Column(name = ASSET_TENANT_ID_PROPERTY) | 49 | @Column(name = ASSET_TENANT_ID_PROPERTY) |
51 | - private String tenantId; | 50 | + private UUID tenantId; |
52 | 51 | ||
53 | @Column(name = ASSET_CUSTOMER_ID_PROPERTY) | 52 | @Column(name = ASSET_CUSTOMER_ID_PROPERTY) |
54 | - private String customerId; | 53 | + private UUID customerId; |
55 | 54 | ||
56 | @Column(name = ASSET_NAME_PROPERTY) | 55 | @Column(name = ASSET_NAME_PROPERTY) |
57 | private String name; | 56 | private String name; |
@@ -77,11 +76,12 @@ public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity | @@ -77,11 +76,12 @@ public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity | ||
77 | if (asset.getId() != null) { | 76 | if (asset.getId() != null) { |
78 | this.setUuid(asset.getId().getId()); | 77 | this.setUuid(asset.getId().getId()); |
79 | } | 78 | } |
79 | + this.setCreatedTime(asset.getCreatedTime()); | ||
80 | if (asset.getTenantId() != null) { | 80 | if (asset.getTenantId() != null) { |
81 | - this.tenantId = UUIDConverter.fromTimeUUID(asset.getTenantId().getId()); | 81 | + this.tenantId = asset.getTenantId().getId(); |
82 | } | 82 | } |
83 | if (asset.getCustomerId() != null) { | 83 | if (asset.getCustomerId() != null) { |
84 | - this.customerId = UUIDConverter.fromTimeUUID(asset.getCustomerId().getId()); | 84 | + this.customerId = asset.getCustomerId().getId(); |
85 | } | 85 | } |
86 | this.name = asset.getName(); | 86 | this.name = asset.getName(); |
87 | this.type = asset.getType(); | 87 | this.type = asset.getType(); |
@@ -91,6 +91,7 @@ public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity | @@ -91,6 +91,7 @@ public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity | ||
91 | 91 | ||
92 | public AbstractAssetEntity(AssetEntity assetEntity) { | 92 | public AbstractAssetEntity(AssetEntity assetEntity) { |
93 | this.setId(assetEntity.getId()); | 93 | this.setId(assetEntity.getId()); |
94 | + this.setCreatedTime(assetEntity.getCreatedTime()); | ||
94 | this.tenantId = assetEntity.getTenantId(); | 95 | this.tenantId = assetEntity.getTenantId(); |
95 | this.customerId = assetEntity.getCustomerId(); | 96 | this.customerId = assetEntity.getCustomerId(); |
96 | this.type = assetEntity.getType(); | 97 | this.type = assetEntity.getType(); |
@@ -115,13 +116,13 @@ public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity | @@ -115,13 +116,13 @@ public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity | ||
115 | } | 116 | } |
116 | 117 | ||
117 | protected Asset toAsset() { | 118 | protected Asset toAsset() { |
118 | - Asset asset = new Asset(new AssetId(UUIDConverter.fromString(id))); | ||
119 | - asset.setCreatedTime(Uuids.unixTimestamp(UUIDConverter.fromString(id))); | 119 | + Asset asset = new Asset(new AssetId(id)); |
120 | + asset.setCreatedTime(createdTime); | ||
120 | if (tenantId != null) { | 121 | if (tenantId != null) { |
121 | - asset.setTenantId(new TenantId(UUIDConverter.fromString(tenantId))); | 122 | + asset.setTenantId(new TenantId(tenantId)); |
122 | } | 123 | } |
123 | if (customerId != null) { | 124 | if (customerId != null) { |
124 | - asset.setCustomerId(new CustomerId(UUIDConverter.fromString(customerId))); | 125 | + asset.setCustomerId(new CustomerId(customerId)); |
125 | } | 126 | } |
126 | asset.setName(name); | 127 | asset.setName(name); |
127 | asset.setType(type); | 128 | asset.setType(type); |
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.sql; | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | ||
18 | -import com.datastax.oss.driver.api.core.uuid.Uuids; | ||
19 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 19 | import lombok.Data; |
21 | import lombok.EqualsAndHashCode; | 20 | import lombok.EqualsAndHashCode; |
@@ -32,6 +31,7 @@ import org.thingsboard.server.dao.util.mapping.JsonStringType; | @@ -32,6 +31,7 @@ import org.thingsboard.server.dao.util.mapping.JsonStringType; | ||
32 | 31 | ||
33 | import javax.persistence.Column; | 32 | import javax.persistence.Column; |
34 | import javax.persistence.MappedSuperclass; | 33 | import javax.persistence.MappedSuperclass; |
34 | +import java.util.UUID; | ||
35 | 35 | ||
36 | @Data | 36 | @Data |
37 | @EqualsAndHashCode(callSuper = true) | 37 | @EqualsAndHashCode(callSuper = true) |
@@ -39,11 +39,11 @@ import javax.persistence.MappedSuperclass; | @@ -39,11 +39,11 @@ import javax.persistence.MappedSuperclass; | ||
39 | @MappedSuperclass | 39 | @MappedSuperclass |
40 | public abstract class AbstractDeviceEntity<T extends Device> extends BaseSqlEntity<T> implements SearchTextEntity<T> { | 40 | public abstract class AbstractDeviceEntity<T extends Device> extends BaseSqlEntity<T> implements SearchTextEntity<T> { |
41 | 41 | ||
42 | - @Column(name = ModelConstants.DEVICE_TENANT_ID_PROPERTY) | ||
43 | - private String tenantId; | 42 | + @Column(name = ModelConstants.DEVICE_TENANT_ID_PROPERTY, columnDefinition = "uuid") |
43 | + private UUID tenantId; | ||
44 | 44 | ||
45 | - @Column(name = ModelConstants.DEVICE_CUSTOMER_ID_PROPERTY) | ||
46 | - private String customerId; | 45 | + @Column(name = ModelConstants.DEVICE_CUSTOMER_ID_PROPERTY, columnDefinition = "uuid") |
46 | + private UUID customerId; | ||
47 | 47 | ||
48 | @Column(name = ModelConstants.DEVICE_TYPE_PROPERTY) | 48 | @Column(name = ModelConstants.DEVICE_TYPE_PROPERTY) |
49 | private String type; | 49 | private String type; |
@@ -67,13 +67,14 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseSqlEnti | @@ -67,13 +67,14 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseSqlEnti | ||
67 | 67 | ||
68 | public AbstractDeviceEntity(Device device) { | 68 | public AbstractDeviceEntity(Device device) { |
69 | if (device.getId() != null) { | 69 | if (device.getId() != null) { |
70 | - this.setUuid(device.getId().getId()); | 70 | + this.setUuid(device.getUuidId()); |
71 | } | 71 | } |
72 | + this.setCreatedTime(device.getCreatedTime()); | ||
72 | if (device.getTenantId() != null) { | 73 | if (device.getTenantId() != null) { |
73 | - this.tenantId = toString(device.getTenantId().getId()); | 74 | + this.tenantId = device.getTenantId().getId(); |
74 | } | 75 | } |
75 | if (device.getCustomerId() != null) { | 76 | if (device.getCustomerId() != null) { |
76 | - this.customerId = toString(device.getCustomerId().getId()); | 77 | + this.customerId = device.getCustomerId().getId(); |
77 | } | 78 | } |
78 | this.name = device.getName(); | 79 | this.name = device.getName(); |
79 | this.type = device.getType(); | 80 | this.type = device.getType(); |
@@ -83,6 +84,7 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseSqlEnti | @@ -83,6 +84,7 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseSqlEnti | ||
83 | 84 | ||
84 | public AbstractDeviceEntity(DeviceEntity deviceEntity) { | 85 | public AbstractDeviceEntity(DeviceEntity deviceEntity) { |
85 | this.setId(deviceEntity.getId()); | 86 | this.setId(deviceEntity.getId()); |
87 | + this.setCreatedTime(deviceEntity.getCreatedTime()); | ||
86 | this.tenantId = deviceEntity.getTenantId(); | 88 | this.tenantId = deviceEntity.getTenantId(); |
87 | this.customerId = deviceEntity.getCustomerId(); | 89 | this.customerId = deviceEntity.getCustomerId(); |
88 | this.type = deviceEntity.getType(); | 90 | this.type = deviceEntity.getType(); |
@@ -104,12 +106,12 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseSqlEnti | @@ -104,12 +106,12 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseSqlEnti | ||
104 | 106 | ||
105 | protected Device toDevice() { | 107 | protected Device toDevice() { |
106 | Device device = new Device(new DeviceId(getUuid())); | 108 | Device device = new Device(new DeviceId(getUuid())); |
107 | - device.setCreatedTime(Uuids.unixTimestamp(getUuid())); | 109 | + device.setCreatedTime(createdTime); |
108 | if (tenantId != null) { | 110 | if (tenantId != null) { |
109 | - device.setTenantId(new TenantId(toUUID(tenantId))); | 111 | + device.setTenantId(new TenantId(tenantId)); |
110 | } | 112 | } |
111 | if (customerId != null) { | 113 | if (customerId != null) { |
112 | - device.setCustomerId(new CustomerId(toUUID(customerId))); | 114 | + device.setCustomerId(new CustomerId(customerId)); |
113 | } | 115 | } |
114 | device.setName(name); | 116 | device.setName(name); |
115 | device.setType(type); | 117 | device.setType(type); |
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.sql; | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | ||
18 | -import com.datastax.oss.driver.api.core.uuid.Uuids; | ||
19 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import com.fasterxml.jackson.databind.ObjectMapper; | 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
21 | import lombok.Data; | 20 | import lombok.Data; |
@@ -35,7 +34,10 @@ import org.thingsboard.server.dao.model.ModelConstants; | @@ -35,7 +34,10 @@ import org.thingsboard.server.dao.model.ModelConstants; | ||
35 | import org.thingsboard.server.dao.model.SearchTextEntity; | 34 | import org.thingsboard.server.dao.model.SearchTextEntity; |
36 | import org.thingsboard.server.dao.util.mapping.JsonStringType; | 35 | import org.thingsboard.server.dao.util.mapping.JsonStringType; |
37 | 36 | ||
38 | -import javax.persistence.*; | 37 | +import javax.persistence.Column; |
38 | +import javax.persistence.EnumType; | ||
39 | +import javax.persistence.Enumerated; | ||
40 | +import javax.persistence.MappedSuperclass; | ||
39 | import java.io.IOException; | 41 | import java.io.IOException; |
40 | import java.util.UUID; | 42 | import java.util.UUID; |
41 | 43 | ||
@@ -53,17 +55,17 @@ import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_TYPE_PROPER | @@ -53,17 +55,17 @@ import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_TYPE_PROPER | ||
53 | public abstract class AbstractEntityViewEntity<T extends EntityView> extends BaseSqlEntity<T> implements SearchTextEntity<T> { | 55 | public abstract class AbstractEntityViewEntity<T extends EntityView> extends BaseSqlEntity<T> implements SearchTextEntity<T> { |
54 | 56 | ||
55 | @Column(name = ModelConstants.ENTITY_VIEW_ENTITY_ID_PROPERTY) | 57 | @Column(name = ModelConstants.ENTITY_VIEW_ENTITY_ID_PROPERTY) |
56 | - private String entityId; | 58 | + private UUID entityId; |
57 | 59 | ||
58 | @Enumerated(EnumType.STRING) | 60 | @Enumerated(EnumType.STRING) |
59 | @Column(name = ENTITY_TYPE_PROPERTY) | 61 | @Column(name = ENTITY_TYPE_PROPERTY) |
60 | private EntityType entityType; | 62 | private EntityType entityType; |
61 | 63 | ||
62 | @Column(name = ModelConstants.ENTITY_VIEW_TENANT_ID_PROPERTY) | 64 | @Column(name = ModelConstants.ENTITY_VIEW_TENANT_ID_PROPERTY) |
63 | - private String tenantId; | 65 | + private UUID tenantId; |
64 | 66 | ||
65 | @Column(name = ModelConstants.ENTITY_VIEW_CUSTOMER_ID_PROPERTY) | 67 | @Column(name = ModelConstants.ENTITY_VIEW_CUSTOMER_ID_PROPERTY) |
66 | - private String customerId; | 68 | + private UUID customerId; |
67 | 69 | ||
68 | @Column(name = ModelConstants.DEVICE_TYPE_PROPERTY) | 70 | @Column(name = ModelConstants.DEVICE_TYPE_PROPERTY) |
69 | private String type; | 71 | private String type; |
@@ -97,15 +99,16 @@ public abstract class AbstractEntityViewEntity<T extends EntityView> extends Bas | @@ -97,15 +99,16 @@ public abstract class AbstractEntityViewEntity<T extends EntityView> extends Bas | ||
97 | if (entityView.getId() != null) { | 99 | if (entityView.getId() != null) { |
98 | this.setUuid(entityView.getId().getId()); | 100 | this.setUuid(entityView.getId().getId()); |
99 | } | 101 | } |
102 | + this.setCreatedTime(entityView.getCreatedTime()); | ||
100 | if (entityView.getEntityId() != null) { | 103 | if (entityView.getEntityId() != null) { |
101 | - this.entityId = toString(entityView.getEntityId().getId()); | 104 | + this.entityId = entityView.getEntityId().getId(); |
102 | this.entityType = entityView.getEntityId().getEntityType(); | 105 | this.entityType = entityView.getEntityId().getEntityType(); |
103 | } | 106 | } |
104 | if (entityView.getTenantId() != null) { | 107 | if (entityView.getTenantId() != null) { |
105 | - this.tenantId = toString(entityView.getTenantId().getId()); | 108 | + this.tenantId = entityView.getTenantId().getId(); |
106 | } | 109 | } |
107 | if (entityView.getCustomerId() != null) { | 110 | if (entityView.getCustomerId() != null) { |
108 | - this.customerId = toString(entityView.getCustomerId().getId()); | 111 | + this.customerId = entityView.getCustomerId().getId(); |
109 | } | 112 | } |
110 | this.type = entityView.getType(); | 113 | this.type = entityView.getType(); |
111 | this.name = entityView.getName(); | 114 | this.name = entityView.getName(); |
@@ -122,6 +125,7 @@ public abstract class AbstractEntityViewEntity<T extends EntityView> extends Bas | @@ -122,6 +125,7 @@ public abstract class AbstractEntityViewEntity<T extends EntityView> extends Bas | ||
122 | 125 | ||
123 | public AbstractEntityViewEntity(EntityViewEntity entityViewEntity) { | 126 | public AbstractEntityViewEntity(EntityViewEntity entityViewEntity) { |
124 | this.setId(entityViewEntity.getId()); | 127 | this.setId(entityViewEntity.getId()); |
128 | + this.setCreatedTime(entityViewEntity.getCreatedTime()); | ||
125 | this.entityId = entityViewEntity.getEntityId(); | 129 | this.entityId = entityViewEntity.getEntityId(); |
126 | this.entityType = entityViewEntity.getEntityType(); | 130 | this.entityType = entityViewEntity.getEntityType(); |
127 | this.tenantId = entityViewEntity.getTenantId(); | 131 | this.tenantId = entityViewEntity.getTenantId(); |
@@ -147,16 +151,16 @@ public abstract class AbstractEntityViewEntity<T extends EntityView> extends Bas | @@ -147,16 +151,16 @@ public abstract class AbstractEntityViewEntity<T extends EntityView> extends Bas | ||
147 | 151 | ||
148 | protected EntityView toEntityView() { | 152 | protected EntityView toEntityView() { |
149 | EntityView entityView = new EntityView(new EntityViewId(getUuid())); | 153 | EntityView entityView = new EntityView(new EntityViewId(getUuid())); |
150 | - entityView.setCreatedTime(Uuids.unixTimestamp(getUuid())); | 154 | + entityView.setCreatedTime(createdTime); |
151 | 155 | ||
152 | if (entityId != null) { | 156 | if (entityId != null) { |
153 | - entityView.setEntityId(EntityIdFactory.getByTypeAndId(entityType.name(), toUUID(entityId).toString())); | 157 | + entityView.setEntityId(EntityIdFactory.getByTypeAndUuid(entityType.name(), entityId)); |
154 | } | 158 | } |
155 | if (tenantId != null) { | 159 | if (tenantId != null) { |
156 | - entityView.setTenantId(new TenantId(toUUID(tenantId))); | 160 | + entityView.setTenantId(new TenantId(tenantId)); |
157 | } | 161 | } |
158 | if (customerId != null) { | 162 | if (customerId != null) { |
159 | - entityView.setCustomerId(new CustomerId(toUUID(customerId))); | 163 | + entityView.setCustomerId(new CustomerId(customerId)); |
160 | } | 164 | } |
161 | entityView.setType(type); | 165 | entityView.setType(type); |
162 | entityView.setName(name); | 166 | entityView.setName(name); |
@@ -15,14 +15,12 @@ | @@ -15,14 +15,12 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.sql; | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | ||
18 | -import com.datastax.oss.driver.api.core.uuid.Uuids; | ||
19 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 19 | import lombok.Data; |
21 | import lombok.EqualsAndHashCode; | 20 | import lombok.EqualsAndHashCode; |
22 | import org.hibernate.annotations.Type; | 21 | import org.hibernate.annotations.Type; |
23 | import org.hibernate.annotations.TypeDef; | 22 | import org.hibernate.annotations.TypeDef; |
24 | import org.thingsboard.server.common.data.AdminSettings; | 23 | import org.thingsboard.server.common.data.AdminSettings; |
25 | -import org.thingsboard.server.common.data.UUIDConverter; | ||
26 | import org.thingsboard.server.common.data.id.AdminSettingsId; | 24 | import org.thingsboard.server.common.data.id.AdminSettingsId; |
27 | import org.thingsboard.server.dao.model.BaseEntity; | 25 | import org.thingsboard.server.dao.model.BaseEntity; |
28 | import org.thingsboard.server.dao.model.BaseSqlEntity; | 26 | import org.thingsboard.server.dao.model.BaseSqlEntity; |
@@ -58,14 +56,15 @@ public final class AdminSettingsEntity extends BaseSqlEntity<AdminSettings> impl | @@ -58,14 +56,15 @@ public final class AdminSettingsEntity extends BaseSqlEntity<AdminSettings> impl | ||
58 | if (adminSettings.getId() != null) { | 56 | if (adminSettings.getId() != null) { |
59 | this.setUuid(adminSettings.getId().getId()); | 57 | this.setUuid(adminSettings.getId().getId()); |
60 | } | 58 | } |
59 | + this.setCreatedTime(adminSettings.getCreatedTime()); | ||
61 | this.key = adminSettings.getKey(); | 60 | this.key = adminSettings.getKey(); |
62 | this.jsonValue = adminSettings.getJsonValue(); | 61 | this.jsonValue = adminSettings.getJsonValue(); |
63 | } | 62 | } |
64 | 63 | ||
65 | @Override | 64 | @Override |
66 | public AdminSettings toData() { | 65 | public AdminSettings toData() { |
67 | - AdminSettings adminSettings = new AdminSettings(new AdminSettingsId(UUIDConverter.fromString(id))); | ||
68 | - adminSettings.setCreatedTime(Uuids.unixTimestamp(UUIDConverter.fromString(id))); | 66 | + AdminSettings adminSettings = new AdminSettings(new AdminSettingsId(id)); |
67 | + adminSettings.setCreatedTime(createdTime); | ||
69 | adminSettings.setKey(key); | 68 | adminSettings.setKey(key); |
70 | adminSettings.setJsonValue(jsonValue); | 69 | adminSettings.setJsonValue(jsonValue); |
71 | return adminSettings; | 70 | return adminSettings; |
@@ -25,6 +25,7 @@ import javax.persistence.Embeddable; | @@ -25,6 +25,7 @@ import javax.persistence.Embeddable; | ||
25 | import javax.persistence.EnumType; | 25 | import javax.persistence.EnumType; |
26 | import javax.persistence.Enumerated; | 26 | import javax.persistence.Enumerated; |
27 | import java.io.Serializable; | 27 | import java.io.Serializable; |
28 | +import java.util.UUID; | ||
28 | 29 | ||
29 | import static org.thingsboard.server.dao.model.ModelConstants.ATTRIBUTE_KEY_COLUMN; | 30 | import static org.thingsboard.server.dao.model.ModelConstants.ATTRIBUTE_KEY_COLUMN; |
30 | import static org.thingsboard.server.dao.model.ModelConstants.ATTRIBUTE_TYPE_COLUMN; | 31 | import static org.thingsboard.server.dao.model.ModelConstants.ATTRIBUTE_TYPE_COLUMN; |
@@ -39,8 +40,8 @@ public class AttributeKvCompositeKey implements Serializable { | @@ -39,8 +40,8 @@ public class AttributeKvCompositeKey implements Serializable { | ||
39 | @Enumerated(EnumType.STRING) | 40 | @Enumerated(EnumType.STRING) |
40 | @Column(name = ENTITY_TYPE_COLUMN) | 41 | @Column(name = ENTITY_TYPE_COLUMN) |
41 | private EntityType entityType; | 42 | private EntityType entityType; |
42 | - @Column(name = ENTITY_ID_COLUMN) | ||
43 | - private String entityId; | 43 | + @Column(name = ENTITY_ID_COLUMN, columnDefinition = "uuid") |
44 | + private UUID entityId; | ||
44 | @Column(name = ATTRIBUTE_TYPE_COLUMN) | 45 | @Column(name = ATTRIBUTE_TYPE_COLUMN) |
45 | private String attributeType; | 46 | private String attributeType; |
46 | @Column(name = ATTRIBUTE_KEY_COLUMN) | 47 | @Column(name = ATTRIBUTE_KEY_COLUMN) |
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.sql; | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | ||
18 | -import com.datastax.oss.driver.api.core.uuid.Uuids; | ||
19 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 19 | import lombok.Data; |
21 | import lombok.EqualsAndHashCode; | 20 | import lombok.EqualsAndHashCode; |
@@ -40,6 +39,7 @@ import javax.persistence.Entity; | @@ -40,6 +39,7 @@ import javax.persistence.Entity; | ||
40 | import javax.persistence.EnumType; | 39 | import javax.persistence.EnumType; |
41 | import javax.persistence.Enumerated; | 40 | import javax.persistence.Enumerated; |
42 | import javax.persistence.Table; | 41 | import javax.persistence.Table; |
42 | +import java.util.UUID; | ||
43 | 43 | ||
44 | import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_ACTION_DATA_PROPERTY; | 44 | import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_ACTION_DATA_PROPERTY; |
45 | import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_ACTION_FAILURE_DETAILS_PROPERTY; | 45 | import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_ACTION_FAILURE_DETAILS_PROPERTY; |
@@ -61,23 +61,23 @@ import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_USER_NAM | @@ -61,23 +61,23 @@ import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_USER_NAM | ||
61 | public class AuditLogEntity extends BaseSqlEntity<AuditLog> implements BaseEntity<AuditLog> { | 61 | public class AuditLogEntity extends BaseSqlEntity<AuditLog> implements BaseEntity<AuditLog> { |
62 | 62 | ||
63 | @Column(name = AUDIT_LOG_TENANT_ID_PROPERTY) | 63 | @Column(name = AUDIT_LOG_TENANT_ID_PROPERTY) |
64 | - private String tenantId; | 64 | + private UUID tenantId; |
65 | 65 | ||
66 | @Column(name = AUDIT_LOG_CUSTOMER_ID_PROPERTY) | 66 | @Column(name = AUDIT_LOG_CUSTOMER_ID_PROPERTY) |
67 | - private String customerId; | 67 | + private UUID customerId; |
68 | 68 | ||
69 | @Enumerated(EnumType.STRING) | 69 | @Enumerated(EnumType.STRING) |
70 | @Column(name = AUDIT_LOG_ENTITY_TYPE_PROPERTY) | 70 | @Column(name = AUDIT_LOG_ENTITY_TYPE_PROPERTY) |
71 | private EntityType entityType; | 71 | private EntityType entityType; |
72 | 72 | ||
73 | @Column(name = AUDIT_LOG_ENTITY_ID_PROPERTY) | 73 | @Column(name = AUDIT_LOG_ENTITY_ID_PROPERTY) |
74 | - private String entityId; | 74 | + private UUID entityId; |
75 | 75 | ||
76 | @Column(name = AUDIT_LOG_ENTITY_NAME_PROPERTY) | 76 | @Column(name = AUDIT_LOG_ENTITY_NAME_PROPERTY) |
77 | private String entityName; | 77 | private String entityName; |
78 | 78 | ||
79 | @Column(name = AUDIT_LOG_USER_ID_PROPERTY) | 79 | @Column(name = AUDIT_LOG_USER_ID_PROPERTY) |
80 | - private String userId; | 80 | + private UUID userId; |
81 | 81 | ||
82 | @Column(name = AUDIT_LOG_USER_NAME_PROPERTY) | 82 | @Column(name = AUDIT_LOG_USER_NAME_PROPERTY) |
83 | private String userName; | 83 | private String userName; |
@@ -105,18 +105,19 @@ public class AuditLogEntity extends BaseSqlEntity<AuditLog> implements BaseEntit | @@ -105,18 +105,19 @@ public class AuditLogEntity extends BaseSqlEntity<AuditLog> implements BaseEntit | ||
105 | if (auditLog.getId() != null) { | 105 | if (auditLog.getId() != null) { |
106 | this.setUuid(auditLog.getId().getId()); | 106 | this.setUuid(auditLog.getId().getId()); |
107 | } | 107 | } |
108 | + this.setCreatedTime(auditLog.getCreatedTime()); | ||
108 | if (auditLog.getTenantId() != null) { | 109 | if (auditLog.getTenantId() != null) { |
109 | - this.tenantId = toString(auditLog.getTenantId().getId()); | 110 | + this.tenantId = auditLog.getTenantId().getId(); |
110 | } | 111 | } |
111 | if (auditLog.getCustomerId() != null) { | 112 | if (auditLog.getCustomerId() != null) { |
112 | - this.customerId = toString(auditLog.getCustomerId().getId()); | 113 | + this.customerId = auditLog.getCustomerId().getId(); |
113 | } | 114 | } |
114 | if (auditLog.getEntityId() != null) { | 115 | if (auditLog.getEntityId() != null) { |
115 | - this.entityId = toString(auditLog.getEntityId().getId()); | 116 | + this.entityId = auditLog.getEntityId().getId(); |
116 | this.entityType = auditLog.getEntityId().getEntityType(); | 117 | this.entityType = auditLog.getEntityId().getEntityType(); |
117 | } | 118 | } |
118 | if (auditLog.getUserId() != null) { | 119 | if (auditLog.getUserId() != null) { |
119 | - this.userId = toString(auditLog.getUserId().getId()); | 120 | + this.userId = auditLog.getUserId().getId(); |
120 | } | 121 | } |
121 | this.entityName = auditLog.getEntityName(); | 122 | this.entityName = auditLog.getEntityName(); |
122 | this.userName = auditLog.getUserName(); | 123 | this.userName = auditLog.getUserName(); |
@@ -129,18 +130,18 @@ public class AuditLogEntity extends BaseSqlEntity<AuditLog> implements BaseEntit | @@ -129,18 +130,18 @@ public class AuditLogEntity extends BaseSqlEntity<AuditLog> implements BaseEntit | ||
129 | @Override | 130 | @Override |
130 | public AuditLog toData() { | 131 | public AuditLog toData() { |
131 | AuditLog auditLog = new AuditLog(new AuditLogId(this.getUuid())); | 132 | AuditLog auditLog = new AuditLog(new AuditLogId(this.getUuid())); |
132 | - auditLog.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | 133 | + auditLog.setCreatedTime(createdTime); |
133 | if (tenantId != null) { | 134 | if (tenantId != null) { |
134 | - auditLog.setTenantId(new TenantId(toUUID(tenantId))); | 135 | + auditLog.setTenantId(new TenantId(tenantId)); |
135 | } | 136 | } |
136 | if (customerId != null) { | 137 | if (customerId != null) { |
137 | - auditLog.setCustomerId(new CustomerId(toUUID(customerId))); | 138 | + auditLog.setCustomerId(new CustomerId(customerId)); |
138 | } | 139 | } |
139 | if (entityId != null) { | 140 | if (entityId != null) { |
140 | - auditLog.setEntityId(EntityIdFactory.getByTypeAndId(entityType.name(), toUUID(entityId).toString())); | 141 | + auditLog.setEntityId(EntityIdFactory.getByTypeAndUuid(entityType.name(), entityId)); |
141 | } | 142 | } |
142 | if (userId != null) { | 143 | if (userId != null) { |
143 | - auditLog.setUserId(new UserId(toUUID(userId))); | 144 | + auditLog.setUserId(new UserId(userId)); |
144 | } | 145 | } |
145 | auditLog.setEntityName(this.entityName); | 146 | auditLog.setEntityName(this.entityName); |
146 | auditLog.setUserName(this.userName); | 147 | auditLog.setUserName(this.userName); |
@@ -73,6 +73,7 @@ public class ComponentDescriptorEntity extends BaseSqlEntity<ComponentDescriptor | @@ -73,6 +73,7 @@ public class ComponentDescriptorEntity extends BaseSqlEntity<ComponentDescriptor | ||
73 | if (component.getId() != null) { | 73 | if (component.getId() != null) { |
74 | this.setUuid(component.getId().getId()); | 74 | this.setUuid(component.getId().getId()); |
75 | } | 75 | } |
76 | + this.setCreatedTime(component.getCreatedTime()); | ||
76 | this.actions = component.getActions(); | 77 | this.actions = component.getActions(); |
77 | this.type = component.getType(); | 78 | this.type = component.getType(); |
78 | this.scope = component.getScope(); | 79 | this.scope = component.getScope(); |
@@ -85,6 +86,7 @@ public class ComponentDescriptorEntity extends BaseSqlEntity<ComponentDescriptor | @@ -85,6 +86,7 @@ public class ComponentDescriptorEntity extends BaseSqlEntity<ComponentDescriptor | ||
85 | @Override | 86 | @Override |
86 | public ComponentDescriptor toData() { | 87 | public ComponentDescriptor toData() { |
87 | ComponentDescriptor data = new ComponentDescriptor(new ComponentDescriptorId(this.getUuid())); | 88 | ComponentDescriptor data = new ComponentDescriptor(new ComponentDescriptorId(this.getUuid())); |
89 | + data.setCreatedTime(createdTime); | ||
88 | data.setType(type); | 90 | data.setType(type); |
89 | data.setScope(scope); | 91 | data.setScope(scope); |
90 | data.setName(this.getName()); | 92 | data.setName(this.getName()); |
@@ -15,14 +15,12 @@ | @@ -15,14 +15,12 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.sql; | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | ||
18 | -import com.datastax.oss.driver.api.core.uuid.Uuids; | ||
19 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 19 | import lombok.Data; |
21 | import lombok.EqualsAndHashCode; | 20 | import lombok.EqualsAndHashCode; |
22 | import org.hibernate.annotations.Type; | 21 | import org.hibernate.annotations.Type; |
23 | import org.hibernate.annotations.TypeDef; | 22 | import org.hibernate.annotations.TypeDef; |
24 | import org.thingsboard.server.common.data.Customer; | 23 | import org.thingsboard.server.common.data.Customer; |
25 | -import org.thingsboard.server.common.data.UUIDConverter; | ||
26 | import org.thingsboard.server.common.data.id.CustomerId; | 24 | import org.thingsboard.server.common.data.id.CustomerId; |
27 | import org.thingsboard.server.common.data.id.TenantId; | 25 | import org.thingsboard.server.common.data.id.TenantId; |
28 | import org.thingsboard.server.dao.model.BaseSqlEntity; | 26 | import org.thingsboard.server.dao.model.BaseSqlEntity; |
@@ -33,6 +31,7 @@ import org.thingsboard.server.dao.util.mapping.JsonStringType; | @@ -33,6 +31,7 @@ import org.thingsboard.server.dao.util.mapping.JsonStringType; | ||
33 | import javax.persistence.Column; | 31 | import javax.persistence.Column; |
34 | import javax.persistence.Entity; | 32 | import javax.persistence.Entity; |
35 | import javax.persistence.Table; | 33 | import javax.persistence.Table; |
34 | +import java.util.UUID; | ||
36 | 35 | ||
37 | @Data | 36 | @Data |
38 | @EqualsAndHashCode(callSuper = true) | 37 | @EqualsAndHashCode(callSuper = true) |
@@ -42,7 +41,7 @@ import javax.persistence.Table; | @@ -42,7 +41,7 @@ import javax.persistence.Table; | ||
42 | public final class CustomerEntity extends BaseSqlEntity<Customer> implements SearchTextEntity<Customer> { | 41 | public final class CustomerEntity extends BaseSqlEntity<Customer> implements SearchTextEntity<Customer> { |
43 | 42 | ||
44 | @Column(name = ModelConstants.CUSTOMER_TENANT_ID_PROPERTY) | 43 | @Column(name = ModelConstants.CUSTOMER_TENANT_ID_PROPERTY) |
45 | - private String tenantId; | 44 | + private UUID tenantId; |
46 | 45 | ||
47 | @Column(name = ModelConstants.CUSTOMER_TITLE_PROPERTY) | 46 | @Column(name = ModelConstants.CUSTOMER_TITLE_PROPERTY) |
48 | private String title; | 47 | private String title; |
@@ -86,7 +85,8 @@ public final class CustomerEntity extends BaseSqlEntity<Customer> implements Sea | @@ -86,7 +85,8 @@ public final class CustomerEntity extends BaseSqlEntity<Customer> implements Sea | ||
86 | if (customer.getId() != null) { | 85 | if (customer.getId() != null) { |
87 | this.setUuid(customer.getId().getId()); | 86 | this.setUuid(customer.getId().getId()); |
88 | } | 87 | } |
89 | - this.tenantId = UUIDConverter.fromTimeUUID(customer.getTenantId().getId()); | 88 | + this.setCreatedTime(customer.getCreatedTime()); |
89 | + this.tenantId = customer.getTenantId().getId(); | ||
90 | this.title = customer.getTitle(); | 90 | this.title = customer.getTitle(); |
91 | this.country = customer.getCountry(); | 91 | this.country = customer.getCountry(); |
92 | this.state = customer.getState(); | 92 | this.state = customer.getState(); |
@@ -112,8 +112,8 @@ public final class CustomerEntity extends BaseSqlEntity<Customer> implements Sea | @@ -112,8 +112,8 @@ public final class CustomerEntity extends BaseSqlEntity<Customer> implements Sea | ||
112 | @Override | 112 | @Override |
113 | public Customer toData() { | 113 | public Customer toData() { |
114 | Customer customer = new Customer(new CustomerId(this.getUuid())); | 114 | Customer customer = new Customer(new CustomerId(this.getUuid())); |
115 | - customer.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | ||
116 | - customer.setTenantId(new TenantId(UUIDConverter.fromString(tenantId))); | 115 | + customer.setCreatedTime(createdTime); |
116 | + customer.setTenantId(new TenantId(tenantId)); | ||
117 | customer.setTitle(title); | 117 | customer.setTitle(title); |
118 | customer.setCountry(country); | 118 | customer.setCountry(country); |
119 | customer.setState(state); | 119 | customer.setState(state); |
@@ -126,4 +126,5 @@ public final class CustomerEntity extends BaseSqlEntity<Customer> implements Sea | @@ -126,4 +126,5 @@ public final class CustomerEntity extends BaseSqlEntity<Customer> implements Sea | ||
126 | customer.setAdditionalInfo(additionalInfo); | 126 | customer.setAdditionalInfo(additionalInfo); |
127 | return customer; | 127 | return customer; |
128 | } | 128 | } |
129 | + | ||
129 | } | 130 | } |
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.sql; | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | ||
18 | -import com.datastax.oss.driver.api.core.uuid.Uuids; | ||
19 | import com.fasterxml.jackson.core.JsonProcessingException; | 18 | import com.fasterxml.jackson.core.JsonProcessingException; |
20 | import com.fasterxml.jackson.databind.JavaType; | 19 | import com.fasterxml.jackson.databind.JavaType; |
21 | import com.fasterxml.jackson.databind.JsonNode; | 20 | import com.fasterxml.jackson.databind.JsonNode; |
@@ -40,6 +39,7 @@ import javax.persistence.Entity; | @@ -40,6 +39,7 @@ import javax.persistence.Entity; | ||
40 | import javax.persistence.Table; | 39 | import javax.persistence.Table; |
41 | import java.io.IOException; | 40 | import java.io.IOException; |
42 | import java.util.HashSet; | 41 | import java.util.HashSet; |
42 | +import java.util.UUID; | ||
43 | 43 | ||
44 | @Data | 44 | @Data |
45 | @Slf4j | 45 | @Slf4j |
@@ -54,7 +54,7 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S | @@ -54,7 +54,7 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S | ||
54 | objectMapper.getTypeFactory().constructCollectionType(HashSet.class, ShortCustomerInfo.class); | 54 | objectMapper.getTypeFactory().constructCollectionType(HashSet.class, ShortCustomerInfo.class); |
55 | 55 | ||
56 | @Column(name = ModelConstants.DASHBOARD_TENANT_ID_PROPERTY) | 56 | @Column(name = ModelConstants.DASHBOARD_TENANT_ID_PROPERTY) |
57 | - private String tenantId; | 57 | + private UUID tenantId; |
58 | 58 | ||
59 | @Column(name = ModelConstants.DASHBOARD_TITLE_PROPERTY) | 59 | @Column(name = ModelConstants.DASHBOARD_TITLE_PROPERTY) |
60 | private String title; | 60 | private String title; |
@@ -77,8 +77,9 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S | @@ -77,8 +77,9 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S | ||
77 | if (dashboard.getId() != null) { | 77 | if (dashboard.getId() != null) { |
78 | this.setUuid(dashboard.getId().getId()); | 78 | this.setUuid(dashboard.getId().getId()); |
79 | } | 79 | } |
80 | + this.setCreatedTime(dashboard.getCreatedTime()); | ||
80 | if (dashboard.getTenantId() != null) { | 81 | if (dashboard.getTenantId() != null) { |
81 | - this.tenantId = toString(dashboard.getTenantId().getId()); | 82 | + this.tenantId = dashboard.getTenantId().getId(); |
82 | } | 83 | } |
83 | this.title = dashboard.getTitle(); | 84 | this.title = dashboard.getTitle(); |
84 | if (dashboard.getAssignedCustomers() != null) { | 85 | if (dashboard.getAssignedCustomers() != null) { |
@@ -104,9 +105,9 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S | @@ -104,9 +105,9 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S | ||
104 | @Override | 105 | @Override |
105 | public Dashboard toData() { | 106 | public Dashboard toData() { |
106 | Dashboard dashboard = new Dashboard(new DashboardId(this.getUuid())); | 107 | Dashboard dashboard = new Dashboard(new DashboardId(this.getUuid())); |
107 | - dashboard.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | 108 | + dashboard.setCreatedTime(this.getCreatedTime()); |
108 | if (tenantId != null) { | 109 | if (tenantId != null) { |
109 | - dashboard.setTenantId(new TenantId(toUUID(tenantId))); | 110 | + dashboard.setTenantId(new TenantId(tenantId)); |
110 | } | 111 | } |
111 | dashboard.setTitle(title); | 112 | dashboard.setTitle(title); |
112 | if (!StringUtils.isEmpty(assignedCustomers)) { | 113 | if (!StringUtils.isEmpty(assignedCustomers)) { |
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.sql; | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | ||
18 | -import com.datastax.oss.driver.api.core.uuid.Uuids; | ||
19 | import com.fasterxml.jackson.core.JsonProcessingException; | 18 | import com.fasterxml.jackson.core.JsonProcessingException; |
20 | import com.fasterxml.jackson.databind.JavaType; | 19 | import com.fasterxml.jackson.databind.JavaType; |
21 | import com.fasterxml.jackson.databind.ObjectMapper; | 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
@@ -36,6 +35,7 @@ import javax.persistence.Entity; | @@ -36,6 +35,7 @@ import javax.persistence.Entity; | ||
36 | import javax.persistence.Table; | 35 | import javax.persistence.Table; |
37 | import java.io.IOException; | 36 | import java.io.IOException; |
38 | import java.util.HashSet; | 37 | import java.util.HashSet; |
38 | +import java.util.UUID; | ||
39 | 39 | ||
40 | @Data | 40 | @Data |
41 | @Slf4j | 41 | @Slf4j |
@@ -49,7 +49,7 @@ public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> implements | @@ -49,7 +49,7 @@ public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> implements | ||
49 | objectMapper.getTypeFactory().constructCollectionType(HashSet.class, ShortCustomerInfo.class); | 49 | objectMapper.getTypeFactory().constructCollectionType(HashSet.class, ShortCustomerInfo.class); |
50 | 50 | ||
51 | @Column(name = ModelConstants.DASHBOARD_TENANT_ID_PROPERTY) | 51 | @Column(name = ModelConstants.DASHBOARD_TENANT_ID_PROPERTY) |
52 | - private String tenantId; | 52 | + private UUID tenantId; |
53 | 53 | ||
54 | @Column(name = ModelConstants.DASHBOARD_TITLE_PROPERTY) | 54 | @Column(name = ModelConstants.DASHBOARD_TITLE_PROPERTY) |
55 | private String title; | 55 | private String title; |
@@ -68,8 +68,9 @@ public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> implements | @@ -68,8 +68,9 @@ public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> implements | ||
68 | if (dashboardInfo.getId() != null) { | 68 | if (dashboardInfo.getId() != null) { |
69 | this.setUuid(dashboardInfo.getId().getId()); | 69 | this.setUuid(dashboardInfo.getId().getId()); |
70 | } | 70 | } |
71 | + this.setCreatedTime(dashboardInfo.getCreatedTime()); | ||
71 | if (dashboardInfo.getTenantId() != null) { | 72 | if (dashboardInfo.getTenantId() != null) { |
72 | - this.tenantId = toString(dashboardInfo.getTenantId().getId()); | 73 | + this.tenantId = dashboardInfo.getTenantId().getId(); |
73 | } | 74 | } |
74 | this.title = dashboardInfo.getTitle(); | 75 | this.title = dashboardInfo.getTitle(); |
75 | if (dashboardInfo.getAssignedCustomers() != null) { | 76 | if (dashboardInfo.getAssignedCustomers() != null) { |
@@ -98,9 +99,9 @@ public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> implements | @@ -98,9 +99,9 @@ public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> implements | ||
98 | @Override | 99 | @Override |
99 | public DashboardInfo toData() { | 100 | public DashboardInfo toData() { |
100 | DashboardInfo dashboardInfo = new DashboardInfo(new DashboardId(this.getUuid())); | 101 | DashboardInfo dashboardInfo = new DashboardInfo(new DashboardId(this.getUuid())); |
101 | - dashboardInfo.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | 102 | + dashboardInfo.setCreatedTime(createdTime); |
102 | if (tenantId != null) { | 103 | if (tenantId != null) { |
103 | - dashboardInfo.setTenantId(new TenantId(toUUID(tenantId))); | 104 | + dashboardInfo.setTenantId(new TenantId(tenantId)); |
104 | } | 105 | } |
105 | dashboardInfo.setTitle(title); | 106 | dashboardInfo.setTitle(title); |
106 | if (!StringUtils.isEmpty(assignedCustomers)) { | 107 | if (!StringUtils.isEmpty(assignedCustomers)) { |
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.sql; | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | ||
18 | -import com.datastax.oss.driver.api.core.uuid.Uuids; | ||
19 | import lombok.Data; | 18 | import lombok.Data; |
20 | import lombok.EqualsAndHashCode; | 19 | import lombok.EqualsAndHashCode; |
21 | import org.thingsboard.server.common.data.id.DeviceCredentialsId; | 20 | import org.thingsboard.server.common.data.id.DeviceCredentialsId; |
@@ -31,6 +30,7 @@ import javax.persistence.Entity; | @@ -31,6 +30,7 @@ import javax.persistence.Entity; | ||
31 | import javax.persistence.EnumType; | 30 | import javax.persistence.EnumType; |
32 | import javax.persistence.Enumerated; | 31 | import javax.persistence.Enumerated; |
33 | import javax.persistence.Table; | 32 | import javax.persistence.Table; |
33 | +import java.util.UUID; | ||
34 | 34 | ||
35 | @Data | 35 | @Data |
36 | @EqualsAndHashCode(callSuper = true) | 36 | @EqualsAndHashCode(callSuper = true) |
@@ -39,7 +39,7 @@ import javax.persistence.Table; | @@ -39,7 +39,7 @@ import javax.persistence.Table; | ||
39 | public final class DeviceCredentialsEntity extends BaseSqlEntity<DeviceCredentials> implements BaseEntity<DeviceCredentials> { | 39 | public final class DeviceCredentialsEntity extends BaseSqlEntity<DeviceCredentials> implements BaseEntity<DeviceCredentials> { |
40 | 40 | ||
41 | @Column(name = ModelConstants.DEVICE_CREDENTIALS_DEVICE_ID_PROPERTY) | 41 | @Column(name = ModelConstants.DEVICE_CREDENTIALS_DEVICE_ID_PROPERTY) |
42 | - private String deviceId; | 42 | + private UUID deviceId; |
43 | 43 | ||
44 | @Enumerated(EnumType.STRING) | 44 | @Enumerated(EnumType.STRING) |
45 | @Column(name = ModelConstants.DEVICE_CREDENTIALS_CREDENTIALS_TYPE_PROPERTY) | 45 | @Column(name = ModelConstants.DEVICE_CREDENTIALS_CREDENTIALS_TYPE_PROPERTY) |
@@ -59,8 +59,9 @@ public final class DeviceCredentialsEntity extends BaseSqlEntity<DeviceCredentia | @@ -59,8 +59,9 @@ public final class DeviceCredentialsEntity extends BaseSqlEntity<DeviceCredentia | ||
59 | if (deviceCredentials.getId() != null) { | 59 | if (deviceCredentials.getId() != null) { |
60 | this.setUuid(deviceCredentials.getId().getId()); | 60 | this.setUuid(deviceCredentials.getId().getId()); |
61 | } | 61 | } |
62 | + this.setCreatedTime(deviceCredentials.getCreatedTime()); | ||
62 | if (deviceCredentials.getDeviceId() != null) { | 63 | if (deviceCredentials.getDeviceId() != null) { |
63 | - this.deviceId = toString(deviceCredentials.getDeviceId().getId()); | 64 | + this.deviceId = deviceCredentials.getDeviceId().getId(); |
64 | } | 65 | } |
65 | this.credentialsType = deviceCredentials.getCredentialsType(); | 66 | this.credentialsType = deviceCredentials.getCredentialsType(); |
66 | this.credentialsId = deviceCredentials.getCredentialsId(); | 67 | this.credentialsId = deviceCredentials.getCredentialsId(); |
@@ -70,9 +71,9 @@ public final class DeviceCredentialsEntity extends BaseSqlEntity<DeviceCredentia | @@ -70,9 +71,9 @@ public final class DeviceCredentialsEntity extends BaseSqlEntity<DeviceCredentia | ||
70 | @Override | 71 | @Override |
71 | public DeviceCredentials toData() { | 72 | public DeviceCredentials toData() { |
72 | DeviceCredentials deviceCredentials = new DeviceCredentials(new DeviceCredentialsId(this.getUuid())); | 73 | DeviceCredentials deviceCredentials = new DeviceCredentials(new DeviceCredentialsId(this.getUuid())); |
73 | - deviceCredentials.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | 74 | + deviceCredentials.setCreatedTime(createdTime); |
74 | if (deviceId != null) { | 75 | if (deviceId != null) { |
75 | - deviceCredentials.setDeviceId(new DeviceId(toUUID(deviceId))); | 76 | + deviceCredentials.setDeviceId(new DeviceId(deviceId)); |
76 | } | 77 | } |
77 | deviceCredentials.setCredentialsType(credentialsType); | 78 | deviceCredentials.setCredentialsType(credentialsType); |
78 | deviceCredentials.setCredentialsId(credentialsId); | 79 | deviceCredentials.setCredentialsId(credentialsId); |
@@ -15,9 +15,9 @@ | @@ -15,9 +15,9 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.sql; | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | ||
18 | +import com.fasterxml.jackson.databind.JsonNode; | ||
18 | import lombok.Data; | 19 | import lombok.Data; |
19 | import lombok.EqualsAndHashCode; | 20 | import lombok.EqualsAndHashCode; |
20 | -import com.fasterxml.jackson.databind.JsonNode; | ||
21 | import org.thingsboard.server.common.data.DeviceInfo; | 21 | import org.thingsboard.server.common.data.DeviceInfo; |
22 | 22 | ||
23 | import java.util.HashMap; | 23 | import java.util.HashMap; |
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.sql; | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | ||
18 | -import com.datastax.oss.driver.api.core.uuid.Uuids; | ||
19 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 19 | import lombok.Data; |
21 | import lombok.EqualsAndHashCode; | 20 | import lombok.EqualsAndHashCode; |
@@ -36,7 +35,6 @@ import javax.persistence.Entity; | @@ -36,7 +35,6 @@ import javax.persistence.Entity; | ||
36 | import javax.persistence.EnumType; | 35 | import javax.persistence.EnumType; |
37 | import javax.persistence.Enumerated; | 36 | import javax.persistence.Enumerated; |
38 | import javax.persistence.Table; | 37 | import javax.persistence.Table; |
39 | - | ||
40 | import java.util.UUID; | 38 | import java.util.UUID; |
41 | 39 | ||
42 | import static org.thingsboard.server.dao.model.ModelConstants.EPOCH_DIFF; | 40 | import static org.thingsboard.server.dao.model.ModelConstants.EPOCH_DIFF; |
@@ -55,17 +53,17 @@ import static org.thingsboard.server.dao.model.ModelConstants.TS_COLUMN; | @@ -55,17 +53,17 @@ import static org.thingsboard.server.dao.model.ModelConstants.TS_COLUMN; | ||
55 | @TypeDef(name = "json", typeClass = JsonStringType.class) | 53 | @TypeDef(name = "json", typeClass = JsonStringType.class) |
56 | @Table(name = EVENT_COLUMN_FAMILY_NAME) | 54 | @Table(name = EVENT_COLUMN_FAMILY_NAME) |
57 | @NoArgsConstructor | 55 | @NoArgsConstructor |
58 | -public class EventEntity extends BaseSqlEntity<Event> implements BaseEntity<Event> { | 56 | +public class EventEntity extends BaseSqlEntity<Event> implements BaseEntity<Event> { |
59 | 57 | ||
60 | @Column(name = EVENT_TENANT_ID_PROPERTY) | 58 | @Column(name = EVENT_TENANT_ID_PROPERTY) |
61 | - private String tenantId; | 59 | + private UUID tenantId; |
62 | 60 | ||
63 | @Enumerated(EnumType.STRING) | 61 | @Enumerated(EnumType.STRING) |
64 | @Column(name = EVENT_ENTITY_TYPE_PROPERTY) | 62 | @Column(name = EVENT_ENTITY_TYPE_PROPERTY) |
65 | private EntityType entityType; | 63 | private EntityType entityType; |
66 | 64 | ||
67 | @Column(name = EVENT_ENTITY_ID_PROPERTY) | 65 | @Column(name = EVENT_ENTITY_ID_PROPERTY) |
68 | - private String entityId; | 66 | + private UUID entityId; |
69 | 67 | ||
70 | @Column(name = EVENT_TYPE_PROPERTY) | 68 | @Column(name = EVENT_TYPE_PROPERTY) |
71 | private String eventType; | 69 | private String eventType; |
@@ -87,12 +85,13 @@ public class EventEntity extends BaseSqlEntity<Event> implements BaseEntity<Eve | @@ -87,12 +85,13 @@ public class EventEntity extends BaseSqlEntity<Event> implements BaseEntity<Eve | ||
87 | } else { | 85 | } else { |
88 | this.ts = System.currentTimeMillis(); | 86 | this.ts = System.currentTimeMillis(); |
89 | } | 87 | } |
88 | + this.setCreatedTime(event.getCreatedTime()); | ||
90 | if (event.getTenantId() != null) { | 89 | if (event.getTenantId() != null) { |
91 | - this.tenantId = toString(event.getTenantId().getId()); | 90 | + this.tenantId = event.getTenantId().getId(); |
92 | } | 91 | } |
93 | if (event.getEntityId() != null) { | 92 | if (event.getEntityId() != null) { |
94 | this.entityType = event.getEntityId().getEntityType(); | 93 | this.entityType = event.getEntityId().getEntityType(); |
95 | - this.entityId = toString(event.getEntityId().getId()); | 94 | + this.entityId = event.getEntityId().getId(); |
96 | } | 95 | } |
97 | this.eventType = event.getType(); | 96 | this.eventType = event.getType(); |
98 | this.eventUid = event.getUid(); | 97 | this.eventUid = event.getUid(); |
@@ -103,9 +102,9 @@ public class EventEntity extends BaseSqlEntity<Event> implements BaseEntity<Eve | @@ -103,9 +102,9 @@ public class EventEntity extends BaseSqlEntity<Event> implements BaseEntity<Eve | ||
103 | @Override | 102 | @Override |
104 | public Event toData() { | 103 | public Event toData() { |
105 | Event event = new Event(new EventId(this.getUuid())); | 104 | Event event = new Event(new EventId(this.getUuid())); |
106 | - event.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | ||
107 | - event.setTenantId(new TenantId(toUUID(tenantId))); | ||
108 | - event.setEntityId(EntityIdFactory.getByTypeAndUuid(entityType, toUUID(entityId))); | 105 | + event.setCreatedTime(createdTime); |
106 | + event.setTenantId(new TenantId(tenantId)); | ||
107 | + event.setEntityId(EntityIdFactory.getByTypeAndUuid(entityType, entityId)); | ||
109 | event.setBody(body); | 108 | event.setBody(body); |
110 | event.setType(eventType); | 109 | event.setType(eventType); |
111 | event.setUid(eventUid); | 110 | event.setUid(eventUid); |
@@ -18,11 +18,11 @@ package org.thingsboard.server.dao.model.sql; | @@ -18,11 +18,11 @@ package org.thingsboard.server.dao.model.sql; | ||
18 | import lombok.AllArgsConstructor; | 18 | import lombok.AllArgsConstructor; |
19 | import lombok.Data; | 19 | import lombok.Data; |
20 | import lombok.NoArgsConstructor; | 20 | import lombok.NoArgsConstructor; |
21 | -import org.thingsboard.server.common.data.UUIDConverter; | ||
22 | import org.thingsboard.server.common.data.relation.EntityRelation; | 21 | import org.thingsboard.server.common.data.relation.EntityRelation; |
23 | 22 | ||
24 | import javax.persistence.Transient; | 23 | import javax.persistence.Transient; |
25 | import java.io.Serializable; | 24 | import java.io.Serializable; |
25 | +import java.util.UUID; | ||
26 | 26 | ||
27 | @NoArgsConstructor | 27 | @NoArgsConstructor |
28 | @AllArgsConstructor | 28 | @AllArgsConstructor |
@@ -32,17 +32,17 @@ public class RelationCompositeKey implements Serializable { | @@ -32,17 +32,17 @@ public class RelationCompositeKey implements Serializable { | ||
32 | @Transient | 32 | @Transient |
33 | private static final long serialVersionUID = -4089175869616037592L; | 33 | private static final long serialVersionUID = -4089175869616037592L; |
34 | 34 | ||
35 | - private String fromId; | 35 | + private UUID fromId; |
36 | private String fromType; | 36 | private String fromType; |
37 | - private String toId; | 37 | + private UUID toId; |
38 | private String toType; | 38 | private String toType; |
39 | private String relationType; | 39 | private String relationType; |
40 | private String relationTypeGroup; | 40 | private String relationTypeGroup; |
41 | 41 | ||
42 | public RelationCompositeKey(EntityRelation relation) { | 42 | public RelationCompositeKey(EntityRelation relation) { |
43 | - this.fromId = UUIDConverter.fromTimeUUID(relation.getFrom().getId()); | 43 | + this.fromId = relation.getFrom().getId(); |
44 | this.fromType = relation.getFrom().getEntityType().name(); | 44 | this.fromType = relation.getFrom().getEntityType().name(); |
45 | - this.toId = UUIDConverter.fromTimeUUID(relation.getTo().getId()); | 45 | + this.toId = relation.getTo().getId(); |
46 | this.toType = relation.getTo().getEntityType().name(); | 46 | this.toType = relation.getTo().getEntityType().name(); |
47 | this.relationType = relation.getType(); | 47 | this.relationType = relation.getType(); |
48 | this.relationTypeGroup = relation.getTypeGroup().name(); | 48 | this.relationTypeGroup = relation.getTypeGroup().name(); |
@@ -19,7 +19,6 @@ import com.fasterxml.jackson.databind.JsonNode; | @@ -19,7 +19,6 @@ import com.fasterxml.jackson.databind.JsonNode; | ||
19 | import lombok.Data; | 19 | import lombok.Data; |
20 | import org.hibernate.annotations.Type; | 20 | import org.hibernate.annotations.Type; |
21 | import org.hibernate.annotations.TypeDef; | 21 | import org.hibernate.annotations.TypeDef; |
22 | -import org.thingsboard.server.common.data.UUIDConverter; | ||
23 | import org.thingsboard.server.common.data.id.EntityIdFactory; | 22 | import org.thingsboard.server.common.data.id.EntityIdFactory; |
24 | import org.thingsboard.server.common.data.relation.EntityRelation; | 23 | import org.thingsboard.server.common.data.relation.EntityRelation; |
25 | import org.thingsboard.server.common.data.relation.RelationTypeGroup; | 24 | import org.thingsboard.server.common.data.relation.RelationTypeGroup; |
@@ -31,6 +30,7 @@ import javax.persistence.Entity; | @@ -31,6 +30,7 @@ import javax.persistence.Entity; | ||
31 | import javax.persistence.Id; | 30 | import javax.persistence.Id; |
32 | import javax.persistence.IdClass; | 31 | import javax.persistence.IdClass; |
33 | import javax.persistence.Table; | 32 | import javax.persistence.Table; |
33 | +import java.util.UUID; | ||
34 | 34 | ||
35 | import static org.thingsboard.server.dao.model.ModelConstants.ADDITIONAL_INFO_PROPERTY; | 35 | import static org.thingsboard.server.dao.model.ModelConstants.ADDITIONAL_INFO_PROPERTY; |
36 | import static org.thingsboard.server.dao.model.ModelConstants.RELATION_COLUMN_FAMILY_NAME; | 36 | import static org.thingsboard.server.dao.model.ModelConstants.RELATION_COLUMN_FAMILY_NAME; |
@@ -49,16 +49,16 @@ import static org.thingsboard.server.dao.model.ModelConstants.RELATION_TYPE_PROP | @@ -49,16 +49,16 @@ import static org.thingsboard.server.dao.model.ModelConstants.RELATION_TYPE_PROP | ||
49 | public final class RelationEntity implements ToData<EntityRelation> { | 49 | public final class RelationEntity implements ToData<EntityRelation> { |
50 | 50 | ||
51 | @Id | 51 | @Id |
52 | - @Column(name = RELATION_FROM_ID_PROPERTY) | ||
53 | - private String fromId; | 52 | + @Column(name = RELATION_FROM_ID_PROPERTY, columnDefinition = "uuid") |
53 | + private UUID fromId; | ||
54 | 54 | ||
55 | @Id | 55 | @Id |
56 | @Column(name = RELATION_FROM_TYPE_PROPERTY) | 56 | @Column(name = RELATION_FROM_TYPE_PROPERTY) |
57 | private String fromType; | 57 | private String fromType; |
58 | 58 | ||
59 | @Id | 59 | @Id |
60 | - @Column(name = RELATION_TO_ID_PROPERTY) | ||
61 | - private String toId; | 60 | + @Column(name = RELATION_TO_ID_PROPERTY, columnDefinition = "uuid") |
61 | + private UUID toId; | ||
62 | 62 | ||
63 | @Id | 63 | @Id |
64 | @Column(name = RELATION_TO_TYPE_PROPERTY) | 64 | @Column(name = RELATION_TO_TYPE_PROPERTY) |
@@ -82,11 +82,11 @@ public final class RelationEntity implements ToData<EntityRelation> { | @@ -82,11 +82,11 @@ public final class RelationEntity implements ToData<EntityRelation> { | ||
82 | 82 | ||
83 | public RelationEntity(EntityRelation relation) { | 83 | public RelationEntity(EntityRelation relation) { |
84 | if (relation.getTo() != null) { | 84 | if (relation.getTo() != null) { |
85 | - this.toId = UUIDConverter.fromTimeUUID(relation.getTo().getId()); | 85 | + this.toId = relation.getTo().getId(); |
86 | this.toType = relation.getTo().getEntityType().name(); | 86 | this.toType = relation.getTo().getEntityType().name(); |
87 | } | 87 | } |
88 | if (relation.getFrom() != null) { | 88 | if (relation.getFrom() != null) { |
89 | - this.fromId = UUIDConverter.fromTimeUUID(relation.getFrom().getId()); | 89 | + this.fromId = relation.getFrom().getId(); |
90 | this.fromType = relation.getFrom().getEntityType().name(); | 90 | this.fromType = relation.getFrom().getEntityType().name(); |
91 | } | 91 | } |
92 | this.relationType = relation.getType(); | 92 | this.relationType = relation.getType(); |
@@ -98,10 +98,10 @@ public final class RelationEntity implements ToData<EntityRelation> { | @@ -98,10 +98,10 @@ public final class RelationEntity implements ToData<EntityRelation> { | ||
98 | public EntityRelation toData() { | 98 | public EntityRelation toData() { |
99 | EntityRelation relation = new EntityRelation(); | 99 | EntityRelation relation = new EntityRelation(); |
100 | if (toId != null && toType != null) { | 100 | if (toId != null && toType != null) { |
101 | - relation.setTo(EntityIdFactory.getByTypeAndUuid(toType, UUIDConverter.fromString(toId))); | 101 | + relation.setTo(EntityIdFactory.getByTypeAndUuid(toType, toId)); |
102 | } | 102 | } |
103 | if (fromId != null && fromType != null) { | 103 | if (fromId != null && fromType != null) { |
104 | - relation.setFrom(EntityIdFactory.getByTypeAndUuid(fromType, UUIDConverter.fromString(fromId))); | 104 | + relation.setFrom(EntityIdFactory.getByTypeAndUuid(fromType, fromId)); |
105 | } | 105 | } |
106 | relation.setType(relationType); | 106 | relation.setType(relationType); |
107 | relation.setTypeGroup(RelationTypeGroup.valueOf(relationTypeGroup)); | 107 | relation.setTypeGroup(RelationTypeGroup.valueOf(relationTypeGroup)); |
@@ -15,13 +15,11 @@ | @@ -15,13 +15,11 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.sql; | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | ||
18 | -import com.datastax.oss.driver.api.core.uuid.Uuids; | ||
19 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 19 | import lombok.Data; |
21 | import lombok.EqualsAndHashCode; | 20 | import lombok.EqualsAndHashCode; |
22 | import org.hibernate.annotations.Type; | 21 | import org.hibernate.annotations.Type; |
23 | import org.hibernate.annotations.TypeDef; | 22 | import org.hibernate.annotations.TypeDef; |
24 | -import org.thingsboard.server.common.data.UUIDConverter; | ||
25 | import org.thingsboard.server.common.data.id.RuleChainId; | 23 | import org.thingsboard.server.common.data.id.RuleChainId; |
26 | import org.thingsboard.server.common.data.id.RuleNodeId; | 24 | import org.thingsboard.server.common.data.id.RuleNodeId; |
27 | import org.thingsboard.server.common.data.id.TenantId; | 25 | import org.thingsboard.server.common.data.id.TenantId; |
@@ -35,6 +33,7 @@ import org.thingsboard.server.dao.util.mapping.JsonStringType; | @@ -35,6 +33,7 @@ import org.thingsboard.server.dao.util.mapping.JsonStringType; | ||
35 | import javax.persistence.Column; | 33 | import javax.persistence.Column; |
36 | import javax.persistence.Entity; | 34 | import javax.persistence.Entity; |
37 | import javax.persistence.Table; | 35 | import javax.persistence.Table; |
36 | +import java.util.UUID; | ||
38 | 37 | ||
39 | @Data | 38 | @Data |
40 | @EqualsAndHashCode(callSuper = true) | 39 | @EqualsAndHashCode(callSuper = true) |
@@ -44,7 +43,7 @@ import javax.persistence.Table; | @@ -44,7 +43,7 @@ import javax.persistence.Table; | ||
44 | public class RuleChainEntity extends BaseSqlEntity<RuleChain> implements SearchTextEntity<RuleChain> { | 43 | public class RuleChainEntity extends BaseSqlEntity<RuleChain> implements SearchTextEntity<RuleChain> { |
45 | 44 | ||
46 | @Column(name = ModelConstants.RULE_CHAIN_TENANT_ID_PROPERTY) | 45 | @Column(name = ModelConstants.RULE_CHAIN_TENANT_ID_PROPERTY) |
47 | - private String tenantId; | 46 | + private UUID tenantId; |
48 | 47 | ||
49 | @Column(name = ModelConstants.RULE_CHAIN_NAME_PROPERTY) | 48 | @Column(name = ModelConstants.RULE_CHAIN_NAME_PROPERTY) |
50 | private String name; | 49 | private String name; |
@@ -53,7 +52,7 @@ public class RuleChainEntity extends BaseSqlEntity<RuleChain> implements SearchT | @@ -53,7 +52,7 @@ public class RuleChainEntity extends BaseSqlEntity<RuleChain> implements SearchT | ||
53 | private String searchText; | 52 | private String searchText; |
54 | 53 | ||
55 | @Column(name = ModelConstants.RULE_CHAIN_FIRST_RULE_NODE_ID_PROPERTY) | 54 | @Column(name = ModelConstants.RULE_CHAIN_FIRST_RULE_NODE_ID_PROPERTY) |
56 | - private String firstRuleNodeId; | 55 | + private UUID firstRuleNodeId; |
57 | 56 | ||
58 | @Column(name = ModelConstants.RULE_CHAIN_ROOT_PROPERTY) | 57 | @Column(name = ModelConstants.RULE_CHAIN_ROOT_PROPERTY) |
59 | private boolean root; | 58 | private boolean root; |
@@ -76,11 +75,12 @@ public class RuleChainEntity extends BaseSqlEntity<RuleChain> implements SearchT | @@ -76,11 +75,12 @@ public class RuleChainEntity extends BaseSqlEntity<RuleChain> implements SearchT | ||
76 | if (ruleChain.getId() != null) { | 75 | if (ruleChain.getId() != null) { |
77 | this.setUuid(ruleChain.getUuidId()); | 76 | this.setUuid(ruleChain.getUuidId()); |
78 | } | 77 | } |
79 | - this.tenantId = toString(DaoUtil.getId(ruleChain.getTenantId())); | 78 | + this.setCreatedTime(ruleChain.getCreatedTime()); |
79 | + this.tenantId = DaoUtil.getId(ruleChain.getTenantId()); | ||
80 | this.name = ruleChain.getName(); | 80 | this.name = ruleChain.getName(); |
81 | this.searchText = ruleChain.getName(); | 81 | this.searchText = ruleChain.getName(); |
82 | if (ruleChain.getFirstRuleNodeId() != null) { | 82 | if (ruleChain.getFirstRuleNodeId() != null) { |
83 | - this.firstRuleNodeId = UUIDConverter.fromTimeUUID(ruleChain.getFirstRuleNodeId().getId()); | 83 | + this.firstRuleNodeId = ruleChain.getFirstRuleNodeId().getId(); |
84 | } | 84 | } |
85 | this.root = ruleChain.isRoot(); | 85 | this.root = ruleChain.isRoot(); |
86 | this.debugMode = ruleChain.isDebugMode(); | 86 | this.debugMode = ruleChain.isDebugMode(); |
@@ -101,11 +101,11 @@ public class RuleChainEntity extends BaseSqlEntity<RuleChain> implements SearchT | @@ -101,11 +101,11 @@ public class RuleChainEntity extends BaseSqlEntity<RuleChain> implements SearchT | ||
101 | @Override | 101 | @Override |
102 | public RuleChain toData() { | 102 | public RuleChain toData() { |
103 | RuleChain ruleChain = new RuleChain(new RuleChainId(this.getUuid())); | 103 | RuleChain ruleChain = new RuleChain(new RuleChainId(this.getUuid())); |
104 | - ruleChain.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | ||
105 | - ruleChain.setTenantId(new TenantId(toUUID(tenantId))); | 104 | + ruleChain.setCreatedTime(createdTime); |
105 | + ruleChain.setTenantId(new TenantId(tenantId)); | ||
106 | ruleChain.setName(name); | 106 | ruleChain.setName(name); |
107 | if (firstRuleNodeId != null) { | 107 | if (firstRuleNodeId != null) { |
108 | - ruleChain.setFirstRuleNodeId(new RuleNodeId(UUIDConverter.fromString(firstRuleNodeId))); | 108 | + ruleChain.setFirstRuleNodeId(new RuleNodeId(firstRuleNodeId)); |
109 | } | 109 | } |
110 | ruleChain.setRoot(root); | 110 | ruleChain.setRoot(root); |
111 | ruleChain.setDebugMode(debugMode); | 111 | ruleChain.setDebugMode(debugMode); |
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.sql; | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | ||
18 | -import com.datastax.oss.driver.api.core.uuid.Uuids; | ||
19 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 19 | import lombok.Data; |
21 | import lombok.EqualsAndHashCode; | 20 | import lombok.EqualsAndHashCode; |
@@ -33,6 +32,7 @@ import org.thingsboard.server.dao.util.mapping.JsonStringType; | @@ -33,6 +32,7 @@ import org.thingsboard.server.dao.util.mapping.JsonStringType; | ||
33 | import javax.persistence.Column; | 32 | import javax.persistence.Column; |
34 | import javax.persistence.Entity; | 33 | import javax.persistence.Entity; |
35 | import javax.persistence.Table; | 34 | import javax.persistence.Table; |
35 | +import java.util.UUID; | ||
36 | 36 | ||
37 | @Data | 37 | @Data |
38 | @EqualsAndHashCode(callSuper = true) | 38 | @EqualsAndHashCode(callSuper = true) |
@@ -42,7 +42,7 @@ import javax.persistence.Table; | @@ -42,7 +42,7 @@ import javax.persistence.Table; | ||
42 | public class RuleNodeEntity extends BaseSqlEntity<RuleNode> implements SearchTextEntity<RuleNode> { | 42 | public class RuleNodeEntity extends BaseSqlEntity<RuleNode> implements SearchTextEntity<RuleNode> { |
43 | 43 | ||
44 | @Column(name = ModelConstants.RULE_NODE_CHAIN_ID_PROPERTY) | 44 | @Column(name = ModelConstants.RULE_NODE_CHAIN_ID_PROPERTY) |
45 | - private String ruleChainId; | 45 | + private UUID ruleChainId; |
46 | 46 | ||
47 | @Column(name = ModelConstants.RULE_NODE_TYPE_PROPERTY) | 47 | @Column(name = ModelConstants.RULE_NODE_TYPE_PROPERTY) |
48 | private String type; | 48 | private String type; |
@@ -71,8 +71,9 @@ public class RuleNodeEntity extends BaseSqlEntity<RuleNode> implements SearchTex | @@ -71,8 +71,9 @@ public class RuleNodeEntity extends BaseSqlEntity<RuleNode> implements SearchTex | ||
71 | if (ruleNode.getId() != null) { | 71 | if (ruleNode.getId() != null) { |
72 | this.setUuid(ruleNode.getUuidId()); | 72 | this.setUuid(ruleNode.getUuidId()); |
73 | } | 73 | } |
74 | + this.setCreatedTime(ruleNode.getCreatedTime()); | ||
74 | if (ruleNode.getRuleChainId() != null) { | 75 | if (ruleNode.getRuleChainId() != null) { |
75 | - this.ruleChainId = toString(DaoUtil.getId(ruleNode.getRuleChainId())); | 76 | + this.ruleChainId = DaoUtil.getId(ruleNode.getRuleChainId()); |
76 | } | 77 | } |
77 | this.type = ruleNode.getType(); | 78 | this.type = ruleNode.getType(); |
78 | this.name = ruleNode.getName(); | 79 | this.name = ruleNode.getName(); |
@@ -95,9 +96,9 @@ public class RuleNodeEntity extends BaseSqlEntity<RuleNode> implements SearchTex | @@ -95,9 +96,9 @@ public class RuleNodeEntity extends BaseSqlEntity<RuleNode> implements SearchTex | ||
95 | @Override | 96 | @Override |
96 | public RuleNode toData() { | 97 | public RuleNode toData() { |
97 | RuleNode ruleNode = new RuleNode(new RuleNodeId(this.getUuid())); | 98 | RuleNode ruleNode = new RuleNode(new RuleNodeId(this.getUuid())); |
98 | - ruleNode.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | 99 | + ruleNode.setCreatedTime(createdTime); |
99 | if (ruleChainId != null) { | 100 | if (ruleChainId != null) { |
100 | - ruleNode.setRuleChainId(new RuleChainId(toUUID(ruleChainId))); | 101 | + ruleNode.setRuleChainId(new RuleChainId(ruleChainId)); |
101 | } | 102 | } |
102 | ruleNode.setType(type); | 103 | ruleNode.setType(type); |
103 | ruleNode.setName(name); | 104 | ruleNode.setName(name); |
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.sql; | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | ||
18 | -import com.datastax.oss.driver.api.core.uuid.Uuids; | ||
19 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 19 | import lombok.Data; |
21 | import lombok.EqualsAndHashCode; | 20 | import lombok.EqualsAndHashCode; |
@@ -90,6 +89,7 @@ public final class TenantEntity extends BaseSqlEntity<Tenant> implements SearchT | @@ -90,6 +89,7 @@ public final class TenantEntity extends BaseSqlEntity<Tenant> implements SearchT | ||
90 | if (tenant.getId() != null) { | 89 | if (tenant.getId() != null) { |
91 | this.setUuid(tenant.getId().getId()); | 90 | this.setUuid(tenant.getId().getId()); |
92 | } | 91 | } |
92 | + this.setCreatedTime(tenant.getCreatedTime()); | ||
93 | this.title = tenant.getTitle(); | 93 | this.title = tenant.getTitle(); |
94 | this.region = tenant.getRegion(); | 94 | this.region = tenant.getRegion(); |
95 | this.country = tenant.getCountry(); | 95 | this.country = tenant.getCountry(); |
@@ -122,7 +122,7 @@ public final class TenantEntity extends BaseSqlEntity<Tenant> implements SearchT | @@ -122,7 +122,7 @@ public final class TenantEntity extends BaseSqlEntity<Tenant> implements SearchT | ||
122 | @Override | 122 | @Override |
123 | public Tenant toData() { | 123 | public Tenant toData() { |
124 | Tenant tenant = new Tenant(new TenantId(this.getUuid())); | 124 | Tenant tenant = new Tenant(new TenantId(this.getUuid())); |
125 | - tenant.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | 125 | + tenant.setCreatedTime(createdTime); |
126 | tenant.setTitle(title); | 126 | tenant.setTitle(title); |
127 | tenant.setRegion(region); | 127 | tenant.setRegion(region); |
128 | tenant.setCountry(country); | 128 | tenant.setCountry(country); |
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.sql; | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | ||
18 | -import com.datastax.oss.driver.api.core.uuid.Uuids; | ||
19 | import lombok.Data; | 18 | import lombok.Data; |
20 | import lombok.EqualsAndHashCode; | 19 | import lombok.EqualsAndHashCode; |
21 | import org.thingsboard.server.common.data.id.UserCredentialsId; | 20 | import org.thingsboard.server.common.data.id.UserCredentialsId; |
@@ -28,6 +27,7 @@ import org.thingsboard.server.dao.model.ModelConstants; | @@ -28,6 +27,7 @@ import org.thingsboard.server.dao.model.ModelConstants; | ||
28 | import javax.persistence.Column; | 27 | import javax.persistence.Column; |
29 | import javax.persistence.Entity; | 28 | import javax.persistence.Entity; |
30 | import javax.persistence.Table; | 29 | import javax.persistence.Table; |
30 | +import java.util.UUID; | ||
31 | 31 | ||
32 | @Data | 32 | @Data |
33 | @EqualsAndHashCode(callSuper = true) | 33 | @EqualsAndHashCode(callSuper = true) |
@@ -36,7 +36,7 @@ import javax.persistence.Table; | @@ -36,7 +36,7 @@ import javax.persistence.Table; | ||
36 | public final class UserCredentialsEntity extends BaseSqlEntity<UserCredentials> implements BaseEntity<UserCredentials> { | 36 | public final class UserCredentialsEntity extends BaseSqlEntity<UserCredentials> implements BaseEntity<UserCredentials> { |
37 | 37 | ||
38 | @Column(name = ModelConstants.USER_CREDENTIALS_USER_ID_PROPERTY, unique = true) | 38 | @Column(name = ModelConstants.USER_CREDENTIALS_USER_ID_PROPERTY, unique = true) |
39 | - private String userId; | 39 | + private UUID userId; |
40 | 40 | ||
41 | @Column(name = ModelConstants.USER_CREDENTIALS_ENABLED_PROPERTY) | 41 | @Column(name = ModelConstants.USER_CREDENTIALS_ENABLED_PROPERTY) |
42 | private boolean enabled; | 42 | private boolean enabled; |
@@ -58,8 +58,9 @@ public final class UserCredentialsEntity extends BaseSqlEntity<UserCredentials> | @@ -58,8 +58,9 @@ public final class UserCredentialsEntity extends BaseSqlEntity<UserCredentials> | ||
58 | if (userCredentials.getId() != null) { | 58 | if (userCredentials.getId() != null) { |
59 | this.setUuid(userCredentials.getId().getId()); | 59 | this.setUuid(userCredentials.getId().getId()); |
60 | } | 60 | } |
61 | + this.setCreatedTime(userCredentials.getCreatedTime()); | ||
61 | if (userCredentials.getUserId() != null) { | 62 | if (userCredentials.getUserId() != null) { |
62 | - this.userId = toString(userCredentials.getUserId().getId()); | 63 | + this.userId = userCredentials.getUserId().getId(); |
63 | } | 64 | } |
64 | this.enabled = userCredentials.isEnabled(); | 65 | this.enabled = userCredentials.isEnabled(); |
65 | this.password = userCredentials.getPassword(); | 66 | this.password = userCredentials.getPassword(); |
@@ -70,9 +71,9 @@ public final class UserCredentialsEntity extends BaseSqlEntity<UserCredentials> | @@ -70,9 +71,9 @@ public final class UserCredentialsEntity extends BaseSqlEntity<UserCredentials> | ||
70 | @Override | 71 | @Override |
71 | public UserCredentials toData() { | 72 | public UserCredentials toData() { |
72 | UserCredentials userCredentials = new UserCredentials(new UserCredentialsId(this.getUuid())); | 73 | UserCredentials userCredentials = new UserCredentials(new UserCredentialsId(this.getUuid())); |
73 | - userCredentials.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | 74 | + userCredentials.setCreatedTime(createdTime); |
74 | if (userId != null) { | 75 | if (userId != null) { |
75 | - userCredentials.setUserId(new UserId(toUUID(userId))); | 76 | + userCredentials.setUserId(new UserId(userId)); |
76 | } | 77 | } |
77 | userCredentials.setEnabled(enabled); | 78 | userCredentials.setEnabled(enabled); |
78 | userCredentials.setPassword(password); | 79 | userCredentials.setPassword(password); |
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.sql; | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | ||
18 | -import com.datastax.oss.driver.api.core.uuid.Uuids; | ||
19 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 19 | import lombok.Data; |
21 | import lombok.EqualsAndHashCode; | 20 | import lombok.EqualsAndHashCode; |
@@ -36,9 +35,7 @@ import javax.persistence.Entity; | @@ -36,9 +35,7 @@ import javax.persistence.Entity; | ||
36 | import javax.persistence.EnumType; | 35 | import javax.persistence.EnumType; |
37 | import javax.persistence.Enumerated; | 36 | import javax.persistence.Enumerated; |
38 | import javax.persistence.Table; | 37 | import javax.persistence.Table; |
39 | - | ||
40 | -import static org.thingsboard.server.common.data.UUIDConverter.fromString; | ||
41 | -import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID; | 38 | +import java.util.UUID; |
42 | 39 | ||
43 | /** | 40 | /** |
44 | * Created by Valerii Sosliuk on 4/21/2017. | 41 | * Created by Valerii Sosliuk on 4/21/2017. |
@@ -51,10 +48,10 @@ import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID; | @@ -51,10 +48,10 @@ import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID; | ||
51 | public class UserEntity extends BaseSqlEntity<User> implements SearchTextEntity<User> { | 48 | public class UserEntity extends BaseSqlEntity<User> implements SearchTextEntity<User> { |
52 | 49 | ||
53 | @Column(name = ModelConstants.USER_TENANT_ID_PROPERTY) | 50 | @Column(name = ModelConstants.USER_TENANT_ID_PROPERTY) |
54 | - private String tenantId; | 51 | + private UUID tenantId; |
55 | 52 | ||
56 | @Column(name = ModelConstants.USER_CUSTOMER_ID_PROPERTY) | 53 | @Column(name = ModelConstants.USER_CUSTOMER_ID_PROPERTY) |
57 | - private String customerId; | 54 | + private UUID customerId; |
58 | 55 | ||
59 | @Enumerated(EnumType.STRING) | 56 | @Enumerated(EnumType.STRING) |
60 | @Column(name = ModelConstants.USER_AUTHORITY_PROPERTY) | 57 | @Column(name = ModelConstants.USER_AUTHORITY_PROPERTY) |
@@ -83,12 +80,13 @@ public class UserEntity extends BaseSqlEntity<User> implements SearchTextEntity< | @@ -83,12 +80,13 @@ public class UserEntity extends BaseSqlEntity<User> implements SearchTextEntity< | ||
83 | if (user.getId() != null) { | 80 | if (user.getId() != null) { |
84 | this.setUuid(user.getId().getId()); | 81 | this.setUuid(user.getId().getId()); |
85 | } | 82 | } |
83 | + this.setCreatedTime(user.getCreatedTime()); | ||
86 | this.authority = user.getAuthority(); | 84 | this.authority = user.getAuthority(); |
87 | if (user.getTenantId() != null) { | 85 | if (user.getTenantId() != null) { |
88 | - this.tenantId = fromTimeUUID(user.getTenantId().getId()); | 86 | + this.tenantId = user.getTenantId().getId(); |
89 | } | 87 | } |
90 | if (user.getCustomerId() != null) { | 88 | if (user.getCustomerId() != null) { |
91 | - this.customerId = fromTimeUUID(user.getCustomerId().getId()); | 89 | + this.customerId = user.getCustomerId().getId(); |
92 | } | 90 | } |
93 | this.email = user.getEmail(); | 91 | this.email = user.getEmail(); |
94 | this.firstName = user.getFirstName(); | 92 | this.firstName = user.getFirstName(); |
@@ -109,13 +107,13 @@ public class UserEntity extends BaseSqlEntity<User> implements SearchTextEntity< | @@ -109,13 +107,13 @@ public class UserEntity extends BaseSqlEntity<User> implements SearchTextEntity< | ||
109 | @Override | 107 | @Override |
110 | public User toData() { | 108 | public User toData() { |
111 | User user = new User(new UserId(this.getUuid())); | 109 | User user = new User(new UserId(this.getUuid())); |
112 | - user.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | 110 | + user.setCreatedTime(createdTime); |
113 | user.setAuthority(authority); | 111 | user.setAuthority(authority); |
114 | if (tenantId != null) { | 112 | if (tenantId != null) { |
115 | - user.setTenantId(new TenantId(fromString(tenantId))); | 113 | + user.setTenantId(new TenantId(tenantId)); |
116 | } | 114 | } |
117 | if (customerId != null) { | 115 | if (customerId != null) { |
118 | - user.setCustomerId(new CustomerId(fromString(customerId))); | 116 | + user.setCustomerId(new CustomerId(customerId)); |
119 | } | 117 | } |
120 | user.setEmail(email); | 118 | user.setEmail(email); |
121 | user.setFirstName(firstName); | 119 | user.setFirstName(firstName); |
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.sql; | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | ||
18 | -import com.datastax.oss.driver.api.core.uuid.Uuids; | ||
19 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 19 | import lombok.Data; |
21 | import lombok.EqualsAndHashCode; | 20 | import lombok.EqualsAndHashCode; |
@@ -32,6 +31,7 @@ import org.thingsboard.server.dao.util.mapping.JsonStringType; | @@ -32,6 +31,7 @@ import org.thingsboard.server.dao.util.mapping.JsonStringType; | ||
32 | import javax.persistence.Column; | 31 | import javax.persistence.Column; |
33 | import javax.persistence.Entity; | 32 | import javax.persistence.Entity; |
34 | import javax.persistence.Table; | 33 | import javax.persistence.Table; |
34 | +import java.util.UUID; | ||
35 | 35 | ||
36 | @Data | 36 | @Data |
37 | @EqualsAndHashCode(callSuper = true) | 37 | @EqualsAndHashCode(callSuper = true) |
@@ -41,7 +41,7 @@ import javax.persistence.Table; | @@ -41,7 +41,7 @@ import javax.persistence.Table; | ||
41 | public final class WidgetTypeEntity extends BaseSqlEntity<WidgetType> implements BaseEntity<WidgetType> { | 41 | public final class WidgetTypeEntity extends BaseSqlEntity<WidgetType> implements BaseEntity<WidgetType> { |
42 | 42 | ||
43 | @Column(name = ModelConstants.WIDGET_TYPE_TENANT_ID_PROPERTY) | 43 | @Column(name = ModelConstants.WIDGET_TYPE_TENANT_ID_PROPERTY) |
44 | - private String tenantId; | 44 | + private UUID tenantId; |
45 | 45 | ||
46 | @Column(name = ModelConstants.WIDGET_TYPE_BUNDLE_ALIAS_PROPERTY) | 46 | @Column(name = ModelConstants.WIDGET_TYPE_BUNDLE_ALIAS_PROPERTY) |
47 | private String bundleAlias; | 47 | private String bundleAlias; |
@@ -64,8 +64,9 @@ public final class WidgetTypeEntity extends BaseSqlEntity<WidgetType> implement | @@ -64,8 +64,9 @@ public final class WidgetTypeEntity extends BaseSqlEntity<WidgetType> implement | ||
64 | if (widgetType.getId() != null) { | 64 | if (widgetType.getId() != null) { |
65 | this.setUuid(widgetType.getId().getId()); | 65 | this.setUuid(widgetType.getId().getId()); |
66 | } | 66 | } |
67 | + this.setCreatedTime(widgetType.getCreatedTime()); | ||
67 | if (widgetType.getTenantId() != null) { | 68 | if (widgetType.getTenantId() != null) { |
68 | - this.tenantId = toString(widgetType.getTenantId().getId()); | 69 | + this.tenantId = widgetType.getTenantId().getId(); |
69 | } | 70 | } |
70 | this.bundleAlias = widgetType.getBundleAlias(); | 71 | this.bundleAlias = widgetType.getBundleAlias(); |
71 | this.alias = widgetType.getAlias(); | 72 | this.alias = widgetType.getAlias(); |
@@ -76,9 +77,9 @@ public final class WidgetTypeEntity extends BaseSqlEntity<WidgetType> implement | @@ -76,9 +77,9 @@ public final class WidgetTypeEntity extends BaseSqlEntity<WidgetType> implement | ||
76 | @Override | 77 | @Override |
77 | public WidgetType toData() { | 78 | public WidgetType toData() { |
78 | WidgetType widgetType = new WidgetType(new WidgetTypeId(this.getUuid())); | 79 | WidgetType widgetType = new WidgetType(new WidgetTypeId(this.getUuid())); |
79 | - widgetType.setCreatedTime(Uuids.unixTimestamp(this.getUuid())); | 80 | + widgetType.setCreatedTime(createdTime); |
80 | if (tenantId != null) { | 81 | if (tenantId != null) { |
81 | - widgetType.setTenantId(new TenantId(toUUID(tenantId))); | 82 | + widgetType.setTenantId(new TenantId(tenantId)); |
82 | } | 83 | } |
83 | widgetType.setBundleAlias(bundleAlias); | 84 | widgetType.setBundleAlias(bundleAlias); |
84 | widgetType.setAlias(alias); | 85 | widgetType.setAlias(alias); |
@@ -16,10 +16,8 @@ | @@ -16,10 +16,8 @@ | ||
16 | package org.thingsboard.server.dao.model.sql; | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | ||
18 | 18 | ||
19 | -import com.datastax.oss.driver.api.core.uuid.Uuids; | ||
20 | import lombok.Data; | 19 | import lombok.Data; |
21 | import lombok.EqualsAndHashCode; | 20 | import lombok.EqualsAndHashCode; |
22 | -import org.thingsboard.server.common.data.UUIDConverter; | ||
23 | import org.thingsboard.server.common.data.id.TenantId; | 21 | import org.thingsboard.server.common.data.id.TenantId; |
24 | import org.thingsboard.server.common.data.id.WidgetsBundleId; | 22 | import org.thingsboard.server.common.data.id.WidgetsBundleId; |
25 | import org.thingsboard.server.common.data.widget.WidgetsBundle; | 23 | import org.thingsboard.server.common.data.widget.WidgetsBundle; |
@@ -30,6 +28,7 @@ import org.thingsboard.server.dao.model.SearchTextEntity; | @@ -30,6 +28,7 @@ import org.thingsboard.server.dao.model.SearchTextEntity; | ||
30 | import javax.persistence.Column; | 28 | import javax.persistence.Column; |
31 | import javax.persistence.Entity; | 29 | import javax.persistence.Entity; |
32 | import javax.persistence.Table; | 30 | import javax.persistence.Table; |
31 | +import java.util.UUID; | ||
33 | 32 | ||
34 | @Data | 33 | @Data |
35 | @EqualsAndHashCode(callSuper = true) | 34 | @EqualsAndHashCode(callSuper = true) |
@@ -38,7 +37,7 @@ import javax.persistence.Table; | @@ -38,7 +37,7 @@ import javax.persistence.Table; | ||
38 | public final class WidgetsBundleEntity extends BaseSqlEntity<WidgetsBundle> implements SearchTextEntity<WidgetsBundle> { | 37 | public final class WidgetsBundleEntity extends BaseSqlEntity<WidgetsBundle> implements SearchTextEntity<WidgetsBundle> { |
39 | 38 | ||
40 | @Column(name = ModelConstants.WIDGETS_BUNDLE_TENANT_ID_PROPERTY) | 39 | @Column(name = ModelConstants.WIDGETS_BUNDLE_TENANT_ID_PROPERTY) |
41 | - private String tenantId; | 40 | + private UUID tenantId; |
42 | 41 | ||
43 | @Column(name = ModelConstants.WIDGETS_BUNDLE_ALIAS_PROPERTY) | 42 | @Column(name = ModelConstants.WIDGETS_BUNDLE_ALIAS_PROPERTY) |
44 | private String alias; | 43 | private String alias; |
@@ -57,8 +56,9 @@ public final class WidgetsBundleEntity extends BaseSqlEntity<WidgetsBundle> impl | @@ -57,8 +56,9 @@ public final class WidgetsBundleEntity extends BaseSqlEntity<WidgetsBundle> impl | ||
57 | if (widgetsBundle.getId() != null) { | 56 | if (widgetsBundle.getId() != null) { |
58 | this.setUuid(widgetsBundle.getId().getId()); | 57 | this.setUuid(widgetsBundle.getId().getId()); |
59 | } | 58 | } |
59 | + this.setCreatedTime(widgetsBundle.getCreatedTime()); | ||
60 | if (widgetsBundle.getTenantId() != null) { | 60 | if (widgetsBundle.getTenantId() != null) { |
61 | - this.tenantId = UUIDConverter.fromTimeUUID(widgetsBundle.getTenantId().getId()); | 61 | + this.tenantId = widgetsBundle.getTenantId().getId(); |
62 | } | 62 | } |
63 | this.alias = widgetsBundle.getAlias(); | 63 | this.alias = widgetsBundle.getAlias(); |
64 | this.title = widgetsBundle.getTitle(); | 64 | this.title = widgetsBundle.getTitle(); |
@@ -76,10 +76,10 @@ public final class WidgetsBundleEntity extends BaseSqlEntity<WidgetsBundle> impl | @@ -76,10 +76,10 @@ public final class WidgetsBundleEntity extends BaseSqlEntity<WidgetsBundle> impl | ||
76 | 76 | ||
77 | @Override | 77 | @Override |
78 | public WidgetsBundle toData() { | 78 | public WidgetsBundle toData() { |
79 | - WidgetsBundle widgetsBundle = new WidgetsBundle(new WidgetsBundleId(UUIDConverter.fromString(id))); | ||
80 | - widgetsBundle.setCreatedTime(Uuids.unixTimestamp(UUIDConverter.fromString(id))); | 79 | + WidgetsBundle widgetsBundle = new WidgetsBundle(new WidgetsBundleId(id)); |
80 | + widgetsBundle.setCreatedTime(createdTime); | ||
81 | if (tenantId != null) { | 81 | if (tenantId != null) { |
82 | - widgetsBundle.setTenantId(new TenantId(UUIDConverter.fromString(tenantId))); | 82 | + widgetsBundle.setTenantId(new TenantId(tenantId)); |
83 | } | 83 | } |
84 | widgetsBundle.setAlias(alias); | 84 | widgetsBundle.setAlias(alias); |
85 | widgetsBundle.setTitle(title); | 85 | widgetsBundle.setTitle(title); |
@@ -18,7 +18,6 @@ package org.thingsboard.server.dao.model.sqlts.latest; | @@ -18,7 +18,6 @@ package org.thingsboard.server.dao.model.sqlts.latest; | ||
18 | import lombok.AllArgsConstructor; | 18 | import lombok.AllArgsConstructor; |
19 | import lombok.Data; | 19 | import lombok.Data; |
20 | import lombok.NoArgsConstructor; | 20 | import lombok.NoArgsConstructor; |
21 | -import org.thingsboard.server.common.data.EntityType; | ||
22 | 21 | ||
23 | import javax.persistence.Transient; | 22 | import javax.persistence.Transient; |
24 | import java.io.Serializable; | 23 | import java.io.Serializable; |
@@ -19,11 +19,9 @@ import lombok.Data; | @@ -19,11 +19,9 @@ import lombok.Data; | ||
19 | import org.thingsboard.server.dao.model.sql.AbstractTsKvEntity; | 19 | import org.thingsboard.server.dao.model.sql.AbstractTsKvEntity; |
20 | import org.thingsboard.server.dao.sqlts.latest.SearchTsKvLatestRepository; | 20 | import org.thingsboard.server.dao.sqlts.latest.SearchTsKvLatestRepository; |
21 | 21 | ||
22 | -import javax.persistence.Column; | ||
23 | import javax.persistence.ColumnResult; | 22 | import javax.persistence.ColumnResult; |
24 | import javax.persistence.ConstructorResult; | 23 | import javax.persistence.ConstructorResult; |
25 | import javax.persistence.Entity; | 24 | import javax.persistence.Entity; |
26 | -import javax.persistence.Id; | ||
27 | import javax.persistence.IdClass; | 25 | import javax.persistence.IdClass; |
28 | import javax.persistence.NamedNativeQueries; | 26 | import javax.persistence.NamedNativeQueries; |
29 | import javax.persistence.NamedNativeQuery; | 27 | import javax.persistence.NamedNativeQuery; |
@@ -32,8 +30,6 @@ import javax.persistence.SqlResultSetMappings; | @@ -32,8 +30,6 @@ import javax.persistence.SqlResultSetMappings; | ||
32 | import javax.persistence.Table; | 30 | import javax.persistence.Table; |
33 | import java.util.UUID; | 31 | import java.util.UUID; |
34 | 32 | ||
35 | -import static org.thingsboard.server.dao.model.ModelConstants.KEY_COLUMN; | ||
36 | - | ||
37 | @Data | 33 | @Data |
38 | @Entity | 34 | @Entity |
39 | @Table(name = "ts_kv_latest") | 35 | @Table(name = "ts_kv_latest") |
@@ -18,14 +18,10 @@ package org.thingsboard.server.dao.model.sqlts.ts; | @@ -18,14 +18,10 @@ package org.thingsboard.server.dao.model.sqlts.ts; | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | import org.thingsboard.server.dao.model.sql.AbstractTsKvEntity; | 19 | import org.thingsboard.server.dao.model.sql.AbstractTsKvEntity; |
20 | 20 | ||
21 | -import javax.persistence.Column; | ||
22 | import javax.persistence.Entity; | 21 | import javax.persistence.Entity; |
23 | -import javax.persistence.Id; | ||
24 | import javax.persistence.IdClass; | 22 | import javax.persistence.IdClass; |
25 | import javax.persistence.Table; | 23 | import javax.persistence.Table; |
26 | 24 | ||
27 | -import static org.thingsboard.server.dao.model.ModelConstants.KEY_COLUMN; | ||
28 | - | ||
29 | @Data | 25 | @Data |
30 | @Entity | 26 | @Entity |
31 | @Table(name = "ts_kv") | 27 | @Table(name = "ts_kv") |
@@ -15,10 +15,7 @@ | @@ -15,10 +15,7 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.nosql; | 16 | package org.thingsboard.server.dao.nosql; |
17 | 17 | ||
18 | -import com.datastax.oss.driver.api.core.cql.AsyncResultSet; | ||
19 | -import com.datastax.oss.driver.api.core.cql.Row; | ||
20 | import com.google.common.base.Function; | 18 | import com.google.common.base.Function; |
21 | -import com.google.common.collect.Lists; | ||
22 | import com.google.common.util.concurrent.AsyncFunction; | 19 | import com.google.common.util.concurrent.AsyncFunction; |
23 | import com.google.common.util.concurrent.Futures; | 20 | import com.google.common.util.concurrent.Futures; |
24 | import com.google.common.util.concurrent.ListenableFuture; | 21 | import com.google.common.util.concurrent.ListenableFuture; |
@@ -27,11 +24,8 @@ import org.thingsboard.common.util.ThingsBoardThreadFactory; | @@ -27,11 +24,8 @@ import org.thingsboard.common.util.ThingsBoardThreadFactory; | ||
27 | import javax.annotation.Nullable; | 24 | import javax.annotation.Nullable; |
28 | import javax.annotation.PostConstruct; | 25 | import javax.annotation.PostConstruct; |
29 | import javax.annotation.PreDestroy; | 26 | import javax.annotation.PreDestroy; |
30 | -import java.util.ArrayList; | ||
31 | -import java.util.List; | ||
32 | import java.util.concurrent.ExecutorService; | 27 | import java.util.concurrent.ExecutorService; |
33 | import java.util.concurrent.Executors; | 28 | import java.util.concurrent.Executors; |
34 | -import java.util.stream.Collectors; | ||
35 | 29 | ||
36 | /** | 30 | /** |
37 | * Created by ashvayka on 21.02.17. | 31 | * Created by ashvayka on 21.02.17. |
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.nosql; | 16 | package org.thingsboard.server.dao.nosql; |
17 | 17 | ||
18 | -import com.datastax.oss.driver.api.core.cql.AsyncResultSet; | ||
19 | import com.google.common.util.concurrent.ListenableFuture; | 18 | import com.google.common.util.concurrent.ListenableFuture; |
20 | import com.google.common.util.concurrent.SettableFuture; | 19 | import com.google.common.util.concurrent.SettableFuture; |
21 | import lombok.extern.slf4j.Slf4j; | 20 | import lombok.extern.slf4j.Slf4j; |
@@ -59,6 +59,4 @@ public interface RelationDao { | @@ -59,6 +59,4 @@ public interface RelationDao { | ||
59 | 59 | ||
60 | ListenableFuture<Boolean> deleteOutboundRelationsAsync(TenantId tenantId, EntityId entity); | 60 | ListenableFuture<Boolean> deleteOutboundRelationsAsync(TenantId tenantId, EntityId entity); |
61 | 61 | ||
62 | - ListenableFuture<PageData<EntityRelation>> findRelations(TenantId tenantId, EntityId from, String relationType, RelationTypeGroup typeGroup, EntityType toType, TimePageLink pageLink); | ||
63 | - | ||
64 | } | 62 | } |
@@ -48,7 +48,6 @@ import java.util.HashMap; | @@ -48,7 +48,6 @@ import java.util.HashMap; | ||
48 | import java.util.List; | 48 | import java.util.List; |
49 | import java.util.Map; | 49 | import java.util.Map; |
50 | import java.util.concurrent.ExecutionException; | 50 | import java.util.concurrent.ExecutionException; |
51 | -import java.util.stream.Collectors; | ||
52 | 51 | ||
53 | /** | 52 | /** |
54 | * Created by igor on 3/12/18. | 53 | * Created by igor on 3/12/18. |
@@ -20,7 +20,6 @@ import org.thingsboard.server.common.data.page.PageLink; | @@ -20,7 +20,6 @@ import org.thingsboard.server.common.data.page.PageLink; | ||
20 | import org.thingsboard.server.common.data.rule.RuleChain; | 20 | import org.thingsboard.server.common.data.rule.RuleChain; |
21 | import org.thingsboard.server.dao.Dao; | 21 | import org.thingsboard.server.dao.Dao; |
22 | 22 | ||
23 | -import java.util.List; | ||
24 | import java.util.UUID; | 23 | import java.util.UUID; |
25 | 24 | ||
26 | /** | 25 | /** |
@@ -20,9 +20,6 @@ import org.thingsboard.server.common.data.id.TenantId; | @@ -20,9 +20,6 @@ import org.thingsboard.server.common.data.id.TenantId; | ||
20 | import org.thingsboard.server.common.data.page.PageData; | 20 | import org.thingsboard.server.common.data.page.PageData; |
21 | import org.thingsboard.server.common.data.page.PageLink; | 21 | import org.thingsboard.server.common.data.page.PageLink; |
22 | 22 | ||
23 | -import java.util.List; | ||
24 | -import java.util.UUID; | ||
25 | - | ||
26 | public abstract class PaginatedRemover<I, D extends IdBased<?>> { | 23 | public abstract class PaginatedRemover<I, D extends IdBased<?>> { |
27 | 24 | ||
28 | private static final int DEFAULT_LIMIT = 100; | 25 | private static final int DEFAULT_LIMIT = 100; |
@@ -20,9 +20,6 @@ import org.thingsboard.server.common.data.id.TenantId; | @@ -20,9 +20,6 @@ import org.thingsboard.server.common.data.id.TenantId; | ||
20 | import org.thingsboard.server.common.data.page.PageData; | 20 | import org.thingsboard.server.common.data.page.PageData; |
21 | import org.thingsboard.server.common.data.page.TimePageLink; | 21 | import org.thingsboard.server.common.data.page.TimePageLink; |
22 | 22 | ||
23 | -import java.util.List; | ||
24 | -import java.util.UUID; | ||
25 | - | ||
26 | public abstract class TimePaginatedRemover<I, D extends IdBased<?>> { | 23 | public abstract class TimePaginatedRemover<I, D extends IdBased<?>> { |
27 | 24 | ||
28 | private static final int DEFAULT_LIMIT = 100; | 25 | private static final int DEFAULT_LIMIT = 100; |
@@ -20,7 +20,6 @@ import org.apache.commons.lang3.StringUtils; | @@ -20,7 +20,6 @@ import org.apache.commons.lang3.StringUtils; | ||
20 | import org.springframework.beans.factory.annotation.Autowired; | 20 | import org.springframework.beans.factory.annotation.Autowired; |
21 | import org.springframework.stereotype.Service; | 21 | import org.springframework.stereotype.Service; |
22 | import org.thingsboard.server.common.data.AdminSettings; | 22 | import org.thingsboard.server.common.data.AdminSettings; |
23 | -import org.thingsboard.server.common.data.Tenant; | ||
24 | import org.thingsboard.server.common.data.id.AdminSettingsId; | 23 | import org.thingsboard.server.common.data.id.AdminSettingsId; |
25 | import org.thingsboard.server.common.data.id.TenantId; | 24 | import org.thingsboard.server.common.data.id.TenantId; |
26 | import org.thingsboard.server.dao.exception.DataValidationException; | 25 | import org.thingsboard.server.dao.exception.DataValidationException; |
@@ -30,8 +30,6 @@ import java.util.List; | @@ -30,8 +30,6 @@ import java.util.List; | ||
30 | import java.util.Optional; | 30 | import java.util.Optional; |
31 | import java.util.UUID; | 31 | import java.util.UUID; |
32 | 32 | ||
33 | -import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID; | ||
34 | - | ||
35 | /** | 33 | /** |
36 | * @author Valerii Sosliuk | 34 | * @author Valerii Sosliuk |
37 | */ | 35 | */ |
@@ -42,9 +40,10 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> | @@ -42,9 +40,10 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> | ||
42 | 40 | ||
43 | protected abstract Class<E> getEntityClass(); | 41 | protected abstract Class<E> getEntityClass(); |
44 | 42 | ||
45 | - protected abstract CrudRepository<E, String> getCrudRepository(); | 43 | + protected abstract CrudRepository<E, UUID> getCrudRepository(); |
46 | 44 | ||
47 | - protected void setSearchText(E entity) {} | 45 | + protected void setSearchText(E entity) { |
46 | + } | ||
48 | 47 | ||
49 | @Override | 48 | @Override |
50 | @Transactional | 49 | @Transactional |
@@ -59,7 +58,9 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> | @@ -59,7 +58,9 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> | ||
59 | setSearchText(entity); | 58 | setSearchText(entity); |
60 | log.debug("Saving entity {}", entity); | 59 | log.debug("Saving entity {}", entity); |
61 | if (entity.getUuid() == null) { | 60 | if (entity.getUuid() == null) { |
62 | - entity.setUuid(Uuids.timeBased()); | 61 | + UUID uuid = Uuids.timeBased(); |
62 | + entity.setUuid(uuid); | ||
63 | + entity.setCreatedTime(Uuids.unixTimestamp(uuid)); | ||
63 | } | 64 | } |
64 | entity = getCrudRepository().save(entity); | 65 | entity = getCrudRepository().save(entity); |
65 | return DaoUtil.getData(entity); | 66 | return DaoUtil.getData(entity); |
@@ -68,23 +69,22 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> | @@ -68,23 +69,22 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> | ||
68 | @Override | 69 | @Override |
69 | public D findById(TenantId tenantId, UUID key) { | 70 | public D findById(TenantId tenantId, UUID key) { |
70 | log.debug("Get entity by key {}", key); | 71 | log.debug("Get entity by key {}", key); |
71 | - Optional<E> entity = getCrudRepository().findById(fromTimeUUID(key)); | 72 | + Optional<E> entity = getCrudRepository().findById(key); |
72 | return DaoUtil.getData(entity); | 73 | return DaoUtil.getData(entity); |
73 | } | 74 | } |
74 | 75 | ||
75 | @Override | 76 | @Override |
76 | public ListenableFuture<D> findByIdAsync(TenantId tenantId, UUID key) { | 77 | public ListenableFuture<D> findByIdAsync(TenantId tenantId, UUID key) { |
77 | log.debug("Get entity by key async {}", key); | 78 | log.debug("Get entity by key async {}", key); |
78 | - return service.submit(() -> DaoUtil.getData(getCrudRepository().findById(fromTimeUUID(key)))); | 79 | + return service.submit(() -> DaoUtil.getData(getCrudRepository().findById(key))); |
79 | } | 80 | } |
80 | 81 | ||
81 | @Override | 82 | @Override |
82 | @Transactional | 83 | @Transactional |
83 | public boolean removeById(TenantId tenantId, UUID id) { | 84 | public boolean removeById(TenantId tenantId, UUID id) { |
84 | - String key = fromTimeUUID(id); | ||
85 | - getCrudRepository().deleteById(key); | ||
86 | - log.debug("Remove request: {}", key); | ||
87 | - return !getCrudRepository().existsById(key); | 85 | + getCrudRepository().deleteById(id); |
86 | + log.debug("Remove request: {}", id); | ||
87 | + return !getCrudRepository().existsById(id); | ||
88 | } | 88 | } |
89 | 89 | ||
90 | @Override | 90 | @Override |
@@ -34,6 +34,7 @@ import java.util.UUID; | @@ -34,6 +34,7 @@ import java.util.UUID; | ||
34 | */ | 34 | */ |
35 | public abstract class JpaAbstractSearchTimeDao<E extends BaseEntity<D>, D> extends JpaAbstractDao<E, D> { | 35 | public abstract class JpaAbstractSearchTimeDao<E extends BaseEntity<D>, D> extends JpaAbstractDao<E, D> { |
36 | 36 | ||
37 | + //TODO 3.1: refactoring to createdTime column | ||
37 | public static <T> Specification<T> getTimeSearchPageSpec(TimePageLink pageLink, String idColumn) { | 38 | public static <T> Specification<T> getTimeSearchPageSpec(TimePageLink pageLink, String idColumn) { |
38 | return new Specification<T>() { | 39 | return new Specification<T>() { |
39 | @Override | 40 | @Override |
@@ -20,21 +20,21 @@ import org.springframework.data.domain.Pageable; | @@ -20,21 +20,21 @@ import org.springframework.data.domain.Pageable; | ||
20 | import org.springframework.data.jpa.repository.Query; | 20 | import org.springframework.data.jpa.repository.Query; |
21 | import org.springframework.data.repository.CrudRepository; | 21 | import org.springframework.data.repository.CrudRepository; |
22 | import org.springframework.data.repository.query.Param; | 22 | import org.springframework.data.repository.query.Param; |
23 | -import org.thingsboard.server.common.data.EntityType; | ||
24 | import org.thingsboard.server.dao.model.sql.AlarmEntity; | 23 | import org.thingsboard.server.dao.model.sql.AlarmEntity; |
25 | import org.thingsboard.server.dao.model.sql.AlarmInfoEntity; | 24 | import org.thingsboard.server.dao.model.sql.AlarmInfoEntity; |
26 | import org.thingsboard.server.dao.util.SqlDao; | 25 | import org.thingsboard.server.dao.util.SqlDao; |
27 | 26 | ||
28 | import java.util.List; | 27 | import java.util.List; |
28 | +import java.util.UUID; | ||
29 | 29 | ||
30 | /** | 30 | /** |
31 | * Created by Valerii Sosliuk on 5/21/2017. | 31 | * Created by Valerii Sosliuk on 5/21/2017. |
32 | */ | 32 | */ |
33 | @SqlDao | 33 | @SqlDao |
34 | -public interface AlarmRepository extends CrudRepository<AlarmEntity, String> { | 34 | +public interface AlarmRepository extends CrudRepository<AlarmEntity, UUID> { |
35 | 35 | ||
36 | @Query("SELECT a FROM AlarmEntity a WHERE a.originatorId = :originatorId AND a.type = :alarmType ORDER BY a.startTs DESC") | 36 | @Query("SELECT a FROM AlarmEntity a WHERE a.originatorId = :originatorId AND a.type = :alarmType ORDER BY a.startTs DESC") |
37 | - List<AlarmEntity> findLatestByOriginatorAndType(@Param("originatorId") String originatorId, | 37 | + List<AlarmEntity> findLatestByOriginatorAndType(@Param("originatorId") UUID originatorId, |
38 | @Param("alarmType") String alarmType, | 38 | @Param("alarmType") String alarmType, |
39 | Pageable pageable); | 39 | Pageable pageable); |
40 | 40 | ||
@@ -46,9 +46,8 @@ public interface AlarmRepository extends CrudRepository<AlarmEntity, String> { | @@ -46,9 +46,8 @@ public interface AlarmRepository extends CrudRepository<AlarmEntity, String> { | ||
46 | "AND re.relationType = :relationType " + | 46 | "AND re.relationType = :relationType " + |
47 | "AND re.fromId = :affectedEntityId " + | 47 | "AND re.fromId = :affectedEntityId " + |
48 | "AND re.fromType = :affectedEntityType " + | 48 | "AND re.fromType = :affectedEntityType " + |
49 | - "AND (:startId IS NULL OR a.id >= :startId) " + | ||
50 | - "AND (:endId IS NULL OR a.id <= :endId) " + | ||
51 | - "AND (:idOffset IS NULL OR a.id < :idOffset) " + | 49 | + "AND (:startTime IS NULL OR a.createdTime >= :startTime) " + |
50 | + "AND (:endTime IS NULL OR a.createdTime <= :endTime) " + | ||
52 | "AND (LOWER(a.type) LIKE LOWER(CONCAT(:searchText, '%'))" + | 51 | "AND (LOWER(a.type) LIKE LOWER(CONCAT(:searchText, '%'))" + |
53 | "OR LOWER(a.severity) LIKE LOWER(CONCAT(:searchText, '%'))" + | 52 | "OR LOWER(a.severity) LIKE LOWER(CONCAT(:searchText, '%'))" + |
54 | "OR LOWER(a.status) LIKE LOWER(CONCAT(:searchText, '%')))", | 53 | "OR LOWER(a.status) LIKE LOWER(CONCAT(:searchText, '%')))", |
@@ -60,19 +59,17 @@ public interface AlarmRepository extends CrudRepository<AlarmEntity, String> { | @@ -60,19 +59,17 @@ public interface AlarmRepository extends CrudRepository<AlarmEntity, String> { | ||
60 | "AND re.relationType = :relationType " + | 59 | "AND re.relationType = :relationType " + |
61 | "AND re.fromId = :affectedEntityId " + | 60 | "AND re.fromId = :affectedEntityId " + |
62 | "AND re.fromType = :affectedEntityType " + | 61 | "AND re.fromType = :affectedEntityType " + |
63 | - "AND (:startId IS NULL OR a.id >= :startId) " + | ||
64 | - "AND (:endId IS NULL OR a.id <= :endId) " + | ||
65 | - "AND (:idOffset IS NULL OR a.id < :idOffset) " + | 62 | + "AND (:startTime IS NULL OR a.createdTime >= :startTime) " + |
63 | + "AND (:endTime IS NULL OR a.createdTime <= :endTime) " + | ||
66 | "AND (LOWER(a.type) LIKE LOWER(CONCAT(:searchText, '%'))" + | 64 | "AND (LOWER(a.type) LIKE LOWER(CONCAT(:searchText, '%'))" + |
67 | "OR LOWER(a.severity) LIKE LOWER(CONCAT(:searchText, '%'))" + | 65 | "OR LOWER(a.severity) LIKE LOWER(CONCAT(:searchText, '%'))" + |
68 | "OR LOWER(a.status) LIKE LOWER(CONCAT(:searchText, '%')))") | 66 | "OR LOWER(a.status) LIKE LOWER(CONCAT(:searchText, '%')))") |
69 | - Page<AlarmInfoEntity> findAlarms(@Param("tenantId") String tenantId, | ||
70 | - @Param("affectedEntityId") String affectedEntityId, | 67 | + Page<AlarmInfoEntity> findAlarms(@Param("tenantId") UUID tenantId, |
68 | + @Param("affectedEntityId") UUID affectedEntityId, | ||
71 | @Param("affectedEntityType") String affectedEntityType, | 69 | @Param("affectedEntityType") String affectedEntityType, |
72 | @Param("relationType") String relationType, | 70 | @Param("relationType") String relationType, |
73 | - @Param("startId") String startId, | ||
74 | - @Param("endId") String endId, | ||
75 | - @Param("idOffset") String idOffset, | 71 | + @Param("startTime") Long startTime, |
72 | + @Param("endTime") Long endTime, | ||
76 | @Param("searchText") String searchText, | 73 | @Param("searchText") String searchText, |
77 | Pageable pageable); | 74 | Pageable pageable); |
78 | } | 75 | } |
@@ -41,7 +41,6 @@ import java.util.List; | @@ -41,7 +41,6 @@ import java.util.List; | ||
41 | import java.util.Objects; | 41 | import java.util.Objects; |
42 | import java.util.UUID; | 42 | import java.util.UUID; |
43 | 43 | ||
44 | -import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID; | ||
45 | import static org.thingsboard.server.dao.DaoUtil.endTimeToId; | 44 | import static org.thingsboard.server.dao.DaoUtil.endTimeToId; |
46 | import static org.thingsboard.server.dao.DaoUtil.startTimeToId; | 45 | import static org.thingsboard.server.dao.DaoUtil.startTimeToId; |
47 | 46 | ||
@@ -65,7 +64,7 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A | @@ -65,7 +64,7 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A | ||
65 | } | 64 | } |
66 | 65 | ||
67 | @Override | 66 | @Override |
68 | - protected CrudRepository<AlarmEntity, String> getCrudRepository() { | 67 | + protected CrudRepository<AlarmEntity, UUID> getCrudRepository() { |
69 | return alarmRepository; | 68 | return alarmRepository; |
70 | } | 69 | } |
71 | 70 | ||
@@ -78,7 +77,7 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A | @@ -78,7 +77,7 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A | ||
78 | public ListenableFuture<Alarm> findLatestByOriginatorAndType(TenantId tenantId, EntityId originator, String type) { | 77 | public ListenableFuture<Alarm> findLatestByOriginatorAndType(TenantId tenantId, EntityId originator, String type) { |
79 | return service.submit(() -> { | 78 | return service.submit(() -> { |
80 | List<AlarmEntity> latest = alarmRepository.findLatestByOriginatorAndType( | 79 | List<AlarmEntity> latest = alarmRepository.findLatestByOriginatorAndType( |
81 | - UUIDConverter.fromTimeUUID(originator.getId()), | 80 | + originator.getId(), |
82 | type, | 81 | type, |
83 | PageRequest.of(0, 1)); | 82 | PageRequest.of(0, 1)); |
84 | return latest.isEmpty() ? null : DaoUtil.getData(latest.get(0)); | 83 | return latest.isEmpty() ? null : DaoUtil.getData(latest.get(0)); |
@@ -106,13 +105,12 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A | @@ -106,13 +105,12 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A | ||
106 | 105 | ||
107 | return DaoUtil.toPageData( | 106 | return DaoUtil.toPageData( |
108 | alarmRepository.findAlarms( | 107 | alarmRepository.findAlarms( |
109 | - fromTimeUUID(tenantId.getId()), | ||
110 | - fromTimeUUID(affectedEntity.getId()), | 108 | + tenantId.getId(), |
109 | + affectedEntity.getId(), | ||
111 | affectedEntity.getEntityType().name(), | 110 | affectedEntity.getEntityType().name(), |
112 | relationType, | 111 | relationType, |
113 | - startTimeToId(query.getPageLink().getStartTime()), | ||
114 | - endTimeToId(query.getPageLink().getEndTime()), | ||
115 | - query.getIdOffset() != null ? UUIDConverter.fromTimeUUID(query.getIdOffset()) : null, | 112 | + query.getPageLink().getStartTime(), |
113 | + query.getPageLink().getEndTime(), | ||
116 | Objects.toString(query.getPageLink().getTextSearch(), ""), | 114 | Objects.toString(query.getPageLink().getTextSearch(), ""), |
117 | DaoUtil.toPageable(query.getPageLink()) | 115 | DaoUtil.toPageable(query.getPageLink()) |
118 | ) | 116 | ) |
@@ -18,7 +18,6 @@ package org.thingsboard.server.dao.sql.asset; | @@ -18,7 +18,6 @@ package org.thingsboard.server.dao.sql.asset; | ||
18 | import org.springframework.data.domain.Page; | 18 | import org.springframework.data.domain.Page; |
19 | import org.springframework.data.domain.Pageable; | 19 | import org.springframework.data.domain.Pageable; |
20 | import org.springframework.data.jpa.repository.Query; | 20 | import org.springframework.data.jpa.repository.Query; |
21 | -import org.springframework.data.repository.CrudRepository; | ||
22 | import org.springframework.data.repository.PagingAndSortingRepository; | 21 | import org.springframework.data.repository.PagingAndSortingRepository; |
23 | import org.springframework.data.repository.query.Param; | 22 | import org.springframework.data.repository.query.Param; |
24 | import org.thingsboard.server.dao.model.sql.AssetEntity; | 23 | import org.thingsboard.server.dao.model.sql.AssetEntity; |
@@ -26,22 +25,23 @@ import org.thingsboard.server.dao.model.sql.AssetInfoEntity; | @@ -26,22 +25,23 @@ import org.thingsboard.server.dao.model.sql.AssetInfoEntity; | ||
26 | import org.thingsboard.server.dao.util.SqlDao; | 25 | import org.thingsboard.server.dao.util.SqlDao; |
27 | 26 | ||
28 | import java.util.List; | 27 | import java.util.List; |
28 | +import java.util.UUID; | ||
29 | 29 | ||
30 | /** | 30 | /** |
31 | * Created by Valerii Sosliuk on 5/21/2017. | 31 | * Created by Valerii Sosliuk on 5/21/2017. |
32 | */ | 32 | */ |
33 | @SqlDao | 33 | @SqlDao |
34 | -public interface AssetRepository extends PagingAndSortingRepository<AssetEntity, String> { | 34 | +public interface AssetRepository extends PagingAndSortingRepository<AssetEntity, UUID> { |
35 | 35 | ||
36 | @Query("SELECT new org.thingsboard.server.dao.model.sql.AssetInfoEntity(a, c.title, c.additionalInfo) " + | 36 | @Query("SELECT new org.thingsboard.server.dao.model.sql.AssetInfoEntity(a, c.title, c.additionalInfo) " + |
37 | "FROM AssetEntity a " + | 37 | "FROM AssetEntity a " + |
38 | "LEFT JOIN CustomerEntity c on c.id = a.customerId " + | 38 | "LEFT JOIN CustomerEntity c on c.id = a.customerId " + |
39 | "WHERE a.id = :assetId") | 39 | "WHERE a.id = :assetId") |
40 | - AssetInfoEntity findAssetInfoById(@Param("assetId") String assetId); | 40 | + AssetInfoEntity findAssetInfoById(@Param("assetId") UUID assetId); |
41 | 41 | ||
42 | @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " + | 42 | @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " + |
43 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") | 43 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
44 | - Page<AssetEntity> findByTenantId(@Param("tenantId") String tenantId, | 44 | + Page<AssetEntity> findByTenantId(@Param("tenantId") UUID tenantId, |
45 | @Param("textSearch") String textSearch, | 45 | @Param("textSearch") String textSearch, |
46 | Pageable pageable); | 46 | Pageable pageable); |
47 | 47 | ||
@@ -50,15 +50,15 @@ public interface AssetRepository extends PagingAndSortingRepository<AssetEntity, | @@ -50,15 +50,15 @@ public interface AssetRepository extends PagingAndSortingRepository<AssetEntity, | ||
50 | "LEFT JOIN CustomerEntity c on c.id = a.customerId " + | 50 | "LEFT JOIN CustomerEntity c on c.id = a.customerId " + |
51 | "WHERE a.tenantId = :tenantId " + | 51 | "WHERE a.tenantId = :tenantId " + |
52 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") | 52 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
53 | - Page<AssetInfoEntity> findAssetInfosByTenantId(@Param("tenantId") String tenantId, | 53 | + Page<AssetInfoEntity> findAssetInfosByTenantId(@Param("tenantId") UUID tenantId, |
54 | @Param("textSearch") String textSearch, | 54 | @Param("textSearch") String textSearch, |
55 | Pageable pageable); | 55 | Pageable pageable); |
56 | 56 | ||
57 | @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " + | 57 | @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " + |
58 | "AND a.customerId = :customerId " + | 58 | "AND a.customerId = :customerId " + |
59 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") | 59 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
60 | - Page<AssetEntity> findByTenantIdAndCustomerId(@Param("tenantId") String tenantId, | ||
61 | - @Param("customerId") String customerId, | 60 | + Page<AssetEntity> findByTenantIdAndCustomerId(@Param("tenantId") UUID tenantId, |
61 | + @Param("customerId") UUID customerId, | ||
62 | @Param("textSearch") String textSearch, | 62 | @Param("textSearch") String textSearch, |
63 | Pageable pageable); | 63 | Pageable pageable); |
64 | 64 | ||
@@ -68,21 +68,21 @@ public interface AssetRepository extends PagingAndSortingRepository<AssetEntity, | @@ -68,21 +68,21 @@ public interface AssetRepository extends PagingAndSortingRepository<AssetEntity, | ||
68 | "WHERE a.tenantId = :tenantId " + | 68 | "WHERE a.tenantId = :tenantId " + |
69 | "AND a.customerId = :customerId " + | 69 | "AND a.customerId = :customerId " + |
70 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") | 70 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") |
71 | - Page<AssetInfoEntity> findAssetInfosByTenantIdAndCustomerId(@Param("tenantId") String tenantId, | ||
72 | - @Param("customerId") String customerId, | 71 | + Page<AssetInfoEntity> findAssetInfosByTenantIdAndCustomerId(@Param("tenantId") UUID tenantId, |
72 | + @Param("customerId") UUID customerId, | ||
73 | @Param("searchText") String searchText, | 73 | @Param("searchText") String searchText, |
74 | Pageable pageable); | 74 | Pageable pageable); |
75 | 75 | ||
76 | - List<AssetEntity> findByTenantIdAndIdIn(String tenantId, List<String> assetIds); | 76 | + List<AssetEntity> findByTenantIdAndIdIn(UUID tenantId, List<UUID> assetIds); |
77 | 77 | ||
78 | - List<AssetEntity> findByTenantIdAndCustomerIdAndIdIn(String tenantId, String customerId, List<String> assetIds); | 78 | + List<AssetEntity> findByTenantIdAndCustomerIdAndIdIn(UUID tenantId, UUID customerId, List<UUID> assetIds); |
79 | 79 | ||
80 | - AssetEntity findByTenantIdAndName(String tenantId, String name); | 80 | + AssetEntity findByTenantIdAndName(UUID tenantId, String name); |
81 | 81 | ||
82 | @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " + | 82 | @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " + |
83 | "AND a.type = :type " + | 83 | "AND a.type = :type " + |
84 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") | 84 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
85 | - Page<AssetEntity> findByTenantIdAndType(@Param("tenantId") String tenantId, | 85 | + Page<AssetEntity> findByTenantIdAndType(@Param("tenantId") UUID tenantId, |
86 | @Param("type") String type, | 86 | @Param("type") String type, |
87 | @Param("textSearch") String textSearch, | 87 | @Param("textSearch") String textSearch, |
88 | Pageable pageable); | 88 | Pageable pageable); |
@@ -93,7 +93,7 @@ public interface AssetRepository extends PagingAndSortingRepository<AssetEntity, | @@ -93,7 +93,7 @@ public interface AssetRepository extends PagingAndSortingRepository<AssetEntity, | ||
93 | "WHERE a.tenantId = :tenantId " + | 93 | "WHERE a.tenantId = :tenantId " + |
94 | "AND a.type = :type " + | 94 | "AND a.type = :type " + |
95 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") | 95 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
96 | - Page<AssetInfoEntity> findAssetInfosByTenantIdAndType(@Param("tenantId") String tenantId, | 96 | + Page<AssetInfoEntity> findAssetInfosByTenantIdAndType(@Param("tenantId") UUID tenantId, |
97 | @Param("type") String type, | 97 | @Param("type") String type, |
98 | @Param("textSearch") String textSearch, | 98 | @Param("textSearch") String textSearch, |
99 | Pageable pageable); | 99 | Pageable pageable); |
@@ -102,8 +102,8 @@ public interface AssetRepository extends PagingAndSortingRepository<AssetEntity, | @@ -102,8 +102,8 @@ public interface AssetRepository extends PagingAndSortingRepository<AssetEntity, | ||
102 | @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " + | 102 | @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " + |
103 | "AND a.customerId = :customerId AND a.type = :type " + | 103 | "AND a.customerId = :customerId AND a.type = :type " + |
104 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") | 104 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
105 | - Page<AssetEntity> findByTenantIdAndCustomerIdAndType(@Param("tenantId") String tenantId, | ||
106 | - @Param("customerId") String customerId, | 105 | + Page<AssetEntity> findByTenantIdAndCustomerIdAndType(@Param("tenantId") UUID tenantId, |
106 | + @Param("customerId") UUID customerId, | ||
107 | @Param("type") String type, | 107 | @Param("type") String type, |
108 | @Param("textSearch") String textSearch, | 108 | @Param("textSearch") String textSearch, |
109 | Pageable pageable); | 109 | Pageable pageable); |
@@ -115,13 +115,13 @@ public interface AssetRepository extends PagingAndSortingRepository<AssetEntity, | @@ -115,13 +115,13 @@ public interface AssetRepository extends PagingAndSortingRepository<AssetEntity, | ||
115 | "AND a.customerId = :customerId " + | 115 | "AND a.customerId = :customerId " + |
116 | "AND a.type = :type " + | 116 | "AND a.type = :type " + |
117 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") | 117 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
118 | - Page<AssetInfoEntity> findAssetInfosByTenantIdAndCustomerIdAndType(@Param("tenantId") String tenantId, | ||
119 | - @Param("customerId") String customerId, | 118 | + Page<AssetInfoEntity> findAssetInfosByTenantIdAndCustomerIdAndType(@Param("tenantId") UUID tenantId, |
119 | + @Param("customerId") UUID customerId, | ||
120 | @Param("type") String type, | 120 | @Param("type") String type, |
121 | @Param("textSearch") String textSearch, | 121 | @Param("textSearch") String textSearch, |
122 | Pageable pageable); | 122 | Pageable pageable); |
123 | 123 | ||
124 | @Query("SELECT DISTINCT a.type FROM AssetEntity a WHERE a.tenantId = :tenantId") | 124 | @Query("SELECT DISTINCT a.type FROM AssetEntity a WHERE a.tenantId = :tenantId") |
125 | - List<String> findTenantAssetTypes(@Param("tenantId") String tenantId); | 125 | + List<String> findTenantAssetTypes(@Param("tenantId") UUID tenantId); |
126 | 126 | ||
127 | } | 127 | } |
@@ -17,7 +17,6 @@ package org.thingsboard.server.dao.sql.asset; | @@ -17,7 +17,6 @@ package org.thingsboard.server.dao.sql.asset; | ||
17 | 17 | ||
18 | import com.google.common.util.concurrent.ListenableFuture; | 18 | import com.google.common.util.concurrent.ListenableFuture; |
19 | import org.springframework.beans.factory.annotation.Autowired; | 19 | import org.springframework.beans.factory.annotation.Autowired; |
20 | -import org.springframework.data.domain.PageRequest; | ||
21 | import org.springframework.data.repository.CrudRepository; | 20 | import org.springframework.data.repository.CrudRepository; |
22 | import org.springframework.stereotype.Component; | 21 | import org.springframework.stereotype.Component; |
23 | import org.thingsboard.server.common.data.EntitySubtype; | 22 | import org.thingsboard.server.common.data.EntitySubtype; |
@@ -41,9 +40,6 @@ import java.util.Objects; | @@ -41,9 +40,6 @@ import java.util.Objects; | ||
41 | import java.util.Optional; | 40 | import java.util.Optional; |
42 | import java.util.UUID; | 41 | import java.util.UUID; |
43 | 42 | ||
44 | -import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID; | ||
45 | -import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUIDs; | ||
46 | - | ||
47 | /** | 43 | /** |
48 | * Created by Valerii Sosliuk on 5/19/2017. | 44 | * Created by Valerii Sosliuk on 5/19/2017. |
49 | */ | 45 | */ |
@@ -60,20 +56,20 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | @@ -60,20 +56,20 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | ||
60 | } | 56 | } |
61 | 57 | ||
62 | @Override | 58 | @Override |
63 | - protected CrudRepository<AssetEntity, String> getCrudRepository() { | 59 | + protected CrudRepository<AssetEntity, UUID> getCrudRepository() { |
64 | return assetRepository; | 60 | return assetRepository; |
65 | } | 61 | } |
66 | 62 | ||
67 | @Override | 63 | @Override |
68 | public AssetInfo findAssetInfoById(TenantId tenantId, UUID assetId) { | 64 | public AssetInfo findAssetInfoById(TenantId tenantId, UUID assetId) { |
69 | - return DaoUtil.getData(assetRepository.findAssetInfoById(fromTimeUUID(assetId))); | 65 | + return DaoUtil.getData(assetRepository.findAssetInfoById(assetId)); |
70 | } | 66 | } |
71 | 67 | ||
72 | @Override | 68 | @Override |
73 | public PageData<Asset> findAssetsByTenantId(UUID tenantId, PageLink pageLink) { | 69 | public PageData<Asset> findAssetsByTenantId(UUID tenantId, PageLink pageLink) { |
74 | return DaoUtil.toPageData(assetRepository | 70 | return DaoUtil.toPageData(assetRepository |
75 | .findByTenantId( | 71 | .findByTenantId( |
76 | - fromTimeUUID(tenantId), | 72 | + tenantId, |
77 | Objects.toString(pageLink.getTextSearch(), ""), | 73 | Objects.toString(pageLink.getTextSearch(), ""), |
78 | DaoUtil.toPageable(pageLink))); | 74 | DaoUtil.toPageable(pageLink))); |
79 | } | 75 | } |
@@ -82,7 +78,7 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | @@ -82,7 +78,7 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | ||
82 | public PageData<AssetInfo> findAssetInfosByTenantId(UUID tenantId, PageLink pageLink) { | 78 | public PageData<AssetInfo> findAssetInfosByTenantId(UUID tenantId, PageLink pageLink) { |
83 | return DaoUtil.toPageData( | 79 | return DaoUtil.toPageData( |
84 | assetRepository.findAssetInfosByTenantId( | 80 | assetRepository.findAssetInfosByTenantId( |
85 | - fromTimeUUID(tenantId), | 81 | + tenantId, |
86 | Objects.toString(pageLink.getTextSearch(), ""), | 82 | Objects.toString(pageLink.getTextSearch(), ""), |
87 | DaoUtil.toPageable(pageLink, AssetInfoEntity.assetInfoColumnMap))); | 83 | DaoUtil.toPageable(pageLink, AssetInfoEntity.assetInfoColumnMap))); |
88 | } | 84 | } |
@@ -90,15 +86,15 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | @@ -90,15 +86,15 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | ||
90 | @Override | 86 | @Override |
91 | public ListenableFuture<List<Asset>> findAssetsByTenantIdAndIdsAsync(UUID tenantId, List<UUID> assetIds) { | 87 | public ListenableFuture<List<Asset>> findAssetsByTenantIdAndIdsAsync(UUID tenantId, List<UUID> assetIds) { |
92 | return service.submit(() -> | 88 | return service.submit(() -> |
93 | - DaoUtil.convertDataList(assetRepository.findByTenantIdAndIdIn(fromTimeUUID(tenantId), fromTimeUUIDs(assetIds)))); | 89 | + DaoUtil.convertDataList(assetRepository.findByTenantIdAndIdIn(tenantId, assetIds))); |
94 | } | 90 | } |
95 | 91 | ||
96 | @Override | 92 | @Override |
97 | public PageData<Asset> findAssetsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink) { | 93 | public PageData<Asset> findAssetsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink) { |
98 | return DaoUtil.toPageData(assetRepository | 94 | return DaoUtil.toPageData(assetRepository |
99 | .findByTenantIdAndCustomerId( | 95 | .findByTenantIdAndCustomerId( |
100 | - fromTimeUUID(tenantId), | ||
101 | - fromTimeUUID(customerId), | 96 | + tenantId, |
97 | + customerId, | ||
102 | Objects.toString(pageLink.getTextSearch(), ""), | 98 | Objects.toString(pageLink.getTextSearch(), ""), |
103 | DaoUtil.toPageable(pageLink))); | 99 | DaoUtil.toPageable(pageLink))); |
104 | } | 100 | } |
@@ -107,8 +103,8 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | @@ -107,8 +103,8 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | ||
107 | public PageData<AssetInfo> findAssetInfosByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink) { | 103 | public PageData<AssetInfo> findAssetInfosByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink) { |
108 | return DaoUtil.toPageData( | 104 | return DaoUtil.toPageData( |
109 | assetRepository.findAssetInfosByTenantIdAndCustomerId( | 105 | assetRepository.findAssetInfosByTenantIdAndCustomerId( |
110 | - fromTimeUUID(tenantId), | ||
111 | - fromTimeUUID(customerId), | 106 | + tenantId, |
107 | + customerId, | ||
112 | Objects.toString(pageLink.getTextSearch(), ""), | 108 | Objects.toString(pageLink.getTextSearch(), ""), |
113 | DaoUtil.toPageable(pageLink, AssetInfoEntity.assetInfoColumnMap))); | 109 | DaoUtil.toPageable(pageLink, AssetInfoEntity.assetInfoColumnMap))); |
114 | } | 110 | } |
@@ -116,12 +112,12 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | @@ -116,12 +112,12 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | ||
116 | @Override | 112 | @Override |
117 | public ListenableFuture<List<Asset>> findAssetsByTenantIdAndCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> assetIds) { | 113 | public ListenableFuture<List<Asset>> findAssetsByTenantIdAndCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> assetIds) { |
118 | return service.submit(() -> | 114 | return service.submit(() -> |
119 | - DaoUtil.convertDataList(assetRepository.findByTenantIdAndCustomerIdAndIdIn(fromTimeUUID(tenantId), fromTimeUUID(customerId), fromTimeUUIDs(assetIds)))); | 115 | + DaoUtil.convertDataList(assetRepository.findByTenantIdAndCustomerIdAndIdIn(tenantId, customerId, assetIds))); |
120 | } | 116 | } |
121 | 117 | ||
122 | @Override | 118 | @Override |
123 | public Optional<Asset> findAssetsByTenantIdAndName(UUID tenantId, String name) { | 119 | public Optional<Asset> findAssetsByTenantIdAndName(UUID tenantId, String name) { |
124 | - Asset asset = DaoUtil.getData(assetRepository.findByTenantIdAndName(fromTimeUUID(tenantId), name)); | 120 | + Asset asset = DaoUtil.getData(assetRepository.findByTenantIdAndName(tenantId, name)); |
125 | return Optional.ofNullable(asset); | 121 | return Optional.ofNullable(asset); |
126 | } | 122 | } |
127 | 123 | ||
@@ -129,7 +125,7 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | @@ -129,7 +125,7 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | ||
129 | public PageData<Asset> findAssetsByTenantIdAndType(UUID tenantId, String type, PageLink pageLink) { | 125 | public PageData<Asset> findAssetsByTenantIdAndType(UUID tenantId, String type, PageLink pageLink) { |
130 | return DaoUtil.toPageData(assetRepository | 126 | return DaoUtil.toPageData(assetRepository |
131 | .findByTenantIdAndType( | 127 | .findByTenantIdAndType( |
132 | - fromTimeUUID(tenantId), | 128 | + tenantId, |
133 | type, | 129 | type, |
134 | Objects.toString(pageLink.getTextSearch(), ""), | 130 | Objects.toString(pageLink.getTextSearch(), ""), |
135 | DaoUtil.toPageable(pageLink))); | 131 | DaoUtil.toPageable(pageLink))); |
@@ -139,7 +135,7 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | @@ -139,7 +135,7 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | ||
139 | public PageData<AssetInfo> findAssetInfosByTenantIdAndType(UUID tenantId, String type, PageLink pageLink) { | 135 | public PageData<AssetInfo> findAssetInfosByTenantIdAndType(UUID tenantId, String type, PageLink pageLink) { |
140 | return DaoUtil.toPageData( | 136 | return DaoUtil.toPageData( |
141 | assetRepository.findAssetInfosByTenantIdAndType( | 137 | assetRepository.findAssetInfosByTenantIdAndType( |
142 | - fromTimeUUID(tenantId), | 138 | + tenantId, |
143 | type, | 139 | type, |
144 | Objects.toString(pageLink.getTextSearch(), ""), | 140 | Objects.toString(pageLink.getTextSearch(), ""), |
145 | DaoUtil.toPageable(pageLink, AssetInfoEntity.assetInfoColumnMap))); | 141 | DaoUtil.toPageable(pageLink, AssetInfoEntity.assetInfoColumnMap))); |
@@ -149,8 +145,8 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | @@ -149,8 +145,8 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | ||
149 | public PageData<Asset> findAssetsByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink) { | 145 | public PageData<Asset> findAssetsByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink) { |
150 | return DaoUtil.toPageData(assetRepository | 146 | return DaoUtil.toPageData(assetRepository |
151 | .findByTenantIdAndCustomerIdAndType( | 147 | .findByTenantIdAndCustomerIdAndType( |
152 | - fromTimeUUID(tenantId), | ||
153 | - fromTimeUUID(customerId), | 148 | + tenantId, |
149 | + customerId, | ||
154 | type, | 150 | type, |
155 | Objects.toString(pageLink.getTextSearch(), ""), | 151 | Objects.toString(pageLink.getTextSearch(), ""), |
156 | DaoUtil.toPageable(pageLink))); | 152 | DaoUtil.toPageable(pageLink))); |
@@ -160,8 +156,8 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | @@ -160,8 +156,8 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | ||
160 | public PageData<AssetInfo> findAssetInfosByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink) { | 156 | public PageData<AssetInfo> findAssetInfosByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink) { |
161 | return DaoUtil.toPageData( | 157 | return DaoUtil.toPageData( |
162 | assetRepository.findAssetInfosByTenantIdAndCustomerIdAndType( | 158 | assetRepository.findAssetInfosByTenantIdAndCustomerIdAndType( |
163 | - fromTimeUUID(tenantId), | ||
164 | - fromTimeUUID(customerId), | 159 | + tenantId, |
160 | + customerId, | ||
165 | type, | 161 | type, |
166 | Objects.toString(pageLink.getTextSearch(), ""), | 162 | Objects.toString(pageLink.getTextSearch(), ""), |
167 | DaoUtil.toPageable(pageLink, AssetInfoEntity.assetInfoColumnMap))); | 163 | DaoUtil.toPageable(pageLink, AssetInfoEntity.assetInfoColumnMap))); |
@@ -169,7 +165,7 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | @@ -169,7 +165,7 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | ||
169 | 165 | ||
170 | @Override | 166 | @Override |
171 | public ListenableFuture<List<EntitySubtype>> findTenantAssetTypesAsync(UUID tenantId) { | 167 | public ListenableFuture<List<EntitySubtype>> findTenantAssetTypesAsync(UUID tenantId) { |
172 | - return service.submit(() -> convertTenantAssetTypesToDto(tenantId, assetRepository.findTenantAssetTypes(fromTimeUUID(tenantId)))); | 168 | + return service.submit(() -> convertTenantAssetTypesToDto(tenantId, assetRepository.findTenantAssetTypes(tenantId))); |
173 | } | 169 | } |
174 | 170 | ||
175 | private List<EntitySubtype> convertTenantAssetTypesToDto(UUID tenantId, List<String> types) { | 171 | private List<EntitySubtype> convertTenantAssetTypesToDto(UUID tenantId, List<String> types) { |
@@ -29,6 +29,7 @@ import org.thingsboard.server.dao.util.SqlDao; | @@ -29,6 +29,7 @@ import org.thingsboard.server.dao.util.SqlDao; | ||
29 | 29 | ||
30 | import java.sql.PreparedStatement; | 30 | import java.sql.PreparedStatement; |
31 | import java.sql.SQLException; | 31 | import java.sql.SQLException; |
32 | +import java.sql.SQLType; | ||
32 | import java.sql.Types; | 33 | import java.sql.Types; |
33 | import java.util.ArrayList; | 34 | import java.util.ArrayList; |
34 | import java.util.List; | 35 | import java.util.List; |
@@ -92,7 +93,7 @@ public abstract class AttributeKvInsertRepository { | @@ -92,7 +93,7 @@ public abstract class AttributeKvInsertRepository { | ||
92 | 93 | ||
93 | ps.setLong(6, kvEntity.getLastUpdateTs()); | 94 | ps.setLong(6, kvEntity.getLastUpdateTs()); |
94 | ps.setString(7, kvEntity.getId().getEntityType().name()); | 95 | ps.setString(7, kvEntity.getId().getEntityType().name()); |
95 | - ps.setString(8, kvEntity.getId().getEntityId()); | 96 | + ps.setObject(8, kvEntity.getId().getEntityId()); |
96 | ps.setString(9, kvEntity.getId().getAttributeType()); | 97 | ps.setString(9, kvEntity.getId().getAttributeType()); |
97 | ps.setString(10, kvEntity.getId().getAttributeKey()); | 98 | ps.setString(10, kvEntity.getId().getAttributeKey()); |
98 | } | 99 | } |
@@ -122,7 +123,7 @@ public abstract class AttributeKvInsertRepository { | @@ -122,7 +123,7 @@ public abstract class AttributeKvInsertRepository { | ||
122 | public void setValues(PreparedStatement ps, int i) throws SQLException { | 123 | public void setValues(PreparedStatement ps, int i) throws SQLException { |
123 | AttributeKvEntity kvEntity = insertEntities.get(i); | 124 | AttributeKvEntity kvEntity = insertEntities.get(i); |
124 | ps.setString(1, kvEntity.getId().getEntityType().name()); | 125 | ps.setString(1, kvEntity.getId().getEntityType().name()); |
125 | - ps.setString(2, kvEntity.getId().getEntityId()); | 126 | + ps.setObject(2, kvEntity.getId().getEntityId()); |
126 | ps.setString(3, kvEntity.getId().getAttributeType()); | 127 | ps.setString(3, kvEntity.getId().getAttributeType()); |
127 | ps.setString(4, kvEntity.getId().getAttributeKey()); | 128 | ps.setString(4, kvEntity.getId().getAttributeKey()); |
128 | 129 |
@@ -26,6 +26,7 @@ import org.thingsboard.server.dao.model.sql.AttributeKvEntity; | @@ -26,6 +26,7 @@ import org.thingsboard.server.dao.model.sql.AttributeKvEntity; | ||
26 | import org.thingsboard.server.dao.util.SqlDao; | 26 | import org.thingsboard.server.dao.util.SqlDao; |
27 | 27 | ||
28 | import java.util.List; | 28 | import java.util.List; |
29 | +import java.util.UUID; | ||
29 | 30 | ||
30 | @SqlDao | 31 | @SqlDao |
31 | public interface AttributeKvRepository extends CrudRepository<AttributeKvEntity, AttributeKvCompositeKey> { | 32 | public interface AttributeKvRepository extends CrudRepository<AttributeKvEntity, AttributeKvCompositeKey> { |
@@ -34,7 +35,7 @@ public interface AttributeKvRepository extends CrudRepository<AttributeKvEntity, | @@ -34,7 +35,7 @@ public interface AttributeKvRepository extends CrudRepository<AttributeKvEntity, | ||
34 | "AND a.id.entityId = :entityId " + | 35 | "AND a.id.entityId = :entityId " + |
35 | "AND a.id.attributeType = :attributeType") | 36 | "AND a.id.attributeType = :attributeType") |
36 | List<AttributeKvEntity> findAllByEntityTypeAndEntityIdAndAttributeType(@Param("entityType") EntityType entityType, | 37 | List<AttributeKvEntity> findAllByEntityTypeAndEntityIdAndAttributeType(@Param("entityType") EntityType entityType, |
37 | - @Param("entityId") String entityId, | 38 | + @Param("entityId") UUID entityId, |
38 | @Param("attributeType") String attributeType); | 39 | @Param("attributeType") String attributeType); |
39 | 40 | ||
40 | @Transactional | 41 | @Transactional |
@@ -44,7 +45,7 @@ public interface AttributeKvRepository extends CrudRepository<AttributeKvEntity, | @@ -44,7 +45,7 @@ public interface AttributeKvRepository extends CrudRepository<AttributeKvEntity, | ||
44 | "AND a.id.attributeType = :attributeType " + | 45 | "AND a.id.attributeType = :attributeType " + |
45 | "AND a.id.attributeKey = :attributeKey") | 46 | "AND a.id.attributeKey = :attributeKey") |
46 | void delete(@Param("entityType") EntityType entityType, | 47 | void delete(@Param("entityType") EntityType entityType, |
47 | - @Param("entityId") String entityId, | 48 | + @Param("entityId") UUID entityId, |
48 | @Param("attributeType") String attributeType, | 49 | @Param("attributeType") String attributeType, |
49 | @Param("attributeKey") String attributeKey); | 50 | @Param("attributeKey") String attributeKey); |
50 | } | 51 | } |
@@ -46,7 +46,7 @@ public class HsqlAttributesInsertRepository extends AttributeKvInsertRepository | @@ -46,7 +46,7 @@ public class HsqlAttributesInsertRepository extends AttributeKvInsertRepository | ||
46 | entities.forEach(entity -> { | 46 | entities.forEach(entity -> { |
47 | jdbcTemplate.update(INSERT_OR_UPDATE, ps -> { | 47 | jdbcTemplate.update(INSERT_OR_UPDATE, ps -> { |
48 | ps.setString(1, entity.getId().getEntityType().name()); | 48 | ps.setString(1, entity.getId().getEntityType().name()); |
49 | - ps.setString(2, entity.getId().getEntityId()); | 49 | + ps.setObject(2, entity.getId().getEntityId()); |
50 | ps.setString(3, entity.getId().getAttributeType()); | 50 | ps.setString(3, entity.getId().getAttributeType()); |
51 | ps.setString(4, entity.getId().getAttributeKey()); | 51 | ps.setString(4, entity.getId().getAttributeKey()); |
52 | ps.setString(5, entity.getStrValue()); | 52 | ps.setString(5, entity.getStrValue()); |
@@ -22,7 +22,6 @@ import lombok.extern.slf4j.Slf4j; | @@ -22,7 +22,6 @@ import lombok.extern.slf4j.Slf4j; | ||
22 | import org.springframework.beans.factory.annotation.Autowired; | 22 | import org.springframework.beans.factory.annotation.Autowired; |
23 | import org.springframework.beans.factory.annotation.Value; | 23 | import org.springframework.beans.factory.annotation.Value; |
24 | import org.springframework.stereotype.Component; | 24 | import org.springframework.stereotype.Component; |
25 | -import org.thingsboard.server.common.data.UUIDConverter; | ||
26 | import org.thingsboard.server.common.data.id.EntityId; | 25 | import org.thingsboard.server.common.data.id.EntityId; |
27 | import org.thingsboard.server.common.data.id.TenantId; | 26 | import org.thingsboard.server.common.data.id.TenantId; |
28 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; | 27 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
@@ -43,8 +42,6 @@ import java.util.List; | @@ -43,8 +42,6 @@ import java.util.List; | ||
43 | import java.util.Optional; | 42 | import java.util.Optional; |
44 | import java.util.stream.Collectors; | 43 | import java.util.stream.Collectors; |
45 | 44 | ||
46 | -import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID; | ||
47 | - | ||
48 | @Component | 45 | @Component |
49 | @Slf4j | 46 | @Slf4j |
50 | @SqlDao | 47 | @SqlDao |
@@ -115,14 +112,14 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl | @@ -115,14 +112,14 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl | ||
115 | DaoUtil.convertDataList(Lists.newArrayList( | 112 | DaoUtil.convertDataList(Lists.newArrayList( |
116 | attributeKvRepository.findAllByEntityTypeAndEntityIdAndAttributeType( | 113 | attributeKvRepository.findAllByEntityTypeAndEntityIdAndAttributeType( |
117 | entityId.getEntityType(), | 114 | entityId.getEntityType(), |
118 | - UUIDConverter.fromTimeUUID(entityId.getId()), | 115 | + entityId.getId(), |
119 | attributeType)))); | 116 | attributeType)))); |
120 | } | 117 | } |
121 | 118 | ||
122 | @Override | 119 | @Override |
123 | public ListenableFuture<Void> save(TenantId tenantId, EntityId entityId, String attributeType, AttributeKvEntry attribute) { | 120 | public ListenableFuture<Void> save(TenantId tenantId, EntityId entityId, String attributeType, AttributeKvEntry attribute) { |
124 | AttributeKvEntity entity = new AttributeKvEntity(); | 121 | AttributeKvEntity entity = new AttributeKvEntity(); |
125 | - entity.setId(new AttributeKvCompositeKey(entityId.getEntityType(), fromTimeUUID(entityId.getId()), attributeType, attribute.getKey())); | 122 | + entity.setId(new AttributeKvCompositeKey(entityId.getEntityType(), entityId.getId(), attributeType, attribute.getKey())); |
126 | entity.setLastUpdateTs(attribute.getLastUpdateTs()); | 123 | entity.setLastUpdateTs(attribute.getLastUpdateTs()); |
127 | entity.setStrValue(attribute.getStrValue().orElse(null)); | 124 | entity.setStrValue(attribute.getStrValue().orElse(null)); |
128 | entity.setDoubleValue(attribute.getDoubleValue().orElse(null)); | 125 | entity.setDoubleValue(attribute.getDoubleValue().orElse(null)); |
@@ -140,7 +137,7 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl | @@ -140,7 +137,7 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl | ||
140 | public ListenableFuture<List<Void>> removeAll(TenantId tenantId, EntityId entityId, String attributeType, List<String> keys) { | 137 | public ListenableFuture<List<Void>> removeAll(TenantId tenantId, EntityId entityId, String attributeType, List<String> keys) { |
141 | return service.submit(() -> { | 138 | return service.submit(() -> { |
142 | keys.forEach(key -> | 139 | keys.forEach(key -> |
143 | - attributeKvRepository.delete(entityId.getEntityType(), UUIDConverter.fromTimeUUID(entityId.getId()), attributeType, key) | 140 | + attributeKvRepository.delete(entityId.getEntityType(), entityId.getId(), attributeType, key) |
144 | ); | 141 | ); |
145 | return null; | 142 | return null; |
146 | }); | 143 | }); |
@@ -149,7 +146,7 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl | @@ -149,7 +146,7 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl | ||
149 | private AttributeKvCompositeKey getAttributeKvCompositeKey(EntityId entityId, String attributeType, String attributeKey) { | 146 | private AttributeKvCompositeKey getAttributeKvCompositeKey(EntityId entityId, String attributeType, String attributeKey) { |
150 | return new AttributeKvCompositeKey( | 147 | return new AttributeKvCompositeKey( |
151 | entityId.getEntityType(), | 148 | entityId.getEntityType(), |
152 | - fromTimeUUID(entityId.getId()), | 149 | + entityId.getId(), |
153 | attributeType, | 150 | attributeType, |
154 | attributeKey); | 151 | attributeKey); |
155 | } | 152 | } |
@@ -25,8 +25,9 @@ import org.thingsboard.server.common.data.audit.ActionType; | @@ -25,8 +25,9 @@ import org.thingsboard.server.common.data.audit.ActionType; | ||
25 | import org.thingsboard.server.dao.model.sql.AuditLogEntity; | 25 | import org.thingsboard.server.dao.model.sql.AuditLogEntity; |
26 | 26 | ||
27 | import java.util.List; | 27 | import java.util.List; |
28 | +import java.util.UUID; | ||
28 | 29 | ||
29 | -public interface AuditLogRepository extends PagingAndSortingRepository<AuditLogEntity, String> { | 30 | +public interface AuditLogRepository extends PagingAndSortingRepository<AuditLogEntity, UUID> { |
30 | 31 | ||
31 | @Query("SELECT a FROM AuditLogEntity a WHERE " + | 32 | @Query("SELECT a FROM AuditLogEntity a WHERE " + |
32 | "a.tenantId = :tenantId " + | 33 | "a.tenantId = :tenantId " + |
@@ -40,7 +41,7 @@ public interface AuditLogRepository extends PagingAndSortingRepository<AuditLogE | @@ -40,7 +41,7 @@ public interface AuditLogRepository extends PagingAndSortingRepository<AuditLogE | ||
40 | "OR LOWER(a.actionStatus) LIKE LOWER(CONCAT(:textSearch, '%')))" | 41 | "OR LOWER(a.actionStatus) LIKE LOWER(CONCAT(:textSearch, '%')))" |
41 | ) | 42 | ) |
42 | Page<AuditLogEntity> findByTenantId( | 43 | Page<AuditLogEntity> findByTenantId( |
43 | - @Param("tenantId") String tenantId, | 44 | + @Param("tenantId") UUID tenantId, |
44 | @Param("textSearch") String textSearch, | 45 | @Param("textSearch") String textSearch, |
45 | @Param("startId") String startId, | 46 | @Param("startId") String startId, |
46 | @Param("endId") String endId, | 47 | @Param("endId") String endId, |
@@ -58,9 +59,9 @@ public interface AuditLogRepository extends PagingAndSortingRepository<AuditLogE | @@ -58,9 +59,9 @@ public interface AuditLogRepository extends PagingAndSortingRepository<AuditLogE | ||
58 | "OR LOWER(a.actionType) LIKE LOWER(CONCAT(:textSearch, '%'))" + | 59 | "OR LOWER(a.actionType) LIKE LOWER(CONCAT(:textSearch, '%'))" + |
59 | "OR LOWER(a.actionStatus) LIKE LOWER(CONCAT(:textSearch, '%')))" | 60 | "OR LOWER(a.actionStatus) LIKE LOWER(CONCAT(:textSearch, '%')))" |
60 | ) | 61 | ) |
61 | - Page<AuditLogEntity> findAuditLogsByTenantIdAndEntityId(@Param("tenantId") String tenantId, | 62 | + Page<AuditLogEntity> findAuditLogsByTenantIdAndEntityId(@Param("tenantId") UUID tenantId, |
62 | @Param("entityType") EntityType entityType, | 63 | @Param("entityType") EntityType entityType, |
63 | - @Param("entityId") String entityId, | 64 | + @Param("entityId") UUID entityId, |
64 | @Param("textSearch") String textSearch, | 65 | @Param("textSearch") String textSearch, |
65 | @Param("startId") String startId, | 66 | @Param("startId") String startId, |
66 | @Param("endId") String endId, | 67 | @Param("endId") String endId, |
@@ -79,8 +80,8 @@ public interface AuditLogRepository extends PagingAndSortingRepository<AuditLogE | @@ -79,8 +80,8 @@ public interface AuditLogRepository extends PagingAndSortingRepository<AuditLogE | ||
79 | "OR LOWER(a.actionType) LIKE LOWER(CONCAT(:textSearch, '%'))" + | 80 | "OR LOWER(a.actionType) LIKE LOWER(CONCAT(:textSearch, '%'))" + |
80 | "OR LOWER(a.actionStatus) LIKE LOWER(CONCAT(:textSearch, '%')))" | 81 | "OR LOWER(a.actionStatus) LIKE LOWER(CONCAT(:textSearch, '%')))" |
81 | ) | 82 | ) |
82 | - Page<AuditLogEntity> findAuditLogsByTenantIdAndCustomerId(@Param("tenantId") String tenantId, | ||
83 | - @Param("customerId") String customerId, | 83 | + Page<AuditLogEntity> findAuditLogsByTenantIdAndCustomerId(@Param("tenantId") UUID tenantId, |
84 | + @Param("customerId") UUID customerId, | ||
84 | @Param("textSearch") String textSearch, | 85 | @Param("textSearch") String textSearch, |
85 | @Param("startId") String startId, | 86 | @Param("startId") String startId, |
86 | @Param("endId") String endId, | 87 | @Param("endId") String endId, |
@@ -98,8 +99,8 @@ public interface AuditLogRepository extends PagingAndSortingRepository<AuditLogE | @@ -98,8 +99,8 @@ public interface AuditLogRepository extends PagingAndSortingRepository<AuditLogE | ||
98 | "OR LOWER(a.actionType) LIKE LOWER(CONCAT(:textSearch, '%'))" + | 99 | "OR LOWER(a.actionType) LIKE LOWER(CONCAT(:textSearch, '%'))" + |
99 | "OR LOWER(a.actionStatus) LIKE LOWER(CONCAT(:textSearch, '%')))" | 100 | "OR LOWER(a.actionStatus) LIKE LOWER(CONCAT(:textSearch, '%')))" |
100 | ) | 101 | ) |
101 | - Page<AuditLogEntity> findAuditLogsByTenantIdAndUserId(@Param("tenantId") String tenantId, | ||
102 | - @Param("userId") String userId, | 102 | + Page<AuditLogEntity> findAuditLogsByTenantIdAndUserId(@Param("tenantId") UUID tenantId, |
103 | + @Param("userId") UUID userId, | ||
103 | @Param("textSearch") String textSearch, | 104 | @Param("textSearch") String textSearch, |
104 | @Param("startId") String startId, | 105 | @Param("startId") String startId, |
105 | @Param("endId") String endId, | 106 | @Param("endId") String endId, |
@@ -36,7 +36,6 @@ import java.util.List; | @@ -36,7 +36,6 @@ import java.util.List; | ||
36 | import java.util.Objects; | 36 | import java.util.Objects; |
37 | import java.util.UUID; | 37 | import java.util.UUID; |
38 | 38 | ||
39 | -import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID; | ||
40 | import static org.thingsboard.server.dao.DaoUtil.endTimeToId; | 39 | import static org.thingsboard.server.dao.DaoUtil.endTimeToId; |
41 | import static org.thingsboard.server.dao.DaoUtil.startTimeToId; | 40 | import static org.thingsboard.server.dao.DaoUtil.startTimeToId; |
42 | 41 | ||
@@ -53,7 +52,7 @@ public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> imp | @@ -53,7 +52,7 @@ public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> imp | ||
53 | } | 52 | } |
54 | 53 | ||
55 | @Override | 54 | @Override |
56 | - protected CrudRepository<AuditLogEntity, String> getCrudRepository() { | 55 | + protected CrudRepository<AuditLogEntity, UUID> getCrudRepository() { |
57 | return auditLogRepository; | 56 | return auditLogRepository; |
58 | } | 57 | } |
59 | 58 | ||
@@ -70,9 +69,9 @@ public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> imp | @@ -70,9 +69,9 @@ public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> imp | ||
70 | return DaoUtil.toPageData( | 69 | return DaoUtil.toPageData( |
71 | auditLogRepository | 70 | auditLogRepository |
72 | .findAuditLogsByTenantIdAndEntityId( | 71 | .findAuditLogsByTenantIdAndEntityId( |
73 | - fromTimeUUID(tenantId), | 72 | + tenantId, |
74 | entityId.getEntityType(), | 73 | entityId.getEntityType(), |
75 | - fromTimeUUID(entityId.getId()), | 74 | + entityId.getId(), |
76 | Objects.toString(pageLink.getTextSearch(), ""), | 75 | Objects.toString(pageLink.getTextSearch(), ""), |
77 | startTimeToId(pageLink.getStartTime()), | 76 | startTimeToId(pageLink.getStartTime()), |
78 | endTimeToId(pageLink.getEndTime()), | 77 | endTimeToId(pageLink.getEndTime()), |
@@ -85,8 +84,8 @@ public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> imp | @@ -85,8 +84,8 @@ public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> imp | ||
85 | return DaoUtil.toPageData( | 84 | return DaoUtil.toPageData( |
86 | auditLogRepository | 85 | auditLogRepository |
87 | .findAuditLogsByTenantIdAndCustomerId( | 86 | .findAuditLogsByTenantIdAndCustomerId( |
88 | - fromTimeUUID(tenantId), | ||
89 | - fromTimeUUID(customerId.getId()), | 87 | + tenantId, |
88 | + customerId.getId(), | ||
90 | Objects.toString(pageLink.getTextSearch(), ""), | 89 | Objects.toString(pageLink.getTextSearch(), ""), |
91 | startTimeToId(pageLink.getStartTime()), | 90 | startTimeToId(pageLink.getStartTime()), |
92 | endTimeToId(pageLink.getEndTime()), | 91 | endTimeToId(pageLink.getEndTime()), |
@@ -99,8 +98,8 @@ public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> imp | @@ -99,8 +98,8 @@ public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> imp | ||
99 | return DaoUtil.toPageData( | 98 | return DaoUtil.toPageData( |
100 | auditLogRepository | 99 | auditLogRepository |
101 | .findAuditLogsByTenantIdAndUserId( | 100 | .findAuditLogsByTenantIdAndUserId( |
102 | - fromTimeUUID(tenantId), | ||
103 | - fromTimeUUID(userId.getId()), | 101 | + tenantId, |
102 | + userId.getId(), | ||
104 | Objects.toString(pageLink.getTextSearch(), ""), | 103 | Objects.toString(pageLink.getTextSearch(), ""), |
105 | startTimeToId(pageLink.getStartTime()), | 104 | startTimeToId(pageLink.getStartTime()), |
106 | endTimeToId(pageLink.getEndTime()), | 105 | endTimeToId(pageLink.getEndTime()), |
@@ -112,7 +111,7 @@ public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> imp | @@ -112,7 +111,7 @@ public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> imp | ||
112 | public PageData<AuditLog> findAuditLogsByTenantId(UUID tenantId, List<ActionType> actionTypes, TimePageLink pageLink) { | 111 | public PageData<AuditLog> findAuditLogsByTenantId(UUID tenantId, List<ActionType> actionTypes, TimePageLink pageLink) { |
113 | return DaoUtil.toPageData( | 112 | return DaoUtil.toPageData( |
114 | auditLogRepository.findByTenantId( | 113 | auditLogRepository.findByTenantId( |
115 | - fromTimeUUID(tenantId), | 114 | + tenantId, |
116 | Objects.toString(pageLink.getTextSearch(), ""), | 115 | Objects.toString(pageLink.getTextSearch(), ""), |
117 | startTimeToId(pageLink.getStartTime()), | 116 | startTimeToId(pageLink.getStartTime()), |
118 | endTimeToId(pageLink.getEndTime()), | 117 | endTimeToId(pageLink.getEndTime()), |
@@ -23,7 +23,6 @@ import org.springframework.transaction.PlatformTransactionManager; | @@ -23,7 +23,6 @@ import org.springframework.transaction.PlatformTransactionManager; | ||
23 | import org.springframework.transaction.TransactionDefinition; | 23 | import org.springframework.transaction.TransactionDefinition; |
24 | import org.springframework.transaction.TransactionStatus; | 24 | import org.springframework.transaction.TransactionStatus; |
25 | import org.springframework.transaction.support.DefaultTransactionDefinition; | 25 | import org.springframework.transaction.support.DefaultTransactionDefinition; |
26 | -import org.thingsboard.server.common.data.UUIDConverter; | ||
27 | import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity; | 26 | import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity; |
28 | 27 | ||
29 | import javax.persistence.EntityManager; | 28 | import javax.persistence.EntityManager; |
@@ -69,7 +68,8 @@ public abstract class AbstractComponentDescriptorInsertRepository implements Com | @@ -69,7 +68,8 @@ public abstract class AbstractComponentDescriptorInsertRepository implements Com | ||
69 | 68 | ||
70 | protected Query getQuery(ComponentDescriptorEntity entity, String query) { | 69 | protected Query getQuery(ComponentDescriptorEntity entity, String query) { |
71 | return entityManager.createNativeQuery(query, ComponentDescriptorEntity.class) | 70 | return entityManager.createNativeQuery(query, ComponentDescriptorEntity.class) |
72 | - .setParameter("id", UUIDConverter.fromTimeUUID(entity.getUuid())) | 71 | + .setParameter("id", entity.getUuid()) |
72 | + .setParameter("created_time", entity.getCreatedTime()) | ||
73 | .setParameter("actions", entity.getActions()) | 73 | .setParameter("actions", entity.getActions()) |
74 | .setParameter("clazz", entity.getClazz()) | 74 | .setParameter("clazz", entity.getClazz()) |
75 | .setParameter("configuration_descriptor", entity.getConfigurationDescriptor().toString()) | 75 | .setParameter("configuration_descriptor", entity.getConfigurationDescriptor().toString()) |
@@ -18,7 +18,6 @@ package org.thingsboard.server.dao.sql.component; | @@ -18,7 +18,6 @@ package org.thingsboard.server.dao.sql.component; | ||
18 | import org.springframework.data.domain.Page; | 18 | import org.springframework.data.domain.Page; |
19 | import org.springframework.data.domain.Pageable; | 19 | import org.springframework.data.domain.Pageable; |
20 | import org.springframework.data.jpa.repository.Query; | 20 | import org.springframework.data.jpa.repository.Query; |
21 | -import org.springframework.data.repository.CrudRepository; | ||
22 | import org.springframework.data.repository.PagingAndSortingRepository; | 21 | import org.springframework.data.repository.PagingAndSortingRepository; |
23 | import org.springframework.data.repository.query.Param; | 22 | import org.springframework.data.repository.query.Param; |
24 | import org.thingsboard.server.common.data.plugin.ComponentScope; | 23 | import org.thingsboard.server.common.data.plugin.ComponentScope; |
@@ -26,13 +25,13 @@ import org.thingsboard.server.common.data.plugin.ComponentType; | @@ -26,13 +25,13 @@ import org.thingsboard.server.common.data.plugin.ComponentType; | ||
26 | import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity; | 25 | import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity; |
27 | import org.thingsboard.server.dao.util.SqlDao; | 26 | import org.thingsboard.server.dao.util.SqlDao; |
28 | 27 | ||
29 | -import java.util.List; | 28 | +import java.util.UUID; |
30 | 29 | ||
31 | /** | 30 | /** |
32 | * Created by Valerii Sosliuk on 5/6/2017. | 31 | * Created by Valerii Sosliuk on 5/6/2017. |
33 | */ | 32 | */ |
34 | @SqlDao | 33 | @SqlDao |
35 | -public interface ComponentDescriptorRepository extends PagingAndSortingRepository<ComponentDescriptorEntity, String> { | 34 | +public interface ComponentDescriptorRepository extends PagingAndSortingRepository<ComponentDescriptorEntity, UUID> { |
36 | 35 | ||
37 | ComponentDescriptorEntity findByClazz(String clazz); | 36 | ComponentDescriptorEntity findByClazz(String clazz); |
38 | 37 |
@@ -16,17 +16,18 @@ | @@ -16,17 +16,18 @@ | ||
16 | package org.thingsboard.server.dao.sql.component; | 16 | package org.thingsboard.server.dao.sql.component; |
17 | 17 | ||
18 | import org.springframework.stereotype.Repository; | 18 | import org.springframework.stereotype.Repository; |
19 | -import org.thingsboard.server.common.data.UUIDConverter; | ||
20 | import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity; | 19 | import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity; |
21 | import org.thingsboard.server.dao.util.HsqlDao; | 20 | import org.thingsboard.server.dao.util.HsqlDao; |
22 | import org.thingsboard.server.dao.util.SqlDao; | 21 | import org.thingsboard.server.dao.util.SqlDao; |
23 | 22 | ||
23 | +import javax.persistence.Query; | ||
24 | + | ||
24 | @SqlDao | 25 | @SqlDao |
25 | @HsqlDao | 26 | @HsqlDao |
26 | @Repository | 27 | @Repository |
27 | public class HsqlComponentDescriptorInsertRepository extends AbstractComponentDescriptorInsertRepository { | 28 | public class HsqlComponentDescriptorInsertRepository extends AbstractComponentDescriptorInsertRepository { |
28 | 29 | ||
29 | - private static final String P_KEY_CONFLICT_STATEMENT = "(component_descriptor.id=I.id)"; | 30 | + private static final String P_KEY_CONFLICT_STATEMENT = "(component_descriptor.id=UUID(I.id))"; |
30 | private static final String UNQ_KEY_CONFLICT_STATEMENT = "(component_descriptor.clazz=I.clazz)"; | 31 | private static final String UNQ_KEY_CONFLICT_STATEMENT = "(component_descriptor.clazz=I.clazz)"; |
31 | 32 | ||
32 | private static final String INSERT_OR_UPDATE_ON_P_KEY_CONFLICT = getInsertString(P_KEY_CONFLICT_STATEMENT); | 33 | private static final String INSERT_OR_UPDATE_ON_P_KEY_CONFLICT = getInsertString(P_KEY_CONFLICT_STATEMENT); |
@@ -38,13 +39,29 @@ public class HsqlComponentDescriptorInsertRepository extends AbstractComponentDe | @@ -38,13 +39,29 @@ public class HsqlComponentDescriptorInsertRepository extends AbstractComponentDe | ||
38 | } | 39 | } |
39 | 40 | ||
40 | @Override | 41 | @Override |
42 | + protected Query getQuery(ComponentDescriptorEntity entity, String query) { | ||
43 | + return entityManager.createNativeQuery(query, ComponentDescriptorEntity.class) | ||
44 | + .setParameter("id", entity.getUuid().toString()) | ||
45 | + .setParameter("created_time", entity.getCreatedTime()) | ||
46 | + .setParameter("actions", entity.getActions()) | ||
47 | + .setParameter("clazz", entity.getClazz()) | ||
48 | + .setParameter("configuration_descriptor", entity.getConfigurationDescriptor().toString()) | ||
49 | + .setParameter("name", entity.getName()) | ||
50 | + .setParameter("scope", entity.getScope().name()) | ||
51 | + .setParameter("search_text", entity.getSearchText()) | ||
52 | + .setParameter("type", entity.getType().name()); | ||
53 | + } | ||
54 | + | ||
55 | + @Override | ||
41 | protected ComponentDescriptorEntity doProcessSaveOrUpdate(ComponentDescriptorEntity entity, String query) { | 56 | protected ComponentDescriptorEntity doProcessSaveOrUpdate(ComponentDescriptorEntity entity, String query) { |
42 | getQuery(entity, query).executeUpdate(); | 57 | getQuery(entity, query).executeUpdate(); |
43 | - return entityManager.find(ComponentDescriptorEntity.class, UUIDConverter.fromTimeUUID(entity.getUuid())); | 58 | + return entityManager.find(ComponentDescriptorEntity.class, entity.getUuid()); |
44 | } | 59 | } |
45 | 60 | ||
46 | private static String getInsertString(String conflictStatement) { | 61 | private static String getInsertString(String conflictStatement) { |
47 | - return "MERGE INTO component_descriptor USING (VALUES :id, :actions, :clazz, :configuration_descriptor, :name, :scope, :search_text, :type) I (id, actions, clazz, configuration_descriptor, name, scope, search_text, type) ON " + conflictStatement + " WHEN MATCHED THEN UPDATE SET component_descriptor.id = I.id, component_descriptor.actions = I.actions, component_descriptor.clazz = I.clazz, component_descriptor.configuration_descriptor = I.configuration_descriptor, component_descriptor.name = I.name, component_descriptor.scope = I.scope, component_descriptor.search_text = I.search_text, component_descriptor.type = I.type" + | ||
48 | - " WHEN NOT MATCHED THEN INSERT (id, actions, clazz, configuration_descriptor, name, scope, search_text, type) VALUES (I.id, I.actions, I.clazz, I.configuration_descriptor, I.name, I.scope, I.search_text, I.type)"; | 62 | + return "MERGE INTO component_descriptor USING (VALUES :id, :created_time, :actions, :clazz, :configuration_descriptor, :name, :scope, :search_text, :type) I (id, created_time, actions, clazz, configuration_descriptor, name, scope, search_text, type) ON " |
63 | + + conflictStatement | ||
64 | + + " WHEN MATCHED THEN UPDATE SET component_descriptor.id = UUID(I.id), component_descriptor.actions = I.actions, component_descriptor.clazz = I.clazz, component_descriptor.configuration_descriptor = I.configuration_descriptor, component_descriptor.name = I.name, component_descriptor.scope = I.scope, component_descriptor.search_text = I.search_text, component_descriptor.type = I.type" + | ||
65 | + " WHEN NOT MATCHED THEN INSERT (id, created_time, actions, clazz, configuration_descriptor, name, scope, search_text, type) VALUES (UUID(I.id), I.created_time, I.actions, I.clazz, I.configuration_descriptor, I.name, I.scope, I.search_text, I.type)"; | ||
49 | } | 66 | } |
50 | } | 67 | } |
@@ -20,7 +20,6 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -20,7 +20,6 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
20 | import org.springframework.data.repository.CrudRepository; | 20 | import org.springframework.data.repository.CrudRepository; |
21 | import org.springframework.stereotype.Component; | 21 | import org.springframework.stereotype.Component; |
22 | import org.springframework.transaction.annotation.Transactional; | 22 | import org.springframework.transaction.annotation.Transactional; |
23 | -import org.thingsboard.server.common.data.UUIDConverter; | ||
24 | import org.thingsboard.server.common.data.id.ComponentDescriptorId; | 23 | import org.thingsboard.server.common.data.id.ComponentDescriptorId; |
25 | import org.thingsboard.server.common.data.id.TenantId; | 24 | import org.thingsboard.server.common.data.id.TenantId; |
26 | import org.thingsboard.server.common.data.page.PageData; | 25 | import org.thingsboard.server.common.data.page.PageData; |
@@ -36,6 +35,7 @@ import org.thingsboard.server.dao.util.SqlDao; | @@ -36,6 +35,7 @@ import org.thingsboard.server.dao.util.SqlDao; | ||
36 | 35 | ||
37 | import java.util.Objects; | 36 | import java.util.Objects; |
38 | import java.util.Optional; | 37 | import java.util.Optional; |
38 | +import java.util.UUID; | ||
39 | 39 | ||
40 | /** | 40 | /** |
41 | * Created by Valerii Sosliuk on 5/6/2017. | 41 | * Created by Valerii Sosliuk on 5/6/2017. |
@@ -57,16 +57,18 @@ public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<Comp | @@ -57,16 +57,18 @@ public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<Comp | ||
57 | } | 57 | } |
58 | 58 | ||
59 | @Override | 59 | @Override |
60 | - protected CrudRepository<ComponentDescriptorEntity, String> getCrudRepository() { | 60 | + protected CrudRepository<ComponentDescriptorEntity, UUID> getCrudRepository() { |
61 | return componentDescriptorRepository; | 61 | return componentDescriptorRepository; |
62 | } | 62 | } |
63 | 63 | ||
64 | @Override | 64 | @Override |
65 | public Optional<ComponentDescriptor> saveIfNotExist(TenantId tenantId, ComponentDescriptor component) { | 65 | public Optional<ComponentDescriptor> saveIfNotExist(TenantId tenantId, ComponentDescriptor component) { |
66 | if (component.getId() == null) { | 66 | if (component.getId() == null) { |
67 | - component.setId(new ComponentDescriptorId(Uuids.timeBased())); | 67 | + UUID uuid = Uuids.timeBased(); |
68 | + component.setId(new ComponentDescriptorId(uuid)); | ||
69 | + component.setCreatedTime(Uuids.unixTimestamp(uuid)); | ||
68 | } | 70 | } |
69 | - if (!componentDescriptorRepository.existsById(UUIDConverter.fromTimeUUID(component.getId().getId()))) { | 71 | + if (!componentDescriptorRepository.existsById(component.getId().getId())) { |
70 | ComponentDescriptorEntity componentDescriptorEntity = new ComponentDescriptorEntity(component); | 72 | ComponentDescriptorEntity componentDescriptorEntity = new ComponentDescriptorEntity(component); |
71 | ComponentDescriptorEntity savedEntity = componentDescriptorInsertRepository.saveOrUpdate(componentDescriptorEntity); | 73 | ComponentDescriptorEntity savedEntity = componentDescriptorInsertRepository.saveOrUpdate(componentDescriptorEntity); |
72 | return Optional.of(savedEntity.toData()); | 74 | return Optional.of(savedEntity.toData()); |
@@ -19,7 +19,6 @@ import org.springframework.stereotype.Repository; | @@ -19,7 +19,6 @@ import org.springframework.stereotype.Repository; | ||
19 | import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity; | 19 | import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity; |
20 | import org.thingsboard.server.dao.util.PsqlDao; | 20 | import org.thingsboard.server.dao.util.PsqlDao; |
21 | import org.thingsboard.server.dao.util.SqlDao; | 21 | import org.thingsboard.server.dao.util.SqlDao; |
22 | -import org.thingsboard.server.dao.util.SqlTsDao; | ||
23 | 22 | ||
24 | @SqlDao | 23 | @SqlDao |
25 | @PsqlDao | 24 | @PsqlDao |
@@ -49,10 +48,10 @@ public class PsqlComponentDescriptorInsertRepository extends AbstractComponentDe | @@ -49,10 +48,10 @@ public class PsqlComponentDescriptorInsertRepository extends AbstractComponentDe | ||
49 | } | 48 | } |
50 | 49 | ||
51 | private static String getInsertOrUpdateStatement(String conflictKeyStatement, String updateKeyStatement) { | 50 | private static String getInsertOrUpdateStatement(String conflictKeyStatement, String updateKeyStatement) { |
52 | - return "INSERT INTO component_descriptor (id, actions, clazz, configuration_descriptor, name, scope, search_text, type) VALUES (:id, :actions, :clazz, :configuration_descriptor, :name, :scope, :search_text, :type) ON CONFLICT " + conflictKeyStatement + " DO UPDATE SET " + updateKeyStatement + " returning *"; | 51 | + return "INSERT INTO component_descriptor (id, created_time, actions, clazz, configuration_descriptor, name, scope, search_text, type) VALUES (:id, :created_time, :actions, :clazz, :configuration_descriptor, :name, :scope, :search_text, :type) ON CONFLICT " + conflictKeyStatement + " DO UPDATE SET " + updateKeyStatement + " returning *"; |
53 | } | 52 | } |
54 | 53 | ||
55 | private static String getUpdateStatement(String id) { | 54 | private static String getUpdateStatement(String id) { |
56 | - return "actions = :actions, " + id + ", configuration_descriptor = :configuration_descriptor, name = :name, scope = :scope, search_text = :search_text, type = :type"; | 55 | + return "actions = :actions, " + id + ",created_time = :created_time, configuration_descriptor = :configuration_descriptor, name = :name, scope = :scope, search_text = :search_text, type = :type"; |
57 | } | 56 | } |
58 | } | 57 | } |
@@ -18,26 +18,25 @@ package org.thingsboard.server.dao.sql.customer; | @@ -18,26 +18,25 @@ package org.thingsboard.server.dao.sql.customer; | ||
18 | import org.springframework.data.domain.Page; | 18 | import org.springframework.data.domain.Page; |
19 | import org.springframework.data.domain.Pageable; | 19 | import org.springframework.data.domain.Pageable; |
20 | import org.springframework.data.jpa.repository.Query; | 20 | import org.springframework.data.jpa.repository.Query; |
21 | -import org.springframework.data.repository.CrudRepository; | ||
22 | import org.springframework.data.repository.PagingAndSortingRepository; | 21 | import org.springframework.data.repository.PagingAndSortingRepository; |
23 | import org.springframework.data.repository.query.Param; | 22 | import org.springframework.data.repository.query.Param; |
24 | import org.thingsboard.server.dao.model.sql.CustomerEntity; | 23 | import org.thingsboard.server.dao.model.sql.CustomerEntity; |
25 | import org.thingsboard.server.dao.util.SqlDao; | 24 | import org.thingsboard.server.dao.util.SqlDao; |
26 | 25 | ||
27 | -import java.util.List; | 26 | +import java.util.UUID; |
28 | 27 | ||
29 | /** | 28 | /** |
30 | * Created by Valerii Sosliuk on 5/6/2017. | 29 | * Created by Valerii Sosliuk on 5/6/2017. |
31 | */ | 30 | */ |
32 | @SqlDao | 31 | @SqlDao |
33 | -public interface CustomerRepository extends PagingAndSortingRepository<CustomerEntity, String> { | 32 | +public interface CustomerRepository extends PagingAndSortingRepository<CustomerEntity, UUID> { |
34 | 33 | ||
35 | @Query("SELECT c FROM CustomerEntity c WHERE c.tenantId = :tenantId " + | 34 | @Query("SELECT c FROM CustomerEntity c WHERE c.tenantId = :tenantId " + |
36 | "AND LOWER(c.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") | 35 | "AND LOWER(c.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
37 | - Page<CustomerEntity> findByTenantId(@Param("tenantId") String tenantId, | 36 | + Page<CustomerEntity> findByTenantId(@Param("tenantId") UUID tenantId, |
38 | @Param("textSearch") String textSearch, | 37 | @Param("textSearch") String textSearch, |
39 | Pageable pageable); | 38 | Pageable pageable); |
40 | 39 | ||
41 | - CustomerEntity findByTenantIdAndTitle(String tenantId, String title); | 40 | + CustomerEntity findByTenantIdAndTitle(UUID tenantId, String title); |
42 | 41 | ||
43 | } | 42 | } |
@@ -19,7 +19,6 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -19,7 +19,6 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
19 | import org.springframework.data.repository.CrudRepository; | 19 | import org.springframework.data.repository.CrudRepository; |
20 | import org.springframework.stereotype.Component; | 20 | import org.springframework.stereotype.Component; |
21 | import org.thingsboard.server.common.data.Customer; | 21 | import org.thingsboard.server.common.data.Customer; |
22 | -import org.thingsboard.server.common.data.UUIDConverter; | ||
23 | import org.thingsboard.server.common.data.page.PageData; | 22 | import org.thingsboard.server.common.data.page.PageData; |
24 | import org.thingsboard.server.common.data.page.PageLink; | 23 | import org.thingsboard.server.common.data.page.PageLink; |
25 | import org.thingsboard.server.dao.DaoUtil; | 24 | import org.thingsboard.server.dao.DaoUtil; |
@@ -48,21 +47,21 @@ public class JpaCustomerDao extends JpaAbstractSearchTextDao<CustomerEntity, Cus | @@ -48,21 +47,21 @@ public class JpaCustomerDao extends JpaAbstractSearchTextDao<CustomerEntity, Cus | ||
48 | } | 47 | } |
49 | 48 | ||
50 | @Override | 49 | @Override |
51 | - protected CrudRepository<CustomerEntity, String> getCrudRepository() { | 50 | + protected CrudRepository<CustomerEntity, UUID> getCrudRepository() { |
52 | return customerRepository; | 51 | return customerRepository; |
53 | } | 52 | } |
54 | 53 | ||
55 | @Override | 54 | @Override |
56 | public PageData<Customer> findCustomersByTenantId(UUID tenantId, PageLink pageLink) { | 55 | public PageData<Customer> findCustomersByTenantId(UUID tenantId, PageLink pageLink) { |
57 | return DaoUtil.toPageData(customerRepository.findByTenantId( | 56 | return DaoUtil.toPageData(customerRepository.findByTenantId( |
58 | - UUIDConverter.fromTimeUUID(tenantId), | 57 | + tenantId, |
59 | Objects.toString(pageLink.getTextSearch(), ""), | 58 | Objects.toString(pageLink.getTextSearch(), ""), |
60 | DaoUtil.toPageable(pageLink))); | 59 | DaoUtil.toPageable(pageLink))); |
61 | } | 60 | } |
62 | 61 | ||
63 | @Override | 62 | @Override |
64 | public Optional<Customer> findCustomersByTenantIdAndTitle(UUID tenantId, String title) { | 63 | public Optional<Customer> findCustomersByTenantIdAndTitle(UUID tenantId, String title) { |
65 | - Customer customer = DaoUtil.getData(customerRepository.findByTenantIdAndTitle(UUIDConverter.fromTimeUUID(tenantId), title)); | 64 | + Customer customer = DaoUtil.getData(customerRepository.findByTenantIdAndTitle(tenantId, title)); |
66 | return Optional.ofNullable(customer); | 65 | return Optional.ofNullable(customer); |
67 | } | 66 | } |
68 | } | 67 | } |
@@ -18,23 +18,22 @@ package org.thingsboard.server.dao.sql.dashboard; | @@ -18,23 +18,22 @@ package org.thingsboard.server.dao.sql.dashboard; | ||
18 | import org.springframework.data.domain.Page; | 18 | import org.springframework.data.domain.Page; |
19 | import org.springframework.data.domain.Pageable; | 19 | import org.springframework.data.domain.Pageable; |
20 | import org.springframework.data.jpa.repository.Query; | 20 | import org.springframework.data.jpa.repository.Query; |
21 | -import org.springframework.data.repository.CrudRepository; | ||
22 | import org.springframework.data.repository.PagingAndSortingRepository; | 21 | import org.springframework.data.repository.PagingAndSortingRepository; |
23 | import org.springframework.data.repository.query.Param; | 22 | import org.springframework.data.repository.query.Param; |
24 | import org.thingsboard.server.dao.model.sql.DashboardInfoEntity; | 23 | import org.thingsboard.server.dao.model.sql.DashboardInfoEntity; |
25 | import org.thingsboard.server.dao.util.SqlDao; | 24 | import org.thingsboard.server.dao.util.SqlDao; |
26 | 25 | ||
27 | -import java.util.List; | 26 | +import java.util.UUID; |
28 | 27 | ||
29 | /** | 28 | /** |
30 | * Created by Valerii Sosliuk on 5/6/2017. | 29 | * Created by Valerii Sosliuk on 5/6/2017. |
31 | */ | 30 | */ |
32 | @SqlDao | 31 | @SqlDao |
33 | -public interface DashboardInfoRepository extends PagingAndSortingRepository<DashboardInfoEntity, String> { | 32 | +public interface DashboardInfoRepository extends PagingAndSortingRepository<DashboardInfoEntity, UUID> { |
34 | 33 | ||
35 | @Query("SELECT di FROM DashboardInfoEntity di WHERE di.tenantId = :tenantId " + | 34 | @Query("SELECT di FROM DashboardInfoEntity di WHERE di.tenantId = :tenantId " + |
36 | "AND LOWER(di.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") | 35 | "AND LOWER(di.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") |
37 | - Page<DashboardInfoEntity> findByTenantId(@Param("tenantId") String tenantId, | 36 | + Page<DashboardInfoEntity> findByTenantId(@Param("tenantId") UUID tenantId, |
38 | @Param("searchText") String searchText, | 37 | @Param("searchText") String searchText, |
39 | Pageable pageable); | 38 | Pageable pageable); |
40 | 39 | ||
@@ -42,8 +41,8 @@ public interface DashboardInfoRepository extends PagingAndSortingRepository<Dash | @@ -42,8 +41,8 @@ public interface DashboardInfoRepository extends PagingAndSortingRepository<Dash | ||
42 | "AND di.id = re.toId AND re.toType = 'DASHBOARD' AND re.relationTypeGroup = 'DASHBOARD' " + | 41 | "AND di.id = re.toId AND re.toType = 'DASHBOARD' AND re.relationTypeGroup = 'DASHBOARD' " + |
43 | "AND re.relationType = 'Contains' AND re.fromId = :customerId AND re.fromType = 'CUSTOMER' " + | 42 | "AND re.relationType = 'Contains' AND re.fromId = :customerId AND re.fromType = 'CUSTOMER' " + |
44 | "AND LOWER(di.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") | 43 | "AND LOWER(di.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") |
45 | - Page<DashboardInfoEntity> findByTenantIdAndCustomerId(@Param("tenantId") String tenantId, | ||
46 | - @Param("customerId") String customerId, | 44 | + Page<DashboardInfoEntity> findByTenantIdAndCustomerId(@Param("tenantId") UUID tenantId, |
45 | + @Param("customerId") UUID customerId, | ||
47 | @Param("searchText") String searchText, | 46 | @Param("searchText") String searchText, |
48 | Pageable pageable); | 47 | Pageable pageable); |
49 | 48 |
@@ -19,9 +19,11 @@ import org.springframework.data.repository.CrudRepository; | @@ -19,9 +19,11 @@ import org.springframework.data.repository.CrudRepository; | ||
19 | import org.thingsboard.server.dao.model.sql.DashboardEntity; | 19 | import org.thingsboard.server.dao.model.sql.DashboardEntity; |
20 | import org.thingsboard.server.dao.util.SqlDao; | 20 | import org.thingsboard.server.dao.util.SqlDao; |
21 | 21 | ||
22 | +import java.util.UUID; | ||
23 | + | ||
22 | /** | 24 | /** |
23 | * Created by Valerii Sosliuk on 5/6/2017. | 25 | * Created by Valerii Sosliuk on 5/6/2017. |
24 | */ | 26 | */ |
25 | @SqlDao | 27 | @SqlDao |
26 | -public interface DashboardRepository extends CrudRepository<DashboardEntity, String> { | 28 | +public interface DashboardRepository extends CrudRepository<DashboardEntity, UUID> { |
27 | } | 29 | } |
@@ -24,6 +24,8 @@ import org.thingsboard.server.dao.model.sql.DashboardEntity; | @@ -24,6 +24,8 @@ import org.thingsboard.server.dao.model.sql.DashboardEntity; | ||
24 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; | 24 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
25 | import org.thingsboard.server.dao.util.SqlDao; | 25 | import org.thingsboard.server.dao.util.SqlDao; |
26 | 26 | ||
27 | +import java.util.UUID; | ||
28 | + | ||
27 | /** | 29 | /** |
28 | * Created by Valerii Sosliuk on 5/6/2017. | 30 | * Created by Valerii Sosliuk on 5/6/2017. |
29 | */ | 31 | */ |
@@ -40,7 +42,7 @@ public class JpaDashboardDao extends JpaAbstractSearchTextDao<DashboardEntity, D | @@ -40,7 +42,7 @@ public class JpaDashboardDao extends JpaAbstractSearchTextDao<DashboardEntity, D | ||
40 | } | 42 | } |
41 | 43 | ||
42 | @Override | 44 | @Override |
43 | - protected CrudRepository<DashboardEntity, String> getCrudRepository() { | 45 | + protected CrudRepository<DashboardEntity, UUID> getCrudRepository() { |
44 | return dashboardRepository; | 46 | return dashboardRepository; |
45 | } | 47 | } |
46 | } | 48 | } |
@@ -20,7 +20,6 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -20,7 +20,6 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
20 | import org.springframework.data.repository.CrudRepository; | 20 | import org.springframework.data.repository.CrudRepository; |
21 | import org.springframework.stereotype.Component; | 21 | import org.springframework.stereotype.Component; |
22 | import org.thingsboard.server.common.data.DashboardInfo; | 22 | import org.thingsboard.server.common.data.DashboardInfo; |
23 | -import org.thingsboard.server.common.data.UUIDConverter; | ||
24 | import org.thingsboard.server.common.data.page.PageData; | 23 | import org.thingsboard.server.common.data.page.PageData; |
25 | import org.thingsboard.server.common.data.page.PageLink; | 24 | import org.thingsboard.server.common.data.page.PageLink; |
26 | import org.thingsboard.server.dao.DaoUtil; | 25 | import org.thingsboard.server.dao.DaoUtil; |
@@ -61,7 +60,7 @@ public class JpaDashboardInfoDao extends JpaAbstractSearchTextDao<DashboardInfoE | @@ -61,7 +60,7 @@ public class JpaDashboardInfoDao extends JpaAbstractSearchTextDao<DashboardInfoE | ||
61 | public PageData<DashboardInfo> findDashboardsByTenantId(UUID tenantId, PageLink pageLink) { | 60 | public PageData<DashboardInfo> findDashboardsByTenantId(UUID tenantId, PageLink pageLink) { |
62 | return DaoUtil.toPageData(dashboardInfoRepository | 61 | return DaoUtil.toPageData(dashboardInfoRepository |
63 | .findByTenantId( | 62 | .findByTenantId( |
64 | - UUIDConverter.fromTimeUUID(tenantId), | 63 | + tenantId, |
65 | Objects.toString(pageLink.getTextSearch(), ""), | 64 | Objects.toString(pageLink.getTextSearch(), ""), |
66 | DaoUtil.toPageable(pageLink))); | 65 | DaoUtil.toPageable(pageLink))); |
67 | } | 66 | } |
@@ -70,8 +69,8 @@ public class JpaDashboardInfoDao extends JpaAbstractSearchTextDao<DashboardInfoE | @@ -70,8 +69,8 @@ public class JpaDashboardInfoDao extends JpaAbstractSearchTextDao<DashboardInfoE | ||
70 | public PageData<DashboardInfo> findDashboardsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink) { | 69 | public PageData<DashboardInfo> findDashboardsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink) { |
71 | return DaoUtil.toPageData(dashboardInfoRepository | 70 | return DaoUtil.toPageData(dashboardInfoRepository |
72 | .findByTenantIdAndCustomerId( | 71 | .findByTenantIdAndCustomerId( |
73 | - UUIDConverter.fromTimeUUID(tenantId), | ||
74 | - UUIDConverter.fromTimeUUID(customerId), | 72 | + tenantId, |
73 | + customerId, | ||
75 | Objects.toString(pageLink.getTextSearch(), ""), | 74 | Objects.toString(pageLink.getTextSearch(), ""), |
76 | DaoUtil.toPageable(pageLink))); | 75 | DaoUtil.toPageable(pageLink))); |
77 | } | 76 | } |
@@ -19,13 +19,15 @@ import org.springframework.data.repository.CrudRepository; | @@ -19,13 +19,15 @@ import org.springframework.data.repository.CrudRepository; | ||
19 | import org.thingsboard.server.dao.model.sql.DeviceCredentialsEntity; | 19 | import org.thingsboard.server.dao.model.sql.DeviceCredentialsEntity; |
20 | import org.thingsboard.server.dao.util.SqlDao; | 20 | import org.thingsboard.server.dao.util.SqlDao; |
21 | 21 | ||
22 | +import java.util.UUID; | ||
23 | + | ||
22 | /** | 24 | /** |
23 | * Created by Valerii Sosliuk on 5/6/2017. | 25 | * Created by Valerii Sosliuk on 5/6/2017. |
24 | */ | 26 | */ |
25 | @SqlDao | 27 | @SqlDao |
26 | -public interface DeviceCredentialsRepository extends CrudRepository<DeviceCredentialsEntity, String> { | 28 | +public interface DeviceCredentialsRepository extends CrudRepository<DeviceCredentialsEntity, UUID> { |
27 | 29 | ||
28 | - DeviceCredentialsEntity findByDeviceId(String deviceId); | 30 | + DeviceCredentialsEntity findByDeviceId(UUID deviceId); |
29 | 31 | ||
30 | DeviceCredentialsEntity findByCredentialsId(String credentialsId); | 32 | DeviceCredentialsEntity findByCredentialsId(String credentialsId); |
31 | } | 33 | } |
@@ -25,24 +25,25 @@ import org.thingsboard.server.dao.model.sql.DeviceInfoEntity; | @@ -25,24 +25,25 @@ import org.thingsboard.server.dao.model.sql.DeviceInfoEntity; | ||
25 | import org.thingsboard.server.dao.util.SqlDao; | 25 | import org.thingsboard.server.dao.util.SqlDao; |
26 | 26 | ||
27 | import java.util.List; | 27 | import java.util.List; |
28 | +import java.util.UUID; | ||
28 | 29 | ||
29 | /** | 30 | /** |
30 | * Created by Valerii Sosliuk on 5/6/2017. | 31 | * Created by Valerii Sosliuk on 5/6/2017. |
31 | */ | 32 | */ |
32 | @SqlDao | 33 | @SqlDao |
33 | -public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntity, String> { | 34 | +public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntity, UUID> { |
34 | 35 | ||
35 | @Query("SELECT new org.thingsboard.server.dao.model.sql.DeviceInfoEntity(d, c.title, c.additionalInfo) " + | 36 | @Query("SELECT new org.thingsboard.server.dao.model.sql.DeviceInfoEntity(d, c.title, c.additionalInfo) " + |
36 | "FROM DeviceEntity d " + | 37 | "FROM DeviceEntity d " + |
37 | "LEFT JOIN CustomerEntity c on c.id = d.customerId " + | 38 | "LEFT JOIN CustomerEntity c on c.id = d.customerId " + |
38 | "WHERE d.id = :deviceId") | 39 | "WHERE d.id = :deviceId") |
39 | - DeviceInfoEntity findDeviceInfoById(@Param("deviceId") String deviceId); | 40 | + DeviceInfoEntity findDeviceInfoById(@Param("deviceId") UUID deviceId); |
40 | 41 | ||
41 | @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " + | 42 | @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " + |
42 | "AND d.customerId = :customerId " + | 43 | "AND d.customerId = :customerId " + |
43 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") | 44 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") |
44 | - Page<DeviceEntity> findByTenantIdAndCustomerId(@Param("tenantId") String tenantId, | ||
45 | - @Param("customerId") String customerId, | 45 | + Page<DeviceEntity> findByTenantIdAndCustomerId(@Param("tenantId") UUID tenantId, |
46 | + @Param("customerId") UUID customerId, | ||
46 | @Param("searchText") String searchText, | 47 | @Param("searchText") String searchText, |
47 | Pageable pageable); | 48 | Pageable pageable); |
48 | 49 | ||
@@ -52,18 +53,18 @@ public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntit | @@ -52,18 +53,18 @@ public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntit | ||
52 | "WHERE d.tenantId = :tenantId " + | 53 | "WHERE d.tenantId = :tenantId " + |
53 | "AND d.customerId = :customerId " + | 54 | "AND d.customerId = :customerId " + |
54 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") | 55 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") |
55 | - Page<DeviceInfoEntity> findDeviceInfosByTenantIdAndCustomerId(@Param("tenantId") String tenantId, | ||
56 | - @Param("customerId") String customerId, | 56 | + Page<DeviceInfoEntity> findDeviceInfosByTenantIdAndCustomerId(@Param("tenantId") UUID tenantId, |
57 | + @Param("customerId") UUID customerId, | ||
57 | @Param("searchText") String searchText, | 58 | @Param("searchText") String searchText, |
58 | Pageable pageable); | 59 | Pageable pageable); |
59 | 60 | ||
60 | @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId") | 61 | @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId") |
61 | - Page<DeviceEntity> findByTenantId(@Param("tenantId") String tenantId, | 62 | + Page<DeviceEntity> findByTenantId(@Param("tenantId") UUID tenantId, |
62 | Pageable pageable); | 63 | Pageable pageable); |
63 | 64 | ||
64 | @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " + | 65 | @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " + |
65 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") | 66 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
66 | - Page<DeviceEntity> findByTenantId(@Param("tenantId") String tenantId, | 67 | + Page<DeviceEntity> findByTenantId(@Param("tenantId") UUID tenantId, |
67 | @Param("textSearch") String textSearch, | 68 | @Param("textSearch") String textSearch, |
68 | Pageable pageable); | 69 | Pageable pageable); |
69 | 70 | ||
@@ -72,14 +73,14 @@ public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntit | @@ -72,14 +73,14 @@ public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntit | ||
72 | "LEFT JOIN CustomerEntity c on c.id = d.customerId " + | 73 | "LEFT JOIN CustomerEntity c on c.id = d.customerId " + |
73 | "WHERE d.tenantId = :tenantId " + | 74 | "WHERE d.tenantId = :tenantId " + |
74 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") | 75 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
75 | - Page<DeviceInfoEntity> findDeviceInfosByTenantId(@Param("tenantId") String tenantId, | 76 | + Page<DeviceInfoEntity> findDeviceInfosByTenantId(@Param("tenantId") UUID tenantId, |
76 | @Param("textSearch") String textSearch, | 77 | @Param("textSearch") String textSearch, |
77 | Pageable pageable); | 78 | Pageable pageable); |
78 | 79 | ||
79 | @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " + | 80 | @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " + |
80 | "AND d.type = :type " + | 81 | "AND d.type = :type " + |
81 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") | 82 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
82 | - Page<DeviceEntity> findByTenantIdAndType(@Param("tenantId") String tenantId, | 83 | + Page<DeviceEntity> findByTenantIdAndType(@Param("tenantId") UUID tenantId, |
83 | @Param("type") String type, | 84 | @Param("type") String type, |
84 | @Param("textSearch") String textSearch, | 85 | @Param("textSearch") String textSearch, |
85 | Pageable pageable); | 86 | Pageable pageable); |
@@ -90,7 +91,7 @@ public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntit | @@ -90,7 +91,7 @@ public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntit | ||
90 | "WHERE d.tenantId = :tenantId " + | 91 | "WHERE d.tenantId = :tenantId " + |
91 | "AND d.type = :type " + | 92 | "AND d.type = :type " + |
92 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") | 93 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
93 | - Page<DeviceInfoEntity> findDeviceInfosByTenantIdAndType(@Param("tenantId") String tenantId, | 94 | + Page<DeviceInfoEntity> findDeviceInfosByTenantIdAndType(@Param("tenantId") UUID tenantId, |
94 | @Param("type") String type, | 95 | @Param("type") String type, |
95 | @Param("textSearch") String textSearch, | 96 | @Param("textSearch") String textSearch, |
96 | Pageable pageable); | 97 | Pageable pageable); |
@@ -99,8 +100,8 @@ public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntit | @@ -99,8 +100,8 @@ public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntit | ||
99 | "AND d.customerId = :customerId " + | 100 | "AND d.customerId = :customerId " + |
100 | "AND d.type = :type " + | 101 | "AND d.type = :type " + |
101 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") | 102 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
102 | - Page<DeviceEntity> findByTenantIdAndCustomerIdAndType(@Param("tenantId") String tenantId, | ||
103 | - @Param("customerId") String customerId, | 103 | + Page<DeviceEntity> findByTenantIdAndCustomerIdAndType(@Param("tenantId") UUID tenantId, |
104 | + @Param("customerId") UUID customerId, | ||
104 | @Param("type") String type, | 105 | @Param("type") String type, |
105 | @Param("textSearch") String textSearch, | 106 | @Param("textSearch") String textSearch, |
106 | Pageable pageable); | 107 | Pageable pageable); |
@@ -112,18 +113,18 @@ public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntit | @@ -112,18 +113,18 @@ public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntit | ||
112 | "AND d.customerId = :customerId " + | 113 | "AND d.customerId = :customerId " + |
113 | "AND d.type = :type " + | 114 | "AND d.type = :type " + |
114 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") | 115 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
115 | - Page<DeviceInfoEntity> findDeviceInfosByTenantIdAndCustomerIdAndType(@Param("tenantId") String tenantId, | ||
116 | - @Param("customerId") String customerId, | 116 | + Page<DeviceInfoEntity> findDeviceInfosByTenantIdAndCustomerIdAndType(@Param("tenantId") UUID tenantId, |
117 | + @Param("customerId") UUID customerId, | ||
117 | @Param("type") String type, | 118 | @Param("type") String type, |
118 | @Param("textSearch") String textSearch, | 119 | @Param("textSearch") String textSearch, |
119 | Pageable pageable); | 120 | Pageable pageable); |
120 | 121 | ||
121 | @Query("SELECT DISTINCT d.type FROM DeviceEntity d WHERE d.tenantId = :tenantId") | 122 | @Query("SELECT DISTINCT d.type FROM DeviceEntity d WHERE d.tenantId = :tenantId") |
122 | - List<String> findTenantDeviceTypes(@Param("tenantId") String tenantId); | 123 | + List<String> findTenantDeviceTypes(@Param("tenantId") UUID tenantId); |
123 | 124 | ||
124 | - DeviceEntity findByTenantIdAndName(String tenantId, String name); | 125 | + DeviceEntity findByTenantIdAndName(UUID tenantId, String name); |
125 | 126 | ||
126 | - List<DeviceEntity> findDevicesByTenantIdAndCustomerIdAndIdIn(String tenantId, String customerId, List<String> deviceIds); | 127 | + List<DeviceEntity> findDevicesByTenantIdAndCustomerIdAndIdIn(UUID tenantId, UUID customerId, List<UUID> deviceIds); |
127 | 128 | ||
128 | - List<DeviceEntity> findDevicesByTenantIdAndIdIn(String tenantId, List<String> deviceIds); | 129 | + List<DeviceEntity> findDevicesByTenantIdAndIdIn(UUID tenantId, List<UUID> deviceIds); |
129 | } | 130 | } |
@@ -18,7 +18,6 @@ package org.thingsboard.server.dao.sql.device; | @@ -18,7 +18,6 @@ package org.thingsboard.server.dao.sql.device; | ||
18 | import org.springframework.beans.factory.annotation.Autowired; | 18 | import org.springframework.beans.factory.annotation.Autowired; |
19 | import org.springframework.data.repository.CrudRepository; | 19 | import org.springframework.data.repository.CrudRepository; |
20 | import org.springframework.stereotype.Component; | 20 | import org.springframework.stereotype.Component; |
21 | -import org.thingsboard.server.common.data.UUIDConverter; | ||
22 | import org.thingsboard.server.common.data.id.TenantId; | 21 | import org.thingsboard.server.common.data.id.TenantId; |
23 | import org.thingsboard.server.common.data.security.DeviceCredentials; | 22 | import org.thingsboard.server.common.data.security.DeviceCredentials; |
24 | import org.thingsboard.server.dao.DaoUtil; | 23 | import org.thingsboard.server.dao.DaoUtil; |
@@ -45,13 +44,13 @@ public class JpaDeviceCredentialsDao extends JpaAbstractDao<DeviceCredentialsEnt | @@ -45,13 +44,13 @@ public class JpaDeviceCredentialsDao extends JpaAbstractDao<DeviceCredentialsEnt | ||
45 | } | 44 | } |
46 | 45 | ||
47 | @Override | 46 | @Override |
48 | - protected CrudRepository<DeviceCredentialsEntity, String> getCrudRepository() { | 47 | + protected CrudRepository<DeviceCredentialsEntity, UUID> getCrudRepository() { |
49 | return deviceCredentialsRepository; | 48 | return deviceCredentialsRepository; |
50 | } | 49 | } |
51 | 50 | ||
52 | @Override | 51 | @Override |
53 | public DeviceCredentials findByDeviceId(TenantId tenantId, UUID deviceId) { | 52 | public DeviceCredentials findByDeviceId(TenantId tenantId, UUID deviceId) { |
54 | - return DaoUtil.getData(deviceCredentialsRepository.findByDeviceId(UUIDConverter.fromTimeUUID(deviceId))); | 53 | + return DaoUtil.getData(deviceCredentialsRepository.findByDeviceId(deviceId)); |
55 | } | 54 | } |
56 | 55 | ||
57 | @Override | 56 | @Override |
@@ -24,7 +24,6 @@ import org.thingsboard.server.common.data.Device; | @@ -24,7 +24,6 @@ import org.thingsboard.server.common.data.Device; | ||
24 | import org.thingsboard.server.common.data.DeviceInfo; | 24 | import org.thingsboard.server.common.data.DeviceInfo; |
25 | import org.thingsboard.server.common.data.EntitySubtype; | 25 | import org.thingsboard.server.common.data.EntitySubtype; |
26 | import org.thingsboard.server.common.data.EntityType; | 26 | import org.thingsboard.server.common.data.EntityType; |
27 | -import org.thingsboard.server.common.data.UUIDConverter; | ||
28 | import org.thingsboard.server.common.data.id.TenantId; | 27 | import org.thingsboard.server.common.data.id.TenantId; |
29 | import org.thingsboard.server.common.data.page.PageData; | 28 | import org.thingsboard.server.common.data.page.PageData; |
30 | import org.thingsboard.server.common.data.page.PageLink; | 29 | import org.thingsboard.server.common.data.page.PageLink; |
@@ -42,9 +41,6 @@ import java.util.Objects; | @@ -42,9 +41,6 @@ import java.util.Objects; | ||
42 | import java.util.Optional; | 41 | import java.util.Optional; |
43 | import java.util.UUID; | 42 | import java.util.UUID; |
44 | 43 | ||
45 | -import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID; | ||
46 | -import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUIDs; | ||
47 | - | ||
48 | /** | 44 | /** |
49 | * Created by Valerii Sosliuk on 5/6/2017. | 45 | * Created by Valerii Sosliuk on 5/6/2017. |
50 | */ | 46 | */ |
@@ -61,13 +57,13 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | @@ -61,13 +57,13 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | ||
61 | } | 57 | } |
62 | 58 | ||
63 | @Override | 59 | @Override |
64 | - protected CrudRepository<DeviceEntity, String> getCrudRepository() { | 60 | + protected CrudRepository<DeviceEntity, UUID> getCrudRepository() { |
65 | return deviceRepository; | 61 | return deviceRepository; |
66 | } | 62 | } |
67 | 63 | ||
68 | @Override | 64 | @Override |
69 | public DeviceInfo findDeviceInfoById(TenantId tenantId, UUID deviceId) { | 65 | public DeviceInfo findDeviceInfoById(TenantId tenantId, UUID deviceId) { |
70 | - return DaoUtil.getData(deviceRepository.findDeviceInfoById(fromTimeUUID(deviceId))); | 66 | + return DaoUtil.getData(deviceRepository.findDeviceInfoById(deviceId)); |
71 | } | 67 | } |
72 | 68 | ||
73 | @Override | 69 | @Override |
@@ -75,12 +71,12 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | @@ -75,12 +71,12 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | ||
75 | if (StringUtils.isEmpty(pageLink.getTextSearch())) { | 71 | if (StringUtils.isEmpty(pageLink.getTextSearch())) { |
76 | return DaoUtil.toPageData( | 72 | return DaoUtil.toPageData( |
77 | deviceRepository.findByTenantId( | 73 | deviceRepository.findByTenantId( |
78 | - fromTimeUUID(tenantId), | 74 | + tenantId, |
79 | DaoUtil.toPageable(pageLink))); | 75 | DaoUtil.toPageable(pageLink))); |
80 | } else { | 76 | } else { |
81 | return DaoUtil.toPageData( | 77 | return DaoUtil.toPageData( |
82 | deviceRepository.findByTenantId( | 78 | deviceRepository.findByTenantId( |
83 | - fromTimeUUID(tenantId), | 79 | + tenantId, |
84 | Objects.toString(pageLink.getTextSearch(), ""), | 80 | Objects.toString(pageLink.getTextSearch(), ""), |
85 | DaoUtil.toPageable(pageLink))); | 81 | DaoUtil.toPageable(pageLink))); |
86 | } | 82 | } |
@@ -90,22 +86,22 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | @@ -90,22 +86,22 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | ||
90 | public PageData<DeviceInfo> findDeviceInfosByTenantId(UUID tenantId, PageLink pageLink) { | 86 | public PageData<DeviceInfo> findDeviceInfosByTenantId(UUID tenantId, PageLink pageLink) { |
91 | return DaoUtil.toPageData( | 87 | return DaoUtil.toPageData( |
92 | deviceRepository.findDeviceInfosByTenantId( | 88 | deviceRepository.findDeviceInfosByTenantId( |
93 | - fromTimeUUID(tenantId), | 89 | + tenantId, |
94 | Objects.toString(pageLink.getTextSearch(), ""), | 90 | Objects.toString(pageLink.getTextSearch(), ""), |
95 | DaoUtil.toPageable(pageLink, DeviceInfoEntity.deviceInfoColumnMap))); | 91 | DaoUtil.toPageable(pageLink, DeviceInfoEntity.deviceInfoColumnMap))); |
96 | } | 92 | } |
97 | 93 | ||
98 | @Override | 94 | @Override |
99 | public ListenableFuture<List<Device>> findDevicesByTenantIdAndIdsAsync(UUID tenantId, List<UUID> deviceIds) { | 95 | public ListenableFuture<List<Device>> findDevicesByTenantIdAndIdsAsync(UUID tenantId, List<UUID> deviceIds) { |
100 | - return service.submit(() -> DaoUtil.convertDataList(deviceRepository.findDevicesByTenantIdAndIdIn(UUIDConverter.fromTimeUUID(tenantId), fromTimeUUIDs(deviceIds)))); | 96 | + return service.submit(() -> DaoUtil.convertDataList(deviceRepository.findDevicesByTenantIdAndIdIn(tenantId, deviceIds))); |
101 | } | 97 | } |
102 | 98 | ||
103 | @Override | 99 | @Override |
104 | public PageData<Device> findDevicesByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink) { | 100 | public PageData<Device> findDevicesByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink) { |
105 | return DaoUtil.toPageData( | 101 | return DaoUtil.toPageData( |
106 | deviceRepository.findByTenantIdAndCustomerId( | 102 | deviceRepository.findByTenantIdAndCustomerId( |
107 | - fromTimeUUID(tenantId), | ||
108 | - fromTimeUUID(customerId), | 103 | + tenantId, |
104 | + customerId, | ||
109 | Objects.toString(pageLink.getTextSearch(), ""), | 105 | Objects.toString(pageLink.getTextSearch(), ""), |
110 | DaoUtil.toPageable(pageLink))); | 106 | DaoUtil.toPageable(pageLink))); |
111 | } | 107 | } |
@@ -114,8 +110,8 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | @@ -114,8 +110,8 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | ||
114 | public PageData<DeviceInfo> findDeviceInfosByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink) { | 110 | public PageData<DeviceInfo> findDeviceInfosByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink) { |
115 | return DaoUtil.toPageData( | 111 | return DaoUtil.toPageData( |
116 | deviceRepository.findDeviceInfosByTenantIdAndCustomerId( | 112 | deviceRepository.findDeviceInfosByTenantIdAndCustomerId( |
117 | - fromTimeUUID(tenantId), | ||
118 | - fromTimeUUID(customerId), | 113 | + tenantId, |
114 | + customerId, | ||
119 | Objects.toString(pageLink.getTextSearch(), ""), | 115 | Objects.toString(pageLink.getTextSearch(), ""), |
120 | DaoUtil.toPageable(pageLink, DeviceInfoEntity.deviceInfoColumnMap))); | 116 | DaoUtil.toPageable(pageLink, DeviceInfoEntity.deviceInfoColumnMap))); |
121 | } | 117 | } |
@@ -123,12 +119,12 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | @@ -123,12 +119,12 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | ||
123 | @Override | 119 | @Override |
124 | public ListenableFuture<List<Device>> findDevicesByTenantIdCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> deviceIds) { | 120 | public ListenableFuture<List<Device>> findDevicesByTenantIdCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> deviceIds) { |
125 | return service.submit(() -> DaoUtil.convertDataList( | 121 | return service.submit(() -> DaoUtil.convertDataList( |
126 | - deviceRepository.findDevicesByTenantIdAndCustomerIdAndIdIn(fromTimeUUID(tenantId), fromTimeUUID(customerId), fromTimeUUIDs(deviceIds)))); | 122 | + deviceRepository.findDevicesByTenantIdAndCustomerIdAndIdIn(tenantId, customerId, deviceIds))); |
127 | } | 123 | } |
128 | 124 | ||
129 | @Override | 125 | @Override |
130 | public Optional<Device> findDeviceByTenantIdAndName(UUID tenantId, String name) { | 126 | public Optional<Device> findDeviceByTenantIdAndName(UUID tenantId, String name) { |
131 | - Device device = DaoUtil.getData(deviceRepository.findByTenantIdAndName(fromTimeUUID(tenantId), name)); | 127 | + Device device = DaoUtil.getData(deviceRepository.findByTenantIdAndName(tenantId, name)); |
132 | return Optional.ofNullable(device); | 128 | return Optional.ofNullable(device); |
133 | } | 129 | } |
134 | 130 | ||
@@ -136,7 +132,7 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | @@ -136,7 +132,7 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | ||
136 | public PageData<Device> findDevicesByTenantIdAndType(UUID tenantId, String type, PageLink pageLink) { | 132 | public PageData<Device> findDevicesByTenantIdAndType(UUID tenantId, String type, PageLink pageLink) { |
137 | return DaoUtil.toPageData( | 133 | return DaoUtil.toPageData( |
138 | deviceRepository.findByTenantIdAndType( | 134 | deviceRepository.findByTenantIdAndType( |
139 | - fromTimeUUID(tenantId), | 135 | + tenantId, |
140 | type, | 136 | type, |
141 | Objects.toString(pageLink.getTextSearch(), ""), | 137 | Objects.toString(pageLink.getTextSearch(), ""), |
142 | DaoUtil.toPageable(pageLink))); | 138 | DaoUtil.toPageable(pageLink))); |
@@ -146,7 +142,7 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | @@ -146,7 +142,7 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | ||
146 | public PageData<DeviceInfo> findDeviceInfosByTenantIdAndType(UUID tenantId, String type, PageLink pageLink) { | 142 | public PageData<DeviceInfo> findDeviceInfosByTenantIdAndType(UUID tenantId, String type, PageLink pageLink) { |
147 | return DaoUtil.toPageData( | 143 | return DaoUtil.toPageData( |
148 | deviceRepository.findDeviceInfosByTenantIdAndType( | 144 | deviceRepository.findDeviceInfosByTenantIdAndType( |
149 | - fromTimeUUID(tenantId), | 145 | + tenantId, |
150 | type, | 146 | type, |
151 | Objects.toString(pageLink.getTextSearch(), ""), | 147 | Objects.toString(pageLink.getTextSearch(), ""), |
152 | DaoUtil.toPageable(pageLink, DeviceInfoEntity.deviceInfoColumnMap))); | 148 | DaoUtil.toPageable(pageLink, DeviceInfoEntity.deviceInfoColumnMap))); |
@@ -156,8 +152,8 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | @@ -156,8 +152,8 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | ||
156 | public PageData<Device> findDevicesByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink) { | 152 | public PageData<Device> findDevicesByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink) { |
157 | return DaoUtil.toPageData( | 153 | return DaoUtil.toPageData( |
158 | deviceRepository.findByTenantIdAndCustomerIdAndType( | 154 | deviceRepository.findByTenantIdAndCustomerIdAndType( |
159 | - fromTimeUUID(tenantId), | ||
160 | - fromTimeUUID(customerId), | 155 | + tenantId, |
156 | + customerId, | ||
161 | type, | 157 | type, |
162 | Objects.toString(pageLink.getTextSearch(), ""), | 158 | Objects.toString(pageLink.getTextSearch(), ""), |
163 | DaoUtil.toPageable(pageLink))); | 159 | DaoUtil.toPageable(pageLink))); |
@@ -167,8 +163,8 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | @@ -167,8 +163,8 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | ||
167 | public PageData<DeviceInfo> findDeviceInfosByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink) { | 163 | public PageData<DeviceInfo> findDeviceInfosByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink) { |
168 | return DaoUtil.toPageData( | 164 | return DaoUtil.toPageData( |
169 | deviceRepository.findDeviceInfosByTenantIdAndCustomerIdAndType( | 165 | deviceRepository.findDeviceInfosByTenantIdAndCustomerIdAndType( |
170 | - fromTimeUUID(tenantId), | ||
171 | - fromTimeUUID(customerId), | 166 | + tenantId, |
167 | + customerId, | ||
172 | type, | 168 | type, |
173 | Objects.toString(pageLink.getTextSearch(), ""), | 169 | Objects.toString(pageLink.getTextSearch(), ""), |
174 | DaoUtil.toPageable(pageLink, DeviceInfoEntity.deviceInfoColumnMap))); | 170 | DaoUtil.toPageable(pageLink, DeviceInfoEntity.deviceInfoColumnMap))); |
@@ -176,7 +172,7 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | @@ -176,7 +172,7 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | ||
176 | 172 | ||
177 | @Override | 173 | @Override |
178 | public ListenableFuture<List<EntitySubtype>> findTenantDeviceTypesAsync(UUID tenantId) { | 174 | public ListenableFuture<List<EntitySubtype>> findTenantDeviceTypesAsync(UUID tenantId) { |
179 | - return service.submit(() -> convertTenantDeviceTypesToDto(tenantId, deviceRepository.findTenantDeviceTypes(fromTimeUUID(tenantId)))); | 175 | + return service.submit(() -> convertTenantDeviceTypesToDto(tenantId, deviceRepository.findTenantDeviceTypes(tenantId))); |
180 | } | 176 | } |
181 | 177 | ||
182 | private List<EntitySubtype> convertTenantDeviceTypesToDto(UUID tenantId, List<String> types) { | 178 | private List<EntitySubtype> convertTenantDeviceTypesToDto(UUID tenantId, List<String> types) { |
@@ -18,7 +18,6 @@ package org.thingsboard.server.dao.sql.entityview; | @@ -18,7 +18,6 @@ package org.thingsboard.server.dao.sql.entityview; | ||
18 | import org.springframework.data.domain.Page; | 18 | import org.springframework.data.domain.Page; |
19 | import org.springframework.data.domain.Pageable; | 19 | import org.springframework.data.domain.Pageable; |
20 | import org.springframework.data.jpa.repository.Query; | 20 | import org.springframework.data.jpa.repository.Query; |
21 | -import org.springframework.data.repository.CrudRepository; | ||
22 | import org.springframework.data.repository.PagingAndSortingRepository; | 21 | import org.springframework.data.repository.PagingAndSortingRepository; |
23 | import org.springframework.data.repository.query.Param; | 22 | import org.springframework.data.repository.query.Param; |
24 | import org.thingsboard.server.dao.model.sql.EntityViewEntity; | 23 | import org.thingsboard.server.dao.model.sql.EntityViewEntity; |
@@ -26,22 +25,23 @@ import org.thingsboard.server.dao.model.sql.EntityViewInfoEntity; | @@ -26,22 +25,23 @@ import org.thingsboard.server.dao.model.sql.EntityViewInfoEntity; | ||
26 | import org.thingsboard.server.dao.util.SqlDao; | 25 | import org.thingsboard.server.dao.util.SqlDao; |
27 | 26 | ||
28 | import java.util.List; | 27 | import java.util.List; |
28 | +import java.util.UUID; | ||
29 | 29 | ||
30 | /** | 30 | /** |
31 | * Created by Victor Basanets on 8/31/2017. | 31 | * Created by Victor Basanets on 8/31/2017. |
32 | */ | 32 | */ |
33 | @SqlDao | 33 | @SqlDao |
34 | -public interface EntityViewRepository extends PagingAndSortingRepository<EntityViewEntity, String> { | 34 | +public interface EntityViewRepository extends PagingAndSortingRepository<EntityViewEntity, UUID> { |
35 | 35 | ||
36 | @Query("SELECT new org.thingsboard.server.dao.model.sql.EntityViewInfoEntity(e, c.title, c.additionalInfo) " + | 36 | @Query("SELECT new org.thingsboard.server.dao.model.sql.EntityViewInfoEntity(e, c.title, c.additionalInfo) " + |
37 | "FROM EntityViewEntity e " + | 37 | "FROM EntityViewEntity e " + |
38 | "LEFT JOIN CustomerEntity c on c.id = e.customerId " + | 38 | "LEFT JOIN CustomerEntity c on c.id = e.customerId " + |
39 | "WHERE e.id = :entityViewId") | 39 | "WHERE e.id = :entityViewId") |
40 | - EntityViewInfoEntity findEntityViewInfoById(@Param("entityViewId") String entityViewId); | 40 | + EntityViewInfoEntity findEntityViewInfoById(@Param("entityViewId") UUID entityViewId); |
41 | 41 | ||
42 | @Query("SELECT e FROM EntityViewEntity e WHERE e.tenantId = :tenantId " + | 42 | @Query("SELECT e FROM EntityViewEntity e WHERE e.tenantId = :tenantId " + |
43 | "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") | 43 | "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
44 | - Page<EntityViewEntity> findByTenantId(@Param("tenantId") String tenantId, | 44 | + Page<EntityViewEntity> findByTenantId(@Param("tenantId") UUID tenantId, |
45 | @Param("textSearch") String textSearch, | 45 | @Param("textSearch") String textSearch, |
46 | Pageable pageable); | 46 | Pageable pageable); |
47 | 47 | ||
@@ -50,14 +50,14 @@ public interface EntityViewRepository extends PagingAndSortingRepository<EntityV | @@ -50,14 +50,14 @@ public interface EntityViewRepository extends PagingAndSortingRepository<EntityV | ||
50 | "LEFT JOIN CustomerEntity c on c.id = e.customerId " + | 50 | "LEFT JOIN CustomerEntity c on c.id = e.customerId " + |
51 | "WHERE e.tenantId = :tenantId " + | 51 | "WHERE e.tenantId = :tenantId " + |
52 | "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") | 52 | "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
53 | - Page<EntityViewInfoEntity> findEntityViewInfosByTenantId(@Param("tenantId") String tenantId, | 53 | + Page<EntityViewInfoEntity> findEntityViewInfosByTenantId(@Param("tenantId") UUID tenantId, |
54 | @Param("textSearch") String textSearch, | 54 | @Param("textSearch") String textSearch, |
55 | Pageable pageable); | 55 | Pageable pageable); |
56 | 56 | ||
57 | @Query("SELECT e FROM EntityViewEntity e WHERE e.tenantId = :tenantId " + | 57 | @Query("SELECT e FROM EntityViewEntity e WHERE e.tenantId = :tenantId " + |
58 | "AND e.type = :type " + | 58 | "AND e.type = :type " + |
59 | "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") | 59 | "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
60 | - Page<EntityViewEntity> findByTenantIdAndType(@Param("tenantId") String tenantId, | 60 | + Page<EntityViewEntity> findByTenantIdAndType(@Param("tenantId") UUID tenantId, |
61 | @Param("type") String type, | 61 | @Param("type") String type, |
62 | @Param("textSearch") String textSearch, | 62 | @Param("textSearch") String textSearch, |
63 | Pageable pageable); | 63 | Pageable pageable); |
@@ -68,7 +68,7 @@ public interface EntityViewRepository extends PagingAndSortingRepository<EntityV | @@ -68,7 +68,7 @@ public interface EntityViewRepository extends PagingAndSortingRepository<EntityV | ||
68 | "WHERE e.tenantId = :tenantId " + | 68 | "WHERE e.tenantId = :tenantId " + |
69 | "AND e.type = :type " + | 69 | "AND e.type = :type " + |
70 | "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") | 70 | "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
71 | - Page<EntityViewInfoEntity> findEntityViewInfosByTenantIdAndType(@Param("tenantId") String tenantId, | 71 | + Page<EntityViewInfoEntity> findEntityViewInfosByTenantIdAndType(@Param("tenantId") UUID tenantId, |
72 | @Param("type") String type, | 72 | @Param("type") String type, |
73 | @Param("textSearch") String textSearch, | 73 | @Param("textSearch") String textSearch, |
74 | Pageable pageable); | 74 | Pageable pageable); |
@@ -76,8 +76,8 @@ public interface EntityViewRepository extends PagingAndSortingRepository<EntityV | @@ -76,8 +76,8 @@ public interface EntityViewRepository extends PagingAndSortingRepository<EntityV | ||
76 | @Query("SELECT e FROM EntityViewEntity e WHERE e.tenantId = :tenantId " + | 76 | @Query("SELECT e FROM EntityViewEntity e WHERE e.tenantId = :tenantId " + |
77 | "AND e.customerId = :customerId " + | 77 | "AND e.customerId = :customerId " + |
78 | "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") | 78 | "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") |
79 | - Page<EntityViewEntity> findByTenantIdAndCustomerId(@Param("tenantId") String tenantId, | ||
80 | - @Param("customerId") String customerId, | 79 | + Page<EntityViewEntity> findByTenantIdAndCustomerId(@Param("tenantId") UUID tenantId, |
80 | + @Param("customerId") UUID customerId, | ||
81 | @Param("searchText") String searchText, | 81 | @Param("searchText") String searchText, |
82 | Pageable pageable); | 82 | Pageable pageable); |
83 | 83 | ||
@@ -87,8 +87,8 @@ public interface EntityViewRepository extends PagingAndSortingRepository<EntityV | @@ -87,8 +87,8 @@ public interface EntityViewRepository extends PagingAndSortingRepository<EntityV | ||
87 | "WHERE e.tenantId = :tenantId " + | 87 | "WHERE e.tenantId = :tenantId " + |
88 | "AND e.customerId = :customerId " + | 88 | "AND e.customerId = :customerId " + |
89 | "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") | 89 | "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") |
90 | - Page<EntityViewInfoEntity> findEntityViewInfosByTenantIdAndCustomerId(@Param("tenantId") String tenantId, | ||
91 | - @Param("customerId") String customerId, | 90 | + Page<EntityViewInfoEntity> findEntityViewInfosByTenantIdAndCustomerId(@Param("tenantId") UUID tenantId, |
91 | + @Param("customerId") UUID customerId, | ||
92 | @Param("searchText") String searchText, | 92 | @Param("searchText") String searchText, |
93 | Pageable pageable); | 93 | Pageable pageable); |
94 | 94 | ||
@@ -96,8 +96,8 @@ public interface EntityViewRepository extends PagingAndSortingRepository<EntityV | @@ -96,8 +96,8 @@ public interface EntityViewRepository extends PagingAndSortingRepository<EntityV | ||
96 | "AND e.customerId = :customerId " + | 96 | "AND e.customerId = :customerId " + |
97 | "AND e.type = :type " + | 97 | "AND e.type = :type " + |
98 | "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") | 98 | "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") |
99 | - Page<EntityViewEntity> findByTenantIdAndCustomerIdAndType(@Param("tenantId") String tenantId, | ||
100 | - @Param("customerId") String customerId, | 99 | + Page<EntityViewEntity> findByTenantIdAndCustomerIdAndType(@Param("tenantId") UUID tenantId, |
100 | + @Param("customerId") UUID customerId, | ||
101 | @Param("type") String type, | 101 | @Param("type") String type, |
102 | @Param("searchText") String searchText, | 102 | @Param("searchText") String searchText, |
103 | Pageable pageable); | 103 | Pageable pageable); |
@@ -109,16 +109,16 @@ public interface EntityViewRepository extends PagingAndSortingRepository<EntityV | @@ -109,16 +109,16 @@ public interface EntityViewRepository extends PagingAndSortingRepository<EntityV | ||
109 | "AND e.customerId = :customerId " + | 109 | "AND e.customerId = :customerId " + |
110 | "AND e.type = :type " + | 110 | "AND e.type = :type " + |
111 | "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") | 111 | "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
112 | - Page<EntityViewInfoEntity> findEntityViewInfosByTenantIdAndCustomerIdAndType(@Param("tenantId") String tenantId, | ||
113 | - @Param("customerId") String customerId, | 112 | + Page<EntityViewInfoEntity> findEntityViewInfosByTenantIdAndCustomerIdAndType(@Param("tenantId") UUID tenantId, |
113 | + @Param("customerId") UUID customerId, | ||
114 | @Param("type") String type, | 114 | @Param("type") String type, |
115 | @Param("textSearch") String textSearch, | 115 | @Param("textSearch") String textSearch, |
116 | Pageable pageable); | 116 | Pageable pageable); |
117 | 117 | ||
118 | - EntityViewEntity findByTenantIdAndName(String tenantId, String name); | 118 | + EntityViewEntity findByTenantIdAndName(UUID tenantId, String name); |
119 | 119 | ||
120 | - List<EntityViewEntity> findAllByTenantIdAndEntityId(String tenantId, String entityId); | 120 | + List<EntityViewEntity> findAllByTenantIdAndEntityId(UUID tenantId, UUID entityId); |
121 | 121 | ||
122 | @Query("SELECT DISTINCT ev.type FROM EntityViewEntity ev WHERE ev.tenantId = :tenantId") | 122 | @Query("SELECT DISTINCT ev.type FROM EntityViewEntity ev WHERE ev.tenantId = :tenantId") |
123 | - List<String> findTenantEntityViewTypes(@Param("tenantId") String tenantId); | 123 | + List<String> findTenantEntityViewTypes(@Param("tenantId") UUID tenantId); |
124 | } | 124 | } |
@@ -19,7 +19,10 @@ import com.google.common.util.concurrent.ListenableFuture; | @@ -19,7 +19,10 @@ import com.google.common.util.concurrent.ListenableFuture; | ||
19 | import org.springframework.beans.factory.annotation.Autowired; | 19 | import org.springframework.beans.factory.annotation.Autowired; |
20 | import org.springframework.data.repository.CrudRepository; | 20 | import org.springframework.data.repository.CrudRepository; |
21 | import org.springframework.stereotype.Component; | 21 | import org.springframework.stereotype.Component; |
22 | -import org.thingsboard.server.common.data.*; | 22 | +import org.thingsboard.server.common.data.EntitySubtype; |
23 | +import org.thingsboard.server.common.data.EntityType; | ||
24 | +import org.thingsboard.server.common.data.EntityView; | ||
25 | +import org.thingsboard.server.common.data.EntityViewInfo; | ||
23 | import org.thingsboard.server.common.data.id.TenantId; | 26 | import org.thingsboard.server.common.data.id.TenantId; |
24 | import org.thingsboard.server.common.data.page.PageData; | 27 | import org.thingsboard.server.common.data.page.PageData; |
25 | import org.thingsboard.server.common.data.page.PageLink; | 28 | import org.thingsboard.server.common.data.page.PageLink; |
@@ -37,8 +40,6 @@ import java.util.Objects; | @@ -37,8 +40,6 @@ import java.util.Objects; | ||
37 | import java.util.Optional; | 40 | import java.util.Optional; |
38 | import java.util.UUID; | 41 | import java.util.UUID; |
39 | 42 | ||
40 | -import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID; | ||
41 | - | ||
42 | /** | 43 | /** |
43 | * Created by Victor Basanets on 8/31/2017. | 44 | * Created by Victor Basanets on 8/31/2017. |
44 | */ | 45 | */ |
@@ -56,20 +57,20 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | @@ -56,20 +57,20 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | ||
56 | } | 57 | } |
57 | 58 | ||
58 | @Override | 59 | @Override |
59 | - protected CrudRepository<EntityViewEntity, String> getCrudRepository() { | 60 | + protected CrudRepository<EntityViewEntity, UUID> getCrudRepository() { |
60 | return entityViewRepository; | 61 | return entityViewRepository; |
61 | } | 62 | } |
62 | 63 | ||
63 | @Override | 64 | @Override |
64 | public EntityViewInfo findEntityViewInfoById(TenantId tenantId, UUID entityViewId) { | 65 | public EntityViewInfo findEntityViewInfoById(TenantId tenantId, UUID entityViewId) { |
65 | - return DaoUtil.getData(entityViewRepository.findEntityViewInfoById(fromTimeUUID(entityViewId))); | 66 | + return DaoUtil.getData(entityViewRepository.findEntityViewInfoById(entityViewId)); |
66 | } | 67 | } |
67 | 68 | ||
68 | @Override | 69 | @Override |
69 | public PageData<EntityView> findEntityViewsByTenantId(UUID tenantId, PageLink pageLink) { | 70 | public PageData<EntityView> findEntityViewsByTenantId(UUID tenantId, PageLink pageLink) { |
70 | return DaoUtil.toPageData( | 71 | return DaoUtil.toPageData( |
71 | entityViewRepository.findByTenantId( | 72 | entityViewRepository.findByTenantId( |
72 | - fromTimeUUID(tenantId), | 73 | + tenantId, |
73 | Objects.toString(pageLink.getTextSearch(), ""), | 74 | Objects.toString(pageLink.getTextSearch(), ""), |
74 | DaoUtil.toPageable(pageLink))); | 75 | DaoUtil.toPageable(pageLink))); |
75 | } | 76 | } |
@@ -78,7 +79,7 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | @@ -78,7 +79,7 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | ||
78 | public PageData<EntityViewInfo> findEntityViewInfosByTenantId(UUID tenantId, PageLink pageLink) { | 79 | public PageData<EntityViewInfo> findEntityViewInfosByTenantId(UUID tenantId, PageLink pageLink) { |
79 | return DaoUtil.toPageData( | 80 | return DaoUtil.toPageData( |
80 | entityViewRepository.findEntityViewInfosByTenantId( | 81 | entityViewRepository.findEntityViewInfosByTenantId( |
81 | - fromTimeUUID(tenantId), | 82 | + tenantId, |
82 | Objects.toString(pageLink.getTextSearch(), ""), | 83 | Objects.toString(pageLink.getTextSearch(), ""), |
83 | DaoUtil.toPageable(pageLink, EntityViewInfoEntity.entityViewInfoColumnMap))); | 84 | DaoUtil.toPageable(pageLink, EntityViewInfoEntity.entityViewInfoColumnMap))); |
84 | } | 85 | } |
@@ -87,7 +88,7 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | @@ -87,7 +88,7 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | ||
87 | public PageData<EntityView> findEntityViewsByTenantIdAndType(UUID tenantId, String type, PageLink pageLink) { | 88 | public PageData<EntityView> findEntityViewsByTenantIdAndType(UUID tenantId, String type, PageLink pageLink) { |
88 | return DaoUtil.toPageData( | 89 | return DaoUtil.toPageData( |
89 | entityViewRepository.findByTenantIdAndType( | 90 | entityViewRepository.findByTenantIdAndType( |
90 | - fromTimeUUID(tenantId), | 91 | + tenantId, |
91 | type, | 92 | type, |
92 | Objects.toString(pageLink.getTextSearch(), ""), | 93 | Objects.toString(pageLink.getTextSearch(), ""), |
93 | DaoUtil.toPageable(pageLink))); | 94 | DaoUtil.toPageable(pageLink))); |
@@ -97,7 +98,7 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | @@ -97,7 +98,7 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | ||
97 | public PageData<EntityViewInfo> findEntityViewInfosByTenantIdAndType(UUID tenantId, String type, PageLink pageLink) { | 98 | public PageData<EntityViewInfo> findEntityViewInfosByTenantIdAndType(UUID tenantId, String type, PageLink pageLink) { |
98 | return DaoUtil.toPageData( | 99 | return DaoUtil.toPageData( |
99 | entityViewRepository.findEntityViewInfosByTenantIdAndType( | 100 | entityViewRepository.findEntityViewInfosByTenantIdAndType( |
100 | - fromTimeUUID(tenantId), | 101 | + tenantId, |
101 | type, | 102 | type, |
102 | Objects.toString(pageLink.getTextSearch(), ""), | 103 | Objects.toString(pageLink.getTextSearch(), ""), |
103 | DaoUtil.toPageable(pageLink, EntityViewInfoEntity.entityViewInfoColumnMap))); | 104 | DaoUtil.toPageable(pageLink, EntityViewInfoEntity.entityViewInfoColumnMap))); |
@@ -106,7 +107,7 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | @@ -106,7 +107,7 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | ||
106 | @Override | 107 | @Override |
107 | public Optional<EntityView> findEntityViewByTenantIdAndName(UUID tenantId, String name) { | 108 | public Optional<EntityView> findEntityViewByTenantIdAndName(UUID tenantId, String name) { |
108 | return Optional.ofNullable( | 109 | return Optional.ofNullable( |
109 | - DaoUtil.getData(entityViewRepository.findByTenantIdAndName(fromTimeUUID(tenantId), name))); | 110 | + DaoUtil.getData(entityViewRepository.findByTenantIdAndName(tenantId, name))); |
110 | } | 111 | } |
111 | 112 | ||
112 | @Override | 113 | @Override |
@@ -115,8 +116,8 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | @@ -115,8 +116,8 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | ||
115 | PageLink pageLink) { | 116 | PageLink pageLink) { |
116 | return DaoUtil.toPageData( | 117 | return DaoUtil.toPageData( |
117 | entityViewRepository.findByTenantIdAndCustomerId( | 118 | entityViewRepository.findByTenantIdAndCustomerId( |
118 | - fromTimeUUID(tenantId), | ||
119 | - fromTimeUUID(customerId), | 119 | + tenantId, |
120 | + customerId, | ||
120 | Objects.toString(pageLink.getTextSearch(), ""), | 121 | Objects.toString(pageLink.getTextSearch(), ""), |
121 | DaoUtil.toPageable(pageLink) | 122 | DaoUtil.toPageable(pageLink) |
122 | )); | 123 | )); |
@@ -126,8 +127,8 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | @@ -126,8 +127,8 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | ||
126 | public PageData<EntityViewInfo> findEntityViewInfosByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink) { | 127 | public PageData<EntityViewInfo> findEntityViewInfosByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink) { |
127 | return DaoUtil.toPageData( | 128 | return DaoUtil.toPageData( |
128 | entityViewRepository.findEntityViewInfosByTenantIdAndCustomerId( | 129 | entityViewRepository.findEntityViewInfosByTenantIdAndCustomerId( |
129 | - fromTimeUUID(tenantId), | ||
130 | - fromTimeUUID(customerId), | 130 | + tenantId, |
131 | + customerId, | ||
131 | Objects.toString(pageLink.getTextSearch(), ""), | 132 | Objects.toString(pageLink.getTextSearch(), ""), |
132 | DaoUtil.toPageable(pageLink, EntityViewInfoEntity.entityViewInfoColumnMap))); | 133 | DaoUtil.toPageable(pageLink, EntityViewInfoEntity.entityViewInfoColumnMap))); |
133 | } | 134 | } |
@@ -136,8 +137,8 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | @@ -136,8 +137,8 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | ||
136 | public PageData<EntityView> findEntityViewsByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink) { | 137 | public PageData<EntityView> findEntityViewsByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink) { |
137 | return DaoUtil.toPageData( | 138 | return DaoUtil.toPageData( |
138 | entityViewRepository.findByTenantIdAndCustomerIdAndType( | 139 | entityViewRepository.findByTenantIdAndCustomerIdAndType( |
139 | - fromTimeUUID(tenantId), | ||
140 | - fromTimeUUID(customerId), | 140 | + tenantId, |
141 | + customerId, | ||
141 | type, | 142 | type, |
142 | Objects.toString(pageLink.getTextSearch(), ""), | 143 | Objects.toString(pageLink.getTextSearch(), ""), |
143 | DaoUtil.toPageable(pageLink) | 144 | DaoUtil.toPageable(pageLink) |
@@ -148,8 +149,8 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | @@ -148,8 +149,8 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | ||
148 | public PageData<EntityViewInfo> findEntityViewInfosByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink) { | 149 | public PageData<EntityViewInfo> findEntityViewInfosByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink) { |
149 | return DaoUtil.toPageData( | 150 | return DaoUtil.toPageData( |
150 | entityViewRepository.findEntityViewInfosByTenantIdAndCustomerIdAndType( | 151 | entityViewRepository.findEntityViewInfosByTenantIdAndCustomerIdAndType( |
151 | - fromTimeUUID(tenantId), | ||
152 | - fromTimeUUID(customerId), | 152 | + tenantId, |
153 | + customerId, | ||
153 | type, | 154 | type, |
154 | Objects.toString(pageLink.getTextSearch(), ""), | 155 | Objects.toString(pageLink.getTextSearch(), ""), |
155 | DaoUtil.toPageable(pageLink, EntityViewInfoEntity.entityViewInfoColumnMap))); | 156 | DaoUtil.toPageable(pageLink, EntityViewInfoEntity.entityViewInfoColumnMap))); |
@@ -158,12 +159,12 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | @@ -158,12 +159,12 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | ||
158 | @Override | 159 | @Override |
159 | public ListenableFuture<List<EntityView>> findEntityViewsByTenantIdAndEntityIdAsync(UUID tenantId, UUID entityId) { | 160 | public ListenableFuture<List<EntityView>> findEntityViewsByTenantIdAndEntityIdAsync(UUID tenantId, UUID entityId) { |
160 | return service.submit(() -> DaoUtil.convertDataList( | 161 | return service.submit(() -> DaoUtil.convertDataList( |
161 | - entityViewRepository.findAllByTenantIdAndEntityId(UUIDConverter.fromTimeUUID(tenantId), UUIDConverter.fromTimeUUID(entityId)))); | 162 | + entityViewRepository.findAllByTenantIdAndEntityId(tenantId, entityId))); |
162 | } | 163 | } |
163 | 164 | ||
164 | @Override | 165 | @Override |
165 | public ListenableFuture<List<EntitySubtype>> findTenantEntityViewTypesAsync(UUID tenantId) { | 166 | public ListenableFuture<List<EntitySubtype>> findTenantEntityViewTypesAsync(UUID tenantId) { |
166 | - return service.submit(() -> convertTenantEntityViewTypesToDto(tenantId, entityViewRepository.findTenantEntityViewTypes(fromTimeUUID(tenantId)))); | 167 | + return service.submit(() -> convertTenantEntityViewTypesToDto(tenantId, entityViewRepository.findTenantEntityViewTypes(tenantId))); |
167 | } | 168 | } |
168 | 169 | ||
169 | private List<EntitySubtype> convertTenantEntityViewTypesToDto(UUID tenantId, List<String> types) { | 170 | private List<EntitySubtype> convertTenantEntityViewTypesToDto(UUID tenantId, List<String> types) { |
@@ -23,7 +23,6 @@ import org.springframework.transaction.PlatformTransactionManager; | @@ -23,7 +23,6 @@ import org.springframework.transaction.PlatformTransactionManager; | ||
23 | import org.springframework.transaction.TransactionDefinition; | 23 | import org.springframework.transaction.TransactionDefinition; |
24 | import org.springframework.transaction.TransactionStatus; | 24 | import org.springframework.transaction.TransactionStatus; |
25 | import org.springframework.transaction.support.DefaultTransactionDefinition; | 25 | import org.springframework.transaction.support.DefaultTransactionDefinition; |
26 | -import org.thingsboard.server.common.data.UUIDConverter; | ||
27 | import org.thingsboard.server.dao.model.sql.EventEntity; | 26 | import org.thingsboard.server.dao.model.sql.EventEntity; |
28 | 27 | ||
29 | import javax.persistence.EntityManager; | 28 | import javax.persistence.EntityManager; |
@@ -69,7 +68,8 @@ public abstract class AbstractEventInsertRepository implements EventInsertReposi | @@ -69,7 +68,8 @@ public abstract class AbstractEventInsertRepository implements EventInsertReposi | ||
69 | 68 | ||
70 | protected Query getQuery(EventEntity entity, String query) { | 69 | protected Query getQuery(EventEntity entity, String query) { |
71 | return entityManager.createNativeQuery(query, EventEntity.class) | 70 | return entityManager.createNativeQuery(query, EventEntity.class) |
72 | - .setParameter("id", UUIDConverter.fromTimeUUID(entity.getUuid())) | 71 | + .setParameter("id", entity.getUuid()) |
72 | + .setParameter("created_time", entity.getCreatedTime()) | ||
73 | .setParameter("body", entity.getBody().toString()) | 73 | .setParameter("body", entity.getBody().toString()) |
74 | .setParameter("entity_id", entity.getEntityId()) | 74 | .setParameter("entity_id", entity.getEntityId()) |
75 | .setParameter("entity_type", entity.getEntityType().name()) | 75 | .setParameter("entity_type", entity.getEntityType().name()) |
@@ -25,60 +25,61 @@ import org.thingsboard.server.dao.model.sql.EventEntity; | @@ -25,60 +25,61 @@ import org.thingsboard.server.dao.model.sql.EventEntity; | ||
25 | import org.thingsboard.server.dao.util.SqlDao; | 25 | import org.thingsboard.server.dao.util.SqlDao; |
26 | 26 | ||
27 | import java.util.List; | 27 | import java.util.List; |
28 | +import java.util.UUID; | ||
28 | 29 | ||
29 | /** | 30 | /** |
30 | * Created by Valerii Sosliuk on 5/3/2017. | 31 | * Created by Valerii Sosliuk on 5/3/2017. |
31 | */ | 32 | */ |
32 | @SqlDao | 33 | @SqlDao |
33 | -public interface EventRepository extends PagingAndSortingRepository<EventEntity, String> { | 34 | +public interface EventRepository extends PagingAndSortingRepository<EventEntity, UUID> { |
34 | 35 | ||
35 | - EventEntity findByTenantIdAndEntityTypeAndEntityIdAndEventTypeAndEventUid(String tenantId, | 36 | + EventEntity findByTenantIdAndEntityTypeAndEntityIdAndEventTypeAndEventUid(UUID tenantId, |
36 | EntityType entityType, | 37 | EntityType entityType, |
37 | - String entityId, | 38 | + UUID entityId, |
38 | String eventType, | 39 | String eventType, |
39 | String eventUid); | 40 | String eventUid); |
40 | 41 | ||
41 | - EventEntity findByTenantIdAndEntityTypeAndEntityId(String tenantId, | 42 | + EventEntity findByTenantIdAndEntityTypeAndEntityId(UUID tenantId, |
42 | EntityType entityType, | 43 | EntityType entityType, |
43 | - String entityId); | 44 | + UUID entityId); |
44 | 45 | ||
45 | @Query("SELECT e FROM EventEntity e WHERE e.tenantId = :tenantId AND e.entityType = :entityType " + | 46 | @Query("SELECT e FROM EventEntity e WHERE e.tenantId = :tenantId AND e.entityType = :entityType " + |
46 | "AND e.entityId = :entityId AND e.eventType = :eventType ORDER BY e.eventType DESC, e.id DESC") | 47 | "AND e.entityId = :entityId AND e.eventType = :eventType ORDER BY e.eventType DESC, e.id DESC") |
47 | List<EventEntity> findLatestByTenantIdAndEntityTypeAndEntityIdAndEventType( | 48 | List<EventEntity> findLatestByTenantIdAndEntityTypeAndEntityIdAndEventType( |
48 | - @Param("tenantId") String tenantId, | 49 | + @Param("tenantId") UUID tenantId, |
49 | @Param("entityType") EntityType entityType, | 50 | @Param("entityType") EntityType entityType, |
50 | - @Param("entityId") String entityId, | 51 | + @Param("entityId") UUID entityId, |
51 | @Param("eventType") String eventType, | 52 | @Param("eventType") String eventType, |
52 | Pageable pageable); | 53 | Pageable pageable); |
53 | 54 | ||
54 | @Query("SELECT e FROM EventEntity e WHERE " + | 55 | @Query("SELECT e FROM EventEntity e WHERE " + |
55 | "e.tenantId = :tenantId " + | 56 | "e.tenantId = :tenantId " + |
56 | "AND e.entityType = :entityType AND e.entityId = :entityId " + | 57 | "AND e.entityType = :entityType AND e.entityId = :entityId " + |
57 | - "AND (:startId IS NULL OR e.id >= :startId) " + | ||
58 | - "AND (:endId IS NULL OR e.id <= :endId) " + | 58 | + "AND (:startTime IS NULL OR e.createdTime >= :startTime) " + |
59 | + "AND (:endTime IS NULL OR e.createdTime <= :endTime) " + | ||
59 | "AND LOWER(e.eventType) LIKE LOWER(CONCAT(:textSearch, '%'))" | 60 | "AND LOWER(e.eventType) LIKE LOWER(CONCAT(:textSearch, '%'))" |
60 | ) | 61 | ) |
61 | - Page<EventEntity> findEventsByTenantIdAndEntityId(@Param("tenantId") String tenantId, | 62 | + Page<EventEntity> findEventsByTenantIdAndEntityId(@Param("tenantId") UUID tenantId, |
62 | @Param("entityType") EntityType entityType, | 63 | @Param("entityType") EntityType entityType, |
63 | - @Param("entityId") String entityId, | 64 | + @Param("entityId") UUID entityId, |
64 | @Param("textSearch") String textSearch, | 65 | @Param("textSearch") String textSearch, |
65 | - @Param("startId") String startId, | ||
66 | - @Param("endId") String endId, | 66 | + @Param("startTime") Long startTime, |
67 | + @Param("endTime") Long endTime, | ||
67 | Pageable pageable); | 68 | Pageable pageable); |
68 | 69 | ||
69 | @Query("SELECT e FROM EventEntity e WHERE " + | 70 | @Query("SELECT e FROM EventEntity e WHERE " + |
70 | "e.tenantId = :tenantId " + | 71 | "e.tenantId = :tenantId " + |
71 | "AND e.entityType = :entityType AND e.entityId = :entityId " + | 72 | "AND e.entityType = :entityType AND e.entityId = :entityId " + |
72 | "AND e.eventType = :eventType " + | 73 | "AND e.eventType = :eventType " + |
73 | - "AND (:startId IS NULL OR e.id >= :startId) " + | ||
74 | - "AND (:endId IS NULL OR e.id <= :endId)" | 74 | + "AND (:startTime IS NULL OR e.createdTime >= :startTime) " + |
75 | + "AND (:endTime IS NULL OR e.createdTime <= :endTime)" | ||
75 | ) | 76 | ) |
76 | - Page<EventEntity> findEventsByTenantIdAndEntityIdAndEventType(@Param("tenantId") String tenantId, | 77 | + Page<EventEntity> findEventsByTenantIdAndEntityIdAndEventType(@Param("tenantId") UUID tenantId, |
77 | @Param("entityType") EntityType entityType, | 78 | @Param("entityType") EntityType entityType, |
78 | - @Param("entityId") String entityId, | 79 | + @Param("entityId") UUID entityId, |
79 | @Param("eventType") String eventType, | 80 | @Param("eventType") String eventType, |
80 | - @Param("startId") String startId, | ||
81 | - @Param("endId") String endId, | 81 | + @Param("startTime") Long startTime, |
82 | + @Param("endTime") Long endTime, | ||
82 | Pageable pageable); | 83 | Pageable pageable); |
83 | 84 | ||
84 | } | 85 | } |
@@ -16,11 +16,12 @@ | @@ -16,11 +16,12 @@ | ||
16 | package org.thingsboard.server.dao.sql.event; | 16 | package org.thingsboard.server.dao.sql.event; |
17 | 17 | ||
18 | import org.springframework.stereotype.Repository; | 18 | import org.springframework.stereotype.Repository; |
19 | -import org.thingsboard.server.common.data.UUIDConverter; | ||
20 | import org.thingsboard.server.dao.model.sql.EventEntity; | 19 | import org.thingsboard.server.dao.model.sql.EventEntity; |
21 | import org.thingsboard.server.dao.util.HsqlDao; | 20 | import org.thingsboard.server.dao.util.HsqlDao; |
22 | import org.thingsboard.server.dao.util.SqlDao; | 21 | import org.thingsboard.server.dao.util.SqlDao; |
23 | 22 | ||
23 | +import javax.persistence.Query; | ||
24 | + | ||
24 | @SqlDao | 25 | @SqlDao |
25 | @HsqlDao | 26 | @HsqlDao |
26 | @Repository | 27 | @Repository |
@@ -40,11 +41,25 @@ public class HsqlEventInsertRepository extends AbstractEventInsertRepository { | @@ -40,11 +41,25 @@ public class HsqlEventInsertRepository extends AbstractEventInsertRepository { | ||
40 | @Override | 41 | @Override |
41 | protected EventEntity doProcessSaveOrUpdate(EventEntity entity, String query) { | 42 | protected EventEntity doProcessSaveOrUpdate(EventEntity entity, String query) { |
42 | getQuery(entity, query).executeUpdate(); | 43 | getQuery(entity, query).executeUpdate(); |
43 | - return entityManager.find(EventEntity.class, UUIDConverter.fromTimeUUID(entity.getUuid())); | 44 | + return entityManager.find(EventEntity.class, entity.getUuid()); |
45 | + } | ||
46 | + | ||
47 | + protected Query getQuery(EventEntity entity, String query) { | ||
48 | + return entityManager.createNativeQuery(query, EventEntity.class) | ||
49 | + .setParameter("id", entity.getUuid().toString()) | ||
50 | + .setParameter("created_time", entity.getCreatedTime()) | ||
51 | + .setParameter("body", entity.getBody().toString()) | ||
52 | + .setParameter("entity_id", entity.getEntityId().toString()) | ||
53 | + .setParameter("entity_type", entity.getEntityType().name()) | ||
54 | + .setParameter("event_type", entity.getEventType()) | ||
55 | + .setParameter("event_uid", entity.getEventUid()) | ||
56 | + .setParameter("tenant_id", entity.getTenantId().toString()) | ||
57 | + .setParameter("ts", entity.getTs()); | ||
44 | } | 58 | } |
45 | 59 | ||
46 | private static String getInsertString(String conflictStatement) { | 60 | private static String getInsertString(String conflictStatement) { |
47 | - return "MERGE INTO event USING (VALUES :id, :body, :entity_id, :entity_type, :event_type, :event_uid, :tenant_id, :ts) I (id, body, entity_id, entity_type, event_type, event_uid, tenant_id, ts) ON " + conflictStatement + " WHEN MATCHED THEN UPDATE SET event.id = I.id, event.body = I.body, event.entity_id = I.entity_id, event.entity_type = I.entity_type, event.event_type = I.event_type, event.event_uid = I.event_uid, event.tenant_id = I.tenant_id, event.ts = I.ts" + | ||
48 | - " WHEN NOT MATCHED THEN INSERT (id, body, entity_id, entity_type, event_type, event_uid, tenant_id, ts) VALUES (I.id, I.body, I.entity_id, I.entity_type, I.event_type, I.event_uid, I.tenant_id, I.ts)"; | 61 | + return "MERGE INTO event USING (VALUES UUID(:id), :created_time, :body, UUID(:entity_id), :entity_type, :event_type, :event_uid, UUID(:tenant_id), :ts) I (id, created_time, body, entity_id, entity_type, event_type, event_uid, tenant_id, ts) ON " + conflictStatement |
62 | + + " WHEN MATCHED THEN UPDATE SET event.id = I.id, event.created_time = I.created_time, event.body = I.body, event.entity_id = I.entity_id, event.entity_type = I.entity_type, event.event_type = I.event_type, event.event_uid = I.event_uid, event.tenant_id = I.tenant_id, event.ts = I.ts" + | ||
63 | + " WHEN NOT MATCHED THEN INSERT (id, created_time, body, entity_id, entity_type, event_type, event_uid, tenant_id, ts) VALUES (I.id, I.created_time, I.body, I.entity_id, I.entity_type, I.event_type, I.event_uid, I.tenant_id, I.ts)"; | ||
49 | } | 64 | } |
50 | } | 65 | } |
@@ -38,9 +38,12 @@ import org.thingsboard.server.dao.sql.JpaAbstractSearchTimeDao; | @@ -38,9 +38,12 @@ import org.thingsboard.server.dao.sql.JpaAbstractSearchTimeDao; | ||
38 | import org.thingsboard.server.dao.util.SqlDao; | 38 | import org.thingsboard.server.dao.util.SqlDao; |
39 | 39 | ||
40 | import javax.persistence.criteria.Predicate; | 40 | import javax.persistence.criteria.Predicate; |
41 | -import java.util.*; | 41 | +import java.util.ArrayList; |
42 | +import java.util.List; | ||
43 | +import java.util.Objects; | ||
44 | +import java.util.Optional; | ||
45 | +import java.util.UUID; | ||
42 | 46 | ||
43 | -import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID; | ||
44 | import static org.thingsboard.server.dao.DaoUtil.endTimeToId; | 47 | import static org.thingsboard.server.dao.DaoUtil.endTimeToId; |
45 | import static org.thingsboard.server.dao.DaoUtil.startTimeToId; | 48 | import static org.thingsboard.server.dao.DaoUtil.startTimeToId; |
46 | import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; | 49 | import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; |
@@ -67,7 +70,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | @@ -67,7 +70,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | ||
67 | } | 70 | } |
68 | 71 | ||
69 | @Override | 72 | @Override |
70 | - protected CrudRepository<EventEntity, String> getCrudRepository() { | 73 | + protected CrudRepository<EventEntity, UUID> getCrudRepository() { |
71 | return eventRepository; | 74 | return eventRepository; |
72 | } | 75 | } |
73 | 76 | ||
@@ -75,7 +78,16 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | @@ -75,7 +78,16 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | ||
75 | public Event save(TenantId tenantId, Event event) { | 78 | public Event save(TenantId tenantId, Event event) { |
76 | log.debug("Save event [{}] ", event); | 79 | log.debug("Save event [{}] ", event); |
77 | if (event.getId() == null) { | 80 | if (event.getId() == null) { |
78 | - event.setId(new EventId(Uuids.timeBased())); | 81 | + UUID timeBased = Uuids.timeBased(); |
82 | + event.setId(new EventId(timeBased)); | ||
83 | + event.setCreatedTime(Uuids.unixTimestamp(timeBased)); | ||
84 | + } else if (event.getCreatedTime() == 0L) { | ||
85 | + UUID eventId = event.getId().getId(); | ||
86 | + if (eventId.version() == 1) { | ||
87 | + event.setCreatedTime(Uuids.unixTimestamp(eventId)); | ||
88 | + } else { | ||
89 | + event.setCreatedTime(System.currentTimeMillis()); | ||
90 | + } | ||
79 | } | 91 | } |
80 | if (StringUtils.isEmpty(event.getUid())) { | 92 | if (StringUtils.isEmpty(event.getUid())) { |
81 | event.setUid(event.getId().toString()); | 93 | event.setUid(event.getId().toString()); |
@@ -87,7 +99,16 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | @@ -87,7 +99,16 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | ||
87 | public ListenableFuture<Event> saveAsync(Event event) { | 99 | public ListenableFuture<Event> saveAsync(Event event) { |
88 | log.debug("Save event [{}] ", event); | 100 | log.debug("Save event [{}] ", event); |
89 | if (event.getId() == null) { | 101 | if (event.getId() == null) { |
90 | - event.setId(new EventId(Uuids.timeBased())); | 102 | + UUID timeBased = Uuids.timeBased(); |
103 | + event.setId(new EventId(timeBased)); | ||
104 | + event.setCreatedTime(Uuids.unixTimestamp(timeBased)); | ||
105 | + } else if (event.getCreatedTime() == 0L) { | ||
106 | + UUID eventId = event.getId().getId(); | ||
107 | + if (eventId.version() == 1) { | ||
108 | + event.setCreatedTime(Uuids.unixTimestamp(eventId)); | ||
109 | + } else { | ||
110 | + event.setCreatedTime(System.currentTimeMillis()); | ||
111 | + } | ||
91 | } | 112 | } |
92 | if (StringUtils.isEmpty(event.getUid())) { | 113 | if (StringUtils.isEmpty(event.getUid())) { |
93 | event.setUid(event.getId().toString()); | 114 | event.setUid(event.getId().toString()); |
@@ -103,7 +124,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | @@ -103,7 +124,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | ||
103 | @Override | 124 | @Override |
104 | public Event findEvent(UUID tenantId, EntityId entityId, String eventType, String eventUid) { | 125 | public Event findEvent(UUID tenantId, EntityId entityId, String eventType, String eventUid) { |
105 | return DaoUtil.getData(eventRepository.findByTenantIdAndEntityTypeAndEntityIdAndEventTypeAndEventUid( | 126 | return DaoUtil.getData(eventRepository.findByTenantIdAndEntityTypeAndEntityIdAndEventTypeAndEventUid( |
106 | - UUIDConverter.fromTimeUUID(tenantId), entityId.getEntityType(), UUIDConverter.fromTimeUUID(entityId.getId()), eventType, eventUid)); | 127 | + tenantId, entityId.getEntityType(), entityId.getId(), eventType, eventUid)); |
107 | } | 128 | } |
108 | 129 | ||
109 | @Override | 130 | @Override |
@@ -111,12 +132,12 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | @@ -111,12 +132,12 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | ||
111 | return DaoUtil.toPageData( | 132 | return DaoUtil.toPageData( |
112 | eventRepository | 133 | eventRepository |
113 | .findEventsByTenantIdAndEntityId( | 134 | .findEventsByTenantIdAndEntityId( |
114 | - fromTimeUUID(tenantId), | 135 | + tenantId, |
115 | entityId.getEntityType(), | 136 | entityId.getEntityType(), |
116 | - fromTimeUUID(entityId.getId()), | 137 | + entityId.getId(), |
117 | Objects.toString(pageLink.getTextSearch(), ""), | 138 | Objects.toString(pageLink.getTextSearch(), ""), |
118 | - startTimeToId(pageLink.getStartTime()), | ||
119 | - endTimeToId(pageLink.getEndTime()), | 139 | + pageLink.getStartTime(), |
140 | + pageLink.getEndTime(), | ||
120 | DaoUtil.toPageable(pageLink))); | 141 | DaoUtil.toPageable(pageLink))); |
121 | } | 142 | } |
122 | 143 | ||
@@ -125,21 +146,21 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | @@ -125,21 +146,21 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | ||
125 | return DaoUtil.toPageData( | 146 | return DaoUtil.toPageData( |
126 | eventRepository | 147 | eventRepository |
127 | .findEventsByTenantIdAndEntityIdAndEventType( | 148 | .findEventsByTenantIdAndEntityIdAndEventType( |
128 | - fromTimeUUID(tenantId), | 149 | + tenantId, |
129 | entityId.getEntityType(), | 150 | entityId.getEntityType(), |
130 | - fromTimeUUID(entityId.getId()), | 151 | + entityId.getId(), |
131 | eventType, | 152 | eventType, |
132 | - startTimeToId(pageLink.getStartTime()), | ||
133 | - endTimeToId(pageLink.getEndTime()), | 153 | + pageLink.getStartTime(), |
154 | + pageLink.getEndTime(), | ||
134 | DaoUtil.toPageable(pageLink))); | 155 | DaoUtil.toPageable(pageLink))); |
135 | } | 156 | } |
136 | 157 | ||
137 | @Override | 158 | @Override |
138 | public List<Event> findLatestEvents(UUID tenantId, EntityId entityId, String eventType, int limit) { | 159 | public List<Event> findLatestEvents(UUID tenantId, EntityId entityId, String eventType, int limit) { |
139 | List<EventEntity> latest = eventRepository.findLatestByTenantIdAndEntityTypeAndEntityIdAndEventType( | 160 | List<EventEntity> latest = eventRepository.findLatestByTenantIdAndEntityTypeAndEntityIdAndEventType( |
140 | - UUIDConverter.fromTimeUUID(tenantId), | 161 | + tenantId, |
141 | entityId.getEntityType(), | 162 | entityId.getEntityType(), |
142 | - UUIDConverter.fromTimeUUID(entityId.getId()), | 163 | + entityId.getId(), |
143 | eventType, | 164 | eventType, |
144 | PageRequest.of(0, limit)); | 165 | PageRequest.of(0, limit)); |
145 | return DaoUtil.convertDataList(latest); | 166 | return DaoUtil.convertDataList(latest); |
@@ -149,7 +170,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | @@ -149,7 +170,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | ||
149 | log.debug("Save event [{}] ", entity); | 170 | log.debug("Save event [{}] ", entity); |
150 | if (entity.getTenantId() == null) { | 171 | if (entity.getTenantId() == null) { |
151 | log.trace("Save system event with predefined id {}", systemTenantId); | 172 | log.trace("Save system event with predefined id {}", systemTenantId); |
152 | - entity.setTenantId(UUIDConverter.fromTimeUUID(systemTenantId)); | 173 | + entity.setTenantId(systemTenantId); |
153 | } | 174 | } |
154 | if (entity.getUuid() == null) { | 175 | if (entity.getUuid() == null) { |
155 | entity.setUuid(Uuids.timeBased()); | 176 | entity.setUuid(Uuids.timeBased()); |
@@ -168,13 +189,13 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | @@ -168,13 +189,13 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | ||
168 | return (root, criteriaQuery, criteriaBuilder) -> { | 189 | return (root, criteriaQuery, criteriaBuilder) -> { |
169 | List<Predicate> predicates = new ArrayList<>(); | 190 | List<Predicate> predicates = new ArrayList<>(); |
170 | if (tenantId != null) { | 191 | if (tenantId != null) { |
171 | - Predicate tenantIdPredicate = criteriaBuilder.equal(root.get("tenantId"), UUIDConverter.fromTimeUUID(tenantId)); | 192 | + Predicate tenantIdPredicate = criteriaBuilder.equal(root.get("tenantId"), tenantId); |
172 | predicates.add(tenantIdPredicate); | 193 | predicates.add(tenantIdPredicate); |
173 | } | 194 | } |
174 | if (entityId != null) { | 195 | if (entityId != null) { |
175 | Predicate entityTypePredicate = criteriaBuilder.equal(root.get("entityType"), entityId.getEntityType()); | 196 | Predicate entityTypePredicate = criteriaBuilder.equal(root.get("entityType"), entityId.getEntityType()); |
176 | predicates.add(entityTypePredicate); | 197 | predicates.add(entityTypePredicate); |
177 | - Predicate entityIdPredicate = criteriaBuilder.equal(root.get("entityId"), UUIDConverter.fromTimeUUID(entityId.getId())); | 198 | + Predicate entityIdPredicate = criteriaBuilder.equal(root.get("entityId"), entityId.getId()); |
178 | predicates.add(entityIdPredicate); | 199 | predicates.add(entityIdPredicate); |
179 | } | 200 | } |
180 | if (eventType != null) { | 201 | if (eventType != null) { |
@@ -28,10 +28,10 @@ import org.thingsboard.server.dao.util.SqlDao; | @@ -28,10 +28,10 @@ import org.thingsboard.server.dao.util.SqlDao; | ||
28 | public class PsqlEventInsertRepository extends AbstractEventInsertRepository { | 28 | public class PsqlEventInsertRepository extends AbstractEventInsertRepository { |
29 | 29 | ||
30 | private static final String P_KEY_CONFLICT_STATEMENT = "(id)"; | 30 | private static final String P_KEY_CONFLICT_STATEMENT = "(id)"; |
31 | - private static final String UNQ_KEY_CONFLICT_STATEMENT = "(tenant_id, entity_type, entity_id, event_type, event_uid)"; | 31 | + private static final String UNQ_KEY_CONFLICT_STATEMENT = "(tenant_id, created_time, entity_type, entity_id, event_type, event_uid)"; |
32 | 32 | ||
33 | private static final String UPDATE_P_KEY_STATEMENT = "id = :id"; | 33 | private static final String UPDATE_P_KEY_STATEMENT = "id = :id"; |
34 | - private static final String UPDATE_UNQ_KEY_STATEMENT = "tenant_id = :tenant_id, entity_type = :entity_type, entity_id = :entity_id, event_type = :event_type, event_uid = :event_uid"; | 34 | + private static final String UPDATE_UNQ_KEY_STATEMENT = "created_time = :created_time, tenant_id = :tenant_id, entity_type = :entity_type, entity_id = :entity_id, event_type = :event_type, event_uid = :event_uid"; |
35 | 35 | ||
36 | private static final String INSERT_OR_UPDATE_ON_P_KEY_CONFLICT = getInsertOrUpdateString(P_KEY_CONFLICT_STATEMENT, UPDATE_UNQ_KEY_STATEMENT); | 36 | private static final String INSERT_OR_UPDATE_ON_P_KEY_CONFLICT = getInsertOrUpdateString(P_KEY_CONFLICT_STATEMENT, UPDATE_UNQ_KEY_STATEMENT); |
37 | private static final String INSERT_OR_UPDATE_ON_UNQ_KEY_CONFLICT = getInsertOrUpdateString(UNQ_KEY_CONFLICT_STATEMENT, UPDATE_P_KEY_STATEMENT); | 37 | private static final String INSERT_OR_UPDATE_ON_UNQ_KEY_CONFLICT = getInsertOrUpdateString(UNQ_KEY_CONFLICT_STATEMENT, UPDATE_P_KEY_STATEMENT); |
@@ -48,6 +48,8 @@ public class PsqlEventInsertRepository extends AbstractEventInsertRepository { | @@ -48,6 +48,8 @@ public class PsqlEventInsertRepository extends AbstractEventInsertRepository { | ||
48 | } | 48 | } |
49 | 49 | ||
50 | private static String getInsertOrUpdateString(String eventKeyStatement, String updateKeyStatement) { | 50 | private static String getInsertOrUpdateString(String eventKeyStatement, String updateKeyStatement) { |
51 | - return "INSERT INTO event (id, body, entity_id, entity_type, event_type, event_uid, tenant_id, ts) VALUES (:id, :body, :entity_id, :entity_type, :event_type, :event_uid, :tenant_id, :ts) ON CONFLICT " + eventKeyStatement + " DO UPDATE SET body = :body, ts = :ts," + updateKeyStatement + " returning *"; | 51 | + return "INSERT INTO event (id, created_time, body, entity_id, entity_type, event_type, event_uid, tenant_id, ts) " + |
52 | + "VALUES (:id, :created_time, :body, :entity_id, :entity_type, :event_type, :event_uid, :tenant_id, :ts) " + | ||
53 | + "ON CONFLICT " + eventKeyStatement + " DO UPDATE SET body = :body, ts = :ts," + updateKeyStatement + " returning *"; | ||
52 | } | 54 | } |
53 | } | 55 | } |
@@ -17,10 +17,10 @@ package org.thingsboard.server.dao.sql.query; | @@ -17,10 +17,10 @@ package org.thingsboard.server.dao.sql.query; | ||
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.apache.commons.lang3.StringUtils; | 19 | import org.apache.commons.lang3.StringUtils; |
20 | +import org.springframework.beans.factory.annotation.Autowired; | ||
21 | +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; | ||
20 | import org.springframework.stereotype.Repository; | 22 | import org.springframework.stereotype.Repository; |
21 | import org.thingsboard.server.common.data.EntityType; | 23 | import org.thingsboard.server.common.data.EntityType; |
22 | -import org.thingsboard.server.common.data.UUIDConverter; | ||
23 | -import org.thingsboard.server.common.data.asset.Asset; | ||
24 | import org.thingsboard.server.common.data.id.CustomerId; | 24 | import org.thingsboard.server.common.data.id.CustomerId; |
25 | import org.thingsboard.server.common.data.id.EntityId; | 25 | import org.thingsboard.server.common.data.id.EntityId; |
26 | import org.thingsboard.server.common.data.id.TenantId; | 26 | import org.thingsboard.server.common.data.id.TenantId; |
@@ -46,8 +46,6 @@ import org.thingsboard.server.common.data.relation.EntitySearchDirection; | @@ -46,8 +46,6 @@ import org.thingsboard.server.common.data.relation.EntitySearchDirection; | ||
46 | import org.thingsboard.server.common.data.relation.EntityTypeFilter; | 46 | import org.thingsboard.server.common.data.relation.EntityTypeFilter; |
47 | import org.thingsboard.server.dao.util.SqlDao; | 47 | import org.thingsboard.server.dao.util.SqlDao; |
48 | 48 | ||
49 | -import javax.persistence.EntityManager; | ||
50 | -import javax.persistence.PersistenceContext; | ||
51 | import java.math.BigInteger; | 49 | import java.math.BigInteger; |
52 | import java.util.Collections; | 50 | import java.util.Collections; |
53 | import java.util.HashMap; | 51 | import java.util.HashMap; |
@@ -77,7 +75,7 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | @@ -77,7 +75,7 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | ||
77 | public static final String HIERARCHICAL_QUERY_TEMPLATE = " FROM (WITH RECURSIVE related_entities(from_id, from_type, to_id, to_type, relation_type, lvl) AS (" + | 75 | public static final String HIERARCHICAL_QUERY_TEMPLATE = " FROM (WITH RECURSIVE related_entities(from_id, from_type, to_id, to_type, relation_type, lvl) AS (" + |
78 | " SELECT from_id, from_type, to_id, to_type, relation_type, 1 as lvl" + | 76 | " SELECT from_id, from_type, to_id, to_type, relation_type, 1 as lvl" + |
79 | " FROM relation" + | 77 | " FROM relation" + |
80 | - " WHERE $in_id = '%s' and $in_type = '%s' and relation_type_group = 'COMMON'" + | 78 | + " WHERE $in_id = :relation_root_id and $in_type = :relation_root_type and relation_type_group = 'COMMON'" + |
81 | " UNION ALL" + | 79 | " UNION ALL" + |
82 | " SELECT r.from_id, r.from_type, r.to_id, r.to_type, r.relation_type, lvl + 1" + | 80 | " SELECT r.from_id, r.from_type, r.to_id, r.to_type, r.relation_type, lvl + 1" + |
83 | " FROM relation r" + | 81 | " FROM relation r" + |
@@ -90,21 +88,23 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | @@ -90,21 +88,23 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | ||
90 | public static final String HIERARCHICAL_TO_QUERY_TEMPLATE = HIERARCHICAL_QUERY_TEMPLATE.replace("$in", "to").replace("$out", "from"); | 88 | public static final String HIERARCHICAL_TO_QUERY_TEMPLATE = HIERARCHICAL_QUERY_TEMPLATE.replace("$in", "to").replace("$out", "from"); |
91 | public static final String HIERARCHICAL_FROM_QUERY_TEMPLATE = HIERARCHICAL_QUERY_TEMPLATE.replace("$in", "from").replace("$out", "to"); | 89 | public static final String HIERARCHICAL_FROM_QUERY_TEMPLATE = HIERARCHICAL_QUERY_TEMPLATE.replace("$in", "from").replace("$out", "to"); |
92 | 90 | ||
93 | - @PersistenceContext | ||
94 | - private EntityManager entityManager; | 91 | + @Autowired |
92 | + protected NamedParameterJdbcTemplate jdbcTemplate; | ||
95 | 93 | ||
96 | @Override | 94 | @Override |
97 | public long countEntitiesByQuery(TenantId tenantId, CustomerId customerId, EntityCountQuery query) { | 95 | public long countEntitiesByQuery(TenantId tenantId, CustomerId customerId, EntityCountQuery query) { |
98 | EntityType entityType = resolveEntityType(query.getEntityFilter()); | 96 | EntityType entityType = resolveEntityType(query.getEntityFilter()); |
99 | - String countQuery = String.format("select count(e.id) from %s e where %s", | ||
100 | - getEntityTableQuery(query.getEntityFilter(), entityType), this.buildEntityWhere(tenantId, customerId, query.getEntityFilter(), | ||
101 | - Collections.emptyList(), entityType)); | ||
102 | - return ((BigInteger) entityManager.createNativeQuery(countQuery) | ||
103 | - .getSingleResult()).longValue(); | 97 | + EntityQueryContext ctx = new EntityQueryContext(); |
98 | + ctx.append("select count(e.id) from "); | ||
99 | + ctx.append(addEntityTableQuery(ctx, query.getEntityFilter(), entityType)); | ||
100 | + ctx.append(" e where "); | ||
101 | + ctx.append(buildEntityWhere(ctx, tenantId, customerId, query.getEntityFilter(), Collections.emptyList(), entityType)); | ||
102 | + return jdbcTemplate.queryForObject(ctx.getQuery(), ctx, Long.class); | ||
104 | } | 103 | } |
105 | 104 | ||
106 | @Override | 105 | @Override |
107 | public PageData<EntityData> findEntityDataByQuery(TenantId tenantId, CustomerId customerId, EntityDataQuery query) { | 106 | public PageData<EntityData> findEntityDataByQuery(TenantId tenantId, CustomerId customerId, EntityDataQuery query) { |
107 | + EntityQueryContext ctx = new EntityQueryContext(); | ||
108 | EntityType entityType = resolveEntityType(query.getEntityFilter()); | 108 | EntityType entityType = resolveEntityType(query.getEntityFilter()); |
109 | EntityDataPageLink pageLink = query.getPageLink(); | 109 | EntityDataPageLink pageLink = query.getPageLink(); |
110 | 110 | ||
@@ -128,9 +128,9 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | @@ -128,9 +128,9 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | ||
128 | .collect(Collectors.toList()); | 128 | .collect(Collectors.toList()); |
129 | 129 | ||
130 | 130 | ||
131 | - String entityWhereClause = this.buildEntityWhere(tenantId, customerId, query.getEntityFilter(), entityFieldsFiltersMapping, entityType); | ||
132 | - String latestJoins = EntityKeyMapping.buildLatestJoins(query.getEntityFilter(), entityType, allLatestMappings); | ||
133 | - String whereClause = this.buildWhere(selectionMapping, latestFiltersMapping, pageLink.getTextSearch()); | 131 | + String entityWhereClause = this.buildEntityWhere(ctx, tenantId, customerId, query.getEntityFilter(), entityFieldsFiltersMapping, entityType); |
132 | + String latestJoins = EntityKeyMapping.buildLatestJoins(ctx, query.getEntityFilter(), entityType, allLatestMappings); | ||
133 | + String whereClause = this.buildWhere(ctx, selectionMapping, latestFiltersMapping, pageLink.getTextSearch()); | ||
134 | String entityFieldsSelection = EntityKeyMapping.buildSelections(entityFieldsSelectionMapping); | 134 | String entityFieldsSelection = EntityKeyMapping.buildSelections(entityFieldsSelectionMapping); |
135 | String entityTypeStr; | 135 | String entityTypeStr; |
136 | if (query.getEntityFilter().getType().equals(EntityFilterType.RELATIONS_QUERY)) { | 136 | if (query.getEntityFilter().getType().equals(EntityFilterType.RELATIONS_QUERY)) { |
@@ -139,9 +139,9 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | @@ -139,9 +139,9 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | ||
139 | entityTypeStr = "'" + entityType.name() + "'"; | 139 | entityTypeStr = "'" + entityType.name() + "'"; |
140 | } | 140 | } |
141 | if (!StringUtils.isEmpty(entityFieldsSelection)) { | 141 | if (!StringUtils.isEmpty(entityFieldsSelection)) { |
142 | - entityFieldsSelection = String.format("e.id, %s, %s", entityTypeStr, entityFieldsSelection); | 142 | + entityFieldsSelection = String.format("e.id id, %s entity_type, %s", entityTypeStr, entityFieldsSelection); |
143 | } else { | 143 | } else { |
144 | - entityFieldsSelection = String.format("e.id, %s", entityTypeStr); | 144 | + entityFieldsSelection = String.format("e.id id, %s entity_type", entityTypeStr); |
145 | } | 145 | } |
146 | String latestSelection = EntityKeyMapping.buildSelections(latestSelectionMapping); | 146 | String latestSelection = EntityKeyMapping.buildSelections(latestSelectionMapping); |
147 | String topSelection = "entities.*"; | 147 | String topSelection = "entities.*"; |
@@ -152,13 +152,13 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | @@ -152,13 +152,13 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | ||
152 | String fromClause = String.format("from (select %s from (select %s from %s e where %s) entities %s %s) result", | 152 | String fromClause = String.format("from (select %s from (select %s from %s e where %s) entities %s %s) result", |
153 | topSelection, | 153 | topSelection, |
154 | entityFieldsSelection, | 154 | entityFieldsSelection, |
155 | - getEntityTableQuery(query.getEntityFilter(), entityType), | 155 | + addEntityTableQuery(ctx, query.getEntityFilter(), entityType), |
156 | entityWhereClause, | 156 | entityWhereClause, |
157 | latestJoins, | 157 | latestJoins, |
158 | whereClause); | 158 | whereClause); |
159 | 159 | ||
160 | - int totalElements = ((BigInteger) entityManager.createNativeQuery(String.format("select count(*) %s", fromClause)) | ||
161 | - .getSingleResult()).intValue(); | 160 | + |
161 | + int totalElements = jdbcTemplate.queryForObject(String.format("select count(*) %s", fromClause), ctx, Integer.class); | ||
162 | 162 | ||
163 | String dataQuery = String.format("select * %s", fromClause); | 163 | String dataQuery = String.format("select * %s", fromClause); |
164 | 164 | ||
@@ -179,17 +179,18 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | @@ -179,17 +179,18 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | ||
179 | if (pageLink.getPageSize() > 0) { | 179 | if (pageLink.getPageSize() > 0) { |
180 | dataQuery = String.format("%s limit %s offset %s", dataQuery, pageLink.getPageSize(), startIndex); | 180 | dataQuery = String.format("%s limit %s offset %s", dataQuery, pageLink.getPageSize(), startIndex); |
181 | } | 181 | } |
182 | - List rows = entityManager.createNativeQuery(dataQuery).getResultList(); | 182 | + List<Map<String, Object>> rows = jdbcTemplate.queryForList(dataQuery, ctx); |
183 | return EntityDataAdapter.createEntityData(pageLink, selectionMapping, rows, totalElements); | 183 | return EntityDataAdapter.createEntityData(pageLink, selectionMapping, rows, totalElements); |
184 | } | 184 | } |
185 | 185 | ||
186 | - private String buildEntityWhere(TenantId tenantId, | 186 | + private String buildEntityWhere(EntityQueryContext ctx, |
187 | + TenantId tenantId, | ||
187 | CustomerId customerId, | 188 | CustomerId customerId, |
188 | EntityFilter entityFilter, | 189 | EntityFilter entityFilter, |
189 | List<EntityKeyMapping> entityFieldsFilters, | 190 | List<EntityKeyMapping> entityFieldsFilters, |
190 | EntityType entityType) { | 191 | EntityType entityType) { |
191 | - String permissionQuery = this.buildPermissionQuery(entityFilter, tenantId, customerId, entityType); | ||
192 | - String entityFilterQuery = this.buildEntityFilterQuery(entityFilter); | 192 | + String permissionQuery = this.buildPermissionQuery(ctx, entityFilter, tenantId, customerId, entityType); |
193 | + String entityFilterQuery = this.buildEntityFilterQuery(ctx, entityFilter); | ||
193 | String result = permissionQuery; | 194 | String result = permissionQuery; |
194 | if (!entityFilterQuery.isEmpty()) { | 195 | if (!entityFilterQuery.isEmpty()) { |
195 | result += " and " + entityFilterQuery; | 196 | result += " and " + entityFilterQuery; |
@@ -200,35 +201,42 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | @@ -200,35 +201,42 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | ||
200 | return result; | 201 | return result; |
201 | } | 202 | } |
202 | 203 | ||
203 | - private String buildPermissionQuery(EntityFilter entityFilter, TenantId tenantId, CustomerId customerId, EntityType entityType) { | 204 | + private String buildPermissionQuery(EntityQueryContext ctx, EntityFilter entityFilter, TenantId tenantId, CustomerId customerId, EntityType entityType) { |
204 | switch (entityFilter.getType()) { | 205 | switch (entityFilter.getType()) { |
205 | case RELATIONS_QUERY: | 206 | case RELATIONS_QUERY: |
206 | case DEVICE_SEARCH_QUERY: | 207 | case DEVICE_SEARCH_QUERY: |
207 | case ASSET_SEARCH_QUERY: | 208 | case ASSET_SEARCH_QUERY: |
208 | - return String.format("e.tenant_id='%s' and e.customer_id='%s'", UUIDConverter.fromTimeUUID(tenantId.getId()), UUIDConverter.fromTimeUUID(customerId.getId())); | 209 | + ctx.addUuidParameter("permissions_tenant_id", tenantId.getId()); |
210 | + ctx.addUuidParameter("permissions_customer_id", customerId.getId()); | ||
211 | + return "e.tenant_id=:permissions_tenant_id and e.customer_id=:permissions_customer_id"; | ||
209 | default: | 212 | default: |
210 | if (entityType == EntityType.TENANT) { | 213 | if (entityType == EntityType.TENANT) { |
211 | - return String.format("e.id='%s'", UUIDConverter.fromTimeUUID(tenantId.getId())); | 214 | + ctx.addUuidParameter("permissions_tenant_id", tenantId.getId()); |
215 | + return "e.id=:permissions_tenant_id"; | ||
212 | } else if (entityType == EntityType.CUSTOMER) { | 216 | } else if (entityType == EntityType.CUSTOMER) { |
213 | - return String.format("e.tenant_id='%s' and e.id='%s'", UUIDConverter.fromTimeUUID(tenantId.getId()), UUIDConverter.fromTimeUUID(customerId.getId())); | 217 | + ctx.addUuidParameter("permissions_tenant_id", tenantId.getId()); |
218 | + ctx.addUuidParameter("permissions_customer_id", customerId.getId()); | ||
219 | + return "e.tenant_id=:permissions_tenant_id and e.id=:permissions_customer_id"; | ||
214 | } else { | 220 | } else { |
215 | - return String.format("e.tenant_id='%s' and e.customer_id='%s'", UUIDConverter.fromTimeUUID(tenantId.getId()), UUIDConverter.fromTimeUUID(customerId.getId())); | 221 | + ctx.addUuidParameter("permissions_tenant_id", tenantId.getId()); |
222 | + ctx.addUuidParameter("permissions_customer_id", customerId.getId()); | ||
223 | + return "e.tenant_id=:permissions_tenant_id and e.customer_id=:permissions_customer_id"; | ||
216 | } | 224 | } |
217 | } | 225 | } |
218 | } | 226 | } |
219 | 227 | ||
220 | - private String buildEntityFilterQuery(EntityFilter entityFilter) { | 228 | + private String buildEntityFilterQuery(EntityQueryContext ctx, EntityFilter entityFilter) { |
221 | switch (entityFilter.getType()) { | 229 | switch (entityFilter.getType()) { |
222 | case SINGLE_ENTITY: | 230 | case SINGLE_ENTITY: |
223 | - return this.singleEntityQuery((SingleEntityFilter) entityFilter); | 231 | + return this.singleEntityQuery(ctx, (SingleEntityFilter) entityFilter); |
224 | case ENTITY_LIST: | 232 | case ENTITY_LIST: |
225 | - return this.entityListQuery((EntityListFilter) entityFilter); | 233 | + return this.entityListQuery(ctx, (EntityListFilter) entityFilter); |
226 | case ENTITY_NAME: | 234 | case ENTITY_NAME: |
227 | - return this.entityNameQuery((EntityNameFilter) entityFilter); | 235 | + return this.entityNameQuery(ctx, (EntityNameFilter) entityFilter); |
228 | case ASSET_TYPE: | 236 | case ASSET_TYPE: |
229 | case DEVICE_TYPE: | 237 | case DEVICE_TYPE: |
230 | case ENTITY_VIEW_TYPE: | 238 | case ENTITY_VIEW_TYPE: |
231 | - return this.typeQuery(entityFilter); | 239 | + return this.typeQuery(ctx, entityFilter); |
232 | case RELATIONS_QUERY: | 240 | case RELATIONS_QUERY: |
233 | case DEVICE_SEARCH_QUERY: | 241 | case DEVICE_SEARCH_QUERY: |
234 | case ASSET_SEARCH_QUERY: | 242 | case ASSET_SEARCH_QUERY: |
@@ -238,52 +246,60 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | @@ -238,52 +246,60 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | ||
238 | } | 246 | } |
239 | } | 247 | } |
240 | 248 | ||
241 | - private String getEntityTableQuery(EntityFilter entityFilter, EntityType entityType) { | 249 | + private String addEntityTableQuery(EntityQueryContext ctx, EntityFilter entityFilter, EntityType entityType) { |
242 | switch (entityFilter.getType()) { | 250 | switch (entityFilter.getType()) { |
243 | case RELATIONS_QUERY: | 251 | case RELATIONS_QUERY: |
244 | - return relationQuery((RelationsQueryFilter) entityFilter); | 252 | + return relationQuery(ctx, (RelationsQueryFilter) entityFilter); |
245 | case DEVICE_SEARCH_QUERY: | 253 | case DEVICE_SEARCH_QUERY: |
246 | DeviceSearchQueryFilter deviceQuery = (DeviceSearchQueryFilter) entityFilter; | 254 | DeviceSearchQueryFilter deviceQuery = (DeviceSearchQueryFilter) entityFilter; |
247 | - return entitySearchQuery(deviceQuery, EntityType.DEVICE, deviceQuery.getDeviceTypes()); | 255 | + return entitySearchQuery(ctx, deviceQuery, EntityType.DEVICE, deviceQuery.getDeviceTypes()); |
248 | case ASSET_SEARCH_QUERY: | 256 | case ASSET_SEARCH_QUERY: |
249 | AssetSearchQueryFilter assetQuery = (AssetSearchQueryFilter) entityFilter; | 257 | AssetSearchQueryFilter assetQuery = (AssetSearchQueryFilter) entityFilter; |
250 | - return entitySearchQuery(assetQuery, EntityType.ASSET, assetQuery.getAssetTypes()); | 258 | + return entitySearchQuery(ctx, assetQuery, EntityType.ASSET, assetQuery.getAssetTypes()); |
251 | default: | 259 | default: |
252 | return entityTableMap.get(entityType); | 260 | return entityTableMap.get(entityType); |
253 | } | 261 | } |
254 | } | 262 | } |
255 | 263 | ||
256 | - private String entitySearchQuery(EntitySearchQueryFilter entityFilter, EntityType entityType, List<String> types) { | 264 | + private String entitySearchQuery(EntityQueryContext ctx, EntitySearchQueryFilter entityFilter, EntityType entityType, List<String> types) { |
257 | EntityId rootId = entityFilter.getRootEntity(); | 265 | EntityId rootId = entityFilter.getRootEntity(); |
258 | //TODO: fetch last level only. | 266 | //TODO: fetch last level only. |
267 | + //TODO: fetch distinct records. | ||
259 | String lvlFilter = getLvlFilter(entityFilter.getMaxLevel()); | 268 | String lvlFilter = getLvlFilter(entityFilter.getMaxLevel()); |
260 | String selectFields = "SELECT tenant_id, customer_id, id, type, name, label FROM " + entityType.name() + " WHERE id in ( SELECT entity_id"; | 269 | String selectFields = "SELECT tenant_id, customer_id, id, type, name, label FROM " + entityType.name() + " WHERE id in ( SELECT entity_id"; |
261 | String from = getQueryTemplate(entityFilter.getDirection()); | 270 | String from = getQueryTemplate(entityFilter.getDirection()); |
271 | + String whereFilter = " WHERE re.relation_type = :where_relation_type AND re.to_type = :where_entity_type"; | ||
262 | 272 | ||
263 | - String whereFilter = " WHERE " + " re.relation_type = '" + entityFilter.getRelationType() + "'" + | ||
264 | - " AND re.to_type = '" + entityType.name() + "'"; | ||
265 | - from = String.format(from, UUIDConverter.fromTimeUUID(rootId.getId()), rootId.getEntityType().name(), lvlFilter, whereFilter); | 273 | + from = String.format(from, lvlFilter, whereFilter); |
266 | String query = "( " + selectFields + from + ")"; | 274 | String query = "( " + selectFields + from + ")"; |
267 | if (types != null && !types.isEmpty()) { | 275 | if (types != null && !types.isEmpty()) { |
268 | - query += " and type in (" + types.stream().map(type -> "'" + type + "'").collect(Collectors.joining(", ")) + ")"; | 276 | + query += " and type in (:relation_sub_types)"; |
277 | + ctx.addStringListParameter("relation_sub_types", types); | ||
269 | } | 278 | } |
270 | query += " )"; | 279 | query += " )"; |
280 | + ctx.addUuidParameter("relation_root_id", rootId.getId()); | ||
281 | + ctx.addStringParameter("relation_root_type", rootId.getEntityType().name()); | ||
282 | + ctx.addStringParameter("where_relation_type", entityFilter.getRelationType()); | ||
283 | + ctx.addStringParameter("where_entity_type", entityType.name()); | ||
271 | return query; | 284 | return query; |
272 | } | 285 | } |
273 | 286 | ||
274 | - private String relationQuery(RelationsQueryFilter entityFilter) { | 287 | + private String relationQuery(EntityQueryContext ctx, RelationsQueryFilter entityFilter) { |
275 | EntityId rootId = entityFilter.getRootEntity(); | 288 | EntityId rootId = entityFilter.getRootEntity(); |
276 | String lvlFilter = getLvlFilter(entityFilter.getMaxLevel()); | 289 | String lvlFilter = getLvlFilter(entityFilter.getMaxLevel()); |
277 | String selectFields = getSelectTenantId() + ", " + getSelectCustomerId() + ", " + | 290 | String selectFields = getSelectTenantId() + ", " + getSelectCustomerId() + ", " + |
278 | " entity.entity_id as id," + getSelectType() + ", " + getSelectName() + ", " + | 291 | " entity.entity_id as id," + getSelectType() + ", " + getSelectName() + ", " + |
279 | getSelectLabel() + ", entity.entity_type as entity_type"; | 292 | getSelectLabel() + ", entity.entity_type as entity_type"; |
280 | String from = getQueryTemplate(entityFilter.getDirection()); | 293 | String from = getQueryTemplate(entityFilter.getDirection()); |
294 | + ctx.addUuidParameter("relation_root_id", rootId.getId()); | ||
295 | + ctx.addStringParameter("relation_root_type", rootId.getEntityType().name()); | ||
281 | 296 | ||
282 | StringBuilder whereFilter; | 297 | StringBuilder whereFilter; |
283 | if (entityFilter.getFilters() != null && !entityFilter.getFilters().isEmpty()) { | 298 | if (entityFilter.getFilters() != null && !entityFilter.getFilters().isEmpty()) { |
284 | whereFilter = new StringBuilder(" WHERE "); | 299 | whereFilter = new StringBuilder(" WHERE "); |
285 | boolean first = true; | 300 | boolean first = true; |
286 | boolean single = entityFilter.getFilters().size() == 1; | 301 | boolean single = entityFilter.getFilters().size() == 1; |
302 | + int entityTypeFilterIdx = 0; | ||
287 | for (EntityTypeFilter etf : entityFilter.getFilters()) { | 303 | for (EntityTypeFilter etf : entityFilter.getFilters()) { |
288 | if (first) { | 304 | if (first) { |
289 | first = false; | 305 | first = false; |
@@ -291,21 +307,23 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | @@ -291,21 +307,23 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | ||
291 | whereFilter.append(" AND "); | 307 | whereFilter.append(" AND "); |
292 | } | 308 | } |
293 | String relationType = etf.getRelationType(); | 309 | String relationType = etf.getRelationType(); |
294 | - String entityTypes = etf.getEntityTypes().stream().map(type -> "'" + type + "'").collect(Collectors.joining(", ")); | ||
295 | if (!single) { | 310 | if (!single) { |
296 | whereFilter.append(" ("); | 311 | whereFilter.append(" ("); |
297 | } | 312 | } |
298 | - whereFilter.append(" re.relation_type = '").append(relationType).append("' and re.") | 313 | + whereFilter.append(" re.relation_type = :where_relation_type").append(entityTypeFilterIdx).append(" and re.") |
299 | .append(entityFilter.getDirection().equals(EntitySearchDirection.FROM) ? "to" : "from") | 314 | .append(entityFilter.getDirection().equals(EntitySearchDirection.FROM) ? "to" : "from") |
300 | - .append("_type in (").append(entityTypes).append(")"); | 315 | + .append("_type in (:where_entity_types").append(entityTypeFilterIdx).append(")"); |
301 | if (!single) { | 316 | if (!single) { |
302 | whereFilter.append(" )"); | 317 | whereFilter.append(" )"); |
303 | } | 318 | } |
319 | + ctx.addStringParameter("where_relation_type" + entityTypeFilterIdx, relationType); | ||
320 | + ctx.addStringListParameter("where_entity_types" + entityTypeFilterIdx, etf.getEntityTypes().stream().map(EntityType::name).collect(Collectors.toList())); | ||
321 | + entityTypeFilterIdx++; | ||
304 | } | 322 | } |
305 | } else { | 323 | } else { |
306 | whereFilter = new StringBuilder(); | 324 | whereFilter = new StringBuilder(); |
307 | } | 325 | } |
308 | - from = String.format(from, UUIDConverter.fromTimeUUID(rootId.getId()), rootId.getEntityType().name(), lvlFilter, whereFilter); | 326 | + from = String.format(from, lvlFilter, whereFilter); |
309 | return "( " + selectFields + from + ")"; | 327 | return "( " + selectFields + from + ")"; |
310 | } | 328 | } |
311 | 329 | ||
@@ -344,7 +362,7 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | @@ -344,7 +362,7 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | ||
344 | private String getSelectCustomerId() { | 362 | private String getSelectCustomerId() { |
345 | return "CASE" + | 363 | return "CASE" + |
346 | " WHEN entity.entity_type = 'TENANT'" + | 364 | " WHEN entity.entity_type = 'TENANT'" + |
347 | - " THEN '" + UUIDConverter.fromTimeUUID(TenantId.NULL_UUID) + "'" + | 365 | + " THEN UUID('" + TenantId.NULL_UUID + "')" + |
348 | " WHEN entity.entity_type = 'CUSTOMER' THEN entity_id" + | 366 | " WHEN entity.entity_type = 'CUSTOMER' THEN entity_id" + |
349 | " WHEN entity.entity_type = 'USER'" + | 367 | " WHEN entity.entity_type = 'USER'" + |
350 | " THEN (select customer_id from tb_user where id = entity_id)" + | 368 | " THEN (select customer_id from tb_user where id = entity_id)" + |
@@ -411,10 +429,9 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | @@ -411,10 +429,9 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | ||
411 | " END as label"; | 429 | " END as label"; |
412 | } | 430 | } |
413 | 431 | ||
414 | - private String buildWhere | ||
415 | - (List<EntityKeyMapping> selectionMapping, List<EntityKeyMapping> latestFiltersMapping, String searchText) { | ||
416 | - String latestFilters = EntityKeyMapping.buildQuery(latestFiltersMapping); | ||
417 | - String textSearchQuery = this.buildTextSearchQuery(selectionMapping, searchText); | 432 | + private String buildWhere(EntityQueryContext ctx, List<EntityKeyMapping> selectionMapping, List<EntityKeyMapping> latestFiltersMapping, String searchText) { |
433 | + String latestFilters = EntityKeyMapping.buildQuery(ctx, latestFiltersMapping); | ||
434 | + String textSearchQuery = this.buildTextSearchQuery(ctx, selectionMapping, searchText); | ||
418 | String query; | 435 | String query; |
419 | if (!StringUtils.isEmpty(latestFilters) && !StringUtils.isEmpty(textSearchQuery)) { | 436 | if (!StringUtils.isEmpty(latestFilters) && !StringUtils.isEmpty(textSearchQuery)) { |
420 | query = String.join(" AND ", latestFilters, textSearchQuery); | 437 | query = String.join(" AND ", latestFilters, textSearchQuery); |
@@ -430,32 +447,38 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | @@ -430,32 +447,38 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | ||
430 | } | 447 | } |
431 | } | 448 | } |
432 | 449 | ||
433 | - private String buildTextSearchQuery(List<EntityKeyMapping> selectionMapping, String searchText) { | 450 | + private String buildTextSearchQuery(EntityQueryContext ctx, List<EntityKeyMapping> selectionMapping, String searchText) { |
434 | if (!StringUtils.isEmpty(searchText) && !selectionMapping.isEmpty()) { | 451 | if (!StringUtils.isEmpty(searchText) && !selectionMapping.isEmpty()) { |
435 | String lowerSearchText = searchText.toLowerCase() + "%"; | 452 | String lowerSearchText = searchText.toLowerCase() + "%"; |
436 | - List<String> searchPredicates = selectionMapping.stream().map(mapping -> String.format("LOWER(%s) LIKE '%s'", | ||
437 | - mapping.getValueAlias(), lowerSearchText)).collect(Collectors.toList()); | 453 | + List<String> searchPredicates = selectionMapping.stream().map(mapping -> { |
454 | + String paramName = mapping.getValueAlias() + "_lowerSearchText"; | ||
455 | + ctx.addStringParameter(paramName, lowerSearchText); | ||
456 | + return String.format("LOWER(%s) LIKE :%s", mapping.getValueAlias(), paramName); | ||
457 | + } | ||
458 | + ).collect(Collectors.toList()); | ||
438 | return String.format("(%s)", String.join(" or ", searchPredicates)); | 459 | return String.format("(%s)", String.join(" or ", searchPredicates)); |
439 | } else { | 460 | } else { |
440 | return null; | 461 | return null; |
441 | } | 462 | } |
463 | + | ||
442 | } | 464 | } |
443 | 465 | ||
444 | - private String singleEntityQuery(SingleEntityFilter filter) { | ||
445 | - return String.format("e.id='%s'", UUIDConverter.fromTimeUUID(filter.getSingleEntity().getId())); | 466 | + private String singleEntityQuery(EntityQueryContext ctx, SingleEntityFilter filter) { |
467 | + ctx.addUuidParameter("entity_filter_single_entity_id", filter.getSingleEntity().getId()); | ||
468 | + return "e.id=:entity_filter_single_entity_id"; | ||
446 | } | 469 | } |
447 | 470 | ||
448 | - private String entityListQuery(EntityListFilter filter) { | ||
449 | - return String.format("e.id in (%s)", | ||
450 | - filter.getEntityList().stream().map(UUID::fromString).map(UUIDConverter::fromTimeUUID) | ||
451 | - .map(s -> String.format("'%s'", s)).collect(Collectors.joining(","))); | 471 | + private String entityListQuery(EntityQueryContext ctx, EntityListFilter filter) { |
472 | + ctx.addUuidListParameter("entity_filter_entity_ids", filter.getEntityList().stream().map(UUID::fromString).collect(Collectors.toList())); | ||
473 | + return "e.id in (:entity_filter_entity_ids)"; | ||
452 | } | 474 | } |
453 | 475 | ||
454 | - private String entityNameQuery(EntityNameFilter filter) { | ||
455 | - return String.format("lower(e.search_text) like lower(concat('%s', '%%'))", filter.getEntityNameFilter()); | 476 | + private String entityNameQuery(EntityQueryContext ctx, EntityNameFilter filter) { |
477 | + ctx.addStringParameter("entity_filter_name_filter", filter.getEntityNameFilter()); | ||
478 | + return "lower(e.search_text) like lower(concat(:entity_filter_name_filter, '%%'))"; | ||
456 | } | 479 | } |
457 | 480 | ||
458 | - private String typeQuery(EntityFilter filter) { | 481 | + private String typeQuery(EntityQueryContext ctx, EntityFilter filter) { |
459 | String type; | 482 | String type; |
460 | String name; | 483 | String name; |
461 | switch (filter.getType()) { | 484 | switch (filter.getType()) { |
@@ -474,7 +497,9 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | @@ -474,7 +497,9 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { | ||
474 | default: | 497 | default: |
475 | throw new RuntimeException("Not supported!"); | 498 | throw new RuntimeException("Not supported!"); |
476 | } | 499 | } |
477 | - return String.format("e.type = '%s' and lower(e.search_text) like lower(concat('%s', '%%'))", type, name); | 500 | + ctx.addStringParameter("entity_filter_type_query_type", type); |
501 | + ctx.addStringParameter("entity_filter_type_query_name", name); | ||
502 | + return "e.type = :entity_filter_type_query_type and lower(e.search_text) like lower(concat(:entity_filter_type_query_name, '%%'))"; | ||
478 | } | 503 | } |
479 | 504 | ||
480 | private EntityType resolveEntityType(EntityFilter entityFilter) { | 505 | private EntityType resolveEntityType(EntityFilter entityFilter) { |
@@ -26,39 +26,41 @@ import org.thingsboard.server.common.data.query.EntityKey; | @@ -26,39 +26,41 @@ import org.thingsboard.server.common.data.query.EntityKey; | ||
26 | import org.thingsboard.server.common.data.query.EntityKeyType; | 26 | import org.thingsboard.server.common.data.query.EntityKeyType; |
27 | import org.thingsboard.server.common.data.query.TsValue; | 27 | import org.thingsboard.server.common.data.query.TsValue; |
28 | 28 | ||
29 | +import java.nio.ByteBuffer; | ||
29 | import java.util.HashMap; | 30 | import java.util.HashMap; |
30 | import java.util.List; | 31 | import java.util.List; |
31 | import java.util.Map; | 32 | import java.util.Map; |
33 | +import java.util.UUID; | ||
32 | import java.util.stream.Collectors; | 34 | import java.util.stream.Collectors; |
33 | 35 | ||
34 | public class EntityDataAdapter { | 36 | public class EntityDataAdapter { |
35 | 37 | ||
36 | public static PageData<EntityData> createEntityData(EntityDataPageLink pageLink, | 38 | public static PageData<EntityData> createEntityData(EntityDataPageLink pageLink, |
37 | List<EntityKeyMapping> selectionMapping, | 39 | List<EntityKeyMapping> selectionMapping, |
38 | - List<Object[]> rows, | 40 | + List<Map<String, Object>> rows, |
39 | int totalElements) { | 41 | int totalElements) { |
40 | - int totalPages = pageLink.getPageSize() > 0 ? (int)Math.ceil((float)totalElements / pageLink.getPageSize()) : 1; | 42 | + int totalPages = pageLink.getPageSize() > 0 ? (int) Math.ceil((float) totalElements / pageLink.getPageSize()) : 1; |
41 | int startIndex = pageLink.getPageSize() * pageLink.getPage(); | 43 | int startIndex = pageLink.getPageSize() * pageLink.getPage(); |
42 | boolean hasNext = pageLink.getPageSize() > 0 && totalElements > startIndex + rows.size(); | 44 | boolean hasNext = pageLink.getPageSize() > 0 && totalElements > startIndex + rows.size(); |
43 | List<EntityData> entitiesData = convertListToEntityData(rows, selectionMapping); | 45 | List<EntityData> entitiesData = convertListToEntityData(rows, selectionMapping); |
44 | return new PageData<>(entitiesData, totalPages, totalElements, hasNext); | 46 | return new PageData<>(entitiesData, totalPages, totalElements, hasNext); |
45 | } | 47 | } |
46 | 48 | ||
47 | - private static List<EntityData> convertListToEntityData(List<Object[]> result, List<EntityKeyMapping> selectionMapping) { | 49 | + private static List<EntityData> convertListToEntityData(List<Map<String, Object>> result, List<EntityKeyMapping> selectionMapping) { |
48 | return result.stream().map(row -> toEntityData(row, selectionMapping)).collect(Collectors.toList()); | 50 | return result.stream().map(row -> toEntityData(row, selectionMapping)).collect(Collectors.toList()); |
49 | } | 51 | } |
50 | 52 | ||
51 | - private static EntityData toEntityData(Object[] row, List<EntityKeyMapping> selectionMapping) { | ||
52 | - String id = (String)row[0]; | ||
53 | - EntityType entityType = EntityType.valueOf((String)row[1]); | ||
54 | - EntityId entityId = EntityIdFactory.getByTypeAndUuid(entityType, UUIDConverter.fromString(id)); | 53 | + private static EntityData toEntityData(Map<String, Object> row, List<EntityKeyMapping> selectionMapping) { |
54 | + UUID id = (UUID)row.get("id"); | ||
55 | + EntityType entityType = EntityType.valueOf((String) row.get("entity_type")); | ||
56 | + EntityId entityId = EntityIdFactory.getByTypeAndUuid(entityType, id); | ||
55 | Map<EntityKeyType, Map<String, TsValue>> latest = new HashMap<>(); | 57 | Map<EntityKeyType, Map<String, TsValue>> latest = new HashMap<>(); |
56 | Map<String, TsValue[]> timeseries = new HashMap<>(); | 58 | Map<String, TsValue[]> timeseries = new HashMap<>(); |
57 | EntityData entityData = new EntityData(entityId, latest, timeseries); | 59 | EntityData entityData = new EntityData(entityId, latest, timeseries); |
58 | - for (EntityKeyMapping mapping: selectionMapping) { | 60 | + for (EntityKeyMapping mapping : selectionMapping) { |
59 | if (!mapping.isIgnore()) { | 61 | if (!mapping.isIgnore()) { |
60 | EntityKey entityKey = mapping.getEntityKey(); | 62 | EntityKey entityKey = mapping.getEntityKey(); |
61 | - Object value = row[mapping.getIndex()]; | 63 | + Object value = row.get(mapping.getValueAlias()); |
62 | String strValue; | 64 | String strValue; |
63 | long ts; | 65 | long ts; |
64 | if (entityKey.getType().equals(EntityKeyType.ENTITY_FIELD)) { | 66 | if (entityKey.getType().equals(EntityKeyType.ENTITY_FIELD)) { |
@@ -66,7 +68,7 @@ public class EntityDataAdapter { | @@ -66,7 +68,7 @@ public class EntityDataAdapter { | ||
66 | ts = System.currentTimeMillis(); | 68 | ts = System.currentTimeMillis(); |
67 | } else { | 69 | } else { |
68 | strValue = convertValue(value); | 70 | strValue = convertValue(value); |
69 | - Object tsObject = row[mapping.getIndex() + 1]; | 71 | + Object tsObject = row.get(mapping.getTsAlias()); |
70 | ts = tsObject != null ? Long.parseLong(tsObject.toString()) : 0; | 72 | ts = tsObject != null ? Long.parseLong(tsObject.toString()) : 0; |
71 | } | 73 | } |
72 | TsValue tsValue = new TsValue(ts, strValue); | 74 | TsValue tsValue = new TsValue(ts, strValue); |
@@ -73,6 +73,7 @@ public class EntityKeyMapping { | @@ -73,6 +73,7 @@ public class EntityKeyMapping { | ||
73 | private boolean ignore = false; | 73 | private boolean ignore = false; |
74 | private List<KeyFilter> keyFilters; | 74 | private List<KeyFilter> keyFilters; |
75 | private EntityKey entityKey; | 75 | private EntityKey entityKey; |
76 | + private int paramIdx = 0; | ||
76 | 77 | ||
77 | public boolean hasFilter() { | 78 | public boolean hasFilter() { |
78 | return keyFilters != null && !keyFilters.isEmpty(); | 79 | return keyFilters != null && !keyFilters.isEmpty(); |
@@ -95,23 +96,23 @@ public class EntityKeyMapping { | @@ -95,23 +96,23 @@ public class EntityKeyMapping { | ||
95 | String column = entityFieldColumnMap.get(entityKey.getKey()); | 96 | String column = entityFieldColumnMap.get(entityKey.getKey()); |
96 | return String.format("e.%s as %s", column, getValueAlias()); | 97 | return String.format("e.%s as %s", column, getValueAlias()); |
97 | } else if (entityKey.getType().equals(EntityKeyType.TIME_SERIES)) { | 98 | } else if (entityKey.getType().equals(EntityKeyType.TIME_SERIES)) { |
98 | - return buildTimeseriesSelection(); | 99 | + return buildTimeSeriesSelection(); |
99 | } else { | 100 | } else { |
100 | return buildAttributeSelection(); | 101 | return buildAttributeSelection(); |
101 | } | 102 | } |
102 | } | 103 | } |
103 | 104 | ||
104 | - public Stream<String> toQueries() { | 105 | + public Stream<String> toQueries(EntityQueryContext ctx) { |
105 | if (hasFilter()) { | 106 | if (hasFilter()) { |
106 | String keyAlias = entityKey.getType().equals(EntityKeyType.ENTITY_FIELD) ? "e" : alias; | 107 | String keyAlias = entityKey.getType().equals(EntityKeyType.ENTITY_FIELD) ? "e" : alias; |
107 | return keyFilters.stream().map(keyFilter -> | 108 | return keyFilters.stream().map(keyFilter -> |
108 | - this.buildKeyQuery(keyAlias, keyFilter)); | 109 | + this.buildKeyQuery(ctx, keyAlias, keyFilter)); |
109 | } else { | 110 | } else { |
110 | return null; | 111 | return null; |
111 | } | 112 | } |
112 | } | 113 | } |
113 | 114 | ||
114 | - public String toLatestJoin(EntityFilter entityFilter, EntityType entityType) { | 115 | + public String toLatestJoin(EntityQueryContext ctx, EntityFilter entityFilter, EntityType entityType) { |
115 | String entityTypeStr; | 116 | String entityTypeStr; |
116 | if (entityFilter.getType().equals(EntityFilterType.RELATIONS_QUERY)) { | 117 | if (entityFilter.getType().equals(EntityFilterType.RELATIONS_QUERY)) { |
117 | entityTypeStr = "entities.entity_type"; | 118 | entityTypeStr = "entities.entity_type"; |
@@ -119,12 +120,13 @@ public class EntityKeyMapping { | @@ -119,12 +120,13 @@ public class EntityKeyMapping { | ||
119 | entityTypeStr = "'" + entityType.name() + "'"; | 120 | entityTypeStr = "'" + entityType.name() + "'"; |
120 | } | 121 | } |
121 | String join = hasFilter() ? "left join" : "left outer join"; | 122 | String join = hasFilter() ? "left join" : "left outer join"; |
123 | + ctx.addStringParameter(alias + "_key_id", entityKey.getKey()); | ||
122 | if (entityKey.getType().equals(EntityKeyType.TIME_SERIES)) { | 124 | if (entityKey.getType().equals(EntityKeyType.TIME_SERIES)) { |
123 | - // TODO: | ||
124 | - throw new RuntimeException("Not implemented!"); | 125 | + return String.format("%s ts_kv_latest %s ON %s.entity_id=to_uuid(entities.id) AND %s.key = (select key_id from ts_kv_dictionary where key = :%s_key_id)", |
126 | + join, alias, alias, alias, alias); | ||
125 | } else { | 127 | } else { |
126 | - String query = String.format("%s attribute_kv %s ON %s.entity_id=entities.id AND %s.entity_type=%s AND %s.attribute_key='%s'", | ||
127 | - join, alias, alias, alias, entityTypeStr, alias, entityKey.getKey()); | 128 | + String query = String.format("%s attribute_kv %s ON %s.entity_id=entities.id AND %s.entity_type=%s AND %s.attribute_key=:%s_key_id", |
129 | + join, alias, alias, alias, entityTypeStr, alias, alias); | ||
128 | if (!entityKey.getType().equals(EntityKeyType.ATTRIBUTE)) { | 130 | if (!entityKey.getType().equals(EntityKeyType.ATTRIBUTE)) { |
129 | String scope; | 131 | String scope; |
130 | if (entityKey.getType().equals(EntityKeyType.CLIENT_ATTRIBUTE)) { | 132 | if (entityKey.getType().equals(EntityKeyType.CLIENT_ATTRIBUTE)) { |
@@ -145,13 +147,13 @@ public class EntityKeyMapping { | @@ -145,13 +147,13 @@ public class EntityKeyMapping { | ||
145 | Collectors.joining(", ")); | 147 | Collectors.joining(", ")); |
146 | } | 148 | } |
147 | 149 | ||
148 | - public static String buildLatestJoins(EntityFilter entityFilter, EntityType entityType, List<EntityKeyMapping> latestMappings) { | ||
149 | - return latestMappings.stream().map(mapping -> mapping.toLatestJoin(entityFilter, entityType)).collect( | 150 | + public static String buildLatestJoins(EntityQueryContext ctx, EntityFilter entityFilter, EntityType entityType, List<EntityKeyMapping> latestMappings) { |
151 | + return latestMappings.stream().map(mapping -> mapping.toLatestJoin(ctx, entityFilter, entityType)).collect( | ||
150 | Collectors.joining(" ")); | 152 | Collectors.joining(" ")); |
151 | } | 153 | } |
152 | 154 | ||
153 | - public static String buildQuery(List<EntityKeyMapping> mappings) { | ||
154 | - return mappings.stream().flatMap(EntityKeyMapping::toQueries).collect( | 155 | + public static String buildQuery(EntityQueryContext ctx, List<EntityKeyMapping> mappings) { |
156 | + return mappings.stream().flatMap(mapping -> mapping.toQueries(ctx)).collect( | ||
155 | Collectors.joining(" AND ")); | 157 | Collectors.joining(" AND ")); |
156 | } | 158 | } |
157 | 159 | ||
@@ -250,40 +252,46 @@ public class EntityKeyMapping { | @@ -250,40 +252,46 @@ public class EntityKeyMapping { | ||
250 | return String.join(", ", attrValSelection, attrTsSelection); | 252 | return String.join(", ", attrValSelection, attrTsSelection); |
251 | } | 253 | } |
252 | 254 | ||
253 | - private String buildTimeseriesSelection() { | ||
254 | - // TODO: | 255 | + private String buildTimeSeriesSelection() { |
255 | String attrValAlias = getValueAlias(); | 256 | String attrValAlias = getValueAlias(); |
256 | String attrTsAlias = getTsAlias(); | 257 | String attrTsAlias = getTsAlias(); |
257 | - return String.format("(select '') as %s, (select 1) as %s", attrValAlias, attrTsAlias); | 258 | + String attrValSelection = |
259 | + String.format("(coalesce(cast(%s.bool_v as varchar), '') || " + | ||
260 | + "coalesce(%s.str_v, '') || " + | ||
261 | + "coalesce(cast(%s.long_v as varchar), '') || " + | ||
262 | + "coalesce(cast(%s.dbl_v as varchar), '') || " + | ||
263 | + "coalesce(cast(%s.json_v as varchar), '')) as %s", alias, alias, alias, alias, alias, attrValAlias); | ||
264 | + String attrTsSelection = String.format("%s.ts as %s", alias, attrTsAlias); | ||
265 | + return String.join(", ", attrValSelection, attrTsSelection); | ||
258 | } | 266 | } |
259 | 267 | ||
260 | - private String buildKeyQuery(String alias, KeyFilter keyFilter) { | ||
261 | - return this.buildPredicateQuery(alias, keyFilter.getKey(), keyFilter.getPredicate()); | 268 | + private String buildKeyQuery(EntityQueryContext ctx, String alias, KeyFilter keyFilter) { |
269 | + return this.buildPredicateQuery(ctx, alias, keyFilter.getKey(), keyFilter.getPredicate()); | ||
262 | } | 270 | } |
263 | 271 | ||
264 | - private String buildPredicateQuery(String alias, EntityKey key, KeyFilterPredicate predicate) { | 272 | + private String buildPredicateQuery(EntityQueryContext ctx, String alias, EntityKey key, KeyFilterPredicate predicate) { |
265 | if (predicate.getType().equals(FilterPredicateType.COMPLEX)) { | 273 | if (predicate.getType().equals(FilterPredicateType.COMPLEX)) { |
266 | - return this.buildComplexPredicateQuery(alias, key, (ComplexFilterPredicate) predicate); | 274 | + return this.buildComplexPredicateQuery(ctx, alias, key, (ComplexFilterPredicate) predicate); |
267 | } else { | 275 | } else { |
268 | - return this.buildSimplePredicateQuery(alias, key, predicate); | 276 | + return this.buildSimplePredicateQuery(ctx, alias, key, predicate); |
269 | } | 277 | } |
270 | } | 278 | } |
271 | 279 | ||
272 | - private String buildComplexPredicateQuery(String alias, EntityKey key, ComplexFilterPredicate predicate) { | 280 | + private String buildComplexPredicateQuery(EntityQueryContext ctx, String alias, EntityKey key, ComplexFilterPredicate predicate) { |
273 | return predicate.getPredicates().stream() | 281 | return predicate.getPredicates().stream() |
274 | - .map(keyFilterPredicate -> this.buildPredicateQuery(alias, key, keyFilterPredicate)).collect(Collectors.joining( | 282 | + .map(keyFilterPredicate -> this.buildPredicateQuery(ctx, alias, key, keyFilterPredicate)).collect(Collectors.joining( |
275 | " " + predicate.getOperation().name() + " " | 283 | " " + predicate.getOperation().name() + " " |
276 | )); | 284 | )); |
277 | } | 285 | } |
278 | 286 | ||
279 | - private String buildSimplePredicateQuery(String alias, EntityKey key, KeyFilterPredicate predicate) { | 287 | + private String buildSimplePredicateQuery(EntityQueryContext ctx, String alias, EntityKey key, KeyFilterPredicate predicate) { |
280 | if (predicate.getType().equals(FilterPredicateType.NUMERIC)) { | 288 | if (predicate.getType().equals(FilterPredicateType.NUMERIC)) { |
281 | if (key.getType().equals(EntityKeyType.ENTITY_FIELD)) { | 289 | if (key.getType().equals(EntityKeyType.ENTITY_FIELD)) { |
282 | String column = entityFieldColumnMap.get(key.getKey()); | 290 | String column = entityFieldColumnMap.get(key.getKey()); |
283 | - return this.buildNumericPredicateQuery(alias + "." + column, (NumericFilterPredicate) predicate); | 291 | + return this.buildNumericPredicateQuery(ctx, alias + "." + column, (NumericFilterPredicate) predicate); |
284 | } else { | 292 | } else { |
285 | - String longQuery = this.buildNumericPredicateQuery(alias + ".long_v", (NumericFilterPredicate) predicate); | ||
286 | - String doubleQuery = this.buildNumericPredicateQuery(alias + ".dbl_v", (NumericFilterPredicate) predicate); | 293 | + String longQuery = this.buildNumericPredicateQuery(ctx, alias + ".long_v", (NumericFilterPredicate) predicate); |
294 | + String doubleQuery = this.buildNumericPredicateQuery(ctx, alias + ".dbl_v", (NumericFilterPredicate) predicate); | ||
287 | return String.format("(%s or %s)", longQuery, doubleQuery); | 295 | return String.format("(%s or %s)", longQuery, doubleQuery); |
288 | } | 296 | } |
289 | } else { | 297 | } else { |
@@ -295,15 +303,16 @@ public class EntityKeyMapping { | @@ -295,15 +303,16 @@ public class EntityKeyMapping { | ||
295 | } | 303 | } |
296 | String field = alias + "." + column; | 304 | String field = alias + "." + column; |
297 | if (predicate.getType().equals(FilterPredicateType.STRING)) { | 305 | if (predicate.getType().equals(FilterPredicateType.STRING)) { |
298 | - return this.buildStringPredicateQuery(field, (StringFilterPredicate) predicate); | 306 | + return this.buildStringPredicateQuery(ctx, field, (StringFilterPredicate) predicate); |
299 | } else { | 307 | } else { |
300 | - return this.buildBooleanPredicateQuery(field, (BooleanFilterPredicate) predicate); | 308 | + return this.buildBooleanPredicateQuery(ctx, field, (BooleanFilterPredicate) predicate); |
301 | } | 309 | } |
302 | } | 310 | } |
303 | } | 311 | } |
304 | 312 | ||
305 | - private String buildStringPredicateQuery(String field, StringFilterPredicate stringFilterPredicate) { | 313 | + private String buildStringPredicateQuery(EntityQueryContext ctx, String field, StringFilterPredicate stringFilterPredicate) { |
306 | String operationField = field; | 314 | String operationField = field; |
315 | + String paramName = getNextParameterName(field); | ||
307 | String value = stringFilterPredicate.getValue(); | 316 | String value = stringFilterPredicate.getValue(); |
308 | String stringOperationQuery = ""; | 317 | String stringOperationQuery = ""; |
309 | if (stringFilterPredicate.isIgnoreCase()) { | 318 | if (stringFilterPredicate.isIgnoreCase()) { |
@@ -312,65 +321,77 @@ public class EntityKeyMapping { | @@ -312,65 +321,77 @@ public class EntityKeyMapping { | ||
312 | } | 321 | } |
313 | switch (stringFilterPredicate.getOperation()) { | 322 | switch (stringFilterPredicate.getOperation()) { |
314 | case EQUAL: | 323 | case EQUAL: |
315 | - stringOperationQuery = String.format("%s = '%s'", operationField, value); | 324 | + stringOperationQuery = String.format("%s = :%s", operationField, paramName); |
316 | break; | 325 | break; |
317 | case NOT_EQUAL: | 326 | case NOT_EQUAL: |
318 | - stringOperationQuery = String.format("%s != '%s'", operationField, value); | 327 | + stringOperationQuery = String.format("%s != :%s", operationField, paramName); |
319 | break; | 328 | break; |
320 | case STARTS_WITH: | 329 | case STARTS_WITH: |
321 | - stringOperationQuery = String.format("%s like '%s%%'", operationField, value); | 330 | + value += "%"; |
331 | + stringOperationQuery = String.format("%s like :%s", operationField, paramName); | ||
322 | break; | 332 | break; |
323 | case ENDS_WITH: | 333 | case ENDS_WITH: |
324 | - stringOperationQuery = String.format("%s like '%%%s'", operationField, value); | 334 | + value = "%" + value; |
335 | + stringOperationQuery = String.format("%s like :%s", operationField, paramName); | ||
325 | break; | 336 | break; |
326 | case CONTAINS: | 337 | case CONTAINS: |
327 | - stringOperationQuery = String.format("%s like '%%%s%%'", operationField, value); | 338 | + value = "%" + value + "%"; |
339 | + stringOperationQuery = String.format("%s like :%s", operationField, paramName); | ||
328 | break; | 340 | break; |
329 | case NOT_CONTAINS: | 341 | case NOT_CONTAINS: |
330 | - stringOperationQuery = String.format("%s not like '%%%s%%'", operationField, value); | 342 | + value = "%" + value + "%"; |
343 | + stringOperationQuery = String.format("%s not like :%s", operationField, paramName); | ||
331 | break; | 344 | break; |
332 | } | 345 | } |
346 | + ctx.addStringParameter(paramName, value); | ||
333 | return String.format("(%s is not null and %s)", field, stringOperationQuery); | 347 | return String.format("(%s is not null and %s)", field, stringOperationQuery); |
334 | } | 348 | } |
335 | 349 | ||
336 | - private String buildNumericPredicateQuery(String field, NumericFilterPredicate numericFilterPredicate) { | ||
337 | - double value = numericFilterPredicate.getValue(); | 350 | + private String buildNumericPredicateQuery(EntityQueryContext ctx, String field, NumericFilterPredicate numericFilterPredicate) { |
351 | + String paramName = getNextParameterName(field); | ||
352 | + ctx.addDoubleParameter(paramName, numericFilterPredicate.getValue()); | ||
338 | String numericOperationQuery = ""; | 353 | String numericOperationQuery = ""; |
339 | switch (numericFilterPredicate.getOperation()) { | 354 | switch (numericFilterPredicate.getOperation()) { |
340 | case EQUAL: | 355 | case EQUAL: |
341 | - numericOperationQuery = String.format("%s = %s", field, value); | 356 | + numericOperationQuery = String.format("%s = :%s", field, paramName); |
342 | break; | 357 | break; |
343 | case NOT_EQUAL: | 358 | case NOT_EQUAL: |
344 | - numericOperationQuery = String.format("%s != '%s'", field, value); | 359 | + numericOperationQuery = String.format("%s != :%s", field, paramName); |
345 | break; | 360 | break; |
346 | case GREATER: | 361 | case GREATER: |
347 | - numericOperationQuery = String.format("%s > %s", field, value); | 362 | + numericOperationQuery = String.format("%s > :%s", field, paramName); |
348 | break; | 363 | break; |
349 | case GREATER_OR_EQUAL: | 364 | case GREATER_OR_EQUAL: |
350 | - numericOperationQuery = String.format("%s >= %s", field, value); | 365 | + numericOperationQuery = String.format("%s >= :%s", field, paramName); |
351 | break; | 366 | break; |
352 | case LESS: | 367 | case LESS: |
353 | - numericOperationQuery = String.format("%s < %s", field, value); | 368 | + numericOperationQuery = String.format("%s < :%s", field, paramName); |
354 | break; | 369 | break; |
355 | case LESS_OR_EQUAL: | 370 | case LESS_OR_EQUAL: |
356 | - numericOperationQuery = String.format("%s <= %s", field, value); | 371 | + numericOperationQuery = String.format("%s <= :%s", field, paramName); |
357 | break; | 372 | break; |
358 | } | 373 | } |
359 | return String.format("(%s is not null and %s)", field, numericOperationQuery); | 374 | return String.format("(%s is not null and %s)", field, numericOperationQuery); |
360 | } | 375 | } |
361 | 376 | ||
362 | - private String buildBooleanPredicateQuery(String field, | 377 | + private String buildBooleanPredicateQuery(EntityQueryContext ctx, String field, |
363 | BooleanFilterPredicate booleanFilterPredicate) { | 378 | BooleanFilterPredicate booleanFilterPredicate) { |
364 | - boolean value = booleanFilterPredicate.isValue(); | 379 | + String paramName = getNextParameterName(field); |
380 | + ctx.addBooleanParameter(paramName, booleanFilterPredicate.isValue()); | ||
365 | String booleanOperationQuery = ""; | 381 | String booleanOperationQuery = ""; |
366 | switch (booleanFilterPredicate.getOperation()) { | 382 | switch (booleanFilterPredicate.getOperation()) { |
367 | case EQUAL: | 383 | case EQUAL: |
368 | - booleanOperationQuery = String.format("%s = %s", field, value); | 384 | + booleanOperationQuery = String.format("%s = :%s", field, paramName); |
369 | break; | 385 | break; |
370 | case NOT_EQUAL: | 386 | case NOT_EQUAL: |
371 | - booleanOperationQuery = String.format("%s != %s", field, value); | 387 | + booleanOperationQuery = String.format("%s != :%s", field, paramName); |
372 | break; | 388 | break; |
373 | } | 389 | } |
374 | return String.format("(%s is not null and %s)", field, booleanOperationQuery); | 390 | return String.format("(%s is not null and %s)", field, booleanOperationQuery); |
375 | } | 391 | } |
392 | + | ||
393 | + private String getNextParameterName(String field) { | ||
394 | + paramIdx++; | ||
395 | + return field.replace(".", "_") + "_" + paramIdx; | ||
396 | + } | ||
376 | } | 397 | } |
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.sql.query; | ||
17 | + | ||
18 | +import org.hibernate.type.PostgresUUIDType; | ||
19 | +import org.springframework.jdbc.core.namedparam.SqlParameterSource; | ||
20 | + | ||
21 | +import java.sql.Types; | ||
22 | +import java.util.HashMap; | ||
23 | +import java.util.List; | ||
24 | +import java.util.Map; | ||
25 | +import java.util.UUID; | ||
26 | + | ||
27 | +public class EntityQueryContext implements SqlParameterSource { | ||
28 | + private static final PostgresUUIDType UUID_TYPE = new PostgresUUIDType(); | ||
29 | + | ||
30 | + private final StringBuilder query; | ||
31 | + private final Map<String, Parameter> params; | ||
32 | + | ||
33 | + public EntityQueryContext() { | ||
34 | + query = new StringBuilder(); | ||
35 | + params = new HashMap<>(); | ||
36 | + } | ||
37 | + | ||
38 | + void addParameter(String name, Object value, int type, String typeName) { | ||
39 | + Parameter existing = params.put(name, new Parameter(value, type, typeName)); | ||
40 | + if (existing != null) { | ||
41 | + throw new RuntimeException("Parameter with name: " + name + " was already registered!"); | ||
42 | + } | ||
43 | + } | ||
44 | + | ||
45 | + public void append(String s) { | ||
46 | + query.append(s); | ||
47 | + } | ||
48 | + | ||
49 | + @Override | ||
50 | + public boolean hasValue(String paramName) { | ||
51 | + return params.containsKey(paramName); | ||
52 | + } | ||
53 | + | ||
54 | + @Override | ||
55 | + public Object getValue(String paramName) throws IllegalArgumentException { | ||
56 | + return checkParameter(paramName).value; | ||
57 | + } | ||
58 | + | ||
59 | + @Override | ||
60 | + public int getSqlType(String paramName) { | ||
61 | + return checkParameter(paramName).type; | ||
62 | + } | ||
63 | + | ||
64 | + private Parameter checkParameter(String paramName) { | ||
65 | + Parameter param = params.get(paramName); | ||
66 | + if (param == null) { | ||
67 | + throw new RuntimeException("Parameter with name: " + paramName + " is not set!"); | ||
68 | + } | ||
69 | + return param; | ||
70 | + } | ||
71 | + | ||
72 | + @Override | ||
73 | + public String getTypeName(String paramName) { | ||
74 | + return params.get(paramName).name; | ||
75 | + } | ||
76 | + | ||
77 | + @Override | ||
78 | + public String[] getParameterNames() { | ||
79 | + return params.keySet().toArray(new String[]{}); | ||
80 | + } | ||
81 | + | ||
82 | + public void addUuidParameter(String name, UUID value) { | ||
83 | + addParameter(name, value, UUID_TYPE.sqlType(), UUID_TYPE.getName()); | ||
84 | + } | ||
85 | + | ||
86 | + public void addStringParameter(String name, String value) { | ||
87 | + addParameter(name, value, Types.VARCHAR, "VARCHAR"); | ||
88 | + } | ||
89 | + | ||
90 | + public void addDoubleParameter(String name, double value) { | ||
91 | + addParameter(name, value, Types.DOUBLE, "DOUBLE"); | ||
92 | + } | ||
93 | + | ||
94 | + public void addStringListParameter(String name, List<String> value) { | ||
95 | + addParameter(name, value, Types.VARCHAR, "VARCHAR"); | ||
96 | + } | ||
97 | + | ||
98 | + public void addBooleanParameter(String name, boolean value) { | ||
99 | + addParameter(name, value, Types.BOOLEAN, "BOOLEAN"); | ||
100 | + } | ||
101 | + | ||
102 | + public void addUuidListParameter(String name, List<UUID> value) { | ||
103 | + addParameter(name, value, UUID_TYPE.sqlType(), UUID_TYPE.getName()); | ||
104 | + } | ||
105 | + | ||
106 | + public String getQuery() { | ||
107 | + return query.toString(); | ||
108 | + } | ||
109 | + | ||
110 | + | ||
111 | + public static class Parameter { | ||
112 | + private final Object value; | ||
113 | + private final int type; | ||
114 | + private final String name; | ||
115 | + | ||
116 | + public Parameter(Object value, int type, String name) { | ||
117 | + this.value = value; | ||
118 | + this.type = type; | ||
119 | + this.name = name; | ||
120 | + } | ||
121 | + } | ||
122 | +} |
@@ -22,6 +22,8 @@ import org.thingsboard.server.dao.model.sql.RelationEntity; | @@ -22,6 +22,8 @@ import org.thingsboard.server.dao.model.sql.RelationEntity; | ||
22 | import org.thingsboard.server.dao.util.HsqlDao; | 22 | import org.thingsboard.server.dao.util.HsqlDao; |
23 | import org.thingsboard.server.dao.util.SqlDao; | 23 | import org.thingsboard.server.dao.util.SqlDao; |
24 | 24 | ||
25 | +import javax.persistence.Query; | ||
26 | + | ||
25 | @HsqlDao | 27 | @HsqlDao |
26 | @SqlDao | 28 | @SqlDao |
27 | @Repository | 29 | @Repository |
@@ -30,9 +32,25 @@ public class HsqlRelationInsertRepository extends AbstractRelationInsertReposito | @@ -30,9 +32,25 @@ public class HsqlRelationInsertRepository extends AbstractRelationInsertReposito | ||
30 | 32 | ||
31 | private static final String INSERT_ON_CONFLICT_DO_UPDATE = "MERGE INTO relation USING (VALUES :fromId, :fromType, :toId, :toType, :relationTypeGroup, :relationType, :additionalInfo) R " + | 33 | private static final String INSERT_ON_CONFLICT_DO_UPDATE = "MERGE INTO relation USING (VALUES :fromId, :fromType, :toId, :toType, :relationTypeGroup, :relationType, :additionalInfo) R " + |
32 | "(from_id, from_type, to_id, to_type, relation_type_group, relation_type, additional_info) " + | 34 | "(from_id, from_type, to_id, to_type, relation_type_group, relation_type, additional_info) " + |
33 | - "ON (relation.from_id = R.from_id AND relation.from_type = R.from_type AND relation.relation_type_group = R.relation_type_group AND relation.relation_type = R.relation_type AND relation.to_id = R.to_id AND relation.to_type = R.to_type) " + | 35 | + "ON (relation.from_id = UUID(R.from_id) AND relation.from_type = R.from_type AND relation.relation_type_group = R.relation_type_group AND relation.relation_type = R.relation_type AND relation.to_id = UUID(R.to_id) AND relation.to_type = R.to_type) " + |
34 | "WHEN MATCHED THEN UPDATE SET relation.additional_info = R.additional_info " + | 36 | "WHEN MATCHED THEN UPDATE SET relation.additional_info = R.additional_info " + |
35 | - "WHEN NOT MATCHED THEN INSERT (from_id, from_type, to_id, to_type, relation_type_group, relation_type, additional_info) VALUES (R.from_id, R.from_type, R.to_id, R.to_type, R.relation_type_group, R.relation_type, R.additional_info)"; | 37 | + "WHEN NOT MATCHED THEN INSERT (from_id, from_type, to_id, to_type, relation_type_group, relation_type, additional_info) VALUES (UUID(R.from_id), R.from_type, UUID(R.to_id), R.to_type, R.relation_type_group, R.relation_type, R.additional_info)"; |
38 | + | ||
39 | + protected Query getQuery(RelationEntity entity, String query) { | ||
40 | + Query nativeQuery = entityManager.createNativeQuery(query, RelationEntity.class); | ||
41 | + if (entity.getAdditionalInfo() == null) { | ||
42 | + nativeQuery.setParameter("additionalInfo", null); | ||
43 | + } else { | ||
44 | + nativeQuery.setParameter("additionalInfo", entity.getAdditionalInfo().toString()); | ||
45 | + } | ||
46 | + return nativeQuery | ||
47 | + .setParameter("fromId", entity.getFromId().toString()) | ||
48 | + .setParameter("fromType", entity.getFromType()) | ||
49 | + .setParameter("toId", entity.getToId().toString()) | ||
50 | + .setParameter("toType", entity.getToType()) | ||
51 | + .setParameter("relationTypeGroup", entity.getRelationTypeGroup()) | ||
52 | + .setParameter("relationType", entity.getRelationType()); | ||
53 | + } | ||
36 | 54 | ||
37 | @Override | 55 | @Override |
38 | public RelationEntity saveOrUpdate(RelationEntity entity) { | 56 | public RelationEntity saveOrUpdate(RelationEntity entity) { |
@@ -44,8 +44,6 @@ import javax.persistence.criteria.Predicate; | @@ -44,8 +44,6 @@ import javax.persistence.criteria.Predicate; | ||
44 | import java.util.ArrayList; | 44 | import java.util.ArrayList; |
45 | import java.util.List; | 45 | import java.util.List; |
46 | 46 | ||
47 | -import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID; | ||
48 | - | ||
49 | /** | 47 | /** |
50 | * Created by Valerii Sosliuk on 5/29/2017. | 48 | * Created by Valerii Sosliuk on 5/29/2017. |
51 | */ | 49 | */ |
@@ -64,7 +62,7 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple | @@ -64,7 +62,7 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple | ||
64 | public ListenableFuture<List<EntityRelation>> findAllByFrom(TenantId tenantId, EntityId from, RelationTypeGroup typeGroup) { | 62 | public ListenableFuture<List<EntityRelation>> findAllByFrom(TenantId tenantId, EntityId from, RelationTypeGroup typeGroup) { |
65 | return service.submit(() -> DaoUtil.convertDataList( | 63 | return service.submit(() -> DaoUtil.convertDataList( |
66 | relationRepository.findAllByFromIdAndFromTypeAndRelationTypeGroup( | 64 | relationRepository.findAllByFromIdAndFromTypeAndRelationTypeGroup( |
67 | - UUIDConverter.fromTimeUUID(from.getId()), | 65 | + from.getId(), |
68 | from.getEntityType().name(), | 66 | from.getEntityType().name(), |
69 | typeGroup.name()))); | 67 | typeGroup.name()))); |
70 | } | 68 | } |
@@ -73,7 +71,7 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple | @@ -73,7 +71,7 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple | ||
73 | public ListenableFuture<List<EntityRelation>> findAllByFromAndType(TenantId tenantId, EntityId from, String relationType, RelationTypeGroup typeGroup) { | 71 | public ListenableFuture<List<EntityRelation>> findAllByFromAndType(TenantId tenantId, EntityId from, String relationType, RelationTypeGroup typeGroup) { |
74 | return service.submit(() -> DaoUtil.convertDataList( | 72 | return service.submit(() -> DaoUtil.convertDataList( |
75 | relationRepository.findAllByFromIdAndFromTypeAndRelationTypeAndRelationTypeGroup( | 73 | relationRepository.findAllByFromIdAndFromTypeAndRelationTypeAndRelationTypeGroup( |
76 | - UUIDConverter.fromTimeUUID(from.getId()), | 74 | + from.getId(), |
77 | from.getEntityType().name(), | 75 | from.getEntityType().name(), |
78 | relationType, | 76 | relationType, |
79 | typeGroup.name()))); | 77 | typeGroup.name()))); |
@@ -83,7 +81,7 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple | @@ -83,7 +81,7 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple | ||
83 | public ListenableFuture<List<EntityRelation>> findAllByTo(TenantId tenantId, EntityId to, RelationTypeGroup typeGroup) { | 81 | public ListenableFuture<List<EntityRelation>> findAllByTo(TenantId tenantId, EntityId to, RelationTypeGroup typeGroup) { |
84 | return service.submit(() -> DaoUtil.convertDataList( | 82 | return service.submit(() -> DaoUtil.convertDataList( |
85 | relationRepository.findAllByToIdAndToTypeAndRelationTypeGroup( | 83 | relationRepository.findAllByToIdAndToTypeAndRelationTypeGroup( |
86 | - UUIDConverter.fromTimeUUID(to.getId()), | 84 | + to.getId(), |
87 | to.getEntityType().name(), | 85 | to.getEntityType().name(), |
88 | typeGroup.name()))); | 86 | typeGroup.name()))); |
89 | } | 87 | } |
@@ -92,7 +90,7 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple | @@ -92,7 +90,7 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple | ||
92 | public ListenableFuture<List<EntityRelation>> findAllByToAndType(TenantId tenantId, EntityId to, String relationType, RelationTypeGroup typeGroup) { | 90 | public ListenableFuture<List<EntityRelation>> findAllByToAndType(TenantId tenantId, EntityId to, String relationType, RelationTypeGroup typeGroup) { |
93 | return service.submit(() -> DaoUtil.convertDataList( | 91 | return service.submit(() -> DaoUtil.convertDataList( |
94 | relationRepository.findAllByToIdAndToTypeAndRelationTypeAndRelationTypeGroup( | 92 | relationRepository.findAllByToIdAndToTypeAndRelationTypeAndRelationTypeGroup( |
95 | - UUIDConverter.fromTimeUUID(to.getId()), | 93 | + to.getId(), |
96 | to.getEntityType().name(), | 94 | to.getEntityType().name(), |
97 | relationType, | 95 | relationType, |
98 | typeGroup.name()))); | 96 | typeGroup.name()))); |
@@ -111,9 +109,9 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple | @@ -111,9 +109,9 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple | ||
111 | } | 109 | } |
112 | 110 | ||
113 | private RelationCompositeKey getRelationCompositeKey(EntityId from, EntityId to, String relationType, RelationTypeGroup typeGroup) { | 111 | private RelationCompositeKey getRelationCompositeKey(EntityId from, EntityId to, String relationType, RelationTypeGroup typeGroup) { |
114 | - return new RelationCompositeKey(fromTimeUUID(from.getId()), | 112 | + return new RelationCompositeKey(from.getId(), |
115 | from.getEntityType().name(), | 113 | from.getEntityType().name(), |
116 | - fromTimeUUID(to.getId()), | 114 | + to.getId(), |
117 | to.getEntityType().name(), | 115 | to.getEntityType().name(), |
118 | relationType, | 116 | relationType, |
119 | typeGroup.name()); | 117 | typeGroup.name()); |
@@ -166,10 +164,10 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple | @@ -166,10 +164,10 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple | ||
166 | @Override | 164 | @Override |
167 | public boolean deleteOutboundRelations(TenantId tenantId, EntityId entity) { | 165 | public boolean deleteOutboundRelations(TenantId tenantId, EntityId entity) { |
168 | boolean relationExistsBeforeDelete = relationRepository | 166 | boolean relationExistsBeforeDelete = relationRepository |
169 | - .findAllByFromIdAndFromType(UUIDConverter.fromTimeUUID(entity.getId()), entity.getEntityType().name()) | 167 | + .findAllByFromIdAndFromType(entity.getId(), entity.getEntityType().name()) |
170 | .size() > 0; | 168 | .size() > 0; |
171 | if (relationExistsBeforeDelete) { | 169 | if (relationExistsBeforeDelete) { |
172 | - relationRepository.deleteByFromIdAndFromType(UUIDConverter.fromTimeUUID(entity.getId()), entity.getEntityType().name()); | 170 | + relationRepository.deleteByFromIdAndFromType(entity.getId(), entity.getEntityType().name()); |
173 | } | 171 | } |
174 | return relationExistsBeforeDelete; | 172 | return relationExistsBeforeDelete; |
175 | } | 173 | } |
@@ -179,33 +177,20 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple | @@ -179,33 +177,20 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple | ||
179 | return service.submit( | 177 | return service.submit( |
180 | () -> { | 178 | () -> { |
181 | boolean relationExistsBeforeDelete = relationRepository | 179 | boolean relationExistsBeforeDelete = relationRepository |
182 | - .findAllByFromIdAndFromType(UUIDConverter.fromTimeUUID(entity.getId()), entity.getEntityType().name()) | 180 | + .findAllByFromIdAndFromType(entity.getId(), entity.getEntityType().name()) |
183 | .size() > 0; | 181 | .size() > 0; |
184 | if (relationExistsBeforeDelete) { | 182 | if (relationExistsBeforeDelete) { |
185 | - relationRepository.deleteByFromIdAndFromType(UUIDConverter.fromTimeUUID(entity.getId()), entity.getEntityType().name()); | 183 | + relationRepository.deleteByFromIdAndFromType(entity.getId(), entity.getEntityType().name()); |
186 | } | 184 | } |
187 | return relationExistsBeforeDelete; | 185 | return relationExistsBeforeDelete; |
188 | }); | 186 | }); |
189 | } | 187 | } |
190 | 188 | ||
191 | - @Override | ||
192 | - public ListenableFuture<PageData<EntityRelation>> findRelations(TenantId tenantId, EntityId from, String relationType, RelationTypeGroup typeGroup, EntityType childType, TimePageLink pageLink) { | ||
193 | - Specification<RelationEntity> timeSearchSpec = JpaAbstractSearchTimeDao.getTimeSearchPageSpec(pageLink, "toId"); | ||
194 | - Specification<RelationEntity> fieldsSpec = getEntityFieldsSpec(from, relationType, typeGroup, childType); | ||
195 | - Sort.Direction sortDirection = Sort.Direction.DESC; | ||
196 | - if (pageLink.getSortOrder() != null) { | ||
197 | - sortDirection = pageLink.getSortOrder().getDirection() == SortOrder.Direction.ASC ? Sort.Direction.ASC : Sort.Direction.DESC; | ||
198 | - } | ||
199 | - Pageable pageable = PageRequest.of(pageLink.getPage(), pageLink.getPageSize(), sortDirection, "toId"); | ||
200 | - return service.submit(() -> | ||
201 | - DaoUtil.toPageData(relationRepository.findAll(Specification.where(timeSearchSpec).and(fieldsSpec), pageable))); | ||
202 | - } | ||
203 | - | ||
204 | private Specification<RelationEntity> getEntityFieldsSpec(EntityId from, String relationType, RelationTypeGroup typeGroup, EntityType childType) { | 189 | private Specification<RelationEntity> getEntityFieldsSpec(EntityId from, String relationType, RelationTypeGroup typeGroup, EntityType childType) { |
205 | return (root, criteriaQuery, criteriaBuilder) -> { | 190 | return (root, criteriaQuery, criteriaBuilder) -> { |
206 | List<Predicate> predicates = new ArrayList<>(); | 191 | List<Predicate> predicates = new ArrayList<>(); |
207 | if (from != null) { | 192 | if (from != null) { |
208 | - Predicate fromIdPredicate = criteriaBuilder.equal(root.get("fromId"), UUIDConverter.fromTimeUUID(from.getId())); | 193 | + Predicate fromIdPredicate = criteriaBuilder.equal(root.get("fromId"), from.getId()); |
209 | predicates.add(fromIdPredicate); | 194 | predicates.add(fromIdPredicate); |
210 | Predicate fromEntityTypePredicate = criteriaBuilder.equal(root.get("fromType"), from.getEntityType().name()); | 195 | Predicate fromEntityTypePredicate = criteriaBuilder.equal(root.get("fromType"), from.getEntityType().name()); |
211 | predicates.add(fromEntityTypePredicate); | 196 | predicates.add(fromEntityTypePredicate); |