Commit 6206d5fcb2c13852b5c1cd2a03f126bcf4d233df

Authored by Volodymyr Babak
1 parent b91bfddf

Native-query changed to JPA

Showing 40 changed files with 320 additions and 258 deletions
... ... @@ -47,7 +47,7 @@ public final class AdminSettingsEntity implements BaseEntity<AdminSettings> {
47 47 private String key;
48 48
49 49 @Type(type = "json")
50   - @Column(name = ADMIN_SETTINGS_JSON_VALUE_PROPERTY, columnDefinition = "json")
  50 + @Column(name = ADMIN_SETTINGS_JSON_VALUE_PROPERTY)
51 51 private JsonNode jsonValue;
52 52
53 53 public AdminSettingsEntity() {
... ...
... ... @@ -82,7 +82,7 @@ public final class AlarmEntity implements BaseEntity<Alarm> {
82 82 private Long clearTs;
83 83
84 84 @Type(type = "json")
85   - @Column(name = ModelConstants.ASSET_ADDITIONAL_INFO_PROPERTY, columnDefinition = "json")
  85 + @Column(name = ModelConstants.ASSET_ADDITIONAL_INFO_PROPERTY)
86 86 private JsonNode details;
87 87
88 88 @Column(name = ALARM_PROPAGATE_PROPERTY)
... ...
... ... @@ -62,7 +62,7 @@ public final class AssetEntity implements SearchTextEntity<Asset> {
62 62 private String searchText;
63 63
64 64 @Type(type = "json")
65   - @Column(name = ModelConstants.ASSET_ADDITIONAL_INFO_PROPERTY, columnDefinition = "json")
  65 + @Column(name = ModelConstants.ASSET_ADDITIONAL_INFO_PROPERTY)
66 66 private JsonNode additionalInfo;
67 67
68 68 public AssetEntity() {
... ...
... ... @@ -58,7 +58,7 @@ public class ComponentDescriptorEntity implements SearchTextEntity<ComponentDesc
58 58 private String clazz;
59 59
60 60 @Type(type = "json")
61   - @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_CONFIGURATION_DESCRIPTOR_PROPERTY, columnDefinition = "json")
  61 + @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_CONFIGURATION_DESCRIPTOR_PROPERTY)
62 62 private JsonNode configurationDescriptor;
63 63
64 64 @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_ACTIONS_PROPERTY)
... ...
... ... @@ -77,7 +77,7 @@ public final class CustomerEntity implements SearchTextEntity<Customer> {
77 77 private String email;
78 78
79 79 @Type(type = "json")
80   - @Column(name = ModelConstants.CUSTOMER_ADDITIONAL_INFO_PROPERTY, columnDefinition = "json")
  80 + @Column(name = ModelConstants.CUSTOMER_ADDITIONAL_INFO_PROPERTY)
81 81 private JsonNode additionalInfo;
82 82
83 83 public CustomerEntity() {
... ...
... ... @@ -57,7 +57,7 @@ public final class DashboardEntity implements SearchTextEntity<Dashboard> {
57 57 private String searchText;
58 58
59 59 @Type(type = "json")
60   - @Column(name = ModelConstants.DASHBOARD_CONFIGURATION_PROPERTY, columnDefinition = "json")
  60 + @Column(name = ModelConstants.DASHBOARD_CONFIGURATION_PROPERTY)
61 61 private JsonNode configuration;
62 62
63 63 public DashboardEntity() {
... ...
... ... @@ -60,7 +60,7 @@ public final class DeviceEntity implements SearchTextEntity<Device> {
60 60 private String searchText;
61 61
62 62 @Type(type = "json")
63   - @Column(name = ModelConstants.DEVICE_ADDITIONAL_INFO_PROPERTY, columnDefinition = "json")
  63 + @Column(name = ModelConstants.DEVICE_ADDITIONAL_INFO_PROPERTY)
64 64 private JsonNode additionalInfo;
65 65
66 66 public DeviceEntity() {
... ...
... ... @@ -63,7 +63,7 @@ public class EventEntity implements BaseEntity<Event> {
63 63 private String eventUid;
64 64
65 65 @Type(type = "json")
66   - @Column(name = EVENT_BODY_PROPERTY, columnDefinition = "json")
  66 + @Column(name = EVENT_BODY_PROPERTY)
67 67 private JsonNode body;
68 68
69 69 public EventEntity(Event event) {
... ...
... ... @@ -63,11 +63,11 @@ public class PluginMetaDataEntity implements SearchTextEntity<PluginMetaData> {
63 63 private ComponentLifecycleState state;
64 64
65 65 @Type(type = "json")
66   - @Column(name = ModelConstants.PLUGIN_CONFIGURATION_PROPERTY, columnDefinition = "json")
  66 + @Column(name = ModelConstants.PLUGIN_CONFIGURATION_PROPERTY)
67 67 private JsonNode configuration;
68 68
69 69 @Type(type = "json")
70   - @Column(name = ModelConstants.ADDITIONAL_INFO_PROPERTY, columnDefinition = "json")
  70 + @Column(name = ModelConstants.ADDITIONAL_INFO_PROPERTY)
71 71 private JsonNode additionalInfo;
72 72
73 73 @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY)
... ...
... ... @@ -62,7 +62,7 @@ public final class RelationEntity implements ToData<EntityRelation> {
62 62 private String relationType;
63 63
64 64 @Type(type = "json")
65   - @Column(name = ADDITIONAL_INFO_PROPERTY, columnDefinition = "json")
  65 + @Column(name = ADDITIONAL_INFO_PROPERTY)
66 66 private JsonNode additionalInfo;
67 67
68 68 public RelationEntity() {
... ...
... ... @@ -64,19 +64,19 @@ public class RuleMetaDataEntity implements SearchTextEntity<RuleMetaData> {
64 64 private String pluginToken;
65 65
66 66 @Type(type = "json")
67   - @Column(name = ModelConstants.RULE_FILTERS, columnDefinition = "json")
  67 + @Column(name = ModelConstants.RULE_FILTERS)
68 68 private JsonNode filters;
69 69
70 70 @Type(type = "json")
71   - @Column(name = ModelConstants.RULE_PROCESSOR, columnDefinition = "json")
  71 + @Column(name = ModelConstants.RULE_PROCESSOR)
72 72 private JsonNode processor;
73 73
74 74 @Type(type = "json")
75   - @Column(name = ModelConstants.RULE_ACTION, columnDefinition = "json")
  75 + @Column(name = ModelConstants.RULE_ACTION)
76 76 private JsonNode action;
77 77
78 78 @Type(type = "json")
79   - @Column(name = ModelConstants.ADDITIONAL_INFO_PROPERTY, columnDefinition = "json")
  79 + @Column(name = ModelConstants.ADDITIONAL_INFO_PROPERTY)
80 80 private JsonNode additionalInfo;
81 81
82 82 public RuleMetaDataEntity() {
... ...
... ... @@ -76,7 +76,7 @@ public final class TenantEntity implements SearchTextEntity<Tenant> {
76 76 private String email;
77 77
78 78 @Type(type="json")
79   - @Column(name = ModelConstants.TENANT_ADDITIONAL_INFO_PROPERTY, columnDefinition = "json")
  79 + @Column(name = ModelConstants.TENANT_ADDITIONAL_INFO_PROPERTY)
80 80 private JsonNode additionalInfo;
81 81
82 82 public TenantEntity() {
... ...
... ... @@ -70,7 +70,7 @@ public class UserEntity implements SearchTextEntity<User> {
70 70 private String lastName;
71 71
72 72 @Type(type="json")
73   - @Column(name = ModelConstants.USER_ADDITIONAL_INFO_PROPERTY, columnDefinition = "json")
  73 + @Column(name = ModelConstants.USER_ADDITIONAL_INFO_PROPERTY)
74 74 private JsonNode additionalInfo;
75 75
76 76 public UserEntity() {
... ...
... ... @@ -56,7 +56,7 @@ public final class WidgetTypeEntity implements BaseEntity<WidgetType> {
56 56 private String name;
57 57
58 58 @Type(type="json")
59   - @Column(name = ModelConstants.WIDGET_TYPE_DESCRIPTOR_PROPERTY, columnDefinition = "json")
  59 + @Column(name = ModelConstants.WIDGET_TYPE_DESCRIPTOR_PROPERTY)
60 60 private JsonNode descriptor;
61 61
62 62 public WidgetTypeEntity() {
... ...
... ... @@ -51,9 +51,6 @@ public final class WidgetsBundleEntity implements SearchTextEntity<WidgetsBundle
51 51 @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY)
52 52 private String searchText;
53 53
54   - @Column(name = ModelConstants.WIDGETS_BUNDLE_IMAGE_PROPERTY)
55   - private byte[] image;
56   -
57 54 public WidgetsBundleEntity() {
58 55 super();
59 56 }
... ... @@ -67,9 +64,6 @@ public final class WidgetsBundleEntity implements SearchTextEntity<WidgetsBundle
67 64 }
68 65 this.alias = widgetsBundle.getAlias();
69 66 this.title = widgetsBundle.getTitle();
70   - if (widgetsBundle.getImage() != null) {
71   - this.image = widgetsBundle.getImage();
72   - }
73 67 }
74 68
75 69 @Override
... ... @@ -101,7 +95,6 @@ public final class WidgetsBundleEntity implements SearchTextEntity<WidgetsBundle
101 95 }
102 96 widgetsBundle.setAlias(alias);
103 97 widgetsBundle.setTitle(title);
104   - widgetsBundle.setImage(image);
105 98 return widgetsBundle;
106 99 }
107 100 }
... ...
... ... @@ -15,12 +15,15 @@
15 15 */
16 16 package org.thingsboard.server.dao.sql.alarm;
17 17
  18 +import org.springframework.data.domain.Pageable;
18 19 import org.springframework.data.jpa.repository.Query;
19 20 import org.springframework.data.repository.CrudRepository;
20 21 import org.springframework.data.repository.query.Param;
  22 +import org.thingsboard.server.common.data.EntityType;
21 23 import org.thingsboard.server.dao.annotation.SqlDao;
22 24 import org.thingsboard.server.dao.model.sql.AlarmEntity;
23 25
  26 +import java.util.List;
24 27 import java.util.UUID;
25 28
26 29 /**
... ... @@ -29,10 +32,11 @@ import java.util.UUID;
29 32 @SqlDao
30 33 public interface AlarmRepository extends CrudRepository<AlarmEntity, UUID> {
31 34
32   - @Query(nativeQuery = true, value = "SELECT * FROM ALARM WHERE TENANT_ID = :tenantId AND ORIGINATOR_ID = :originatorId " +
33   - "AND ORIGINATOR_TYPE = :entityType AND TYPE = :alarmType ORDER BY TYPE ASC, ID DESC LIMIT 1")
34   - AlarmEntity findLatestByOriginatorAndType(@Param("tenantId") UUID tenantId,
35   - @Param("originatorId") UUID originatorId,
36   - @Param("entityType") int entityType,
37   - @Param("alarmType") String alarmType);
  35 + @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")
  37 + List<AlarmEntity> findLatestByOriginatorAndType(@Param("tenantId") UUID tenantId,
  38 + @Param("originatorId") UUID originatorId,
  39 + @Param("entityType") EntityType entityType,
  40 + @Param("alarmType") String alarmType,
  41 + Pageable pageable);
38 42 }
... ...
... ... @@ -21,6 +21,7 @@ import com.google.common.util.concurrent.Futures;
21 21 import com.google.common.util.concurrent.ListenableFuture;
22 22 import lombok.extern.slf4j.Slf4j;
23 23 import org.springframework.beans.factory.annotation.Autowired;
  24 +import org.springframework.data.domain.PageRequest;
24 25 import org.springframework.data.repository.CrudRepository;
25 26 import org.springframework.stereotype.Component;
26 27 import org.springframework.transaction.annotation.Transactional;
... ... @@ -74,12 +75,15 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A
74 75 @Override
75 76 @Transactional(propagation = REQUIRES_NEW)
76 77 public ListenableFuture<Alarm> findLatestByOriginatorAndType(TenantId tenantId, EntityId originator, String type) {
77   - return service.submit(() ->
78   - DaoUtil.getData(alarmRepository.findLatestByOriginatorAndType(
79   - tenantId.getId(),
80   - originator.getId(),
81   - originator.getEntityType().ordinal(),
82   - type)));
  78 + return service.submit(() -> {
  79 + List<AlarmEntity> latest = alarmRepository.findLatestByOriginatorAndType(
  80 + tenantId.getId(),
  81 + originator.getId(),
  82 + originator.getEntityType(),
  83 + type,
  84 + new PageRequest(0, 1));
  85 + return latest.isEmpty() ? null : DaoUtil.getData(latest.get(0));
  86 + });
83 87 }
84 88
85 89 @Override
... ...
... ... @@ -15,6 +15,8 @@
15 15 */
16 16 package org.thingsboard.server.dao.sql.asset;
17 17
  18 +import org.springframework.data.domain.Page;
  19 +import org.springframework.data.domain.Pageable;
18 20 import org.springframework.data.jpa.repository.Query;
19 21 import org.springframework.data.repository.CrudRepository;
20 22 import org.springframework.data.repository.query.Param;
... ... @@ -31,23 +33,23 @@ import java.util.UUID;
31 33 @SqlDao
32 34 public interface AssetRepository extends CrudRepository<AssetEntity, UUID> {
33 35
34   - @Query(nativeQuery = true, value = "SELECT * FROM ASSET WHERE TENANT_ID = :tenantId " +
35   - "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(:textSearch, '%')) " +
36   - "AND ID > :idOffset ORDER BY ID LIMIT :limit")
37   - List<AssetEntity> findByTenantId(@Param("limit") int limit,
38   - @Param("tenantId") UUID tenantId,
  36 + @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " +
  37 + "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " +
  38 + "AND a.id > :idOffset ORDER BY a.id")
  39 + List<AssetEntity> findByTenantId(@Param("tenantId") UUID tenantId,
39 40 @Param("textSearch") String textSearch,
40   - @Param("idOffset") UUID idOffset);
  41 + @Param("idOffset") UUID idOffset,
  42 + Pageable pageable);
41 43
42   - @Query(nativeQuery = true, value = "SELECT * FROM ASSET WHERE TENANT_ID = :tenantId " +
43   - "AND CUSTOMER_ID = :customerId " +
44   - "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(:textSearch, '%')) " +
45   - "AND ID > :idOffset ORDER BY ID LIMIT :limit")
46   - List<AssetEntity> findByTenantIdAndCustomerId(@Param("limit") int limit,
47   - @Param("tenantId") UUID tenantId,
  44 + @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " +
  45 + "AND a.customerId = :customerId " +
  46 + "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " +
  47 + "AND a.id > :idOffset ORDER BY a.id")
  48 + List<AssetEntity> findByTenantIdAndCustomerId(@Param("tenantId") UUID tenantId,
48 49 @Param("customerId") UUID customerId,
49 50 @Param("textSearch") String textSearch,
50   - @Param("idOffset") UUID idOffset);
  51 + @Param("idOffset") UUID idOffset,
  52 + Pageable pageable);
51 53
52 54 List<AssetEntity> findByTenantIdAndIdIn(UUID tenantId, List<UUID> assetIds);
53 55
... ... @@ -55,27 +57,27 @@ public interface AssetRepository extends CrudRepository<AssetEntity, UUID> {
55 57
56 58 AssetEntity findByTenantIdAndName(UUID tenantId, String name);
57 59
58   - @Query(nativeQuery = true, value = "SELECT * FROM ASSET WHERE TENANT_ID = :tenantId " +
59   - "AND TYPE = :type " +
60   - "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(:textSearch, '%')) " +
61   - "AND ID > :idOffset ORDER BY ID LIMIT :limit")
62   - List<AssetEntity> findByTenantIdAndType(@Param("limit") int limit,
63   - @Param("tenantId") UUID tenantId,
  60 + @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " +
  61 + "AND a.type = :type " +
  62 + "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " +
  63 + "AND a.id > :idOffset ORDER BY a.id")
  64 + List<AssetEntity> findByTenantIdAndType(@Param("tenantId") UUID tenantId,
64 65 @Param("type") String type,
65 66 @Param("textSearch") String textSearch,
66   - @Param("idOffset") UUID idOffset);
  67 + @Param("idOffset") UUID idOffset,
  68 + Pageable pageable);
67 69
68   - @Query(nativeQuery = true, value = "SELECT * FROM ASSET WHERE TENANT_ID = :tenantId " +
69   - "AND CUSTOMER_ID = :customerId AND TYPE = :type " +
70   - "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(:textSearch, '%')) " +
71   - "AND ID > :idOffset ORDER BY ID LIMIT :limit")
72   - List<AssetEntity> findByTenantIdAndCustomerIdAndType(@Param("limit") int limit,
73   - @Param("tenantId") UUID tenantId,
  70 + @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " +
  71 + "AND a.customerId = :customerId AND a.type = :type " +
  72 + "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " +
  73 + "AND a.id > :idOffset ORDER BY a.id")
  74 + List<AssetEntity> findByTenantIdAndCustomerIdAndType(@Param("tenantId") UUID tenantId,
74 75 @Param("customerId") UUID customerId,
75 76 @Param("type") String type,
76 77 @Param("textSearch") String textSearch,
77   - @Param("idOffset") UUID idOffset);
  78 + @Param("idOffset") UUID idOffset,
  79 + Pageable pageable);
78 80
79   - @Query(value = "SELECT NEW org.thingsboard.server.common.data.asset.TenantAssetType(a.type, a.tenantId) FROM AssetEntity a GROUP BY a.tenantId, a.type")
  81 + @Query("SELECT NEW org.thingsboard.server.common.data.asset.TenantAssetType(a.type, a.tenantId) FROM AssetEntity a GROUP BY a.tenantId, a.type")
80 82 List<TenantAssetType> findTenantAssetTypes();
81 83 }
... ...
... ... @@ -17,6 +17,7 @@ package org.thingsboard.server.dao.sql.asset;
17 17
18 18 import com.google.common.util.concurrent.ListenableFuture;
19 19 import org.springframework.beans.factory.annotation.Autowired;
  20 +import org.springframework.data.domain.PageRequest;
20 21 import org.springframework.data.repository.CrudRepository;
21 22 import org.springframework.stereotype.Component;
22 23 import org.thingsboard.server.common.data.asset.Asset;
... ... @@ -29,6 +30,7 @@ import org.thingsboard.server.dao.model.sql.AssetEntity;
29 30 import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
30 31
31 32 import java.util.List;
  33 +import java.util.Objects;
32 34 import java.util.Optional;
33 35 import java.util.UUID;
34 36
... ... @@ -58,10 +60,10 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im
58 60 public List<Asset> findAssetsByTenantId(UUID tenantId, TextPageLink pageLink) {
59 61 return DaoUtil.convertDataList(assetRepository
60 62 .findByTenantId(
61   - pageLink.getLimit(),
62 63 tenantId,
63   - pageLink.getTextSearch(),
64   - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset()));
  64 + Objects.toString(pageLink.getTextSearch(), ""),
  65 + pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
  66 + new PageRequest(0, pageLink.getLimit())));
65 67 }
66 68
67 69 @Override
... ... @@ -74,11 +76,11 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im
74 76 public List<Asset> findAssetsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) {
75 77 return DaoUtil.convertDataList(assetRepository
76 78 .findByTenantIdAndCustomerId(
77   - pageLink.getLimit(),
78 79 tenantId,
79 80 customerId,
80   - pageLink.getTextSearch(),
81   - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset()));
  81 + Objects.toString(pageLink.getTextSearch(), ""),
  82 + pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
  83 + new PageRequest(0, pageLink.getLimit())));
82 84 }
83 85
84 86 @Override
... ... @@ -97,23 +99,23 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im
97 99 public List<Asset> findAssetsByTenantIdAndType(UUID tenantId, String type, TextPageLink pageLink) {
98 100 return DaoUtil.convertDataList(assetRepository
99 101 .findByTenantIdAndType(
100   - pageLink.getLimit(),
101 102 tenantId,
102 103 type,
103   - pageLink.getTextSearch(),
104   - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset()));
  104 + Objects.toString(pageLink.getTextSearch(), ""),
  105 + pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
  106 + new PageRequest(0, pageLink.getLimit())));
105 107 }
106 108
107 109 @Override
108 110 public List<Asset> findAssetsByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, TextPageLink pageLink) {
109 111 return DaoUtil.convertDataList(assetRepository
110 112 .findByTenantIdAndCustomerIdAndType(
111   - pageLink.getLimit(),
112 113 tenantId,
113 114 customerId,
114 115 type,
115   - pageLink.getTextSearch(),
116   - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset()));
  116 + Objects.toString(pageLink.getTextSearch(), ""),
  117 + pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
  118 + new PageRequest(0, pageLink.getLimit())));
117 119 }
118 120
119 121 @Override
... ...
... ... @@ -15,6 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.sql.component;
17 17
  18 +import org.springframework.data.domain.Pageable;
18 19 import org.springframework.data.jpa.repository.Query;
19 20 import org.springframework.data.repository.CrudRepository;
20 21 import org.springframework.data.repository.query.Param;
... ... @@ -32,22 +33,22 @@ public interface ComponentDescriptorRepository extends CrudRepository<ComponentD
32 33
33 34 ComponentDescriptorEntity findByClazz(String clazz);
34 35
35   - @Query(nativeQuery = true, value = "SELECT * FROM COMPONENT_DESCRIPTOR WHERE TYPE = :type " +
36   - "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(:textSearch, '%')) " +
37   - "AND ID > :idOffset ORDER BY ID LIMIT :limit")
38   - List<ComponentDescriptorEntity> findByType(@Param("limit") int limit,
39   - @Param("type") String type,
  36 + @Query("SELECT cd FROM ComponentDescriptorEntity cd WHERE cd.type = :type " +
  37 + "AND LOWER(cd.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " +
  38 + "AND cd.id > :idOffset ORDER BY cd.id")
  39 + List<ComponentDescriptorEntity> findByType(@Param("type") String type,
40 40 @Param("textSearch") String textSearch,
41   - @Param("idOffset") UUID idOffset);
  41 + @Param("idOffset") UUID idOffset,
  42 + Pageable pageable);
42 43
43   - @Query(nativeQuery = true, value = "SELECT * FROM COMPONENT_DESCRIPTOR WHERE TYPE = :type " +
44   - "AND SCOPE = :scope AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(:textSearch, '%')) " +
45   - "AND ID > :idOffset ORDER BY ID LIMIT :limit")
46   - List<ComponentDescriptorEntity> findByScopeAndType(@Param("limit") int limit,
47   - @Param("type") String type,
  44 + @Query("SELECT cd FROM ComponentDescriptorEntity cd WHERE cd.type = :type " +
  45 + "AND cd.scope = :scope AND LOWER(cd.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " +
  46 + "AND cd.id > :idOffset ORDER BY cd.id")
  47 + List<ComponentDescriptorEntity> findByScopeAndType(@Param("type") String type,
48 48 @Param("scope") String scope,
49 49 @Param("textSearch") String textSearch,
50   - @Param("idOffset") UUID idOffset);
  50 + @Param("idOffset") UUID idOffset,
  51 + Pageable pageable);
51 52
52 53 void deleteByClazz(String clazz);
53 54 }
... ...
... ... @@ -17,6 +17,7 @@ package org.thingsboard.server.dao.sql.component;
17 17
18 18 import com.datastax.driver.core.utils.UUIDs;
19 19 import org.springframework.beans.factory.annotation.Autowired;
  20 +import org.springframework.data.domain.PageRequest;
