Commit 004cc216d265f42db91e971ad7379ba0bd082820

Authored by Andrii Shvaika
Committed by Andrew Shvayka
1 parent 2aaa51fe

Refactoing of UUIDs storage

Showing 100 changed files with 787 additions and 572 deletions

Too many changes to show.

To preserve performance only 100 of 129 files are displayed.

... ... @@ -22,37 +22,37 @@ BEGIN
22 22 END;
23 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 26 OUT deleted bigint) AS
27 27 $$
28 28 BEGIN
29 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 31 tenant_id, customer_id, ttl) into deleted;
32 32 END;
33 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 36 OUT deleted bigint) AS
37 37 $$
38 38 BEGIN
39 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 41 tenant_id, customer_id, ttl) into deleted;
42 42 END;
43 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 46 OUT deleted bigint) AS
47 47 $$
48 48 BEGIN
49 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 51 tenant_id, customer_id, ttl) into deleted;
52 52 END;
53 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 56 IN system_ttl bigint, INOUT deleted bigint)
57 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 15 */
16 16 package org.thingsboard.server.service.subscription;
17 17
  18 +import com.google.common.util.concurrent.FutureCallback;
18 19 import com.google.common.util.concurrent.Futures;
19 20 import com.google.common.util.concurrent.ListenableFuture;
  21 +import com.google.common.util.concurrent.MoreExecutors;
20 22 import lombok.extern.slf4j.Slf4j;
  23 +import org.checkerframework.checker.nullness.qual.Nullable;
21 24 import org.springframework.beans.factory.annotation.Autowired;
  25 +import org.springframework.beans.factory.annotation.Value;
22 26 import org.springframework.context.annotation.Lazy;
23 27 import org.springframework.context.event.EventListener;
24 28 import org.springframework.stereotype.Service;
... ... @@ -33,6 +37,8 @@ import org.thingsboard.server.common.data.kv.TsKvEntry;
33 37 import org.thingsboard.server.common.data.page.PageData;
34 38 import org.thingsboard.server.common.data.query.EntityData;
35 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 42 import org.thingsboard.server.common.data.query.TsValue;
37 43 import org.thingsboard.server.common.msg.queue.ServiceType;
38 44 import org.thingsboard.server.common.msg.queue.TbCallback;
... ... @@ -53,6 +59,7 @@ import org.thingsboard.server.service.telemetry.cmd.v2.EntityDataUpdate;
53 59 import org.thingsboard.server.service.telemetry.cmd.v2.EntityHistoryCmd;
54 60 import org.thingsboard.server.service.telemetry.cmd.v2.LatestValueCmd;
55 61 import org.thingsboard.server.service.telemetry.cmd.v2.TimeSeriesCmd;
  62 +import org.thingsboard.server.service.telemetry.sub.SubscriptionErrorCode;
56 63 import org.thingsboard.server.service.telemetry.sub.SubscriptionUpdate;
57 64
58 65 import javax.annotation.PostConstruct;
... ... @@ -60,6 +67,7 @@ import javax.annotation.PreDestroy;
60 67 import java.util.ArrayList;
61 68 import java.util.HashMap;
62 69 import java.util.LinkedHashMap;
  70 +import java.util.LinkedHashSet;
63 71 import java.util.List;
64 72 import java.util.Map;
65 73 import java.util.Set;
... ... @@ -67,7 +75,6 @@ import java.util.concurrent.ConcurrentHashMap;
67 75 import java.util.concurrent.ExecutionException;
68 76 import java.util.concurrent.ExecutorService;
69 77 import java.util.concurrent.Executors;
70   -import java.util.function.Function;
71 78 import java.util.stream.Collectors;
72 79
73 80 @Slf4j
... ... @@ -101,11 +108,16 @@ public class DefaultTbEntityDataSubscriptionService implements TbEntityDataSubsc
101 108 @Autowired
102 109 private TimeseriesService tsService;
103 110
  111 + @Value("${database.ts.type}")
  112 + private String databaseTsType;
  113 +
104 114 private ExecutorService wsCallBackExecutor;
  115 + private boolean tsInSqlDB;
105 116
106 117 @PostConstruct
107 118 public void initExecutor() {
108 119 wsCallBackExecutor = Executors.newSingleThreadExecutor(ThingsBoardThreadFactory.forName("ws-entity-sub-callback"));
  120 + tsInSqlDB = databaseTsType.equalsIgnoreCase("sql") || databaseTsType.equalsIgnoreCase("timescale");
109 121 }
110 122
111 123 @PreDestroy
... ... @@ -156,7 +168,70 @@ public class DefaultTbEntityDataSubscriptionService implements TbEntityDataSubsc
156 168 }
157 169
158 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 237 private void handleHistoryCmd(TelemetryWebSocketSessionRef session, int cmdId, EntityDataQuery query, EntityHistoryCmd historyCmd) {
... ... @@ -181,6 +256,8 @@ public class DefaultTbEntityDataSubscriptionService implements TbEntityDataSubsc
181 256 keyData.forEach((k, v) -> entityData.getTimeseries().put(k, v.toArray(new TsValue[v.size()])));
182 257 } catch (InterruptedException | ExecutionException e) {
183 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 263 EntityDataUpdate update = new EntityDataUpdate(cmdId, data, null);
... ...
... ... @@ -15,18 +15,30 @@
15 15 */
16 16 package org.thingsboard.server.service.telemetry.cmd.v2;
17 17
  18 +import lombok.AllArgsConstructor;
18 19 import lombok.Data;
19 20 import org.thingsboard.server.common.data.page.PageData;
20 21 import org.thingsboard.server.common.data.query.EntityData;
  22 +import org.thingsboard.server.service.telemetry.sub.SubscriptionErrorCode;
21 23
22 24 import java.util.List;
23 25
24 26 @Data
  27 +@AllArgsConstructor
25 28 public class EntityDataUpdate {
26 29
27 30 private final int cmdId;
28 31 private final PageData<EntityData> data;
29 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 35 protected void doCleanUp(Connection connection) {
36 36 long totalPartitionsRemoved = executeQuery(connection, "call drop_partitions_by_max_ttl('" + partitionType + "'," + systemTtl + ", 0);");
37 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 39 log.info("Total telemetry removed stats by TTL for entities: [{}]", totalEntitiesTelemetryRemoved);
40 40 }
41 41 }
\ No newline at end of file
... ...
... ... @@ -29,7 +29,7 @@ public class TimescaleTimeseriesCleanUpService extends AbstractTimeseriesCleanUp
29 29
30 30 @Override
31 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 33 log.info("Total telemetry removed stats by TTL for entities: [{}]", totalEntitiesTelemetryRemoved);
34 34 }
35 35 }
\ No newline at end of file
... ...
... ... @@ -18,6 +18,7 @@ package org.thingsboard.server.controller;
18 18 import org.junit.After;
19 19 import org.junit.Assert;
20 20 import org.junit.Before;
  21 +import org.junit.Ignore;
21 22 import org.junit.Test;
22 23 import org.springframework.beans.factory.annotation.Autowired;
23 24 import org.thingsboard.server.common.data.Device;
... ... @@ -32,6 +33,8 @@ import org.thingsboard.server.common.data.query.DeviceTypeFilter;
32 33 import org.thingsboard.server.common.data.query.EntityData;
33 34 import org.thingsboard.server.common.data.query.EntityDataPageLink;
34 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 38 import org.thingsboard.server.common.data.query.TsValue;
36 39 import org.thingsboard.server.common.data.security.Authority;
37 40 import org.thingsboard.server.dao.timeseries.TimeseriesService;
... ... @@ -39,6 +42,7 @@ import org.thingsboard.server.service.telemetry.cmd.TelemetryPluginCmdsWrapper;
39 42 import org.thingsboard.server.service.telemetry.cmd.v2.EntityDataCmd;
40 43 import org.thingsboard.server.service.telemetry.cmd.v2.EntityDataUpdate;
41 44 import org.thingsboard.server.service.telemetry.cmd.v2.EntityHistoryCmd;
  45 +import org.thingsboard.server.service.telemetry.cmd.v2.LatestValueCmd;
