Commit fe8b776540ba6fbb2f32ef0cf183ec1df348080e
Committed by
GitHub
Merge pull request #204 from thingsboard/feature/uuids-refactoring
Refactoring from UUIDs to Strings in SQL DAO to support ordering
Showing
100 changed files
with
742 additions
and
673 deletions
Too many changes to show.
To preserve performance only 100 of 133 files are displayed.
@@ -106,7 +106,7 @@ coap: | @@ -106,7 +106,7 @@ coap: | ||
106 | timeout: "${COAP_TIMEOUT:10000}" | 106 | timeout: "${COAP_TIMEOUT:10000}" |
107 | 107 | ||
108 | database: | 108 | database: |
109 | - type: "${DATABASE_TYPE:cassandra}" # cassandra OR sql | 109 | + type: "${DATABASE_TYPE:sql}" # cassandra OR sql |
110 | 110 | ||
111 | # Cassandra driver configuration parameters | 111 | # Cassandra driver configuration parameters |
112 | cassandra: | 112 | cassandra: |
@@ -66,6 +66,11 @@ | @@ -66,6 +66,11 @@ | ||
66 | <artifactId>mockito-all</artifactId> | 66 | <artifactId>mockito-all</artifactId> |
67 | <scope>test</scope> | 67 | <scope>test</scope> |
68 | </dependency> | 68 | </dependency> |
69 | + <dependency> | ||
70 | + <groupId>com.datastax.cassandra</groupId> | ||
71 | + <artifactId>cassandra-driver-core</artifactId> | ||
72 | + <scope>test</scope> | ||
73 | + </dependency> | ||
69 | </dependencies> | 74 | </dependencies> |
70 | 75 | ||
71 | <build> | 76 | <build> |
1 | +/** | ||
2 | + * Copyright © 2016-2017 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.common.data; | ||
17 | + | ||
18 | +import java.util.List; | ||
19 | +import java.util.UUID; | ||
20 | +import java.util.stream.Collectors; | ||
21 | + | ||
22 | +/** | ||
23 | + * Created by ashvayka on 13.07.17. | ||
24 | + */ | ||
25 | +public class UUIDConverter { | ||
26 | + | ||
27 | + public static UUID fromString(String src) { | ||
28 | + return UUID.fromString(src.substring(7, 15) + "-" + src.substring(3, 7) + "-1" | ||
29 | + + src.substring(0, 3) + "-" + src.substring(15, 19) + "-" + src.substring(19)); | ||
30 | + } | ||
31 | + | ||
32 | + public static String fromTimeUUID(UUID src) { | ||
33 | + if (src.version() != 1) { | ||
34 | + throw new IllegalArgumentException("Not a time UUID!"); | ||
35 | + } | ||
36 | + String str = src.toString(); | ||
37 | + // 58e0a7d7-eebc-11d8-9669-0800200c9a66 => 1d8eebc58e0a7d796690800200c9a66. Note that [11d8] -> [1d8] | ||
38 | + return str.substring(15, 18) + str.substring(9, 13) + str.substring(0, 8) + str.substring(19, 23) + str.substring(24); | ||
39 | + } | ||
40 | + | ||
41 | + public static List<String> fromTimeUUIDs(List<UUID> uuids) { | ||
42 | + if (uuids == null) { | ||
43 | + return null; | ||
44 | + } | ||
45 | + return uuids.stream().map(UUIDConverter::fromTimeUUID).collect(Collectors.toList()); | ||
46 | + } | ||
47 | + | ||
48 | +} | ||
49 | + |
@@ -15,6 +15,7 @@ | @@ -15,6 +15,7 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.common.data.asset; | 16 | package org.thingsboard.server.common.data.asset; |
17 | 17 | ||
18 | +import org.thingsboard.server.common.data.UUIDConverter; | ||
18 | import org.thingsboard.server.common.data.id.TenantId; | 19 | import org.thingsboard.server.common.data.id.TenantId; |
19 | 20 | ||
20 | import java.util.UUID; | 21 | import java.util.UUID; |
@@ -40,6 +41,11 @@ public class TenantAssetType { | @@ -40,6 +41,11 @@ public class TenantAssetType { | ||
40 | this.tenantId = new TenantId(tenantId); | 41 | this.tenantId = new TenantId(tenantId); |
41 | } | 42 | } |
42 | 43 | ||
44 | + public TenantAssetType(String type, String tenantId) { | ||
45 | + this.type = type; | ||
46 | + this.tenantId = new TenantId(UUIDConverter.fromString(tenantId)); | ||
47 | + } | ||
48 | + | ||
43 | public String getType() { | 49 | public String getType() { |
44 | return type; | 50 | return type; |
45 | } | 51 | } |
1 | +/** | ||
2 | + * Copyright © 2016-2017 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.common.data; | ||
17 | + | ||
18 | +import com.datastax.driver.core.utils.UUIDs; | ||
19 | +import org.junit.Assert; | ||
20 | +import org.junit.Test; | ||
21 | +import org.junit.runner.RunWith; | ||
22 | +import org.mockito.runners.MockitoJUnitRunner; | ||
23 | + | ||
24 | +import java.util.Random; | ||
25 | +import java.util.UUID; | ||
26 | + | ||
27 | +/** | ||
28 | + * Created by ashvayka on 14.07.17. | ||
29 | + */ | ||
30 | +@RunWith(MockitoJUnitRunner.class) | ||
31 | +public class UUIDConverterTest { | ||
32 | + | ||
33 | + @Test | ||
34 | + public void basicUuidToStringTest() { | ||
35 | + UUID original = UUID.fromString("58e0a7d7-eebc-11d8-9669-0800200c9a66"); | ||
36 | + String result = UUIDConverter.fromTimeUUID(original); | ||
37 | + Assert.assertEquals("1d8eebc58e0a7d796690800200c9a66", result); | ||
38 | + } | ||
39 | + | ||
40 | + @Test | ||
41 | + public void basicStringToUUIDTest() { | ||
42 | + UUID result = UUIDConverter.fromString("1d8eebc58e0a7d796690800200c9a66"); | ||
43 | + Assert.assertEquals(UUID.fromString("58e0a7d7-eebc-11d8-9669-0800200c9a66"), result); | ||
44 | + } | ||
45 | + | ||
46 | + @Test(expected = IllegalArgumentException.class) | ||
47 | + public void nonV1UuidToStringTest() { | ||
48 | + UUIDConverter.fromTimeUUID(UUID.fromString("58e0a7d7-eebc-01d8-9669-0800200c9a66")); | ||
49 | + } | ||
50 | + | ||
51 | + @Test | ||
52 | + public void basicUuidComperisonTest() { | ||
53 | + Random r = new Random(System.currentTimeMillis()); | ||
54 | + for (int i = 0; i < 100000; i++) { | ||
55 | + long ts = System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 365 * 10; | ||
56 | + long before = (long) (Math.random() * ts); | ||
57 | + long after = (long) (Math.random() * ts); | ||
58 | + if (before > after) { | ||
59 | + long tmp = after; | ||
60 | + after = before; | ||
61 | + before = tmp; | ||
62 | + } | ||
63 | + | ||
64 | + String beforeStr = UUIDConverter.fromTimeUUID(UUIDs.startOf(before)); | ||
65 | + String afterStr = UUIDConverter.fromTimeUUID(UUIDs.startOf(after)); | ||
66 | + | ||
67 | + if (afterStr.compareTo(beforeStr) < 0) { | ||
68 | + System.out.println("Before: " + before + " | " + beforeStr); | ||
69 | + System.out.println("After: " + after + " | " + afterStr); | ||
70 | + } | ||
71 | + Assert.assertTrue(afterStr.compareTo(beforeStr) >= 0); | ||
72 | + } | ||
73 | + } | ||
74 | + | ||
75 | + | ||
76 | +} |
@@ -47,7 +47,6 @@ import javax.annotation.PostConstruct; | @@ -47,7 +47,6 @@ import javax.annotation.PostConstruct; | ||
47 | import javax.annotation.PreDestroy; | 47 | import javax.annotation.PreDestroy; |
48 | import java.util.ArrayList; | 48 | import java.util.ArrayList; |
49 | import java.util.List; | 49 | import java.util.List; |
50 | -import java.util.UUID; | ||
51 | import java.util.concurrent.ExecutionException; | 50 | import java.util.concurrent.ExecutionException; |
52 | import java.util.concurrent.ExecutorService; | 51 | import java.util.concurrent.ExecutorService; |
53 | import java.util.concurrent.Executors; | 52 | import java.util.concurrent.Executors; |
@@ -33,11 +33,11 @@ import org.thingsboard.server.common.data.id.EntityId; | @@ -33,11 +33,11 @@ import org.thingsboard.server.common.data.id.EntityId; | ||
33 | import org.thingsboard.server.common.data.id.TenantId; | 33 | import org.thingsboard.server.common.data.id.TenantId; |
34 | import org.thingsboard.server.common.data.relation.EntityRelation; | 34 | import org.thingsboard.server.common.data.relation.EntityRelation; |
35 | import org.thingsboard.server.common.data.relation.RelationTypeGroup; | 35 | import org.thingsboard.server.common.data.relation.RelationTypeGroup; |
36 | -import org.thingsboard.server.dao.nosql.CassandraAbstractModelDao; | ||
37 | -import org.thingsboard.server.dao.util.NoSqlDao; | ||
38 | import org.thingsboard.server.dao.model.ModelConstants; | 36 | import org.thingsboard.server.dao.model.ModelConstants; |
39 | import org.thingsboard.server.dao.model.nosql.AlarmEntity; | 37 | import org.thingsboard.server.dao.model.nosql.AlarmEntity; |
38 | +import org.thingsboard.server.dao.nosql.CassandraAbstractModelDao; | ||
40 | import org.thingsboard.server.dao.relation.RelationDao; | 39 | import org.thingsboard.server.dao.relation.RelationDao; |
40 | +import org.thingsboard.server.dao.util.NoSqlDao; | ||
41 | 41 | ||
42 | import java.util.ArrayList; | 42 | import java.util.ArrayList; |
43 | import java.util.List; | 43 | import java.util.List; |
@@ -20,7 +20,6 @@ import org.thingsboard.server.common.data.asset.Asset; | @@ -20,7 +20,6 @@ import org.thingsboard.server.common.data.asset.Asset; | ||
20 | import org.thingsboard.server.common.data.asset.TenantAssetType; | 20 | import org.thingsboard.server.common.data.asset.TenantAssetType; |
21 | import org.thingsboard.server.common.data.page.TextPageLink; | 21 | import org.thingsboard.server.common.data.page.TextPageLink; |
22 | import org.thingsboard.server.dao.Dao; | 22 | import org.thingsboard.server.dao.Dao; |
23 | -import org.thingsboard.server.dao.model.TenantAssetTypeEntity; | ||
24 | 23 | ||
25 | import java.util.List; | 24 | import java.util.List; |
26 | import java.util.Optional; | 25 | import java.util.Optional; |
@@ -18,9 +18,9 @@ package org.thingsboard.server.dao.asset; | @@ -18,9 +18,9 @@ package org.thingsboard.server.dao.asset; | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | import org.thingsboard.server.common.data.EntityType; | 19 | import org.thingsboard.server.common.data.EntityType; |
20 | import org.thingsboard.server.common.data.relation.EntityRelation; | 20 | import org.thingsboard.server.common.data.relation.EntityRelation; |
21 | -import org.thingsboard.server.dao.relation.RelationsSearchParameters; | ||
22 | import org.thingsboard.server.dao.relation.EntityRelationsQuery; | 21 | import org.thingsboard.server.dao.relation.EntityRelationsQuery; |
23 | import org.thingsboard.server.dao.relation.EntityTypeFilter; | 22 | import org.thingsboard.server.dao.relation.EntityTypeFilter; |
23 | +import org.thingsboard.server.dao.relation.RelationsSearchParameters; | ||
24 | 24 | ||
25 | import javax.annotation.Nullable; | 25 | import javax.annotation.Nullable; |
26 | import java.util.Collections; | 26 | import java.util.Collections; |
@@ -51,7 +51,7 @@ import java.util.List; | @@ -51,7 +51,7 @@ import java.util.List; | ||
51 | import java.util.Optional; | 51 | import java.util.Optional; |
52 | import java.util.stream.Collectors; | 52 | import java.util.stream.Collectors; |
53 | 53 | ||
54 | -import static org.thingsboard.server.dao.DaoUtil.*; | 54 | +import static org.thingsboard.server.dao.DaoUtil.toUUIDs; |
55 | import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; | 55 | import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; |
56 | import static org.thingsboard.server.dao.service.Validator.*; | 56 | import static org.thingsboard.server.dao.service.Validator.*; |
57 | 57 |
@@ -27,11 +27,11 @@ import org.springframework.stereotype.Component; | @@ -27,11 +27,11 @@ import org.springframework.stereotype.Component; | ||
27 | import org.thingsboard.server.common.data.asset.Asset; | 27 | import org.thingsboard.server.common.data.asset.Asset; |
28 | import org.thingsboard.server.common.data.asset.TenantAssetType; | 28 | import org.thingsboard.server.common.data.asset.TenantAssetType; |
29 | import org.thingsboard.server.common.data.page.TextPageLink; | 29 | import org.thingsboard.server.common.data.page.TextPageLink; |
30 | -import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; | ||
31 | import org.thingsboard.server.dao.DaoUtil; | 30 | import org.thingsboard.server.dao.DaoUtil; |
32 | -import org.thingsboard.server.dao.util.NoSqlDao; | ||
33 | import org.thingsboard.server.dao.model.TenantAssetTypeEntity; | 31 | import org.thingsboard.server.dao.model.TenantAssetTypeEntity; |
34 | import org.thingsboard.server.dao.model.nosql.AssetEntity; | 32 | import org.thingsboard.server.dao.model.nosql.AssetEntity; |
33 | +import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; | ||
34 | +import org.thingsboard.server.dao.util.NoSqlDao; | ||
35 | 35 | ||
36 | import javax.annotation.Nullable; | 36 | import javax.annotation.Nullable; |
37 | import java.util.*; | 37 | import java.util.*; |
@@ -15,8 +15,6 @@ | @@ -15,8 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.attributes; | 16 | package org.thingsboard.server.dao.attributes; |
17 | 17 | ||
18 | -import com.datastax.driver.core.ResultSet; | ||
19 | -import com.datastax.driver.core.ResultSetFuture; | ||
20 | import com.google.common.collect.Lists; | 18 | import com.google.common.collect.Lists; |
21 | import com.google.common.util.concurrent.Futures; | 19 | import com.google.common.util.concurrent.Futures; |
22 | import com.google.common.util.concurrent.ListenableFuture; | 20 | import com.google.common.util.concurrent.ListenableFuture; |
@@ -26,10 +26,10 @@ import org.springframework.stereotype.Component; | @@ -26,10 +26,10 @@ import org.springframework.stereotype.Component; | ||
26 | import org.thingsboard.server.common.data.id.EntityId; | 26 | import org.thingsboard.server.common.data.id.EntityId; |
27 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; | 27 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
28 | import org.thingsboard.server.common.data.kv.BaseAttributeKvEntry; | 28 | import org.thingsboard.server.common.data.kv.BaseAttributeKvEntry; |
29 | -import org.thingsboard.server.dao.nosql.CassandraAbstractAsyncDao; | ||
30 | -import org.thingsboard.server.dao.util.NoSqlDao; | ||
31 | import org.thingsboard.server.dao.model.ModelConstants; | 29 | import org.thingsboard.server.dao.model.ModelConstants; |
30 | +import org.thingsboard.server.dao.nosql.CassandraAbstractAsyncDao; | ||
32 | import org.thingsboard.server.dao.timeseries.CassandraBaseTimeseriesDao; | 31 | import org.thingsboard.server.dao.timeseries.CassandraBaseTimeseriesDao; |
32 | +import org.thingsboard.server.dao.util.NoSqlDao; | ||
33 | 33 | ||
34 | import javax.annotation.PostConstruct; | 34 | import javax.annotation.PostConstruct; |
35 | import javax.annotation.PreDestroy; | 35 | import javax.annotation.PreDestroy; |
@@ -17,9 +17,10 @@ package org.thingsboard.server.dao.cassandra; | @@ -17,9 +17,10 @@ package org.thingsboard.server.dao.cassandra; | ||
17 | 17 | ||
18 | import org.springframework.beans.factory.annotation.Value; | 18 | import org.springframework.beans.factory.annotation.Value; |
19 | import org.springframework.stereotype.Component; | 19 | import org.springframework.stereotype.Component; |
20 | -import javax.annotation.PostConstruct; | ||
21 | import org.thingsboard.server.dao.util.NoSqlDao; | 20 | import org.thingsboard.server.dao.util.NoSqlDao; |
22 | 21 | ||
22 | +import javax.annotation.PostConstruct; | ||
23 | + | ||
23 | @Component | 24 | @Component |
24 | @NoSqlDao | 25 | @NoSqlDao |
25 | public class CassandraCluster extends AbstractCassandraCluster { | 26 | public class CassandraCluster extends AbstractCassandraCluster { |
@@ -27,11 +27,11 @@ import org.thingsboard.server.common.data.page.TextPageLink; | @@ -27,11 +27,11 @@ import org.thingsboard.server.common.data.page.TextPageLink; | ||
27 | import org.thingsboard.server.common.data.plugin.ComponentDescriptor; | 27 | import org.thingsboard.server.common.data.plugin.ComponentDescriptor; |
28 | import org.thingsboard.server.common.data.plugin.ComponentScope; | 28 | import org.thingsboard.server.common.data.plugin.ComponentScope; |
29 | import org.thingsboard.server.common.data.plugin.ComponentType; | 29 | import org.thingsboard.server.common.data.plugin.ComponentType; |
30 | -import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; | ||
31 | import org.thingsboard.server.dao.DaoUtil; | 30 | import org.thingsboard.server.dao.DaoUtil; |
32 | -import org.thingsboard.server.dao.util.NoSqlDao; | ||
33 | import org.thingsboard.server.dao.model.ModelConstants; | 31 | import org.thingsboard.server.dao.model.ModelConstants; |
34 | import org.thingsboard.server.dao.model.nosql.ComponentDescriptorEntity; | 32 | import org.thingsboard.server.dao.model.nosql.ComponentDescriptorEntity; |
33 | +import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; | ||
34 | +import org.thingsboard.server.dao.util.NoSqlDao; | ||
35 | 35 | ||
36 | import java.util.Arrays; | 36 | import java.util.Arrays; |
37 | import java.util.List; | 37 | import java.util.List; |
@@ -20,11 +20,11 @@ import lombok.extern.slf4j.Slf4j; | @@ -20,11 +20,11 @@ import lombok.extern.slf4j.Slf4j; | ||
20 | import org.springframework.stereotype.Component; | 20 | import org.springframework.stereotype.Component; |
21 | import org.thingsboard.server.common.data.Customer; | 21 | import org.thingsboard.server.common.data.Customer; |
22 | import org.thingsboard.server.common.data.page.TextPageLink; | 22 | import org.thingsboard.server.common.data.page.TextPageLink; |
23 | -import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; | ||
24 | import org.thingsboard.server.dao.DaoUtil; | 23 | import org.thingsboard.server.dao.DaoUtil; |
25 | -import org.thingsboard.server.dao.util.NoSqlDao; | ||
26 | import org.thingsboard.server.dao.model.ModelConstants; | 24 | import org.thingsboard.server.dao.model.ModelConstants; |
27 | import org.thingsboard.server.dao.model.nosql.CustomerEntity; | 25 | import org.thingsboard.server.dao.model.nosql.CustomerEntity; |
26 | +import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; | ||
27 | +import org.thingsboard.server.dao.util.NoSqlDao; | ||
28 | 28 | ||
29 | import java.util.Arrays; | 29 | import java.util.Arrays; |
30 | import java.util.List; | 30 | import java.util.List; |
@@ -15,12 +15,12 @@ | @@ -15,12 +15,12 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.customer; | 16 | package org.thingsboard.server.dao.customer; |
17 | 17 | ||
18 | -import java.util.Optional; | ||
19 | import org.thingsboard.server.common.data.Customer; | 18 | import org.thingsboard.server.common.data.Customer; |
20 | import org.thingsboard.server.common.data.page.TextPageLink; | 19 | import org.thingsboard.server.common.data.page.TextPageLink; |
21 | import org.thingsboard.server.dao.Dao; | 20 | import org.thingsboard.server.dao.Dao; |
22 | 21 | ||
23 | import java.util.List; | 22 | import java.util.List; |
23 | +import java.util.Optional; | ||
24 | import java.util.UUID; | 24 | import java.util.UUID; |
25 | 25 | ||
26 | /** | 26 | /** |
@@ -15,12 +15,6 @@ | @@ -15,12 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.customer; | 16 | package org.thingsboard.server.dao.customer; |
17 | 17 | ||
18 | -import static org.thingsboard.server.dao.service.Validator.validateId; | ||
19 | - | ||
20 | -import java.io.IOException; | ||
21 | -import java.util.List; | ||
22 | -import java.util.Optional; | ||
23 | - | ||
24 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
25 | import com.fasterxml.jackson.databind.ObjectMapper; | 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
26 | import com.google.common.util.concurrent.ListenableFuture; | 20 | import com.google.common.util.concurrent.ListenableFuture; |
@@ -45,6 +39,12 @@ import org.thingsboard.server.dao.service.Validator; | @@ -45,6 +39,12 @@ import org.thingsboard.server.dao.service.Validator; | ||
45 | import org.thingsboard.server.dao.tenant.TenantDao; | 39 | import org.thingsboard.server.dao.tenant.TenantDao; |
46 | import org.thingsboard.server.dao.user.UserService; | 40 | import org.thingsboard.server.dao.user.UserService; |
47 | 41 | ||
42 | +import java.io.IOException; | ||
43 | +import java.util.List; | ||
44 | +import java.util.Optional; | ||
45 | + | ||
46 | +import static org.thingsboard.server.dao.service.Validator.validateId; | ||
47 | + | ||
48 | @Service | 48 | @Service |
49 | @Slf4j | 49 | @Slf4j |
50 | public class CustomerServiceImpl extends AbstractEntityService implements CustomerService { | 50 | public class CustomerServiceImpl extends AbstractEntityService implements CustomerService { |
@@ -17,9 +17,9 @@ package org.thingsboard.server.dao.dashboard; | @@ -17,9 +17,9 @@ package org.thingsboard.server.dao.dashboard; | ||
17 | 17 | ||
18 | import org.springframework.stereotype.Component; | 18 | import org.springframework.stereotype.Component; |
19 | import org.thingsboard.server.common.data.Dashboard; | 19 | import org.thingsboard.server.common.data.Dashboard; |
20 | +import org.thingsboard.server.dao.model.nosql.DashboardEntity; | ||
20 | import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; | 21 | import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; |
21 | import org.thingsboard.server.dao.util.NoSqlDao; | 22 | import org.thingsboard.server.dao.util.NoSqlDao; |
22 | -import org.thingsboard.server.dao.model.nosql.DashboardEntity; | ||
23 | 23 | ||
24 | import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME; | 24 | import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME; |
25 | 25 |
@@ -19,10 +19,10 @@ import lombok.extern.slf4j.Slf4j; | @@ -19,10 +19,10 @@ import lombok.extern.slf4j.Slf4j; | ||
19 | import org.springframework.stereotype.Component; | 19 | import org.springframework.stereotype.Component; |
20 | import org.thingsboard.server.common.data.DashboardInfo; | 20 | import org.thingsboard.server.common.data.DashboardInfo; |
21 | import org.thingsboard.server.common.data.page.TextPageLink; | 21 | import org.thingsboard.server.common.data.page.TextPageLink; |
22 | -import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; | ||
23 | import org.thingsboard.server.dao.DaoUtil; | 22 | import org.thingsboard.server.dao.DaoUtil; |
24 | -import org.thingsboard.server.dao.util.NoSqlDao; | ||
25 | import org.thingsboard.server.dao.model.nosql.DashboardInfoEntity; | 23 | import org.thingsboard.server.dao.model.nosql.DashboardInfoEntity; |
24 | +import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; | ||
25 | +import org.thingsboard.server.dao.util.NoSqlDao; | ||
26 | 26 | ||
27 | import java.util.Arrays; | 27 | import java.util.Arrays; |
28 | import java.util.Collections; | 28 | import java.util.Collections; |
@@ -19,11 +19,11 @@ import com.datastax.driver.core.querybuilder.Select.Where; | @@ -19,11 +19,11 @@ import com.datastax.driver.core.querybuilder.Select.Where; | ||
19 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
20 | import org.springframework.stereotype.Component; | 20 | import org.springframework.stereotype.Component; |
21 | import org.thingsboard.server.common.data.security.DeviceCredentials; | 21 | import org.thingsboard.server.common.data.security.DeviceCredentials; |
22 | -import org.thingsboard.server.dao.nosql.CassandraAbstractModelDao; | ||
23 | import org.thingsboard.server.dao.DaoUtil; | 22 | import org.thingsboard.server.dao.DaoUtil; |
24 | -import org.thingsboard.server.dao.util.NoSqlDao; | ||
25 | import org.thingsboard.server.dao.model.ModelConstants; | 23 | import org.thingsboard.server.dao.model.ModelConstants; |
26 | import org.thingsboard.server.dao.model.nosql.DeviceCredentialsEntity; | 24 | import org.thingsboard.server.dao.model.nosql.DeviceCredentialsEntity; |
25 | +import org.thingsboard.server.dao.nosql.CassandraAbstractModelDao; | ||
26 | +import org.thingsboard.server.dao.util.NoSqlDao; | ||
27 | 27 | ||
28 | import java.util.UUID; | 28 | import java.util.UUID; |
29 | 29 |
@@ -27,11 +27,11 @@ import org.springframework.stereotype.Component; | @@ -27,11 +27,11 @@ import org.springframework.stereotype.Component; | ||
27 | import org.thingsboard.server.common.data.Device; | 27 | import org.thingsboard.server.common.data.Device; |
28 | import org.thingsboard.server.common.data.TenantDeviceType; | 28 | import org.thingsboard.server.common.data.TenantDeviceType; |
29 | import org.thingsboard.server.common.data.page.TextPageLink; | 29 | import org.thingsboard.server.common.data.page.TextPageLink; |
30 | -import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; | ||
31 | import org.thingsboard.server.dao.DaoUtil; | 30 | import org.thingsboard.server.dao.DaoUtil; |
32 | -import org.thingsboard.server.dao.util.NoSqlDao; | ||
33 | import org.thingsboard.server.dao.model.TenantDeviceTypeEntity; | 31 | import org.thingsboard.server.dao.model.TenantDeviceTypeEntity; |
34 | import org.thingsboard.server.dao.model.nosql.DeviceEntity; | 32 | import org.thingsboard.server.dao.model.nosql.DeviceEntity; |
33 | +import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; | ||
34 | +import org.thingsboard.server.dao.util.NoSqlDao; | ||
35 | 35 | ||
36 | import javax.annotation.Nullable; | 36 | import javax.annotation.Nullable; |
37 | import java.util.*; | 37 | import java.util.*; |
@@ -20,7 +20,6 @@ import org.thingsboard.server.common.data.Device; | @@ -20,7 +20,6 @@ import org.thingsboard.server.common.data.Device; | ||
20 | import org.thingsboard.server.common.data.TenantDeviceType; | 20 | import org.thingsboard.server.common.data.TenantDeviceType; |
21 | import org.thingsboard.server.common.data.page.TextPageLink; | 21 | import org.thingsboard.server.common.data.page.TextPageLink; |
22 | import org.thingsboard.server.dao.Dao; | 22 | import org.thingsboard.server.dao.Dao; |
23 | -import org.thingsboard.server.dao.model.TenantDeviceTypeEntity; | ||
24 | 23 | ||
25 | import java.util.List; | 24 | import java.util.List; |
26 | import java.util.Optional; | 25 | import java.util.Optional; |
@@ -21,7 +21,7 @@ import com.google.common.util.concurrent.ListenableFuture; | @@ -21,7 +21,7 @@ import com.google.common.util.concurrent.ListenableFuture; | ||
21 | import lombok.extern.slf4j.Slf4j; | 21 | import lombok.extern.slf4j.Slf4j; |
22 | import org.springframework.beans.factory.annotation.Autowired; | 22 | import org.springframework.beans.factory.annotation.Autowired; |
23 | import org.springframework.stereotype.Service; | 23 | import org.springframework.stereotype.Service; |
24 | -import org.thingsboard.server.common.data.*; | 24 | +import org.thingsboard.server.common.data.HasName; |
25 | import org.thingsboard.server.common.data.alarm.AlarmId; | 25 | import org.thingsboard.server.common.data.alarm.AlarmId; |
26 | import org.thingsboard.server.common.data.id.*; | 26 | import org.thingsboard.server.common.data.id.*; |
27 | import org.thingsboard.server.dao.alarm.AlarmService; | 27 | import org.thingsboard.server.dao.alarm.AlarmService; |
@@ -28,11 +28,11 @@ import org.thingsboard.server.common.data.id.EntityId; | @@ -28,11 +28,11 @@ import org.thingsboard.server.common.data.id.EntityId; | ||
28 | import org.thingsboard.server.common.data.id.EventId; | 28 | import org.thingsboard.server.common.data.id.EventId; |
29 | import org.thingsboard.server.common.data.id.TenantId; | 29 | import org.thingsboard.server.common.data.id.TenantId; |
30 | import org.thingsboard.server.common.data.page.TimePageLink; | 30 | import org.thingsboard.server.common.data.page.TimePageLink; |
31 | -import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTimeDao; | ||
32 | import org.thingsboard.server.dao.DaoUtil; | 31 | import org.thingsboard.server.dao.DaoUtil; |
33 | -import org.thingsboard.server.dao.util.NoSqlDao; | ||
34 | import org.thingsboard.server.dao.model.ModelConstants; | 32 | import org.thingsboard.server.dao.model.ModelConstants; |
35 | import org.thingsboard.server.dao.model.nosql.EventEntity; | 33 | import org.thingsboard.server.dao.model.nosql.EventEntity; |
34 | +import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTimeDao; | ||
35 | +import org.thingsboard.server.dao.util.NoSqlDao; | ||
36 | 36 | ||
37 | import java.util.Arrays; | 37 | import java.util.Arrays; |
38 | import java.util.List; | 38 | import java.util.List; |
1 | +/** | ||
2 | + * Copyright © 2016-2017 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.dao.model; | ||
17 | + | ||
18 | +import lombok.Data; | ||
19 | +import org.thingsboard.server.common.data.UUIDConverter; | ||
20 | + | ||
21 | +import javax.persistence.Column; | ||
22 | +import javax.persistence.Id; | ||
23 | +import javax.persistence.MappedSuperclass; | ||
24 | +import java.util.UUID; | ||
25 | + | ||
26 | +/** | ||
27 | + * Created by ashvayka on 13.07.17. | ||
28 | + */ | ||
29 | +@Data | ||
30 | +@MappedSuperclass | ||
31 | +public abstract class BaseSqlEntity<D> implements BaseEntity<D> { | ||
32 | + | ||
33 | + @Id | ||
34 | + @Column(name = ModelConstants.ID_PROPERTY) | ||
35 | + protected String id; | ||
36 | + | ||
37 | + @Override | ||
38 | + public UUID getId() { | ||
39 | + if (id == null) { | ||
40 | + return null; | ||
41 | + } | ||
42 | + return UUIDConverter.fromString(id); | ||
43 | + } | ||
44 | + | ||
45 | + public void setId(UUID id) { | ||
46 | + this.id = UUIDConverter.fromTimeUUID(id); | ||
47 | + } | ||
48 | + | ||
49 | + protected UUID toUUID(String src){ | ||
50 | + return UUIDConverter.fromString(src); | ||
51 | + } | ||
52 | + | ||
53 | + protected String toString(UUID timeUUID){ | ||
54 | + return UUIDConverter.fromTimeUUID(timeUUID); | ||
55 | + } | ||
56 | + | ||
57 | +} |
@@ -15,18 +15,20 @@ | @@ -15,18 +15,20 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model; | 16 | package org.thingsboard.server.dao.model; |
17 | 17 | ||
18 | -import java.util.UUID; | ||
19 | - | ||
20 | import com.datastax.driver.core.utils.UUIDs; | 18 | import com.datastax.driver.core.utils.UUIDs; |
21 | import org.apache.commons.lang3.ArrayUtils; | 19 | import org.apache.commons.lang3.ArrayUtils; |
20 | +import org.thingsboard.server.common.data.UUIDConverter; | ||
22 | import org.thingsboard.server.common.data.kv.Aggregation; | 21 | import org.thingsboard.server.common.data.kv.Aggregation; |
23 | 22 | ||
23 | +import java.util.UUID; | ||
24 | + | ||
24 | public class ModelConstants { | 25 | public class ModelConstants { |
25 | 26 | ||
26 | private ModelConstants() { | 27 | private ModelConstants() { |
27 | } | 28 | } |
28 | 29 | ||
29 | public static UUID NULL_UUID = UUIDs.startOf(0); | 30 | public static UUID NULL_UUID = UUIDs.startOf(0); |
31 | + public static String NULL_UUID_STR = UUIDConverter.fromTimeUUID(NULL_UUID); | ||
30 | 32 | ||
31 | /** | 33 | /** |
32 | * Generic constants. | 34 | * Generic constants. |
@@ -15,24 +15,20 @@ | @@ -15,24 +15,20 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.nosql; | 16 | package org.thingsboard.server.dao.model.nosql; |
17 | 17 | ||
18 | -import static org.thingsboard.server.dao.model.ModelConstants.ADMIN_SETTINGS_COLUMN_FAMILY_NAME; | ||
19 | -import static org.thingsboard.server.dao.model.ModelConstants.ADMIN_SETTINGS_JSON_VALUE_PROPERTY; | ||
20 | -import static org.thingsboard.server.dao.model.ModelConstants.ADMIN_SETTINGS_KEY_PROPERTY; | ||
21 | -import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; | ||
22 | - | ||
23 | -import java.util.UUID; | ||
24 | - | ||
25 | -import org.thingsboard.server.common.data.AdminSettings; | ||
26 | -import org.thingsboard.server.common.data.id.AdminSettingsId; | ||
27 | -import org.thingsboard.server.dao.model.BaseEntity; | ||
28 | -import org.thingsboard.server.dao.model.type.JsonCodec; | ||
29 | - | ||
30 | import com.datastax.driver.core.utils.UUIDs; | 18 | import com.datastax.driver.core.utils.UUIDs; |
31 | import com.datastax.driver.mapping.annotations.Column; | 19 | import com.datastax.driver.mapping.annotations.Column; |
32 | import com.datastax.driver.mapping.annotations.PartitionKey; | 20 | import com.datastax.driver.mapping.annotations.PartitionKey; |
33 | import com.datastax.driver.mapping.annotations.Table; | 21 | import com.datastax.driver.mapping.annotations.Table; |
34 | import com.datastax.driver.mapping.annotations.Transient; | 22 | import com.datastax.driver.mapping.annotations.Transient; |
35 | import com.fasterxml.jackson.databind.JsonNode; | 23 | import com.fasterxml.jackson.databind.JsonNode; |
24 | +import org.thingsboard.server.common.data.AdminSettings; | ||
25 | +import org.thingsboard.server.common.data.id.AdminSettingsId; | ||
26 | +import org.thingsboard.server.dao.model.BaseEntity; | ||
27 | +import org.thingsboard.server.dao.model.type.JsonCodec; | ||
28 | + | ||
29 | +import java.util.UUID; | ||
30 | + | ||
31 | +import static org.thingsboard.server.dao.model.ModelConstants.*; | ||
36 | 32 | ||
37 | @Table(name = ADMIN_SETTINGS_COLUMN_FAMILY_NAME) | 33 | @Table(name = ADMIN_SETTINGS_COLUMN_FAMILY_NAME) |
38 | public final class AdminSettingsEntity implements BaseEntity<AdminSettings> { | 34 | public final class AdminSettingsEntity implements BaseEntity<AdminSettings> { |
@@ -15,20 +15,19 @@ | @@ -15,20 +15,19 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.nosql; | 16 | package org.thingsboard.server.dao.model.nosql; |
17 | 17 | ||
18 | -import java.util.UUID; | ||
19 | - | ||
20 | -import org.thingsboard.server.common.data.Customer; | ||
21 | -import org.thingsboard.server.common.data.id.CustomerId; | ||
22 | -import org.thingsboard.server.common.data.id.TenantId; | ||
23 | -import org.thingsboard.server.dao.model.SearchTextEntity; | ||
24 | -import org.thingsboard.server.dao.model.type.JsonCodec; | ||
25 | - | ||
26 | import com.datastax.driver.core.utils.UUIDs; | 18 | import com.datastax.driver.core.utils.UUIDs; |
27 | import com.datastax.driver.mapping.annotations.Column; | 19 | import com.datastax.driver.mapping.annotations.Column; |
28 | import com.datastax.driver.mapping.annotations.PartitionKey; | 20 | import com.datastax.driver.mapping.annotations.PartitionKey; |
29 | import com.datastax.driver.mapping.annotations.Table; | 21 | import com.datastax.driver.mapping.annotations.Table; |
30 | import com.datastax.driver.mapping.annotations.Transient; | 22 | import com.datastax.driver.mapping.annotations.Transient; |
31 | import com.fasterxml.jackson.databind.JsonNode; | 23 | import com.fasterxml.jackson.databind.JsonNode; |
24 | +import org.thingsboard.server.common.data.Customer; | ||
25 | +import org.thingsboard.server.common.data.id.CustomerId; | ||
26 | +import org.thingsboard.server.common.data.id.TenantId; | ||
27 | +import org.thingsboard.server.dao.model.SearchTextEntity; | ||
28 | +import org.thingsboard.server.dao.model.type.JsonCodec; | ||
29 | + | ||
30 | +import java.util.UUID; | ||
32 | 31 | ||
33 | import static org.thingsboard.server.dao.model.ModelConstants.*; | 32 | import static org.thingsboard.server.dao.model.ModelConstants.*; |
34 | 33 |
@@ -15,8 +15,12 @@ | @@ -15,8 +15,12 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.nosql; | 16 | package org.thingsboard.server.dao.model.nosql; |
17 | 17 | ||
18 | -import java.util.UUID; | ||
19 | - | 18 | +import com.datastax.driver.core.utils.UUIDs; |
19 | +import com.datastax.driver.mapping.annotations.Column; | ||
20 | +import com.datastax.driver.mapping.annotations.PartitionKey; | ||
21 | +import com.datastax.driver.mapping.annotations.Table; | ||
22 | +import com.datastax.driver.mapping.annotations.Transient; | ||
23 | +import com.fasterxml.jackson.databind.JsonNode; | ||
20 | import org.thingsboard.server.common.data.Dashboard; | 24 | import org.thingsboard.server.common.data.Dashboard; |
21 | import org.thingsboard.server.common.data.id.CustomerId; | 25 | import org.thingsboard.server.common.data.id.CustomerId; |
22 | import org.thingsboard.server.common.data.id.DashboardId; | 26 | import org.thingsboard.server.common.data.id.DashboardId; |
@@ -24,12 +28,7 @@ import org.thingsboard.server.common.data.id.TenantId; | @@ -24,12 +28,7 @@ import org.thingsboard.server.common.data.id.TenantId; | ||
24 | import org.thingsboard.server.dao.model.SearchTextEntity; | 28 | import org.thingsboard.server.dao.model.SearchTextEntity; |
25 | import org.thingsboard.server.dao.model.type.JsonCodec; | 29 | import org.thingsboard.server.dao.model.type.JsonCodec; |
26 | 30 | ||
27 | -import com.datastax.driver.core.utils.UUIDs; | ||
28 | -import com.datastax.driver.mapping.annotations.Column; | ||
29 | -import com.datastax.driver.mapping.annotations.PartitionKey; | ||
30 | -import com.datastax.driver.mapping.annotations.Table; | ||
31 | -import com.datastax.driver.mapping.annotations.Transient; | ||
32 | -import com.fasterxml.jackson.databind.JsonNode; | 31 | +import java.util.UUID; |
33 | 32 | ||
34 | import static org.thingsboard.server.dao.model.ModelConstants.*; | 33 | import static org.thingsboard.server.dao.model.ModelConstants.*; |
35 | 34 |
@@ -15,19 +15,18 @@ | @@ -15,19 +15,18 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.nosql; | 16 | package org.thingsboard.server.dao.model.nosql; |
17 | 17 | ||
18 | -import java.util.UUID; | ||
19 | - | 18 | +import com.datastax.driver.core.utils.UUIDs; |
19 | +import com.datastax.driver.mapping.annotations.Column; | ||
20 | +import com.datastax.driver.mapping.annotations.PartitionKey; | ||
21 | +import com.datastax.driver.mapping.annotations.Table; | ||
22 | +import com.datastax.driver.mapping.annotations.Transient; | ||
20 | import org.thingsboard.server.common.data.DashboardInfo; | 23 | import org.thingsboard.server.common.data.DashboardInfo; |
21 | import org.thingsboard.server.common.data.id.CustomerId; | 24 | import org.thingsboard.server.common.data.id.CustomerId; |
22 | import org.thingsboard.server.common.data.id.DashboardId; | 25 | import org.thingsboard.server.common.data.id.DashboardId; |
23 | import org.thingsboard.server.common.data.id.TenantId; | 26 | import org.thingsboard.server.common.data.id.TenantId; |
24 | import org.thingsboard.server.dao.model.SearchTextEntity; | 27 | import org.thingsboard.server.dao.model.SearchTextEntity; |
25 | 28 | ||
26 | -import com.datastax.driver.core.utils.UUIDs; | ||
27 | -import com.datastax.driver.mapping.annotations.Column; | ||
28 | -import com.datastax.driver.mapping.annotations.PartitionKey; | ||
29 | -import com.datastax.driver.mapping.annotations.Table; | ||
30 | -import com.datastax.driver.mapping.annotations.Transient; | 29 | +import java.util.UUID; |
31 | 30 | ||
32 | import static org.thingsboard.server.dao.model.ModelConstants.*; | 31 | import static org.thingsboard.server.dao.model.ModelConstants.*; |
33 | 32 |
@@ -15,8 +15,11 @@ | @@ -15,8 +15,11 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.nosql; | 16 | package org.thingsboard.server.dao.model.nosql; |
17 | 17 | ||
18 | -import java.util.UUID; | ||
19 | - | 18 | +import com.datastax.driver.core.utils.UUIDs; |
19 | +import com.datastax.driver.mapping.annotations.Column; | ||
20 | +import com.datastax.driver.mapping.annotations.PartitionKey; | ||
21 | +import com.datastax.driver.mapping.annotations.Table; | ||
22 | +import com.datastax.driver.mapping.annotations.Transient; | ||
20 | import org.thingsboard.server.common.data.id.DeviceCredentialsId; | 23 | import org.thingsboard.server.common.data.id.DeviceCredentialsId; |
21 | import org.thingsboard.server.common.data.id.DeviceId; | 24 | import org.thingsboard.server.common.data.id.DeviceId; |
22 | import org.thingsboard.server.common.data.security.DeviceCredentials; | 25 | import org.thingsboard.server.common.data.security.DeviceCredentials; |
@@ -24,11 +27,7 @@ import org.thingsboard.server.common.data.security.DeviceCredentialsType; | @@ -24,11 +27,7 @@ import org.thingsboard.server.common.data.security.DeviceCredentialsType; | ||
24 | import org.thingsboard.server.dao.model.BaseEntity; | 27 | import org.thingsboard.server.dao.model.BaseEntity; |
25 | import org.thingsboard.server.dao.model.type.DeviceCredentialsTypeCodec; | 28 | import org.thingsboard.server.dao.model.type.DeviceCredentialsTypeCodec; |
26 | 29 | ||
27 | -import com.datastax.driver.core.utils.UUIDs; | ||
28 | -import com.datastax.driver.mapping.annotations.Column; | ||
29 | -import com.datastax.driver.mapping.annotations.PartitionKey; | ||
30 | -import com.datastax.driver.mapping.annotations.Table; | ||
31 | -import com.datastax.driver.mapping.annotations.Transient; | 30 | +import java.util.UUID; |
32 | 31 | ||
33 | import static org.thingsboard.server.dao.model.ModelConstants.*; | 32 | import static org.thingsboard.server.dao.model.ModelConstants.*; |
34 | 33 |
@@ -28,10 +28,10 @@ import org.thingsboard.server.common.data.id.TenantId; | @@ -28,10 +28,10 @@ import org.thingsboard.server.common.data.id.TenantId; | ||
28 | import org.thingsboard.server.dao.model.SearchTextEntity; | 28 | import org.thingsboard.server.dao.model.SearchTextEntity; |
29 | import org.thingsboard.server.dao.model.type.JsonCodec; | 29 | import org.thingsboard.server.dao.model.type.JsonCodec; |
30 | 30 | ||
31 | -import static org.thingsboard.server.dao.model.ModelConstants.*; | ||
32 | - | ||
33 | import java.util.UUID; | 31 | import java.util.UUID; |
34 | 32 | ||
33 | +import static org.thingsboard.server.dao.model.ModelConstants.*; | ||
34 | + | ||
35 | @Table(name = DEVICE_COLUMN_FAMILY_NAME) | 35 | @Table(name = DEVICE_COLUMN_FAMILY_NAME) |
36 | public final class DeviceEntity implements SearchTextEntity<Device> { | 36 | public final class DeviceEntity implements SearchTextEntity<Device> { |
37 | 37 |
@@ -26,11 +26,11 @@ import org.thingsboard.server.dao.model.SearchTextEntity; | @@ -26,11 +26,11 @@ import org.thingsboard.server.dao.model.SearchTextEntity; | ||
26 | import org.thingsboard.server.dao.model.type.ComponentLifecycleStateCodec; | 26 | import org.thingsboard.server.dao.model.type.ComponentLifecycleStateCodec; |
27 | import org.thingsboard.server.dao.model.type.JsonCodec; | 27 | import org.thingsboard.server.dao.model.type.JsonCodec; |
28 | 28 | ||
29 | -import static org.thingsboard.server.dao.model.ModelConstants.*; | ||
30 | - | ||
31 | import java.util.Objects; | 29 | import java.util.Objects; |
32 | import java.util.UUID; | 30 | import java.util.UUID; |
33 | 31 | ||
32 | +import static org.thingsboard.server.dao.model.ModelConstants.*; | ||
33 | + | ||
34 | @Table(name = PLUGIN_COLUMN_FAMILY_NAME) | 34 | @Table(name = PLUGIN_COLUMN_FAMILY_NAME) |
35 | public class PluginMetaDataEntity implements SearchTextEntity<PluginMetaData> { | 35 | public class PluginMetaDataEntity implements SearchTextEntity<PluginMetaData> { |
36 | 36 |
@@ -30,12 +30,12 @@ import org.thingsboard.server.dao.model.SearchTextEntity; | @@ -30,12 +30,12 @@ import org.thingsboard.server.dao.model.SearchTextEntity; | ||
30 | import org.thingsboard.server.dao.model.type.ComponentLifecycleStateCodec; | 30 | import org.thingsboard.server.dao.model.type.ComponentLifecycleStateCodec; |
31 | import org.thingsboard.server.dao.model.type.JsonCodec; | 31 | import org.thingsboard.server.dao.model.type.JsonCodec; |
32 | 32 | ||
33 | -import static org.thingsboard.server.dao.model.ModelConstants.*; | ||
34 | - | ||
35 | import javax.persistence.Transient; | 33 | import javax.persistence.Transient; |
36 | import java.util.Objects; | 34 | import java.util.Objects; |
37 | import java.util.UUID; | 35 | import java.util.UUID; |
38 | 36 | ||
37 | +import static org.thingsboard.server.dao.model.ModelConstants.*; | ||
38 | + | ||
39 | @Table(name = RULE_COLUMN_FAMILY_NAME) | 39 | @Table(name = RULE_COLUMN_FAMILY_NAME) |
40 | public class RuleMetaDataEntity implements SearchTextEntity<RuleMetaData> { | 40 | public class RuleMetaDataEntity implements SearchTextEntity<RuleMetaData> { |
41 | 41 |
@@ -15,19 +15,19 @@ | @@ -15,19 +15,19 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.nosql; | 16 | package org.thingsboard.server.dao.model.nosql; |
17 | 17 | ||
18 | -import java.util.UUID; | ||
19 | - | ||
20 | -import org.thingsboard.server.common.data.Tenant; | ||
21 | -import org.thingsboard.server.common.data.id.TenantId; | ||
22 | -import org.thingsboard.server.dao.model.SearchTextEntity; | ||
23 | -import org.thingsboard.server.dao.model.type.JsonCodec; | ||
24 | - | ||
25 | import com.datastax.driver.core.utils.UUIDs; | 18 | import com.datastax.driver.core.utils.UUIDs; |
26 | import com.datastax.driver.mapping.annotations.Column; | 19 | import com.datastax.driver.mapping.annotations.Column; |
27 | import com.datastax.driver.mapping.annotations.PartitionKey; | 20 | import com.datastax.driver.mapping.annotations.PartitionKey; |
28 | import com.datastax.driver.mapping.annotations.Table; | 21 | import com.datastax.driver.mapping.annotations.Table; |
29 | import com.datastax.driver.mapping.annotations.Transient; | 22 | import com.datastax.driver.mapping.annotations.Transient; |
30 | import com.fasterxml.jackson.databind.JsonNode; | 23 | import com.fasterxml.jackson.databind.JsonNode; |
24 | +import org.thingsboard.server.common.data.Tenant; | ||
25 | +import org.thingsboard.server.common.data.id.TenantId; | ||
26 | +import org.thingsboard.server.dao.model.SearchTextEntity; | ||
27 | +import org.thingsboard.server.dao.model.type.JsonCodec; | ||
28 | + | ||
29 | +import java.util.UUID; | ||
30 | + | ||
31 | import static org.thingsboard.server.dao.model.ModelConstants.*; | 31 | import static org.thingsboard.server.dao.model.ModelConstants.*; |
32 | 32 | ||
33 | @Table(name = TENANT_COLUMN_FAMILY_NAME) | 33 | @Table(name = TENANT_COLUMN_FAMILY_NAME) |
@@ -15,18 +15,18 @@ | @@ -15,18 +15,18 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.nosql; | 16 | package org.thingsboard.server.dao.model.nosql; |
17 | 17 | ||
18 | -import java.util.UUID; | ||
19 | - | ||
20 | -import org.thingsboard.server.common.data.id.UserCredentialsId; | ||
21 | -import org.thingsboard.server.common.data.id.UserId; | ||
22 | -import org.thingsboard.server.common.data.security.UserCredentials; | ||
23 | - | ||
24 | import com.datastax.driver.core.utils.UUIDs; | 18 | import com.datastax.driver.core.utils.UUIDs; |
25 | import com.datastax.driver.mapping.annotations.Column; | 19 | import com.datastax.driver.mapping.annotations.Column; |
26 | import com.datastax.driver.mapping.annotations.PartitionKey; | 20 | import com.datastax.driver.mapping.annotations.PartitionKey; |
27 | import com.datastax.driver.mapping.annotations.Table; | 21 | import com.datastax.driver.mapping.annotations.Table; |
28 | import com.datastax.driver.mapping.annotations.Transient; | 22 | import com.datastax.driver.mapping.annotations.Transient; |
23 | +import org.thingsboard.server.common.data.id.UserCredentialsId; | ||
24 | +import org.thingsboard.server.common.data.id.UserId; | ||
25 | +import org.thingsboard.server.common.data.security.UserCredentials; | ||
29 | import org.thingsboard.server.dao.model.BaseEntity; | 26 | import org.thingsboard.server.dao.model.BaseEntity; |
27 | + | ||
28 | +import java.util.UUID; | ||
29 | + | ||
30 | import static org.thingsboard.server.dao.model.ModelConstants.*; | 30 | import static org.thingsboard.server.dao.model.ModelConstants.*; |
31 | 31 | ||
32 | @Table(name = USER_CREDENTIALS_COLUMN_FAMILY_NAME) | 32 | @Table(name = USER_CREDENTIALS_COLUMN_FAMILY_NAME) |
@@ -15,8 +15,12 @@ | @@ -15,8 +15,12 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.nosql; | 16 | package org.thingsboard.server.dao.model.nosql; |
17 | 17 | ||
18 | -import java.util.UUID; | ||
19 | - | 18 | +import com.datastax.driver.core.utils.UUIDs; |
19 | +import com.datastax.driver.mapping.annotations.Column; | ||
20 | +import com.datastax.driver.mapping.annotations.PartitionKey; | ||
21 | +import com.datastax.driver.mapping.annotations.Table; | ||
22 | +import com.datastax.driver.mapping.annotations.Transient; | ||
23 | +import com.fasterxml.jackson.databind.JsonNode; | ||
20 | import org.thingsboard.server.common.data.User; | 24 | import org.thingsboard.server.common.data.User; |
21 | import org.thingsboard.server.common.data.id.CustomerId; | 25 | import org.thingsboard.server.common.data.id.CustomerId; |
22 | import org.thingsboard.server.common.data.id.TenantId; | 26 | import org.thingsboard.server.common.data.id.TenantId; |
@@ -26,12 +30,8 @@ import org.thingsboard.server.dao.model.SearchTextEntity; | @@ -26,12 +30,8 @@ import org.thingsboard.server.dao.model.SearchTextEntity; | ||
26 | import org.thingsboard.server.dao.model.type.AuthorityCodec; | 30 | import org.thingsboard.server.dao.model.type.AuthorityCodec; |
27 | import org.thingsboard.server.dao.model.type.JsonCodec; | 31 | import org.thingsboard.server.dao.model.type.JsonCodec; |
28 | 32 | ||
29 | -import com.datastax.driver.core.utils.UUIDs; | ||
30 | -import com.datastax.driver.mapping.annotations.Column; | ||
31 | -import com.datastax.driver.mapping.annotations.PartitionKey; | ||
32 | -import com.datastax.driver.mapping.annotations.Table; | ||
33 | -import com.datastax.driver.mapping.annotations.Transient; | ||
34 | -import com.fasterxml.jackson.databind.JsonNode; | 33 | +import java.util.UUID; |
34 | + | ||
35 | import static org.thingsboard.server.dao.model.ModelConstants.*; | 35 | import static org.thingsboard.server.dao.model.ModelConstants.*; |
36 | 36 | ||
37 | @Table(name = USER_COLUMN_FAMILY_NAME) | 37 | @Table(name = USER_COLUMN_FAMILY_NAME) |
@@ -26,10 +26,11 @@ import org.thingsboard.server.common.data.id.WidgetTypeId; | @@ -26,10 +26,11 @@ import org.thingsboard.server.common.data.id.WidgetTypeId; | ||
26 | import org.thingsboard.server.common.data.widget.WidgetType; | 26 | import org.thingsboard.server.common.data.widget.WidgetType; |
27 | import org.thingsboard.server.dao.model.BaseEntity; | 27 | import org.thingsboard.server.dao.model.BaseEntity; |
28 | import org.thingsboard.server.dao.model.type.JsonCodec; | 28 | import org.thingsboard.server.dao.model.type.JsonCodec; |
29 | -import static org.thingsboard.server.dao.model.ModelConstants.*; | ||
30 | 29 | ||
31 | import java.util.UUID; | 30 | import java.util.UUID; |
32 | 31 | ||
32 | +import static org.thingsboard.server.dao.model.ModelConstants.*; | ||
33 | + | ||
33 | @Table(name = WIDGET_TYPE_COLUMN_FAMILY_NAME) | 34 | @Table(name = WIDGET_TYPE_COLUMN_FAMILY_NAME) |
34 | public final class WidgetTypeEntity implements BaseEntity<WidgetType> { | 35 | public final class WidgetTypeEntity implements BaseEntity<WidgetType> { |
35 | 36 |
@@ -25,11 +25,12 @@ import org.thingsboard.server.common.data.id.TenantId; | @@ -25,11 +25,12 @@ import org.thingsboard.server.common.data.id.TenantId; | ||
25 | import org.thingsboard.server.common.data.id.WidgetsBundleId; | 25 | import org.thingsboard.server.common.data.id.WidgetsBundleId; |
26 | import org.thingsboard.server.common.data.widget.WidgetsBundle; | 26 | import org.thingsboard.server.common.data.widget.WidgetsBundle; |
27 | import org.thingsboard.server.dao.model.SearchTextEntity; | 27 | import org.thingsboard.server.dao.model.SearchTextEntity; |
28 | -import static org.thingsboard.server.dao.model.ModelConstants.*; | ||
29 | 28 | ||
30 | import java.nio.ByteBuffer; | 29 | import java.nio.ByteBuffer; |
31 | import java.util.UUID; | 30 | import java.util.UUID; |
32 | 31 | ||
32 | +import static org.thingsboard.server.dao.model.ModelConstants.*; | ||
33 | + | ||
33 | @Table(name = WIDGETS_BUNDLE_COLUMN_FAMILY_NAME) | 34 | @Table(name = WIDGETS_BUNDLE_COLUMN_FAMILY_NAME) |
34 | public final class WidgetsBundleEntity implements SearchTextEntity<WidgetsBundle> { | 35 | public final class WidgetsBundleEntity implements SearchTextEntity<WidgetsBundle> { |
35 | 36 |
@@ -18,31 +18,33 @@ package org.thingsboard.server.dao.model.sql; | @@ -18,31 +18,33 @@ package org.thingsboard.server.dao.model.sql; | ||
18 | import com.datastax.driver.core.utils.UUIDs; | 18 | import com.datastax.driver.core.utils.UUIDs; |
19 | import com.fasterxml.jackson.databind.JsonNode; | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 20 | import lombok.Data; |
21 | +import lombok.EqualsAndHashCode; | ||
21 | import org.hibernate.annotations.Type; | 22 | import org.hibernate.annotations.Type; |
22 | import org.hibernate.annotations.TypeDef; | 23 | import org.hibernate.annotations.TypeDef; |
23 | import org.thingsboard.server.common.data.AdminSettings; | 24 | import org.thingsboard.server.common.data.AdminSettings; |
25 | +import org.thingsboard.server.common.data.UUIDConverter; | ||
24 | import org.thingsboard.server.common.data.id.AdminSettingsId; | 26 | import org.thingsboard.server.common.data.id.AdminSettingsId; |
25 | import org.thingsboard.server.dao.model.BaseEntity; | 27 | import org.thingsboard.server.dao.model.BaseEntity; |
28 | +import org.thingsboard.server.dao.model.BaseSqlEntity; | ||
26 | import org.thingsboard.server.dao.util.mapping.JsonStringType; | 29 | import org.thingsboard.server.dao.util.mapping.JsonStringType; |
27 | 30 | ||
28 | -import javax.persistence.*; | ||
29 | -import java.util.UUID; | 31 | +import javax.persistence.Column; |
32 | +import javax.persistence.Entity; | ||
33 | +import javax.persistence.Table; | ||
34 | +import javax.persistence.Transient; | ||
30 | 35 | ||
31 | import static org.thingsboard.server.dao.model.ModelConstants.*; | 36 | import static org.thingsboard.server.dao.model.ModelConstants.*; |
32 | 37 | ||
33 | @Data | 38 | @Data |
39 | +@EqualsAndHashCode(callSuper = true) | ||
34 | @Entity | 40 | @Entity |
35 | @TypeDef(name = "json", typeClass = JsonStringType.class) | 41 | @TypeDef(name = "json", typeClass = JsonStringType.class) |
36 | @Table(name = ADMIN_SETTINGS_COLUMN_FAMILY_NAME) | 42 | @Table(name = ADMIN_SETTINGS_COLUMN_FAMILY_NAME) |
37 | -public final class AdminSettingsEntity implements BaseEntity<AdminSettings> { | 43 | +public final class AdminSettingsEntity extends BaseSqlEntity<AdminSettings> implements BaseEntity<AdminSettings> { |
38 | 44 | ||
39 | @Transient | 45 | @Transient |
40 | private static final long serialVersionUID = 842759712850362147L; | 46 | private static final long serialVersionUID = 842759712850362147L; |
41 | 47 | ||
42 | - @Id | ||
43 | - @Column(name = ID_PROPERTY) | ||
44 | - private UUID id; | ||
45 | - | ||
46 | @Column(name = ADMIN_SETTINGS_KEY_PROPERTY) | 48 | @Column(name = ADMIN_SETTINGS_KEY_PROPERTY) |
47 | private String key; | 49 | private String key; |
48 | 50 | ||
@@ -56,26 +58,16 @@ public final class AdminSettingsEntity implements BaseEntity<AdminSettings> { | @@ -56,26 +58,16 @@ public final class AdminSettingsEntity implements BaseEntity<AdminSettings> { | ||
56 | 58 | ||
57 | public AdminSettingsEntity(AdminSettings adminSettings) { | 59 | public AdminSettingsEntity(AdminSettings adminSettings) { |
58 | if (adminSettings.getId() != null) { | 60 | if (adminSettings.getId() != null) { |
59 | - this.id = adminSettings.getId().getId(); | 61 | + this.setId(adminSettings.getId().getId()); |
60 | } | 62 | } |
61 | this.key = adminSettings.getKey(); | 63 | this.key = adminSettings.getKey(); |
62 | this.jsonValue = adminSettings.getJsonValue(); | 64 | this.jsonValue = adminSettings.getJsonValue(); |
63 | } | 65 | } |
64 | 66 | ||
65 | @Override | 67 | @Override |
66 | - public UUID getId() { | ||
67 | - return id; | ||
68 | - } | ||
69 | - | ||
70 | - @Override | ||
71 | - public void setId(UUID id) { | ||
72 | - this.id = id; | ||
73 | - } | ||
74 | - | ||
75 | - @Override | ||
76 | public AdminSettings toData() { | 68 | public AdminSettings toData() { |
77 | - AdminSettings adminSettings = new AdminSettings(new AdminSettingsId(id)); | ||
78 | - adminSettings.setCreatedTime(UUIDs.unixTimestamp(id)); | 69 | + AdminSettings adminSettings = new AdminSettings(new AdminSettingsId(UUIDConverter.fromString(id))); |
70 | + adminSettings.setCreatedTime(UUIDs.unixTimestamp(UUIDConverter.fromString(id))); | ||
79 | adminSettings.setKey(key); | 71 | adminSettings.setKey(key); |
80 | adminSettings.setJsonValue(jsonValue); | 72 | adminSettings.setJsonValue(jsonValue); |
81 | return adminSettings; | 73 | return adminSettings; |
@@ -18,9 +18,11 @@ package org.thingsboard.server.dao.model.sql; | @@ -18,9 +18,11 @@ package org.thingsboard.server.dao.model.sql; | ||
18 | import com.datastax.driver.core.utils.UUIDs; | 18 | import com.datastax.driver.core.utils.UUIDs; |
19 | import com.fasterxml.jackson.databind.JsonNode; | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 20 | import lombok.Data; |
21 | +import lombok.EqualsAndHashCode; | ||
21 | import org.hibernate.annotations.Type; | 22 | import org.hibernate.annotations.Type; |
22 | import org.hibernate.annotations.TypeDef; | 23 | import org.hibernate.annotations.TypeDef; |
23 | import org.thingsboard.server.common.data.EntityType; | 24 | import org.thingsboard.server.common.data.EntityType; |
25 | +import org.thingsboard.server.common.data.UUIDConverter; | ||
24 | import org.thingsboard.server.common.data.alarm.Alarm; | 26 | import org.thingsboard.server.common.data.alarm.Alarm; |
25 | import org.thingsboard.server.common.data.alarm.AlarmId; | 27 | import org.thingsboard.server.common.data.alarm.AlarmId; |
26 | import org.thingsboard.server.common.data.alarm.AlarmSeverity; | 28 | import org.thingsboard.server.common.data.alarm.AlarmSeverity; |
@@ -28,32 +30,29 @@ import org.thingsboard.server.common.data.alarm.AlarmStatus; | @@ -28,32 +30,29 @@ import org.thingsboard.server.common.data.alarm.AlarmStatus; | ||
28 | import org.thingsboard.server.common.data.id.EntityIdFactory; | 30 | import org.thingsboard.server.common.data.id.EntityIdFactory; |
29 | import org.thingsboard.server.common.data.id.TenantId; | 31 | import org.thingsboard.server.common.data.id.TenantId; |
30 | import org.thingsboard.server.dao.model.BaseEntity; | 32 | import org.thingsboard.server.dao.model.BaseEntity; |
33 | +import org.thingsboard.server.dao.model.BaseSqlEntity; | ||
31 | import org.thingsboard.server.dao.model.ModelConstants; | 34 | import org.thingsboard.server.dao.model.ModelConstants; |
32 | import org.thingsboard.server.dao.util.mapping.JsonStringType; | 35 | import org.thingsboard.server.dao.util.mapping.JsonStringType; |
33 | 36 | ||
34 | import javax.persistence.*; | 37 | import javax.persistence.*; |
35 | -import java.util.UUID; | ||
36 | 38 | ||
37 | import static org.thingsboard.server.dao.model.ModelConstants.*; | 39 | import static org.thingsboard.server.dao.model.ModelConstants.*; |
38 | 40 | ||
39 | @Data | 41 | @Data |
42 | +@EqualsAndHashCode(callSuper = true) | ||
40 | @Entity | 43 | @Entity |
41 | @TypeDef(name = "json", typeClass = JsonStringType.class) | 44 | @TypeDef(name = "json", typeClass = JsonStringType.class) |
42 | @Table(name = ALARM_COLUMN_FAMILY_NAME) | 45 | @Table(name = ALARM_COLUMN_FAMILY_NAME) |
43 | -public final class AlarmEntity implements BaseEntity<Alarm> { | 46 | +public final class AlarmEntity extends BaseSqlEntity<Alarm> implements BaseEntity<Alarm> { |
44 | 47 | ||
45 | @Transient | 48 | @Transient |
46 | private static final long serialVersionUID = -339979717281685984L; | 49 | private static final long serialVersionUID = -339979717281685984L; |
47 | 50 | ||
48 | - @Id | ||
49 | - @Column(name = ID_PROPERTY) | ||
50 | - private UUID id; | ||
51 | - | ||
52 | @Column(name = ALARM_TENANT_ID_PROPERTY) | 51 | @Column(name = ALARM_TENANT_ID_PROPERTY) |
53 | - private UUID tenantId; | 52 | + private String tenantId; |
54 | 53 | ||
55 | @Column(name = ALARM_ORIGINATOR_ID_PROPERTY) | 54 | @Column(name = ALARM_ORIGINATOR_ID_PROPERTY) |
56 | - private UUID originatorId; | 55 | + private String originatorId; |
57 | 56 | ||
58 | @Column(name = ALARM_ORIGINATOR_TYPE_PROPERTY) | 57 | @Column(name = ALARM_ORIGINATOR_TYPE_PROPERTY) |
59 | private EntityType originatorType; | 58 | private EntityType originatorType; |
@@ -94,13 +93,13 @@ public final class AlarmEntity implements BaseEntity<Alarm> { | @@ -94,13 +93,13 @@ public final class AlarmEntity implements BaseEntity<Alarm> { | ||
94 | 93 | ||
95 | public AlarmEntity(Alarm alarm) { | 94 | public AlarmEntity(Alarm alarm) { |
96 | if (alarm.getId() != null) { | 95 | if (alarm.getId() != null) { |
97 | - this.id = alarm.getId().getId(); | 96 | + this.setId(alarm.getId().getId()); |
98 | } | 97 | } |
99 | if (alarm.getTenantId() != null) { | 98 | if (alarm.getTenantId() != null) { |
100 | - this.tenantId = alarm.getTenantId().getId(); | 99 | + this.tenantId = UUIDConverter.fromTimeUUID(alarm.getTenantId().getId()); |
101 | } | 100 | } |
102 | this.type = alarm.getType(); | 101 | this.type = alarm.getType(); |
103 | - this.originatorId = alarm.getOriginator().getId(); | 102 | + this.originatorId = UUIDConverter.fromTimeUUID(alarm.getOriginator().getId()); |
104 | this.originatorType = alarm.getOriginator().getEntityType(); | 103 | this.originatorType = alarm.getOriginator().getEntityType(); |
105 | this.type = alarm.getType(); | 104 | this.type = alarm.getType(); |
106 | this.severity = alarm.getSeverity(); | 105 | this.severity = alarm.getSeverity(); |
@@ -115,12 +114,12 @@ public final class AlarmEntity implements BaseEntity<Alarm> { | @@ -115,12 +114,12 @@ public final class AlarmEntity implements BaseEntity<Alarm> { | ||
115 | 114 | ||
116 | @Override | 115 | @Override |
117 | public Alarm toData() { | 116 | public Alarm toData() { |
118 | - Alarm alarm = new Alarm(new AlarmId(id)); | ||
119 | - alarm.setCreatedTime(UUIDs.unixTimestamp(id)); | 117 | + Alarm alarm = new Alarm(new AlarmId(UUIDConverter.fromString(id))); |
118 | + alarm.setCreatedTime(UUIDs.unixTimestamp(UUIDConverter.fromString(id))); | ||
120 | if (tenantId != null) { | 119 | if (tenantId != null) { |
121 | - alarm.setTenantId(new TenantId(tenantId)); | 120 | + alarm.setTenantId(new TenantId(UUIDConverter.fromString(tenantId))); |
122 | } | 121 | } |
123 | - alarm.setOriginator(EntityIdFactory.getByTypeAndUuid(originatorType, originatorId)); | 122 | + alarm.setOriginator(EntityIdFactory.getByTypeAndUuid(originatorType, UUIDConverter.fromString(originatorId))); |
124 | alarm.setType(type); | 123 | alarm.setType(type); |
125 | alarm.setSeverity(severity); | 124 | alarm.setSeverity(severity); |
126 | alarm.setStatus(status); | 125 | alarm.setStatus(status); |
@@ -18,39 +18,41 @@ package org.thingsboard.server.dao.model.sql; | @@ -18,39 +18,41 @@ package org.thingsboard.server.dao.model.sql; | ||
18 | import com.datastax.driver.core.utils.UUIDs; | 18 | import com.datastax.driver.core.utils.UUIDs; |
19 | import com.fasterxml.jackson.databind.JsonNode; | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 20 | import lombok.Data; |
21 | +import lombok.EqualsAndHashCode; | ||
21 | import org.hibernate.annotations.Type; | 22 | import org.hibernate.annotations.Type; |
22 | import org.hibernate.annotations.TypeDef; | 23 | import org.hibernate.annotations.TypeDef; |
24 | +import org.thingsboard.server.common.data.UUIDConverter; | ||
23 | import org.thingsboard.server.common.data.asset.Asset; | 25 | import org.thingsboard.server.common.data.asset.Asset; |
24 | import org.thingsboard.server.common.data.id.AssetId; | 26 | import org.thingsboard.server.common.data.id.AssetId; |
25 | import org.thingsboard.server.common.data.id.CustomerId; | 27 | import org.thingsboard.server.common.data.id.CustomerId; |
26 | import org.thingsboard.server.common.data.id.TenantId; | 28 | import org.thingsboard.server.common.data.id.TenantId; |
29 | +import org.thingsboard.server.dao.model.BaseSqlEntity; | ||
27 | import org.thingsboard.server.dao.model.ModelConstants; | 30 | import org.thingsboard.server.dao.model.ModelConstants; |
28 | import org.thingsboard.server.dao.model.SearchTextEntity; | 31 | import org.thingsboard.server.dao.model.SearchTextEntity; |
29 | import org.thingsboard.server.dao.util.mapping.JsonStringType; | 32 | import org.thingsboard.server.dao.util.mapping.JsonStringType; |
30 | 33 | ||
31 | -import javax.persistence.*; | ||
32 | -import java.util.UUID; | 34 | +import javax.persistence.Column; |
35 | +import javax.persistence.Entity; | ||
36 | +import javax.persistence.Table; | ||
37 | +import javax.persistence.Transient; | ||
33 | 38 | ||
34 | import static org.thingsboard.server.dao.model.ModelConstants.*; | 39 | import static org.thingsboard.server.dao.model.ModelConstants.*; |
35 | 40 | ||
36 | @Data | 41 | @Data |
42 | +@EqualsAndHashCode(callSuper = true) | ||
37 | @Entity | 43 | @Entity |
38 | @TypeDef(name = "json", typeClass = JsonStringType.class) | 44 | @TypeDef(name = "json", typeClass = JsonStringType.class) |
39 | @Table(name = ASSET_COLUMN_FAMILY_NAME) | 45 | @Table(name = ASSET_COLUMN_FAMILY_NAME) |
40 | -public final class AssetEntity implements SearchTextEntity<Asset> { | 46 | +public final class AssetEntity extends BaseSqlEntity<Asset> implements SearchTextEntity<Asset> { |
41 | 47 | ||
42 | @Transient | 48 | @Transient |
43 | private static final long serialVersionUID = -4089175869616037592L; | 49 | private static final long serialVersionUID = -4089175869616037592L; |
44 | 50 | ||
45 | - @Id | ||
46 | - @Column(name = ID_PROPERTY) | ||
47 | - private UUID id; | ||
48 | - | ||
49 | @Column(name = ASSET_TENANT_ID_PROPERTY) | 51 | @Column(name = ASSET_TENANT_ID_PROPERTY) |
50 | - private UUID tenantId; | 52 | + private String tenantId; |
51 | 53 | ||
52 | @Column(name = ASSET_CUSTOMER_ID_PROPERTY) | 54 | @Column(name = ASSET_CUSTOMER_ID_PROPERTY) |
53 | - private UUID customerId; | 55 | + private String customerId; |
54 | 56 | ||
55 | @Column(name = ASSET_NAME_PROPERTY) | 57 | @Column(name = ASSET_NAME_PROPERTY) |
56 | private String name; | 58 | private String name; |
@@ -71,13 +73,13 @@ public final class AssetEntity implements SearchTextEntity<Asset> { | @@ -71,13 +73,13 @@ public final class AssetEntity implements SearchTextEntity<Asset> { | ||
71 | 73 | ||
72 | public AssetEntity(Asset asset) { | 74 | public AssetEntity(Asset asset) { |
73 | if (asset.getId() != null) { | 75 | if (asset.getId() != null) { |
74 | - this.id = asset.getId().getId(); | 76 | + this.setId(asset.getId().getId()); |
75 | } | 77 | } |
76 | if (asset.getTenantId() != null) { | 78 | if (asset.getTenantId() != null) { |
77 | - this.tenantId = asset.getTenantId().getId(); | 79 | + this.tenantId = UUIDConverter.fromTimeUUID(asset.getTenantId().getId()); |
78 | } | 80 | } |
79 | if (asset.getCustomerId() != null) { | 81 | if (asset.getCustomerId() != null) { |
80 | - this.customerId = asset.getCustomerId().getId(); | 82 | + this.customerId = UUIDConverter.fromTimeUUID(asset.getCustomerId().getId()); |
81 | } | 83 | } |
82 | this.name = asset.getName(); | 84 | this.name = asset.getName(); |
83 | this.type = asset.getType(); | 85 | this.type = asset.getType(); |
@@ -100,13 +102,13 @@ public final class AssetEntity implements SearchTextEntity<Asset> { | @@ -100,13 +102,13 @@ public final class AssetEntity implements SearchTextEntity<Asset> { | ||
100 | 102 | ||
101 | @Override | 103 | @Override |
102 | public Asset toData() { | 104 | public Asset toData() { |
103 | - Asset asset = new Asset(new AssetId(id)); | ||
104 | - asset.setCreatedTime(UUIDs.unixTimestamp(id)); | 105 | + Asset asset = new Asset(new AssetId(UUIDConverter.fromString(id))); |
106 | + asset.setCreatedTime(UUIDs.unixTimestamp(UUIDConverter.fromString(id))); | ||
105 | if (tenantId != null) { | 107 | if (tenantId != null) { |
106 | - asset.setTenantId(new TenantId(tenantId)); | 108 | + asset.setTenantId(new TenantId(UUIDConverter.fromString(tenantId))); |
107 | } | 109 | } |
108 | if (customerId != null) { | 110 | if (customerId != null) { |
109 | - asset.setCustomerId(new CustomerId(customerId)); | 111 | + asset.setCustomerId(new CustomerId(UUIDConverter.fromString(customerId))); |
110 | } | 112 | } |
111 | asset.setName(name); | 113 | asset.setName(name); |
112 | asset.setType(type); | 114 | asset.setType(type); |
@@ -21,14 +21,13 @@ import lombok.NoArgsConstructor; | @@ -21,14 +21,13 @@ import lombok.NoArgsConstructor; | ||
21 | import org.thingsboard.server.common.data.EntityType; | 21 | import org.thingsboard.server.common.data.EntityType; |
22 | 22 | ||
23 | import java.io.Serializable; | 23 | import java.io.Serializable; |
24 | -import java.util.UUID; | ||
25 | 24 | ||
26 | @Data | 25 | @Data |
27 | @AllArgsConstructor | 26 | @AllArgsConstructor |
28 | @NoArgsConstructor | 27 | @NoArgsConstructor |
29 | public class AttributeKvCompositeKey implements Serializable { | 28 | public class AttributeKvCompositeKey implements Serializable { |
30 | private EntityType entityType; | 29 | private EntityType entityType; |
31 | - private UUID entityId; | 30 | + private String entityId; |
32 | private String attributeType; | 31 | private String attributeType; |
33 | private String attributeKey; | 32 | private String attributeKey; |
34 | } | 33 | } |
@@ -22,7 +22,6 @@ import org.thingsboard.server.dao.model.ToData; | @@ -22,7 +22,6 @@ import org.thingsboard.server.dao.model.ToData; | ||
22 | 22 | ||
23 | import javax.persistence.*; | 23 | import javax.persistence.*; |
24 | import java.io.Serializable; | 24 | import java.io.Serializable; |
25 | -import java.util.UUID; | ||
26 | 25 | ||
27 | import static org.thingsboard.server.dao.model.ModelConstants.*; | 26 | import static org.thingsboard.server.dao.model.ModelConstants.*; |
28 | 27 | ||
@@ -39,7 +38,7 @@ public class AttributeKvEntity implements ToData<AttributeKvEntry>, Serializable | @@ -39,7 +38,7 @@ public class AttributeKvEntity implements ToData<AttributeKvEntry>, Serializable | ||
39 | 38 | ||
40 | @Id | 39 | @Id |
41 | @Column(name = ENTITY_ID_COLUMN) | 40 | @Column(name = ENTITY_ID_COLUMN) |
42 | - private UUID entityId; | 41 | + private String entityId; |
43 | 42 | ||
44 | @Id | 43 | @Id |
45 | @Column(name = ATTRIBUTE_TYPE_COLUMN) | 44 | @Column(name = ATTRIBUTE_TYPE_COLUMN) |
@@ -17,32 +17,30 @@ package org.thingsboard.server.dao.model.sql; | @@ -17,32 +17,30 @@ package org.thingsboard.server.dao.model.sql; | ||
17 | 17 | ||
18 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
19 | import lombok.Data; | 19 | import lombok.Data; |
20 | +import lombok.EqualsAndHashCode; | ||
20 | import org.hibernate.annotations.Type; | 21 | import org.hibernate.annotations.Type; |
21 | import org.hibernate.annotations.TypeDef; | 22 | import org.hibernate.annotations.TypeDef; |
22 | import org.thingsboard.server.common.data.id.ComponentDescriptorId; | 23 | import org.thingsboard.server.common.data.id.ComponentDescriptorId; |
23 | import org.thingsboard.server.common.data.plugin.ComponentDescriptor; | 24 | import org.thingsboard.server.common.data.plugin.ComponentDescriptor; |
24 | import org.thingsboard.server.common.data.plugin.ComponentScope; | 25 | import org.thingsboard.server.common.data.plugin.ComponentScope; |
25 | import org.thingsboard.server.common.data.plugin.ComponentType; | 26 | import org.thingsboard.server.common.data.plugin.ComponentType; |
27 | +import org.thingsboard.server.dao.model.BaseSqlEntity; | ||
26 | import org.thingsboard.server.dao.model.ModelConstants; | 28 | import org.thingsboard.server.dao.model.ModelConstants; |
27 | import org.thingsboard.server.dao.model.SearchTextEntity; | 29 | import org.thingsboard.server.dao.model.SearchTextEntity; |
28 | import org.thingsboard.server.dao.util.mapping.JsonStringType; | 30 | import org.thingsboard.server.dao.util.mapping.JsonStringType; |
29 | 31 | ||
30 | import javax.persistence.*; | 32 | import javax.persistence.*; |
31 | -import java.util.UUID; | ||
32 | 33 | ||
33 | @Data | 34 | @Data |
35 | +@EqualsAndHashCode(callSuper = true) | ||
34 | @Entity | 36 | @Entity |
35 | @TypeDef(name = "json", typeClass = JsonStringType.class) | 37 | @TypeDef(name = "json", typeClass = JsonStringType.class) |
36 | @Table(name = ModelConstants.COMPONENT_DESCRIPTOR_COLUMN_FAMILY_NAME) | 38 | @Table(name = ModelConstants.COMPONENT_DESCRIPTOR_COLUMN_FAMILY_NAME) |
37 | -public class ComponentDescriptorEntity implements SearchTextEntity<ComponentDescriptor> { | 39 | +public class ComponentDescriptorEntity extends BaseSqlEntity<ComponentDescriptor> implements SearchTextEntity<ComponentDescriptor> { |
38 | 40 | ||
39 | @Transient | 41 | @Transient |
40 | private static final long serialVersionUID = 253590350877992402L; | 42 | private static final long serialVersionUID = 253590350877992402L; |
41 | 43 | ||
42 | - @Id | ||
43 | - @Column(name = ModelConstants.ID_PROPERTY) | ||
44 | - private UUID id; | ||
45 | - | ||
46 | @Enumerated(EnumType.STRING) | 44 | @Enumerated(EnumType.STRING) |
47 | @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_TYPE_PROPERTY) | 45 | @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_TYPE_PROPERTY) |
48 | private ComponentType type; | 46 | private ComponentType type; |
@@ -72,7 +70,7 @@ public class ComponentDescriptorEntity implements SearchTextEntity<ComponentDesc | @@ -72,7 +70,7 @@ public class ComponentDescriptorEntity implements SearchTextEntity<ComponentDesc | ||
72 | 70 | ||
73 | public ComponentDescriptorEntity(ComponentDescriptor component) { | 71 | public ComponentDescriptorEntity(ComponentDescriptor component) { |
74 | if (component.getId() != null) { | 72 | if (component.getId() != null) { |
75 | - this.id = component.getId().getId(); | 73 | + this.setId(component.getId().getId()); |
76 | } | 74 | } |
77 | this.actions = component.getActions(); | 75 | this.actions = component.getActions(); |
78 | this.type = component.getType(); | 76 | this.type = component.getType(); |
@@ -85,7 +83,7 @@ public class ComponentDescriptorEntity implements SearchTextEntity<ComponentDesc | @@ -85,7 +83,7 @@ public class ComponentDescriptorEntity implements SearchTextEntity<ComponentDesc | ||
85 | 83 | ||
86 | @Override | 84 | @Override |
87 | public ComponentDescriptor toData() { | 85 | public ComponentDescriptor toData() { |
88 | - ComponentDescriptor data = new ComponentDescriptor(new ComponentDescriptorId(id)); | 86 | + ComponentDescriptor data = new ComponentDescriptor(new ComponentDescriptorId(this.getId())); |
89 | data.setType(type); | 87 | data.setType(type); |
90 | data.setScope(scope); | 88 | data.setScope(scope); |
91 | data.setName(this.getName()); | 89 | data.setName(this.getName()); |
@@ -95,16 +93,6 @@ public class ComponentDescriptorEntity implements SearchTextEntity<ComponentDesc | @@ -95,16 +93,6 @@ public class ComponentDescriptorEntity implements SearchTextEntity<ComponentDesc | ||
95 | return data; | 93 | return data; |
96 | } | 94 | } |
97 | 95 | ||
98 | - @Override | ||
99 | - public UUID getId() { | ||
100 | - return id; | ||
101 | - } | ||
102 | - | ||
103 | - @Override | ||
104 | - public void setId(UUID id) { | ||
105 | - this.id = id; | ||
106 | - } | ||
107 | - | ||
108 | public String getSearchText() { | 96 | public String getSearchText() { |
109 | return searchText; | 97 | return searchText; |
110 | } | 98 | } |
@@ -18,33 +18,35 @@ package org.thingsboard.server.dao.model.sql; | @@ -18,33 +18,35 @@ package org.thingsboard.server.dao.model.sql; | ||
18 | import com.datastax.driver.core.utils.UUIDs; | 18 | import com.datastax.driver.core.utils.UUIDs; |
19 | import com.fasterxml.jackson.databind.JsonNode; | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 20 | import lombok.Data; |
21 | +import lombok.EqualsAndHashCode; | ||
21 | import org.hibernate.annotations.Type; | 22 | import org.hibernate.annotations.Type; |
22 | import org.hibernate.annotations.TypeDef; | 23 | import org.hibernate.annotations.TypeDef; |
23 | import org.thingsboard.server.common.data.Customer; | 24 | import org.thingsboard.server.common.data.Customer; |
25 | +import org.thingsboard.server.common.data.UUIDConverter; | ||
24 | import org.thingsboard.server.common.data.id.CustomerId; | 26 | import org.thingsboard.server.common.data.id.CustomerId; |
25 | import org.thingsboard.server.common.data.id.TenantId; | 27 | import org.thingsboard.server.common.data.id.TenantId; |
28 | +import org.thingsboard.server.dao.model.BaseSqlEntity; | ||
26 | import org.thingsboard.server.dao.model.ModelConstants; | 29 | import org.thingsboard.server.dao.model.ModelConstants; |
27 | import org.thingsboard.server.dao.model.SearchTextEntity; | 30 | import org.thingsboard.server.dao.model.SearchTextEntity; |
28 | import org.thingsboard.server.dao.util.mapping.JsonStringType; | 31 | import org.thingsboard.server.dao.util.mapping.JsonStringType; |
29 | 32 | ||
30 | -import javax.persistence.*; | ||
31 | -import java.util.UUID; | 33 | +import javax.persistence.Column; |
34 | +import javax.persistence.Entity; | ||
35 | +import javax.persistence.Table; | ||
36 | +import javax.persistence.Transient; | ||
32 | 37 | ||
33 | @Data | 38 | @Data |
39 | +@EqualsAndHashCode(callSuper = true) | ||
34 | @Entity | 40 | @Entity |
35 | @TypeDef(name = "json", typeClass = JsonStringType.class) | 41 | @TypeDef(name = "json", typeClass = JsonStringType.class) |
36 | @Table(name = ModelConstants.CUSTOMER_COLUMN_FAMILY_NAME) | 42 | @Table(name = ModelConstants.CUSTOMER_COLUMN_FAMILY_NAME) |
37 | -public final class CustomerEntity implements SearchTextEntity<Customer> { | 43 | +public final class CustomerEntity extends BaseSqlEntity<Customer> implements SearchTextEntity<Customer> { |
38 | 44 | ||
39 | @Transient | 45 | @Transient |
40 | private static final long serialVersionUID = 8951342124082981556L; | 46 | private static final long serialVersionUID = 8951342124082981556L; |
41 | 47 | ||
42 | - @Id | ||
43 | - @Column(name = ModelConstants.ID_PROPERTY) | ||
44 | - private UUID id; | ||
45 | - | ||
46 | @Column(name = ModelConstants.CUSTOMER_TENANT_ID_PROPERTY) | 48 | @Column(name = ModelConstants.CUSTOMER_TENANT_ID_PROPERTY) |
47 | - private UUID tenantId; | 49 | + private String tenantId; |
48 | 50 | ||
49 | @Column(name = ModelConstants.CUSTOMER_TITLE_PROPERTY) | 51 | @Column(name = ModelConstants.CUSTOMER_TITLE_PROPERTY) |
50 | private String title; | 52 | private String title; |
@@ -86,9 +88,9 @@ public final class CustomerEntity implements SearchTextEntity<Customer> { | @@ -86,9 +88,9 @@ public final class CustomerEntity implements SearchTextEntity<Customer> { | ||
86 | 88 | ||
87 | public CustomerEntity(Customer customer) { | 89 | public CustomerEntity(Customer customer) { |
88 | if (customer.getId() != null) { | 90 | if (customer.getId() != null) { |
89 | - this.id = customer.getId().getId(); | 91 | + this.setId(customer.getId().getId()); |
90 | } | 92 | } |
91 | - this.tenantId = customer.getTenantId().getId(); | 93 | + this.tenantId = UUIDConverter.fromTimeUUID(customer.getTenantId().getId()); |
92 | this.title = customer.getTitle(); | 94 | this.title = customer.getTitle(); |
93 | this.country = customer.getCountry(); | 95 | this.country = customer.getCountry(); |
94 | this.state = customer.getState(); | 96 | this.state = customer.getState(); |
@@ -102,16 +104,6 @@ public final class CustomerEntity implements SearchTextEntity<Customer> { | @@ -102,16 +104,6 @@ public final class CustomerEntity implements SearchTextEntity<Customer> { | ||
102 | } | 104 | } |
103 | 105 | ||
104 | @Override | 106 | @Override |
105 | - public UUID getId() { | ||
106 | - return id; | ||
107 | - } | ||
108 | - | ||
109 | - @Override | ||
110 | - public void setId(UUID id) { | ||
111 | - this.id = id; | ||
112 | - } | ||
113 | - | ||
114 | - @Override | ||
115 | public String getSearchTextSource() { | 107 | public String getSearchTextSource() { |
116 | return title; | 108 | return title; |
117 | } | 109 | } |
@@ -123,9 +115,9 @@ public final class CustomerEntity implements SearchTextEntity<Customer> { | @@ -123,9 +115,9 @@ public final class CustomerEntity implements SearchTextEntity<Customer> { | ||
123 | 115 | ||
124 | @Override | 116 | @Override |
125 | public Customer toData() { | 117 | public Customer toData() { |
126 | - Customer customer = new Customer(new CustomerId(id)); | ||
127 | - customer.setCreatedTime(UUIDs.unixTimestamp(id)); | ||
128 | - customer.setTenantId(new TenantId(tenantId)); | 118 | + Customer customer = new Customer(new CustomerId(getId())); |
119 | + customer.setCreatedTime(UUIDs.unixTimestamp(getId())); | ||
120 | + customer.setTenantId(new TenantId(UUIDConverter.fromString(tenantId))); | ||
129 | customer.setTitle(title); | 121 | customer.setTitle(title); |
130 | customer.setCountry(country); | 122 | customer.setCountry(country); |
131 | customer.setState(state); | 123 | customer.setState(state); |
@@ -18,37 +18,38 @@ package org.thingsboard.server.dao.model.sql; | @@ -18,37 +18,38 @@ package org.thingsboard.server.dao.model.sql; | ||
18 | import com.datastax.driver.core.utils.UUIDs; | 18 | import com.datastax.driver.core.utils.UUIDs; |
19 | import com.fasterxml.jackson.databind.JsonNode; | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 20 | import lombok.Data; |
21 | +import lombok.EqualsAndHashCode; | ||
21 | import org.hibernate.annotations.Type; | 22 | import org.hibernate.annotations.Type; |
22 | import org.hibernate.annotations.TypeDef; | 23 | import org.hibernate.annotations.TypeDef; |
23 | import org.thingsboard.server.common.data.Dashboard; | 24 | import org.thingsboard.server.common.data.Dashboard; |
24 | import org.thingsboard.server.common.data.id.CustomerId; | 25 | import org.thingsboard.server.common.data.id.CustomerId; |
25 | import org.thingsboard.server.common.data.id.DashboardId; | 26 | import org.thingsboard.server.common.data.id.DashboardId; |
26 | import org.thingsboard.server.common.data.id.TenantId; | 27 | import org.thingsboard.server.common.data.id.TenantId; |
28 | +import org.thingsboard.server.dao.model.BaseSqlEntity; | ||
27 | import org.thingsboard.server.dao.model.ModelConstants; | 29 | import org.thingsboard.server.dao.model.ModelConstants; |
28 | import org.thingsboard.server.dao.model.SearchTextEntity; | 30 | import org.thingsboard.server.dao.model.SearchTextEntity; |
29 | import org.thingsboard.server.dao.util.mapping.JsonStringType; | 31 | import org.thingsboard.server.dao.util.mapping.JsonStringType; |
30 | 32 | ||
31 | -import javax.persistence.*; | ||
32 | -import java.util.UUID; | 33 | +import javax.persistence.Column; |
34 | +import javax.persistence.Entity; | ||
35 | +import javax.persistence.Table; | ||
36 | +import javax.persistence.Transient; | ||
33 | 37 | ||
34 | @Data | 38 | @Data |
39 | +@EqualsAndHashCode(callSuper = true) | ||
35 | @Entity | 40 | @Entity |
36 | @TypeDef(name = "json", typeClass = JsonStringType.class) | 41 | @TypeDef(name = "json", typeClass = JsonStringType.class) |
37 | @Table(name = ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME) | 42 | @Table(name = ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME) |
38 | -public final class DashboardEntity implements SearchTextEntity<Dashboard> { | 43 | +public final class DashboardEntity extends BaseSqlEntity<Dashboard> implements SearchTextEntity<Dashboard> { |
39 | 44 | ||
40 | @Transient | 45 | @Transient |
41 | private static final long serialVersionUID = -4838084363113078898L; | 46 | private static final long serialVersionUID = -4838084363113078898L; |
42 | 47 | ||
43 | - @Id | ||
44 | - @Column(name = ModelConstants.ID_PROPERTY) | ||
45 | - private UUID id; | ||
46 | - | ||
47 | @Column(name = ModelConstants.DASHBOARD_TENANT_ID_PROPERTY) | 48 | @Column(name = ModelConstants.DASHBOARD_TENANT_ID_PROPERTY) |
48 | - private UUID tenantId; | 49 | + private String tenantId; |
49 | 50 | ||
50 | @Column(name = ModelConstants.DASHBOARD_CUSTOMER_ID_PROPERTY) | 51 | @Column(name = ModelConstants.DASHBOARD_CUSTOMER_ID_PROPERTY) |
51 | - private UUID customerId; | 52 | + private String customerId; |
52 | 53 | ||
53 | @Column(name = ModelConstants.DASHBOARD_TITLE_PROPERTY) | 54 | @Column(name = ModelConstants.DASHBOARD_TITLE_PROPERTY) |
54 | private String title; | 55 | private String title; |
@@ -66,13 +67,13 @@ public final class DashboardEntity implements SearchTextEntity<Dashboard> { | @@ -66,13 +67,13 @@ public final class DashboardEntity implements SearchTextEntity<Dashboard> { | ||
66 | 67 | ||
67 | public DashboardEntity(Dashboard dashboard) { | 68 | public DashboardEntity(Dashboard dashboard) { |
68 | if (dashboard.getId() != null) { | 69 | if (dashboard.getId() != null) { |
69 | - this.id = dashboard.getId().getId(); | 70 | + this.setId(dashboard.getId().getId()); |
70 | } | 71 | } |
71 | if (dashboard.getTenantId() != null) { | 72 | if (dashboard.getTenantId() != null) { |
72 | - this.tenantId = dashboard.getTenantId().getId(); | 73 | + this.tenantId = toString(dashboard.getTenantId().getId()); |
73 | } | 74 | } |
74 | if (dashboard.getCustomerId() != null) { | 75 | if (dashboard.getCustomerId() != null) { |
75 | - this.customerId = dashboard.getCustomerId().getId(); | 76 | + this.customerId = toString(dashboard.getCustomerId().getId()); |
76 | } | 77 | } |
77 | this.title = dashboard.getTitle(); | 78 | this.title = dashboard.getTitle(); |
78 | this.configuration = dashboard.getConfiguration(); | 79 | this.configuration = dashboard.getConfiguration(); |
@@ -90,13 +91,13 @@ public final class DashboardEntity implements SearchTextEntity<Dashboard> { | @@ -90,13 +91,13 @@ public final class DashboardEntity implements SearchTextEntity<Dashboard> { | ||
90 | 91 | ||
91 | @Override | 92 | @Override |
92 | public Dashboard toData() { | 93 | public Dashboard toData() { |
93 | - Dashboard dashboard = new Dashboard(new DashboardId(id)); | ||
94 | - dashboard.setCreatedTime(UUIDs.unixTimestamp(id)); | 94 | + Dashboard dashboard = new Dashboard(new DashboardId(this.getId())); |
95 | + dashboard.setCreatedTime(UUIDs.unixTimestamp(this.getId())); | ||
95 | if (tenantId != null) { | 96 | if (tenantId != null) { |
96 | - dashboard.setTenantId(new TenantId(tenantId)); | 97 | + dashboard.setTenantId(new TenantId(toUUID(tenantId))); |
97 | } | 98 | } |
98 | if (customerId != null) { | 99 | if (customerId != null) { |
99 | - dashboard.setCustomerId(new CustomerId(customerId)); | 100 | + dashboard.setCustomerId(new CustomerId(toUUID(customerId))); |
100 | } | 101 | } |
101 | dashboard.setTitle(title); | 102 | dashboard.setTitle(title); |
102 | dashboard.setConfiguration(configuration); | 103 | dashboard.setConfiguration(configuration); |
@@ -17,33 +17,34 @@ package org.thingsboard.server.dao.model.sql; | @@ -17,33 +17,34 @@ package org.thingsboard.server.dao.model.sql; | ||
17 | 17 | ||
18 | import com.datastax.driver.core.utils.UUIDs; | 18 | import com.datastax.driver.core.utils.UUIDs; |
19 | import lombok.Data; | 19 | import lombok.Data; |
20 | +import lombok.EqualsAndHashCode; | ||
20 | import org.thingsboard.server.common.data.DashboardInfo; | 21 | import org.thingsboard.server.common.data.DashboardInfo; |
21 | import org.thingsboard.server.common.data.id.CustomerId; | 22 | import org.thingsboard.server.common.data.id.CustomerId; |
22 | import org.thingsboard.server.common.data.id.DashboardId; | 23 | import org.thingsboard.server.common.data.id.DashboardId; |
23 | import org.thingsboard.server.common.data.id.TenantId; | 24 | import org.thingsboard.server.common.data.id.TenantId; |
25 | +import org.thingsboard.server.dao.model.BaseSqlEntity; | ||
24 | import org.thingsboard.server.dao.model.ModelConstants; | 26 | import org.thingsboard.server.dao.model.ModelConstants; |
25 | import org.thingsboard.server.dao.model.SearchTextEntity; | 27 | import org.thingsboard.server.dao.model.SearchTextEntity; |
26 | 28 | ||
27 | -import javax.persistence.*; | ||
28 | -import java.util.UUID; | 29 | +import javax.persistence.Column; |
30 | +import javax.persistence.Entity; | ||
31 | +import javax.persistence.Table; | ||
32 | +import javax.persistence.Transient; | ||
29 | 33 | ||
30 | @Data | 34 | @Data |
35 | +@EqualsAndHashCode(callSuper = true) | ||
31 | @Entity | 36 | @Entity |
32 | @Table(name = ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME) | 37 | @Table(name = ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME) |
33 | -public class DashboardInfoEntity implements SearchTextEntity<DashboardInfo> { | 38 | +public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> implements SearchTextEntity<DashboardInfo> { |
34 | 39 | ||
35 | @Transient | 40 | @Transient |
36 | private static final long serialVersionUID = -5525675905528050250L; | 41 | private static final long serialVersionUID = -5525675905528050250L; |
37 | 42 | ||
38 | - @Id | ||
39 | - @Column(name = ModelConstants.ID_PROPERTY) | ||
40 | - private UUID id; | ||
41 | - | ||
42 | @Column(name = ModelConstants.DASHBOARD_TENANT_ID_PROPERTY) | 43 | @Column(name = ModelConstants.DASHBOARD_TENANT_ID_PROPERTY) |
43 | - private UUID tenantId; | 44 | + private String tenantId; |
44 | 45 | ||
45 | @Column(name = ModelConstants.DASHBOARD_CUSTOMER_ID_PROPERTY) | 46 | @Column(name = ModelConstants.DASHBOARD_CUSTOMER_ID_PROPERTY) |
46 | - private UUID customerId; | 47 | + private String customerId; |
47 | 48 | ||
48 | @Column(name = ModelConstants.DASHBOARD_TITLE_PROPERTY) | 49 | @Column(name = ModelConstants.DASHBOARD_TITLE_PROPERTY) |
49 | private String title; | 50 | private String title; |
@@ -57,13 +58,13 @@ public class DashboardInfoEntity implements SearchTextEntity<DashboardInfo> { | @@ -57,13 +58,13 @@ public class DashboardInfoEntity implements SearchTextEntity<DashboardInfo> { | ||
57 | 58 | ||
58 | public DashboardInfoEntity(DashboardInfo dashboardInfo) { | 59 | public DashboardInfoEntity(DashboardInfo dashboardInfo) { |
59 | if (dashboardInfo.getId() != null) { | 60 | if (dashboardInfo.getId() != null) { |
60 | - this.id = dashboardInfo.getId().getId(); | 61 | + this.setId(dashboardInfo.getId().getId()); |
61 | } | 62 | } |
62 | if (dashboardInfo.getTenantId() != null) { | 63 | if (dashboardInfo.getTenantId() != null) { |
63 | - this.tenantId = dashboardInfo.getTenantId().getId(); | 64 | + this.tenantId = toString(dashboardInfo.getTenantId().getId()); |
64 | } | 65 | } |
65 | if (dashboardInfo.getCustomerId() != null) { | 66 | if (dashboardInfo.getCustomerId() != null) { |
66 | - this.customerId = dashboardInfo.getCustomerId().getId(); | 67 | + this.customerId = toString(dashboardInfo.getCustomerId().getId()); |
67 | } | 68 | } |
68 | this.title = dashboardInfo.getTitle(); | 69 | this.title = dashboardInfo.getTitle(); |
69 | } | 70 | } |
@@ -84,13 +85,13 @@ public class DashboardInfoEntity implements SearchTextEntity<DashboardInfo> { | @@ -84,13 +85,13 @@ public class DashboardInfoEntity implements SearchTextEntity<DashboardInfo> { | ||
84 | 85 | ||
85 | @Override | 86 | @Override |
86 | public DashboardInfo toData() { | 87 | public DashboardInfo toData() { |
87 | - DashboardInfo dashboardInfo = new DashboardInfo(new DashboardId(id)); | ||
88 | - dashboardInfo.setCreatedTime(UUIDs.unixTimestamp(id)); | 88 | + DashboardInfo dashboardInfo = new DashboardInfo(new DashboardId(getId())); |
89 | + dashboardInfo.setCreatedTime(UUIDs.unixTimestamp(getId())); | ||
89 | if (tenantId != null) { | 90 | if (tenantId != null) { |
90 | - dashboardInfo.setTenantId(new TenantId(tenantId)); | 91 | + dashboardInfo.setTenantId(new TenantId(toUUID(tenantId))); |
91 | } | 92 | } |
92 | if (customerId != null) { | 93 | if (customerId != null) { |
93 | - dashboardInfo.setCustomerId(new CustomerId(customerId)); | 94 | + dashboardInfo.setCustomerId(new CustomerId(toUUID(customerId))); |
94 | } | 95 | } |
95 | dashboardInfo.setTitle(title); | 96 | dashboardInfo.setTitle(title); |
96 | return dashboardInfo; | 97 | return dashboardInfo; |
@@ -17,29 +17,28 @@ package org.thingsboard.server.dao.model.sql; | @@ -17,29 +17,28 @@ package org.thingsboard.server.dao.model.sql; | ||
17 | 17 | ||
18 | import com.datastax.driver.core.utils.UUIDs; | 18 | import com.datastax.driver.core.utils.UUIDs; |
19 | import lombok.Data; | 19 | import lombok.Data; |
20 | +import lombok.EqualsAndHashCode; | ||
20 | import org.thingsboard.server.common.data.id.DeviceCredentialsId; | 21 | import org.thingsboard.server.common.data.id.DeviceCredentialsId; |
21 | import org.thingsboard.server.common.data.id.DeviceId; | 22 | import org.thingsboard.server.common.data.id.DeviceId; |
22 | import org.thingsboard.server.common.data.security.DeviceCredentials; | 23 | import org.thingsboard.server.common.data.security.DeviceCredentials; |
23 | import org.thingsboard.server.common.data.security.DeviceCredentialsType; | 24 | import org.thingsboard.server.common.data.security.DeviceCredentialsType; |
24 | import org.thingsboard.server.dao.model.BaseEntity; | 25 | import org.thingsboard.server.dao.model.BaseEntity; |
26 | +import org.thingsboard.server.dao.model.BaseSqlEntity; | ||
25 | import org.thingsboard.server.dao.model.ModelConstants; | 27 | import org.thingsboard.server.dao.model.ModelConstants; |
26 | 28 | ||
27 | import javax.persistence.*; | 29 | import javax.persistence.*; |
28 | -import java.util.UUID; | ||
29 | 30 | ||
30 | @Data | 31 | @Data |
32 | +@EqualsAndHashCode(callSuper = true) | ||
31 | @Entity | 33 | @Entity |
32 | @Table(name = ModelConstants.DEVICE_CREDENTIALS_COLUMN_FAMILY_NAME) | 34 | @Table(name = ModelConstants.DEVICE_CREDENTIALS_COLUMN_FAMILY_NAME) |
33 | -public final class DeviceCredentialsEntity implements BaseEntity<DeviceCredentials> { | 35 | +public final class DeviceCredentialsEntity extends BaseSqlEntity<DeviceCredentials> implements BaseEntity<DeviceCredentials> { |
34 | 36 | ||
35 | @Transient | 37 | @Transient |
36 | private static final long serialVersionUID = -2512362753385470464L; | 38 | private static final long serialVersionUID = -2512362753385470464L; |
37 | - @Id | ||
38 | - @Column(name = ModelConstants.ID_PROPERTY) | ||
39 | - private UUID id; | ||
40 | - | 39 | + |
41 | @Column(name = ModelConstants.DEVICE_CREDENTIALS_DEVICE_ID_PROPERTY) | 40 | @Column(name = ModelConstants.DEVICE_CREDENTIALS_DEVICE_ID_PROPERTY) |
42 | - private UUID deviceId; | 41 | + private String deviceId; |
43 | 42 | ||
44 | @Enumerated(EnumType.STRING) | 43 | @Enumerated(EnumType.STRING) |
45 | @Column(name = ModelConstants.DEVICE_CREDENTIALS_CREDENTIALS_TYPE_PROPERTY) | 44 | @Column(name = ModelConstants.DEVICE_CREDENTIALS_CREDENTIALS_TYPE_PROPERTY) |
@@ -57,22 +56,22 @@ public final class DeviceCredentialsEntity implements BaseEntity<DeviceCredentia | @@ -57,22 +56,22 @@ public final class DeviceCredentialsEntity implements BaseEntity<DeviceCredentia | ||
57 | 56 | ||
58 | public DeviceCredentialsEntity(DeviceCredentials deviceCredentials) { | 57 | public DeviceCredentialsEntity(DeviceCredentials deviceCredentials) { |
59 | if (deviceCredentials.getId() != null) { | 58 | if (deviceCredentials.getId() != null) { |
60 | - this.id = deviceCredentials.getId().getId(); | 59 | + this.setId(deviceCredentials.getId().getId()); |
61 | } | 60 | } |
62 | if (deviceCredentials.getDeviceId() != null) { | 61 | if (deviceCredentials.getDeviceId() != null) { |
63 | - this.deviceId = deviceCredentials.getDeviceId().getId(); | 62 | + this.deviceId = toString(deviceCredentials.getDeviceId().getId()); |
64 | } | 63 | } |
65 | this.credentialsType = deviceCredentials.getCredentialsType(); | 64 | this.credentialsType = deviceCredentials.getCredentialsType(); |
66 | this.credentialsId = deviceCredentials.getCredentialsId(); | 65 | this.credentialsId = deviceCredentials.getCredentialsId(); |
67 | - this.credentialsValue = deviceCredentials.getCredentialsValue(); | 66 | + this.credentialsValue = deviceCredentials.getCredentialsValue(); |
68 | } | 67 | } |
69 | - | 68 | + |
70 | @Override | 69 | @Override |
71 | public DeviceCredentials toData() { | 70 | public DeviceCredentials toData() { |
72 | - DeviceCredentials deviceCredentials = new DeviceCredentials(new DeviceCredentialsId(id)); | ||
73 | - deviceCredentials.setCreatedTime(UUIDs.unixTimestamp(id)); | 71 | + DeviceCredentials deviceCredentials = new DeviceCredentials(new DeviceCredentialsId(getId())); |
72 | + deviceCredentials.setCreatedTime(UUIDs.unixTimestamp(getId())); | ||
74 | if (deviceId != null) { | 73 | if (deviceId != null) { |
75 | - deviceCredentials.setDeviceId(new DeviceId(deviceId)); | 74 | + deviceCredentials.setDeviceId(new DeviceId(toUUID(deviceId))); |
76 | } | 75 | } |
77 | deviceCredentials.setCredentialsType(credentialsType); | 76 | deviceCredentials.setCredentialsType(credentialsType); |
78 | deviceCredentials.setCredentialsId(credentialsId); | 77 | deviceCredentials.setCredentialsId(credentialsId); |
@@ -18,44 +18,45 @@ package org.thingsboard.server.dao.model.sql; | @@ -18,44 +18,45 @@ package org.thingsboard.server.dao.model.sql; | ||
18 | import com.datastax.driver.core.utils.UUIDs; | 18 | import com.datastax.driver.core.utils.UUIDs; |
19 | import com.fasterxml.jackson.databind.JsonNode; | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 20 | import lombok.Data; |
21 | +import lombok.EqualsAndHashCode; | ||
21 | import org.hibernate.annotations.Type; | 22 | import org.hibernate.annotations.Type; |
22 | import org.hibernate.annotations.TypeDef; | 23 | import org.hibernate.annotations.TypeDef; |
23 | import org.thingsboard.server.common.data.Device; | 24 | import org.thingsboard.server.common.data.Device; |
24 | import org.thingsboard.server.common.data.id.CustomerId; | 25 | import org.thingsboard.server.common.data.id.CustomerId; |
25 | import org.thingsboard.server.common.data.id.DeviceId; | 26 | import org.thingsboard.server.common.data.id.DeviceId; |
26 | import org.thingsboard.server.common.data.id.TenantId; | 27 | import org.thingsboard.server.common.data.id.TenantId; |
28 | +import org.thingsboard.server.dao.model.BaseSqlEntity; | ||
27 | import org.thingsboard.server.dao.model.ModelConstants; | 29 | import org.thingsboard.server.dao.model.ModelConstants; |
28 | import org.thingsboard.server.dao.model.SearchTextEntity; | 30 | import org.thingsboard.server.dao.model.SearchTextEntity; |
29 | import org.thingsboard.server.dao.util.mapping.JsonStringType; | 31 | import org.thingsboard.server.dao.util.mapping.JsonStringType; |
30 | 32 | ||
31 | -import javax.persistence.*; | ||
32 | -import java.util.UUID; | 33 | +import javax.persistence.Column; |
34 | +import javax.persistence.Entity; | ||
35 | +import javax.persistence.Table; | ||
36 | +import javax.persistence.Transient; | ||
33 | 37 | ||
34 | @Data | 38 | @Data |
39 | +@EqualsAndHashCode(callSuper = true) | ||
35 | @Entity | 40 | @Entity |
36 | @TypeDef(name = "json", typeClass = JsonStringType.class) | 41 | @TypeDef(name = "json", typeClass = JsonStringType.class) |
37 | @Table(name = ModelConstants.DEVICE_COLUMN_FAMILY_NAME) | 42 | @Table(name = ModelConstants.DEVICE_COLUMN_FAMILY_NAME) |
38 | -public final class DeviceEntity implements SearchTextEntity<Device> { | 43 | +public final class DeviceEntity extends BaseSqlEntity<Device> implements SearchTextEntity<Device> { |
39 | 44 | ||
40 | @Transient | 45 | @Transient |
41 | private static final long serialVersionUID = 8050086401213322856L; | 46 | private static final long serialVersionUID = 8050086401213322856L; |
42 | 47 | ||
43 | - @Id | ||
44 | - @Column(name = ModelConstants.ID_PROPERTY) | ||
45 | - private UUID id; | ||
46 | - | ||
47 | @Column(name = ModelConstants.DEVICE_TENANT_ID_PROPERTY) | 48 | @Column(name = ModelConstants.DEVICE_TENANT_ID_PROPERTY) |
48 | - private UUID tenantId; | 49 | + private String tenantId; |
49 | 50 | ||
50 | @Column(name = ModelConstants.DEVICE_CUSTOMER_ID_PROPERTY) | 51 | @Column(name = ModelConstants.DEVICE_CUSTOMER_ID_PROPERTY) |
51 | - private UUID customerId; | 52 | + private String customerId; |
52 | 53 | ||
53 | @Column(name = ModelConstants.DEVICE_TYPE_PROPERTY) | 54 | @Column(name = ModelConstants.DEVICE_TYPE_PROPERTY) |
54 | private String type; | 55 | private String type; |
55 | 56 | ||
56 | @Column(name = ModelConstants.DEVICE_NAME_PROPERTY) | 57 | @Column(name = ModelConstants.DEVICE_NAME_PROPERTY) |
57 | private String name; | 58 | private String name; |
58 | - | 59 | + |
59 | @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) | 60 | @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) |
60 | private String searchText; | 61 | private String searchText; |
61 | 62 | ||
@@ -69,13 +70,13 @@ public final class DeviceEntity implements SearchTextEntity<Device> { | @@ -69,13 +70,13 @@ public final class DeviceEntity implements SearchTextEntity<Device> { | ||
69 | 70 | ||
70 | public DeviceEntity(Device device) { | 71 | public DeviceEntity(Device device) { |
71 | if (device.getId() != null) { | 72 | if (device.getId() != null) { |
72 | - this.id = device.getId().getId(); | 73 | + this.setId(device.getId().getId()); |
73 | } | 74 | } |
74 | if (device.getTenantId() != null) { | 75 | if (device.getTenantId() != null) { |
75 | - this.tenantId = device.getTenantId().getId(); | 76 | + this.tenantId = toString(device.getTenantId().getId()); |
76 | } | 77 | } |
77 | if (device.getCustomerId() != null) { | 78 | if (device.getCustomerId() != null) { |
78 | - this.customerId = device.getCustomerId().getId(); | 79 | + this.customerId = toString(device.getCustomerId().getId()); |
79 | } | 80 | } |
80 | this.name = device.getName(); | 81 | this.name = device.getName(); |
81 | this.type = device.getType(); | 82 | this.type = device.getType(); |
@@ -91,16 +92,16 @@ public final class DeviceEntity implements SearchTextEntity<Device> { | @@ -91,16 +92,16 @@ public final class DeviceEntity implements SearchTextEntity<Device> { | ||
91 | public void setSearchText(String searchText) { | 92 | public void setSearchText(String searchText) { |
92 | this.searchText = searchText; | 93 | this.searchText = searchText; |
93 | } | 94 | } |
94 | - | 95 | + |
95 | @Override | 96 | @Override |
96 | public Device toData() { | 97 | public Device toData() { |
97 | - Device device = new Device(new DeviceId(id)); | ||
98 | - device.setCreatedTime(UUIDs.unixTimestamp(id)); | 98 | + Device device = new Device(new DeviceId(getId())); |
99 | + device.setCreatedTime(UUIDs.unixTimestamp(getId())); | ||
99 | if (tenantId != null) { | 100 | if (tenantId != null) { |
100 | - device.setTenantId(new TenantId(tenantId)); | 101 | + device.setTenantId(new TenantId(toUUID(tenantId))); |
101 | } | 102 | } |
102 | if (customerId != null) { | 103 | if (customerId != null) { |
103 | - device.setCustomerId(new CustomerId(customerId)); | 104 | + device.setCustomerId(new CustomerId(toUUID(customerId))); |
104 | } | 105 | } |
105 | device.setName(name); | 106 | device.setName(name); |
106 | device.setType(type); | 107 | device.setType(type); |
@@ -18,43 +18,43 @@ package org.thingsboard.server.dao.model.sql; | @@ -18,43 +18,43 @@ package org.thingsboard.server.dao.model.sql; | ||
18 | import com.datastax.driver.core.utils.UUIDs; | 18 | import com.datastax.driver.core.utils.UUIDs; |
19 | import com.fasterxml.jackson.databind.JsonNode; | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 20 | import lombok.Data; |
21 | +import lombok.EqualsAndHashCode; | ||
21 | import lombok.NoArgsConstructor; | 22 | import lombok.NoArgsConstructor; |
22 | import org.hibernate.annotations.Type; | 23 | import org.hibernate.annotations.Type; |
23 | import org.hibernate.annotations.TypeDef; | 24 | import org.hibernate.annotations.TypeDef; |
24 | import org.thingsboard.server.common.data.EntityType; | 25 | import org.thingsboard.server.common.data.EntityType; |
25 | import org.thingsboard.server.common.data.Event; | 26 | import org.thingsboard.server.common.data.Event; |
26 | -import org.thingsboard.server.common.data.id.*; | 27 | +import org.thingsboard.server.common.data.id.EntityIdFactory; |
28 | +import org.thingsboard.server.common.data.id.EventId; | ||
29 | +import org.thingsboard.server.common.data.id.TenantId; | ||
27 | import org.thingsboard.server.dao.model.BaseEntity; | 30 | import org.thingsboard.server.dao.model.BaseEntity; |
31 | +import org.thingsboard.server.dao.model.BaseSqlEntity; | ||
28 | import org.thingsboard.server.dao.util.mapping.JsonStringType; | 32 | import org.thingsboard.server.dao.util.mapping.JsonStringType; |
29 | 33 | ||
30 | import javax.persistence.*; | 34 | import javax.persistence.*; |
31 | -import java.util.UUID; | ||
32 | 35 | ||
33 | import static org.thingsboard.server.dao.model.ModelConstants.*; | 36 | import static org.thingsboard.server.dao.model.ModelConstants.*; |
34 | 37 | ||
35 | @Data | 38 | @Data |
39 | +@EqualsAndHashCode(callSuper = true) | ||
36 | @Entity | 40 | @Entity |
37 | @TypeDef(name = "json", typeClass = JsonStringType.class) | 41 | @TypeDef(name = "json", typeClass = JsonStringType.class) |
38 | @Table(name = EVENT_COLUMN_FAMILY_NAME) | 42 | @Table(name = EVENT_COLUMN_FAMILY_NAME) |
39 | @NoArgsConstructor | 43 | @NoArgsConstructor |
40 | -public class EventEntity implements BaseEntity<Event> { | 44 | +public class EventEntity extends BaseSqlEntity<Event> implements BaseEntity<Event> { |
41 | 45 | ||
42 | @Transient | 46 | @Transient |
43 | private static final long serialVersionUID = -5717830061727466727L; | 47 | private static final long serialVersionUID = -5717830061727466727L; |
44 | 48 | ||
45 | - @Id | ||
46 | - @Column(name = ID_PROPERTY) | ||
47 | - private UUID id; | ||
48 | - | ||
49 | @Column(name = EVENT_TENANT_ID_PROPERTY) | 49 | @Column(name = EVENT_TENANT_ID_PROPERTY) |
50 | - private UUID tenantId; | 50 | + private String tenantId; |
51 | 51 | ||
52 | @Enumerated(EnumType.STRING) | 52 | @Enumerated(EnumType.STRING) |
53 | @Column(name = EVENT_ENTITY_TYPE_PROPERTY) | 53 | @Column(name = EVENT_ENTITY_TYPE_PROPERTY) |
54 | private EntityType entityType; | 54 | private EntityType entityType; |
55 | 55 | ||
56 | @Column(name = EVENT_ENTITY_ID_PROPERTY) | 56 | @Column(name = EVENT_ENTITY_ID_PROPERTY) |
57 | - private UUID entityId; | 57 | + private String entityId; |
58 | 58 | ||
59 | @Column(name = EVENT_TYPE_PROPERTY) | 59 | @Column(name = EVENT_TYPE_PROPERTY) |
60 | private String eventType; | 60 | private String eventType; |
@@ -68,52 +68,27 @@ public class EventEntity implements BaseEntity<Event> { | @@ -68,52 +68,27 @@ public class EventEntity implements BaseEntity<Event> { | ||
68 | 68 | ||
69 | public EventEntity(Event event) { | 69 | public EventEntity(Event event) { |
70 | if (event.getId() != null) { | 70 | if (event.getId() != null) { |
71 | - this.id = event.getId().getId(); | 71 | + this.setId(event.getId().getId()); |
72 | } | 72 | } |
73 | if (event.getTenantId() != null) { | 73 | if (event.getTenantId() != null) { |
74 | - this.tenantId = event.getTenantId().getId(); | 74 | + this.tenantId = toString(event.getTenantId().getId()); |
75 | } | 75 | } |
76 | if (event.getEntityId() != null) { | 76 | if (event.getEntityId() != null) { |
77 | this.entityType = event.getEntityId().getEntityType(); | 77 | this.entityType = event.getEntityId().getEntityType(); |
78 | - this.entityId = event.getEntityId().getId(); | 78 | + this.entityId = toString(event.getEntityId().getId()); |
79 | } | 79 | } |
80 | this.eventType = event.getType(); | 80 | this.eventType = event.getType(); |
81 | this.eventUid = event.getUid(); | 81 | this.eventUid = event.getUid(); |
82 | this.body = event.getBody(); | 82 | this.body = event.getBody(); |
83 | } | 83 | } |
84 | 84 | ||
85 | - @Override | ||
86 | - public UUID getId() { | ||
87 | - return id; | ||
88 | - } | ||
89 | - | ||
90 | - @Override | ||
91 | - public void setId(UUID id) { | ||
92 | - this.id = id; | ||
93 | - } | ||
94 | 85 | ||
95 | @Override | 86 | @Override |
96 | public Event toData() { | 87 | public Event toData() { |
97 | - Event event = new Event(new EventId(id)); | ||
98 | - event.setCreatedTime(UUIDs.unixTimestamp(id)); | ||
99 | - event.setTenantId(new TenantId(tenantId)); | ||
100 | - switch (entityType) { | ||
101 | - case TENANT: | ||
102 | - event.setEntityId(new TenantId(entityId)); | ||
103 | - break; | ||
104 | - case DEVICE: | ||
105 | - event.setEntityId(new DeviceId(entityId)); | ||
106 | - break; | ||
107 | - case CUSTOMER: | ||
108 | - event.setEntityId(new CustomerId(entityId)); | ||
109 | - break; | ||
110 | - case RULE: | ||
111 | - event.setEntityId(new RuleId(entityId)); | ||
112 | - break; | ||
113 | - case PLUGIN: | ||
114 | - event.setEntityId(new PluginId(entityId)); | ||
115 | - break; | ||
116 | - } | 88 | + Event event = new Event(new EventId(getId())); |
89 | + event.setCreatedTime(UUIDs.unixTimestamp(getId())); | ||
90 | + event.setTenantId(new TenantId(toUUID(tenantId))); | ||
91 | + event.setEntityId(EntityIdFactory.getByTypeAndUuid(entityType, toUUID(entityId))); | ||
117 | event.setBody(body); | 92 | event.setBody(body); |
118 | event.setType(eventType); | 93 | event.setType(eventType); |
119 | event.setUid(eventUid); | 94 | event.setUid(eventUid); |
@@ -18,36 +18,38 @@ package org.thingsboard.server.dao.model.sql; | @@ -18,36 +18,38 @@ package org.thingsboard.server.dao.model.sql; | ||
18 | import com.datastax.driver.core.utils.UUIDs; | 18 | import com.datastax.driver.core.utils.UUIDs; |
19 | import com.fasterxml.jackson.databind.JsonNode; | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 20 | import lombok.Data; |
21 | +import lombok.EqualsAndHashCode; | ||
21 | import org.hibernate.annotations.Type; | 22 | import org.hibernate.annotations.Type; |
22 | import org.hibernate.annotations.TypeDef; | 23 | import org.hibernate.annotations.TypeDef; |
23 | import org.thingsboard.server.common.data.id.PluginId; | 24 | import org.thingsboard.server.common.data.id.PluginId; |
24 | import org.thingsboard.server.common.data.id.TenantId; | 25 | import org.thingsboard.server.common.data.id.TenantId; |
25 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; | 26 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; |
26 | import org.thingsboard.server.common.data.plugin.PluginMetaData; | 27 | import org.thingsboard.server.common.data.plugin.PluginMetaData; |
28 | +import org.thingsboard.server.dao.model.BaseSqlEntity; | ||
27 | import org.thingsboard.server.dao.model.ModelConstants; | 29 | import org.thingsboard.server.dao.model.ModelConstants; |
28 | import org.thingsboard.server.dao.model.SearchTextEntity; | 30 | import org.thingsboard.server.dao.model.SearchTextEntity; |
29 | import org.thingsboard.server.dao.util.mapping.JsonStringType; | 31 | import org.thingsboard.server.dao.util.mapping.JsonStringType; |
30 | 32 | ||
31 | import javax.persistence.*; | 33 | import javax.persistence.*; |
32 | -import java.util.UUID; | 34 | + |
35 | +import static org.thingsboard.server.common.data.UUIDConverter.fromString; | ||
36 | +import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID; | ||
33 | 37 | ||
34 | @Data | 38 | @Data |
39 | +@EqualsAndHashCode(callSuper = true) | ||
35 | @Entity | 40 | @Entity |
36 | @TypeDef(name = "json", typeClass = JsonStringType.class) | 41 | @TypeDef(name = "json", typeClass = JsonStringType.class) |
37 | @Table(name = ModelConstants.PLUGIN_COLUMN_FAMILY_NAME) | 42 | @Table(name = ModelConstants.PLUGIN_COLUMN_FAMILY_NAME) |
38 | -public class PluginMetaDataEntity implements SearchTextEntity<PluginMetaData> { | 43 | +public class PluginMetaDataEntity extends BaseSqlEntity<PluginMetaData> implements SearchTextEntity<PluginMetaData> { |
39 | 44 | ||
40 | @Transient | 45 | @Transient |
41 | private static final long serialVersionUID = -6164321050824823149L; | 46 | private static final long serialVersionUID = -6164321050824823149L; |
42 | - @Id | ||
43 | - @Column(name = ModelConstants.ID_PROPERTY) | ||
44 | - private UUID id; | ||
45 | 47 | ||
46 | @Column(name = ModelConstants.PLUGIN_API_TOKEN_PROPERTY) | 48 | @Column(name = ModelConstants.PLUGIN_API_TOKEN_PROPERTY) |
47 | private String apiToken; | 49 | private String apiToken; |
48 | 50 | ||
49 | @Column(name = ModelConstants.PLUGIN_TENANT_ID_PROPERTY) | 51 | @Column(name = ModelConstants.PLUGIN_TENANT_ID_PROPERTY) |
50 | - private UUID tenantId; | 52 | + private String tenantId; |
51 | 53 | ||
52 | @Column(name = ModelConstants.PLUGIN_NAME_PROPERTY) | 54 | @Column(name = ModelConstants.PLUGIN_NAME_PROPERTY) |
53 | private String name; | 55 | private String name; |
@@ -78,9 +80,9 @@ public class PluginMetaDataEntity implements SearchTextEntity<PluginMetaData> { | @@ -78,9 +80,9 @@ public class PluginMetaDataEntity implements SearchTextEntity<PluginMetaData> { | ||
78 | 80 | ||
79 | public PluginMetaDataEntity(PluginMetaData pluginMetaData) { | 81 | public PluginMetaDataEntity(PluginMetaData pluginMetaData) { |
80 | if (pluginMetaData.getId() != null) { | 82 | if (pluginMetaData.getId() != null) { |
81 | - this.id = pluginMetaData.getId().getId(); | 83 | + this.setId(pluginMetaData.getId().getId()); |
82 | } | 84 | } |
83 | - this.tenantId = pluginMetaData.getTenantId().getId(); | 85 | + this.tenantId = fromTimeUUID(pluginMetaData.getTenantId().getId()); |
84 | this.apiToken = pluginMetaData.getApiToken(); | 86 | this.apiToken = pluginMetaData.getApiToken(); |
85 | this.clazz = pluginMetaData.getClazz(); | 87 | this.clazz = pluginMetaData.getClazz(); |
86 | this.name = pluginMetaData.getName(); | 88 | this.name = pluginMetaData.getName(); |
@@ -102,20 +104,10 @@ public class PluginMetaDataEntity implements SearchTextEntity<PluginMetaData> { | @@ -102,20 +104,10 @@ public class PluginMetaDataEntity implements SearchTextEntity<PluginMetaData> { | ||
102 | } | 104 | } |
103 | 105 | ||
104 | @Override | 106 | @Override |
105 | - public UUID getId() { | ||
106 | - return id; | ||
107 | - } | ||
108 | - | ||
109 | - @Override | ||
110 | - public void setId(UUID id) { | ||
111 | - this.id = id; | ||
112 | - } | ||
113 | - | ||
114 | - @Override | ||
115 | public PluginMetaData toData() { | 107 | public PluginMetaData toData() { |
116 | - PluginMetaData data = new PluginMetaData(new PluginId(id)); | ||
117 | - data.setTenantId(new TenantId(tenantId)); | ||
118 | - data.setCreatedTime(UUIDs.unixTimestamp(id)); | 108 | + PluginMetaData data = new PluginMetaData(new PluginId(getId())); |
109 | + data.setTenantId(new TenantId(fromString(tenantId))); | ||
110 | + data.setCreatedTime(UUIDs.unixTimestamp(getId())); | ||
119 | data.setName(name); | 111 | data.setName(name); |
120 | data.setClazz(clazz); | 112 | data.setClazz(clazz); |
121 | data.setPublicAccess(publicAccess); | 113 | data.setPublicAccess(publicAccess); |
@@ -18,11 +18,11 @@ package org.thingsboard.server.dao.model.sql; | @@ -18,11 +18,11 @@ package org.thingsboard.server.dao.model.sql; | ||
18 | import lombok.AllArgsConstructor; | 18 | import lombok.AllArgsConstructor; |
19 | import lombok.Data; | 19 | import lombok.Data; |
20 | import lombok.NoArgsConstructor; | 20 | import lombok.NoArgsConstructor; |
21 | +import org.thingsboard.server.common.data.UUIDConverter; | ||
21 | import org.thingsboard.server.common.data.relation.EntityRelation; | 22 | import org.thingsboard.server.common.data.relation.EntityRelation; |
22 | 23 | ||
23 | import javax.persistence.Transient; | 24 | import javax.persistence.Transient; |
24 | import java.io.Serializable; | 25 | import java.io.Serializable; |
25 | -import java.util.UUID; | ||
26 | 26 | ||
27 | @NoArgsConstructor | 27 | @NoArgsConstructor |
28 | @AllArgsConstructor | 28 | @AllArgsConstructor |
@@ -32,17 +32,17 @@ public class RelationCompositeKey implements Serializable { | @@ -32,17 +32,17 @@ public class RelationCompositeKey implements Serializable { | ||
32 | @Transient | 32 | @Transient |
33 | private static final long serialVersionUID = -4089175869616037592L; | 33 | private static final long serialVersionUID = -4089175869616037592L; |
34 | 34 | ||
35 | - private UUID fromId; | 35 | + private String fromId; |
36 | private String fromType; | 36 | private String fromType; |
37 | - private UUID toId; | 37 | + private String toId; |
38 | private String toType; | 38 | private String toType; |
39 | private String relationType; | 39 | private String relationType; |
40 | private String relationTypeGroup; | 40 | private String relationTypeGroup; |
41 | 41 | ||
42 | public RelationCompositeKey(EntityRelation relation) { | 42 | public RelationCompositeKey(EntityRelation relation) { |
43 | - this.fromId = relation.getFrom().getId(); | 43 | + this.fromId = UUIDConverter.fromTimeUUID(relation.getFrom().getId()); |
44 | this.fromType = relation.getFrom().getEntityType().name(); | 44 | this.fromType = relation.getFrom().getEntityType().name(); |
45 | - this.toId = relation.getTo().getId(); | 45 | + this.toId = UUIDConverter.fromTimeUUID(relation.getTo().getId()); |
46 | this.toType = relation.getTo().getEntityType().name(); | 46 | this.toType = relation.getTo().getEntityType().name(); |
47 | this.relationType = relation.getType(); | 47 | this.relationType = relation.getType(); |
48 | this.relationTypeGroup = relation.getTypeGroup().name(); | 48 | this.relationTypeGroup = relation.getTypeGroup().name(); |
@@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.JsonNode; | @@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.JsonNode; | ||
19 | import lombok.Data; | 19 | import lombok.Data; |
20 | import org.hibernate.annotations.Type; | 20 | import org.hibernate.annotations.Type; |
21 | import org.hibernate.annotations.TypeDef; | 21 | import org.hibernate.annotations.TypeDef; |
22 | +import org.thingsboard.server.common.data.UUIDConverter; | ||
22 | import org.thingsboard.server.common.data.id.EntityIdFactory; | 23 | import org.thingsboard.server.common.data.id.EntityIdFactory; |
23 | import org.thingsboard.server.common.data.relation.EntityRelation; | 24 | import org.thingsboard.server.common.data.relation.EntityRelation; |
24 | import org.thingsboard.server.common.data.relation.RelationTypeGroup; | 25 | import org.thingsboard.server.common.data.relation.RelationTypeGroup; |
@@ -26,7 +27,6 @@ import org.thingsboard.server.dao.model.ToData; | @@ -26,7 +27,6 @@ import org.thingsboard.server.dao.model.ToData; | ||
26 | import org.thingsboard.server.dao.util.mapping.JsonStringType; | 27 | import org.thingsboard.server.dao.util.mapping.JsonStringType; |
27 | 28 | ||
28 | import javax.persistence.*; | 29 | import javax.persistence.*; |
29 | -import java.util.UUID; | ||
30 | 30 | ||
31 | import static org.thingsboard.server.dao.model.ModelConstants.*; | 31 | import static org.thingsboard.server.dao.model.ModelConstants.*; |
32 | 32 | ||
@@ -39,7 +39,7 @@ public final class RelationEntity implements ToData<EntityRelation> { | @@ -39,7 +39,7 @@ public final class RelationEntity implements ToData<EntityRelation> { | ||
39 | 39 | ||
40 | @Id | 40 | @Id |
41 | @Column(name = RELATION_FROM_ID_PROPERTY) | 41 | @Column(name = RELATION_FROM_ID_PROPERTY) |
42 | - private UUID fromId; | 42 | + private String fromId; |
43 | 43 | ||
44 | @Id | 44 | @Id |
45 | @Column(name = RELATION_FROM_TYPE_PROPERTY) | 45 | @Column(name = RELATION_FROM_TYPE_PROPERTY) |
@@ -47,7 +47,7 @@ public final class RelationEntity implements ToData<EntityRelation> { | @@ -47,7 +47,7 @@ public final class RelationEntity implements ToData<EntityRelation> { | ||
47 | 47 | ||
48 | @Id | 48 | @Id |
49 | @Column(name = RELATION_TO_ID_PROPERTY) | 49 | @Column(name = RELATION_TO_ID_PROPERTY) |
50 | - private UUID toId; | 50 | + private String toId; |
51 | 51 | ||
52 | @Id | 52 | @Id |
53 | @Column(name = RELATION_TO_TYPE_PROPERTY) | 53 | @Column(name = RELATION_TO_TYPE_PROPERTY) |
@@ -71,11 +71,11 @@ public final class RelationEntity implements ToData<EntityRelation> { | @@ -71,11 +71,11 @@ public final class RelationEntity implements ToData<EntityRelation> { | ||
71 | 71 | ||
72 | public RelationEntity(EntityRelation relation) { | 72 | public RelationEntity(EntityRelation relation) { |
73 | if (relation.getTo() != null) { | 73 | if (relation.getTo() != null) { |
74 | - this.toId = relation.getTo().getId(); | 74 | + this.toId = UUIDConverter.fromTimeUUID(relation.getTo().getId()); |
75 | this.toType = relation.getTo().getEntityType().name(); | 75 | this.toType = relation.getTo().getEntityType().name(); |
76 | } | 76 | } |
77 | if (relation.getFrom() != null) { | 77 | if (relation.getFrom() != null) { |
78 | - this.fromId = relation.getFrom().getId(); | 78 | + this.fromId = UUIDConverter.fromTimeUUID(relation.getFrom().getId()); |
79 | this.fromType = relation.getFrom().getEntityType().name(); | 79 | this.fromType = relation.getFrom().getEntityType().name(); |
80 | } | 80 | } |
81 | this.relationType = relation.getType(); | 81 | this.relationType = relation.getType(); |
@@ -87,10 +87,10 @@ public final class RelationEntity implements ToData<EntityRelation> { | @@ -87,10 +87,10 @@ public final class RelationEntity implements ToData<EntityRelation> { | ||
87 | public EntityRelation toData() { | 87 | public EntityRelation toData() { |
88 | EntityRelation relation = new EntityRelation(); | 88 | EntityRelation relation = new EntityRelation(); |
89 | if (toId != null && toType != null) { | 89 | if (toId != null && toType != null) { |
90 | - relation.setTo(EntityIdFactory.getByTypeAndUuid(toType, toId)); | 90 | + relation.setTo(EntityIdFactory.getByTypeAndUuid(toType, UUIDConverter.fromString(toId))); |
91 | } | 91 | } |
92 | if (fromId != null && fromType != null) { | 92 | if (fromId != null && fromType != null) { |
93 | - relation.setFrom(EntityIdFactory.getByTypeAndUuid(fromType, fromId)); | 93 | + relation.setFrom(EntityIdFactory.getByTypeAndUuid(fromType, UUIDConverter.fromString(fromId))); |
94 | } | 94 | } |
95 | relation.setType(relationType); | 95 | relation.setType(relationType); |
96 | relation.setTypeGroup(RelationTypeGroup.valueOf(relationTypeGroup)); | 96 | relation.setTypeGroup(RelationTypeGroup.valueOf(relationTypeGroup)); |
@@ -18,6 +18,7 @@ package org.thingsboard.server.dao.model.sql; | @@ -18,6 +18,7 @@ package org.thingsboard.server.dao.model.sql; | ||
18 | import com.datastax.driver.core.utils.UUIDs; | 18 | import com.datastax.driver.core.utils.UUIDs; |
19 | import com.fasterxml.jackson.databind.JsonNode; | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 20 | import lombok.Data; |
21 | +import lombok.EqualsAndHashCode; | ||
21 | import org.hibernate.annotations.Type; | 22 | import org.hibernate.annotations.Type; |
22 | import org.hibernate.annotations.TypeDef; | 23 | import org.hibernate.annotations.TypeDef; |
23 | import org.thingsboard.server.common.data.id.RuleId; | 24 | import org.thingsboard.server.common.data.id.RuleId; |
@@ -25,27 +26,25 @@ import org.thingsboard.server.common.data.id.TenantId; | @@ -25,27 +26,25 @@ import org.thingsboard.server.common.data.id.TenantId; | ||
25 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; | 26 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; |
26 | import org.thingsboard.server.common.data.rule.RuleMetaData; | 27 | import org.thingsboard.server.common.data.rule.RuleMetaData; |
27 | import org.thingsboard.server.dao.DaoUtil; | 28 | import org.thingsboard.server.dao.DaoUtil; |
29 | +import org.thingsboard.server.dao.model.BaseSqlEntity; | ||
28 | import org.thingsboard.server.dao.model.ModelConstants; | 30 | import org.thingsboard.server.dao.model.ModelConstants; |
29 | import org.thingsboard.server.dao.model.SearchTextEntity; | 31 | import org.thingsboard.server.dao.model.SearchTextEntity; |
30 | import org.thingsboard.server.dao.util.mapping.JsonStringType; | 32 | import org.thingsboard.server.dao.util.mapping.JsonStringType; |
31 | 33 | ||
32 | import javax.persistence.*; | 34 | import javax.persistence.*; |
33 | -import java.util.UUID; | ||
34 | 35 | ||
35 | @Data | 36 | @Data |
37 | +@EqualsAndHashCode(callSuper = true) | ||
36 | @Entity | 38 | @Entity |
37 | @TypeDef(name = "json", typeClass = JsonStringType.class) | 39 | @TypeDef(name = "json", typeClass = JsonStringType.class) |
38 | @Table(name = ModelConstants.RULE_COLUMN_FAMILY_NAME) | 40 | @Table(name = ModelConstants.RULE_COLUMN_FAMILY_NAME) |
39 | -public class RuleMetaDataEntity implements SearchTextEntity<RuleMetaData> { | 41 | +public class RuleMetaDataEntity extends BaseSqlEntity<RuleMetaData> implements SearchTextEntity<RuleMetaData> { |
40 | 42 | ||
41 | @Transient | 43 | @Transient |
42 | private static final long serialVersionUID = -1506905644259463884L; | 44 | private static final long serialVersionUID = -1506905644259463884L; |
43 | - @Id | ||
44 | - @Column(name = ModelConstants.ID_PROPERTY) | ||
45 | - private UUID id; | ||
46 | 45 | ||
47 | @Column(name = ModelConstants.RULE_TENANT_ID_PROPERTY) | 46 | @Column(name = ModelConstants.RULE_TENANT_ID_PROPERTY) |
48 | - private UUID tenantId; | 47 | + private String tenantId; |
49 | 48 | ||
50 | @Column(name = ModelConstants.RULE_NAME_PROPERTY) | 49 | @Column(name = ModelConstants.RULE_NAME_PROPERTY) |
51 | private String name; | 50 | private String name; |
@@ -84,9 +83,9 @@ public class RuleMetaDataEntity implements SearchTextEntity<RuleMetaData> { | @@ -84,9 +83,9 @@ public class RuleMetaDataEntity implements SearchTextEntity<RuleMetaData> { | ||
84 | 83 | ||
85 | public RuleMetaDataEntity(RuleMetaData rule) { | 84 | public RuleMetaDataEntity(RuleMetaData rule) { |
86 | if (rule.getId() != null) { | 85 | if (rule.getId() != null) { |
87 | - this.id = rule.getUuidId(); | 86 | + this.setId(rule.getUuidId()); |
88 | } | 87 | } |
89 | - this.tenantId = DaoUtil.getId(rule.getTenantId()); | 88 | + this.tenantId = toString(DaoUtil.getId(rule.getTenantId())); |
90 | this.name = rule.getName(); | 89 | this.name = rule.getName(); |
91 | this.pluginToken = rule.getPluginToken(); | 90 | this.pluginToken = rule.getPluginToken(); |
92 | this.state = rule.getState(); | 91 | this.state = rule.getState(); |
@@ -109,23 +108,13 @@ public class RuleMetaDataEntity implements SearchTextEntity<RuleMetaData> { | @@ -109,23 +108,13 @@ public class RuleMetaDataEntity implements SearchTextEntity<RuleMetaData> { | ||
109 | } | 108 | } |
110 | 109 | ||
111 | @Override | 110 | @Override |
112 | - public UUID getId() { | ||
113 | - return id; | ||
114 | - } | ||
115 | - | ||
116 | - @Override | ||
117 | - public void setId(UUID id) { | ||
118 | - this.id = id; | ||
119 | - } | ||
120 | - | ||
121 | - @Override | ||
122 | public RuleMetaData toData() { | 111 | public RuleMetaData toData() { |
123 | - RuleMetaData rule = new RuleMetaData(new RuleId(id)); | ||
124 | - rule.setTenantId(new TenantId(tenantId)); | 112 | + RuleMetaData rule = new RuleMetaData(new RuleId(getId())); |
113 | + rule.setTenantId(new TenantId(toUUID(tenantId))); | ||
125 | rule.setName(name); | 114 | rule.setName(name); |
126 | rule.setState(state); | 115 | rule.setState(state); |
127 | rule.setWeight(weight); | 116 | rule.setWeight(weight); |
128 | - rule.setCreatedTime(UUIDs.unixTimestamp(id)); | 117 | + rule.setCreatedTime(UUIDs.unixTimestamp(getId())); |
129 | rule.setPluginToken(pluginToken); | 118 | rule.setPluginToken(pluginToken); |
130 | rule.setFilters(filters); | 119 | rule.setFilters(filters); |
131 | rule.setProcessor(processor); | 120 | rule.setProcessor(processor); |
@@ -18,11 +18,9 @@ package org.thingsboard.server.dao.model.sql; | @@ -18,11 +18,9 @@ package org.thingsboard.server.dao.model.sql; | ||
18 | import lombok.AllArgsConstructor; | 18 | import lombok.AllArgsConstructor; |
19 | import lombok.Data; | 19 | import lombok.Data; |
20 | 20 | ||
21 | -import java.util.UUID; | ||
22 | - | ||
23 | @AllArgsConstructor | 21 | @AllArgsConstructor |
24 | @Data | 22 | @Data |
25 | public class TenantDeviceTypeEntity { | 23 | public class TenantDeviceTypeEntity { |
26 | - private UUID tenantId; | 24 | + private String tenantId; |
27 | private String type; | 25 | private String type; |
28 | } | 26 | } |
@@ -18,30 +18,31 @@ package org.thingsboard.server.dao.model.sql; | @@ -18,30 +18,31 @@ package org.thingsboard.server.dao.model.sql; | ||
18 | import com.datastax.driver.core.utils.UUIDs; | 18 | import com.datastax.driver.core.utils.UUIDs; |
19 | import com.fasterxml.jackson.databind.JsonNode; | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 20 | import lombok.Data; |
21 | +import lombok.EqualsAndHashCode; | ||
21 | import org.hibernate.annotations.Type; | 22 | import org.hibernate.annotations.Type; |
22 | import org.hibernate.annotations.TypeDef; | 23 | import org.hibernate.annotations.TypeDef; |
23 | import org.thingsboard.server.common.data.Tenant; | 24 | import org.thingsboard.server.common.data.Tenant; |
24 | import org.thingsboard.server.common.data.id.TenantId; | 25 | import org.thingsboard.server.common.data.id.TenantId; |
26 | +import org.thingsboard.server.dao.model.BaseSqlEntity; | ||
25 | import org.thingsboard.server.dao.model.ModelConstants; | 27 | import org.thingsboard.server.dao.model.ModelConstants; |
26 | import org.thingsboard.server.dao.model.SearchTextEntity; | 28 | import org.thingsboard.server.dao.model.SearchTextEntity; |
27 | import org.thingsboard.server.dao.util.mapping.JsonStringType; | 29 | import org.thingsboard.server.dao.util.mapping.JsonStringType; |
28 | 30 | ||
29 | -import javax.persistence.*; | ||
30 | -import java.util.UUID; | 31 | +import javax.persistence.Column; |
32 | +import javax.persistence.Entity; | ||
33 | +import javax.persistence.Table; | ||
34 | +import javax.persistence.Transient; | ||
31 | 35 | ||
32 | @Data | 36 | @Data |
37 | +@EqualsAndHashCode(callSuper = true) | ||
33 | @Entity | 38 | @Entity |
34 | @TypeDef(name = "json", typeClass = JsonStringType.class) | 39 | @TypeDef(name = "json", typeClass = JsonStringType.class) |
35 | @Table(name = ModelConstants.TENANT_COLUMN_FAMILY_NAME) | 40 | @Table(name = ModelConstants.TENANT_COLUMN_FAMILY_NAME) |
36 | -public final class TenantEntity implements SearchTextEntity<Tenant> { | 41 | +public final class TenantEntity extends BaseSqlEntity<Tenant> implements SearchTextEntity<Tenant> { |
37 | 42 | ||
38 | @Transient | 43 | @Transient |
39 | private static final long serialVersionUID = -4330655990232136337L; | 44 | private static final long serialVersionUID = -4330655990232136337L; |
40 | 45 | ||
41 | - @Id | ||
42 | - @Column(name = ModelConstants.ID_PROPERTY) | ||
43 | - private UUID id; | ||
44 | - | ||
45 | @Column(name = ModelConstants.TENANT_TITLE_PROPERTY) | 46 | @Column(name = ModelConstants.TENANT_TITLE_PROPERTY) |
46 | private String title; | 47 | private String title; |
47 | 48 | ||
@@ -75,7 +76,7 @@ public final class TenantEntity implements SearchTextEntity<Tenant> { | @@ -75,7 +76,7 @@ public final class TenantEntity implements SearchTextEntity<Tenant> { | ||
75 | @Column(name = ModelConstants.EMAIL_PROPERTY) | 76 | @Column(name = ModelConstants.EMAIL_PROPERTY) |
76 | private String email; | 77 | private String email; |
77 | 78 | ||
78 | - @Type(type="json") | 79 | + @Type(type = "json") |
79 | @Column(name = ModelConstants.TENANT_ADDITIONAL_INFO_PROPERTY) | 80 | @Column(name = ModelConstants.TENANT_ADDITIONAL_INFO_PROPERTY) |
80 | private JsonNode additionalInfo; | 81 | private JsonNode additionalInfo; |
81 | 82 | ||
@@ -85,7 +86,7 @@ public final class TenantEntity implements SearchTextEntity<Tenant> { | @@ -85,7 +86,7 @@ public final class TenantEntity implements SearchTextEntity<Tenant> { | ||
85 | 86 | ||
86 | public TenantEntity(Tenant tenant) { | 87 | public TenantEntity(Tenant tenant) { |
87 | if (tenant.getId() != null) { | 88 | if (tenant.getId() != null) { |
88 | - this.id = tenant.getId().getId(); | 89 | + this.setId(tenant.getId().getId()); |
89 | } | 90 | } |
90 | this.title = tenant.getTitle(); | 91 | this.title = tenant.getTitle(); |
91 | this.region = tenant.getRegion(); | 92 | this.region = tenant.getRegion(); |
@@ -116,8 +117,8 @@ public final class TenantEntity implements SearchTextEntity<Tenant> { | @@ -116,8 +117,8 @@ public final class TenantEntity implements SearchTextEntity<Tenant> { | ||
116 | 117 | ||
117 | @Override | 118 | @Override |
118 | public Tenant toData() { | 119 | public Tenant toData() { |
119 | - Tenant tenant = new Tenant(new TenantId(id)); | ||
120 | - tenant.setCreatedTime(UUIDs.unixTimestamp(id)); | 120 | + Tenant tenant = new Tenant(new TenantId(getId())); |
121 | + tenant.setCreatedTime(UUIDs.unixTimestamp(getId())); | ||
121 | tenant.setTitle(title); | 122 | tenant.setTitle(title); |
122 | tenant.setRegion(region); | 123 | tenant.setRegion(region); |
123 | tenant.setCountry(country); | 124 | tenant.setCountry(country); |
@@ -22,18 +22,17 @@ import org.thingsboard.server.common.data.EntityType; | @@ -22,18 +22,17 @@ import org.thingsboard.server.common.data.EntityType; | ||
22 | 22 | ||
23 | import javax.persistence.Transient; | 23 | import javax.persistence.Transient; |
24 | import java.io.Serializable; | 24 | import java.io.Serializable; |
25 | -import java.util.UUID; | ||
26 | 25 | ||
27 | @Data | 26 | @Data |
28 | @AllArgsConstructor | 27 | @AllArgsConstructor |
29 | @NoArgsConstructor | 28 | @NoArgsConstructor |
30 | -public class TsKvCompositeKey implements Serializable{ | 29 | +public class TsKvCompositeKey implements Serializable { |
31 | 30 | ||
32 | @Transient | 31 | @Transient |
33 | private static final long serialVersionUID = -4089175869616037523L; | 32 | private static final long serialVersionUID = -4089175869616037523L; |
34 | 33 | ||
35 | private EntityType entityType; | 34 | private EntityType entityType; |
36 | - private UUID entityId; | 35 | + private String entityId; |
37 | private String key; | 36 | private String key; |
38 | private long ts; | 37 | private long ts; |
39 | } | 38 | } |
@@ -21,7 +21,6 @@ import org.thingsboard.server.common.data.kv.*; | @@ -21,7 +21,6 @@ import org.thingsboard.server.common.data.kv.*; | ||
21 | import org.thingsboard.server.dao.model.ToData; | 21 | import org.thingsboard.server.dao.model.ToData; |
22 | 22 | ||
23 | import javax.persistence.*; | 23 | import javax.persistence.*; |
24 | -import java.util.UUID; | ||
25 | 24 | ||
26 | import static org.thingsboard.server.dao.model.ModelConstants.*; | 25 | import static org.thingsboard.server.dao.model.ModelConstants.*; |
27 | 26 | ||
@@ -69,7 +68,7 @@ public final class TsKvEntity implements ToData<TsKvEntry> { | @@ -69,7 +68,7 @@ public final class TsKvEntity implements ToData<TsKvEntry> { | ||
69 | 68 | ||
70 | @Id | 69 | @Id |
71 | @Column(name = ENTITY_ID_COLUMN) | 70 | @Column(name = ENTITY_ID_COLUMN) |
72 | - private UUID entityId; | 71 | + private String entityId; |
73 | 72 | ||
74 | @Id | 73 | @Id |
75 | @Column(name = KEY_COLUMN) | 74 | @Column(name = KEY_COLUMN) |
@@ -15,12 +15,13 @@ | @@ -15,12 +15,13 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.sql; | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | ||
18 | -import lombok.*; | 18 | +import lombok.AllArgsConstructor; |
19 | +import lombok.Data; | ||
20 | +import lombok.NoArgsConstructor; | ||
19 | import org.thingsboard.server.common.data.EntityType; | 21 | import org.thingsboard.server.common.data.EntityType; |
20 | 22 | ||
21 | import javax.persistence.Transient; | 23 | import javax.persistence.Transient; |
22 | import java.io.Serializable; | 24 | import java.io.Serializable; |
23 | -import java.util.UUID; | ||
24 | 25 | ||
25 | @Data | 26 | @Data |
26 | @NoArgsConstructor | 27 | @NoArgsConstructor |
@@ -31,6 +32,6 @@ public class TsKvLatestCompositeKey implements Serializable{ | @@ -31,6 +32,6 @@ public class TsKvLatestCompositeKey implements Serializable{ | ||
31 | private static final long serialVersionUID = -4089175869616037523L; | 32 | private static final long serialVersionUID = -4089175869616037523L; |
32 | 33 | ||
33 | private EntityType entityType; | 34 | private EntityType entityType; |
34 | - private UUID entityId; | 35 | + private String entityId; |
35 | private String key; | 36 | private String key; |
36 | } | 37 | } |
@@ -21,7 +21,6 @@ import org.thingsboard.server.common.data.kv.*; | @@ -21,7 +21,6 @@ import org.thingsboard.server.common.data.kv.*; | ||
21 | import org.thingsboard.server.dao.model.ToData; | 21 | import org.thingsboard.server.dao.model.ToData; |
22 | 22 | ||
23 | import javax.persistence.*; | 23 | import javax.persistence.*; |
24 | -import java.util.UUID; | ||
25 | 24 | ||
26 | import static org.thingsboard.server.dao.model.ModelConstants.*; | 25 | import static org.thingsboard.server.dao.model.ModelConstants.*; |
27 | 26 | ||
@@ -31,6 +30,8 @@ import static org.thingsboard.server.dao.model.ModelConstants.*; | @@ -31,6 +30,8 @@ import static org.thingsboard.server.dao.model.ModelConstants.*; | ||
31 | @IdClass(TsKvLatestCompositeKey.class) | 30 | @IdClass(TsKvLatestCompositeKey.class) |
32 | public final class TsKvLatestEntity implements ToData<TsKvEntry> { | 31 | public final class TsKvLatestEntity implements ToData<TsKvEntry> { |
33 | 32 | ||
33 | + | ||
34 | + //TODO: reafctor this and TsKvEntity to avoid code duplicates | ||
34 | @Id | 35 | @Id |
35 | @Enumerated(EnumType.STRING) | 36 | @Enumerated(EnumType.STRING) |
36 | @Column(name = ENTITY_TYPE_COLUMN) | 37 | @Column(name = ENTITY_TYPE_COLUMN) |
@@ -38,7 +39,7 @@ public final class TsKvLatestEntity implements ToData<TsKvEntry> { | @@ -38,7 +39,7 @@ public final class TsKvLatestEntity implements ToData<TsKvEntry> { | ||
38 | 39 | ||
39 | @Id | 40 | @Id |
40 | @Column(name = ENTITY_ID_COLUMN) | 41 | @Column(name = ENTITY_ID_COLUMN) |
41 | - private UUID entityId; | 42 | + private String entityId; |
42 | 43 | ||
43 | @Id | 44 | @Id |
44 | @Column(name = KEY_COLUMN) | 45 | @Column(name = KEY_COLUMN) |
@@ -17,29 +17,30 @@ package org.thingsboard.server.dao.model.sql; | @@ -17,29 +17,30 @@ package org.thingsboard.server.dao.model.sql; | ||
17 | 17 | ||
18 | import com.datastax.driver.core.utils.UUIDs; | 18 | import com.datastax.driver.core.utils.UUIDs; |
19 | import lombok.Data; | 19 | import lombok.Data; |
20 | +import lombok.EqualsAndHashCode; | ||
20 | import org.thingsboard.server.common.data.id.UserCredentialsId; | 21 | import org.thingsboard.server.common.data.id.UserCredentialsId; |
21 | import org.thingsboard.server.common.data.id.UserId; | 22 | import org.thingsboard.server.common.data.id.UserId; |
22 | import org.thingsboard.server.common.data.security.UserCredentials; | 23 | import org.thingsboard.server.common.data.security.UserCredentials; |
23 | import org.thingsboard.server.dao.model.BaseEntity; | 24 | import org.thingsboard.server.dao.model.BaseEntity; |
25 | +import org.thingsboard.server.dao.model.BaseSqlEntity; | ||
24 | import org.thingsboard.server.dao.model.ModelConstants; | 26 | import org.thingsboard.server.dao.model.ModelConstants; |
25 | 27 | ||
26 | -import javax.persistence.*; | ||
27 | -import java.util.UUID; | 28 | +import javax.persistence.Column; |
29 | +import javax.persistence.Entity; | ||
30 | +import javax.persistence.Table; | ||
31 | +import javax.persistence.Transient; | ||
28 | 32 | ||
29 | @Data | 33 | @Data |
34 | +@EqualsAndHashCode(callSuper = true) | ||
30 | @Entity | 35 | @Entity |
31 | @Table(name = ModelConstants.USER_CREDENTIALS_COLUMN_FAMILY_NAME) | 36 | @Table(name = ModelConstants.USER_CREDENTIALS_COLUMN_FAMILY_NAME) |
32 | -public final class UserCredentialsEntity implements BaseEntity<UserCredentials> { | 37 | +public final class UserCredentialsEntity extends BaseSqlEntity<UserCredentials> implements BaseEntity<UserCredentials> { |
33 | 38 | ||
34 | @Transient | 39 | @Transient |
35 | private static final long serialVersionUID = -3989724854149114846L; | 40 | private static final long serialVersionUID = -3989724854149114846L; |
36 | 41 | ||
37 | - @Id | ||
38 | - @Column(name = ModelConstants.ID_PROPERTY) | ||
39 | - private UUID id; | ||
40 | - | ||
41 | @Column(name = ModelConstants.USER_CREDENTIALS_USER_ID_PROPERTY, unique = true) | 42 | @Column(name = ModelConstants.USER_CREDENTIALS_USER_ID_PROPERTY, unique = true) |
42 | - private UUID userId; | 43 | + private String userId; |
43 | 44 | ||
44 | @Column(name = ModelConstants.USER_CREDENTIALS_ENABLED_PROPERTY) | 45 | @Column(name = ModelConstants.USER_CREDENTIALS_ENABLED_PROPERTY) |
45 | private boolean enabled; | 46 | private boolean enabled; |
@@ -59,10 +60,10 @@ public final class UserCredentialsEntity implements BaseEntity<UserCredentials> | @@ -59,10 +60,10 @@ public final class UserCredentialsEntity implements BaseEntity<UserCredentials> | ||
59 | 60 | ||
60 | public UserCredentialsEntity(UserCredentials userCredentials) { | 61 | public UserCredentialsEntity(UserCredentials userCredentials) { |
61 | if (userCredentials.getId() != null) { | 62 | if (userCredentials.getId() != null) { |
62 | - this.id = userCredentials.getId().getId(); | 63 | + this.setId(userCredentials.getId().getId()); |
63 | } | 64 | } |
64 | if (userCredentials.getUserId() != null) { | 65 | if (userCredentials.getUserId() != null) { |
65 | - this.userId = userCredentials.getUserId().getId(); | 66 | + this.userId = toString(userCredentials.getUserId().getId()); |
66 | } | 67 | } |
67 | this.enabled = userCredentials.isEnabled(); | 68 | this.enabled = userCredentials.isEnabled(); |
68 | this.password = userCredentials.getPassword(); | 69 | this.password = userCredentials.getPassword(); |
@@ -72,10 +73,10 @@ public final class UserCredentialsEntity implements BaseEntity<UserCredentials> | @@ -72,10 +73,10 @@ public final class UserCredentialsEntity implements BaseEntity<UserCredentials> | ||
72 | 73 | ||
73 | @Override | 74 | @Override |
74 | public UserCredentials toData() { | 75 | public UserCredentials toData() { |
75 | - UserCredentials userCredentials = new UserCredentials(new UserCredentialsId(id)); | ||
76 | - userCredentials.setCreatedTime(UUIDs.unixTimestamp(id)); | 76 | + UserCredentials userCredentials = new UserCredentials(new UserCredentialsId(getId())); |
77 | + userCredentials.setCreatedTime(UUIDs.unixTimestamp(getId())); | ||
77 | if (userId != null) { | 78 | if (userId != null) { |
78 | - userCredentials.setUserId(new UserId(userId)); | 79 | + userCredentials.setUserId(new UserId(toUUID(userId))); |
79 | } | 80 | } |
80 | userCredentials.setEnabled(enabled); | 81 | userCredentials.setEnabled(enabled); |
81 | userCredentials.setPassword(password); | 82 | userCredentials.setPassword(password); |
@@ -84,13 +85,4 @@ public final class UserCredentialsEntity implements BaseEntity<UserCredentials> | @@ -84,13 +85,4 @@ public final class UserCredentialsEntity implements BaseEntity<UserCredentials> | ||
84 | return userCredentials; | 85 | return userCredentials; |
85 | } | 86 | } |
86 | 87 | ||
87 | - @Override | ||
88 | - public UUID getId() { | ||
89 | - return id; | ||
90 | - } | ||
91 | - | ||
92 | - @Override | ||
93 | - public void setId(UUID id) { | ||
94 | - this.id = id; | ||
95 | - } | ||
96 | } | 88 | } |
@@ -18,6 +18,7 @@ package org.thingsboard.server.dao.model.sql; | @@ -18,6 +18,7 @@ package org.thingsboard.server.dao.model.sql; | ||
18 | import com.datastax.driver.core.utils.UUIDs; | 18 | import com.datastax.driver.core.utils.UUIDs; |
19 | import com.fasterxml.jackson.databind.JsonNode; | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 20 | import lombok.Data; |
21 | +import lombok.EqualsAndHashCode; | ||
21 | import org.hibernate.annotations.Type; | 22 | import org.hibernate.annotations.Type; |
22 | import org.hibernate.annotations.TypeDef; | 23 | import org.hibernate.annotations.TypeDef; |
23 | import org.thingsboard.server.common.data.User; | 24 | import org.thingsboard.server.common.data.User; |
@@ -25,33 +26,33 @@ import org.thingsboard.server.common.data.id.CustomerId; | @@ -25,33 +26,33 @@ import org.thingsboard.server.common.data.id.CustomerId; | ||
25 | import org.thingsboard.server.common.data.id.TenantId; | 26 | import org.thingsboard.server.common.data.id.TenantId; |
26 | import org.thingsboard.server.common.data.id.UserId; | 27 | import org.thingsboard.server.common.data.id.UserId; |
27 | import org.thingsboard.server.common.data.security.Authority; | 28 | import org.thingsboard.server.common.data.security.Authority; |
29 | +import org.thingsboard.server.dao.model.BaseSqlEntity; | ||
28 | import org.thingsboard.server.dao.model.ModelConstants; | 30 | import org.thingsboard.server.dao.model.ModelConstants; |
29 | import org.thingsboard.server.dao.model.SearchTextEntity; | 31 | import org.thingsboard.server.dao.model.SearchTextEntity; |
30 | import org.thingsboard.server.dao.util.mapping.JsonStringType; | 32 | import org.thingsboard.server.dao.util.mapping.JsonStringType; |
31 | 33 | ||
32 | import javax.persistence.*; | 34 | import javax.persistence.*; |
33 | -import java.util.UUID; | 35 | + |
36 | +import static org.thingsboard.server.common.data.UUIDConverter.fromString; | ||
37 | +import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID; | ||
34 | 38 | ||
35 | /** | 39 | /** |
36 | * Created by Valerii Sosliuk on 4/21/2017. | 40 | * Created by Valerii Sosliuk on 4/21/2017. |
37 | */ | 41 | */ |
38 | @Data | 42 | @Data |
43 | +@EqualsAndHashCode(callSuper = true) | ||
39 | @Entity | 44 | @Entity |
40 | @TypeDef(name = "json", typeClass = JsonStringType.class) | 45 | @TypeDef(name = "json", typeClass = JsonStringType.class) |
41 | @Table(name = ModelConstants.USER_PG_HIBERNATE_COLUMN_FAMILY_NAME) | 46 | @Table(name = ModelConstants.USER_PG_HIBERNATE_COLUMN_FAMILY_NAME) |
42 | -public class UserEntity implements SearchTextEntity<User> { | 47 | +public class UserEntity extends BaseSqlEntity<User> implements SearchTextEntity<User> { |
43 | @Transient | 48 | @Transient |
44 | private static final long serialVersionUID = -271106508790582977L; | 49 | private static final long serialVersionUID = -271106508790582977L; |
45 | 50 | ||
46 | - @Id | ||
47 | - @Column(name = ModelConstants.ID_PROPERTY) | ||
48 | - private UUID id; | ||
49 | - | ||
50 | @Column(name = ModelConstants.USER_TENANT_ID_PROPERTY) | 51 | @Column(name = ModelConstants.USER_TENANT_ID_PROPERTY) |
51 | - private UUID tenantId; | 52 | + private String tenantId; |
52 | 53 | ||
53 | @Column(name = ModelConstants.USER_CUSTOMER_ID_PROPERTY) | 54 | @Column(name = ModelConstants.USER_CUSTOMER_ID_PROPERTY) |
54 | - private UUID customerId; | 55 | + private String customerId; |
55 | 56 | ||
56 | @Enumerated(EnumType.STRING) | 57 | @Enumerated(EnumType.STRING) |
57 | @Column(name = ModelConstants.USER_AUTHORITY_PROPERTY) | 58 | @Column(name = ModelConstants.USER_AUTHORITY_PROPERTY) |
@@ -69,7 +70,7 @@ public class UserEntity implements SearchTextEntity<User> { | @@ -69,7 +70,7 @@ public class UserEntity implements SearchTextEntity<User> { | ||
69 | @Column(name = ModelConstants.USER_LAST_NAME_PROPERTY) | 70 | @Column(name = ModelConstants.USER_LAST_NAME_PROPERTY) |
70 | private String lastName; | 71 | private String lastName; |
71 | 72 | ||
72 | - @Type(type="json") | 73 | + @Type(type = "json") |
73 | @Column(name = ModelConstants.USER_ADDITIONAL_INFO_PROPERTY) | 74 | @Column(name = ModelConstants.USER_ADDITIONAL_INFO_PROPERTY) |
74 | private JsonNode additionalInfo; | 75 | private JsonNode additionalInfo; |
75 | 76 | ||
@@ -78,14 +79,14 @@ public class UserEntity implements SearchTextEntity<User> { | @@ -78,14 +79,14 @@ public class UserEntity implements SearchTextEntity<User> { | ||
78 | 79 | ||
79 | public UserEntity(User user) { | 80 | public UserEntity(User user) { |
80 | if (user.getId() != null) { | 81 | if (user.getId() != null) { |
81 | - this.id = user.getId().getId(); | 82 | + this.setId(user.getId().getId()); |
82 | } | 83 | } |
83 | this.authority = user.getAuthority(); | 84 | this.authority = user.getAuthority(); |
84 | if (user.getTenantId() != null) { | 85 | if (user.getTenantId() != null) { |
85 | - this.tenantId = user.getTenantId().getId(); | 86 | + this.tenantId = fromTimeUUID(user.getTenantId().getId()); |
86 | } | 87 | } |
87 | if (user.getCustomerId() != null) { | 88 | if (user.getCustomerId() != null) { |
88 | - this.customerId = user.getCustomerId().getId(); | 89 | + this.customerId = fromTimeUUID(user.getCustomerId().getId()); |
89 | } | 90 | } |
90 | this.email = user.getEmail(); | 91 | this.email = user.getEmail(); |
91 | this.firstName = user.getFirstName(); | 92 | this.firstName = user.getFirstName(); |
@@ -104,25 +105,15 @@ public class UserEntity implements SearchTextEntity<User> { | @@ -104,25 +105,15 @@ public class UserEntity implements SearchTextEntity<User> { | ||
104 | } | 105 | } |
105 | 106 | ||
106 | @Override | 107 | @Override |
107 | - public UUID getId() { | ||
108 | - return id; | ||
109 | - } | ||
110 | - | ||
111 | - @Override | ||
112 | - public void setId(UUID id) { | ||
113 | - this.id = id; | ||
114 | - } | ||
115 | - | ||
116 | - @Override | ||
117 | public User toData() { | 108 | public User toData() { |
118 | - User user = new User(new UserId(id)); | ||
119 | - user.setCreatedTime(UUIDs.unixTimestamp(id)); | 109 | + User user = new User(new UserId(getId())); |
110 | + user.setCreatedTime(UUIDs.unixTimestamp(getId())); | ||
120 | user.setAuthority(authority); | 111 | user.setAuthority(authority); |
121 | if (tenantId != null) { | 112 | if (tenantId != null) { |
122 | - user.setTenantId(new TenantId(tenantId)); | 113 | + user.setTenantId(new TenantId(fromString(tenantId))); |
123 | } | 114 | } |
124 | if (customerId != null) { | 115 | if (customerId != null) { |
125 | - user.setCustomerId(new CustomerId(customerId)); | 116 | + user.setCustomerId(new CustomerId(fromString(customerId))); |
126 | } | 117 | } |
127 | user.setEmail(email); | 118 | user.setEmail(email); |
128 | user.setFirstName(firstName); | 119 | user.setFirstName(firstName); |
@@ -18,33 +18,34 @@ package org.thingsboard.server.dao.model.sql; | @@ -18,33 +18,34 @@ package org.thingsboard.server.dao.model.sql; | ||
18 | import com.datastax.driver.core.utils.UUIDs; | 18 | import com.datastax.driver.core.utils.UUIDs; |
19 | import com.fasterxml.jackson.databind.JsonNode; | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import lombok.Data; | 20 | import lombok.Data; |
21 | +import lombok.EqualsAndHashCode; | ||
21 | import org.hibernate.annotations.Type; | 22 | import org.hibernate.annotations.Type; |
22 | import org.hibernate.annotations.TypeDef; | 23 | import org.hibernate.annotations.TypeDef; |
23 | import org.thingsboard.server.common.data.id.TenantId; | 24 | import org.thingsboard.server.common.data.id.TenantId; |
24 | import org.thingsboard.server.common.data.id.WidgetTypeId; | 25 | import org.thingsboard.server.common.data.id.WidgetTypeId; |
25 | import org.thingsboard.server.common.data.widget.WidgetType; | 26 | import org.thingsboard.server.common.data.widget.WidgetType; |
26 | import org.thingsboard.server.dao.model.BaseEntity; | 27 | import org.thingsboard.server.dao.model.BaseEntity; |
28 | +import org.thingsboard.server.dao.model.BaseSqlEntity; | ||
27 | import org.thingsboard.server.dao.model.ModelConstants; | 29 | import org.thingsboard.server.dao.model.ModelConstants; |
28 | import org.thingsboard.server.dao.util.mapping.JsonStringType; | 30 | import org.thingsboard.server.dao.util.mapping.JsonStringType; |
29 | 31 | ||
30 | -import javax.persistence.*; | ||
31 | -import java.util.UUID; | 32 | +import javax.persistence.Column; |
33 | +import javax.persistence.Entity; | ||
34 | +import javax.persistence.Table; | ||
35 | +import javax.persistence.Transient; | ||
32 | 36 | ||
33 | @Data | 37 | @Data |
38 | +@EqualsAndHashCode(callSuper = true) | ||
34 | @Entity | 39 | @Entity |
35 | @TypeDef(name = "json", typeClass = JsonStringType.class) | 40 | @TypeDef(name = "json", typeClass = JsonStringType.class) |
36 | @Table(name = ModelConstants.WIDGET_TYPE_COLUMN_FAMILY_NAME) | 41 | @Table(name = ModelConstants.WIDGET_TYPE_COLUMN_FAMILY_NAME) |
37 | -public final class WidgetTypeEntity implements BaseEntity<WidgetType> { | 42 | +public final class WidgetTypeEntity extends BaseSqlEntity<WidgetType> implements BaseEntity<WidgetType> { |
38 | 43 | ||
39 | @Transient | 44 | @Transient |
40 | private static final long serialVersionUID = -5436279069884988630L; | 45 | private static final long serialVersionUID = -5436279069884988630L; |
41 | 46 | ||
42 | - @Id | ||
43 | - @Column(name = ModelConstants.ID_PROPERTY) | ||
44 | - private UUID id; | ||
45 | - | ||
46 | @Column(name = ModelConstants.WIDGET_TYPE_TENANT_ID_PROPERTY) | 47 | @Column(name = ModelConstants.WIDGET_TYPE_TENANT_ID_PROPERTY) |
47 | - private UUID tenantId; | 48 | + private String tenantId; |
48 | 49 | ||
49 | @Column(name = ModelConstants.WIDGET_TYPE_BUNDLE_ALIAS_PROPERTY) | 50 | @Column(name = ModelConstants.WIDGET_TYPE_BUNDLE_ALIAS_PROPERTY) |
50 | private String bundleAlias; | 51 | private String bundleAlias; |
@@ -65,10 +66,10 @@ public final class WidgetTypeEntity implements BaseEntity<WidgetType> { | @@ -65,10 +66,10 @@ public final class WidgetTypeEntity implements BaseEntity<WidgetType> { | ||
65 | 66 | ||
66 | public WidgetTypeEntity(WidgetType widgetType) { | 67 | public WidgetTypeEntity(WidgetType widgetType) { |
67 | if (widgetType.getId() != null) { | 68 | if (widgetType.getId() != null) { |
68 | - this.id = widgetType.getId().getId(); | 69 | + this.setId(widgetType.getId().getId()); |
69 | } | 70 | } |
70 | if (widgetType.getTenantId() != null) { | 71 | if (widgetType.getTenantId() != null) { |
71 | - this.tenantId = widgetType.getTenantId().getId(); | 72 | + this.tenantId = toString(widgetType.getTenantId().getId()); |
72 | } | 73 | } |
73 | this.bundleAlias = widgetType.getBundleAlias(); | 74 | this.bundleAlias = widgetType.getBundleAlias(); |
74 | this.alias = widgetType.getAlias(); | 75 | this.alias = widgetType.getAlias(); |
@@ -77,21 +78,11 @@ public final class WidgetTypeEntity implements BaseEntity<WidgetType> { | @@ -77,21 +78,11 @@ public final class WidgetTypeEntity implements BaseEntity<WidgetType> { | ||
77 | } | 78 | } |
78 | 79 | ||
79 | @Override | 80 | @Override |
80 | - public UUID getId() { | ||
81 | - return id; | ||
82 | - } | ||
83 | - | ||
84 | - @Override | ||
85 | - public void setId(UUID id) { | ||
86 | - this.id = id; | ||
87 | - } | ||
88 | - | ||
89 | - @Override | ||
90 | public WidgetType toData() { | 81 | public WidgetType toData() { |
91 | - WidgetType widgetType = new WidgetType(new WidgetTypeId(id)); | ||
92 | - widgetType.setCreatedTime(UUIDs.unixTimestamp(id)); | 82 | + WidgetType widgetType = new WidgetType(new WidgetTypeId(getId())); |
83 | + widgetType.setCreatedTime(UUIDs.unixTimestamp(getId())); | ||
93 | if (tenantId != null) { | 84 | if (tenantId != null) { |
94 | - widgetType.setTenantId(new TenantId(tenantId)); | 85 | + widgetType.setTenantId(new TenantId(toUUID(tenantId))); |
95 | } | 86 | } |
96 | widgetType.setBundleAlias(bundleAlias); | 87 | widgetType.setBundleAlias(bundleAlias); |
97 | widgetType.setAlias(alias); | 88 | widgetType.setAlias(alias); |
@@ -18,29 +18,31 @@ package org.thingsboard.server.dao.model.sql; | @@ -18,29 +18,31 @@ package org.thingsboard.server.dao.model.sql; | ||
18 | 18 | ||
19 | import com.datastax.driver.core.utils.UUIDs; | 19 | import com.datastax.driver.core.utils.UUIDs; |
20 | import lombok.Data; | 20 | import lombok.Data; |
21 | +import lombok.EqualsAndHashCode; | ||
22 | +import org.thingsboard.server.common.data.UUIDConverter; | ||
21 | import org.thingsboard.server.common.data.id.TenantId; | 23 | import org.thingsboard.server.common.data.id.TenantId; |
22 | import org.thingsboard.server.common.data.id.WidgetsBundleId; | 24 | import org.thingsboard.server.common.data.id.WidgetsBundleId; |
23 | import org.thingsboard.server.common.data.widget.WidgetsBundle; | 25 | import org.thingsboard.server.common.data.widget.WidgetsBundle; |
26 | +import org.thingsboard.server.dao.model.BaseSqlEntity; | ||
24 | import org.thingsboard.server.dao.model.ModelConstants; | 27 | import org.thingsboard.server.dao.model.ModelConstants; |
25 | import org.thingsboard.server.dao.model.SearchTextEntity; | 28 | import org.thingsboard.server.dao.model.SearchTextEntity; |
26 | 29 | ||
27 | -import javax.persistence.*; | ||
28 | -import java.util.UUID; | 30 | +import javax.persistence.Column; |
31 | +import javax.persistence.Entity; | ||
32 | +import javax.persistence.Table; | ||
33 | +import javax.persistence.Transient; | ||
29 | 34 | ||
30 | @Data | 35 | @Data |
36 | +@EqualsAndHashCode(callSuper = true) | ||
31 | @Entity | 37 | @Entity |
32 | @Table(name = ModelConstants.WIDGETS_BUNDLE_COLUMN_FAMILY_NAME) | 38 | @Table(name = ModelConstants.WIDGETS_BUNDLE_COLUMN_FAMILY_NAME) |
33 | -public final class WidgetsBundleEntity implements SearchTextEntity<WidgetsBundle> { | 39 | +public final class WidgetsBundleEntity extends BaseSqlEntity<WidgetsBundle> implements SearchTextEntity<WidgetsBundle> { |
34 | 40 | ||
35 | @Transient | 41 | @Transient |
36 | private static final long serialVersionUID = 6897035686422298096L; | 42 | private static final long serialVersionUID = 6897035686422298096L; |
37 | 43 | ||
38 | - @Id | ||
39 | - @Column(name = ModelConstants.ID_PROPERTY) | ||
40 | - private UUID id; | ||
41 | - | ||
42 | @Column(name = ModelConstants.WIDGETS_BUNDLE_TENANT_ID_PROPERTY) | 44 | @Column(name = ModelConstants.WIDGETS_BUNDLE_TENANT_ID_PROPERTY) |
43 | - private UUID tenantId; | 45 | + private String tenantId; |
44 | 46 | ||
45 | @Column(name = ModelConstants.WIDGETS_BUNDLE_ALIAS_PROPERTY) | 47 | @Column(name = ModelConstants.WIDGETS_BUNDLE_ALIAS_PROPERTY) |
46 | private String alias; | 48 | private String alias; |
@@ -57,26 +59,16 @@ public final class WidgetsBundleEntity implements SearchTextEntity<WidgetsBundle | @@ -57,26 +59,16 @@ public final class WidgetsBundleEntity implements SearchTextEntity<WidgetsBundle | ||
57 | 59 | ||
58 | public WidgetsBundleEntity(WidgetsBundle widgetsBundle) { | 60 | public WidgetsBundleEntity(WidgetsBundle widgetsBundle) { |
59 | if (widgetsBundle.getId() != null) { | 61 | if (widgetsBundle.getId() != null) { |
60 | - this.id = widgetsBundle.getId().getId(); | 62 | + this.setId(widgetsBundle.getId().getId()); |
61 | } | 63 | } |
62 | if (widgetsBundle.getTenantId() != null) { | 64 | if (widgetsBundle.getTenantId() != null) { |
63 | - this.tenantId = widgetsBundle.getTenantId().getId(); | 65 | + this.tenantId = UUIDConverter.fromTimeUUID(widgetsBundle.getTenantId().getId()); |
64 | } | 66 | } |
65 | this.alias = widgetsBundle.getAlias(); | 67 | this.alias = widgetsBundle.getAlias(); |
66 | this.title = widgetsBundle.getTitle(); | 68 | this.title = widgetsBundle.getTitle(); |
67 | } | 69 | } |
68 | 70 | ||
69 | @Override | 71 | @Override |
70 | - public UUID getId() { | ||
71 | - return id; | ||
72 | - } | ||
73 | - | ||
74 | - @Override | ||
75 | - public void setId(UUID id) { | ||
76 | - this.id = id; | ||
77 | - } | ||
78 | - | ||
79 | - @Override | ||
80 | public String getSearchTextSource() { | 72 | public String getSearchTextSource() { |
81 | return title; | 73 | return title; |
82 | } | 74 | } |
@@ -88,10 +80,10 @@ public final class WidgetsBundleEntity implements SearchTextEntity<WidgetsBundle | @@ -88,10 +80,10 @@ public final class WidgetsBundleEntity implements SearchTextEntity<WidgetsBundle | ||
88 | 80 | ||
89 | @Override | 81 | @Override |
90 | public WidgetsBundle toData() { | 82 | public WidgetsBundle toData() { |
91 | - WidgetsBundle widgetsBundle = new WidgetsBundle(new WidgetsBundleId(id)); | ||
92 | - widgetsBundle.setCreatedTime(UUIDs.unixTimestamp(id)); | 83 | + WidgetsBundle widgetsBundle = new WidgetsBundle(new WidgetsBundleId(UUIDConverter.fromString(id))); |
84 | + widgetsBundle.setCreatedTime(UUIDs.unixTimestamp(UUIDConverter.fromString(id))); | ||
93 | if (tenantId != null) { | 85 | if (tenantId != null) { |
94 | - widgetsBundle.setTenantId(new TenantId(tenantId)); | 86 | + widgetsBundle.setTenantId(new TenantId(UUIDConverter.fromString(tenantId))); |
95 | } | 87 | } |
96 | widgetsBundle.setAlias(alias); | 88 | widgetsBundle.setAlias(alias); |
97 | widgetsBundle.setTitle(title); | 89 | widgetsBundle.setTitle(title); |
@@ -17,8 +17,6 @@ package org.thingsboard.server.dao.model.type; | @@ -17,8 +17,6 @@ package org.thingsboard.server.dao.model.type; | ||
17 | 17 | ||
18 | import com.datastax.driver.extras.codecs.enums.EnumNameCodec; | 18 | import com.datastax.driver.extras.codecs.enums.EnumNameCodec; |
19 | import org.thingsboard.server.common.data.alarm.AlarmSeverity; | 19 | import org.thingsboard.server.common.data.alarm.AlarmSeverity; |
20 | -import org.thingsboard.server.common.data.alarm.AlarmStatus; | ||
21 | -import org.thingsboard.server.dao.alarm.AlarmService; | ||
22 | 20 | ||
23 | public class AlarmSeverityCodec extends EnumNameCodec<AlarmSeverity> { | 21 | public class AlarmSeverityCodec extends EnumNameCodec<AlarmSeverity> { |
24 | 22 |
@@ -15,9 +15,8 @@ | @@ -15,9 +15,8 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.type; | 16 | package org.thingsboard.server.dao.model.type; |
17 | 17 | ||
18 | -import org.thingsboard.server.common.data.security.Authority; | ||
19 | - | ||
20 | import com.datastax.driver.extras.codecs.enums.EnumNameCodec; | 18 | import com.datastax.driver.extras.codecs.enums.EnumNameCodec; |
19 | +import org.thingsboard.server.common.data.security.Authority; | ||
21 | 20 | ||
22 | public class AuthorityCodec extends EnumNameCodec<Authority> { | 21 | public class AuthorityCodec extends EnumNameCodec<Authority> { |
23 | 22 |
@@ -17,7 +17,6 @@ package org.thingsboard.server.dao.model.type; | @@ -17,7 +17,6 @@ package org.thingsboard.server.dao.model.type; | ||
17 | 17 | ||
18 | import com.datastax.driver.extras.codecs.enums.EnumNameCodec; | 18 | import com.datastax.driver.extras.codecs.enums.EnumNameCodec; |
19 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; | 19 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; |
20 | -import org.thingsboard.server.common.data.security.Authority; | ||
21 | 20 | ||
22 | public class ComponentLifecycleStateCodec extends EnumNameCodec<ComponentLifecycleState> { | 21 | public class ComponentLifecycleStateCodec extends EnumNameCodec<ComponentLifecycleState> { |
23 | 22 |
@@ -17,7 +17,6 @@ package org.thingsboard.server.dao.model.type; | @@ -17,7 +17,6 @@ package org.thingsboard.server.dao.model.type; | ||
17 | 17 | ||
18 | import com.datastax.driver.extras.codecs.enums.EnumNameCodec; | 18 | import com.datastax.driver.extras.codecs.enums.EnumNameCodec; |
19 | import org.thingsboard.server.common.data.plugin.ComponentScope; | 19 | import org.thingsboard.server.common.data.plugin.ComponentScope; |
20 | -import org.thingsboard.server.common.data.plugin.ComponentType; | ||
21 | 20 | ||
22 | public class ComponentScopeCodec extends EnumNameCodec<ComponentScope> { | 21 | public class ComponentScopeCodec extends EnumNameCodec<ComponentScope> { |
23 | 22 |
@@ -16,7 +16,6 @@ | @@ -16,7 +16,6 @@ | ||
16 | package org.thingsboard.server.dao.model.type; | 16 | package org.thingsboard.server.dao.model.type; |
17 | 17 | ||
18 | import com.datastax.driver.extras.codecs.enums.EnumNameCodec; | 18 | import com.datastax.driver.extras.codecs.enums.EnumNameCodec; |
19 | -import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; | ||
20 | import org.thingsboard.server.common.data.plugin.ComponentType; | 19 | import org.thingsboard.server.common.data.plugin.ComponentType; |
21 | 20 | ||
22 | public class ComponentTypeCodec extends EnumNameCodec<ComponentType> { | 21 | public class ComponentTypeCodec extends EnumNameCodec<ComponentType> { |
@@ -15,9 +15,8 @@ | @@ -15,9 +15,8 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.type; | 16 | package org.thingsboard.server.dao.model.type; |
17 | 17 | ||
18 | -import org.thingsboard.server.common.data.security.DeviceCredentialsType; | ||
19 | - | ||
20 | import com.datastax.driver.extras.codecs.enums.EnumNameCodec; | 18 | import com.datastax.driver.extras.codecs.enums.EnumNameCodec; |
19 | +import org.thingsboard.server.common.data.security.DeviceCredentialsType; | ||
21 | 20 | ||
22 | public class DeviceCredentialsTypeCodec extends EnumNameCodec<DeviceCredentialsType> { | 21 | public class DeviceCredentialsTypeCodec extends EnumNameCodec<DeviceCredentialsType> { |
23 | 22 |
@@ -17,7 +17,6 @@ package org.thingsboard.server.dao.model.type; | @@ -17,7 +17,6 @@ package org.thingsboard.server.dao.model.type; | ||
17 | 17 | ||
18 | import com.datastax.driver.extras.codecs.enums.EnumNameCodec; | 18 | import com.datastax.driver.extras.codecs.enums.EnumNameCodec; |
19 | import org.thingsboard.server.common.data.EntityType; | 19 | import org.thingsboard.server.common.data.EntityType; |
20 | -import org.thingsboard.server.common.data.plugin.ComponentType; | ||
21 | 20 | ||
22 | public class EntityTypeCodec extends EnumNameCodec<EntityType> { | 21 | public class EntityTypeCodec extends EnumNameCodec<EntityType> { |
23 | 22 |
@@ -15,9 +15,8 @@ | @@ -15,9 +15,8 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.dao.model.type; | 16 | package org.thingsboard.server.dao.model.type; |
17 | 17 | ||
18 | -import org.thingsboard.server.common.data.relation.RelationTypeGroup; | ||
19 | - | ||
20 | import com.datastax.driver.extras.codecs.enums.EnumNameCodec; | 18 | import com.datastax.driver.extras.codecs.enums.EnumNameCodec; |
19 | +import org.thingsboard.server.common.data.relation.RelationTypeGroup; | ||
21 | 20 | ||
22 | public class RelationTypeGroupCodec extends EnumNameCodec<RelationTypeGroup> { | 21 | public class RelationTypeGroupCodec extends EnumNameCodec<RelationTypeGroup> { |
23 | 22 |
@@ -22,11 +22,11 @@ import org.thingsboard.server.common.data.id.PluginId; | @@ -22,11 +22,11 @@ import org.thingsboard.server.common.data.id.PluginId; | ||
22 | import org.thingsboard.server.common.data.id.TenantId; | 22 | import org.thingsboard.server.common.data.id.TenantId; |
23 | import org.thingsboard.server.common.data.page.TextPageLink; | 23 | import org.thingsboard.server.common.data.page.TextPageLink; |
24 | import org.thingsboard.server.common.data.plugin.PluginMetaData; | 24 | import org.thingsboard.server.common.data.plugin.PluginMetaData; |
25 | -import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; | ||
26 | import org.thingsboard.server.dao.DaoUtil; | 25 | import org.thingsboard.server.dao.DaoUtil; |
27 | -import org.thingsboard.server.dao.util.NoSqlDao; | ||
28 | import org.thingsboard.server.dao.model.ModelConstants; | 26 | import org.thingsboard.server.dao.model.ModelConstants; |
29 | import org.thingsboard.server.dao.model.nosql.PluginMetaDataEntity; | 27 | import org.thingsboard.server.dao.model.nosql.PluginMetaDataEntity; |
28 | +import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; | ||
29 | +import org.thingsboard.server.dao.util.NoSqlDao; | ||
30 | 30 | ||
31 | import java.util.Arrays; | 31 | import java.util.Arrays; |
32 | import java.util.List; | 32 | import java.util.List; |
@@ -28,11 +28,11 @@ import org.thingsboard.server.common.data.id.EntityIdFactory; | @@ -28,11 +28,11 @@ import org.thingsboard.server.common.data.id.EntityIdFactory; | ||
28 | import org.thingsboard.server.common.data.page.TimePageLink; | 28 | import org.thingsboard.server.common.data.page.TimePageLink; |
29 | import org.thingsboard.server.common.data.relation.EntityRelation; | 29 | import org.thingsboard.server.common.data.relation.EntityRelation; |
30 | import org.thingsboard.server.common.data.relation.RelationTypeGroup; | 30 | import org.thingsboard.server.common.data.relation.RelationTypeGroup; |
31 | +import org.thingsboard.server.dao.model.ModelConstants; | ||
32 | +import org.thingsboard.server.dao.model.type.RelationTypeGroupCodec; | ||
31 | import org.thingsboard.server.dao.nosql.CassandraAbstractAsyncDao; | 33 | import org.thingsboard.server.dao.nosql.CassandraAbstractAsyncDao; |
32 | import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTimeDao; | 34 | import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTimeDao; |
33 | import org.thingsboard.server.dao.util.NoSqlDao; | 35 | import org.thingsboard.server.dao.util.NoSqlDao; |
34 | -import org.thingsboard.server.dao.model.ModelConstants; | ||
35 | -import org.thingsboard.server.dao.model.type.RelationTypeGroupCodec; | ||
36 | 36 | ||
37 | import javax.annotation.PostConstruct; | 37 | import javax.annotation.PostConstruct; |
38 | import java.util.ArrayList; | 38 | import java.util.ArrayList; |
@@ -22,11 +22,11 @@ import org.thingsboard.server.common.data.id.RuleId; | @@ -22,11 +22,11 @@ import org.thingsboard.server.common.data.id.RuleId; | ||
22 | import org.thingsboard.server.common.data.id.TenantId; | 22 | import org.thingsboard.server.common.data.id.TenantId; |
23 | import org.thingsboard.server.common.data.page.TextPageLink; | 23 | import org.thingsboard.server.common.data.page.TextPageLink; |
24 | import org.thingsboard.server.common.data.rule.RuleMetaData; | 24 | import org.thingsboard.server.common.data.rule.RuleMetaData; |
25 | -import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; | ||
26 | import org.thingsboard.server.dao.DaoUtil; | 25 | import org.thingsboard.server.dao.DaoUtil; |
27 | -import org.thingsboard.server.dao.util.NoSqlDao; | ||
28 | import org.thingsboard.server.dao.model.ModelConstants; | 26 | import org.thingsboard.server.dao.model.ModelConstants; |
29 | import org.thingsboard.server.dao.model.nosql.RuleMetaDataEntity; | 27 | import org.thingsboard.server.dao.model.nosql.RuleMetaDataEntity; |
28 | +import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; | ||
29 | +import org.thingsboard.server.dao.util.NoSqlDao; | ||
30 | 30 | ||
31 | import java.util.Arrays; | 31 | import java.util.Arrays; |
32 | import java.util.List; | 32 | import java.util.List; |
@@ -19,10 +19,10 @@ import com.datastax.driver.core.querybuilder.Select.Where; | @@ -19,10 +19,10 @@ import com.datastax.driver.core.querybuilder.Select.Where; | ||
19 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
20 | import org.springframework.stereotype.Component; | 20 | import org.springframework.stereotype.Component; |
21 | import org.thingsboard.server.common.data.AdminSettings; | 21 | import org.thingsboard.server.common.data.AdminSettings; |
22 | -import org.thingsboard.server.dao.nosql.CassandraAbstractModelDao; | ||
23 | import org.thingsboard.server.dao.DaoUtil; | 22 | import org.thingsboard.server.dao.DaoUtil; |
24 | -import org.thingsboard.server.dao.util.NoSqlDao; | ||
25 | import org.thingsboard.server.dao.model.nosql.AdminSettingsEntity; | 23 | import org.thingsboard.server.dao.model.nosql.AdminSettingsEntity; |
24 | +import org.thingsboard.server.dao.nosql.CassandraAbstractModelDao; | ||
25 | +import org.thingsboard.server.dao.util.NoSqlDao; | ||
26 | 26 | ||
27 | import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | 27 | import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
28 | import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | 28 | import static com.datastax.driver.core.querybuilder.QueryBuilder.select; |
@@ -28,6 +28,8 @@ import org.thingsboard.server.dao.model.BaseEntity; | @@ -28,6 +28,8 @@ import org.thingsboard.server.dao.model.BaseEntity; | ||
28 | import java.util.List; | 28 | import java.util.List; |
29 | import java.util.UUID; | 29 | import java.util.UUID; |
30 | 30 | ||
31 | +import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID; | ||
32 | + | ||
31 | /** | 33 | /** |
32 | * @author Valerii Sosliuk | 34 | * @author Valerii Sosliuk |
33 | */ | 35 | */ |
@@ -38,7 +40,7 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> | @@ -38,7 +40,7 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> | ||
38 | 40 | ||
39 | protected abstract Class<E> getEntityClass(); | 41 | protected abstract Class<E> getEntityClass(); |
40 | 42 | ||
41 | - protected abstract CrudRepository<E, UUID> getCrudRepository(); | 43 | + protected abstract CrudRepository<E, String> getCrudRepository(); |
42 | 44 | ||
43 | protected void setSearchText(E entity) {} | 45 | protected void setSearchText(E entity) {} |
44 | 46 | ||
@@ -64,19 +66,20 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> | @@ -64,19 +66,20 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> | ||
64 | @Override | 66 | @Override |
65 | public D findById(UUID key) { | 67 | public D findById(UUID key) { |
66 | log.debug("Get entity by key {}", key); | 68 | log.debug("Get entity by key {}", key); |
67 | - E entity = getCrudRepository().findOne(key); | 69 | + E entity = getCrudRepository().findOne(fromTimeUUID(key)); |
68 | return DaoUtil.getData(entity); | 70 | return DaoUtil.getData(entity); |
69 | } | 71 | } |
70 | 72 | ||
71 | @Override | 73 | @Override |
72 | public ListenableFuture<D> findByIdAsync(UUID key) { | 74 | public ListenableFuture<D> findByIdAsync(UUID key) { |
73 | log.debug("Get entity by key async {}", key); | 75 | log.debug("Get entity by key async {}", key); |
74 | - return service.submit(() -> DaoUtil.getData(getCrudRepository().findOne(key))); | 76 | + return service.submit(() -> DaoUtil.getData(getCrudRepository().findOne(fromTimeUUID(key)))); |
75 | } | 77 | } |
76 | 78 | ||
77 | @Override | 79 | @Override |
78 | @Transactional | 80 | @Transactional |
79 | - public boolean removeById(UUID key) { | 81 | + public boolean removeById(UUID id) { |
82 | + String key = fromTimeUUID(id); | ||
80 | getCrudRepository().delete(key); | 83 | getCrudRepository().delete(key); |
81 | log.debug("Remove request: {}", key); | 84 | log.debug("Remove request: {}", key); |
82 | return getCrudRepository().findOne(key) == null; | 85 | return getCrudRepository().findOne(key) == null; |
@@ -17,9 +17,9 @@ package org.thingsboard.server.dao.sql; | @@ -17,9 +17,9 @@ package org.thingsboard.server.dao.sql; | ||
17 | 17 | ||
18 | import com.datastax.driver.core.utils.UUIDs; | 18 | import com.datastax.driver.core.utils.UUIDs; |
19 | import org.springframework.data.jpa.domain.Specification; | 19 | import org.springframework.data.jpa.domain.Specification; |
20 | +import org.thingsboard.server.common.data.UUIDConverter; | ||
20 | import org.thingsboard.server.common.data.page.TimePageLink; | 21 | import org.thingsboard.server.common.data.page.TimePageLink; |
21 | import org.thingsboard.server.dao.model.BaseEntity; | 22 | import org.thingsboard.server.dao.model.BaseEntity; |
22 | -import static org.thingsboard.server.dao.model.ModelConstants.*; | ||
23 | 23 | ||
24 | import javax.persistence.criteria.CriteriaBuilder; | 24 | import javax.persistence.criteria.CriteriaBuilder; |
25 | import javax.persistence.criteria.CriteriaQuery; | 25 | import javax.persistence.criteria.CriteriaQuery; |
@@ -41,30 +41,30 @@ public abstract class JpaAbstractSearchTimeDao<E extends BaseEntity<D>, D> exten | @@ -41,30 +41,30 @@ public abstract class JpaAbstractSearchTimeDao<E extends BaseEntity<D>, D> exten | ||
41 | List<Predicate> predicates = new ArrayList<>(); | 41 | List<Predicate> predicates = new ArrayList<>(); |
42 | if (pageLink.isAscOrder()) { | 42 | if (pageLink.isAscOrder()) { |
43 | if (pageLink.getIdOffset() != null) { | 43 | if (pageLink.getIdOffset() != null) { |
44 | - Predicate lowerBound = criteriaBuilder.greaterThan(root.get(idColumn), pageLink.getIdOffset()); | 44 | + Predicate lowerBound = criteriaBuilder.greaterThan(root.get(idColumn), UUIDConverter.fromTimeUUID(pageLink.getIdOffset())); |
45 | predicates.add(lowerBound); | 45 | predicates.add(lowerBound); |
46 | } else if (pageLink.getStartTime() != null) { | 46 | } else if (pageLink.getStartTime() != null) { |
47 | UUID startOf = UUIDs.startOf(pageLink.getStartTime()); | 47 | UUID startOf = UUIDs.startOf(pageLink.getStartTime()); |
48 | - Predicate lowerBound = criteriaBuilder.greaterThanOrEqualTo(root.get(idColumn), startOf); | 48 | + Predicate lowerBound = criteriaBuilder.greaterThanOrEqualTo(root.get(idColumn), UUIDConverter.fromTimeUUID(startOf)); |
49 | predicates.add(lowerBound); | 49 | predicates.add(lowerBound); |
50 | } | 50 | } |
51 | if (pageLink.getEndTime() != null) { | 51 | if (pageLink.getEndTime() != null) { |
52 | UUID endOf = UUIDs.endOf(pageLink.getEndTime()); | 52 | UUID endOf = UUIDs.endOf(pageLink.getEndTime()); |
53 | - Predicate upperBound = criteriaBuilder.lessThanOrEqualTo(root.get(idColumn), endOf); | 53 | + Predicate upperBound = criteriaBuilder.lessThanOrEqualTo(root.get(idColumn), UUIDConverter.fromTimeUUID(endOf)); |
54 | predicates.add(upperBound); | 54 | predicates.add(upperBound); |
55 | } | 55 | } |
56 | } else { | 56 | } else { |
57 | if (pageLink.getIdOffset() != null) { | 57 | if (pageLink.getIdOffset() != null) { |
58 | - Predicate lowerBound = criteriaBuilder.lessThan(root.get(idColumn), pageLink.getIdOffset()); | 58 | + Predicate lowerBound = criteriaBuilder.lessThan(root.get(idColumn), UUIDConverter.fromTimeUUID(pageLink.getIdOffset())); |
59 | predicates.add(lowerBound); | 59 | predicates.add(lowerBound); |
60 | } else if (pageLink.getEndTime() != null) { | 60 | } else if (pageLink.getEndTime() != null) { |
61 | UUID endOf = UUIDs.endOf(pageLink.getEndTime()); | 61 | UUID endOf = UUIDs.endOf(pageLink.getEndTime()); |
62 | - Predicate lowerBound = criteriaBuilder.lessThanOrEqualTo(root.get(idColumn), endOf); | 62 | + Predicate lowerBound = criteriaBuilder.lessThanOrEqualTo(root.get(idColumn), UUIDConverter.fromTimeUUID(endOf)); |
63 | predicates.add(lowerBound); | 63 | predicates.add(lowerBound); |
64 | } | 64 | } |
65 | if (pageLink.getStartTime() != null) { | 65 | if (pageLink.getStartTime() != null) { |
66 | UUID startOf = UUIDs.startOf(pageLink.getStartTime()); | 66 | UUID startOf = UUIDs.startOf(pageLink.getStartTime()); |
67 | - Predicate upperBound = criteriaBuilder.greaterThanOrEqualTo(root.get(idColumn), startOf); | 67 | + Predicate upperBound = criteriaBuilder.greaterThanOrEqualTo(root.get(idColumn), UUIDConverter.fromTimeUUID(startOf)); |
68 | predicates.add(upperBound); | 68 | predicates.add(upperBound); |
69 | } | 69 | } |
70 | } | 70 | } |
@@ -20,22 +20,21 @@ import org.springframework.data.jpa.repository.Query; | @@ -20,22 +20,21 @@ import org.springframework.data.jpa.repository.Query; | ||
20 | import org.springframework.data.repository.CrudRepository; | 20 | import org.springframework.data.repository.CrudRepository; |
21 | import org.springframework.data.repository.query.Param; | 21 | import org.springframework.data.repository.query.Param; |
22 | import org.thingsboard.server.common.data.EntityType; | 22 | import org.thingsboard.server.common.data.EntityType; |
23 | -import org.thingsboard.server.dao.util.SqlDao; | ||
24 | import org.thingsboard.server.dao.model.sql.AlarmEntity; | 23 | import org.thingsboard.server.dao.model.sql.AlarmEntity; |
24 | +import org.thingsboard.server.dao.util.SqlDao; | ||
25 | 25 | ||
26 | import java.util.List; | 26 | import java.util.List; |
27 | -import java.util.UUID; | ||
28 | 27 | ||
29 | /** | 28 | /** |
30 | * Created by Valerii Sosliuk on 5/21/2017. | 29 | * Created by Valerii Sosliuk on 5/21/2017. |
31 | */ | 30 | */ |
32 | @SqlDao | 31 | @SqlDao |
33 | -public interface AlarmRepository extends CrudRepository<AlarmEntity, UUID> { | 32 | +public interface AlarmRepository extends CrudRepository<AlarmEntity, String> { |
34 | 33 | ||
35 | @Query("SELECT a FROM AlarmEntity a WHERE a.tenantId = :tenantId AND a.originatorId = :originatorId " + | 34 | @Query("SELECT a FROM AlarmEntity a WHERE a.tenantId = :tenantId AND a.originatorId = :originatorId " + |
36 | "AND a.originatorType = :entityType AND a.type = :alarmType ORDER BY a.type ASC, a.id DESC") | 35 | "AND a.originatorType = :entityType AND a.type = :alarmType ORDER BY a.type ASC, a.id DESC") |
37 | - List<AlarmEntity> findLatestByOriginatorAndType(@Param("tenantId") UUID tenantId, | ||
38 | - @Param("originatorId") UUID originatorId, | 36 | + List<AlarmEntity> findLatestByOriginatorAndType(@Param("tenantId") String tenantId, |
37 | + @Param("originatorId") String originatorId, | ||
39 | @Param("entityType") EntityType entityType, | 38 | @Param("entityType") EntityType entityType, |
40 | @Param("alarmType") String alarmType, | 39 | @Param("alarmType") String alarmType, |
41 | Pageable pageable); | 40 | Pageable pageable); |
@@ -24,8 +24,8 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -24,8 +24,8 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
24 | import org.springframework.data.domain.PageRequest; | 24 | import org.springframework.data.domain.PageRequest; |
25 | import org.springframework.data.repository.CrudRepository; | 25 | import org.springframework.data.repository.CrudRepository; |
26 | import org.springframework.stereotype.Component; | 26 | import org.springframework.stereotype.Component; |
27 | -import org.springframework.transaction.annotation.Transactional; | ||
28 | import org.thingsboard.server.common.data.EntityType; | 27 | import org.thingsboard.server.common.data.EntityType; |
28 | +import org.thingsboard.server.common.data.UUIDConverter; | ||
29 | import org.thingsboard.server.common.data.alarm.Alarm; | 29 | import org.thingsboard.server.common.data.alarm.Alarm; |
30 | import org.thingsboard.server.common.data.alarm.AlarmInfo; | 30 | import org.thingsboard.server.common.data.alarm.AlarmInfo; |
31 | import org.thingsboard.server.common.data.alarm.AlarmQuery; | 31 | import org.thingsboard.server.common.data.alarm.AlarmQuery; |
@@ -37,17 +37,15 @@ import org.thingsboard.server.common.data.relation.RelationTypeGroup; | @@ -37,17 +37,15 @@ import org.thingsboard.server.common.data.relation.RelationTypeGroup; | ||
37 | import org.thingsboard.server.dao.DaoUtil; | 37 | import org.thingsboard.server.dao.DaoUtil; |
38 | import org.thingsboard.server.dao.alarm.AlarmDao; | 38 | import org.thingsboard.server.dao.alarm.AlarmDao; |
39 | import org.thingsboard.server.dao.alarm.BaseAlarmService; | 39 | import org.thingsboard.server.dao.alarm.BaseAlarmService; |
40 | -import org.thingsboard.server.dao.util.SqlDao; | ||
41 | import org.thingsboard.server.dao.model.sql.AlarmEntity; | 40 | import org.thingsboard.server.dao.model.sql.AlarmEntity; |
42 | import org.thingsboard.server.dao.relation.RelationDao; | 41 | import org.thingsboard.server.dao.relation.RelationDao; |
43 | import org.thingsboard.server.dao.sql.JpaAbstractDao; | 42 | import org.thingsboard.server.dao.sql.JpaAbstractDao; |
43 | +import org.thingsboard.server.dao.util.SqlDao; | ||
44 | 44 | ||
45 | import java.util.ArrayList; | 45 | import java.util.ArrayList; |
46 | import java.util.List; | 46 | import java.util.List; |
47 | import java.util.UUID; | 47 | import java.util.UUID; |
48 | 48 | ||
49 | -import static org.springframework.transaction.annotation.Propagation.REQUIRES_NEW; | ||
50 | - | ||
51 | /** | 49 | /** |
52 | * Created by Valerii Sosliuk on 5/19/2017. | 50 | * Created by Valerii Sosliuk on 5/19/2017. |
53 | */ | 51 | */ |
@@ -68,7 +66,7 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A | @@ -68,7 +66,7 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A | ||
68 | } | 66 | } |
69 | 67 | ||
70 | @Override | 68 | @Override |
71 | - protected CrudRepository<AlarmEntity, UUID> getCrudRepository() { | 69 | + protected CrudRepository<AlarmEntity, String> getCrudRepository() { |
72 | return alarmRepository; | 70 | return alarmRepository; |
73 | } | 71 | } |
74 | 72 | ||
@@ -76,8 +74,8 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A | @@ -76,8 +74,8 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A | ||
76 | public ListenableFuture<Alarm> findLatestByOriginatorAndType(TenantId tenantId, EntityId originator, String type) { | 74 | public ListenableFuture<Alarm> findLatestByOriginatorAndType(TenantId tenantId, EntityId originator, String type) { |
77 | return service.submit(() -> { | 75 | return service.submit(() -> { |
78 | List<AlarmEntity> latest = alarmRepository.findLatestByOriginatorAndType( | 76 | List<AlarmEntity> latest = alarmRepository.findLatestByOriginatorAndType( |
79 | - tenantId.getId(), | ||
80 | - originator.getId(), | 77 | + UUIDConverter.fromTimeUUID(tenantId.getId()), |
78 | + UUIDConverter.fromTimeUUID(originator.getId()), | ||
81 | originator.getEntityType(), | 79 | originator.getEntityType(), |
82 | type, | 80 | type, |
83 | new PageRequest(0, 1)); | 81 | new PageRequest(0, 1)); |
@@ -24,57 +24,56 @@ import org.thingsboard.server.dao.model.sql.AssetEntity; | @@ -24,57 +24,56 @@ import org.thingsboard.server.dao.model.sql.AssetEntity; | ||
24 | import org.thingsboard.server.dao.util.SqlDao; | 24 | import org.thingsboard.server.dao.util.SqlDao; |
25 | 25 | ||
26 | import java.util.List; | 26 | import java.util.List; |
27 | -import java.util.UUID; | ||
28 | 27 | ||
29 | /** | 28 | /** |
30 | * Created by Valerii Sosliuk on 5/21/2017. | 29 | * Created by Valerii Sosliuk on 5/21/2017. |
31 | */ | 30 | */ |
32 | @SqlDao | 31 | @SqlDao |
33 | -public interface AssetRepository extends CrudRepository<AssetEntity, UUID> { | 32 | +public interface AssetRepository extends CrudRepository<AssetEntity, String> { |
34 | 33 | ||
35 | @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " + | 34 | @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " + |
36 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " + | 35 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " + |
37 | "AND a.id > :idOffset ORDER BY a.id") | 36 | "AND a.id > :idOffset ORDER BY a.id") |
38 | - List<AssetEntity> findByTenantId(@Param("tenantId") UUID tenantId, | 37 | + List<AssetEntity> findByTenantId(@Param("tenantId") String tenantId, |
39 | @Param("textSearch") String textSearch, | 38 | @Param("textSearch") String textSearch, |
40 | - @Param("idOffset") UUID idOffset, | 39 | + @Param("idOffset") String idOffset, |
41 | Pageable pageable); | 40 | Pageable pageable); |
42 | 41 | ||
43 | @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " + | 42 | @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " + |
44 | "AND a.customerId = :customerId " + | 43 | "AND a.customerId = :customerId " + |
45 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " + | 44 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " + |
46 | "AND a.id > :idOffset ORDER BY a.id") | 45 | "AND a.id > :idOffset ORDER BY a.id") |
47 | - List<AssetEntity> findByTenantIdAndCustomerId(@Param("tenantId") UUID tenantId, | ||
48 | - @Param("customerId") UUID customerId, | 46 | + List<AssetEntity> findByTenantIdAndCustomerId(@Param("tenantId") String tenantId, |
47 | + @Param("customerId") String customerId, | ||
49 | @Param("textSearch") String textSearch, | 48 | @Param("textSearch") String textSearch, |
50 | - @Param("idOffset") UUID idOffset, | 49 | + @Param("idOffset") String idOffset, |
51 | Pageable pageable); | 50 | Pageable pageable); |
52 | 51 | ||
53 | - List<AssetEntity> findByTenantIdAndIdIn(UUID tenantId, List<UUID> assetIds); | 52 | + List<AssetEntity> findByTenantIdAndIdIn(String tenantId, List<String> assetIds); |
54 | 53 | ||
55 | - List<AssetEntity> findByTenantIdAndCustomerIdAndIdIn(UUID tenantId, UUID customerId, List<UUID> assetIds); | 54 | + List<AssetEntity> findByTenantIdAndCustomerIdAndIdIn(String tenantId, String customerId, List<String> assetIds); |
56 | 55 | ||
57 | - AssetEntity findByTenantIdAndName(UUID tenantId, String name); | 56 | + AssetEntity findByTenantIdAndName(String tenantId, String name); |
58 | 57 | ||
59 | @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " + | 58 | @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " + |
60 | "AND a.type = :type " + | 59 | "AND a.type = :type " + |
61 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " + | 60 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " + |
62 | "AND a.id > :idOffset ORDER BY a.id") | 61 | "AND a.id > :idOffset ORDER BY a.id") |
63 | - List<AssetEntity> findByTenantIdAndType(@Param("tenantId") UUID tenantId, | 62 | + List<AssetEntity> findByTenantIdAndType(@Param("tenantId") String tenantId, |
64 | @Param("type") String type, | 63 | @Param("type") String type, |
65 | @Param("textSearch") String textSearch, | 64 | @Param("textSearch") String textSearch, |
66 | - @Param("idOffset") UUID idOffset, | 65 | + @Param("idOffset") String idOffset, |
67 | Pageable pageable); | 66 | Pageable pageable); |
68 | 67 | ||
69 | @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " + | 68 | @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " + |
70 | "AND a.customerId = :customerId AND a.type = :type " + | 69 | "AND a.customerId = :customerId AND a.type = :type " + |
71 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " + | 70 | "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " + |
72 | "AND a.id > :idOffset ORDER BY a.id") | 71 | "AND a.id > :idOffset ORDER BY a.id") |
73 | - List<AssetEntity> findByTenantIdAndCustomerIdAndType(@Param("tenantId") UUID tenantId, | ||
74 | - @Param("customerId") UUID customerId, | 72 | + List<AssetEntity> findByTenantIdAndCustomerIdAndType(@Param("tenantId") String tenantId, |
73 | + @Param("customerId") String customerId, | ||
75 | @Param("type") String type, | 74 | @Param("type") String type, |
76 | @Param("textSearch") String textSearch, | 75 | @Param("textSearch") String textSearch, |
77 | - @Param("idOffset") UUID idOffset, | 76 | + @Param("idOffset") String idOffset, |
78 | Pageable pageable); | 77 | Pageable pageable); |
79 | 78 | ||
80 | @Query("SELECT NEW org.thingsboard.server.common.data.asset.TenantAssetType(a.type, a.tenantId) FROM AssetEntity a GROUP BY a.tenantId, a.type") | 79 | @Query("SELECT NEW org.thingsboard.server.common.data.asset.TenantAssetType(a.type, a.tenantId) FROM AssetEntity a GROUP BY a.tenantId, a.type") |
@@ -24,17 +24,19 @@ import org.thingsboard.server.common.data.asset.Asset; | @@ -24,17 +24,19 @@ import org.thingsboard.server.common.data.asset.Asset; | ||
24 | import org.thingsboard.server.common.data.asset.TenantAssetType; | 24 | import org.thingsboard.server.common.data.asset.TenantAssetType; |
25 | import org.thingsboard.server.common.data.page.TextPageLink; | 25 | import org.thingsboard.server.common.data.page.TextPageLink; |
26 | import org.thingsboard.server.dao.DaoUtil; | 26 | import org.thingsboard.server.dao.DaoUtil; |
27 | -import org.thingsboard.server.dao.util.SqlDao; | ||
28 | import org.thingsboard.server.dao.asset.AssetDao; | 27 | import org.thingsboard.server.dao.asset.AssetDao; |
29 | import org.thingsboard.server.dao.model.sql.AssetEntity; | 28 | import org.thingsboard.server.dao.model.sql.AssetEntity; |
30 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; | 29 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
30 | +import org.thingsboard.server.dao.util.SqlDao; | ||
31 | 31 | ||
32 | import java.util.List; | 32 | import java.util.List; |
33 | import java.util.Objects; | 33 | import java.util.Objects; |
34 | import java.util.Optional; | 34 | import java.util.Optional; |
35 | import java.util.UUID; | 35 | import java.util.UUID; |
36 | 36 | ||
37 | -import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; | 37 | +import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID; |
38 | +import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUIDs; | ||
39 | +import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID_STR; | ||
38 | 40 | ||
39 | /** | 41 | /** |
40 | * Created by Valerii Sosliuk on 5/19/2017. | 42 | * Created by Valerii Sosliuk on 5/19/2017. |
@@ -52,7 +54,7 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | @@ -52,7 +54,7 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | ||
52 | } | 54 | } |
53 | 55 | ||
54 | @Override | 56 | @Override |
55 | - protected CrudRepository<AssetEntity, UUID> getCrudRepository() { | 57 | + protected CrudRepository<AssetEntity, String> getCrudRepository() { |
56 | return assetRepository; | 58 | return assetRepository; |
57 | } | 59 | } |
58 | 60 | ||
@@ -60,38 +62,38 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | @@ -60,38 +62,38 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | ||
60 | public List<Asset> findAssetsByTenantId(UUID tenantId, TextPageLink pageLink) { | 62 | public List<Asset> findAssetsByTenantId(UUID tenantId, TextPageLink pageLink) { |
61 | return DaoUtil.convertDataList(assetRepository | 63 | return DaoUtil.convertDataList(assetRepository |
62 | .findByTenantId( | 64 | .findByTenantId( |
63 | - tenantId, | 65 | + fromTimeUUID(tenantId), |
64 | Objects.toString(pageLink.getTextSearch(), ""), | 66 | Objects.toString(pageLink.getTextSearch(), ""), |
65 | - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(), | 67 | + pageLink.getIdOffset() == null ? NULL_UUID_STR : fromTimeUUID(pageLink.getIdOffset()), |
66 | new PageRequest(0, pageLink.getLimit()))); | 68 | new PageRequest(0, pageLink.getLimit()))); |
67 | } | 69 | } |
68 | 70 | ||
69 | @Override | 71 | @Override |
70 | public ListenableFuture<List<Asset>> findAssetsByTenantIdAndIdsAsync(UUID tenantId, List<UUID> assetIds) { | 72 | public ListenableFuture<List<Asset>> findAssetsByTenantIdAndIdsAsync(UUID tenantId, List<UUID> assetIds) { |
71 | return service.submit(() -> | 73 | return service.submit(() -> |
72 | - DaoUtil.convertDataList(assetRepository.findByTenantIdAndIdIn(tenantId, assetIds))); | 74 | + DaoUtil.convertDataList(assetRepository.findByTenantIdAndIdIn(fromTimeUUID(tenantId), fromTimeUUIDs(assetIds)))); |
73 | } | 75 | } |
74 | 76 | ||
75 | @Override | 77 | @Override |
76 | public List<Asset> findAssetsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) { | 78 | public List<Asset> findAssetsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) { |
77 | return DaoUtil.convertDataList(assetRepository | 79 | return DaoUtil.convertDataList(assetRepository |
78 | .findByTenantIdAndCustomerId( | 80 | .findByTenantIdAndCustomerId( |
79 | - tenantId, | ||
80 | - customerId, | 81 | + fromTimeUUID(tenantId), |
82 | + fromTimeUUID(customerId), | ||
81 | Objects.toString(pageLink.getTextSearch(), ""), | 83 | Objects.toString(pageLink.getTextSearch(), ""), |
82 | - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(), | 84 | + pageLink.getIdOffset() == null ? NULL_UUID_STR : fromTimeUUID(pageLink.getIdOffset()), |
83 | new PageRequest(0, pageLink.getLimit()))); | 85 | new PageRequest(0, pageLink.getLimit()))); |
84 | } | 86 | } |
85 | 87 | ||
86 | @Override | 88 | @Override |
87 | public ListenableFuture<List<Asset>> findAssetsByTenantIdAndCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> assetIds) { | 89 | public ListenableFuture<List<Asset>> findAssetsByTenantIdAndCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> assetIds) { |
88 | return service.submit(() -> | 90 | return service.submit(() -> |
89 | - DaoUtil.convertDataList(assetRepository.findByTenantIdAndCustomerIdAndIdIn(tenantId, customerId, assetIds))); | 91 | + DaoUtil.convertDataList(assetRepository.findByTenantIdAndCustomerIdAndIdIn(fromTimeUUID(tenantId), fromTimeUUID(customerId), fromTimeUUIDs(assetIds)))); |
90 | } | 92 | } |
91 | 93 | ||
92 | @Override | 94 | @Override |
93 | public Optional<Asset> findAssetsByTenantIdAndName(UUID tenantId, String name) { | 95 | public Optional<Asset> findAssetsByTenantIdAndName(UUID tenantId, String name) { |
94 | - Asset asset = DaoUtil.getData(assetRepository.findByTenantIdAndName(tenantId, name)); | 96 | + Asset asset = DaoUtil.getData(assetRepository.findByTenantIdAndName(fromTimeUUID(tenantId), name)); |
95 | return Optional.ofNullable(asset); | 97 | return Optional.ofNullable(asset); |
96 | } | 98 | } |
97 | 99 | ||
@@ -99,10 +101,10 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | @@ -99,10 +101,10 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | ||
99 | public List<Asset> findAssetsByTenantIdAndType(UUID tenantId, String type, TextPageLink pageLink) { | 101 | public List<Asset> findAssetsByTenantIdAndType(UUID tenantId, String type, TextPageLink pageLink) { |
100 | return DaoUtil.convertDataList(assetRepository | 102 | return DaoUtil.convertDataList(assetRepository |
101 | .findByTenantIdAndType( | 103 | .findByTenantIdAndType( |
102 | - tenantId, | 104 | + fromTimeUUID(tenantId), |
103 | type, | 105 | type, |
104 | Objects.toString(pageLink.getTextSearch(), ""), | 106 | Objects.toString(pageLink.getTextSearch(), ""), |
105 | - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(), | 107 | + pageLink.getIdOffset() == null ? NULL_UUID_STR : fromTimeUUID(pageLink.getIdOffset()), |
106 | new PageRequest(0, pageLink.getLimit()))); | 108 | new PageRequest(0, pageLink.getLimit()))); |
107 | } | 109 | } |
108 | 110 | ||
@@ -110,11 +112,11 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | @@ -110,11 +112,11 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | ||
110 | public List<Asset> findAssetsByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, TextPageLink pageLink) { | 112 | public List<Asset> findAssetsByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, TextPageLink pageLink) { |
111 | return DaoUtil.convertDataList(assetRepository | 113 | return DaoUtil.convertDataList(assetRepository |
112 | .findByTenantIdAndCustomerIdAndType( | 114 | .findByTenantIdAndCustomerIdAndType( |
113 | - tenantId, | ||
114 | - customerId, | 115 | + fromTimeUUID(tenantId), |
116 | + fromTimeUUID(customerId), | ||
115 | type, | 117 | type, |
116 | Objects.toString(pageLink.getTextSearch(), ""), | 118 | Objects.toString(pageLink.getTextSearch(), ""), |
117 | - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(), | 119 | + pageLink.getIdOffset() == null ? NULL_UUID_STR : fromTimeUUID(pageLink.getIdOffset()), |
118 | new PageRequest(0, pageLink.getLimit()))); | 120 | new PageRequest(0, pageLink.getLimit()))); |
119 | } | 121 | } |
120 | 122 |
@@ -17,18 +17,17 @@ package org.thingsboard.server.dao.sql.attributes; | @@ -17,18 +17,17 @@ package org.thingsboard.server.dao.sql.attributes; | ||
17 | 17 | ||
18 | import org.springframework.data.repository.CrudRepository; | 18 | import org.springframework.data.repository.CrudRepository; |
19 | import org.thingsboard.server.common.data.EntityType; | 19 | import org.thingsboard.server.common.data.EntityType; |
20 | -import org.thingsboard.server.dao.util.SqlDao; | ||
21 | import org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey; | 20 | import org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey; |
22 | import org.thingsboard.server.dao.model.sql.AttributeKvEntity; | 21 | import org.thingsboard.server.dao.model.sql.AttributeKvEntity; |
22 | +import org.thingsboard.server.dao.util.SqlDao; | ||
23 | 23 | ||
24 | import java.util.List; | 24 | import java.util.List; |
25 | -import java.util.UUID; | ||
26 | 25 | ||
27 | @SqlDao | 26 | @SqlDao |
28 | public interface AttributeKvRepository extends CrudRepository<AttributeKvEntity, AttributeKvCompositeKey> { | 27 | public interface AttributeKvRepository extends CrudRepository<AttributeKvEntity, AttributeKvCompositeKey> { |
29 | 28 | ||
30 | List<AttributeKvEntity> findAllByEntityTypeAndEntityIdAndAttributeType(EntityType entityType, | 29 | List<AttributeKvEntity> findAllByEntityTypeAndEntityIdAndAttributeType(EntityType entityType, |
31 | - UUID entityId, | 30 | + String entityId, |
32 | String attributeType); | 31 | String attributeType); |
33 | } | 32 | } |
34 | 33 |
@@ -20,20 +20,23 @@ import com.google.common.util.concurrent.ListenableFuture; | @@ -20,20 +20,23 @@ import com.google.common.util.concurrent.ListenableFuture; | ||
20 | import lombok.extern.slf4j.Slf4j; | 20 | import lombok.extern.slf4j.Slf4j; |
21 | import org.springframework.beans.factory.annotation.Autowired; | 21 | import org.springframework.beans.factory.annotation.Autowired; |
22 | import org.springframework.stereotype.Component; | 22 | import org.springframework.stereotype.Component; |
23 | +import org.thingsboard.server.common.data.UUIDConverter; | ||
23 | import org.thingsboard.server.common.data.id.EntityId; | 24 | import org.thingsboard.server.common.data.id.EntityId; |
24 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; | 25 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
25 | import org.thingsboard.server.dao.DaoUtil; | 26 | import org.thingsboard.server.dao.DaoUtil; |
26 | -import org.thingsboard.server.dao.util.SqlDao; | ||
27 | import org.thingsboard.server.dao.attributes.AttributesDao; | 27 | import org.thingsboard.server.dao.attributes.AttributesDao; |
28 | import org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey; | 28 | import org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey; |
29 | import org.thingsboard.server.dao.model.sql.AttributeKvEntity; | 29 | import org.thingsboard.server.dao.model.sql.AttributeKvEntity; |
30 | import org.thingsboard.server.dao.sql.JpaAbstractDaoListeningExecutorService; | 30 | import org.thingsboard.server.dao.sql.JpaAbstractDaoListeningExecutorService; |
31 | +import org.thingsboard.server.dao.util.SqlDao; | ||
31 | 32 | ||
32 | import java.util.Collection; | 33 | import java.util.Collection; |
33 | import java.util.List; | 34 | import java.util.List; |
34 | import java.util.Optional; | 35 | import java.util.Optional; |
35 | import java.util.stream.Collectors; | 36 | import java.util.stream.Collectors; |
36 | 37 | ||
38 | +import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID; | ||
39 | + | ||
37 | @Component | 40 | @Component |
38 | @Slf4j | 41 | @Slf4j |
39 | @SqlDao | 42 | @SqlDao |
@@ -45,11 +48,7 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl | @@ -45,11 +48,7 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl | ||
45 | @Override | 48 | @Override |
46 | public ListenableFuture<Optional<AttributeKvEntry>> find(EntityId entityId, String attributeType, String attributeKey) { | 49 | public ListenableFuture<Optional<AttributeKvEntry>> find(EntityId entityId, String attributeType, String attributeKey) { |
47 | AttributeKvCompositeKey compositeKey = | 50 | AttributeKvCompositeKey compositeKey = |
48 | - new AttributeKvCompositeKey( | ||
49 | - entityId.getEntityType(), | ||
50 | - entityId.getId(), | ||
51 | - attributeType, | ||
52 | - attributeKey); | 51 | + getAttributeKvCompositeKey(entityId, attributeType, attributeKey); |
53 | return service.submit(() -> | 52 | return service.submit(() -> |
54 | Optional.of(DaoUtil.getData(attributeKvRepository.findOne(compositeKey)))); | 53 | Optional.of(DaoUtil.getData(attributeKvRepository.findOne(compositeKey)))); |
55 | } | 54 | } |
@@ -60,11 +59,7 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl | @@ -60,11 +59,7 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl | ||
60 | attributeKeys | 59 | attributeKeys |
61 | .stream() | 60 | .stream() |
62 | .map(attributeKey -> | 61 | .map(attributeKey -> |
63 | - new AttributeKvCompositeKey( | ||
64 | - entityId.getEntityType(), | ||
65 | - entityId.getId(), | ||
66 | - attributeType, | ||
67 | - attributeKey)) | 62 | + getAttributeKvCompositeKey(entityId, attributeType, attributeKey)) |
68 | .collect(Collectors.toList()); | 63 | .collect(Collectors.toList()); |
69 | return service.submit(() -> | 64 | return service.submit(() -> |
70 | DaoUtil.convertDataList(Lists.newArrayList(attributeKvRepository.findAll(compositeKeys)))); | 65 | DaoUtil.convertDataList(Lists.newArrayList(attributeKvRepository.findAll(compositeKeys)))); |
@@ -76,7 +71,7 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl | @@ -76,7 +71,7 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl | ||
76 | DaoUtil.convertDataList(Lists.newArrayList( | 71 | DaoUtil.convertDataList(Lists.newArrayList( |
77 | attributeKvRepository.findAllByEntityTypeAndEntityIdAndAttributeType( | 72 | attributeKvRepository.findAllByEntityTypeAndEntityIdAndAttributeType( |
78 | entityId.getEntityType(), | 73 | entityId.getEntityType(), |
79 | - entityId.getId(), | 74 | + UUIDConverter.fromTimeUUID(entityId.getId()), |
80 | attributeType)))); | 75 | attributeType)))); |
81 | } | 76 | } |
82 | 77 | ||
@@ -84,7 +79,7 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl | @@ -84,7 +79,7 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl | ||
84 | public ListenableFuture<Void> save(EntityId entityId, String attributeType, AttributeKvEntry attribute) { | 79 | public ListenableFuture<Void> save(EntityId entityId, String attributeType, AttributeKvEntry attribute) { |
85 | AttributeKvEntity entity = new AttributeKvEntity(); | 80 | AttributeKvEntity entity = new AttributeKvEntity(); |
86 | entity.setEntityType(entityId.getEntityType()); | 81 | entity.setEntityType(entityId.getEntityType()); |
87 | - entity.setEntityId(entityId.getId()); | 82 | + entity.setEntityId(fromTimeUUID(entityId.getId())); |
88 | entity.setAttributeType(attributeType); | 83 | entity.setAttributeType(attributeType); |
89 | entity.setAttributeKey(attribute.getKey()); | 84 | entity.setAttributeKey(attribute.getKey()); |
90 | entity.setLastUpdateTs(attribute.getLastUpdateTs()); | 85 | entity.setLastUpdateTs(attribute.getLastUpdateTs()); |
@@ -105,7 +100,7 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl | @@ -105,7 +100,7 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl | ||
105 | .map(key -> { | 100 | .map(key -> { |
106 | AttributeKvEntity entityToDelete = new AttributeKvEntity(); | 101 | AttributeKvEntity entityToDelete = new AttributeKvEntity(); |
107 | entityToDelete.setEntityType(entityId.getEntityType()); | 102 | entityToDelete.setEntityType(entityId.getEntityType()); |
108 | - entityToDelete.setEntityId(entityId.getId()); | 103 | + entityToDelete.setEntityId(fromTimeUUID(entityId.getId())); |
109 | entityToDelete.setAttributeType(attributeType); | 104 | entityToDelete.setAttributeType(attributeType); |
110 | entityToDelete.setAttributeKey(key); | 105 | entityToDelete.setAttributeKey(key); |
111 | return entityToDelete; | 106 | return entityToDelete; |
@@ -116,4 +111,12 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl | @@ -116,4 +111,12 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl | ||
116 | return null; | 111 | return null; |
117 | }); | 112 | }); |
118 | } | 113 | } |
114 | + | ||
115 | + private AttributeKvCompositeKey getAttributeKvCompositeKey(EntityId entityId, String attributeType, String attributeKey) { | ||
116 | + return new AttributeKvCompositeKey( | ||
117 | + entityId.getEntityType(), | ||
118 | + fromTimeUUID(entityId.getId()), | ||
119 | + attributeType, | ||
120 | + attributeKey); | ||
121 | + } | ||
119 | } | 122 | } |
@@ -21,8 +21,8 @@ import org.springframework.data.repository.CrudRepository; | @@ -21,8 +21,8 @@ import org.springframework.data.repository.CrudRepository; | ||
21 | import org.springframework.data.repository.query.Param; | 21 | import org.springframework.data.repository.query.Param; |
22 | import org.thingsboard.server.common.data.plugin.ComponentScope; | 22 | import org.thingsboard.server.common.data.plugin.ComponentScope; |
23 | import org.thingsboard.server.common.data.plugin.ComponentType; | 23 | import org.thingsboard.server.common.data.plugin.ComponentType; |
24 | -import org.thingsboard.server.dao.util.SqlDao; | ||
25 | import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity; | 24 | import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity; |
25 | +import org.thingsboard.server.dao.util.SqlDao; | ||
26 | 26 | ||
27 | import java.util.List; | 27 | import java.util.List; |
28 | import java.util.UUID; | 28 | import java.util.UUID; |
@@ -31,7 +31,7 @@ import java.util.UUID; | @@ -31,7 +31,7 @@ import java.util.UUID; | ||
31 | * Created by Valerii Sosliuk on 5/6/2017. | 31 | * Created by Valerii Sosliuk on 5/6/2017. |
32 | */ | 32 | */ |
33 | @SqlDao | 33 | @SqlDao |
34 | -public interface ComponentDescriptorRepository extends CrudRepository<ComponentDescriptorEntity, UUID> { | 34 | +public interface ComponentDescriptorRepository extends CrudRepository<ComponentDescriptorEntity, String> { |
35 | 35 | ||
36 | ComponentDescriptorEntity findByClazz(String clazz); | 36 | ComponentDescriptorEntity findByClazz(String clazz); |
37 | 37 | ||
@@ -40,7 +40,7 @@ public interface ComponentDescriptorRepository extends CrudRepository<ComponentD | @@ -40,7 +40,7 @@ public interface ComponentDescriptorRepository extends CrudRepository<ComponentD | ||
40 | "AND cd.id > :idOffset ORDER BY cd.id") | 40 | "AND cd.id > :idOffset ORDER BY cd.id") |
41 | List<ComponentDescriptorEntity> findByType(@Param("type") ComponentType type, | 41 | List<ComponentDescriptorEntity> findByType(@Param("type") ComponentType type, |
42 | @Param("textSearch") String textSearch, | 42 | @Param("textSearch") String textSearch, |
43 | - @Param("idOffset") UUID idOffset, | 43 | + @Param("idOffset") String idOffset, |
44 | Pageable pageable); | 44 | Pageable pageable); |
45 | 45 | ||
46 | @Query("SELECT cd FROM ComponentDescriptorEntity cd WHERE cd.type = :type " + | 46 | @Query("SELECT cd FROM ComponentDescriptorEntity cd WHERE cd.type = :type " + |
@@ -49,7 +49,7 @@ public interface ComponentDescriptorRepository extends CrudRepository<ComponentD | @@ -49,7 +49,7 @@ public interface ComponentDescriptorRepository extends CrudRepository<ComponentD | ||
49 | List<ComponentDescriptorEntity> findByScopeAndType(@Param("type") ComponentType type, | 49 | List<ComponentDescriptorEntity> findByScopeAndType(@Param("type") ComponentType type, |
50 | @Param("scope") ComponentScope scope, | 50 | @Param("scope") ComponentScope scope, |
51 | @Param("textSearch") String textSearch, | 51 | @Param("textSearch") String textSearch, |
52 | - @Param("idOffset") UUID idOffset, | 52 | + @Param("idOffset") String idOffset, |
53 | Pageable pageable); | 53 | Pageable pageable); |
54 | 54 | ||
55 | void deleteByClazz(String clazz); | 55 | void deleteByClazz(String clazz); |
@@ -20,23 +20,23 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -20,23 +20,23 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
20 | import org.springframework.data.domain.PageRequest; | 20 | import org.springframework.data.domain.PageRequest; |
21 | import org.springframework.data.repository.CrudRepository; | 21 | import org.springframework.data.repository.CrudRepository; |
22 | import org.springframework.stereotype.Component; | 22 | import org.springframework.stereotype.Component; |
23 | +import org.thingsboard.server.common.data.UUIDConverter; | ||
23 | import org.thingsboard.server.common.data.id.ComponentDescriptorId; | 24 | import org.thingsboard.server.common.data.id.ComponentDescriptorId; |
24 | import org.thingsboard.server.common.data.page.TextPageLink; | 25 | import org.thingsboard.server.common.data.page.TextPageLink; |
25 | import org.thingsboard.server.common.data.plugin.ComponentDescriptor; | 26 | import org.thingsboard.server.common.data.plugin.ComponentDescriptor; |
26 | import org.thingsboard.server.common.data.plugin.ComponentScope; | 27 | import org.thingsboard.server.common.data.plugin.ComponentScope; |
27 | import org.thingsboard.server.common.data.plugin.ComponentType; | 28 | import org.thingsboard.server.common.data.plugin.ComponentType; |
28 | import org.thingsboard.server.dao.DaoUtil; | 29 | import org.thingsboard.server.dao.DaoUtil; |
29 | -import org.thingsboard.server.dao.util.SqlDao; | ||
30 | import org.thingsboard.server.dao.component.ComponentDescriptorDao; | 30 | import org.thingsboard.server.dao.component.ComponentDescriptorDao; |
31 | import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity; | 31 | import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity; |
32 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; | 32 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
33 | +import org.thingsboard.server.dao.util.SqlDao; | ||
33 | 34 | ||
34 | import java.util.List; | 35 | import java.util.List; |
35 | import java.util.Objects; | 36 | import java.util.Objects; |
36 | import java.util.Optional; | 37 | import java.util.Optional; |
37 | -import java.util.UUID; | ||
38 | 38 | ||
39 | -import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; | 39 | +import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID_STR; |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * Created by Valerii Sosliuk on 5/6/2017. | 42 | * Created by Valerii Sosliuk on 5/6/2017. |
@@ -55,7 +55,7 @@ public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<Comp | @@ -55,7 +55,7 @@ public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<Comp | ||
55 | } | 55 | } |
56 | 56 | ||
57 | @Override | 57 | @Override |
58 | - protected CrudRepository<ComponentDescriptorEntity, UUID> getCrudRepository() { | 58 | + protected CrudRepository<ComponentDescriptorEntity, String> getCrudRepository() { |
59 | return componentDescriptorRepository; | 59 | return componentDescriptorRepository; |
60 | } | 60 | } |
61 | 61 | ||
@@ -64,8 +64,7 @@ public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<Comp | @@ -64,8 +64,7 @@ public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<Comp | ||
64 | if (component.getId() == null) { | 64 | if (component.getId() == null) { |
65 | component.setId(new ComponentDescriptorId(UUIDs.timeBased())); | 65 | component.setId(new ComponentDescriptorId(UUIDs.timeBased())); |
66 | } | 66 | } |
67 | - boolean exists = componentDescriptorRepository.findOne(component.getId().getId()) != null; | ||
68 | - if (!exists) { | 67 | + if (componentDescriptorRepository.findOne(UUIDConverter.fromTimeUUID(component.getId().getId())) == null) { |
69 | return Optional.of(save(component)); | 68 | return Optional.of(save(component)); |
70 | } | 69 | } |
71 | return Optional.empty(); | 70 | return Optional.empty(); |
@@ -87,7 +86,7 @@ public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<Comp | @@ -87,7 +86,7 @@ public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<Comp | ||
87 | .findByType( | 86 | .findByType( |
88 | type, | 87 | type, |
89 | Objects.toString(pageLink.getTextSearch(), ""), | 88 | Objects.toString(pageLink.getTextSearch(), ""), |
90 | - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(), | 89 | + pageLink.getIdOffset() == null ? NULL_UUID_STR : UUIDConverter.fromTimeUUID(pageLink.getIdOffset()), |
91 | new PageRequest(0, pageLink.getLimit()))); | 90 | new PageRequest(0, pageLink.getLimit()))); |
92 | } | 91 | } |
93 | 92 | ||
@@ -98,7 +97,7 @@ public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<Comp | @@ -98,7 +97,7 @@ public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<Comp | ||
98 | type, | 97 | type, |
99 | scope, | 98 | scope, |
100 | Objects.toString(pageLink.getTextSearch(), ""), | 99 | Objects.toString(pageLink.getTextSearch(), ""), |
101 | - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(), | 100 | + pageLink.getIdOffset() == null ? NULL_UUID_STR : UUIDConverter.fromTimeUUID(pageLink.getIdOffset()), |
102 | new PageRequest(0, pageLink.getLimit()))); | 101 | new PageRequest(0, pageLink.getLimit()))); |
103 | } | 102 | } |
104 | 103 |
@@ -19,26 +19,25 @@ import org.springframework.data.domain.Pageable; | @@ -19,26 +19,25 @@ import org.springframework.data.domain.Pageable; | ||
19 | import org.springframework.data.jpa.repository.Query; | 19 | import org.springframework.data.jpa.repository.Query; |
20 | import org.springframework.data.repository.CrudRepository; | 20 | import org.springframework.data.repository.CrudRepository; |
21 | import org.springframework.data.repository.query.Param; | 21 | import org.springframework.data.repository.query.Param; |
22 | -import org.thingsboard.server.dao.util.SqlDao; | ||
23 | import org.thingsboard.server.dao.model.sql.CustomerEntity; | 22 | import org.thingsboard.server.dao.model.sql.CustomerEntity; |
23 | +import org.thingsboard.server.dao.util.SqlDao; | ||
24 | 24 | ||
25 | import java.util.List; | 25 | import java.util.List; |
26 | -import java.util.UUID; | ||
27 | 26 | ||
28 | /** | 27 | /** |
29 | * Created by Valerii Sosliuk on 5/6/2017. | 28 | * Created by Valerii Sosliuk on 5/6/2017. |
30 | */ | 29 | */ |
31 | @SqlDao | 30 | @SqlDao |
32 | -public interface CustomerRepository extends CrudRepository<CustomerEntity, UUID> { | 31 | +public interface CustomerRepository extends CrudRepository<CustomerEntity, String> { |
33 | 32 | ||
34 | @Query("SELECT c FROM CustomerEntity c WHERE c.tenantId = :tenantId " + | 33 | @Query("SELECT c FROM CustomerEntity c WHERE c.tenantId = :tenantId " + |
35 | "AND LOWER(c.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " + | 34 | "AND LOWER(c.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " + |
36 | "AND c.id > :idOffset ORDER BY c.id") | 35 | "AND c.id > :idOffset ORDER BY c.id") |
37 | - List<CustomerEntity> findByTenantId(@Param("tenantId") UUID tenantId, | 36 | + List<CustomerEntity> findByTenantId(@Param("tenantId") String tenantId, |
38 | @Param("textSearch") String textSearch, | 37 | @Param("textSearch") String textSearch, |
39 | - @Param("idOffset") UUID idOffset, | 38 | + @Param("idOffset") String idOffset, |
40 | Pageable pageable); | 39 | Pageable pageable); |
41 | 40 | ||
42 | - CustomerEntity findByTenantIdAndTitle(UUID tenantId, String title); | 41 | + CustomerEntity findByTenantIdAndTitle(String tenantId, String title); |
43 | 42 | ||
44 | } | 43 | } |
@@ -20,19 +20,20 @@ import org.springframework.data.domain.PageRequest; | @@ -20,19 +20,20 @@ import org.springframework.data.domain.PageRequest; | ||
20 | import org.springframework.data.repository.CrudRepository; | 20 | import org.springframework.data.repository.CrudRepository; |
21 | import org.springframework.stereotype.Component; | 21 | import org.springframework.stereotype.Component; |
22 | import org.thingsboard.server.common.data.Customer; | 22 | import org.thingsboard.server.common.data.Customer; |
23 | +import org.thingsboard.server.common.data.UUIDConverter; | ||
23 | import org.thingsboard.server.common.data.page.TextPageLink; | 24 | import org.thingsboard.server.common.data.page.TextPageLink; |
24 | import org.thingsboard.server.dao.DaoUtil; | 25 | import org.thingsboard.server.dao.DaoUtil; |
25 | -import org.thingsboard.server.dao.util.SqlDao; | ||
26 | import org.thingsboard.server.dao.customer.CustomerDao; | 26 | import org.thingsboard.server.dao.customer.CustomerDao; |
27 | import org.thingsboard.server.dao.model.sql.CustomerEntity; | 27 | import org.thingsboard.server.dao.model.sql.CustomerEntity; |
28 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; | 28 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
29 | +import org.thingsboard.server.dao.util.SqlDao; | ||
29 | 30 | ||
30 | import java.util.List; | 31 | import java.util.List; |
31 | import java.util.Objects; | 32 | import java.util.Objects; |
32 | import java.util.Optional; | 33 | import java.util.Optional; |
33 | import java.util.UUID; | 34 | import java.util.UUID; |
34 | 35 | ||
35 | -import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; | 36 | +import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID_STR; |
36 | 37 | ||
37 | /** | 38 | /** |
38 | * Created by Valerii Sosliuk on 5/6/2017. | 39 | * Created by Valerii Sosliuk on 5/6/2017. |
@@ -50,22 +51,22 @@ public class JpaCustomerDao extends JpaAbstractSearchTextDao<CustomerEntity, Cus | @@ -50,22 +51,22 @@ public class JpaCustomerDao extends JpaAbstractSearchTextDao<CustomerEntity, Cus | ||
50 | } | 51 | } |
51 | 52 | ||
52 | @Override | 53 | @Override |
53 | - protected CrudRepository<CustomerEntity, UUID> getCrudRepository() { | 54 | + protected CrudRepository<CustomerEntity, String> getCrudRepository() { |
54 | return customerRepository; | 55 | return customerRepository; |
55 | } | 56 | } |
56 | 57 | ||
57 | @Override | 58 | @Override |
58 | public List<Customer> findCustomersByTenantId(UUID tenantId, TextPageLink pageLink) { | 59 | public List<Customer> findCustomersByTenantId(UUID tenantId, TextPageLink pageLink) { |
59 | return DaoUtil.convertDataList(customerRepository.findByTenantId( | 60 | return DaoUtil.convertDataList(customerRepository.findByTenantId( |
60 | - tenantId, | 61 | + UUIDConverter.fromTimeUUID(tenantId), |
61 | Objects.toString(pageLink.getTextSearch(), ""), | 62 | Objects.toString(pageLink.getTextSearch(), ""), |
62 | - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(), | 63 | + pageLink.getIdOffset() == null ? NULL_UUID_STR : UUIDConverter.fromTimeUUID(pageLink.getIdOffset()), |
63 | new PageRequest(0, pageLink.getLimit()))); | 64 | new PageRequest(0, pageLink.getLimit()))); |
64 | } | 65 | } |
65 | 66 | ||
66 | @Override | 67 | @Override |
67 | public Optional<Customer> findCustomersByTenantIdAndTitle(UUID tenantId, String title) { | 68 | public Optional<Customer> findCustomersByTenantIdAndTitle(UUID tenantId, String title) { |
68 | - Customer customer = DaoUtil.getData(customerRepository.findByTenantIdAndTitle(tenantId, title)); | 69 | + Customer customer = DaoUtil.getData(customerRepository.findByTenantIdAndTitle(UUIDConverter.fromTimeUUID(tenantId), title)); |
69 | return Optional.ofNullable(customer); | 70 | return Optional.ofNullable(customer); |
70 | } | 71 | } |
71 | } | 72 | } |
@@ -19,8 +19,8 @@ import org.springframework.data.domain.Pageable; | @@ -19,8 +19,8 @@ import org.springframework.data.domain.Pageable; | ||
19 | import org.springframework.data.jpa.repository.Query; | 19 | import org.springframework.data.jpa.repository.Query; |
20 | import org.springframework.data.repository.CrudRepository; | 20 | import org.springframework.data.repository.CrudRepository; |
21 | import org.springframework.data.repository.query.Param; | 21 | import org.springframework.data.repository.query.Param; |
22 | -import org.thingsboard.server.dao.util.SqlDao; | ||
23 | import org.thingsboard.server.dao.model.sql.DashboardInfoEntity; | 22 | import org.thingsboard.server.dao.model.sql.DashboardInfoEntity; |
23 | +import org.thingsboard.server.dao.util.SqlDao; | ||
24 | 24 | ||
25 | import java.util.List; | 25 | import java.util.List; |
26 | import java.util.UUID; | 26 | import java.util.UUID; |
@@ -29,22 +29,22 @@ import java.util.UUID; | @@ -29,22 +29,22 @@ import java.util.UUID; | ||
29 | * Created by Valerii Sosliuk on 5/6/2017. | 29 | * Created by Valerii Sosliuk on 5/6/2017. |
30 | */ | 30 | */ |
31 | @SqlDao | 31 | @SqlDao |
32 | -public interface DashboardInfoRepository extends CrudRepository<DashboardInfoEntity, UUID> { | 32 | +public interface DashboardInfoRepository extends CrudRepository<DashboardInfoEntity, String> { |
33 | 33 | ||
34 | @Query("SELECT di FROM DashboardInfoEntity di WHERE di.tenantId = :tenantId " + | 34 | @Query("SELECT di FROM DashboardInfoEntity di WHERE di.tenantId = :tenantId " + |
35 | "AND LOWER(di.searchText) LIKE LOWER(CONCAT(:searchText, '%')) " + | 35 | "AND LOWER(di.searchText) LIKE LOWER(CONCAT(:searchText, '%')) " + |
36 | "AND di.id > :idOffset ORDER BY di.id") | 36 | "AND di.id > :idOffset ORDER BY di.id") |
37 | - List<DashboardInfoEntity> findByTenantId(@Param("tenantId") UUID tenantId, | 37 | + List<DashboardInfoEntity> findByTenantId(@Param("tenantId") String tenantId, |
38 | @Param("searchText") String searchText, | 38 | @Param("searchText") String searchText, |
39 | - @Param("idOffset") UUID idOffset, | 39 | + @Param("idOffset") String idOffset, |
40 | Pageable pageable); | 40 | Pageable pageable); |
41 | 41 | ||
42 | @Query("SELECT di FROM DashboardInfoEntity di WHERE di.tenantId = :tenantId " + | 42 | @Query("SELECT di FROM DashboardInfoEntity di WHERE di.tenantId = :tenantId " + |
43 | "AND di.customerId = :customerId AND LOWER(di.searchText) LIKE LOWER(CONCAT(:searchText, '%')) " + | 43 | "AND di.customerId = :customerId AND LOWER(di.searchText) LIKE LOWER(CONCAT(:searchText, '%')) " + |
44 | "AND di.id > :idOffset ORDER BY di.id") | 44 | "AND di.id > :idOffset ORDER BY di.id") |
45 | - List<DashboardInfoEntity> findByTenantIdAndCustomerId(@Param("tenantId") UUID tenantId, | ||
46 | - @Param("customerId") UUID customerId, | 45 | + List<DashboardInfoEntity> findByTenantIdAndCustomerId(@Param("tenantId") String tenantId, |
46 | + @Param("customerId") String customerId, | ||
47 | @Param("searchText") String searchText, | 47 | @Param("searchText") String searchText, |
48 | - @Param("idOffset") UUID idOffset, | 48 | + @Param("idOffset") String idOffset, |
49 | Pageable pageable); | 49 | Pageable pageable); |
50 | } | 50 | } |
@@ -16,14 +16,12 @@ | @@ -16,14 +16,12 @@ | ||
16 | package org.thingsboard.server.dao.sql.dashboard; | 16 | package org.thingsboard.server.dao.sql.dashboard; |
17 | 17 | ||
18 | import org.springframework.data.repository.CrudRepository; | 18 | import org.springframework.data.repository.CrudRepository; |
19 | -import org.thingsboard.server.dao.util.SqlDao; | ||
20 | import org.thingsboard.server.dao.model.sql.DashboardEntity; | 19 | import org.thingsboard.server.dao.model.sql.DashboardEntity; |
21 | - | ||
22 | -import java.util.UUID; | 20 | +import org.thingsboard.server.dao.util.SqlDao; |
23 | 21 | ||
24 | /** | 22 | /** |
25 | * Created by Valerii Sosliuk on 5/6/2017. | 23 | * Created by Valerii Sosliuk on 5/6/2017. |
26 | */ | 24 | */ |
27 | @SqlDao | 25 | @SqlDao |
28 | -public interface DashboardRepository extends CrudRepository<DashboardEntity, UUID> { | 26 | +public interface DashboardRepository extends CrudRepository<DashboardEntity, String> { |
29 | } | 27 | } |
@@ -19,12 +19,10 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -19,12 +19,10 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
19 | import org.springframework.data.repository.CrudRepository; | 19 | import org.springframework.data.repository.CrudRepository; |
20 | import org.springframework.stereotype.Component; | 20 | import org.springframework.stereotype.Component; |
21 | import org.thingsboard.server.common.data.Dashboard; | 21 | import org.thingsboard.server.common.data.Dashboard; |
22 | -import org.thingsboard.server.dao.util.SqlDao; | ||
23 | import org.thingsboard.server.dao.dashboard.DashboardDao; | 22 | import org.thingsboard.server.dao.dashboard.DashboardDao; |
24 | import org.thingsboard.server.dao.model.sql.DashboardEntity; | 23 | import org.thingsboard.server.dao.model.sql.DashboardEntity; |
25 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; | 24 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
26 | - | ||
27 | -import java.util.UUID; | 25 | +import org.thingsboard.server.dao.util.SqlDao; |
28 | 26 | ||
29 | /** | 27 | /** |
30 | * Created by Valerii Sosliuk on 5/6/2017. | 28 | * Created by Valerii Sosliuk on 5/6/2017. |
@@ -42,7 +40,7 @@ public class JpaDashboardDao extends JpaAbstractSearchTextDao<DashboardEntity, D | @@ -42,7 +40,7 @@ public class JpaDashboardDao extends JpaAbstractSearchTextDao<DashboardEntity, D | ||
42 | } | 40 | } |
43 | 41 | ||
44 | @Override | 42 | @Override |
45 | - protected CrudRepository<DashboardEntity, UUID> getCrudRepository() { | 43 | + protected CrudRepository<DashboardEntity, String> getCrudRepository() { |
46 | return dashboardRepository; | 44 | return dashboardRepository; |
47 | } | 45 | } |
48 | } | 46 | } |
@@ -20,18 +20,19 @@ import org.springframework.data.domain.PageRequest; | @@ -20,18 +20,19 @@ import org.springframework.data.domain.PageRequest; | ||
20 | import org.springframework.data.repository.CrudRepository; | 20 | import org.springframework.data.repository.CrudRepository; |
21 | import org.springframework.stereotype.Component; | 21 | import org.springframework.stereotype.Component; |
22 | import org.thingsboard.server.common.data.DashboardInfo; | 22 | import org.thingsboard.server.common.data.DashboardInfo; |
23 | +import org.thingsboard.server.common.data.UUIDConverter; | ||
23 | import org.thingsboard.server.common.data.page.TextPageLink; | 24 | import org.thingsboard.server.common.data.page.TextPageLink; |
24 | import org.thingsboard.server.dao.DaoUtil; | 25 | import org.thingsboard.server.dao.DaoUtil; |
25 | -import org.thingsboard.server.dao.util.SqlDao; | ||
26 | import org.thingsboard.server.dao.dashboard.DashboardInfoDao; | 26 | import org.thingsboard.server.dao.dashboard.DashboardInfoDao; |
27 | import org.thingsboard.server.dao.model.sql.DashboardInfoEntity; | 27 | import org.thingsboard.server.dao.model.sql.DashboardInfoEntity; |
28 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; | 28 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
29 | +import org.thingsboard.server.dao.util.SqlDao; | ||
29 | 30 | ||
30 | import java.util.List; | 31 | import java.util.List; |
31 | import java.util.Objects; | 32 | import java.util.Objects; |
32 | import java.util.UUID; | 33 | import java.util.UUID; |
33 | 34 | ||
34 | -import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; | 35 | +import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID_STR; |
35 | 36 | ||
36 | /** | 37 | /** |
37 | * Created by Valerii Sosliuk on 5/6/2017. | 38 | * Created by Valerii Sosliuk on 5/6/2017. |
@@ -57,9 +58,9 @@ public class JpaDashboardInfoDao extends JpaAbstractSearchTextDao<DashboardInfoE | @@ -57,9 +58,9 @@ public class JpaDashboardInfoDao extends JpaAbstractSearchTextDao<DashboardInfoE | ||
57 | public List<DashboardInfo> findDashboardsByTenantId(UUID tenantId, TextPageLink pageLink) { | 58 | public List<DashboardInfo> findDashboardsByTenantId(UUID tenantId, TextPageLink pageLink) { |
58 | return DaoUtil.convertDataList(dashboardInfoRepository | 59 | return DaoUtil.convertDataList(dashboardInfoRepository |
59 | .findByTenantId( | 60 | .findByTenantId( |
60 | - tenantId, | 61 | + UUIDConverter.fromTimeUUID(tenantId), |
61 | Objects.toString(pageLink.getTextSearch(), ""), | 62 | Objects.toString(pageLink.getTextSearch(), ""), |
62 | - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(), | 63 | + pageLink.getIdOffset() == null ? NULL_UUID_STR : UUIDConverter.fromTimeUUID(pageLink.getIdOffset()), |
63 | new PageRequest(0, pageLink.getLimit()))); | 64 | new PageRequest(0, pageLink.getLimit()))); |
64 | } | 65 | } |
65 | 66 | ||
@@ -67,10 +68,10 @@ public class JpaDashboardInfoDao extends JpaAbstractSearchTextDao<DashboardInfoE | @@ -67,10 +68,10 @@ public class JpaDashboardInfoDao extends JpaAbstractSearchTextDao<DashboardInfoE | ||
67 | public List<DashboardInfo> findDashboardsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) { | 68 | public List<DashboardInfo> findDashboardsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) { |
68 | return DaoUtil.convertDataList(dashboardInfoRepository | 69 | return DaoUtil.convertDataList(dashboardInfoRepository |
69 | .findByTenantIdAndCustomerId( | 70 | .findByTenantIdAndCustomerId( |
70 | - tenantId, | ||
71 | - customerId, | 71 | + UUIDConverter.fromTimeUUID(tenantId), |
72 | + UUIDConverter.fromTimeUUID(customerId), | ||
72 | Objects.toString(pageLink.getTextSearch(), ""), | 73 | Objects.toString(pageLink.getTextSearch(), ""), |
73 | - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(), | 74 | + pageLink.getIdOffset() == null ? NULL_UUID_STR : UUIDConverter.fromTimeUUID(pageLink.getIdOffset()), |
74 | new PageRequest(0, pageLink.getLimit()))); | 75 | new PageRequest(0, pageLink.getLimit()))); |
75 | } | 76 | } |
76 | } | 77 | } |
@@ -16,18 +16,16 @@ | @@ -16,18 +16,16 @@ | ||
16 | package org.thingsboard.server.dao.sql.device; | 16 | package org.thingsboard.server.dao.sql.device; |
17 | 17 | ||
18 | import org.springframework.data.repository.CrudRepository; | 18 | import org.springframework.data.repository.CrudRepository; |
19 | -import org.thingsboard.server.dao.util.SqlDao; | ||
20 | import org.thingsboard.server.dao.model.sql.DeviceCredentialsEntity; | 19 | import org.thingsboard.server.dao.model.sql.DeviceCredentialsEntity; |
21 | - | ||
22 | -import java.util.UUID; | 20 | +import org.thingsboard.server.dao.util.SqlDao; |
23 | 21 | ||
24 | /** | 22 | /** |
25 | * Created by Valerii Sosliuk on 5/6/2017. | 23 | * Created by Valerii Sosliuk on 5/6/2017. |
26 | */ | 24 | */ |
27 | @SqlDao | 25 | @SqlDao |
28 | -public interface DeviceCredentialsRepository extends CrudRepository<DeviceCredentialsEntity, UUID> { | 26 | +public interface DeviceCredentialsRepository extends CrudRepository<DeviceCredentialsEntity, String> { |
29 | 27 | ||
30 | - DeviceCredentialsEntity findByDeviceId(UUID deviceId); | 28 | + DeviceCredentialsEntity findByDeviceId(String deviceId); |
31 | 29 | ||
32 | DeviceCredentialsEntity findByCredentialsId(String credentialsId); | 30 | DeviceCredentialsEntity findByCredentialsId(String credentialsId); |
33 | } | 31 | } |
@@ -19,46 +19,45 @@ import org.springframework.data.domain.Pageable; | @@ -19,46 +19,45 @@ import org.springframework.data.domain.Pageable; | ||
19 | import org.springframework.data.jpa.repository.Query; | 19 | import org.springframework.data.jpa.repository.Query; |
20 | import org.springframework.data.repository.CrudRepository; | 20 | import org.springframework.data.repository.CrudRepository; |
21 | import org.springframework.data.repository.query.Param; | 21 | import org.springframework.data.repository.query.Param; |
22 | -import org.thingsboard.server.dao.util.SqlDao; | ||
23 | import org.thingsboard.server.dao.model.sql.DeviceEntity; | 22 | import org.thingsboard.server.dao.model.sql.DeviceEntity; |
24 | import org.thingsboard.server.dao.model.sql.TenantDeviceTypeEntity; | 23 | import org.thingsboard.server.dao.model.sql.TenantDeviceTypeEntity; |
24 | +import org.thingsboard.server.dao.util.SqlDao; | ||
25 | 25 | ||
26 | import java.util.List; | 26 | import java.util.List; |
27 | -import java.util.UUID; | ||
28 | 27 | ||
29 | /** | 28 | /** |
30 | * Created by Valerii Sosliuk on 5/6/2017. | 29 | * Created by Valerii Sosliuk on 5/6/2017. |
31 | */ | 30 | */ |
32 | @SqlDao | 31 | @SqlDao |
33 | -public interface DeviceRepository extends CrudRepository<DeviceEntity, UUID> { | 32 | +public interface DeviceRepository extends CrudRepository<DeviceEntity, String> { |
34 | 33 | ||
35 | 34 | ||
36 | @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " + | 35 | @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " + |
37 | "AND d.customerId = :customerId " + | 36 | "AND d.customerId = :customerId " + |
38 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:searchText, '%')) " + | 37 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:searchText, '%')) " + |
39 | "AND d.id > :idOffset ORDER BY d.id") | 38 | "AND d.id > :idOffset ORDER BY d.id") |
40 | - List<DeviceEntity> findByTenantIdAndCustomerId(@Param("tenantId") UUID tenantId, | ||
41 | - @Param("customerId") UUID customerId, | 39 | + List<DeviceEntity> findByTenantIdAndCustomerId(@Param("tenantId") String tenantId, |
40 | + @Param("customerId") String customerId, | ||
42 | @Param("searchText") String searchText, | 41 | @Param("searchText") String searchText, |
43 | - @Param("idOffset") UUID idOffset, | 42 | + @Param("idOffset") String idOffset, |
44 | Pageable pageable); | 43 | Pageable pageable); |
45 | 44 | ||
46 | @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " + | 45 | @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " + |
47 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " + | 46 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " + |
48 | "AND d.id > :idOffset ORDER BY d.id") | 47 | "AND d.id > :idOffset ORDER BY d.id") |
49 | - List<DeviceEntity> findByTenantId(@Param("tenantId") UUID tenantId, | 48 | + List<DeviceEntity> findByTenantId(@Param("tenantId") String tenantId, |
50 | @Param("textSearch") String textSearch, | 49 | @Param("textSearch") String textSearch, |
51 | - @Param("idOffset") UUID idOffset, | 50 | + @Param("idOffset") String idOffset, |
52 | Pageable pageable); | 51 | Pageable pageable); |
53 | 52 | ||
54 | @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " + | 53 | @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " + |
55 | "AND d.type = :type " + | 54 | "AND d.type = :type " + |
56 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " + | 55 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " + |
57 | "AND d.id > :idOffset ORDER BY d.id") | 56 | "AND d.id > :idOffset ORDER BY d.id") |
58 | - List<DeviceEntity> findByTenantIdAndType(@Param("tenantId") UUID tenantId, | 57 | + List<DeviceEntity> findByTenantIdAndType(@Param("tenantId") String tenantId, |
59 | @Param("type") String type, | 58 | @Param("type") String type, |
60 | @Param("textSearch") String textSearch, | 59 | @Param("textSearch") String textSearch, |
61 | - @Param("idOffset") UUID idOffset, | 60 | + @Param("idOffset") String idOffset, |
62 | Pageable pageable); | 61 | Pageable pageable); |
63 | 62 | ||
64 | @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " + | 63 | @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " + |
@@ -66,19 +65,19 @@ public interface DeviceRepository extends CrudRepository<DeviceEntity, UUID> { | @@ -66,19 +65,19 @@ public interface DeviceRepository extends CrudRepository<DeviceEntity, UUID> { | ||
66 | "AND d.type = :type " + | 65 | "AND d.type = :type " + |
67 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " + | 66 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " + |
68 | "AND d.id > :idOffset ORDER BY d.id") | 67 | "AND d.id > :idOffset ORDER BY d.id") |
69 | - List<DeviceEntity> findByTenantIdAndCustomerIdAndType(@Param("tenantId") UUID tenantId, | ||
70 | - @Param("customerId") UUID customerId, | 68 | + List<DeviceEntity> findByTenantIdAndCustomerIdAndType(@Param("tenantId") String tenantId, |
69 | + @Param("customerId") String customerId, | ||
71 | @Param("type") String type, | 70 | @Param("type") String type, |
72 | @Param("textSearch") String textSearch, | 71 | @Param("textSearch") String textSearch, |
73 | - @Param("idOffset") UUID idOffset, | 72 | + @Param("idOffset") String idOffset, |
74 | Pageable pageable); | 73 | Pageable pageable); |
75 | 74 | ||
76 | @Query("SELECT DISTINCT NEW org.thingsboard.server.dao.model.sql.TenantDeviceTypeEntity(d.tenantId, d.type) FROM DeviceEntity d") | 75 | @Query("SELECT DISTINCT NEW org.thingsboard.server.dao.model.sql.TenantDeviceTypeEntity(d.tenantId, d.type) FROM DeviceEntity d") |
77 | List<TenantDeviceTypeEntity> findTenantDeviceTypes(); | 76 | List<TenantDeviceTypeEntity> findTenantDeviceTypes(); |
78 | 77 | ||
79 | - DeviceEntity findByTenantIdAndName(UUID tenantId, String name); | 78 | + DeviceEntity findByTenantIdAndName(String tenantId, String name); |
80 | 79 | ||
81 | - List<DeviceEntity> findDevicesByTenantIdAndCustomerIdAndIdIn(UUID tenantId, UUID customerId, List<UUID> deviceIds); | 80 | + List<DeviceEntity> findDevicesByTenantIdAndCustomerIdAndIdIn(String tenantId, String customerId, List<String> deviceIds); |
82 | 81 | ||
83 | - List<DeviceEntity> findDevicesByTenantIdAndIdIn(UUID tenantId, List<UUID> deviceIds); | 82 | + List<DeviceEntity> findDevicesByTenantIdAndIdIn(String tenantId, List<String> deviceIds); |
84 | } | 83 | } |
@@ -18,12 +18,13 @@ package org.thingsboard.server.dao.sql.device; | @@ -18,12 +18,13 @@ package org.thingsboard.server.dao.sql.device; | ||
18 | import org.springframework.beans.factory.annotation.Autowired; | 18 | import org.springframework.beans.factory.annotation.Autowired; |
19 | import org.springframework.data.repository.CrudRepository; | 19 | import org.springframework.data.repository.CrudRepository; |
20 | import org.springframework.stereotype.Component; | 20 | import org.springframework.stereotype.Component; |
21 | +import org.thingsboard.server.common.data.UUIDConverter; | ||
21 | import org.thingsboard.server.common.data.security.DeviceCredentials; | 22 | import org.thingsboard.server.common.data.security.DeviceCredentials; |
22 | import org.thingsboard.server.dao.DaoUtil; | 23 | import org.thingsboard.server.dao.DaoUtil; |
23 | -import org.thingsboard.server.dao.util.SqlDao; | ||
24 | import org.thingsboard.server.dao.device.DeviceCredentialsDao; | 24 | import org.thingsboard.server.dao.device.DeviceCredentialsDao; |
25 | import org.thingsboard.server.dao.model.sql.DeviceCredentialsEntity; | 25 | import org.thingsboard.server.dao.model.sql.DeviceCredentialsEntity; |
26 | import org.thingsboard.server.dao.sql.JpaAbstractDao; | 26 | import org.thingsboard.server.dao.sql.JpaAbstractDao; |
27 | +import org.thingsboard.server.dao.util.SqlDao; | ||
27 | 28 | ||
28 | import java.util.UUID; | 29 | import java.util.UUID; |
29 | 30 | ||
@@ -43,13 +44,13 @@ public class JpaDeviceCredentialsDao extends JpaAbstractDao<DeviceCredentialsEnt | @@ -43,13 +44,13 @@ public class JpaDeviceCredentialsDao extends JpaAbstractDao<DeviceCredentialsEnt | ||
43 | } | 44 | } |
44 | 45 | ||
45 | @Override | 46 | @Override |
46 | - protected CrudRepository<DeviceCredentialsEntity, UUID> getCrudRepository() { | 47 | + protected CrudRepository<DeviceCredentialsEntity, String> getCrudRepository() { |
47 | return deviceCredentialsRepository; | 48 | return deviceCredentialsRepository; |
48 | } | 49 | } |
49 | 50 | ||
50 | @Override | 51 | @Override |
51 | public DeviceCredentials findByDeviceId(UUID deviceId) { | 52 | public DeviceCredentials findByDeviceId(UUID deviceId) { |
52 | - return DaoUtil.getData(deviceCredentialsRepository.findByDeviceId(deviceId)); | 53 | + return DaoUtil.getData(deviceCredentialsRepository.findByDeviceId(UUIDConverter.fromTimeUUID(deviceId))); |
53 | } | 54 | } |
54 | 55 | ||
55 | @Override | 56 | @Override |
@@ -22,18 +22,21 @@ import org.springframework.data.repository.CrudRepository; | @@ -22,18 +22,21 @@ import org.springframework.data.repository.CrudRepository; | ||
22 | import org.springframework.stereotype.Component; | 22 | import org.springframework.stereotype.Component; |
23 | import org.thingsboard.server.common.data.Device; | 23 | import org.thingsboard.server.common.data.Device; |
24 | import org.thingsboard.server.common.data.TenantDeviceType; | 24 | import org.thingsboard.server.common.data.TenantDeviceType; |
25 | +import org.thingsboard.server.common.data.UUIDConverter; | ||
25 | import org.thingsboard.server.common.data.id.TenantId; | 26 | import org.thingsboard.server.common.data.id.TenantId; |
26 | import org.thingsboard.server.common.data.page.TextPageLink; | 27 | import org.thingsboard.server.common.data.page.TextPageLink; |
27 | import org.thingsboard.server.dao.DaoUtil; | 28 | import org.thingsboard.server.dao.DaoUtil; |
28 | -import org.thingsboard.server.dao.util.SqlDao; | ||
29 | import org.thingsboard.server.dao.device.DeviceDao; | 29 | import org.thingsboard.server.dao.device.DeviceDao; |
30 | import org.thingsboard.server.dao.model.sql.DeviceEntity; | 30 | import org.thingsboard.server.dao.model.sql.DeviceEntity; |
31 | import org.thingsboard.server.dao.model.sql.TenantDeviceTypeEntity; | 31 | import org.thingsboard.server.dao.model.sql.TenantDeviceTypeEntity; |
32 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; | 32 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
33 | +import org.thingsboard.server.dao.util.SqlDao; | ||
33 | 34 | ||
34 | import java.util.*; | 35 | import java.util.*; |
35 | 36 | ||
36 | -import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; | 37 | +import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUID; |
38 | +import static org.thingsboard.server.common.data.UUIDConverter.fromTimeUUIDs; | ||
39 | +import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID_STR; | ||
37 | 40 | ||
38 | /** | 41 | /** |
39 | * Created by Valerii Sosliuk on 5/6/2017. | 42 | * Created by Valerii Sosliuk on 5/6/2017. |
@@ -51,7 +54,7 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | @@ -51,7 +54,7 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | ||
51 | } | 54 | } |
52 | 55 | ||
53 | @Override | 56 | @Override |
54 | - protected CrudRepository<DeviceEntity, UUID> getCrudRepository() { | 57 | + protected CrudRepository<DeviceEntity, String> getCrudRepository() { |
55 | return deviceRepository; | 58 | return deviceRepository; |
56 | } | 59 | } |
57 | 60 | ||
@@ -59,37 +62,37 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | @@ -59,37 +62,37 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | ||
59 | public List<Device> findDevicesByTenantId(UUID tenantId, TextPageLink pageLink) { | 62 | public List<Device> findDevicesByTenantId(UUID tenantId, TextPageLink pageLink) { |
60 | return DaoUtil.convertDataList( | 63 | return DaoUtil.convertDataList( |
61 | deviceRepository.findByTenantId( | 64 | deviceRepository.findByTenantId( |
62 | - tenantId, | 65 | + fromTimeUUID(tenantId), |
63 | Objects.toString(pageLink.getTextSearch(), ""), | 66 | Objects.toString(pageLink.getTextSearch(), ""), |
64 | - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(), | 67 | + pageLink.getIdOffset() == null ? NULL_UUID_STR : fromTimeUUID(pageLink.getIdOffset()), |
65 | new PageRequest(0, pageLink.getLimit()))); | 68 | new PageRequest(0, pageLink.getLimit()))); |
66 | } | 69 | } |
67 | 70 | ||
68 | @Override | 71 | @Override |
69 | public ListenableFuture<List<Device>> findDevicesByTenantIdAndIdsAsync(UUID tenantId, List<UUID> deviceIds) { | 72 | public ListenableFuture<List<Device>> findDevicesByTenantIdAndIdsAsync(UUID tenantId, List<UUID> deviceIds) { |
70 | - return service.submit(() -> DaoUtil.convertDataList(deviceRepository.findDevicesByTenantIdAndIdIn(tenantId, deviceIds))); | 73 | + return service.submit(() -> DaoUtil.convertDataList(deviceRepository.findDevicesByTenantIdAndIdIn(UUIDConverter.fromTimeUUID(tenantId), fromTimeUUIDs(deviceIds)))); |
71 | } | 74 | } |
72 | 75 | ||
73 | @Override | 76 | @Override |
74 | public List<Device> findDevicesByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) { | 77 | public List<Device> findDevicesByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) { |
75 | return DaoUtil.convertDataList( | 78 | return DaoUtil.convertDataList( |
76 | deviceRepository.findByTenantIdAndCustomerId( | 79 | deviceRepository.findByTenantIdAndCustomerId( |
77 | - tenantId, | ||
78 | - customerId, | 80 | + fromTimeUUID(tenantId), |
81 | + fromTimeUUID(customerId), | ||
79 | Objects.toString(pageLink.getTextSearch(), ""), | 82 | Objects.toString(pageLink.getTextSearch(), ""), |
80 | - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(), | 83 | + pageLink.getIdOffset() == null ? NULL_UUID_STR : fromTimeUUID(pageLink.getIdOffset()), |
81 | new PageRequest(0, pageLink.getLimit()))); | 84 | new PageRequest(0, pageLink.getLimit()))); |
82 | } | 85 | } |
83 | 86 | ||
84 | @Override | 87 | @Override |
85 | public ListenableFuture<List<Device>> findDevicesByTenantIdCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> deviceIds) { | 88 | public ListenableFuture<List<Device>> findDevicesByTenantIdCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> deviceIds) { |
86 | return service.submit(() -> DaoUtil.convertDataList( | 89 | return service.submit(() -> DaoUtil.convertDataList( |
87 | - deviceRepository.findDevicesByTenantIdAndCustomerIdAndIdIn(tenantId, customerId, deviceIds))); | 90 | + deviceRepository.findDevicesByTenantIdAndCustomerIdAndIdIn(fromTimeUUID(tenantId), fromTimeUUID(customerId), fromTimeUUIDs(deviceIds)))); |
88 | } | 91 | } |
89 | 92 | ||
90 | @Override | 93 | @Override |
91 | public Optional<Device> findDeviceByTenantIdAndName(UUID tenantId, String name) { | 94 | public Optional<Device> findDeviceByTenantIdAndName(UUID tenantId, String name) { |
92 | - Device device = DaoUtil.getData(deviceRepository.findByTenantIdAndName(tenantId, name)); | 95 | + Device device = DaoUtil.getData(deviceRepository.findByTenantIdAndName(fromTimeUUID(tenantId), name)); |
93 | return Optional.ofNullable(device); | 96 | return Optional.ofNullable(device); |
94 | } | 97 | } |
95 | 98 | ||
@@ -97,10 +100,10 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | @@ -97,10 +100,10 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | ||
97 | public List<Device> findDevicesByTenantIdAndType(UUID tenantId, String type, TextPageLink pageLink) { | 100 | public List<Device> findDevicesByTenantIdAndType(UUID tenantId, String type, TextPageLink pageLink) { |
98 | return DaoUtil.convertDataList( | 101 | return DaoUtil.convertDataList( |
99 | deviceRepository.findByTenantIdAndType( | 102 | deviceRepository.findByTenantIdAndType( |
100 | - tenantId, | 103 | + fromTimeUUID(tenantId), |
101 | type, | 104 | type, |
102 | Objects.toString(pageLink.getTextSearch(), ""), | 105 | Objects.toString(pageLink.getTextSearch(), ""), |
103 | - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(), | 106 | + pageLink.getIdOffset() == null ? NULL_UUID_STR : fromTimeUUID(pageLink.getIdOffset()), |
104 | new PageRequest(0, pageLink.getLimit()))); | 107 | new PageRequest(0, pageLink.getLimit()))); |
105 | } | 108 | } |
106 | 109 | ||
@@ -108,11 +111,11 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | @@ -108,11 +111,11 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | ||
108 | public List<Device> findDevicesByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, TextPageLink pageLink) { | 111 | public List<Device> findDevicesByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, TextPageLink pageLink) { |
109 | return DaoUtil.convertDataList( | 112 | return DaoUtil.convertDataList( |
110 | deviceRepository.findByTenantIdAndCustomerIdAndType( | 113 | deviceRepository.findByTenantIdAndCustomerIdAndType( |
111 | - tenantId, | ||
112 | - customerId, | 114 | + fromTimeUUID(tenantId), |
115 | + fromTimeUUID(customerId), | ||
113 | type, | 116 | type, |
114 | Objects.toString(pageLink.getTextSearch(), ""), | 117 | Objects.toString(pageLink.getTextSearch(), ""), |
115 | - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(), | 118 | + pageLink.getIdOffset() == null ? NULL_UUID_STR : fromTimeUUID(pageLink.getIdOffset()), |
116 | new PageRequest(0, pageLink.getLimit()))); | 119 | new PageRequest(0, pageLink.getLimit()))); |
117 | } | 120 | } |
118 | 121 | ||
@@ -126,7 +129,7 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | @@ -126,7 +129,7 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> | ||
126 | if (entities != null && !entities.isEmpty()) { | 129 | if (entities != null && !entities.isEmpty()) { |
127 | list = new ArrayList<>(); | 130 | list = new ArrayList<>(); |
128 | for (TenantDeviceTypeEntity entity : entities) { | 131 | for (TenantDeviceTypeEntity entity : entities) { |
129 | - list.add(new TenantDeviceType(entity.getType(), new TenantId(entity.getTenantId()))); | 132 | + list.add(new TenantDeviceType(entity.getType(), new TenantId(UUIDConverter.fromString(entity.getTenantId())))); |
130 | } | 133 | } |
131 | } | 134 | } |
132 | return list; | 135 | return list; |
@@ -21,21 +21,19 @@ import org.thingsboard.server.common.data.EntityType; | @@ -21,21 +21,19 @@ import org.thingsboard.server.common.data.EntityType; | ||
21 | import org.thingsboard.server.dao.model.sql.EventEntity; | 21 | import org.thingsboard.server.dao.model.sql.EventEntity; |
22 | import org.thingsboard.server.dao.util.SqlDao; | 22 | import org.thingsboard.server.dao.util.SqlDao; |
23 | 23 | ||
24 | -import java.util.UUID; | ||
25 | - | ||
26 | /** | 24 | /** |
27 | * Created by Valerii Sosliuk on 5/3/2017. | 25 | * Created by Valerii Sosliuk on 5/3/2017. |
28 | */ | 26 | */ |
29 | @SqlDao | 27 | @SqlDao |
30 | -public interface EventRepository extends CrudRepository<EventEntity, UUID>, JpaSpecificationExecutor<EventEntity> { | 28 | +public interface EventRepository extends CrudRepository<EventEntity, String>, JpaSpecificationExecutor<EventEntity> { |
31 | 29 | ||
32 | - EventEntity findByTenantIdAndEntityTypeAndEntityIdAndEventTypeAndEventUid(UUID tenantId, | 30 | + EventEntity findByTenantIdAndEntityTypeAndEntityIdAndEventTypeAndEventUid(String tenantId, |
33 | EntityType entityType, | 31 | EntityType entityType, |
34 | - UUID entityId, | 32 | + String entityId, |
35 | String eventType, | 33 | String eventType, |
36 | String eventUid); | 34 | String eventUid); |
37 | 35 | ||
38 | - EventEntity findByTenantIdAndEntityTypeAndEntityId(UUID tenantId, | 36 | + EventEntity findByTenantIdAndEntityTypeAndEntityId(String tenantId, |
39 | EntityType entityType, | 37 | EntityType entityType, |
40 | - UUID entityId); | 38 | + String entityId); |
41 | } | 39 | } |
@@ -26,14 +26,15 @@ import org.springframework.data.jpa.domain.Specification; | @@ -26,14 +26,15 @@ import org.springframework.data.jpa.domain.Specification; | ||
26 | import org.springframework.data.repository.CrudRepository; | 26 | import org.springframework.data.repository.CrudRepository; |
27 | import org.springframework.stereotype.Component; | 27 | import org.springframework.stereotype.Component; |
28 | import org.thingsboard.server.common.data.Event; | 28 | import org.thingsboard.server.common.data.Event; |
29 | +import org.thingsboard.server.common.data.UUIDConverter; | ||
29 | import org.thingsboard.server.common.data.id.EntityId; | 30 | import org.thingsboard.server.common.data.id.EntityId; |
30 | import org.thingsboard.server.common.data.id.EventId; | 31 | import org.thingsboard.server.common.data.id.EventId; |
31 | import org.thingsboard.server.common.data.page.TimePageLink; | 32 | import org.thingsboard.server.common.data.page.TimePageLink; |
32 | import org.thingsboard.server.dao.DaoUtil; | 33 | import org.thingsboard.server.dao.DaoUtil; |
33 | -import org.thingsboard.server.dao.util.SqlDao; | ||
34 | import org.thingsboard.server.dao.event.EventDao; | 34 | import org.thingsboard.server.dao.event.EventDao; |
35 | import org.thingsboard.server.dao.model.sql.EventEntity; | 35 | import org.thingsboard.server.dao.model.sql.EventEntity; |
36 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTimeDao; | 36 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTimeDao; |
37 | +import org.thingsboard.server.dao.util.SqlDao; | ||
37 | 38 | ||
38 | import javax.persistence.criteria.CriteriaBuilder; | 39 | import javax.persistence.criteria.CriteriaBuilder; |
39 | import javax.persistence.criteria.CriteriaQuery; | 40 | import javax.persistence.criteria.CriteriaQuery; |
@@ -67,7 +68,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | @@ -67,7 +68,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | ||
67 | } | 68 | } |
68 | 69 | ||
69 | @Override | 70 | @Override |
70 | - protected CrudRepository<EventEntity, UUID> getCrudRepository() { | 71 | + protected CrudRepository<EventEntity, String> getCrudRepository() { |
71 | return eventRepository; | 72 | return eventRepository; |
72 | } | 73 | } |
73 | 74 | ||
@@ -91,7 +92,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | @@ -91,7 +92,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | ||
91 | @Override | 92 | @Override |
92 | public Event findEvent(UUID tenantId, EntityId entityId, String eventType, String eventUid) { | 93 | public Event findEvent(UUID tenantId, EntityId entityId, String eventType, String eventUid) { |
93 | return DaoUtil.getData(eventRepository.findByTenantIdAndEntityTypeAndEntityIdAndEventTypeAndEventUid( | 94 | return DaoUtil.getData(eventRepository.findByTenantIdAndEntityTypeAndEntityIdAndEventTypeAndEventUid( |
94 | - tenantId, entityId.getEntityType(), entityId.getId(), eventType, eventUid)); | 95 | + UUIDConverter.fromTimeUUID(tenantId), entityId.getEntityType(), UUIDConverter.fromTimeUUID(entityId.getId()), eventType, eventUid)); |
95 | } | 96 | } |
96 | 97 | ||
97 | @Override | 98 | @Override |
@@ -112,7 +113,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | @@ -112,7 +113,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | ||
112 | log.debug("Save event [{}] ", entity); | 113 | log.debug("Save event [{}] ", entity); |
113 | if (entity.getTenantId() == null) { | 114 | if (entity.getTenantId() == null) { |
114 | log.trace("Save system event with predefined id {}", systemTenantId); | 115 | log.trace("Save system event with predefined id {}", systemTenantId); |
115 | - entity.setTenantId(systemTenantId); | 116 | + entity.setTenantId(UUIDConverter.fromTimeUUID(systemTenantId)); |
116 | } | 117 | } |
117 | if (entity.getId() == null) { | 118 | if (entity.getId() == null) { |
118 | entity.setId(UUIDs.timeBased()); | 119 | entity.setId(UUIDs.timeBased()); |
@@ -133,13 +134,13 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | @@ -133,13 +134,13 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | ||
133 | public Predicate toPredicate(Root<EventEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) { | 134 | public Predicate toPredicate(Root<EventEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) { |
134 | List<Predicate> predicates = new ArrayList<Predicate>(); | 135 | List<Predicate> predicates = new ArrayList<Predicate>(); |
135 | if (tenantId != null) { | 136 | if (tenantId != null) { |
136 | - Predicate tenantIdPredicate = criteriaBuilder.equal(root.get("tenantId"), tenantId); | 137 | + Predicate tenantIdPredicate = criteriaBuilder.equal(root.get("tenantId"), UUIDConverter.fromTimeUUID(tenantId)); |
137 | predicates.add(tenantIdPredicate); | 138 | predicates.add(tenantIdPredicate); |
138 | } | 139 | } |
139 | if (entityId != null) { | 140 | if (entityId != null) { |
140 | Predicate entityTypePredicate = criteriaBuilder.equal(root.get("entityType"), entityId.getEntityType()); | 141 | Predicate entityTypePredicate = criteriaBuilder.equal(root.get("entityType"), entityId.getEntityType()); |
141 | predicates.add(entityTypePredicate); | 142 | predicates.add(entityTypePredicate); |
142 | - Predicate entityIdPredicate = criteriaBuilder.equal(root.get("entityId"), entityId.getId()); | 143 | + Predicate entityIdPredicate = criteriaBuilder.equal(root.get("entityId"), UUIDConverter.fromTimeUUID(entityId.getId())); |
143 | predicates.add(entityIdPredicate); | 144 | predicates.add(entityIdPredicate); |
144 | } | 145 | } |
145 | if (eventType != null) { | 146 | if (eventType != null) { |