20 21 import org.springframework.data.repository.CrudRepository;
21 22 import org.springframework.stereotype.Component;
22 23 import org.thingsboard.server.common.data.id.ComponentDescriptorId;
... ... @@ -31,6 +32,7 @@ import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity;
31 32 import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
32 33
33 34 import java.util.List;
  35 +import java.util.Objects;
34 36 import java.util.Optional;
35 37 import java.util.UUID;
36 38
... ... @@ -83,21 +85,21 @@ public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<Comp
83 85 public List<ComponentDescriptor> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink) {
84 86 return DaoUtil.convertDataList(componentDescriptorRepository
85 87 .findByType(
86   - pageLink.getLimit(),
87 88 type.toString(),
88   - pageLink.getTextSearch(),
89   - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset()));
  89 + Objects.toString(pageLink.getTextSearch(), ""),
  90 + pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
  91 + new PageRequest(0, pageLink.getLimit())));
90 92 }
91 93
92 94 @Override
93 95 public List<ComponentDescriptor> findByScopeAndTypeAndPageLink(ComponentScope scope, ComponentType type, TextPageLink pageLink) {
94 96 return DaoUtil.convertDataList(componentDescriptorRepository
95 97 .findByScopeAndType(
96   - pageLink.getLimit(),
97 98 type.toString(),
98 99 scope.toString(),
99   - pageLink.getTextSearch(),
100   - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset()));
  100 + Objects.toString(pageLink.getTextSearch(), ""),
  101 + pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
  102 + new PageRequest(0, pageLink.getLimit())));