42 46
43 47 import java.util.Arrays;
44 48 import java.util.Collections;
... ... @@ -142,4 +146,58 @@ public class BaseWebsocketApiTest extends AbstractWebsocketTest {
142 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 15 */
16 16 package org.thingsboard.server.controller.sql;
17 17
18   -import org.thingsboard.server.controller.BaseEntityQueryControllerTest;
19 18 import org.thingsboard.server.controller.BaseWebsocketApiTest;
20 19 import org.thingsboard.server.dao.service.DaoSqlTest;
21 20
... ...
... ... @@ -15,16 +15,8 @@
15 15 */
16 16 package org.thingsboard.server.common.data.page;
17 17
18   -import com.fasterxml.jackson.annotation.JsonCreator;
19 18 import com.fasterxml.jackson.annotation.JsonIgnore;
20   -import com.fasterxml.jackson.annotation.JsonProperty;
21 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 21 @Data
30 22 public class TimePageLink extends PageLink {
... ...
... ... @@ -21,8 +21,11 @@ import org.junit.Test;
21 21 import org.junit.runner.RunWith;
22 22 import org.mockito.runners.MockitoJUnitRunner;
23 23
  24 +import java.util.ArrayList;
  25 +import java.util.Arrays;
24 26 import java.util.Random;
25 27 import java.util.UUID;
  28 +import java.util.stream.Collectors;
26 29
27 30 /**
28 31 * Created by ashvayka on 14.07.17.
... ... @@ -37,6 +40,18 @@ public class UUIDConverterTest {
37 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 55 @Test
41 56 public void basicStringToUUIDTest() {
42 57 UUID result = UUIDConverter.fromString("1d8eebc58e0a7d796690800200c9a66");
... ...
... ... @@ -27,7 +27,13 @@ import org.thingsboard.server.common.data.page.PageLink;
27 27 import org.thingsboard.server.common.data.page.SortOrder;
28 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 38 public abstract class DaoUtil {
33 39
... ... @@ -77,9 +83,6 @@ public abstract class DaoUtil {
77 83 if (columnMap.containsKey(property)) {
78 84 property = columnMap.get(property);
79 85 }
80   - if (property.equals("createdTime")) {
81   - property = "id";
82   - }
83 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 24 import org.thingsboard.server.common.data.page.PageData;
25 25 import org.thingsboard.server.dao.Dao;
26 26
27   -import java.util.List;
28 27 import java.util.UUID;
29 28
30 29 /**
... ...
... ... @@ -29,12 +29,12 @@ import org.springframework.util.StringUtils;
29 29 import org.thingsboard.common.util.ThingsBoardThreadFactory;
30 30 import org.thingsboard.server.common.data.Tenant;
31 31 import org.thingsboard.server.common.data.alarm.Alarm;
32   -import org.thingsboard.server.common.data.id.AlarmId;
33 32 import org.thingsboard.server.common.data.alarm.AlarmInfo;
34 33 import org.thingsboard.server.common.data.alarm.AlarmQuery;
35 34 import org.thingsboard.server.common.data.alarm.AlarmSearchStatus;
36 35 import org.thingsboard.server.common.data.alarm.AlarmSeverity;
37 36 import org.thingsboard.server.common.data.alarm.AlarmStatus;
  37 +import org.thingsboard.server.common.data.id.AlarmId;
38 38 import org.thingsboard.server.common.data.id.EntityId;
39 39 import org.thingsboard.server.common.data.id.TenantId;
40 40 import org.thingsboard.server.common.data.page.PageData;
... ...
... ... @@ -28,7 +28,6 @@ import org.springframework.beans.factory.annotation.Autowired;
28 28 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
29 29 import org.springframework.stereotype.Service;
30 30 import org.springframework.util.StringUtils;
31   -import org.thingsboard.server.common.data.BaseData;
32 31 import org.thingsboard.server.common.data.EntityType;
33 32 import org.thingsboard.server.common.data.HasName;
34 33 import org.thingsboard.server.common.data.audit.ActionStatus;
... ... @@ -38,7 +37,6 @@ import org.thingsboard.server.common.data.id.AuditLogId;
38 37 import org.thingsboard.server.common.data.id.CustomerId;
39 38 import org.thingsboard.server.common.data.id.EntityId;
40 39 import org.thingsboard.server.common.data.id.TenantId;
41   -import org.thingsboard.server.common.data.id.UUIDBased;
42 40 import org.thingsboard.server.common.data.id.UserId;
43 41 import org.thingsboard.server.common.data.kv.AttributeKvEntry;
44 42 import org.thingsboard.server.common.data.page.PageData;
... ...
... ... @@ -18,14 +18,12 @@ package org.thingsboard.server.dao.audit;
18 18 import com.google.common.util.concurrent.ListenableFuture;
19 19 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
20 20 import org.springframework.stereotype.Service;
21   -import org.thingsboard.server.common.data.BaseData;
22 21 import org.thingsboard.server.common.data.HasName;
23 22 import org.thingsboard.server.common.data.audit.ActionType;
24 23 import org.thingsboard.server.common.data.audit.AuditLog;
25 24 import org.thingsboard.server.common.data.id.CustomerId;
26 25 import org.thingsboard.server.common.data.id.EntityId;
27 26 import org.thingsboard.server.common.data.id.TenantId;
28   -import org.thingsboard.server.common.data.id.UUIDBased;
29 27 import org.thingsboard.server.common.data.id.UserId;
30 28 import org.thingsboard.server.common.data.page.PageData;
31 29 import org.thingsboard.server.common.data.page.TimePageLink;
... ...
... ... @@ -37,7 +37,6 @@ import org.thingsboard.server.dao.exception.IncorrectParameterException;
37 37 import org.thingsboard.server.dao.service.DataValidator;
38 38 import org.thingsboard.server.dao.service.Validator;
39 39
40   -import java.util.List;
41 40 import java.util.Optional;
42 41
43 42 /**
... ...
... ... @@ -24,7 +24,6 @@ import org.thingsboard.server.common.data.plugin.ComponentScope;
24 24 import org.thingsboard.server.common.data.plugin.ComponentType;
25 25 import org.thingsboard.server.dao.Dao;
26 26
27   -import java.util.List;
28 27 import java.util.Optional;
29 28
30 29 /**
... ...
... ... @@ -21,7 +21,6 @@ import org.thingsboard.server.common.data.page.PageData;
21 21 import org.thingsboard.server.common.data.page.PageLink;
22 22 import org.thingsboard.server.dao.Dao;
23 23
24   -import java.util.List;
25 24 import java.util.Optional;
26 25 import java.util.UUID;
27 26
... ...
... ... @@ -42,7 +42,6 @@ import org.thingsboard.server.dao.tenant.TenantDao;
42 42 import org.thingsboard.server.dao.user.UserService;
43 43
44 44 import java.io.IOException;
45   -import java.util.List;
46 45 import java.util.Optional;
47 46
48 47 import static org.thingsboard.server.dao.service.Validator.validateId;
... ...
... ... @@ -15,14 +15,11 @@
15 15 */
16 16 package org.thingsboard.server.dao.dashboard;
17 17
18   -import com.google.common.util.concurrent.ListenableFuture;
19 18 import org.thingsboard.server.common.data.DashboardInfo;
20 19 import org.thingsboard.server.common.data.page.PageData;
21 20 import org.thingsboard.server.common.data.page.PageLink;
22   -import org.thingsboard.server.common.data.page.TimePageLink;
23 21 import org.thingsboard.server.dao.Dao;
24 22
25   -import java.util.List;
26 23 import java.util.UUID;
27 24
28 25 /**
... ...
... ... @@ -29,7 +29,12 @@ import org.springframework.cache.annotation.CacheEvict;
29 29 import org.springframework.cache.annotation.Cacheable;
30 30 import org.springframework.cache.annotation.Caching;
31 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 38 import org.thingsboard.server.common.data.entityview.EntityViewSearchQuery;
34 39 import org.thingsboard.server.common.data.id.CustomerId;
35 40 import org.thingsboard.server.common.data.id.EntityId;
... ...
... ... @@ -23,4 +23,8 @@ public interface BaseEntity<D> extends ToData<D> {
23 23
24 24 void setUuid(UUID id);
25 25
  26 + long getCreatedTime();
  27 +
  28 + void setCreatedTime(long createdTime);
  29 +
26 30 }
... ...
... ... @@ -16,7 +16,6 @@
16 16 package org.thingsboard.server.dao.model;
17 17
18 18 import lombok.Data;
19   -import org.thingsboard.server.common.data.UUIDConverter;
20 19
21 20 import javax.persistence.Column;
22 21 import javax.persistence.Id;
... ... @@ -31,28 +30,30 @@ import java.util.UUID;
31 30 public abstract class BaseSqlEntity<D> implements BaseEntity<D> {
32 31
33 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 39 @Override
38 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 44 @Override
46 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 17
18 18 import com.datastax.oss.driver.api.core.uuid.Uuids;
19 19 import org.apache.commons.lang3.ArrayUtils;
20   -import org.thingsboard.server.common.data.UUIDConverter;
21 20 import org.thingsboard.server.common.data.id.TenantId;
22 21 import org.thingsboard.server.common.data.kv.Aggregation;
23 22
... ... @@ -29,7 +28,6 @@ public class ModelConstants {
29 28 }
30 29
31 30 public static final UUID NULL_UUID = Uuids.startOf(0);
32   - public static final String NULL_UUID_STR = UUIDConverter.fromTimeUUID(NULL_UUID);
33 31 public static final TenantId SYSTEM_TENANT = new TenantId(ModelConstants.NULL_UUID);
34 32
35 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 37 * Generic constants.
40 38 */
41 39 public static final String ID_PROPERTY = "id";
  40 + public static final String CREATED_TIME_PROPERTY = "created_time";
42 41 public static final String USER_ID_PROPERTY = "user_id";
43 42 public static final String TENANT_ID_PROPERTY = "tenant_id";
44 43 public static final String CUSTOMER_ID_PROPERTY = "customer_id";
... ...
... ... @@ -15,7 +15,6 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.oss.driver.api.core.uuid.Uuids;
19 18 import com.fasterxml.jackson.databind.JsonNode;
20 19 import lombok.Data;
21 20 import lombok.EqualsAndHashCode;
... ... @@ -24,11 +23,10 @@ import org.hibernate.annotations.TypeDef;
24 23 import org.springframework.util.CollectionUtils;
25 24 import org.springframework.util.StringUtils;
26 25 import org.thingsboard.server.common.data.EntityType;
27   -import org.thingsboard.server.common.data.UUIDConverter;
28 26 import org.thingsboard.server.common.data.alarm.Alarm;
29   -import org.thingsboard.server.common.data.id.AlarmId;
30 27 import org.thingsboard.server.common.data.alarm.AlarmSeverity;
31 28 import org.thingsboard.server.common.data.alarm.AlarmStatus;
  29 +import org.thingsboard.server.common.data.id.AlarmId;
32 30 import org.thingsboard.server.common.data.id.EntityIdFactory;
33 31 import org.thingsboard.server.common.data.id.TenantId;
34 32 import org.thingsboard.server.dao.model.BaseEntity;
... ... @@ -42,6 +40,7 @@ import javax.persistence.Enumerated;
42 40 import javax.persistence.MappedSuperclass;
43 41 import java.util.Arrays;
44 42 import java.util.Collections;
  43 +import java.util.UUID;
45 44
46 45 import static org.thingsboard.server.dao.model.ModelConstants.ALARM_ACK_TS_PROPERTY;
47 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 62 public abstract class AbstractAlarmEntity<T extends Alarm> extends BaseSqlEntity<T> implements BaseEntity<T> {
64 63
65 64 @Column(name = ALARM_TENANT_ID_PROPERTY)
66   - private String tenantId;
  65 + private UUID tenantId;
67 66
68 67 @Column(name = ALARM_ORIGINATOR_ID_PROPERTY)
69   - private String originatorId;
  68 + private UUID originatorId;
70 69
71 70 @Column(name = ALARM_ORIGINATOR_TYPE_PROPERTY)
72 71 private EntityType originatorType;
... ... @@ -110,13 +109,14 @@ public abstract class AbstractAlarmEntity<T extends Alarm> extends BaseSqlEntity
110 109
111 110 public AbstractAlarmEntity(Alarm alarm) {
112 111 if (alarm.getId() != null) {
113   - this.setUuid(alarm.getId().getId());
  112 + this.setUuid(alarm.getUuidId());
114 113 }
  114 + this.setCreatedTime(alarm.getCreatedTime());
115 115 if (alarm.getTenantId() != null) {
116   - this.tenantId = UUIDConverter.fromTimeUUID(alarm.getTenantId().getId());
  116 + this.tenantId = alarm.getTenantId().getId();
117 117 }
118 118 this.type = alarm.getType();
119   - this.originatorId = UUIDConverter.fromTimeUUID(alarm.getOriginator().getId());
  119 + this.originatorId = alarm.getOriginator().getId();
120 120 this.originatorType = alarm.getOriginator().getEntityType();
121 121 this.type = alarm.getType();
122 122 this.severity = alarm.getSeverity();
... ... @@ -153,12 +153,12 @@ public abstract class AbstractAlarmEntity<T extends Alarm> extends BaseSqlEntity
153 153 }
154 154
155 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 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 162 alarm.setType(type);
163 163 alarm.setSeverity(severity);
164 164 alarm.setStatus(status);
... ...
... ... @@ -15,13 +15,11 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.oss.driver.api.core.uuid.Uuids;
19 18 import com.fasterxml.jackson.databind.JsonNode;
20 19 import lombok.Data;
21 20 import lombok.EqualsAndHashCode;
22 21 import org.hibernate.annotations.Type;
23 22 import org.hibernate.annotations.TypeDef;
24   -import org.thingsboard.server.common.data.UUIDConverter;
25 23 import org.thingsboard.server.common.data.asset.Asset;
26 24 import org.thingsboard.server.common.data.id.AssetId;
27 25 import org.thingsboard.server.common.data.id.CustomerId;
... ... @@ -33,6 +31,7 @@ import org.thingsboard.server.dao.util.mapping.JsonStringType;
33 31
34 32 import javax.persistence.Column;
35 33 import javax.persistence.MappedSuperclass;
  34 +import java.util.UUID;
36 35
37 36 import static org.thingsboard.server.dao.model.ModelConstants.ASSET_CUSTOMER_ID_PROPERTY;
38 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 47 public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity<T> implements SearchTextEntity<T> {
49 48
50 49 @Column(name = ASSET_TENANT_ID_PROPERTY)
51   - private String tenantId;
  50 + private UUID tenantId;
52 51
53 52 @Column(name = ASSET_CUSTOMER_ID_PROPERTY)
54   - private String customerId;
  53 + private UUID customerId;
55 54
56 55 @Column(name = ASSET_NAME_PROPERTY)
57 56 private String name;
... ... @@ -77,11 +76,12 @@ public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity
77 76 if (asset.getId() != null) {
78 77 this.setUuid(asset.getId().getId());
79 78 }
  79 + this.setCreatedTime(asset.getCreatedTime());
80 80 if (asset.getTenantId() != null) {
81   - this.tenantId = UUIDConverter.fromTimeUUID(asset.getTenantId().getId());
  81 + this.tenantId = asset.getTenantId().getId();
82 82 }
83 83 if (asset.getCustomerId() != null) {
84   - this.customerId = UUIDConverter.fromTimeUUID(asset.getCustomerId().getId());
  84 + this.customerId = asset.getCustomerId().getId();
85 85 }
86 86 this.name = asset.getName();
87 87 this.type = asset.getType();
... ... @@ -91,6 +91,7 @@ public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity
91 91
92 92 public AbstractAssetEntity(AssetEntity assetEntity) {
93 93 this.setId(assetEntity.getId());
  94 + this.setCreatedTime(assetEntity.getCreatedTime());
94 95 this.tenantId = assetEntity.getTenantId();
95 96 this.customerId = assetEntity.getCustomerId();
96 97 this.type = assetEntity.getType();
... ... @@ -115,13 +116,13 @@ public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity
115 116 }
116 117
117 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 121 if (tenantId != null) {
121   - asset.setTenantId(new TenantId(UUIDConverter.fromString(tenantId)));
  122 + asset.setTenantId(new TenantId(tenantId));
122 123 }
123 124 if (customerId != null) {
124   - asset.setCustomerId(new CustomerId(UUIDConverter.fromString(customerId)));
  125 + asset.setCustomerId(new CustomerId(customerId));
125 126 }
126 127 asset.setName(name);
127 128 asset.setType(type);
... ...
... ... @@ -15,7 +15,6 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.oss.driver.api.core.uuid.Uuids;
19 18 import com.fasterxml.jackson.databind.JsonNode;
20 19 import lombok.Data;
21 20 import lombok.EqualsAndHashCode;
... ... @@ -32,6 +31,7 @@ import org.thingsboard.server.dao.util.mapping.JsonStringType;
32 31
33 32 import javax.persistence.Column;
34 33 import javax.persistence.MappedSuperclass;
  34 +import java.util.UUID;
35 35
36 36 @Data
37 37 @EqualsAndHashCode(callSuper = true)
... ... @@ -39,11 +39,11 @@ import javax.persistence.MappedSuperclass;
39 39 @MappedSuperclass
40 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 48 @Column(name = ModelConstants.DEVICE_TYPE_PROPERTY)
49 49 private String type;
... ... @@ -67,13 +67,14 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseSqlEnti
67 67
68 68 public AbstractDeviceEntity(Device device) {
69 69 if (device.getId() != null) {
70   - this.setUuid(device.getId().getId());
  70 + this.setUuid(device.getUuidId());
71 71 }
  72 + this.setCreatedTime(device.getCreatedTime());
72 73 if (device.getTenantId() != null) {
73   - this.tenantId = toString(device.getTenantId().getId());
  74 + this.tenantId = device.getTenantId().getId();
74 75 }
75 76 if (device.getCustomerId() != null) {
76   - this.customerId = toString(device.getCustomerId().getId());
  77 + this.customerId = device.getCustomerId().getId();
77 78 }
78 79 this.name = device.getName();
79 80 this.type = device.getType();
... ... @@ -83,6 +84,7 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseSqlEnti
83 84
84 85 public AbstractDeviceEntity(DeviceEntity deviceEntity) {
85 86 this.setId(deviceEntity.getId());
  87 + this.setCreatedTime(deviceEntity.getCreatedTime());
86 88 this.tenantId = deviceEntity.getTenantId();
87 89 this.customerId = deviceEntity.getCustomerId();
88 90 this.type = deviceEntity.getType();
... ... @@ -104,12 +106,12 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseSqlEnti
104 106
105 107 protected Device toDevice() {
106 108 Device device = new Device(new DeviceId(getUuid()));
107   - device.setCreatedTime(Uuids.unixTimestamp(getUuid()));
  109 + device.setCreatedTime(createdTime);
108 110 if (tenantId != null) {
109   - device.setTenantId(new TenantId(toUUID(tenantId)));
  111 + device.setTenantId(new TenantId(tenantId));
110 112 }
111 113 if (customerId != null) {
112   - device.setCustomerId(new CustomerId(toUUID(customerId)));
  114 + device.setCustomerId(new CustomerId(customerId));
113 115 }
114 116 device.setName(name);
115 117 device.setType(type);
... ...
... ... @@ -15,7 +15,6 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.oss.driver.api.core.uuid.Uuids;
19 18 import com.fasterxml.jackson.databind.JsonNode;
20 19 import com.fasterxml.jackson.databind.ObjectMapper;
21 20 import lombok.Data;
... ... @@ -35,7 +34,10 @@ import org.thingsboard.server.dao.model.ModelConstants;
35 34 import org.thingsboard.server.dao.model.SearchTextEntity;
36 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 41 import java.io.IOException;
40 42 import java.util.UUID;
41 43
... ... @@ -53,17 +55,17 @@ import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_TYPE_PROPER
53 55 public abstract class AbstractEntityViewEntity<T extends EntityView> extends BaseSqlEntity<T> implements SearchTextEntity<T> {
54 56
55 57 @Column(name = ModelConstants.ENTITY_VIEW_ENTITY_ID_PROPERTY)
56   - private String entityId;
  58 + private UUID entityId;
57 59
58 60 @Enumerated(EnumType.STRING)
59 61 @Column(name = ENTITY_TYPE_PROPERTY)
60 62 private EntityType entityType;
61 63
62 64 @Column(name = ModelConstants.ENTITY_VIEW_TENANT_ID_PROPERTY)
63   - private String tenantId;
  65 + private UUID tenantId;
64 66
65 67 @Column(name = ModelConstants.ENTITY_VIEW_CUSTOMER_ID_PROPERTY)
66   - private String customerId;
  68 + private UUID customerId;
67 69
68 70 @Column(name = ModelConstants.DEVICE_TYPE_PROPERTY)
69 71 private String type;
... ... @@ -97,15 +99,16 @@ public abstract class AbstractEntityViewEntity<T extends EntityView> extends Bas
97 99 if (entityView.getId() != null) {
98 100 this.setUuid(entityView.getId().getId());
99 101 }
  102 + this.setCreatedTime(entityView.getCreatedTime());
100 103 if (entityView.getEntityId() != null) {
101   - this.entityId = toString(entityView.getEntityId().getId());
  104 + this.entityId = entityView.getEntityId().getId();
102 105 this.entityType = entityView.getEntityId().getEntityType();
103 106 }
104 107 if (entityView.getTenantId() != null) {
105   - this.tenantId = toString(entityView.getTenantId().getId());
  108 + this.tenantId = entityView.getTenantId().getId();
106 109 }
107 110 if (entityView.getCustomerId() != null) {
108   - this.customerId = toString(entityView.getCustomerId().getId());
  111 + this.customerId = entityView.getCustomerId().getId();
109 112 }
110 113 this.type = entityView.getType();
111 114 this.name = entityView.getName();
... ... @@ -122,6 +125,7 @@ public abstract class AbstractEntityViewEntity<T extends EntityView> extends Bas
122 125
123 126 public AbstractEntityViewEntity(EntityViewEntity entityViewEntity) {
124 127 this.setId(entityViewEntity.getId());
  128 + this.setCreatedTime(entityViewEntity.getCreatedTime());
125 129 this.entityId = entityViewEntity.getEntityId();
126 130 this.entityType = entityViewEntity.getEntityType();
127 131 this.tenantId = entityViewEntity.getTenantId();
... ... @@ -147,16 +151,16 @@ public abstract class AbstractEntityViewEntity<T extends EntityView> extends Bas
147 151
148 152 protected EntityView toEntityView() {
149 153 EntityView entityView = new EntityView(new EntityViewId(getUuid()));
150   - entityView.setCreatedTime(Uuids.unixTimestamp(getUuid()));
  154 + entityView.setCreatedTime(createdTime);
151 155
152 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 159 if (tenantId != null) {
156   - entityView.setTenantId(new TenantId(toUUID(tenantId)));
  160 + entityView.setTenantId(new TenantId(tenantId));
157 161 }
158 162 if (customerId != null) {
159   - entityView.setCustomerId(new CustomerId(toUUID(customerId)));
  163 + entityView.setCustomerId(new CustomerId(customerId));
160 164 }
161 165 entityView.setType(type);
162 166 entityView.setName(name);
... ...
... ... @@ -15,14 +15,12 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.oss.driver.api.core.uuid.Uuids;
19 18 import com.fasterxml.jackson.databind.JsonNode;
20 19 import lombok.Data;
21 20 import lombok.EqualsAndHashCode;
22 21 import org.hibernate.annotations.Type;
23 22 import org.hibernate.annotations.TypeDef;
24 23 import org.thingsboard.server.common.data.AdminSettings;
25   -import org.thingsboard.server.common.data.UUIDConverter;
26 24 import org.thingsboard.server.common.data.id.AdminSettingsId;
27 25 import org.thingsboard.server.dao.model.BaseEntity;
28 26 import org.thingsboard.server.dao.model.BaseSqlEntity;
... ... @@ -58,14 +56,15 @@ public final class AdminSettingsEntity extends BaseSqlEntity<AdminSettings> impl
58 56 if (adminSettings.getId() != null) {
59 57 this.setUuid(adminSettings.getId().getId());
60 58 }
  59 + this.setCreatedTime(adminSettings.getCreatedTime());
61 60 this.key = adminSettings.getKey();
62 61 this.jsonValue = adminSettings.getJsonValue();
63 62 }
64 63
65 64 @Override
66 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 68 adminSettings.setKey(key);
70 69 adminSettings.setJsonValue(jsonValue);
71 70 return adminSettings;
... ...
... ... @@ -25,6 +25,7 @@ import javax.persistence.Embeddable;
25 25 import javax.persistence.EnumType;
26 26 import javax.persistence.Enumerated;
27 27 import java.io.Serializable;
  28 +import java.util.UUID;
28 29
29 30 import static org.thingsboard.server.dao.model.ModelConstants.ATTRIBUTE_KEY_COLUMN;
30 31 import static org.thingsboard.server.dao.model.ModelConstants.ATTRIBUTE_TYPE_COLUMN;
... ... @@ -39,8 +40,8 @@ public class AttributeKvCompositeKey implements Serializable {
39 40 @Enumerated(EnumType.STRING)
40 41 @Column(name = ENTITY_TYPE_COLUMN)
41 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 45 @Column(name = ATTRIBUTE_TYPE_COLUMN)
45 46 private String attributeType;
46 47 @Column(name = ATTRIBUTE_KEY_COLUMN)
... ...
... ... @@ -15,7 +15,6 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.oss.driver.api.core.uuid.Uuids;
19 18 import com.fasterxml.jackson.databind.JsonNode;
20 19 import lombok.Data;
21 20 import lombok.EqualsAndHashCode;
... ... @@ -40,6 +39,7 @@ import javax.persistence.Entity;
40 39 import javax.persistence.EnumType;
41 40 import javax.persistence.Enumerated;
42 41 import javax.persistence.Table;
  42 +import java.util.UUID;
43 43
44 44 import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_ACTION_DATA_PROPERTY;
45 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 61 public class AuditLogEntity extends BaseSqlEntity<AuditLog> implements BaseEntity<AuditLog> {
62 62
63 63 @Column(name = AUDIT_LOG_TENANT_ID_PROPERTY)
64   - private String tenantId;
  64 + private UUID tenantId;
65 65
66 66 @Column(name = AUDIT_LOG_CUSTOMER_ID_PROPERTY)
67   - private String customerId;
  67 + private UUID customerId;
68 68
69 69 @Enumerated(EnumType.STRING)
70 70 @Column(name = AUDIT_LOG_ENTITY_TYPE_PROPERTY)
71 71 private EntityType entityType;
72 72
73 73 @Column(name = AUDIT_LOG_ENTITY_ID_PROPERTY)
74   - private String entityId;
  74 + private UUID entityId;
75 75
76 76 @Column(name = AUDIT_LOG_ENTITY_NAME_PROPERTY)
77 77 private String entityName;
78 78
79 79 @Column(name = AUDIT_LOG_USER_ID_PROPERTY)
80   - private String userId;
  80 + private UUID userId;
81 81
82 82 @Column(name = AUDIT_LOG_USER_NAME_PROPERTY)
83 83 private String userName;
... ... @@ -105,18 +105,19 @@ public class AuditLogEntity extends BaseSqlEntity<AuditLog> implements BaseEntit
105 105 if (auditLog.getId() != null) {
106 106 this.setUuid(auditLog.getId().getId());
107 107 }
  108 + this.setCreatedTime(auditLog.getCreatedTime());
108 109 if (auditLog.getTenantId() != null) {
109   - this.tenantId = toString(auditLog.getTenantId().getId());
  110 + this.tenantId = auditLog.getTenantId().getId();
110 111 }
111 112 if (auditLog.getCustomerId() != null) {
112   - this.customerId = toString(auditLog.getCustomerId().getId());
  113 + this.customerId = auditLog.getCustomerId().getId();
113 114 }
114 115 if (auditLog.getEntityId() != null) {
115   - this.entityId = toString(auditLog.getEntityId().getId());
  116 + this.entityId = auditLog.getEntityId().getId();
116 117 this.entityType = auditLog.getEntityId().getEntityType();
117 118 }
118 119 if (auditLog.getUserId() != null) {
119   - this.userId = toString(auditLog.getUserId().getId());
  120 + this.userId = auditLog.getUserId().getId();
120 121 }
121 122 this.entityName = auditLog.getEntityName();
122 123 this.userName = auditLog.getUserName();
... ... @@ -129,18 +130,18 @@ public class AuditLogEntity extends BaseSqlEntity<AuditLog> implements BaseEntit
129 130 @Override
130 131 public AuditLog toData() {
131 132 AuditLog auditLog = new AuditLog(new AuditLogId(this.getUuid()));
132   - auditLog.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
  133 + auditLog.setCreatedTime(createdTime);
133 134 if (tenantId != null) {
134   - auditLog.setTenantId(new TenantId(toUUID(tenantId)));
  135 + auditLog.setTenantId(new TenantId(tenantId));
135 136 }
136 137 if (customerId != null) {
137   - auditLog.setCustomerId(new CustomerId(toUUID(customerId)));
  138 + auditLog.setCustomerId(new CustomerId(customerId));
138 139 }
139 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 143 if (userId != null) {
143   - auditLog.setUserId(new UserId(toUUID(userId)));
  144 + auditLog.setUserId(new UserId(userId));
144 145 }
145 146 auditLog.setEntityName(this.entityName);
146 147 auditLog.setUserName(this.userName);
... ...
... ... @@ -73,6 +73,7 @@ public class ComponentDescriptorEntity extends BaseSqlEntity<ComponentDescriptor
73 73 if (component.getId() != null) {
74 74 this.setUuid(component.getId().getId());
75 75 }
  76 + this.setCreatedTime(component.getCreatedTime());
76 77 this.actions = component.getActions();
77 78 this.type = component.getType();
78 79 this.scope = component.getScope();
... ... @@ -85,6 +86,7 @@ public class ComponentDescriptorEntity extends BaseSqlEntity<ComponentDescriptor
85 86 @Override
86 87 public ComponentDescriptor toData() {
87 88 ComponentDescriptor data = new ComponentDescriptor(new ComponentDescriptorId(this.getUuid()));
  89 + data.setCreatedTime(createdTime);
88 90 data.setType(type);
89 91 data.setScope(scope);
90 92 data.setName(this.getName());
... ...
... ... @@ -15,14 +15,12 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.oss.driver.api.core.uuid.Uuids;
19 18 import com.fasterxml.jackson.databind.JsonNode;
20 19 import lombok.Data;
21 20 import lombok.EqualsAndHashCode;
22 21 import org.hibernate.annotations.Type;
23 22 import org.hibernate.annotations.TypeDef;
24 23 import org.thingsboard.server.common.data.Customer;
25   -import org.thingsboard.server.common.data.UUIDConverter;
26 24 import org.thingsboard.server.common.data.id.CustomerId;
27 25 import org.thingsboard.server.common.data.id.TenantId;
28 26 import org.thingsboard.server.dao.model.BaseSqlEntity;
... ... @@ -33,6 +31,7 @@ import org.thingsboard.server.dao.util.mapping.JsonStringType;
33 31 import javax.persistence.Column;
34 32 import javax.persistence.Entity;
35 33 import javax.persistence.Table;
  34 +import java.util.UUID;
36 35
37 36 @Data
38 37 @EqualsAndHashCode(callSuper = true)
... ... @@ -42,7 +41,7 @@ import javax.persistence.Table;
42 41 public final class CustomerEntity extends BaseSqlEntity<Customer> implements SearchTextEntity<Customer> {
43 42
44 43 @Column(name = ModelConstants.CUSTOMER_TENANT_ID_PROPERTY)
45   - private String tenantId;
  44 + private UUID tenantId;
46 45
47 46 @Column(name = ModelConstants.CUSTOMER_TITLE_PROPERTY)
48 47 private String title;
... ... @@ -86,7 +85,8 @@ public final class CustomerEntity extends BaseSqlEntity<Customer> implements Sea
86 85 if (customer.getId() != null) {
87 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 90 this.title = customer.getTitle();
91 91 this.country = customer.getCountry();
92 92 this.state = customer.getState();
... ... @@ -112,8 +112,8 @@ public final class CustomerEntity extends BaseSqlEntity<Customer> implements Sea
112 112 @Override
113 113 public Customer toData() {
114 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 117 customer.setTitle(title);
118 118 customer.setCountry(country);
119 119 customer.setState(state);
... ... @@ -126,4 +126,5 @@ public final class CustomerEntity extends BaseSqlEntity<Customer> implements Sea
126 126 customer.setAdditionalInfo(additionalInfo);
127 127 return customer;
128 128 }
  129 +
129 130 }
... ...
... ... @@ -15,7 +15,6 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.oss.driver.api.core.uuid.Uuids;
19 18 import com.fasterxml.jackson.core.JsonProcessingException;
20 19 import com.fasterxml.jackson.databind.JavaType;
21 20 import com.fasterxml.jackson.databind.JsonNode;
... ... @@ -40,6 +39,7 @@ import javax.persistence.Entity;
40 39 import javax.persistence.Table;
41 40 import java.io.IOException;
42 41 import java.util.HashSet;
  42 +import java.util.UUID;
43 43
44 44 @Data
45 45 @Slf4j
... ... @@ -54,7 +54,7 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S
54 54 objectMapper.getTypeFactory().constructCollectionType(HashSet.class, ShortCustomerInfo.class);
55 55
56 56 @Column(name = ModelConstants.DASHBOARD_TENANT_ID_PROPERTY)
57   - private String tenantId;
  57 + private UUID tenantId;
58 58
59 59 @Column(name = ModelConstants.DASHBOARD_TITLE_PROPERTY)
60 60 private String title;
... ... @@ -77,8 +77,9 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S
77 77 if (dashboard.getId() != null) {
78 78 this.setUuid(dashboard.getId().getId());
79 79 }
  80 + this.setCreatedTime(dashboard.getCreatedTime());
80 81 if (dashboard.getTenantId() != null) {
81   - this.tenantId = toString(dashboard.getTenantId().getId());
  82 + this.tenantId = dashboard.getTenantId().getId();
82 83 }
83 84 this.title = dashboard.getTitle();
84 85 if (dashboard.getAssignedCustomers() != null) {
... ... @@ -104,9 +105,9 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements S
104 105 @Override
105 106 public Dashboard toData() {
106 107 Dashboard dashboard = new Dashboard(new DashboardId(this.getUuid()));
107   - dashboard.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
  108 + dashboard.setCreatedTime(this.getCreatedTime());
108 109 if (tenantId != null) {
109   - dashboard.setTenantId(new TenantId(toUUID(tenantId)));
  110 + dashboard.setTenantId(new TenantId(tenantId));
110 111 }
111 112 dashboard.setTitle(title);
112 113 if (!StringUtils.isEmpty(assignedCustomers)) {
... ...
... ... @@ -15,7 +15,6 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.oss.driver.api.core.uuid.Uuids;
19 18 import com.fasterxml.jackson.core.JsonProcessingException;
20 19 import com.fasterxml.jackson.databind.JavaType;
21 20 import com.fasterxml.jackson.databind.ObjectMapper;
... ... @@ -36,6 +35,7 @@ import javax.persistence.Entity;
36 35 import javax.persistence.Table;
37 36 import java.io.IOException;
38 37 import java.util.HashSet;
  38 +import java.util.UUID;
39 39
40 40 @Data
41 41 @Slf4j
... ... @@ -49,7 +49,7 @@ public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> implements
49 49 objectMapper.getTypeFactory().constructCollectionType(HashSet.class, ShortCustomerInfo.class);
50 50
51 51 @Column(name = ModelConstants.DASHBOARD_TENANT_ID_PROPERTY)
52   - private String tenantId;
  52 + private UUID tenantId;
53 53
54 54 @Column(name = ModelConstants.DASHBOARD_TITLE_PROPERTY)
55 55 private String title;
... ... @@ -68,8 +68,9 @@ public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> implements
68 68 if (dashboardInfo.getId() != null) {
69 69 this.setUuid(dashboardInfo.getId().getId());
70 70 }
  71 + this.setCreatedTime(dashboardInfo.getCreatedTime());
71 72 if (dashboardInfo.getTenantId() != null) {
72   - this.tenantId = toString(dashboardInfo.getTenantId().getId());
  73 + this.tenantId = dashboardInfo.getTenantId().getId();
73 74 }
74 75 this.title = dashboardInfo.getTitle();
75 76 if (dashboardInfo.getAssignedCustomers() != null) {
... ... @@ -98,9 +99,9 @@ public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> implements
98 99 @Override
99 100 public DashboardInfo toData() {
100 101 DashboardInfo dashboardInfo = new DashboardInfo(new DashboardId(this.getUuid()));
101   - dashboardInfo.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
  102 + dashboardInfo.setCreatedTime(createdTime);
102 103 if (tenantId != null) {
103   - dashboardInfo.setTenantId(new TenantId(toUUID(tenantId)));
  104 + dashboardInfo.setTenantId(new TenantId(tenantId));
104 105 }
105 106 dashboardInfo.setTitle(title);
106 107 if (!StringUtils.isEmpty(assignedCustomers)) {
... ...
... ... @@ -15,7 +15,6 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.oss.driver.api.core.uuid.Uuids;
19 18 import lombok.Data;
20 19 import lombok.EqualsAndHashCode;
21 20 import org.thingsboard.server.common.data.id.DeviceCredentialsId;
... ... @@ -31,6 +30,7 @@ import javax.persistence.Entity;
31 30 import javax.persistence.EnumType;
32 31 import javax.persistence.Enumerated;
33 32 import javax.persistence.Table;
  33 +import java.util.UUID;
34 34
35 35 @Data
36 36 @EqualsAndHashCode(callSuper = true)
... ... @@ -39,7 +39,7 @@ import javax.persistence.Table;
39 39 public final class DeviceCredentialsEntity extends BaseSqlEntity<DeviceCredentials> implements BaseEntity<DeviceCredentials> {
40 40
41 41 @Column(name = ModelConstants.DEVICE_CREDENTIALS_DEVICE_ID_PROPERTY)
42   - private String deviceId;
  42 + private UUID deviceId;
43 43
44 44 @Enumerated(EnumType.STRING)
45 45 @Column(name = ModelConstants.DEVICE_CREDENTIALS_CREDENTIALS_TYPE_PROPERTY)
... ... @@ -59,8 +59,9 @@ public final class DeviceCredentialsEntity extends BaseSqlEntity<DeviceCredentia
59 59 if (deviceCredentials.getId() != null) {
60 60 this.setUuid(deviceCredentials.getId().getId());
61 61 }
  62 + this.setCreatedTime(deviceCredentials.getCreatedTime());
62 63 if (deviceCredentials.getDeviceId() != null) {
63   - this.deviceId = toString(deviceCredentials.getDeviceId().getId());
  64 + this.deviceId = deviceCredentials.getDeviceId().getId();
64 65 }
65 66 this.credentialsType = deviceCredentials.getCredentialsType();
66 67 this.credentialsId = deviceCredentials.getCredentialsId();
... ... @@ -70,9 +71,9 @@ public final class DeviceCredentialsEntity extends BaseSqlEntity<DeviceCredentia
70 71 @Override
71 72 public DeviceCredentials toData() {
72 73 DeviceCredentials deviceCredentials = new DeviceCredentials(new DeviceCredentialsId(this.getUuid()));
73   - deviceCredentials.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
  74 + deviceCredentials.setCreatedTime(createdTime);
74 75 if (deviceId != null) {
75   - deviceCredentials.setDeviceId(new DeviceId(toUUID(deviceId)));
  76 + deviceCredentials.setDeviceId(new DeviceId(deviceId));
76 77 }
77 78 deviceCredentials.setCredentialsType(credentialsType);
78 79 deviceCredentials.setCredentialsId(credentialsId);
... ...
... ... @@ -15,9 +15,9 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
  18 +import com.fasterxml.jackson.databind.JsonNode;
18 19 import lombok.Data;
19 20 import lombok.EqualsAndHashCode;
20   -import com.fasterxml.jackson.databind.JsonNode;
21 21 import org.thingsboard.server.common.data.DeviceInfo;
22 22
23 23 import java.util.HashMap;
... ...
... ... @@ -15,7 +15,6 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.oss.driver.api.core.uuid.Uuids;
19 18 import com.fasterxml.jackson.databind.JsonNode;
20 19 import lombok.Data;
21 20 import lombok.EqualsAndHashCode;
... ... @@ -36,7 +35,6 @@ import javax.persistence.Entity;
36 35 import javax.persistence.EnumType;
37 36 import javax.persistence.Enumerated;
38 37 import javax.persistence.Table;
39   -
40 38 import java.util.UUID;
41 39
42 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 53 @TypeDef(name = "json", typeClass = JsonStringType.class)
56 54 @Table(name = EVENT_COLUMN_FAMILY_NAME)
57 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 58 @Column(name = EVENT_TENANT_ID_PROPERTY)
61   - private String tenantId;
  59 + private UUID tenantId;
62 60
63 61 @Enumerated(EnumType.STRING)
64 62 @Column(name = EVENT_ENTITY_TYPE_PROPERTY)
65 63 private EntityType entityType;
66 64
67 65 @Column(name = EVENT_ENTITY_ID_PROPERTY)
68   - private String entityId;
  66 + private UUID entityId;
69 67
70 68 @Column(name = EVENT_TYPE_PROPERTY)
71 69 private String eventType;
... ... @@ -87,12 +85,13 @@ public class EventEntity extends BaseSqlEntity<Event> implements BaseEntity<Eve
87 85 } else {
88 86 this.ts = System.currentTimeMillis();
89 87 }
  88 + this.setCreatedTime(event.getCreatedTime());
90 89 if (event.getTenantId() != null) {
91   - this.tenantId = toString(event.getTenantId().getId());
  90 + this.tenantId = event.getTenantId().getId();
92 91 }
93 92 if (event.getEntityId() != null) {
94 93 this.entityType = event.getEntityId().getEntityType();
95   - this.entityId = toString(event.getEntityId().getId());
  94 + this.entityId = event.getEntityId().getId();
96 95 }
97 96 this.eventType = event.getType();
98 97 this.eventUid = event.getUid();
... ... @@ -103,9 +102,9 @@ public class EventEntity extends BaseSqlEntity<Event> implements BaseEntity<Eve
103 102 @Override
104 103 public Event toData() {
105 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 108 event.setBody(body);
110 109 event.setType(eventType);
111 110 event.setUid(eventUid);
... ...
... ... @@ -18,11 +18,11 @@ package org.thingsboard.server.dao.model.sql;
18 18 import lombok.AllArgsConstructor;
19 19 import lombok.Data;
20 20 import lombok.NoArgsConstructor;
21   -import org.thingsboard.server.common.data.UUIDConverter;
22 21 import org.thingsboard.server.common.data.relation.EntityRelation;
23 22
24 23 import javax.persistence.Transient;
25 24 import java.io.Serializable;
  25 +import java.util.UUID;
26 26
27 27 @NoArgsConstructor
28 28 @AllArgsConstructor
... ... @@ -32,17 +32,17 @@ public class RelationCompositeKey implements Serializable {
32 32 @Transient
33 33 private static final long serialVersionUID = -4089175869616037592L;
34 34
35   - private String fromId;
  35 + private UUID fromId;
36 36 private String fromType;
37   - private String toId;
  37 + private UUID toId;
38 38 private String toType;
39 39 private String relationType;
40 40 private String relationTypeGroup;
41 41
42 42 public RelationCompositeKey(EntityRelation relation) {
43   - this.fromId = UUIDConverter.fromTimeUUID(relation.getFrom().getId());
  43 + this.fromId = relation.getFrom().getId();
44 44 this.fromType = relation.getFrom().getEntityType().name();
45   - this.toId = UUIDConverter.fromTimeUUID(relation.getTo().getId());
  45 + this.toId = relation.getTo().getId();
46 46 this.toType = relation.getTo().getEntityType().name();
47 47 this.relationType = relation.getType();
48 48 this.relationTypeGroup = relation.getTypeGroup().name();
... ...
... ... @@ -19,7 +19,6 @@ import com.fasterxml.jackson.databind.JsonNode;
19 19 import lombok.Data;
20 20 import org.hibernate.annotations.Type;
21 21 import org.hibernate.annotations.TypeDef;
22   -import org.thingsboard.server.common.data.UUIDConverter;
23 22 import org.thingsboard.server.common.data.id.EntityIdFactory;
24 23 import org.thingsboard.server.common.data.relation.EntityRelation;
25 24 import org.thingsboard.server.common.data.relation.RelationTypeGroup;
... ... @@ -31,6 +30,7 @@ import javax.persistence.Entity;
31 30 import javax.persistence.Id;
32 31 import javax.persistence.IdClass;
33 32 import javax.persistence.Table;
  33 +import java.util.UUID;
34 34
35 35 import static org.thingsboard.server.dao.model.ModelConstants.ADDITIONAL_INFO_PROPERTY;
36 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 49 public final class RelationEntity implements ToData<EntityRelation> {
50 50
51 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 55 @Id
56 56 @Column(name = RELATION_FROM_TYPE_PROPERTY)
57 57 private String fromType;
58 58
59 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 63 @Id
64 64 @Column(name = RELATION_TO_TYPE_PROPERTY)
... ... @@ -82,11 +82,11 @@ public final class RelationEntity implements ToData<EntityRelation> {
82 82
83 83 public RelationEntity(EntityRelation relation) {
84 84 if (relation.getTo() != null) {
85   - this.toId = UUIDConverter.fromTimeUUID(relation.getTo().getId());
  85 + this.toId = relation.getTo().getId();
86 86 this.toType = relation.getTo().getEntityType().name();
87 87 }
88 88 if (relation.getFrom() != null) {
89   - this.fromId = UUIDConverter.fromTimeUUID(relation.getFrom().getId());
  89 + this.fromId = relation.getFrom().getId();
90 90 this.fromType = relation.getFrom().getEntityType().name();
91 91 }
92 92 this.relationType = relation.getType();
... ... @@ -98,10 +98,10 @@ public final class RelationEntity implements ToData<EntityRelation> {
98 98 public EntityRelation toData() {
99 99 EntityRelation relation = new EntityRelation();
100 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 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 106 relation.setType(relationType);
107 107 relation.setTypeGroup(RelationTypeGroup.valueOf(relationTypeGroup));
... ...
... ... @@ -15,13 +15,11 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.oss.driver.api.core.uuid.Uuids;
19 18 import com.fasterxml.jackson.databind.JsonNode;
20 19 import lombok.Data;
21 20 import lombok.EqualsAndHashCode;
22 21 import org.hibernate.annotations.Type;
23 22 import org.hibernate.annotations.TypeDef;
24   -import org.thingsboard.server.common.data.UUIDConverter;
25 23 import org.thingsboard.server.common.data.id.RuleChainId;
26 24 import org.thingsboard.server.common.data.id.RuleNodeId;
27 25 import org.thingsboard.server.common.data.id.TenantId;
... ... @@ -35,6 +33,7 @@ import org.thingsboard.server.dao.util.mapping.JsonStringType;
35 33 import javax.persistence.Column;
36 34 import javax.persistence.Entity;
37 35 import javax.persistence.Table;
  36 +import java.util.UUID;
38 37
39 38 @Data
40 39 @EqualsAndHashCode(callSuper = true)
... ... @@ -44,7 +43,7 @@ import javax.persistence.Table;
44 43 public class RuleChainEntity extends BaseSqlEntity<RuleChain> implements SearchTextEntity<RuleChain> {
45 44
46 45 @Column(name = ModelConstants.RULE_CHAIN_TENANT_ID_PROPERTY)
47   - private String tenantId;
  46 + private UUID tenantId;
48 47
49 48 @Column(name = ModelConstants.RULE_CHAIN_NAME_PROPERTY)
50 49 private String name;
... ... @@ -53,7 +52,7 @@ public class RuleChainEntity extends BaseSqlEntity<RuleChain> implements SearchT
53 52 private String searchText;
54 53
55 54 @Column(name = ModelConstants.RULE_CHAIN_FIRST_RULE_NODE_ID_PROPERTY)
56   - private String firstRuleNodeId;
  55 + private UUID firstRuleNodeId;
57 56
58 57 @Column(name = ModelConstants.RULE_CHAIN_ROOT_PROPERTY)
59 58 private boolean root;
... ... @@ -76,11 +75,12 @@ public class RuleChainEntity extends BaseSqlEntity<RuleChain> implements SearchT
76 75 if (ruleChain.getId() != null) {
77 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 80 this.name = ruleChain.getName();
81 81 this.searchText = ruleChain.getName();
82 82 if (ruleChain.getFirstRuleNodeId() != null) {
83   - this.firstRuleNodeId = UUIDConverter.fromTimeUUID(ruleChain.getFirstRuleNodeId().getId());
  83 + this.firstRuleNodeId = ruleChain.getFirstRuleNodeId().getId();
84 84 }
85 85 this.root = ruleChain.isRoot();
86 86 this.debugMode = ruleChain.isDebugMode();
... ... @@ -101,11 +101,11 @@ public class RuleChainEntity extends BaseSqlEntity<RuleChain> implements SearchT
101 101 @Override
102 102 public RuleChain toData() {
103 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 106 ruleChain.setName(name);
107 107 if (firstRuleNodeId != null) {
108   - ruleChain.setFirstRuleNodeId(new RuleNodeId(UUIDConverter.fromString(firstRuleNodeId)));
  108 + ruleChain.setFirstRuleNodeId(new RuleNodeId(firstRuleNodeId));
109 109 }
110 110 ruleChain.setRoot(root);
111 111 ruleChain.setDebugMode(debugMode);
... ...
... ... @@ -15,7 +15,6 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.oss.driver.api.core.uuid.Uuids;
19 18 import com.fasterxml.jackson.databind.JsonNode;
20 19 import lombok.Data;
21 20 import lombok.EqualsAndHashCode;
... ... @@ -33,6 +32,7 @@ import org.thingsboard.server.dao.util.mapping.JsonStringType;
33 32 import javax.persistence.Column;
34 33 import javax.persistence.Entity;
35 34 import javax.persistence.Table;
  35 +import java.util.UUID;
36 36
37 37 @Data
38 38 @EqualsAndHashCode(callSuper = true)
... ... @@ -42,7 +42,7 @@ import javax.persistence.Table;
42 42 public class RuleNodeEntity extends BaseSqlEntity<RuleNode> implements SearchTextEntity<RuleNode> {
43 43
44 44 @Column(name = ModelConstants.RULE_NODE_CHAIN_ID_PROPERTY)
45   - private String ruleChainId;
  45 + private UUID ruleChainId;
46 46
47 47 @Column(name = ModelConstants.RULE_NODE_TYPE_PROPERTY)
48 48 private String type;
... ... @@ -71,8 +71,9 @@ public class RuleNodeEntity extends BaseSqlEntity<RuleNode> implements SearchTex
71 71 if (ruleNode.getId() != null) {
72 72 this.setUuid(ruleNode.getUuidId());
73 73 }
  74 + this.setCreatedTime(ruleNode.getCreatedTime());
74 75 if (ruleNode.getRuleChainId() != null) {
75   - this.ruleChainId = toString(DaoUtil.getId(ruleNode.getRuleChainId()));
  76 + this.ruleChainId = DaoUtil.getId(ruleNode.getRuleChainId());
76 77 }
77 78 this.type = ruleNode.getType();
78 79 this.name = ruleNode.getName();
... ... @@ -95,9 +96,9 @@ public class RuleNodeEntity extends BaseSqlEntity<RuleNode> implements SearchTex
95 96 @Override
96 97 public RuleNode toData() {
97 98 RuleNode ruleNode = new RuleNode(new RuleNodeId(this.getUuid()));
98   - ruleNode.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
  99 + ruleNode.setCreatedTime(createdTime);
99 100 if (ruleChainId != null) {
100   - ruleNode.setRuleChainId(new RuleChainId(toUUID(ruleChainId)));
  101 + ruleNode.setRuleChainId(new RuleChainId(ruleChainId));
101 102 }
102 103 ruleNode.setType(type);
103 104 ruleNode.setName(name);
... ...
... ... @@ -15,7 +15,6 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.oss.driver.api.core.uuid.Uuids;
19 18 import com.fasterxml.jackson.databind.JsonNode;
20 19 import lombok.Data;
21 20 import lombok.EqualsAndHashCode;
... ... @@ -90,6 +89,7 @@ public final class TenantEntity extends BaseSqlEntity<Tenant> implements SearchT
90 89 if (tenant.getId() != null) {
91 90 this.setUuid(tenant.getId().getId());
92 91 }
  92 + this.setCreatedTime(tenant.getCreatedTime());
93 93 this.title = tenant.getTitle();
94 94 this.region = tenant.getRegion();
95 95 this.country = tenant.getCountry();
... ... @@ -122,7 +122,7 @@ public final class TenantEntity extends BaseSqlEntity<Tenant> implements SearchT
122 122 @Override
123 123 public Tenant toData() {
124 124 Tenant tenant = new Tenant(new TenantId(this.getUuid()));
125   - tenant.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
  125 + tenant.setCreatedTime(createdTime);
126 126 tenant.setTitle(title);
127 127 tenant.setRegion(region);
128 128 tenant.setCountry(country);
... ...
... ... @@ -15,7 +15,6 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.oss.driver.api.core.uuid.Uuids;
19 18 import lombok.Data;
20 19 import lombok.EqualsAndHashCode;
21 20 import org.thingsboard.server.common.data.id.UserCredentialsId;
... ... @@ -28,6 +27,7 @@ import org.thingsboard.server.dao.model.ModelConstants;
28 27 import javax.persistence.Column;
29 28 import javax.persistence.Entity;
30 29 import javax.persistence.Table;
  30 +import java.util.UUID;
31 31
32 32 @Data
33 33 @EqualsAndHashCode(callSuper = true)
... ... @@ -36,7 +36,7 @@ import javax.persistence.Table;
36 36 public final class UserCredentialsEntity extends BaseSqlEntity<UserCredentials> implements BaseEntity<UserCredentials> {
37 37
38 38 @Column(name = ModelConstants.USER_CREDENTIALS_USER_ID_PROPERTY, unique = true)
39   - private String userId;
  39 + private UUID userId;
40 40
41 41 @Column(name = ModelConstants.USER_CREDENTIALS_ENABLED_PROPERTY)
42 42 private boolean enabled;
... ... @@ -58,8 +58,9 @@ public final class UserCredentialsEntity extends BaseSqlEntity<UserCredentials>
58 58 if (userCredentials.getId() != null) {
59 59 this.setUuid(userCredentials.getId().getId());
60 60 }
  61 + this.setCreatedTime(userCredentials.getCreatedTime());
61 62 if (userCredentials.getUserId() != null) {
62   - this.userId = toString(userCredentials.getUserId().getId());
  63 + this.userId = userCredentials.getUserId().getId();
63 64 }
64 65 this.enabled = userCredentials.isEnabled();
65 66 this.password = userCredentials.getPassword();
... ... @@ -70,9 +71,9 @@ public final class UserCredentialsEntity extends BaseSqlEntity<UserCredentials>
70 71 @Override
71 72 public UserCredentials toData() {
72 73 UserCredentials userCredentials = new UserCredentials(new UserCredentialsId(this.getUuid()));
73   - userCredentials.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
  74 + userCredentials.setCreatedTime(createdTime);
74 75 if (userId != null) {
75   - userCredentials.setUserId(new UserId(toUUID(userId)));
  76 + userCredentials.setUserId(new UserId(userId));
76 77 }
77 78 userCredentials.setEnabled(enabled);
78 79 userCredentials.setPassword(password);
... ...
... ... @@ -15,7 +15,6 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.oss.driver.api.core.uuid.Uuids;
19 18 import com.fasterxml.jackson.databind.JsonNode;
20 19 import lombok.Data;
21 20 import lombok.EqualsAndHashCode;
... ... @@ -36,9 +35,7 @@ import javax.persistence.Entity;
36 35 import javax.persistence.EnumType;
37 36 import javax.persistence.Enumerated;
38 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 41 * Created by Valerii Sosliuk on 4/21/2017.
... ... @@ -51,10 +48,10 @@ import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID;
51 48 public class UserEntity extends BaseSqlEntity<User> implements SearchTextEntity<User> {
52 49
53 50 @Column(name = ModelConstants.USER_TENANT_ID_PROPERTY)
54   - private String tenantId;
  51 + private UUID tenantId;
55 52
56 53 @Column(name = ModelConstants.USER_CUSTOMER_ID_PROPERTY)
57   - private String customerId;
  54 + private UUID customerId;
58 55
59 56 @Enumerated(EnumType.STRING)
60 57 @Column(name = ModelConstants.USER_AUTHORITY_PROPERTY)
... ... @@ -83,12 +80,13 @@ public class UserEntity extends BaseSqlEntity<User> implements SearchTextEntity<
83 80 if (user.getId() != null) {
84 81 this.setUuid(user.getId().getId());
85 82 }
  83 + this.setCreatedTime(user.getCreatedTime());
86 84 this.authority = user.getAuthority();
87 85 if (user.getTenantId() != null) {
88   - this.tenantId = fromTimeUUID(user.getTenantId().getId());
  86 + this.tenantId = user.getTenantId().getId();
89 87 }
90 88 if (user.getCustomerId() != null) {
91   - this.customerId = fromTimeUUID(user.getCustomerId().getId());
  89 + this.customerId = user.getCustomerId().getId();
92 90 }
93 91 this.email = user.getEmail();
94 92 this.firstName = user.getFirstName();
... ... @@ -109,13 +107,13 @@ public class UserEntity extends BaseSqlEntity<User> implements SearchTextEntity<
109 107 @Override
110 108 public User toData() {
111 109 User user = new User(new UserId(this.getUuid()));
112   - user.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
  110 + user.setCreatedTime(createdTime);
113 111 user.setAuthority(authority);
114 112 if (tenantId != null) {
115   - user.setTenantId(new TenantId(fromString(tenantId)));
  113 + user.setTenantId(new TenantId(tenantId));
116 114 }
117 115 if (customerId != null) {
118   - user.setCustomerId(new CustomerId(fromString(customerId)));
  116 + user.setCustomerId(new CustomerId(customerId));
119 117 }
120 118 user.setEmail(email);
121 119 user.setFirstName(firstName);
... ...
... ... @@ -15,7 +15,6 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.oss.driver.api.core.uuid.Uuids;
19 18 import com.fasterxml.jackson.databind.JsonNode;
20 19 import lombok.Data;
21 20 import lombok.EqualsAndHashCode;
... ... @@ -32,6 +31,7 @@ import org.thingsboard.server.dao.util.mapping.JsonStringType;
32 31 import javax.persistence.Column;
33 32 import javax.persistence.Entity;
34 33 import javax.persistence.Table;
  34 +import java.util.UUID;
35 35
36 36 @Data
37 37 @EqualsAndHashCode(callSuper = true)
... ... @@ -41,7 +41,7 @@ import javax.persistence.Table;
41 41 public final class WidgetTypeEntity extends BaseSqlEntity<WidgetType> implements BaseEntity<WidgetType> {
42 42
43 43 @Column(name = ModelConstants.WIDGET_TYPE_TENANT_ID_PROPERTY)
44   - private String tenantId;
  44 + private UUID tenantId;
45 45
46 46 @Column(name = ModelConstants.WIDGET_TYPE_BUNDLE_ALIAS_PROPERTY)
47 47 private String bundleAlias;
... ... @@ -64,8 +64,9 @@ public final class WidgetTypeEntity extends BaseSqlEntity<WidgetType> implement
64 64 if (widgetType.getId() != null) {
65 65 this.setUuid(widgetType.getId().getId());
66 66 }
  67 + this.setCreatedTime(widgetType.getCreatedTime());
67 68 if (widgetType.getTenantId() != null) {
68   - this.tenantId = toString(widgetType.getTenantId().getId());
  69 + this.tenantId = widgetType.getTenantId().getId();
69 70 }
70 71 this.bundleAlias = widgetType.getBundleAlias();
71 72 this.alias = widgetType.getAlias();
... ... @@ -76,9 +77,9 @@ public final class WidgetTypeEntity extends BaseSqlEntity<WidgetType> implement
76 77 @Override
77 78 public WidgetType toData() {
78 79 WidgetType widgetType = new WidgetType(new WidgetTypeId(this.getUuid()));
79   - widgetType.setCreatedTime(Uuids.unixTimestamp(this.getUuid()));
  80 + widgetType.setCreatedTime(createdTime);
80 81 if (tenantId != null) {
81   - widgetType.setTenantId(new TenantId(toUUID(tenantId)));
  82 + widgetType.setTenantId(new TenantId(tenantId));
82 83 }
83 84 widgetType.setBundleAlias(bundleAlias);
84 85 widgetType.setAlias(alias);
... ...
... ... @@ -16,10 +16,8 @@
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18 18
19   -import com.datastax.oss.driver.api.core.uuid.Uuids;
20 19 import lombok.Data;
21 20 import lombok.EqualsAndHashCode;
22   -import org.thingsboard.server.common.data.UUIDConverter;
23 21 import org.thingsboard.server.common.data.id.TenantId;
24 22 import org.thingsboard.server.common.data.id.WidgetsBundleId;
25 23 import org.thingsboard.server.common.data.widget.WidgetsBundle;
... ... @@ -30,6 +28,7 @@ import org.thingsboard.server.dao.model.SearchTextEntity;
30 28 import javax.persistence.Column;
31 29 import javax.persistence.Entity;
32 30 import javax.persistence.Table;
  31 +import java.util.UUID;
33 32
34 33 @Data
35 34 @EqualsAndHashCode(callSuper = true)
... ... @@ -38,7 +37,7 @@ import javax.persistence.Table;
38 37 public final class WidgetsBundleEntity extends BaseSqlEntity<WidgetsBundle> implements SearchTextEntity<WidgetsBundle> {
39 38
40 39 @Column(name = ModelConstants.WIDGETS_BUNDLE_TENANT_ID_PROPERTY)
41   - private String tenantId;
  40 + private UUID tenantId;
42 41
43 42 @Column(name = ModelConstants.WIDGETS_BUNDLE_ALIAS_PROPERTY)
44 43 private String alias;
... ... @@ -57,8 +56,9 @@ public final class WidgetsBundleEntity extends BaseSqlEntity<WidgetsBundle> impl
57 56 if (widgetsBundle.getId() != null) {
58 57 this.setUuid(widgetsBundle.getId().getId());
59 58 }
  59 + this.setCreatedTime(widgetsBundle.getCreatedTime());
60 60 if (widgetsBundle.getTenantId() != null) {
61   - this.tenantId = UUIDConverter.fromTimeUUID(widgetsBundle.getTenantId().getId());
  61 + this.tenantId = widgetsBundle.getTenantId().getId();
62 62 }
63 63 this.alias = widgetsBundle.getAlias();
64 64 this.title = widgetsBundle.getTitle();
... ... @@ -76,10 +76,10 @@ public final class WidgetsBundleEntity extends BaseSqlEntity<WidgetsBundle> impl
76 76
77 77 @Override
78 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 81 if (tenantId != null) {
82   - widgetsBundle.setTenantId(new TenantId(UUIDConverter.fromString(tenantId)));
  82 + widgetsBundle.setTenantId(new TenantId(tenantId));
83 83 }
84 84 widgetsBundle.setAlias(alias);
85 85 widgetsBundle.setTitle(title);
... ...
... ... @@ -18,7 +18,6 @@ package org.thingsboard.server.dao.model.sqlts.latest;
18 18 import lombok.AllArgsConstructor;
19 19 import lombok.Data;
20 20 import lombok.NoArgsConstructor;
21   -import org.thingsboard.server.common.data.EntityType;
22 21
23 22 import javax.persistence.Transient;
24 23 import java.io.Serializable;
... ...
... ... @@ -19,11 +19,9 @@ import lombok.Data;
19 19 import org.thingsboard.server.dao.model.sql.AbstractTsKvEntity;
20 20 import org.thingsboard.server.dao.sqlts.latest.SearchTsKvLatestRepository;
21 21
22   -import javax.persistence.Column;
23 22 import javax.persistence.ColumnResult;
24 23 import javax.persistence.ConstructorResult;
25 24 import javax.persistence.Entity;
26   -import javax.persistence.Id;
27 25 import javax.persistence.IdClass;
28 26 import javax.persistence.NamedNativeQueries;
29 27 import javax.persistence.NamedNativeQuery;
... ... @@ -32,8 +30,6 @@ import javax.persistence.SqlResultSetMappings;
32 30 import javax.persistence.Table;
33 31 import java.util.UUID;
34 32
35   -import static org.thingsboard.server.dao.model.ModelConstants.KEY_COLUMN;
36   -
37 33 @Data
38 34 @Entity
39 35 @Table(name = "ts_kv_latest")
... ...
... ... @@ -18,14 +18,10 @@ package org.thingsboard.server.dao.model.sqlts.ts;
18 18 import lombok.Data;
19 19 import org.thingsboard.server.dao.model.sql.AbstractTsKvEntity;
20 20
21   -import javax.persistence.Column;
22 21 import javax.persistence.Entity;
23   -import javax.persistence.Id;
24 22 import javax.persistence.IdClass;
25 23 import javax.persistence.Table;
26 24
27   -import static org.thingsboard.server.dao.model.ModelConstants.KEY_COLUMN;
28   -
29 25 @Data
30 26 @Entity
31 27 @Table(name = "ts_kv")
... ...
... ... @@ -15,10 +15,7 @@
15 15 */
16 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 18 import com.google.common.base.Function;
21   -import com.google.common.collect.Lists;
22 19 import com.google.common.util.concurrent.AsyncFunction;
23 20 import com.google.common.util.concurrent.Futures;
24 21 import com.google.common.util.concurrent.ListenableFuture;
... ... @@ -27,11 +24,8 @@ import org.thingsboard.common.util.ThingsBoardThreadFactory;
27 24 import javax.annotation.Nullable;
28 25 import javax.annotation.PostConstruct;
29 26 import javax.annotation.PreDestroy;
30   -import java.util.ArrayList;
31   -import java.util.List;
32 27 import java.util.concurrent.ExecutorService;
33 28 import java.util.concurrent.Executors;
34   -import java.util.stream.Collectors;
35 29
36 30 /**
37 31 * Created by ashvayka on 21.02.17.
... ...
... ... @@ -15,7 +15,6 @@
15 15 */
16 16 package org.thingsboard.server.dao.nosql;
17 17
18   -import com.datastax.oss.driver.api.core.cql.AsyncResultSet;
19 18 import com.google.common.util.concurrent.ListenableFuture;
20 19 import com.google.common.util.concurrent.SettableFuture;
21 20 import lombok.extern.slf4j.Slf4j;
... ...
... ... @@ -59,6 +59,4 @@ public interface RelationDao {
59 59
60 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 48 import java.util.List;
49 49 import java.util.Map;
50 50 import java.util.concurrent.ExecutionException;
51   -import java.util.stream.Collectors;
52 51
53 52 /**
54 53 * Created by igor on 3/12/18.
... ...
... ... @@ -20,7 +20,6 @@ import org.thingsboard.server.common.data.page.PageLink;
20 20 import org.thingsboard.server.common.data.rule.RuleChain;
21 21 import org.thingsboard.server.dao.Dao;
22 22
23   -import java.util.List;
24 23 import java.util.UUID;
25 24
26 25 /**
... ...
... ... @@ -20,9 +20,6 @@ import org.thingsboard.server.common.data.id.TenantId;
20 20 import org.thingsboard.server.common.data.page.PageData;
21 21 import org.thingsboard.server.common.data.page.PageLink;
22 22
23   -import java.util.List;
24   -import java.util.UUID;
25   -
26 23 public abstract class PaginatedRemover<I, D extends IdBased<?>> {
27 24
28 25 private static final int DEFAULT_LIMIT = 100;
... ...
... ... @@ -20,9 +20,6 @@ import org.thingsboard.server.common.data.id.TenantId;
20 20 import org.thingsboard.server.common.data.page.PageData;
21 21 import org.thingsboard.server.common.data.page.TimePageLink;
22 22
23   -import java.util.List;
24   -import java.util.UUID;
25   -
26 23 public abstract class TimePaginatedRemover<I, D extends IdBased<?>> {
27 24
28 25 private static final int DEFAULT_LIMIT = 100;
... ...
... ... @@ -20,7 +20,6 @@ import org.apache.commons.lang3.StringUtils;
20 20 import org.springframework.beans.factory.annotation.Autowired;
21 21 import org.springframework.stereotype.Service;
22 22 import org.thingsboard.server.common.data.AdminSettings;
23   -import org.thingsboard.server.common.data.Tenant;
24 23 import org.thingsboard.server.common.data.id.AdminSettingsId;
25 24 import org.thingsboard.server.common.data.id.TenantId;
26 25 import org.thingsboard.server.dao.exception.DataValidationException;
... ...
... ... @@ -30,8 +30,6 @@ import java.util.List;
30 30 import java.util.Optional;
31 31 import java.util.UUID;
32 32
33   -import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID;
34   -
35 33 /**
36 34 * @author Valerii Sosliuk
37 35 */
... ... @@ -42,9 +40,10 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D>
42 40
43 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 48 @Override
50 49 @Transactional
... ... @@ -59,7 +58,9 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D>
59 58 setSearchText(entity);
60 59 log.debug("Saving entity {}", entity);
61 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 65 entity = getCrudRepository().save(entity);
65 66 return DaoUtil.getData(entity);
... ... @@ -68,23 +69,22 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D>
68 69 @Override
69 70 public D findById(TenantId tenantId, UUID key) {
70 71 log.debug("Get entity by key {}", key);
71   - Optional<E> entity = getCrudRepository().findById(fromTimeUUID(key));
  72 + Optional<E> entity = getCrudRepository().findById(key);
72 73 return DaoUtil.getData(entity);
73 74 }
74 75
75 76 @Override
76 77 public ListenableFuture<D> findByIdAsync(TenantId tenantId, UUID key) {
77 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 82 @Override
82 83 @Transactional
83 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 90 @Override
... ...
... ... @@ -34,6 +34,7 @@ import java.util.UUID;
34 34 */
35 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 38 public static <T> Specification<T> getTimeSearchPageSpec(TimePageLink pageLink, String idColumn) {
38 39 return new Specification<T>() {
39 40 @Override
... ...
... ... @@ -20,21 +20,21 @@ import org.springframework.data.domain.Pageable;
20 20 import org.springframework.data.jpa.repository.Query;
21 21 import org.springframework.data.repository.CrudRepository;
22 22 import org.springframework.data.repository.query.Param;
23   -import org.thingsboard.server.common.data.EntityType;
24 23 import org.thingsboard.server.dao.model.sql.AlarmEntity;
25 24 import org.thingsboard.server.dao.model.sql.AlarmInfoEntity;
26 25 import org.thingsboard.server.dao.util.SqlDao;
27 26
28 27 import java.util.List;
  28 +import java.util.UUID;
29 29
30 30 /**
31 31 * Created by Valerii Sosliuk on 5/21/2017.
32 32 */
33 33 @SqlDao
34   -public interface AlarmRepository extends CrudRepository<AlarmEntity, String> {
  34 +public interface AlarmRepository extends CrudRepository<AlarmEntity, UUID> {
35 35
36 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 38 @Param("alarmType") String alarmType,
39 39 Pageable pageable);
40 40
... ... @@ -46,9 +46,8 @@ public interface AlarmRepository extends CrudRepository<AlarmEntity, String> {
46 46 "AND re.relationType = :relationType " +
47 47 "AND re.fromId = :affectedEntityId " +
48 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 51 "AND (LOWER(a.type) LIKE LOWER(CONCAT(:searchText, '%'))" +
53 52 "OR LOWER(a.severity) LIKE LOWER(CONCAT(:searchText, '%'))" +
54 53 "OR LOWER(a.status) LIKE LOWER(CONCAT(:searchText, '%')))",
... ... @@ -60,19 +59,17 @@ public interface AlarmRepository extends CrudRepository<AlarmEntity, String> {
60 59 "AND re.relationType = :relationType " +
61 60 "AND re.fromId = :affectedEntityId " +
62 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 64 "AND (LOWER(a.type) LIKE LOWER(CONCAT(:searchText, '%'))" +
67 65 "OR LOWER(a.severity) LIKE LOWER(CONCAT(:searchText, '%'))" +
68 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 69 @Param("affectedEntityType") String affectedEntityType,
72 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 73 @Param("searchText") String searchText,
77 74 Pageable pageable);
78 75 }
... ...
... ... @@ -41,7 +41,6 @@ import java.util.List;
41 41 import java.util.Objects;
42 42 import java.util.UUID;
43 43
44   -import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID;
45 44 import static org.thingsboard.server.dao.DaoUtil.endTimeToId;
46 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 64 }
66 65
67 66 @Override
68   - protected CrudRepository<AlarmEntity, String> getCrudRepository() {
  67 + protected CrudRepository<AlarmEntity, UUID> getCrudRepository() {
69 68 return alarmRepository;
70 69 }
71 70
... ... @@ -78,7 +77,7 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A
78 77 public ListenableFuture<Alarm> findLatestByOriginatorAndType(TenantId tenantId, EntityId originator, String type) {
79 78 return service.submit(() -> {
80 79 List<AlarmEntity> latest = alarmRepository.findLatestByOriginatorAndType(
81   - UUIDConverter.fromTimeUUID(originator.getId()),
  80 + originator.getId(),
82 81 type,
83 82 PageRequest.of(0, 1));
84 83 return latest.isEmpty() ? null : DaoUtil.getData(latest.get(0));
... ... @@ -106,13 +105,12 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A
106 105
107 106 return DaoUtil.toPageData(
108 107 alarmRepository.findAlarms(
109   - fromTimeUUID(tenantId.getId()),
110   - fromTimeUUID(affectedEntity.getId()),
  108 + tenantId.getId(),
  109 + affectedEntity.getId(),
111 110 affectedEntity.getEntityType().name(),
112 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 114 Objects.toString(query.getPageLink().getTextSearch(), ""),
117 115 DaoUtil.toPageable(query.getPageLink())
118 116 )
... ...
... ... @@ -18,7 +18,6 @@ package org.thingsboard.server.dao.sql.asset;
18 18 import org.springframework.data.domain.Page;
19 19 import org.springframework.data.domain.Pageable;
20 20 import org.springframework.data.jpa.repository.Query;
21   -import org.springframework.data.repository.CrudRepository;
22 21 import org.springframework.data.repository.PagingAndSortingRepository;
23 22 import org.springframework.data.repository.query.Param;
24 23 import org.thingsboard.server.dao.model.sql.AssetEntity;
... ... @@ -26,22 +25,23 @@ import org.thingsboard.server.dao.model.sql.AssetInfoEntity;
26 25 import org.thingsboard.server.dao.util.SqlDao;
27 26
28 27 import java.util.List;
  28 +import java.util.UUID;
29 29
30 30 /**
31 31 * Created by Valerii Sosliuk on 5/21/2017.
32 32 */
33 33 @SqlDao
34   -public interface AssetRepository extends PagingAndSortingRepository<AssetEntity, String> {
  34 +public interface AssetRepository extends PagingAndSortingRepository<AssetEntity, UUID> {
35 35
36 36 @Query("SELECT new org.thingsboard.server.dao.model.sql.AssetInfoEntity(a, c.title, c.additionalInfo) " +
37 37 "FROM AssetEntity a " +
38 38 "LEFT JOIN CustomerEntity c on c.id = a.customerId " +
39 39 "WHERE a.id = :assetId")
40   - AssetInfoEntity findAssetInfoById(@Param("assetId") String assetId);
  40 + AssetInfoEntity findAssetInfoById(@Param("assetId") UUID assetId);
41 41
42 42 @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " +
43 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 45 @Param("textSearch") String textSearch,
46 46 Pageable pageable);
47 47
... ... @@ -50,15 +50,15 @@ public interface AssetRepository extends PagingAndSortingRepository<AssetEntity,
50 50 "LEFT JOIN CustomerEntity c on c.id = a.customerId " +
51 51 "WHERE a.tenantId = :tenantId " +
52 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 54 @Param("textSearch") String textSearch,
55 55 Pageable pageable);
56 56
57 57 @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " +
58 58 "AND a.customerId = :customerId " +
59 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 62 @Param("textSearch") String textSearch,
63 63 Pageable pageable);
64 64
... ... @@ -68,21 +68,21 @@ public interface AssetRepository extends PagingAndSortingRepository<AssetEntity,
68 68 "WHERE a.tenantId = :tenantId " +
69 69 "AND a.customerId = :customerId " +
70 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 73 @Param("searchText") String searchText,
74 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 82 @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " +
83 83 "AND a.type = :type " +
84 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 86 @Param("type") String type,
87 87 @Param("textSearch") String textSearch,
88 88 Pageable pageable);
... ... @@ -93,7 +93,7 @@ public interface AssetRepository extends PagingAndSortingRepository<AssetEntity,
93 93 "WHERE a.tenantId = :tenantId " +
94 94 "AND a.type = :type " +
95 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 97 @Param("type") String type,
98 98 @Param("textSearch") String textSearch,
99 99 Pageable pageable);
... ... @@ -102,8 +102,8 @@ public interface AssetRepository extends PagingAndSortingRepository<AssetEntity,
102 102 @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " +
103 103 "AND a.customerId = :customerId AND a.type = :type " +
104 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 107 @Param("type") String type,
108 108 @Param("textSearch") String textSearch,
109 109 Pageable pageable);
... ... @@ -115,13 +115,13 @@ public interface AssetRepository extends PagingAndSortingRepository<AssetEntity,
115 115 "AND a.customerId = :customerId " +
116 116 "AND a.type = :type " +
117 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 120 @Param("type") String type,
121 121 @Param("textSearch") String textSearch,
122 122 Pageable pageable);
123 123
124 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 17
18 18 import com.google.common.util.concurrent.ListenableFuture;
19 19 import org.springframework.beans.factory.annotation.Autowired;
20   -import org.springframework.data.domain.PageRequest;
21 20 import org.springframework.data.repository.CrudRepository;
22 21 import org.springframework.stereotype.Component;
23 22 import org.thingsboard.server.common.data.EntitySubtype;
... ... @@ -41,9 +40,6 @@ import java.util.Objects;
41 40 import java.util.Optional;
42 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 44 * Created by Valerii Sosliuk on 5/19/2017.
49 45 */
... ... @@ -60,20 +56,20 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im
60 56 }
61 57
62 58 @Override
63   - protected CrudRepository<AssetEntity, String> getCrudRepository() {
  59 + protected CrudRepository<AssetEntity, UUID> getCrudRepository() {
64 60 return assetRepository;
65 61 }
66 62
67 63 @Override
68 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 68 @Override
73 69 public PageData<Asset> findAssetsByTenantId(UUID tenantId, PageLink pageLink) {
74 70 return DaoUtil.toPageData(assetRepository
75 71 .findByTenantId(
76   - fromTimeUUID(tenantId),
  72 + tenantId,
77 73 Objects.toString(pageLink.getTextSearch(), ""),
78 74 DaoUtil.toPageable(pageLink)));
79 75 }
... ... @@ -82,7 +78,7 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im
82 78 public PageData<AssetInfo> findAssetInfosByTenantId(UUID tenantId, PageLink pageLink) {
83 79 return DaoUtil.toPageData(
84 80 assetRepository.findAssetInfosByTenantId(
85   - fromTimeUUID(tenantId),
  81 + tenantId,
86 82 Objects.toString(pageLink.getTextSearch(), ""),
87 83 DaoUtil.toPageable(pageLink, AssetInfoEntity.assetInfoColumnMap)));
88 84 }
... ... @@ -90,15 +86,15 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im
90 86 @Override
91 87 public ListenableFuture<List<Asset>> findAssetsByTenantIdAndIdsAsync(UUID tenantId, List<UUID> assetIds) {
92 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 92 @Override
97 93 public PageData<Asset> findAssetsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink) {
98 94 return DaoUtil.toPageData(assetRepository
99 95 .findByTenantIdAndCustomerId(
100   - fromTimeUUID(tenantId),
101   - fromTimeUUID(customerId),
  96 + tenantId,
  97 + customerId,
102 98 Objects.toString(pageLink.getTextSearch(), ""),
103 99 DaoUtil.toPageable(pageLink)));
104 100 }
... ... @@ -107,8 +103,8 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im
107 103 public PageData<AssetInfo> findAssetInfosByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink) {
108 104 return DaoUtil.toPageData(
109 105 assetRepository.findAssetInfosByTenantIdAndCustomerId(
110   - fromTimeUUID(tenantId),
111   - fromTimeUUID(customerId),
  106 + tenantId,
  107 + customerId,
112 108 Objects.toString(pageLink.getTextSearch(), ""),
113 109 DaoUtil.toPageable(pageLink, AssetInfoEntity.assetInfoColumnMap)));
114 110 }
... ... @@ -116,12 +112,12 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im
116 112 @Override
117 113 public ListenableFuture<List<Asset>> findAssetsByTenantIdAndCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> assetIds) {
118 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 118 @Override
123 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 121 return Optional.ofNullable(asset);
126 122 }
127 123
... ... @@ -129,7 +125,7 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im
129 125 public PageData<Asset> findAssetsByTenantIdAndType(UUID tenantId, String type, PageLink pageLink) {
130 126 return DaoUtil.toPageData(assetRepository
131 127 .findByTenantIdAndType(
132   - fromTimeUUID(tenantId),
  128 + tenantId,
133 129 type,
134 130 Objects.toString(pageLink.getTextSearch(), ""),
135 131 DaoUtil.toPageable(pageLink)));
... ... @@ -139,7 +135,7 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im
139 135 public PageData<AssetInfo> findAssetInfosByTenantIdAndType(UUID tenantId, String type, PageLink pageLink) {
140 136 return DaoUtil.toPageData(
141 137 assetRepository.findAssetInfosByTenantIdAndType(
142   - fromTimeUUID(tenantId),
  138 + tenantId,
143 139 type,
144 140 Objects.toString(pageLink.getTextSearch(), ""),
145 141 DaoUtil.toPageable(pageLink, AssetInfoEntity.assetInfoColumnMap)));
... ... @@ -149,8 +145,8 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im
149 145 public PageData<Asset> findAssetsByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink) {
150 146 return DaoUtil.toPageData(assetRepository
151 147 .findByTenantIdAndCustomerIdAndType(
152   - fromTimeUUID(tenantId),
153   - fromTimeUUID(customerId),
  148 + tenantId,
  149 + customerId,
154 150 type,
155 151 Objects.toString(pageLink.getTextSearch(), ""),
156 152 DaoUtil.toPageable(pageLink)));
... ... @@ -160,8 +156,8 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im
160 156 public PageData<AssetInfo> findAssetInfosByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink) {
161 157 return DaoUtil.toPageData(
162 158 assetRepository.findAssetInfosByTenantIdAndCustomerIdAndType(
163   - fromTimeUUID(tenantId),
164   - fromTimeUUID(customerId),
  159 + tenantId,
  160 + customerId,
165 161 type,
166 162 Objects.toString(pageLink.getTextSearch(), ""),
167 163 DaoUtil.toPageable(pageLink, AssetInfoEntity.assetInfoColumnMap)));
... ... @@ -169,7 +165,7 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im
169 165
170 166 @Override
171 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 171 private List<EntitySubtype> convertTenantAssetTypesToDto(UUID tenantId, List<String> types) {
... ...
... ... @@ -29,6 +29,7 @@ import org.thingsboard.server.dao.util.SqlDao;
29 29
30 30 import java.sql.PreparedStatement;
31 31 import java.sql.SQLException;
  32 +import java.sql.SQLType;
32 33 import java.sql.Types;
33 34 import java.util.ArrayList;
34 35 import java.util.List;
... ... @@ -92,7 +93,7 @@ public abstract class AttributeKvInsertRepository {
92 93
93 94 ps.setLong(6, kvEntity.getLastUpdateTs());
94 95 ps.setString(7, kvEntity.getId().getEntityType().name());
95   - ps.setString(8, kvEntity.getId().getEntityId());
  96 + ps.setObject(8, kvEntity.getId().getEntityId());
96 97 ps.setString(9, kvEntity.getId().getAttributeType());
97 98 ps.setString(10, kvEntity.getId().getAttributeKey());
98 99 }
... ... @@ -122,7 +123,7 @@ public abstract class AttributeKvInsertRepository {
122 123 public void setValues(PreparedStatement ps, int i) throws SQLException {
123 124 AttributeKvEntity kvEntity = insertEntities.get(i);
124 125 ps.setString(1, kvEntity.getId().getEntityType().name());
125   - ps.setString(2, kvEntity.getId().getEntityId());
  126 + ps.setObject(2, kvEntity.getId().getEntityId());
126 127 ps.setString(3, kvEntity.getId().getAttributeType());
127 128 ps.setString(4, kvEntity.getId().getAttributeKey());
128 129
... ...
... ... @@ -26,6 +26,7 @@ import org.thingsboard.server.dao.model.sql.AttributeKvEntity;
26 26 import org.thingsboard.server.dao.util.SqlDao;
27 27
28 28 import java.util.List;
  29 +import java.util.UUID;
29 30
30 31 @SqlDao
31 32 public interface AttributeKvRepository extends CrudRepository<AttributeKvEntity, AttributeKvCompositeKey> {
... ... @@ -34,7 +35,7 @@ public interface AttributeKvRepository extends CrudRepository<AttributeKvEntity,
34 35 "AND a.id.entityId = :entityId " +
35 36 "AND a.id.attributeType = :attributeType")
36 37 List<AttributeKvEntity> findAllByEntityTypeAndEntityIdAndAttributeType(@Param("entityType") EntityType entityType,
37   - @Param("entityId") String entityId,
  38 + @Param("entityId") UUID entityId,
38 39 @Param("attributeType") String attributeType);
39 40
40 41 @Transactional
... ... @@ -44,7 +45,7 @@ public interface AttributeKvRepository extends CrudRepository<AttributeKvEntity,
44 45 "AND a.id.attributeType = :attributeType " +
45 46 "AND a.id.attributeKey = :attributeKey")
46 47 void delete(@Param("entityType") EntityType entityType,
47   - @Param("entityId") String entityId,
  48 + @Param("entityId") UUID entityId,
48 49 @Param("attributeType") String attributeType,
49 50 @Param("attributeKey") String attributeKey);
50 51 }
... ...
... ... @@ -46,7 +46,7 @@ public class HsqlAttributesInsertRepository extends AttributeKvInsertRepository
46 46 entities.forEach(entity -> {
47 47 jdbcTemplate.update(INSERT_OR_UPDATE, ps -> {
48 48 ps.setString(1, entity.getId().getEntityType().name());
49   - ps.setString(2, entity.getId().getEntityId());
  49 + ps.setObject(2, entity.getId().getEntityId());
50 50 ps.setString(3, entity.getId().getAttributeType());
51 51 ps.setString(4, entity.getId().getAttributeKey());
52 52 ps.setString(5, entity.getStrValue());
... ...
... ... @@ -22,7 +22,6 @@ import lombok.extern.slf4j.Slf4j;
22 22 import org.springframework.beans.factory.annotation.Autowired;
23 23 import org.springframework.beans.factory.annotation.Value;
24 24 import org.springframework.stereotype.Component;
25   -import org.thingsboard.server.common.data.UUIDConverter;
26 25 import org.thingsboard.server.common.data.id.EntityId;
27 26 import org.thingsboard.server.common.data.id.TenantId;
28 27 import org.thingsboard.server.common.data.kv.AttributeKvEntry;
... ... @@ -43,8 +42,6 @@ import java.util.List;
43 42 import java.util.Optional;
44 43 import java.util.stream.Collectors;
45 44
46   -import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID;
47   -
48 45 @Component
49 46 @Slf4j
50 47 @SqlDao
... ... @@ -115,14 +112,14 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl
115 112 DaoUtil.convertDataList(Lists.newArrayList(
116 113 attributeKvRepository.findAllByEntityTypeAndEntityIdAndAttributeType(
117 114 entityId.getEntityType(),
118   - UUIDConverter.fromTimeUUID(entityId.getId()),
  115 + entityId.getId(),
119 116 attributeType))));
120 117 }
121 118
122 119 @Override
123 120 public ListenableFuture<Void> save(TenantId tenantId, EntityId entityId, String attributeType, AttributeKvEntry attribute) {
124 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 123 entity.setLastUpdateTs(attribute.getLastUpdateTs());
127 124 entity.setStrValue(attribute.getStrValue().orElse(null));
128 125 entity.setDoubleValue(attribute.getDoubleValue().orElse(null));
... ... @@ -140,7 +137,7 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl
140 137 public ListenableFuture<List<Void>> removeAll(TenantId tenantId, EntityId entityId, String attributeType, List<String> keys) {
141 138 return service.submit(() -> {
142 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 142 return null;
146 143 });
... ... @@ -149,7 +146,7 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl
149 146 private AttributeKvCompositeKey getAttributeKvCompositeKey(EntityId entityId, String attributeType, String attributeKey) {
150 147 return new AttributeKvCompositeKey(
151 148 entityId.getEntityType(),
152   - fromTimeUUID(entityId.getId()),
  149 + entityId.getId(),
153 150 attributeType,
154 151 attributeKey);
155 152 }
... ...
... ... @@ -25,8 +25,9 @@ import org.thingsboard.server.common.data.audit.ActionType;
25 25 import org.thingsboard.server.dao.model.sql.AuditLogEntity;
26 26
27 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 32 @Query("SELECT a FROM AuditLogEntity a WHERE " +
32 33 "a.tenantId = :tenantId " +
... ... @@ -40,7 +41,7 @@ public interface AuditLogRepository extends PagingAndSortingRepository<AuditLogE
40 41 "OR LOWER(a.actionStatus) LIKE LOWER(CONCAT(:textSearch, '%')))"
41 42 )
42 43 Page<AuditLogEntity> findByTenantId(
43   - @Param("tenantId") String tenantId,
  44 + @Param("tenantId") UUID tenantId,
44 45 @Param("textSearch") String textSearch,
45 46 @Param("startId") String startId,
46 47 @Param("endId") String endId,
... ... @@ -58,9 +59,9 @@ public interface AuditLogRepository extends PagingAndSortingRepository<AuditLogE
58 59 "OR LOWER(a.actionType) LIKE LOWER(CONCAT(:textSearch, '%'))" +
59 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 63 @Param("entityType") EntityType entityType,
63   - @Param("entityId") String entityId,
  64 + @Param("entityId") UUID entityId,
64 65 @Param("textSearch") String textSearch,
65 66 @Param("startId") String startId,
66 67 @Param("endId") String endId,
... ... @@ -79,8 +80,8 @@ public interface AuditLogRepository extends PagingAndSortingRepository<AuditLogE
79 80 "OR LOWER(a.actionType) LIKE LOWER(CONCAT(:textSearch, '%'))" +
80 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 85 @Param("textSearch") String textSearch,
85 86 @Param("startId") String startId,
86 87 @Param("endId") String endId,
... ... @@ -98,8 +99,8 @@ public interface AuditLogRepository extends PagingAndSortingRepository<AuditLogE
98 99 "OR LOWER(a.actionType) LIKE LOWER(CONCAT(:textSearch, '%'))" +
99 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 104 @Param("textSearch") String textSearch,
104 105 @Param("startId") String startId,
105 106 @Param("endId") String endId,
... ...
... ... @@ -36,7 +36,6 @@ import java.util.List;
36 36 import java.util.Objects;
37 37 import java.util.UUID;
38 38
39   -import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID;
40 39 import static org.thingsboard.server.dao.DaoUtil.endTimeToId;
41 40 import static org.thingsboard.server.dao.DaoUtil.startTimeToId;
42 41
... ... @@ -53,7 +52,7 @@ public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> imp
53 52 }
54 53
55 54 @Override
56   - protected CrudRepository<AuditLogEntity, String> getCrudRepository() {
  55 + protected CrudRepository<AuditLogEntity, UUID> getCrudRepository() {
57 56 return auditLogRepository;
58 57 }
59 58
... ... @@ -70,9 +69,9 @@ public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> imp
70 69 return DaoUtil.toPageData(
71 70 auditLogRepository
72 71 .findAuditLogsByTenantIdAndEntityId(
73   - fromTimeUUID(tenantId),
  72 + tenantId,
74 73 entityId.getEntityType(),
75   - fromTimeUUID(entityId.getId()),
  74 + entityId.getId(),
76 75 Objects.toString(pageLink.getTextSearch(), ""),
77 76 startTimeToId(pageLink.getStartTime()),
78 77 endTimeToId(pageLink.getEndTime()),
... ... @@ -85,8 +84,8 @@ public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> imp
85 84 return DaoUtil.toPageData(
86 85 auditLogRepository
87 86 .findAuditLogsByTenantIdAndCustomerId(
88   - fromTimeUUID(tenantId),
89   - fromTimeUUID(customerId.getId()),
  87 + tenantId,
  88 + customerId.getId(),
90 89 Objects.toString(pageLink.getTextSearch(), ""),
91 90 startTimeToId(pageLink.getStartTime()),
92 91 endTimeToId(pageLink.getEndTime()),
... ... @@ -99,8 +98,8 @@ public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> imp
99 98 return DaoUtil.toPageData(
100 99 auditLogRepository
101 100 .findAuditLogsByTenantIdAndUserId(
102   - fromTimeUUID(tenantId),
103   - fromTimeUUID(userId.getId()),
  101 + tenantId,
  102 + userId.getId(),
104 103 Objects.toString(pageLink.getTextSearch(), ""),
105 104 startTimeToId(pageLink.getStartTime()),
106 105 endTimeToId(pageLink.getEndTime()),
... ... @@ -112,7 +111,7 @@ public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> imp
112 111 public PageData<AuditLog> findAuditLogsByTenantId(UUID tenantId, List<ActionType> actionTypes, TimePageLink pageLink) {
113 112 return DaoUtil.toPageData(
114 113 auditLogRepository.findByTenantId(
115   - fromTimeUUID(tenantId),
  114 + tenantId,
116 115 Objects.toString(pageLink.getTextSearch(), ""),
117 116 startTimeToId(pageLink.getStartTime()),
118 117 endTimeToId(pageLink.getEndTime()),
... ...
... ... @@ -23,7 +23,6 @@ import org.springframework.transaction.PlatformTransactionManager;
23 23 import org.springframework.transaction.TransactionDefinition;
24 24 import org.springframework.transaction.TransactionStatus;
25 25 import org.springframework.transaction.support.DefaultTransactionDefinition;
26   -import org.thingsboard.server.common.data.UUIDConverter;
27 26 import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity;
28 27
29 28 import javax.persistence.EntityManager;
... ... @@ -69,7 +68,8 @@ public abstract class AbstractComponentDescriptorInsertRepository implements Com
69 68
70 69 protected Query getQuery(ComponentDescriptorEntity entity, String query) {
71 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 73 .setParameter("actions", entity.getActions())
74 74 .setParameter("clazz", entity.getClazz())
75 75 .setParameter("configuration_descriptor", entity.getConfigurationDescriptor().toString())
... ...
... ... @@ -18,7 +18,6 @@ package org.thingsboard.server.dao.sql.component;
18 18 import org.springframework.data.domain.Page;
19 19 import org.springframework.data.domain.Pageable;
20 20 import org.springframework.data.jpa.repository.Query;
21   -import org.springframework.data.repository.CrudRepository;
22 21 import org.springframework.data.repository.PagingAndSortingRepository;
23 22 import org.springframework.data.repository.query.Param;
24 23 import org.thingsboard.server.common.data.plugin.ComponentScope;
... ... @@ -26,13 +25,13 @@ import org.thingsboard.server.common.data.plugin.ComponentType;
26 25 import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity;
27 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 31 * Created by Valerii Sosliuk on 5/6/2017.
33 32 */
34 33 @SqlDao
35   -public interface ComponentDescriptorRepository extends PagingAndSortingRepository<ComponentDescriptorEntity, String> {
  34 +public interface ComponentDescriptorRepository extends PagingAndSortingRepository<ComponentDescriptorEntity, UUID> {
36 35
37 36 ComponentDescriptorEntity findByClazz(String clazz);
38 37
... ...
... ... @@ -16,7 +16,6 @@
16 16 package org.thingsboard.server.dao.sql.component;
17 17
18 18 import org.springframework.stereotype.Repository;
19   -import org.thingsboard.server.common.data.UUIDConverter;
20 19 import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity;
21 20 import org.thingsboard.server.dao.util.HsqlDao;
22 21 import org.thingsboard.server.dao.util.SqlDao;
... ... @@ -40,11 +39,11 @@ public class HsqlComponentDescriptorInsertRepository extends AbstractComponentDe
40 39 @Override
41 40 protected ComponentDescriptorEntity doProcessSaveOrUpdate(ComponentDescriptorEntity entity, String query) {
42 41 getQuery(entity, query).executeUpdate();
43   - return entityManager.find(ComponentDescriptorEntity.class, UUIDConverter.fromTimeUUID(entity.getUuid()));
  42 + return entityManager.find(ComponentDescriptorEntity.class, entity.getUuid());
44 43 }
45 44
46 45 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)";
  46 + return "MERGE INTO component_descriptor USING (VALUES :id, :created_time, :actions, :clazz, :configuration_descriptor, :name, :scope, :search_text, :type) I (id, craeted_time, 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" +
  47 + " WHEN NOT MATCHED THEN INSERT (id, created_time, actions, clazz, configuration_descriptor, name, scope, search_text, type) VALUES (I.id, I.created_time, I.actions, I.clazz, I.configuration_descriptor, I.name, I.scope, I.search_text, I.type)";
49 48 }
50 49 }
... ...
... ... @@ -5,7 +5,7 @@
5 5 * you may not use this file except in compliance with the License.
6 6 * You may obtain a copy of the License at
7 7 *
8   - * http://www.apache.org/licenses/LICENSE-2.0
  8 + * http://www.apache.org/licenses/LICENSE-2.0
9 9 *
10 10 * Unless required by applicable law or agreed to in writing, software
11 11 * distributed under the License is distributed on an "AS IS" BASIS,
... ... @@ -20,7 +20,6 @@ import org.springframework.beans.factory.annotation.Autowired;
20 20 import org.springframework.data.repository.CrudRepository;
21 21 import org.springframework.stereotype.Component;
22 22 import org.springframework.transaction.annotation.Transactional;
23   -import org.thingsboard.server.common.data.UUIDConverter;
24 23 import org.thingsboard.server.common.data.id.ComponentDescriptorId;
25 24 import org.thingsboard.server.common.data.id.TenantId;
26 25 import org.thingsboard.server.common.data.page.PageData;
... ... @@ -36,6 +35,7 @@ import org.thingsboard.server.dao.util.SqlDao;
36 35
37 36 import java.util.Objects;
38 37 import java.util.Optional;
  38 +import java.util.UUID;
39 39
40 40 /**
41 41 * Created by Valerii Sosliuk on 5/6/2017.
... ... @@ -57,16 +57,18 @@ public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<Comp
57 57 }
58 58
59 59 @Override
60   - protected CrudRepository<ComponentDescriptorEntity, String> getCrudRepository() {
  60 + protected CrudRepository<ComponentDescriptorEntity, UUID> getCrudRepository() {
61 61 return componentDescriptorRepository;
62 62 }
63 63
64 64 @Override
65 65 public Optional<ComponentDescriptor> saveIfNotExist(TenantId tenantId, ComponentDescriptor component) {
66 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 72 ComponentDescriptorEntity componentDescriptorEntity = new ComponentDescriptorEntity(component);
71 73 ComponentDescriptorEntity savedEntity = componentDescriptorInsertRepository.saveOrUpdate(componentDescriptorEntity);
72 74 return Optional.of(savedEntity.toData());
... ...
... ... @@ -19,7 +19,6 @@ import org.springframework.stereotype.Repository;
19 19 import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity;
20 20 import org.thingsboard.server.dao.util.PsqlDao;
21 21 import org.thingsboard.server.dao.util.SqlDao;
22   -import org.thingsboard.server.dao.util.SqlTsDao;
23 22
24 23 @SqlDao
25 24 @PsqlDao
... ... @@ -49,10 +48,10 @@ public class PsqlComponentDescriptorInsertRepository extends AbstractComponentDe
49 48 }
50 49
51 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 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 18 import org.springframework.data.domain.Page;
19 19 import org.springframework.data.domain.Pageable;
20 20 import org.springframework.data.jpa.repository.Query;
21   -import org.springframework.data.repository.CrudRepository;
22 21 import org.springframework.data.repository.PagingAndSortingRepository;
23 22 import org.springframework.data.repository.query.Param;
24 23 import org.thingsboard.server.dao.model.sql.CustomerEntity;
25 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 29 * Created by Valerii Sosliuk on 5/6/2017.
31 30 */
32 31 @SqlDao
33   -public interface CustomerRepository extends PagingAndSortingRepository<CustomerEntity, String> {
  32 +public interface CustomerRepository extends PagingAndSortingRepository<CustomerEntity, UUID> {
34 33
35 34 @Query("SELECT c FROM CustomerEntity c WHERE c.tenantId = :tenantId " +
36 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 37 @Param("textSearch") String textSearch,
39 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 19 import org.springframework.data.repository.CrudRepository;
20 20 import org.springframework.stereotype.Component;
21 21 import org.thingsboard.server.common.data.Customer;
22   -import org.thingsboard.server.common.data.UUIDConverter;
23 22 import org.thingsboard.server.common.data.page.PageData;
24 23 import org.thingsboard.server.common.data.page.PageLink;
25 24 import org.thingsboard.server.dao.DaoUtil;
... ... @@ -48,21 +47,21 @@ public class JpaCustomerDao extends JpaAbstractSearchTextDao<CustomerEntity, Cus
48 47 }
49 48
50 49 @Override
51   - protected CrudRepository<CustomerEntity, String> getCrudRepository() {
  50 + protected CrudRepository<CustomerEntity, UUID> getCrudRepository() {
52 51 return customerRepository;
53 52 }
54 53
55 54 @Override
56 55 public PageData<Customer> findCustomersByTenantId(UUID tenantId, PageLink pageLink) {
57 56 return DaoUtil.toPageData(customerRepository.findByTenantId(
58   - UUIDConverter.fromTimeUUID(tenantId),
  57 + tenantId,
59 58 Objects.toString(pageLink.getTextSearch(), ""),
60 59 DaoUtil.toPageable(pageLink)));
61 60 }
62 61
63 62 @Override
64 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 65 return Optional.ofNullable(customer);
67 66 }
68 67 }
... ...
... ... @@ -18,23 +18,22 @@ package org.thingsboard.server.dao.sql.dashboard;
18 18 import org.springframework.data.domain.Page;
19 19 import org.springframework.data.domain.Pageable;
20 20 import org.springframework.data.jpa.repository.Query;
21   -import org.springframework.data.repository.CrudRepository;
22 21 import org.springframework.data.repository.PagingAndSortingRepository;
23 22 import org.springframework.data.repository.query.Param;
24 23 import org.thingsboard.server.dao.model.sql.DashboardInfoEntity;
25 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 29 * Created by Valerii Sosliuk on 5/6/2017.
31 30 */
32 31 @SqlDao
33   -public interface DashboardInfoRepository extends PagingAndSortingRepository<DashboardInfoEntity, String> {
  32 +public interface DashboardInfoRepository extends PagingAndSortingRepository<DashboardInfoEntity, UUID> {
34 33
35 34 @Query("SELECT di FROM DashboardInfoEntity di WHERE di.tenantId = :tenantId " +
36 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 37 @Param("searchText") String searchText,
39 38 Pageable pageable);
40 39
... ... @@ -42,8 +41,8 @@ public interface DashboardInfoRepository extends PagingAndSortingRepository<Dash
42 41 "AND di.id = re.toId AND re.toType = 'DASHBOARD' AND re.relationTypeGroup = 'DASHBOARD' " +
43 42 "AND re.relationType = 'Contains' AND re.fromId = :customerId AND re.fromType = 'CUSTOMER' " +
44 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 46 @Param("searchText") String searchText,
48 47 Pageable pageable);
49 48
... ...
... ... @@ -19,9 +19,11 @@ import org.springframework.data.repository.CrudRepository;
19 19 import org.thingsboard.server.dao.model.sql.DashboardEntity;
20 20 import org.thingsboard.server.dao.util.SqlDao;
21 21
  22 +import java.util.UUID;
  23 +
22 24 /**
23 25 * Created by Valerii Sosliuk on 5/6/2017.
24 26 */
25 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 24 import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
25 25 import org.thingsboard.server.dao.util.SqlDao;
26 26
  27 +import java.util.UUID;
  28 +
27 29 /**
28 30 * Created by Valerii Sosliuk on 5/6/2017.
29 31 */
... ... @@ -40,7 +42,7 @@ public class JpaDashboardDao extends JpaAbstractSearchTextDao<DashboardEntity, D
40 42 }
41 43
42 44 @Override
43   - protected CrudRepository<DashboardEntity, String> getCrudRepository() {
  45 + protected CrudRepository<DashboardEntity, UUID> getCrudRepository() {
44 46 return dashboardRepository;
45 47 }
46 48 }
... ...
... ... @@ -20,7 +20,6 @@ import org.springframework.beans.factory.annotation.Autowired;
20 20 import org.springframework.data.repository.CrudRepository;
21 21 import org.springframework.stereotype.Component;
22 22 import org.thingsboard.server.common.data.DashboardInfo;
23   -import org.thingsboard.server.common.data.UUIDConverter;
24 23 import org.thingsboard.server.common.data.page.PageData;
25 24 import org.thingsboard.server.common.data.page.PageLink;
26 25 import org.thingsboard.server.dao.DaoUtil;
... ... @@ -61,7 +60,7 @@ public class JpaDashboardInfoDao extends JpaAbstractSearchTextDao<DashboardInfoE
61 60 public PageData<DashboardInfo> findDashboardsByTenantId(UUID tenantId, PageLink pageLink) {
62 61 return DaoUtil.toPageData(dashboardInfoRepository
63 62 .findByTenantId(
64   - UUIDConverter.fromTimeUUID(tenantId),
  63 + tenantId,
65 64 Objects.toString(pageLink.getTextSearch(), ""),
66 65 DaoUtil.toPageable(pageLink)));
67 66 }
... ... @@ -70,8 +69,8 @@ public class JpaDashboardInfoDao extends JpaAbstractSearchTextDao<DashboardInfoE
70 69 public PageData<DashboardInfo> findDashboardsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink) {
71 70 return DaoUtil.toPageData(dashboardInfoRepository
72 71 .findByTenantIdAndCustomerId(
73   - UUIDConverter.fromTimeUUID(tenantId),
74   - UUIDConverter.fromTimeUUID(customerId),
  72 + tenantId,
  73 + customerId,
75 74 Objects.toString(pageLink.getTextSearch(), ""),
76 75 DaoUtil.toPageable(pageLink)));
77 76 }
... ...
... ... @@ -19,13 +19,15 @@ import org.springframework.data.repository.CrudRepository;
19 19 import org.thingsboard.server.dao.model.sql.DeviceCredentialsEntity;
20 20 import org.thingsboard.server.dao.util.SqlDao;
21 21
  22 +import java.util.UUID;
  23 +
22 24 /**
23 25 * Created by Valerii Sosliuk on 5/6/2017.
24 26 */
25 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 32 DeviceCredentialsEntity findByCredentialsId(String credentialsId);
31 33 }
... ...
... ... @@ -25,24 +25,25 @@ import org.thingsboard.server.dao.model.sql.DeviceInfoEntity;
25 25 import org.thingsboard.server.dao.util.SqlDao;
26 26
27 27 import java.util.List;
  28 +import java.util.UUID;
28 29
29 30 /**
30 31 * Created by Valerii Sosliuk on 5/6/2017.
31 32 */
32 33 @SqlDao
33   -public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntity, String> {
  34 +public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntity, UUID> {
34 35
35 36 @Query("SELECT new org.thingsboard.server.dao.model.sql.DeviceInfoEntity(d, c.title, c.additionalInfo) " +
36 37 "FROM DeviceEntity d " +
37 38 "LEFT JOIN CustomerEntity c on c.id = d.customerId " +
38 39 "WHERE d.id = :deviceId")
39   - DeviceInfoEntity findDeviceInfoById(@Param("deviceId") String deviceId);
  40 + DeviceInfoEntity findDeviceInfoById(@Param("deviceId") UUID deviceId);
40 41
41 42 @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " +
42 43 "AND d.customerId = :customerId " +
43 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 47 @Param("searchText") String searchText,
47 48 Pageable pageable);
48 49
... ... @@ -52,18 +53,18 @@ public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntit
52 53 "WHERE d.tenantId = :tenantId " +
53 54 "AND d.customerId = :customerId " +
54 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 58 @Param("searchText") String searchText,
58 59 Pageable pageable);
59 60
60 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 63 Pageable pageable);
63 64
64 65 @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " +
65 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 68 @Param("textSearch") String textSearch,
68 69 Pageable pageable);
69 70
... ... @@ -72,14 +73,14 @@ public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntit
72 73 "LEFT JOIN CustomerEntity c on c.id = d.customerId " +
73 74 "WHERE d.tenantId = :tenantId " +
74 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 77 @Param("textSearch") String textSearch,
77 78 Pageable pageable);
78 79
79 80 @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " +
80 81 "AND d.type = :type " +
81 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 84 @Param("type") String type,
84 85 @Param("textSearch") String textSearch,
85 86 Pageable pageable);
... ... @@ -90,7 +91,7 @@ public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntit
90 91 "WHERE d.tenantId = :tenantId " +
91 92 "AND d.type = :type " +
92 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 95 @Param("type") String type,
95 96 @Param("textSearch") String textSearch,
96 97 Pageable pageable);
... ... @@ -99,8 +100,8 @@ public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntit
99 100 "AND d.customerId = :customerId " +
100 101 "AND d.type = :type " +
101 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 105 @Param("type") String type,
105 106 @Param("textSearch") String textSearch,
106 107 Pageable pageable);
... ... @@ -112,18 +113,18 @@ public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntit
112 113 "AND d.customerId = :customerId " +
113 114 "AND d.type = :type " +
114 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 118 @Param("type") String type,
118 119 @Param("textSearch") String textSearch,
119 120 Pageable pageable);
120 121
121 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 18 import org.springframework.beans.factory.annotation.Autowired;
19 19 import org.springframework.data.repository.CrudRepository;
20 20 import org.springframework.stereotype.Component;
21   -import org.thingsboard.server.common.data.UUIDConverter;
22 21 import org.thingsboard.server.common.data.id.TenantId;
23 22 import org.thingsboard.server.common.data.security.DeviceCredentials;
24 23 import org.thingsboard.server.dao.DaoUtil;
... ... @@ -45,13 +44,13 @@ public class JpaDeviceCredentialsDao extends JpaAbstractDao<DeviceCredentialsEnt
45 44 }
46 45
47 46 @Override
48   - protected CrudRepository<DeviceCredentialsEntity, String> getCrudRepository() {
  47 + protected CrudRepository<DeviceCredentialsEntity, UUID> getCrudRepository() {
49 48 return deviceCredentialsRepository;
50 49 }
51 50
52 51 @Override
53 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 56 @Override
... ...
... ... @@ -24,7 +24,6 @@ import org.thingsboard.server.common.data.Device;
24 24 import org.thingsboard.server.common.data.DeviceInfo;
25 25 import org.thingsboard.server.common.data.EntitySubtype;
26 26 import org.thingsboard.server.common.data.EntityType;
27   -import org.thingsboard.server.common.data.UUIDConverter;
28 27 import org.thingsboard.server.common.data.id.TenantId;
29 28 import org.thingsboard.server.common.data.page.PageData;
30 29 import org.thingsboard.server.common.data.page.PageLink;
... ... @@ -42,9 +41,6 @@ import java.util.Objects;
42 41 import java.util.Optional;
43 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 45 * Created by Valerii Sosliuk on 5/6/2017.
50 46 */
... ... @@ -61,13 +57,13 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device>
61 57 }
62 58
63 59 @Override
64   - protected CrudRepository<DeviceEntity, String> getCrudRepository() {
  60 + protected CrudRepository<DeviceEntity, UUID> getCrudRepository() {
65 61 return deviceRepository;
66 62 }
67 63
68 64 @Override
69 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 69 @Override
... ... @@ -75,12 +71,12 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device>
75 71 if (StringUtils.isEmpty(pageLink.getTextSearch())) {
76 72 return DaoUtil.toPageData(
77 73 deviceRepository.findByTenantId(
78   - fromTimeUUID(tenantId),
  74 + tenantId,
79 75 DaoUtil.toPageable(pageLink)));
80 76 } else {
81 77 return DaoUtil.toPageData(
82 78 deviceRepository.findByTenantId(
83   - fromTimeUUID(tenantId),
  79 + tenantId,
84 80 Objects.toString(pageLink.getTextSearch(), ""),
85 81 DaoUtil.toPageable(pageLink)));
86 82 }
... ... @@ -90,22 +86,22 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device>
90 86 public PageData<DeviceInfo> findDeviceInfosByTenantId(UUID tenantId, PageLink pageLink) {
91 87 return DaoUtil.toPageData(
92 88 deviceRepository.findDeviceInfosByTenantId(
93   - fromTimeUUID(tenantId),
  89 + tenantId,
94 90 Objects.toString(pageLink.getTextSearch(), ""),
95 91 DaoUtil.toPageable(pageLink, DeviceInfoEntity.deviceInfoColumnMap)));
96 92 }
97 93
98 94 @Override
99 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 99 @Override
104 100 public PageData<Device> findDevicesByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink) {
105 101 return DaoUtil.toPageData(
106 102 deviceRepository.findByTenantIdAndCustomerId(
107   - fromTimeUUID(tenantId),
108   - fromTimeUUID(customerId),
  103 + tenantId,
  104 + customerId,
109 105 Objects.toString(pageLink.getTextSearch(), ""),
110 106 DaoUtil.toPageable(pageLink)));
111 107 }
... ... @@ -114,8 +110,8 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device>
114 110 public PageData<DeviceInfo> findDeviceInfosByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink) {
115 111 return DaoUtil.toPageData(
116 112 deviceRepository.findDeviceInfosByTenantIdAndCustomerId(
117   - fromTimeUUID(tenantId),
118   - fromTimeUUID(customerId),
  113 + tenantId,
  114 + customerId,
119 115 Objects.toString(pageLink.getTextSearch(), ""),
120 116 DaoUtil.toPageable(pageLink, DeviceInfoEntity.deviceInfoColumnMap)));
121 117 }
... ... @@ -123,12 +119,12 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device>
123 119 @Override
124 120 public ListenableFuture<List<Device>> findDevicesByTenantIdCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> deviceIds) {
125 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 125 @Override
130 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 128 return Optional.ofNullable(device);
133 129 }
134 130
... ... @@ -136,7 +132,7 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device>
136 132 public PageData<Device> findDevicesByTenantIdAndType(UUID tenantId, String type, PageLink pageLink) {
137 133 return DaoUtil.toPageData(
138 134 deviceRepository.findByTenantIdAndType(
139   - fromTimeUUID(tenantId),
  135 + tenantId,
140 136 type,
141 137 Objects.toString(pageLink.getTextSearch(), ""),
142 138 DaoUtil.toPageable(pageLink)));
... ... @@ -146,7 +142,7 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device>
146 142 public PageData<DeviceInfo> findDeviceInfosByTenantIdAndType(UUID tenantId, String type, PageLink pageLink) {
147 143 return DaoUtil.toPageData(
148 144 deviceRepository.findDeviceInfosByTenantIdAndType(
149   - fromTimeUUID(tenantId),
  145 + tenantId,
150 146 type,
151 147 Objects.toString(pageLink.getTextSearch(), ""),
152 148 DaoUtil.toPageable(pageLink, DeviceInfoEntity.deviceInfoColumnMap)));
... ... @@ -156,8 +152,8 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device>
156 152 public PageData<Device> findDevicesByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink) {
157 153 return DaoUtil.toPageData(
158 154 deviceRepository.findByTenantIdAndCustomerIdAndType(
159   - fromTimeUUID(tenantId),
160   - fromTimeUUID(customerId),
  155 + tenantId,
  156 + customerId,
161 157 type,
162 158 Objects.toString(pageLink.getTextSearch(), ""),
163 159 DaoUtil.toPageable(pageLink)));
... ... @@ -167,8 +163,8 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device>
167 163 public PageData<DeviceInfo> findDeviceInfosByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink) {
168 164 return DaoUtil.toPageData(
169 165 deviceRepository.findDeviceInfosByTenantIdAndCustomerIdAndType(
170   - fromTimeUUID(tenantId),
171   - fromTimeUUID(customerId),
  166 + tenantId,
  167 + customerId,
172 168 type,
173 169 Objects.toString(pageLink.getTextSearch(), ""),
174 170 DaoUtil.toPageable(pageLink, DeviceInfoEntity.deviceInfoColumnMap)));
... ... @@ -176,7 +172,7 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device>
176 172
177 173 @Override
178 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 178 private List<EntitySubtype> convertTenantDeviceTypesToDto(UUID tenantId, List<String> types) {
... ...
... ... @@ -18,7 +18,6 @@ package org.thingsboard.server.dao.sql.entityview;
18 18 import org.springframework.data.domain.Page;
19 19 import org.springframework.data.domain.Pageable;
20 20 import org.springframework.data.jpa.repository.Query;
21   -import org.springframework.data.repository.CrudRepository;
22 21 import org.springframework.data.repository.PagingAndSortingRepository;
23 22 import org.springframework.data.repository.query.Param;
24 23 import org.thingsboard.server.dao.model.sql.EntityViewEntity;
... ... @@ -26,22 +25,23 @@ import org.thingsboard.server.dao.model.sql.EntityViewInfoEntity;
26 25 import org.thingsboard.server.dao.util.SqlDao;
27 26
28 27 import java.util.List;
  28 +import java.util.UUID;
29 29
30 30 /**
31 31 * Created by Victor Basanets on 8/31/2017.
32 32 */
33 33 @SqlDao
34   -public interface EntityViewRepository extends PagingAndSortingRepository<EntityViewEntity, String> {
  34 +public interface EntityViewRepository extends PagingAndSortingRepository<EntityViewEntity, UUID> {
35 35
36 36 @Query("SELECT new org.thingsboard.server.dao.model.sql.EntityViewInfoEntity(e, c.title, c.additionalInfo) " +
37 37 "FROM EntityViewEntity e " +
38 38 "LEFT JOIN CustomerEntity c on c.id = e.customerId " +
39 39 "WHERE e.id = :entityViewId")
40   - EntityViewInfoEntity findEntityViewInfoById(@Param("entityViewId") String entityViewId);
  40 + EntityViewInfoEntity findEntityViewInfoById(@Param("entityViewId") UUID entityViewId);
41 41
42 42 @Query("SELECT e FROM EntityViewEntity e WHERE e.tenantId = :tenantId " +
43 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 45 @Param("textSearch") String textSearch,
46 46 Pageable pageable);
47 47
... ... @@ -50,14 +50,14 @@ public interface EntityViewRepository extends PagingAndSortingRepository<EntityV
50 50 "LEFT JOIN CustomerEntity c on c.id = e.customerId " +
51 51 "WHERE e.tenantId = :tenantId " +
52 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 54 @Param("textSearch") String textSearch,
55 55 Pageable pageable);
56 56
57 57 @Query("SELECT e FROM EntityViewEntity e WHERE e.tenantId = :tenantId " +
58 58 "AND e.type = :type " +
59 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 61 @Param("type") String type,
62 62 @Param("textSearch") String textSearch,
63 63 Pageable pageable);
... ... @@ -68,7 +68,7 @@ public interface EntityViewRepository extends PagingAndSortingRepository<EntityV
68 68 "WHERE e.tenantId = :tenantId " +
69 69 "AND e.type = :type " +
70 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 72 @Param("type") String type,
73 73 @Param("textSearch") String textSearch,
74 74 Pageable pageable);
... ... @@ -76,8 +76,8 @@ public interface EntityViewRepository extends PagingAndSortingRepository<EntityV
76 76 @Query("SELECT e FROM EntityViewEntity e WHERE e.tenantId = :tenantId " +
77 77 "AND e.customerId = :customerId " +
78 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 81 @Param("searchText") String searchText,
82 82 Pageable pageable);
83 83
... ... @@ -87,8 +87,8 @@ public interface EntityViewRepository extends PagingAndSortingRepository<EntityV
87 87 "WHERE e.tenantId = :tenantId " +
88 88 "AND e.customerId = :customerId " +
89 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 92 @Param("searchText") String searchText,
93 93 Pageable pageable);
94 94
... ... @@ -96,8 +96,8 @@ public interface EntityViewRepository extends PagingAndSortingRepository<EntityV
96 96 "AND e.customerId = :customerId " +
97 97 "AND e.type = :type " +
98 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 101 @Param("type") String type,
102 102 @Param("searchText") String searchText,
103 103 Pageable pageable);
... ... @@ -109,16 +109,16 @@ public interface EntityViewRepository extends PagingAndSortingRepository<EntityV
109 109 "AND e.customerId = :customerId " +
110 110 "AND e.type = :type " +
111 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 114 @Param("type") String type,
115 115 @Param("textSearch") String textSearch,
116 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 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 19 import org.springframework.beans.factory.annotation.Autowired;
20 20 import org.springframework.data.repository.CrudRepository;
21 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 26 import org.thingsboard.server.common.data.id.TenantId;
24 27 import org.thingsboard.server.common.data.page.PageData;
25 28 import org.thingsboard.server.common.data.page.PageLink;
... ... @@ -37,8 +40,6 @@ import java.util.Objects;
37 40 import java.util.Optional;
38 41 import java.util.UUID;
39 42
40   -import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID;
41   -
42 43 /**
43 44 * Created by Victor Basanets on 8/31/2017.
44 45 */
... ... @@ -56,20 +57,20 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity,
56 57 }
57 58
58 59 @Override
59   - protected CrudRepository<EntityViewEntity, String> getCrudRepository() {
  60 + protected CrudRepository<EntityViewEntity, UUID> getCrudRepository() {
60 61 return entityViewRepository;
61 62 }
62 63
63 64 @Override
64 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 69 @Override
69 70 public PageData<EntityView> findEntityViewsByTenantId(UUID tenantId, PageLink pageLink) {
70 71 return DaoUtil.toPageData(
71 72 entityViewRepository.findByTenantId(
72   - fromTimeUUID(tenantId),
  73 + tenantId,
73 74 Objects.toString(pageLink.getTextSearch(), ""),
74 75 DaoUtil.toPageable(pageLink)));
75 76 }
... ... @@ -78,7 +79,7 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity,
78 79 public PageData<EntityViewInfo> findEntityViewInfosByTenantId(UUID tenantId, PageLink pageLink) {
79 80 return DaoUtil.toPageData(
80 81 entityViewRepository.findEntityViewInfosByTenantId(
81   - fromTimeUUID(tenantId),
  82 + tenantId,
82 83 Objects.toString(pageLink.getTextSearch(), ""),
83 84 DaoUtil.toPageable(pageLink, EntityViewInfoEntity.entityViewInfoColumnMap)));
84 85 }
... ... @@ -87,7 +88,7 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity,
87 88 public PageData<EntityView> findEntityViewsByTenantIdAndType(UUID tenantId, String type, PageLink pageLink) {
88 89 return DaoUtil.toPageData(
89 90 entityViewRepository.findByTenantIdAndType(
90   - fromTimeUUID(tenantId),
  91 + tenantId,
91 92 type,
92 93 Objects.toString(pageLink.getTextSearch(), ""),
93 94 DaoUtil.toPageable(pageLink)));
... ... @@ -97,7 +98,7 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity,
97 98 public PageData<EntityViewInfo> findEntityViewInfosByTenantIdAndType(UUID tenantId, String type, PageLink pageLink) {
98 99 return DaoUtil.toPageData(
99 100 entityViewRepository.findEntityViewInfosByTenantIdAndType(
100   - fromTimeUUID(tenantId),
  101 + tenantId,
101 102 type,
102 103 Objects.toString(pageLink.getTextSearch(), ""),
103 104 DaoUtil.toPageable(pageLink, EntityViewInfoEntity.entityViewInfoColumnMap)));
... ... @@ -106,7 +107,7 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity,
106 107 @Override
107 108 public Optional<EntityView> findEntityViewByTenantIdAndName(UUID tenantId, String name) {
108 109 return Optional.ofNullable(
109   - DaoUtil.getData(entityViewRepository.findByTenantIdAndName(fromTimeUUID(tenantId), name)));
  110 + DaoUtil.getData(entityViewRepository.findByTenantIdAndName(tenantId, name)));
110 111 }
111 112
112 113 @Override
... ... @@ -115,8 +116,8 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity,
115 116 PageLink pageLink) {
116 117 return DaoUtil.toPageData(
117 118 entityViewRepository.findByTenantIdAndCustomerId(
118   - fromTimeUUID(tenantId),
119   - fromTimeUUID(customerId),
  119 + tenantId,
  120 + customerId,
120 121 Objects.toString(pageLink.getTextSearch(), ""),
121 122 DaoUtil.toPageable(pageLink)
122 123 ));
... ... @@ -126,8 +127,8 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity,
126 127 public PageData<EntityViewInfo> findEntityViewInfosByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink) {
127 128 return DaoUtil.toPageData(
128 129 entityViewRepository.findEntityViewInfosByTenantIdAndCustomerId(
129   - fromTimeUUID(tenantId),
130   - fromTimeUUID(customerId),
  130 + tenantId,
  131 + customerId,
131 132 Objects.toString(pageLink.getTextSearch(), ""),
132 133 DaoUtil.toPageable(pageLink, EntityViewInfoEntity.entityViewInfoColumnMap)));
133 134 }
... ... @@ -136,8 +137,8 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity,
136 137 public PageData<EntityView> findEntityViewsByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink) {
137 138 return DaoUtil.toPageData(
138 139 entityViewRepository.findByTenantIdAndCustomerIdAndType(
139   - fromTimeUUID(tenantId),
140   - fromTimeUUID(customerId),
  140 + tenantId,
  141 + customerId,
141 142 type,
142 143 Objects.toString(pageLink.getTextSearch(), ""),
143 144 DaoUtil.toPageable(pageLink)
... ... @@ -148,8 +149,8 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity,
148 149 public PageData<EntityViewInfo> findEntityViewInfosByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink) {
149 150 return DaoUtil.toPageData(
150 151 entityViewRepository.findEntityViewInfosByTenantIdAndCustomerIdAndType(
151   - fromTimeUUID(tenantId),
152   - fromTimeUUID(customerId),
  152 + tenantId,
  153 + customerId,
153 154 type,
154 155 Objects.toString(pageLink.getTextSearch(), ""),
155 156 DaoUtil.toPageable(pageLink, EntityViewInfoEntity.entityViewInfoColumnMap)));
... ... @@ -158,12 +159,12 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity,
158 159 @Override
159 160 public ListenableFuture<List<EntityView>> findEntityViewsByTenantIdAndEntityIdAsync(UUID tenantId, UUID entityId) {
160 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 165 @Override
165 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 170 private List<EntitySubtype> convertTenantEntityViewTypesToDto(UUID tenantId, List<String> types) {
... ...
... ... @@ -23,7 +23,6 @@ import org.springframework.transaction.PlatformTransactionManager;
23 23 import org.springframework.transaction.TransactionDefinition;
24 24 import org.springframework.transaction.TransactionStatus;
25 25 import org.springframework.transaction.support.DefaultTransactionDefinition;
26   -import org.thingsboard.server.common.data.UUIDConverter;
27 26 import org.thingsboard.server.dao.model.sql.EventEntity;
28 27
29 28 import javax.persistence.EntityManager;
... ... @@ -69,7 +68,8 @@ public abstract class AbstractEventInsertRepository implements EventInsertReposi
69 68
70 69 protected Query getQuery(EventEntity entity, String query) {
71 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 73 .setParameter("body", entity.getBody().toString())
74 74 .setParameter("entity_id", entity.getEntityId())
75 75 .setParameter("entity_type", entity.getEntityType().name())
... ...
... ... @@ -25,60 +25,61 @@ import org.thingsboard.server.dao.model.sql.EventEntity;
25 25 import org.thingsboard.server.dao.util.SqlDao;
26 26
27 27 import java.util.List;
  28 +import java.util.UUID;
28 29
29 30 /**
30 31 * Created by Valerii Sosliuk on 5/3/2017.
31 32 */
32 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 37 EntityType entityType,
37   - String entityId,
  38 + UUID entityId,
38 39 String eventType,
39 40 String eventUid);
40 41
41   - EventEntity findByTenantIdAndEntityTypeAndEntityId(String tenantId,
  42 + EventEntity findByTenantIdAndEntityTypeAndEntityId(UUID tenantId,
42 43 EntityType entityType,
43   - String entityId);
  44 + UUID entityId);
44 45
45 46 @Query("SELECT e FROM EventEntity e WHERE e.tenantId = :tenantId AND e.entityType = :entityType " +
46 47 "AND e.entityId = :entityId AND e.eventType = :eventType ORDER BY e.eventType DESC, e.id DESC")
47 48 List<EventEntity> findLatestByTenantIdAndEntityTypeAndEntityIdAndEventType(
48   - @Param("tenantId") String tenantId,
  49 + @Param("tenantId") UUID tenantId,
49 50 @Param("entityType") EntityType entityType,
50   - @Param("entityId") String entityId,
  51 + @Param("entityId") UUID entityId,
51 52 @Param("eventType") String eventType,
52 53 Pageable pageable);
53 54
54 55 @Query("SELECT e FROM EventEntity e WHERE " +
55 56 "e.tenantId = :tenantId " +
56 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 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 63 @Param("entityType") EntityType entityType,
63   - @Param("entityId") String entityId,
  64 + @Param("entityId") UUID entityId,
64 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 68 Pageable pageable);
68 69
69 70 @Query("SELECT e FROM EventEntity e WHERE " +
70 71 "e.tenantId = :tenantId " +
71 72 "AND e.entityType = :entityType AND e.entityId = :entityId " +
72 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 78 @Param("entityType") EntityType entityType,
78   - @Param("entityId") String entityId,
  79 + @Param("entityId") UUID entityId,
79 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 83 Pageable pageable);
83 84
84 85 }
... ...
... ... @@ -16,11 +16,12 @@
16 16 package org.thingsboard.server.dao.sql.event;
17 17
18 18 import org.springframework.stereotype.Repository;
19   -import org.thingsboard.server.common.data.UUIDConverter;
20 19 import org.thingsboard.server.dao.model.sql.EventEntity;
21 20 import org.thingsboard.server.dao.util.HsqlDao;
22 21 import org.thingsboard.server.dao.util.SqlDao;
23 22
  23 +import javax.persistence.Query;
  24 +
24 25 @SqlDao
25 26 @HsqlDao
26 27 @Repository
... ... @@ -40,11 +41,25 @@ public class HsqlEventInsertRepository extends AbstractEventInsertRepository {
40 41 @Override
41 42 protected EventEntity doProcessSaveOrUpdate(EventEntity entity, String query) {
42 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 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 }
\ No newline at end of file
... ...
... ... @@ -38,9 +38,12 @@ import org.thingsboard.server.dao.sql.JpaAbstractSearchTimeDao;
38 38 import org.thingsboard.server.dao.util.SqlDao;
39 39
40 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 47 import static org.thingsboard.server.dao.DaoUtil.endTimeToId;
45 48 import static org.thingsboard.server.dao.DaoUtil.startTimeToId;
46 49 import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
... ... @@ -67,7 +70,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event
67 70 }
68 71
69 72 @Override
70   - protected CrudRepository<EventEntity, String> getCrudRepository() {
  73 + protected CrudRepository<EventEntity, UUID> getCrudRepository() {
71 74 return eventRepository;
72 75 }
73 76
... ... @@ -75,7 +78,16 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event
75 78 public Event save(TenantId tenantId, Event event) {
76 79 log.debug("Save event [{}] ", event);
77 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 92 if (StringUtils.isEmpty(event.getUid())) {
81 93 event.setUid(event.getId().toString());
... ... @@ -87,7 +99,16 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event
87 99 public ListenableFuture<Event> saveAsync(Event event) {
88 100 log.debug("Save event [{}] ", event);
89 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 113 if (StringUtils.isEmpty(event.getUid())) {
93 114 event.setUid(event.getId().toString());
... ... @@ -103,7 +124,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event
103 124 @Override
104 125 public Event findEvent(UUID tenantId, EntityId entityId, String eventType, String eventUid) {
105 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 130 @Override
... ... @@ -111,12 +132,12 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event
111 132 return DaoUtil.toPageData(
112 133 eventRepository
113 134 .findEventsByTenantIdAndEntityId(
114   - fromTimeUUID(tenantId),
  135 + tenantId,
115 136 entityId.getEntityType(),
116   - fromTimeUUID(entityId.getId()),
  137 + entityId.getId(),
117 138 Objects.toString(pageLink.getTextSearch(), ""),
118   - startTimeToId(pageLink.getStartTime()),
119   - endTimeToId(pageLink.getEndTime()),
  139 + pageLink.getStartTime(),
  140 + pageLink.getEndTime(),
120 141 DaoUtil.toPageable(pageLink)));
121 142 }
122 143
... ... @@ -125,21 +146,21 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event
125 146 return DaoUtil.toPageData(
126 147 eventRepository
127 148 .findEventsByTenantIdAndEntityIdAndEventType(
128   - fromTimeUUID(tenantId),
  149 + tenantId,
129 150 entityId.getEntityType(),
130   - fromTimeUUID(entityId.getId()),
  151 + entityId.getId(),
131 152 eventType,
132   - startTimeToId(pageLink.getStartTime()),
133   - endTimeToId(pageLink.getEndTime()),
  153 + pageLink.getStartTime(),
  154 + pageLink.getEndTime(),
134 155 DaoUtil.toPageable(pageLink)));
135 156 }
136 157
137 158 @Override
138 159 public List<Event> findLatestEvents(UUID tenantId, EntityId entityId, String eventType, int limit) {
139 160 List<EventEntity> latest = eventRepository.findLatestByTenantIdAndEntityTypeAndEntityIdAndEventType(
140   - UUIDConverter.fromTimeUUID(tenantId),
  161 + tenantId,
141 162 entityId.getEntityType(),
142   - UUIDConverter.fromTimeUUID(entityId.getId()),
  163 + entityId.getId(),
143 164 eventType,
144 165 PageRequest.of(0, limit));
145 166 return DaoUtil.convertDataList(latest);
... ... @@ -149,7 +170,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event
149 170 log.debug("Save event [{}] ", entity);
150 171 if (entity.getTenantId() == null) {
151 172 log.trace("Save system event with predefined id {}", systemTenantId);
152   - entity.setTenantId(UUIDConverter.fromTimeUUID(systemTenantId));
  173 + entity.setTenantId(systemTenantId);
153 174 }
154 175 if (entity.getUuid() == null) {
155 176 entity.setUuid(Uuids.timeBased());
... ... @@ -168,13 +189,13 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event
168 189 return (root, criteriaQuery, criteriaBuilder) -> {
169 190 List<Predicate> predicates = new ArrayList<>();
170 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 193 predicates.add(tenantIdPredicate);
173 194 }
174 195 if (entityId != null) {
175 196 Predicate entityTypePredicate = criteriaBuilder.equal(root.get("entityType"), entityId.getEntityType());
176 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 199 predicates.add(entityIdPredicate);
179 200 }
180 201 if (eventType != null) {
... ...
... ... @@ -28,10 +28,10 @@ import org.thingsboard.server.dao.util.SqlDao;
28 28 public class PsqlEventInsertRepository extends AbstractEventInsertRepository {
29 29
30 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 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 36 private static final String INSERT_OR_UPDATE_ON_P_KEY_CONFLICT = getInsertOrUpdateString(P_KEY_CONFLICT_STATEMENT, UPDATE_UNQ_KEY_STATEMENT);
37 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 48 }
49 49
50 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 }
\ No newline at end of file
... ...
... ... @@ -19,8 +19,6 @@ import lombok.extern.slf4j.Slf4j;
19 19 import org.apache.commons.lang3.StringUtils;
20 20 import org.springframework.stereotype.Repository;
21 21 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 22 import org.thingsboard.server.common.data.id.CustomerId;
25 23 import org.thingsboard.server.common.data.id.EntityId;
26 24 import org.thingsboard.server.common.data.id.TenantId;
... ... @@ -205,14 +203,14 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository {
205 203 case RELATIONS_QUERY:
206 204 case DEVICE_SEARCH_QUERY:
207 205 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()));
  206 + return String.format("e.tenant_id='%s' and e.customer_id='%s'", tenantId.getId(), customerId.getId());
209 207 default:
210 208 if (entityType == EntityType.TENANT) {
211   - return String.format("e.id='%s'", UUIDConverter.fromTimeUUID(tenantId.getId()));
  209 + return String.format("e.id='%s'", tenantId.getId());
212 210 } 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()));
  211 + return String.format("e.tenant_id='%s' and e.id='%s'", tenantId.getId(), customerId.getId());
214 212 } else {
215   - return String.format("e.tenant_id='%s' and e.customer_id='%s'", UUIDConverter.fromTimeUUID(tenantId.getId()), UUIDConverter.fromTimeUUID(customerId.getId()));
  213 + return String.format("e.tenant_id='%s' and e.customer_id='%s'", tenantId.getId(), customerId.getId());
216 214 }
217 215 }
218 216 }
... ... @@ -256,13 +254,14 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository {
256 254 private String entitySearchQuery(EntitySearchQueryFilter entityFilter, EntityType entityType, List<String> types) {
257 255 EntityId rootId = entityFilter.getRootEntity();
258 256 //TODO: fetch last level only.
  257 + //TODO: fetch distinct records.
259 258 String lvlFilter = getLvlFilter(entityFilter.getMaxLevel());
260 259 String selectFields = "SELECT tenant_id, customer_id, id, type, name, label FROM " + entityType.name() + " WHERE id in ( SELECT entity_id";
261 260 String from = getQueryTemplate(entityFilter.getDirection());
262 261
263 262 String whereFilter = " WHERE " + " re.relation_type = '" + entityFilter.getRelationType() + "'" +
264 263 " AND re.to_type = '" + entityType.name() + "'";
265   - from = String.format(from, UUIDConverter.fromTimeUUID(rootId.getId()), rootId.getEntityType().name(), lvlFilter, whereFilter);
  264 + from = String.format(from, rootId.getId(), rootId.getEntityType().name(), lvlFilter, whereFilter);
266 265 String query = "( " + selectFields + from + ")";
267 266 if (types != null && !types.isEmpty()) {
268 267 query += " and type in (" + types.stream().map(type -> "'" + type + "'").collect(Collectors.joining(", ")) + ")";
... ... @@ -305,7 +304,7 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository {
305 304 } else {
306 305 whereFilter = new StringBuilder();
307 306 }
308   - from = String.format(from, UUIDConverter.fromTimeUUID(rootId.getId()), rootId.getEntityType().name(), lvlFilter, whereFilter);
  307 + from = String.format(from, rootId.getId(), rootId.getEntityType().name(), lvlFilter, whereFilter);
309 308 return "( " + selectFields + from + ")";
310 309 }
311 310
... ... @@ -344,7 +343,7 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository {
344 343 private String getSelectCustomerId() {
345 344 return "CASE" +
346 345 " WHEN entity.entity_type = 'TENANT'" +
347   - " THEN '" + UUIDConverter.fromTimeUUID(TenantId.NULL_UUID) + "'" +
  346 + " THEN UUID('" + TenantId.NULL_UUID + "')" +
348 347 " WHEN entity.entity_type = 'CUSTOMER' THEN entity_id" +
349 348 " WHEN entity.entity_type = 'USER'" +
350 349 " THEN (select customer_id from tb_user where id = entity_id)" +
... ... @@ -442,12 +441,12 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository {
442 441 }
443 442
444 443 private String singleEntityQuery(SingleEntityFilter filter) {
445   - return String.format("e.id='%s'", UUIDConverter.fromTimeUUID(filter.getSingleEntity().getId()));
  444 + return String.format("e.id='%s'", filter.getSingleEntity().getId());
446 445 }
447 446
448 447 private String entityListQuery(EntityListFilter filter) {
449 448 return String.format("e.id in (%s)",
450   - filter.getEntityList().stream().map(UUID::fromString).map(UUIDConverter::fromTimeUUID)
  449 + filter.getEntityList().stream().map(UUID::fromString)
451 450 .map(s -> String.format("'%s'", s)).collect(Collectors.joining(",")));
452 451 }
453 452
... ...
... ... @@ -26,9 +26,11 @@ import org.thingsboard.server.common.data.query.EntityKey;
26 26 import org.thingsboard.server.common.data.query.EntityKeyType;
27 27 import org.thingsboard.server.common.data.query.TsValue;
28 28
  29 +import java.nio.ByteBuffer;
29 30 import java.util.HashMap;
30 31 import java.util.List;
31 32 import java.util.Map;
  33 +import java.util.UUID;
32 34 import java.util.stream.Collectors;
33 35
34 36 public class EntityDataAdapter {
... ... @@ -49,9 +51,10 @@ public class EntityDataAdapter {
49 51 }
50 52
51 53 private static EntityData toEntityData(Object[] row, List<EntityKeyMapping> selectionMapping) {
52   - String id = (String)row[0];
  54 + ByteBuffer bb = ByteBuffer.wrap((byte[])row[0]);
  55 + UUID id = new UUID(bb.getLong(), bb.getLong());
53 56 EntityType entityType = EntityType.valueOf((String)row[1]);
54   - EntityId entityId = EntityIdFactory.getByTypeAndUuid(entityType, UUIDConverter.fromString(id));
  57 + EntityId entityId = EntityIdFactory.getByTypeAndUuid(entityType, id);
55 58 Map<EntityKeyType, Map<String, TsValue>> latest = new HashMap<>();
56 59 Map<String, TsValue[]> timeseries = new HashMap<>();
57 60 EntityData entityData = new EntityData(entityId, latest, timeseries);
... ...
... ... @@ -94,7 +94,7 @@ public class EntityKeyMapping {
94 94 String column = entityFieldColumnMap.get(entityKey.getKey());
95 95 return String.format("e.%s as %s", column, getValueAlias());
96 96 } else if (entityKey.getType().equals(EntityKeyType.TIME_SERIES)) {
97   - return buildTimeseriesSelection();
  97 + return buildTimeSeriesSelection();
98 98 } else {
99 99 return buildAttributeSelection();
100 100 }
... ... @@ -119,8 +119,8 @@ public class EntityKeyMapping {
119 119 }
120 120 String join = hasFilter() ? "left join" : "left outer join";
121 121 if (entityKey.getType().equals(EntityKeyType.TIME_SERIES)) {
122   - // TODO:
123   - throw new RuntimeException("Not implemented!");
  122 + 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')",
  123 + join, alias, alias, alias, entityKey.getKey());
124 124 } else {
125 125 String query = String.format("%s attribute_kv %s ON %s.entity_id=entities.id AND %s.entity_type=%s AND %s.attribute_key='%s'",
126 126 join, alias, alias, alias, entityTypeStr, alias, entityKey.getKey());
... ... @@ -249,11 +249,17 @@ public class EntityKeyMapping {
249 249 return String.join(", ", attrValSelection, attrTsSelection);
250 250 }
251 251
252   - private String buildTimeseriesSelection() {
253   - // TODO:
  252 + private String buildTimeSeriesSelection() {
254 253 String attrValAlias = getValueAlias();
255 254 String attrTsAlias = getTsAlias();
256   - return String.format("(select '') as %s, (select 1) as %s", attrValAlias, attrTsAlias);
  255 + String attrValSelection =
  256 + String.format("(coalesce(cast(%s.bool_v as varchar), '') || " +
  257 + "coalesce(%s.str_v, '') || " +
  258 + "coalesce(cast(%s.long_v as varchar), '') || " +
  259 + "coalesce(cast(%s.dbl_v as varchar), '') || " +
  260 + "coalesce(cast(%s.json_v as varchar), '')) as %s", alias, alias, alias, alias, alias, attrValAlias);
  261 + String attrTsSelection = String.format("%s.ts as %s", alias, attrTsAlias);
  262 + return String.join(", ", attrValSelection, attrTsSelection);
257 263 }
258 264
259 265 private String buildKeyQuery(String alias, KeyFilter keyFilter) {
... ...
... ... @@ -22,6 +22,8 @@ import org.thingsboard.server.dao.model.sql.RelationEntity;
22 22 import org.thingsboard.server.dao.util.HsqlDao;
23 23 import org.thingsboard.server.dao.util.SqlDao;
24 24
  25 +import javax.persistence.Query;
  26 +
25 27 @HsqlDao
26 28 @SqlDao
27 29 @Repository
... ... @@ -30,9 +32,25 @@ public class HsqlRelationInsertRepository extends AbstractRelationInsertReposito
30 32
31 33 private static final String INSERT_ON_CONFLICT_DO_UPDATE = "MERGE INTO relation USING (VALUES :fromId, :fromType, :toId, :toType, :relationTypeGroup, :relationType, :additionalInfo) R " +
32 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 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 55 @Override
38 56 public RelationEntity saveOrUpdate(RelationEntity entity) {
... ...
... ... @@ -44,8 +44,6 @@ import javax.persistence.criteria.Predicate;
44 44 import java.util.ArrayList;
45 45 import java.util.List;
46 46
47   -import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID;
48   -
49 47 /**
50 48 * Created by Valerii Sosliuk on 5/29/2017.
51 49 */
... ... @@ -64,7 +62,7 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple
64 62 public ListenableFuture<List<EntityRelation>> findAllByFrom(TenantId tenantId, EntityId from, RelationTypeGroup typeGroup) {
65 63 return service.submit(() -> DaoUtil.convertDataList(
66 64 relationRepository.findAllByFromIdAndFromTypeAndRelationTypeGroup(
67   - UUIDConverter.fromTimeUUID(from.getId()),
  65 + from.getId(),
68 66 from.getEntityType().name(),
69 67 typeGroup.name())));
70 68 }
... ... @@ -73,7 +71,7 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple
73 71 public ListenableFuture<List<EntityRelation>> findAllByFromAndType(TenantId tenantId, EntityId from, String relationType, RelationTypeGroup typeGroup) {
74 72 return service.submit(() -> DaoUtil.convertDataList(
75 73 relationRepository.findAllByFromIdAndFromTypeAndRelationTypeAndRelationTypeGroup(
76   - UUIDConverter.fromTimeUUID(from.getId()),
  74 + from.getId(),
77 75 from.getEntityType().name(),
78 76 relationType,
79 77 typeGroup.name())));
... ... @@ -83,7 +81,7 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple
83 81 public ListenableFuture<List<EntityRelation>> findAllByTo(TenantId tenantId, EntityId to, RelationTypeGroup typeGroup) {
84 82 return service.submit(() -> DaoUtil.convertDataList(
85 83 relationRepository.findAllByToIdAndToTypeAndRelationTypeGroup(
86   - UUIDConverter.fromTimeUUID(to.getId()),
  84 + to.getId(),
87 85 to.getEntityType().name(),
88 86 typeGroup.name())));
89 87 }
... ... @@ -92,7 +90,7 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple
92 90 public ListenableFuture<List<EntityRelation>> findAllByToAndType(TenantId tenantId, EntityId to, String relationType, RelationTypeGroup typeGroup) {
93 91 return service.submit(() -> DaoUtil.convertDataList(
94 92 relationRepository.findAllByToIdAndToTypeAndRelationTypeAndRelationTypeGroup(
95   - UUIDConverter.fromTimeUUID(to.getId()),
  93 + to.getId(),
96 94 to.getEntityType().name(),
97 95 relationType,
98 96 typeGroup.name())));
... ... @@ -111,9 +109,9 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple
111 109 }
112 110
113 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 113 from.getEntityType().name(),
116   - fromTimeUUID(to.getId()),
  114 + to.getId(),
117 115 to.getEntityType().name(),
118 116 relationType,
119 117 typeGroup.name());
... ... @@ -166,10 +164,10 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple
166 164 @Override
167 165 public boolean deleteOutboundRelations(TenantId tenantId, EntityId entity) {
168 166 boolean relationExistsBeforeDelete = relationRepository
169   - .findAllByFromIdAndFromType(UUIDConverter.fromTimeUUID(entity.getId()), entity.getEntityType().name())
  167 + .findAllByFromIdAndFromType(entity.getId(), entity.getEntityType().name())
170 168 .size() > 0;
171 169 if (relationExistsBeforeDelete) {
172   - relationRepository.deleteByFromIdAndFromType(UUIDConverter.fromTimeUUID(entity.getId()), entity.getEntityType().name());
  170 + relationRepository.deleteByFromIdAndFromType(entity.getId(), entity.getEntityType().name());
173 171 }
174 172 return relationExistsBeforeDelete;
175 173 }
... ... @@ -179,33 +177,20 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple
179 177 return service.submit(
180 178 () -> {
181 179 boolean relationExistsBeforeDelete = relationRepository
182   - .findAllByFromIdAndFromType(UUIDConverter.fromTimeUUID(entity.getId()), entity.getEntityType().name())
  180 + .findAllByFromIdAndFromType(entity.getId(), entity.getEntityType().name())
183 181 .size() > 0;
184 182 if (relationExistsBeforeDelete) {
185   - relationRepository.deleteByFromIdAndFromType(UUIDConverter.fromTimeUUID(entity.getId()), entity.getEntityType().name());
  183 + relationRepository.deleteByFromIdAndFromType(entity.getId(), entity.getEntityType().name());
186 184 }
187 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 189 private Specification<RelationEntity> getEntityFieldsSpec(EntityId from, String relationType, RelationTypeGroup typeGroup, EntityType childType) {
205 190 return (root, criteriaQuery, criteriaBuilder) -> {
206 191 List<Predicate> predicates = new ArrayList<>();
207 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 194 predicates.add(fromIdPredicate);
210 195 Predicate fromEntityTypePredicate = criteriaBuilder.equal(root.get("fromType"), from.getEntityType().name());
211 196 predicates.add(fromEntityTypePredicate);
... ...
... ... @@ -23,30 +23,31 @@ import org.thingsboard.server.dao.model.sql.RelationEntity;
23 23 import org.thingsboard.server.dao.util.SqlDao;
24 24
25 25 import java.util.List;
  26 +import java.util.UUID;
26 27
27 28 @SqlDao
28 29 public interface RelationRepository
29 30 extends CrudRepository<RelationEntity, RelationCompositeKey>, JpaSpecificationExecutor<RelationEntity> {
30 31
31   - List<RelationEntity> findAllByFromIdAndFromTypeAndRelationTypeGroup(String fromId,
  32 + List<RelationEntity> findAllByFromIdAndFromTypeAndRelationTypeGroup(UUID fromId,
32 33 String fromType,
33 34 String relationTypeGroup);
34 35
35   - List<RelationEntity> findAllByFromIdAndFromTypeAndRelationTypeAndRelationTypeGroup(String fromId,
  36 + List<RelationEntity> findAllByFromIdAndFromTypeAndRelationTypeAndRelationTypeGroup(UUID fromId,
36 37 String fromType,
37 38 String relationType,
38 39 String relationTypeGroup);
39 40
40   - List<RelationEntity> findAllByToIdAndToTypeAndRelationTypeGroup(String toId,
  41 + List<RelationEntity> findAllByToIdAndToTypeAndRelationTypeGroup(UUID toId,
41 42 String toType,
42 43 String relationTypeGroup);
43 44
44   - List<RelationEntity> findAllByToIdAndToTypeAndRelationTypeAndRelationTypeGroup(String toId,
  45 + List<RelationEntity> findAllByToIdAndToTypeAndRelationTypeAndRelationTypeGroup(UUID toId,
45 46 String toType,
46 47 String relationType,
47 48 String relationTypeGroup);
48 49
49   - List<RelationEntity> findAllByFromIdAndFromType(String fromId,
  50 + List<RelationEntity> findAllByFromIdAndFromType(UUID fromId,
50 51 String fromType);
51 52
52 53 @Transactional
... ... @@ -56,5 +57,5 @@ public interface RelationRepository
56 57 void deleteById(RelationCompositeKey id);
57 58
58 59 @Transactional
59   - void deleteByFromIdAndFromType(String fromId, String fromType);
  60 + void deleteByFromIdAndFromType(UUID fromId, String fromType);
60 61 }
... ...
... ... @@ -17,10 +17,8 @@ package org.thingsboard.server.dao.sql.rule;
17 17
18 18 import lombok.extern.slf4j.Slf4j;
19 19 import org.springframework.beans.factory.annotation.Autowired;
20   -import org.springframework.data.domain.PageRequest;
21 20 import org.springframework.data.repository.CrudRepository;
22 21 import org.springframework.stereotype.Component;
23   -import org.thingsboard.server.common.data.UUIDConverter;
24 22 import org.thingsboard.server.common.data.page.PageData;
25 23 import org.thingsboard.server.common.data.page.PageLink;
26 24 import org.thingsboard.server.common.data.rule.RuleChain;
... ... @@ -30,12 +28,9 @@ import org.thingsboard.server.dao.rule.RuleChainDao;
30 28 import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
31 29 import org.thingsboard.server.dao.util.SqlDao;
32 30
33   -import java.util.List;
34 31 import java.util.Objects;
35 32 import java.util.UUID;
36 33
37   -import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID_STR;
38   -
39 34 @Slf4j
40 35 @Component
41 36 @SqlDao
... ... @@ -58,7 +53,7 @@ public class JpaRuleChainDao extends JpaAbstractSearchTextDao<RuleChainEntity, R
58 53 public PageData<RuleChain> findRuleChainsByTenantId(UUID tenantId, PageLink pageLink) {
59 54 return DaoUtil.toPageData(ruleChainRepository
60 55 .findByTenantId(
61   - UUIDConverter.fromTimeUUID(tenantId),
  56 + tenantId,
62 57 Objects.toString(pageLink.getTextSearch(), ""),
63 58 DaoUtil.toPageable(pageLink)));
64 59 }
... ...
... ... @@ -18,20 +18,19 @@ package org.thingsboard.server.dao.sql.rule;
18 18 import org.springframework.data.domain.Page;
19 19 import org.springframework.data.domain.Pageable;
20 20 import org.springframework.data.jpa.repository.Query;
21   -import org.springframework.data.repository.CrudRepository;
22 21 import org.springframework.data.repository.PagingAndSortingRepository;
23 22 import org.springframework.data.repository.query.Param;
24 23 import org.thingsboard.server.dao.model.sql.RuleChainEntity;
25 24 import org.thingsboard.server.dao.util.SqlDao;
26 25
27   -import java.util.List;
  26 +import java.util.UUID;
28 27
29 28 @SqlDao
30   -public interface RuleChainRepository extends PagingAndSortingRepository<RuleChainEntity, String> {
  29 +public interface RuleChainRepository extends PagingAndSortingRepository<RuleChainEntity, UUID> {
31 30
32 31 @Query("SELECT rc FROM RuleChainEntity rc WHERE rc.tenantId = :tenantId " +
33 32 "AND LOWER(rc.searchText) LIKE LOWER(CONCAT(:searchText, '%'))")
34   - Page<RuleChainEntity> findByTenantId(@Param("tenantId") String tenantId,
  33 + Page<RuleChainEntity> findByTenantId(@Param("tenantId") UUID tenantId,
35 34 @Param("searchText") String searchText,
36 35 Pageable pageable);
37 36
... ...