101 103 }
102 104
103 105 @Override
... ...
... ... @@ -15,6 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.sql.customer;
17 17
  18 +import org.springframework.data.domain.Pageable;
18 19 import org.springframework.data.jpa.repository.Query;
19 20 import org.springframework.data.repository.CrudRepository;
20 21 import org.springframework.data.repository.query.Param;
... ... @@ -30,13 +31,13 @@ import java.util.UUID;
30 31 @SqlDao
31 32 public interface CustomerRepository extends CrudRepository<CustomerEntity, UUID> {
32 33
33   - @Query(nativeQuery = true, value = "SELECT * FROM CUSTOMER WHERE TENANT_ID = :tenantId " +
34   - "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(:textSearch, '%')) " +
35   - "AND ID > :idOffset ORDER BY ID LIMIT :limit")
36   - List<CustomerEntity> findByTenantId(@Param("limit") int limit,
37   - @Param("tenantId") UUID tenantId,
  34 + @Query("SELECT c FROM CustomerEntity c WHERE c.tenantId = :tenantId " +
  35 + "AND LOWER(c.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " +
  36 + "AND c.id > :idOffset ORDER BY c.id")
  37 + List<CustomerEntity> findByTenantId(@Param("tenantId") UUID tenantId,
38 38 @Param("textSearch") String textSearch,
39   - @Param("idOffset") UUID idOffset);
  39 + @Param("idOffset") UUID idOffset,
  40 + Pageable pageable);
40 41
41 42 CustomerEntity findByTenantIdAndTitle(UUID tenantId, String title);
42 43
... ...
... ... @@ -16,6 +16,7 @@
16 16 package org.thingsboard.server.dao.sql.customer;
17 17
18 18 import org.springframework.beans.factory.annotation.Autowired;
  19 +import org.springframework.data.domain.PageRequest;
19 20 import org.springframework.data.repository.CrudRepository;
20 21 import org.springframework.stereotype.Component;
21 22 import org.thingsboard.server.common.data.Customer;
... ... @@ -27,6 +28,7 @@ import org.thingsboard.server.dao.model.sql.CustomerEntity;
27 28 import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
28 29
29 30 import java.util.List;
  31 +import java.util.Objects;
30 32 import java.util.Optional;
31 33 import java.util.UUID;
32 34
... ... @@ -54,8 +56,11 @@ public class JpaCustomerDao extends JpaAbstractSearchTextDao<CustomerEntity, Cus
54 56
55 57 @Override
56 58 public List<Customer> findCustomersByTenantId(UUID tenantId, TextPageLink pageLink) {
57   - return DaoUtil.convertDataList(customerRepository.findByTenantId(pageLink.getLimit(), tenantId,
58   - pageLink.getTextSearch(), pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset()));
  59 + return DaoUtil.convertDataList(customerRepository.findByTenantId(
  60 + tenantId,
  61 + Objects.toString(pageLink.getTextSearch(), ""),
  62 + pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
  63 + new PageRequest(0, pageLink.getLimit())));
59 64 }
60 65
61 66 @Override
... ...
... ... @@ -15,6 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.sql.dashboard;
17 17
  18 +import org.springframework.data.domain.Pageable;
18 19 import org.springframework.data.jpa.repository.Query;
19 20 import org.springframework.data.repository.CrudRepository;
20 21 import org.springframework.data.repository.query.Param;
... ... @@ -30,20 +31,20 @@ import java.util.UUID;
30 31 @SqlDao
31 32 public interface DashboardInfoRepository extends CrudRepository<DashboardInfoEntity, UUID> {
32 33
33   - @Query(nativeQuery = true, value = "SELECT * FROM DASHBOARD WHERE TENANT_ID = :tenantId " +
34   - "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(:textSearch, '%')) " +
35   - "AND ID > :idOffset ORDER BY ID LIMIT :limit")
36   - List<DashboardInfoEntity> findByTenantId(@Param("limit") int limit,
37   - @Param("tenantId") UUID tenantId,
38   - @Param("textSearch") String textSearch,
39   - @Param("idOffset") UUID idOffset);
  34 + @Query("SELECT di FROM DashboardInfoEntity di WHERE di.tenantId = :tenantId " +
  35 + "AND LOWER(di.searchText) LIKE LOWER(CONCAT(:searchText, '%')) " +
  36 + "AND di.id > :idOffset ORDER BY di.id")
  37 + List<DashboardInfoEntity> findByTenantId(@Param("tenantId") UUID tenantId,
  38 + @Param("searchText") String searchText,
  39 + @Param("idOffset") UUID idOffset,
  40 + Pageable pageable);
40 41
41   - @Query(nativeQuery = true, value = "SELECT * FROM DASHBOARD WHERE TENANT_ID = :tenantId " +
42   - "AND CUSTOMER_ID = :customerId AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(:textSearch, '%')) " +
43   - "AND ID > :idOffset ORDER BY ID LIMIT :limit")
44   - List<DashboardInfoEntity> findByTenantIdAndCustomerId(@Param("limit") int limit,
45   - @Param("tenantId") UUID 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, '%')) " +
  44 + "AND di.id > :idOffset ORDER BY di.id")
  45 + List<DashboardInfoEntity> findByTenantIdAndCustomerId(@Param("tenantId") UUID tenantId,
46 46 @Param("customerId") UUID customerId,
47   - @Param("textSearch") String textSearch,
48   - @Param("idOffset") UUID idOffset);
  47 + @Param("searchText") String searchText,
  48 + @Param("idOffset") UUID idOffset,
  49 + Pageable pageable);
49 50 }
... ...
... ... @@ -16,6 +16,7 @@
16 16 package org.thingsboard.server.dao.sql.dashboard;
17 17
18 18 import org.springframework.beans.factory.annotation.Autowired;
  19 +import org.springframework.data.domain.PageRequest;
19 20 import org.springframework.data.repository.CrudRepository;
20 21 import org.springframework.stereotype.Component;
21 22 import org.thingsboard.server.common.data.DashboardInfo;
... ... @@ -27,6 +28,7 @@ import org.thingsboard.server.dao.model.sql.DashboardInfoEntity;
27 28 import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
28 29
29 30 import java.util.List;
  31 +import java.util.Objects;
30 32 import java.util.UUID;
31 33
32 34 import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
... ... @@ -55,20 +57,20 @@ public class JpaDashboardInfoDao extends JpaAbstractSearchTextDao<DashboardInfoE
55 57 public List<DashboardInfo> findDashboardsByTenantId(UUID tenantId, TextPageLink pageLink) {
56 58 return DaoUtil.convertDataList(dashboardInfoRepository
57 59 .findByTenantId(
58   - pageLink.getLimit(),
59 60 tenantId,
60   - pageLink.getTextSearch(),
61   - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset()));
  61 + Objects.toString(pageLink.getTextSearch(), ""),
  62 + pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
  63 + new PageRequest(0, pageLink.getLimit())));
62 64 }
63 65
64 66 @Override
65 67 public List<DashboardInfo> findDashboardsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) {
66 68 return DaoUtil.convertDataList(dashboardInfoRepository
67 69 .findByTenantIdAndCustomerId(
68   - pageLink.getLimit(),
69 70 tenantId,
70 71 customerId,
71   - pageLink.getTextSearch(),
72   - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset()));
  72 + Objects.toString(pageLink.getTextSearch(), ""),
  73 + pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
  74 + new PageRequest(0, pageLink.getLimit())));
73 75 }
74 76 }
... ...
... ... @@ -15,6 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.sql.device;
17 17
  18 +import org.springframework.data.domain.Pageable;
18 19 import org.springframework.data.jpa.repository.Query;
19 20 import org.springframework.data.repository.CrudRepository;
20 21 import org.springframework.data.repository.query.Param;
... ... @@ -32,47 +33,47 @@ import java.util.UUID;
32 33 public interface DeviceRepository extends CrudRepository<DeviceEntity, UUID> {
33 34
34 35
35   - @Query(nativeQuery = true, value = "SELECT * FROM DEVICE WHERE TENANT_ID = :tenantId " +
36   - "AND CUSTOMER_ID = :customerId " +
37   - "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(:searchText, '%')) " +
38   - "AND ID > :idOffset ORDER BY ID LIMIT :limit")
39   - List<DeviceEntity> findByTenantIdAndCustomerId(@Param("limit") int limit,
40   - @Param("tenantId") UUID tenantId,
  36 + @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " +
  37 + "AND d.customerId = :customerId " +
  38 + "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:searchText, '%')) " +
  39 + "AND d.id > :idOffset ORDER BY d.id")
  40 + List<DeviceEntity> findByTenantIdAndCustomerId(@Param("tenantId") UUID tenantId,
41 41 @Param("customerId") UUID customerId,
42 42 @Param("searchText") String searchText,
43   - @Param("idOffset") UUID idOffset);
  43 + @Param("idOffset") UUID idOffset,
  44 + Pageable pageable);
44 45
45   - @Query(nativeQuery = true, value = "SELECT * FROM DEVICE WHERE TENANT_ID = :tenantId " +
46   - "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(:textSearch, '%')) " +
47   - "AND ID > :idOffset ORDER BY ID LIMIT :limit")
48   - List<DeviceEntity> findByTenantId(@Param("limit") int limit,
49   - @Param("tenantId") UUID tenantId,
  46 + @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " +
  47 + "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " +
  48 + "AND d.id > :idOffset ORDER BY d.id")
  49 + List<DeviceEntity> findByTenantId(@Param("tenantId") UUID tenantId,
50 50 @Param("textSearch") String textSearch,
51   - @Param("idOffset") UUID idOffset);
  51 + @Param("idOffset") UUID idOffset,
  52 + Pageable pageable);
52 53
53   - @Query(nativeQuery = true, value = "SELECT * FROM DEVICE WHERE TENANT_ID = :tenantId " +
54   - "AND TYPE = :type " +
55   - "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(:textSearch, '%')) " +
56   - "AND ID > :idOffset ORDER BY ID LIMIT :limit")
57   - List<DeviceEntity> findByTenantIdAndType(@Param("limit") int limit,
58   - @Param("tenantId") UUID tenantId,
  54 + @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " +
  55 + "AND d.type = :type " +
  56 + "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " +
  57 + "AND d.id > :idOffset ORDER BY d.id")
  58 + List<DeviceEntity> findByTenantIdAndType(@Param("tenantId") UUID tenantId,
59 59 @Param("type") String type,
60 60 @Param("textSearch") String textSearch,
61   - @Param("idOffset") UUID idOffset);
  61 + @Param("idOffset") UUID idOffset,
  62 + Pageable pageable);
62 63
63   - @Query(nativeQuery = true, value = "SELECT * FROM DEVICE WHERE TENANT_ID = :tenantId " +
64   - "AND CUSTOMER_ID = :customerId " +
65   - "AND TYPE = :type " +
66   - "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(:textSearch, '%')) " +
67   - "AND ID > :idOffset ORDER BY ID LIMIT :limit")
68   - List<DeviceEntity> findByTenantIdAndCustomerIdAndType(@Param("limit") int limit,
69   - @Param("tenantId") UUID tenantId,
  64 + @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId " +
  65 + "AND d.customerId = :customerId " +
  66 + "AND d.type = :type " +
  67 + "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " +
  68 + "AND d.id > :idOffset ORDER BY d.id")
  69 + List<DeviceEntity> findByTenantIdAndCustomerIdAndType(@Param("tenantId") UUID tenantId,
70 70 @Param("customerId") UUID customerId,
71 71 @Param("type") String type,
72 72 @Param("textSearch") String textSearch,
73   - @Param("idOffset") UUID idOffset);
  73 + @Param("idOffset") UUID idOffset,
  74 + Pageable pageable);
74 75
75   - @Query(value = "SELECT DISTINCT NEW org.thingsboard.server.dao.model.sql.TenantDeviceTypeEntity(d.tenantId, d.type) FROM DeviceEntity d")
  76 + @Query("SELECT DISTINCT NEW org.thingsboard.server.dao.model.sql.TenantDeviceTypeEntity(d.tenantId, d.type) FROM DeviceEntity d")
76 77 List<TenantDeviceTypeEntity> findTenantDeviceTypes();
77 78
78 79 DeviceEntity findByTenantIdAndName(UUID tenantId, String name);
... ...
... ... @@ -17,6 +17,7 @@ package org.thingsboard.server.dao.sql.device;
17 17
18 18 import com.google.common.util.concurrent.ListenableFuture;
19 19 import org.springframework.beans.factory.annotation.Autowired;
  20 +import org.springframework.data.domain.PageRequest;
20 21 import org.springframework.data.repository.CrudRepository;
21 22 import org.springframework.stereotype.Component;
22 23 import org.thingsboard.server.common.data.Device;
... ... @@ -58,11 +59,10 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device>
58 59 public List<Device> findDevicesByTenantId(UUID tenantId, TextPageLink pageLink) {
59 60 return DaoUtil.convertDataList(
60 61 deviceRepository.findByTenantId(
61   - pageLink.getLimit(),
62 62 tenantId,
63   - pageLink.getTextSearch(),
64   - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset())
65   - );
  63 + Objects.toString(pageLink.getTextSearch(), ""),
  64 + pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
  65 + new PageRequest(0, pageLink.getLimit())));
66 66 }
67 67
68 68 @Override
... ... @@ -74,12 +74,11 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device>
74 74 public List<Device> findDevicesByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) {
75 75 return DaoUtil.convertDataList(
76 76 deviceRepository.findByTenantIdAndCustomerId(
77   - pageLink.getLimit(),
78 77 tenantId,
79 78 customerId,
80   - pageLink.getTextSearch(),
81   - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset())
82   - );
  79 + Objects.toString(pageLink.getTextSearch(), ""),
  80 + pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
  81 + new PageRequest(0, pageLink.getLimit())));
83 82 }
84 83
85 84 @Override
... ... @@ -98,25 +97,23 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device>
98 97 public List<Device> findDevicesByTenantIdAndType(UUID tenantId, String type, TextPageLink pageLink) {
99 98 return DaoUtil.convertDataList(
100 99 deviceRepository.findByTenantIdAndType(
101   - pageLink.getLimit(),
102 100 tenantId,
103 101 type,
104   - pageLink.getTextSearch(),
105   - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset())
106   - );
  102 + Objects.toString(pageLink.getTextSearch(), ""),
  103 + pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
  104 + new PageRequest(0, pageLink.getLimit())));
107 105 }
108 106
109 107 @Override
110 108 public List<Device> findDevicesByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, TextPageLink pageLink) {
111 109 return DaoUtil.convertDataList(
112 110 deviceRepository.findByTenantIdAndCustomerIdAndType(
113   - pageLink.getLimit(),
114 111 tenantId,
115 112 customerId,
116 113 type,
117   - pageLink.getTextSearch(),
118   - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset())
119   - );
  114 + Objects.toString(pageLink.getTextSearch(), ""),
  115 + pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
  116 + new PageRequest(0, pageLink.getLimit())));
120 117 }
121 118
122 119 @Override
... ...
... ... @@ -17,6 +17,7 @@ package org.thingsboard.server.dao.sql.plugin;
17 17
18 18 import lombok.extern.slf4j.Slf4j;
19 19 import org.springframework.beans.factory.annotation.Autowired;
  20 +import org.springframework.data.domain.PageRequest;
20 21 import org.springframework.data.repository.CrudRepository;
21 22 import org.springframework.stereotype.Component;
22 23 import org.thingsboard.server.common.data.id.PluginId;
... ... @@ -31,6 +32,7 @@ import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
31 32
32 33 import java.util.Arrays;
33 34 import java.util.List;
  35 +import java.util.Objects;
34 36 import java.util.UUID;
35 37
36 38 import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
... ... @@ -96,10 +98,10 @@ public class JpaBasePluginDao extends JpaAbstractSearchTextDao<PluginMetaDataEnt
96 98 log.debug("Try to find plugins by tenantId [{}] and pageLink [{}]", tenantId, pageLink);
97 99 List<PluginMetaDataEntity> entities = pluginMetaDataRepository
98 100 .findByTenantIdAndPageLink(
99   - pageLink.getLimit(),
100 101 tenantId.getId(),
101   - pageLink.getTextSearch(),
102   - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset());
  102 + Objects.toString(pageLink.getTextSearch(), ""),
  103 + pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
  104 + new PageRequest(0, pageLink.getLimit()));
103 105 if (log.isTraceEnabled()) {
104 106 log.trace("Search result: [{}]", Arrays.toString(entities.toArray()));
105 107 } else {
... ... @@ -113,11 +115,11 @@ public class JpaBasePluginDao extends JpaAbstractSearchTextDao<PluginMetaDataEnt
113 115 log.debug("Try to find all tenant plugins by tenantId [{}] and pageLink [{}]", tenantId, pageLink);
114 116 List<PluginMetaDataEntity> entities = pluginMetaDataRepository
115 117 .findAllTenantPluginsByTenantId(
116   - pageLink.getLimit(),
117 118 tenantId,
118 119 NULL_UUID,
119   - pageLink.getTextSearch(),
120   - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset());
  120 + Objects.toString(pageLink.getTextSearch(), ""),
  121 + pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
  122 + new PageRequest(0, pageLink.getLimit()));
121 123 if (log.isTraceEnabled()) {
122 124 log.trace("Search result: [{}]", Arrays.toString(entities.toArray()));
123 125 } else {
... ...
... ... @@ -15,6 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.sql.plugin;
17 17
  18 +import org.springframework.data.domain.Pageable;
18 19 import org.springframework.data.jpa.repository.Query;
19 20 import org.springframework.data.repository.CrudRepository;
20 21 import org.springframework.data.repository.query.Param;
... ... @@ -32,20 +33,20 @@ public interface PluginMetaDataRepository extends CrudRepository<PluginMetaDataE
32 33
33 34 PluginMetaDataEntity findByApiToken(String apiToken);
34 35
35   - @Query(nativeQuery = true, value = "SELECT * FROM PLUGIN WHERE TENANT_ID = :tenantId " +
36   - "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(:textSearch, '%')) " +
37   - "AND ID > :idOffset ORDER BY ID LIMIT :limit")
38   - List<PluginMetaDataEntity> findByTenantIdAndPageLink(@Param("limit") int limit,
39   - @Param("tenantId") UUID tenantId,
  36 + @Query("SELECT pmd FROM PluginMetaDataEntity pmd WHERE pmd.tenantId = :tenantId " +
  37 + "AND LOWER(pmd.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " +
  38 + "AND pmd.id > :idOffset ORDER BY pmd.id")
  39 + List<PluginMetaDataEntity> findByTenantIdAndPageLink(@Param("tenantId") UUID tenantId,
40 40 @Param("textSearch") String textSearch,
41   - @Param("idOffset") UUID idOffset);
  41 + @Param("idOffset") UUID idOffset,
  42 + Pageable pageable);
42 43
43   - @Query(nativeQuery = true, value = "SELECT * FROM PLUGIN WHERE TENANT_ID IN (:tenantId, :nullTenantId) " +
44   - "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(:textSearch, '%')) " +
45   - "AND ID > :idOffset ORDER BY ID LIMIT :limit")
46   - List<PluginMetaDataEntity> findAllTenantPluginsByTenantId(@Param("limit") int limit,
47   - @Param("tenantId") UUID tenantId,
  44 + @Query("SELECT pmd FROM PluginMetaDataEntity pmd WHERE pmd.tenantId IN (:tenantId, :nullTenantId) " +
  45 + "AND LOWER(pmd.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " +
  46 + "AND pmd.id > :idOffset ORDER BY pmd.id")
  47 + List<PluginMetaDataEntity> findAllTenantPluginsByTenantId(@Param("tenantId") UUID tenantId,
48 48 @Param("nullTenantId") UUID nullTenantId,
49 49 @Param("textSearch") String textSearch,
50   - @Param("idOffset") UUID idOffset);
  50 + @Param("idOffset") UUID idOffset,
  51 + Pageable pageable);
51 52 }
... ...
... ... @@ -17,6 +17,7 @@ package org.thingsboard.server.dao.sql.rule;
17 17
18 18 import lombok.extern.slf4j.Slf4j;
19 19 import org.springframework.beans.factory.annotation.Autowired;
  20 +import org.springframework.data.domain.PageRequest;
20 21 import org.springframework.data.repository.CrudRepository;
21 22 import org.springframework.stereotype.Component;
22 23 import org.thingsboard.server.common.data.id.RuleId;
... ... @@ -31,6 +32,7 @@ import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
31 32
32 33 import java.util.Arrays;
33 34 import java.util.List;
  35 +import java.util.Objects;
34 36 import java.util.UUID;
35 37
36 38 import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
... ... @@ -73,10 +75,10 @@ public class JpaBaseRuleDao extends JpaAbstractSearchTextDao<RuleMetaDataEntity,
73 75 List<RuleMetaDataEntity> entities =
74 76 ruleMetaDataRepository
75 77 .findByTenantIdAndPageLink(
76   - pageLink.getLimit(),
77 78 tenantId.getId(),
78   - pageLink.getTextSearch(),
79   - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset());
  79 + Objects.toString(pageLink.getTextSearch(), ""),
  80 + pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
  81 + new PageRequest(0, pageLink.getLimit()));
80 82 if (log.isTraceEnabled()) {
81 83 log.trace("Search result: [{}]", Arrays.toString(entities.toArray()));
82 84 } else {
... ... @@ -91,11 +93,11 @@ public class JpaBaseRuleDao extends JpaAbstractSearchTextDao<RuleMetaDataEntity,
91 93 List<RuleMetaDataEntity> entities =
92 94 ruleMetaDataRepository
93 95 .findAllTenantRulesByTenantId(
94   - pageLink.getLimit(),
95 96 tenantId,
96 97 NULL_UUID,
97   - pageLink.getTextSearch(),
98   - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset());
  98 + Objects.toString(pageLink.getTextSearch(), ""),
  99 + pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
  100 + new PageRequest(0, pageLink.getLimit()));
99 101
100 102 if (log.isTraceEnabled()) {
101 103 log.trace("Search result: [{}]", Arrays.toString(entities.toArray()));
... ...
... ... @@ -15,6 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.sql.rule;
17 17
  18 +import org.springframework.data.domain.Pageable;
18 19 import org.springframework.data.jpa.repository.Query;
19 20 import org.springframework.data.repository.CrudRepository;
20 21 import org.springframework.data.repository.query.Param;
... ... @@ -32,20 +33,20 @@ public interface RuleMetaDataRepository extends CrudRepository<RuleMetaDataEntit
32 33
33 34 List<RuleMetaDataEntity> findByPluginToken(String pluginToken);
34 35
35   - @Query(nativeQuery = true, value = "SELECT * FROM RULE WHERE TENANT_ID = :tenantId " +
36   - "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(:textSearch, '%')) " +
37   - "AND ID > :idOffset ORDER BY ID LIMIT :limit")
38   - List<RuleMetaDataEntity> findByTenantIdAndPageLink(@Param("limit") int limit,
39   - @Param("tenantId") UUID tenantId,
  36 + @Query("SELECT rmd FROM RuleMetaDataEntity rmd WHERE rmd.tenantId = :tenantId " +
  37 + "AND LOWER(rmd.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " +
  38 + "AND rmd.id > :idOffset ORDER BY rmd.id")
  39 + List<RuleMetaDataEntity> findByTenantIdAndPageLink(@Param("tenantId") UUID tenantId,
40 40 @Param("textSearch") String textSearch,
41   - @Param("idOffset") UUID idOffset);
  41 + @Param("idOffset") UUID idOffset,
  42 + Pageable pageable);
42 43
43   - @Query(nativeQuery = true, value = "SELECT * FROM RULE WHERE TENANT_ID IN (:tenantId, :nullTenantId) " +
44   - "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(:textSearch, '%')) " +
45   - "AND ID > :idOffset ORDER BY ID LIMIT :limit")
46   - List<RuleMetaDataEntity> findAllTenantRulesByTenantId(@Param("limit") int limit,
47   - @Param("tenantId") UUID tenantId,
  44 + @Query("SELECT rmd FROM RuleMetaDataEntity rmd WHERE rmd.tenantId IN (:tenantId, :nullTenantId) " +
  45 + "AND LOWER(rmd.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " +
  46 + "AND rmd.id > :idOffset ORDER BY rmd.id")
  47 + List<RuleMetaDataEntity> findAllTenantRulesByTenantId(@Param("tenantId") UUID tenantId,
48 48 @Param("nullTenantId") UUID nullTenantId,
49 49 @Param("textSearch") String textSearch,
50   - @Param("idOffset") UUID idOffset);
  50 + @Param("idOffset") UUID idOffset,
  51 + Pageable pageable);
51 52 }
... ...
... ... @@ -16,6 +16,7 @@
16 16 package org.thingsboard.server.dao.sql.tenant;
17 17
18 18 import org.springframework.beans.factory.annotation.Autowired;
  19 +import org.springframework.data.domain.PageRequest;
19 20 import org.springframework.data.repository.CrudRepository;
20 21 import org.springframework.stereotype.Component;
21 22 import org.thingsboard.server.common.data.Tenant;
... ... @@ -27,6 +28,7 @@ import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
27 28 import org.thingsboard.server.dao.tenant.TenantDao;
28 29
29 30 import java.util.List;
  31 +import java.util.Objects;
30 32 import java.util.UUID;
31 33
32 34 import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
... ... @@ -55,9 +57,9 @@ public class JpaTenantDao extends JpaAbstractSearchTextDao<TenantEntity, Tenant>
55 57 public List<Tenant> findTenantsByRegion(String region, TextPageLink pageLink) {
56 58 return DaoUtil.convertDataList(tenantRepository
57 59 .findByRegionNextPage(
58   - pageLink.getLimit(),
59 60 region,
60   - pageLink.getTextSearch(),
61   - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset()));
  61 + Objects.toString(pageLink.getTextSearch(), ""),
  62 + pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
  63 + new PageRequest(0, pageLink.getLimit())));
62 64 }
63 65 }
... ...
... ... @@ -15,6 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.sql.tenant;
17 17
  18 +import org.springframework.data.domain.Pageable;
18 19 import org.springframework.data.jpa.repository.Query;
19 20 import org.springframework.data.repository.CrudRepository;
20 21 import org.springframework.data.repository.query.Param;
... ... @@ -30,11 +31,11 @@ import java.util.UUID;
30 31 @SqlDao
31 32 public interface TenantRepository extends CrudRepository<TenantEntity, UUID> {
32 33
33   - @Query(nativeQuery = true, value = "SELECT * FROM TENANT WHERE REGION = :region " +
34   - "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(:textSearch, '%')) " +
35   - "AND ID > :idOffset ORDER BY ID LIMIT :limit")
36   - List<TenantEntity> findByRegionNextPage(@Param("limit") int limit,
37   - @Param("region") String region,
  34 + @Query("SELECT t FROM TenantEntity t WHERE t.region = :region " +
  35 + "AND LOWER(t.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " +
  36 + "AND t.id > :idOffset ORDER BY t.id")
  37 + List<TenantEntity> findByRegionNextPage(@Param("region") String region,
38 38 @Param("textSearch") String textSearch,
39   - @Param("idOffset") UUID idOffset);
  39 + @Param("idOffset") UUID idOffset,
  40 + Pageable pageable);
40 41 }
... ...
... ... @@ -15,12 +15,15 @@
15 15 */
16 16 package org.thingsboard.server.dao.sql.timeseries;
17 17
  18 +import com.google.common.base.Function;
18 19 import com.google.common.collect.Lists;
  20 +import com.google.common.util.concurrent.Futures;
19 21 import com.google.common.util.concurrent.ListenableFuture;
20 22 import lombok.extern.slf4j.Slf4j;
21 23 import org.springframework.beans.factory.annotation.Autowired;
22 24 import org.springframework.stereotype.Component;
23 25 import org.thingsboard.server.common.data.id.EntityId;
  26 +import org.thingsboard.server.common.data.kv.Aggregation;
24 27 import org.thingsboard.server.common.data.kv.TsKvEntry;
25 28 import org.thingsboard.server.common.data.kv.TsKvQuery;
26 29 import org.thingsboard.server.dao.DaoUtil;
... ... @@ -31,7 +34,9 @@ import org.thingsboard.server.dao.model.sql.TsKvLatestEntity;
31 34 import org.thingsboard.server.dao.sql.JpaAbstractDaoListeningExecutorService;
32 35 import org.thingsboard.server.dao.timeseries.TimeseriesDao;
33 36
  37 +import javax.annotation.Nullable;
34 38 import java.util.List;
  39 +import java.util.stream.Collectors;
35 40
36 41 @Component
37 42 @Slf4j
... ... @@ -46,12 +51,34 @@ public class JpaTimeseriesDao extends JpaAbstractDaoListeningExecutorService imp
46 51
47 52 @Override
48 53 public ListenableFuture<List<TsKvEntry>> findAllAsync(EntityId entityId, List<TsKvQuery> queries) {
49   - // TODO - Add implementation
50   - return service.submit(() -> null);
  54 + List<ListenableFuture<List<TsKvEntry>>> futures = queries
  55 + .stream()
  56 + .map(query -> findAllAsync(entityId, query))
  57 + .collect(Collectors.toList());
  58 + return Futures.transform(Futures.allAsList(futures), new Function<List<List<TsKvEntry>>, List<TsKvEntry>>() {
  59 + @Nullable
  60 + @Override
  61 + public List<TsKvEntry> apply(@Nullable List<List<TsKvEntry>> results) {
  62 + if (results == null || results.isEmpty()) {
  63 + return null;
  64 + }
  65 + return results.stream()
  66 + .flatMap(List::stream)
  67 + .collect(Collectors.toList());
  68 + }
  69 + }, service);
51 70 }
52 71
53 72 private ListenableFuture<List<TsKvEntry>> findAllAsync(EntityId entityId, TsKvQuery query) {
54   - return null;
  73 + if (query.getAggregation() == Aggregation.NONE) {
  74 + return findAllAsyncWithLimit(entityId, query);
  75 + } else {
  76 + return service.submit(() -> null);
  77 + }
  78 + }
  79 +
  80 + private ListenableFuture<List<TsKvEntry>> findAllAsyncWithLimit(EntityId entityId, TsKvQuery query) {
  81 + return service.submit(() -> null);
55 82 }
56 83
57 84 @Override
... ...
... ... @@ -16,6 +16,7 @@
16 16 package org.thingsboard.server.dao.sql.user;
17 17
18 18 import org.springframework.beans.factory.annotation.Autowired;
  19 +import org.springframework.data.domain.PageRequest;
19 20 import org.springframework.data.repository.CrudRepository;
20 21 import org.springframework.stereotype.Component;
21 22 import org.thingsboard.server.common.data.User;
... ... @@ -24,11 +25,11 @@ import org.thingsboard.server.common.data.security.Authority;
24 25 import org.thingsboard.server.dao.DaoUtil;
25 26 import org.thingsboard.server.dao.annotation.SqlDao;
26 27 import org.thingsboard.server.dao.model.sql.UserEntity;
27   -import org.thingsboard.server.dao.sql.JpaAbstractDao;
28 28 import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
29 29 import org.thingsboard.server.dao.user.UserDao;
30 30
31 31 import java.util.List;
  32 +import java.util.Objects;
32 33 import java.util.UUID;
33 34
34 35 import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
... ... @@ -66,9 +67,9 @@ public class JpaUserDao extends JpaAbstractSearchTextDao<UserEntity, User> imple
66 67 tenantId,
67 68 NULL_UUID,
68 69 pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
69   - pageLink.getTextSearch(),
70   - Authority.TENANT_ADMIN.name(),
71   - pageLink.getLimit()));
  70 + Objects.toString(pageLink.getTextSearch(), ""),
  71 + Authority.TENANT_ADMIN,
  72 + new PageRequest(0, pageLink.getLimit())));
72 73 }
73 74
74 75 @Override
... ... @@ -79,9 +80,9 @@ public class JpaUserDao extends JpaAbstractSearchTextDao<UserEntity, User> imple
79 80 tenantId,
80 81 customerId,
81 82 pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
82   - pageLink.getTextSearch(),
83   - Authority.CUSTOMER_USER.name(),
84   - pageLink.getLimit()));
  83 + Objects.toString(pageLink.getTextSearch(), ""),
  84 + Authority.CUSTOMER_USER,
  85 + new PageRequest(0, pageLink.getLimit())));
85 86
86 87 }
87 88 }
... ...
... ... @@ -15,9 +15,11 @@
15 15 */
16 16 package org.thingsboard.server.dao.sql.user;
17 17
  18 +import org.springframework.data.domain.Pageable;
18 19 import org.springframework.data.jpa.repository.Query;
19 20 import org.springframework.data.repository.CrudRepository;
20 21 import org.springframework.data.repository.query.Param;
  22 +import org.thingsboard.server.common.data.security.Authority;
21 23 import org.thingsboard.server.dao.annotation.SqlDao;
22 24 import org.thingsboard.server.dao.model.sql.UserEntity;
23 25
... ... @@ -32,15 +34,15 @@ public interface UserRepository extends CrudRepository<UserEntity, UUID> {
32 34
33 35 UserEntity findByEmail(String email);
34 36
35   - @Query(nativeQuery = true, value = "SELECT * FROM TB_USER WHERE TENANT_ID = :tenantId " +
36   - "AND CUSTOMER_ID = :customerId AND AUTHORITY = :authority " +
37   - "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(:searchText, '%'))" +
38   - "AND ID > :idOffset ORDER BY ID LIMIT :limit")
  37 + @Query("SELECT u FROM UserEntity u WHERE u.tenantId = :tenantId " +
  38 + "AND u.customerId = :customerId AND u.authority = :authority " +
  39 + "AND LOWER(u.searchText) LIKE LOWER(CONCAT(:searchText, '%'))" +
  40 + "AND u.id > :idOffset ORDER BY u.id")
39 41 List<UserEntity> findUsersByAuthority(@Param("tenantId") UUID tenantId,
40 42 @Param("customerId") UUID customerId,
41 43 @Param("idOffset") UUID idOffset,
42 44 @Param("searchText") String searchText,
43   - @Param("authority") String authority,
44   - @Param("limit") int limit);
  45 + @Param("authority") Authority authority,
  46 + Pageable pageable);
45 47
46 48 }
\ No newline at end of file
... ...
... ... @@ -16,6 +16,7 @@
16 16 package org.thingsboard.server.dao.sql.widget;
17 17
18 18 import org.springframework.beans.factory.annotation.Autowired;
  19 +import org.springframework.data.domain.PageRequest;
19 20 import org.springframework.data.repository.CrudRepository;
20 21 import org.springframework.stereotype.Component;
21 22 import org.thingsboard.server.common.data.page.TextPageLink;
... ... @@ -27,6 +28,7 @@ import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
27 28 import org.thingsboard.server.dao.widget.WidgetsBundleDao;
28 29
29 30 import java.util.List;
  31 +import java.util.Objects;
30 32 import java.util.UUID;
31 33
32 34 import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
... ... @@ -61,10 +63,10 @@ public class JpaWidgetsBundleDao extends JpaAbstractSearchTextDao<WidgetsBundleE
61 63 return DaoUtil.convertDataList(
62 64 widgetsBundleRepository
63 65 .findSystemWidgetsBundles(
64   - pageLink.getLimit(),
65 66 NULL_UUID,
66   - pageLink.getTextSearch(),
67   - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset()));
  67 + Objects.toString(pageLink.getTextSearch(), ""),
  68 + pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
  69 + new PageRequest(0, pageLink.getLimit())));
68 70 }
69 71
70 72 @Override
... ... @@ -72,10 +74,10 @@ public class JpaWidgetsBundleDao extends JpaAbstractSearchTextDao<WidgetsBundleE
72 74 return DaoUtil.convertDataList(
73 75 widgetsBundleRepository
74 76 .findTenantWidgetsBundlesByTenantId(
75   - pageLink.getLimit(),
76 77 tenantId,
77   - pageLink.getTextSearch(),
78   - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset()));
  78 + Objects.toString(pageLink.getTextSearch(), ""),
  79 + pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
  80 + new PageRequest(0, pageLink.getLimit())));
79 81 }
80 82
81 83 @Override
... ... @@ -83,10 +85,10 @@ public class JpaWidgetsBundleDao extends JpaAbstractSearchTextDao<WidgetsBundleE
83 85 return DaoUtil.convertDataList(
84 86 widgetsBundleRepository
85 87 .findAllTenantWidgetsBundlesByTenantId(
86   - pageLink.getLimit(),
87 88 tenantId,
88 89 NULL_UUID,
89   - pageLink.getTextSearch(),
90   - pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset()));
  90 + Objects.toString(pageLink.getTextSearch(), ""),
  91 + pageLink.getIdOffset() == null ? NULL_UUID : pageLink.getIdOffset(),
  92 + new PageRequest(0, pageLink.getLimit())));
91 93 }
92 94 }
... ...
... ... @@ -15,6 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.sql.widget;
17 17
  18 +import org.springframework.data.domain.Pageable;
18 19 import org.springframework.data.jpa.repository.Query;
19 20 import org.springframework.data.repository.CrudRepository;
20 21 import org.springframework.data.repository.query.Param;
... ... @@ -32,28 +33,28 @@ public interface WidgetsBundleRepository extends CrudRepository<WidgetsBundleEnt
32 33
33 34 WidgetsBundleEntity findWidgetsBundleByTenantIdAndAlias(UUID tenantId, String alias);
34 35
35   - @Query(nativeQuery = true, value = "SELECT * FROM WIDGETS_BUNDLE WHERE TENANT_ID = :systemTenantId " +
36   - "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(:searchText, '%')) " +
37   - "AND ID > :idOffset ORDER BY ID LIMIT :limit")
38   - List<WidgetsBundleEntity> findSystemWidgetsBundles(@Param("limit") int limit,
39   - @Param("systemTenantId") UUID systemTenantId,
  36 + @Query("SELECT wb FROM WidgetsBundleEntity wb WHERE wb.tenantId = :systemTenantId " +
  37 + "AND LOWER(wb.searchText) LIKE LOWER(CONCAT(:searchText, '%')) " +
  38 + "AND wb.id > :idOffset ORDER BY wb.id")
  39 + List<WidgetsBundleEntity> findSystemWidgetsBundles(@Param("systemTenantId") UUID systemTenantId,
40 40 @Param("searchText") String searchText,
41   - @Param("idOffset") UUID idOffset);
  41 + @Param("idOffset") UUID idOffset,
  42 + Pageable pageable);
42 43
43   - @Query(nativeQuery = true, value = "SELECT * FROM WIDGETS_BUNDLE WHERE TENANT_ID = :tenantId " +
44   - "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(:textSearch, '%')) " +
45   - "AND ID > :idOffset ORDER BY ID LIMIT :limit")
46   - List<WidgetsBundleEntity> findTenantWidgetsBundlesByTenantId(@Param("limit") int limit,
47   - @Param("tenantId") UUID tenantId,
  44 + @Query("SELECT wb FROM WidgetsBundleEntity wb WHERE wb.tenantId = :tenantId " +
  45 + "AND LOWER(wb.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " +
  46 + "AND wb.id > :idOffset ORDER BY wb.id")
  47 + List<WidgetsBundleEntity> findTenantWidgetsBundlesByTenantId(@Param("tenantId") UUID tenantId,
48 48 @Param("textSearch") String textSearch,
49   - @Param("idOffset") UUID idOffset);
  49 + @Param("idOffset") UUID idOffset,
  50 + Pageable pageable);
50 51
51   - @Query(nativeQuery = true, value = "SELECT * FROM WIDGETS_BUNDLE WHERE TENANT_ID IN (:tenantId, :nullTenantId) " +
52   - "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(:textSearch, '%')) " +
53   - "AND ID > :idOffset ORDER BY ID LIMIT :limit")
54   - List<WidgetsBundleEntity> findAllTenantWidgetsBundlesByTenantId(@Param("limit") int limit,
55   - @Param("tenantId") UUID tenantId,
  52 + @Query("SELECT wb FROM WidgetsBundleEntity wb WHERE wb.tenantId IN (:tenantId, :nullTenantId) " +
  53 + "AND LOWER(wb.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " +
  54 + "AND wb.id > :idOffset ORDER BY wb.id")
  55 + List<WidgetsBundleEntity> findAllTenantWidgetsBundlesByTenantId(@Param("tenantId") UUID tenantId,
56 56 @Param("nullTenantId") UUID nullTenantId,
57 57 @Param("textSearch") String textSearch,
58   - @Param("idOffset") UUID idOffset);
  58 + @Param("idOffset") UUID idOffset,
  59 + Pageable pageable);
59 60 }
... ...
... ... @@ -18,6 +18,7 @@ package org.thingsboard.server.dao.sql.alarm;
18 18 import com.google.common.util.concurrent.ListenableFuture;
19 19 import org.junit.Test;
20 20 import org.springframework.beans.factory.annotation.Autowired;
  21 +import org.springframework.data.domain.PageRequest;
21 22 import org.thingsboard.server.common.data.EntityType;
22 23 import org.thingsboard.server.common.data.alarm.Alarm;
23 24 import org.thingsboard.server.common.data.alarm.AlarmId;
... ... @@ -59,7 +60,7 @@ public class JpaAlarmDaoTest extends AbstractJpaDaoTest {
59 60 saveAlarm(alarm3Id, tenantId, originator2Id, "TEST_ALARM");
60 61 assertEquals(3, alarmDao.find().size());
61 62 AlarmEntity alarmEntity = alarmRepository.findLatestByOriginatorAndType(
62   - tenantId, originator1Id, EntityType.DEVICE.ordinal(), "TEST_ALARM");
  63 + tenantId, originator1Id, EntityType.DEVICE, "TEST_ALARM", new PageRequest(0, 1)).get(0);
63 64 assertNotNull(alarmEntity);
64 65 ListenableFuture<Alarm> future = alarmDao
65 66 .findLatestByOriginatorAndType(new TenantId(tenantId), new DeviceId(originator1Id), "TEST_ALARM");
... ...
... ... @@ -7,4 +7,8 @@ spring.jpa.hibernate.ddl-auto=validate
7 7
8 8 spring.datasource.url=jdbc:postgresql://localhost:5432/thingsboard
9 9 spring.datasource.username=postgres
10   -spring.datasource.password=postgres
\ No newline at end of file
  10 +spring.datasource.password=postgres
  11 +
  12 +#spring.datasource.url=jdbc:h2:mem:test;MODE=PostgreSQL
  13 +#spring.datasource.schema=classpath:postgres/schema.sql
  14 +#spring.datasource.data=classpath:postgres/system-data.sql;classpath:system-test.sql
\ No newline at end of file
... ...