Commit 9def2e21d555a3bc58965f670294abfe5bef4120

Authored by mp-loki
1 parent 63988199

Entity DAOs

Showing 20 changed files with 737 additions and 265 deletions
... ... @@ -22,15 +22,21 @@ import javax.persistence.Id;
22 22 import javax.persistence.Table;
23 23 import javax.persistence.Transient;
24 24 import com.fasterxml.jackson.databind.JsonNode;
  25 +import com.fasterxml.jackson.databind.ObjectMapper;
  26 +import lombok.Data;
  27 +import lombok.extern.slf4j.Slf4j;
25 28 import org.thingsboard.server.common.data.AdminSettings;
26 29 import org.thingsboard.server.common.data.id.AdminSettingsId;
27 30 import org.thingsboard.server.dao.model.BaseEntity;
28 31
  32 +import java.io.IOException;
29 33 import java.util.UUID;
30 34
31 35 import static org.thingsboard.server.dao.model.ModelConstants.*;
32 36
33   -//@Entity
  37 +@Data
  38 +@Slf4j
  39 +@Entity
34 40 @Table(name = ADMIN_SETTINGS_COLUMN_FAMILY_NAME)
35 41 public final class AdminSettingsEntity implements BaseEntity<AdminSettings> {
36 42
... ... @@ -45,7 +51,7 @@ public final class AdminSettingsEntity implements BaseEntity<AdminSettings> {
45 51 private String key;
46 52
47 53 @Column(name = ADMIN_SETTINGS_JSON_VALUE_PROPERTY)
48   - private JsonNode jsonValue;
  54 + private String jsonValue;
49 55
50 56 public AdminSettingsEntity() {
51 57 super();
... ... @@ -56,33 +62,21 @@ public final class AdminSettingsEntity implements BaseEntity<AdminSettings> {
56 62 this.id = adminSettings.getId().getId();
57 63 }
58 64 this.key = adminSettings.getKey();
59   - this.jsonValue = adminSettings.getJsonValue();
  65 + if (jsonValue != null) {
  66 + this.jsonValue = adminSettings.getJsonValue().toString();
  67 + }
60 68 }
61   -
  69 +
  70 + @Override
62 71 public UUID getId() {
63 72 return id;
64 73 }
65 74
  75 + @Override
66 76 public void setId(UUID id) {
67 77 this.id = id;
68 78 }
69 79
70   - public String getKey() {
71   - return key;
72   - }
73   -
74   - public void setKey(String key) {
75   - this.key = key;
76   - }
77   -
78   - public JsonNode getJsonValue() {
79   - return jsonValue;
80   - }
81   -
82   - public void setJsonValue(JsonNode jsonValue) {
83   - this.jsonValue = jsonValue;
84   - }
85   -
86 80 @Override
87 81 public int hashCode() {
88 82 final int prime = 31;
... ... @@ -138,7 +132,16 @@ public final class AdminSettingsEntity implements BaseEntity<AdminSettings> {
138 132 AdminSettings adminSettings = new AdminSettings(new AdminSettingsId(id));
139 133 adminSettings.setCreatedTime(UUIDs.unixTimestamp(id));
140 134 adminSettings.setKey(key);
141   - adminSettings.setJsonValue(jsonValue);
  135 + if (jsonValue != null) {
  136 + ObjectMapper mapper = new ObjectMapper();
  137 + JsonNode jsonNode = null;
  138 + try {
  139 + jsonNode = mapper.readTree(jsonValue);
  140 + adminSettings.setJsonValue(jsonNode);
  141 + } catch (IOException e) {
  142 + log.error(e.getMessage(), e);
  143 + }
  144 + }
142 145 return adminSettings;
143 146 }
144 147
... ...
... ... @@ -21,6 +21,9 @@ import javax.persistence.Id;
21 21 import javax.persistence.Table;
22 22 import javax.persistence.Transient;
23 23 import com.fasterxml.jackson.databind.JsonNode;
  24 +import com.fasterxml.jackson.databind.ObjectMapper;
  25 +import lombok.Data;
  26 +import lombok.extern.slf4j.Slf4j;
24 27 import org.thingsboard.server.common.data.id.ComponentDescriptorId;
25 28 import org.thingsboard.server.common.data.plugin.ComponentDescriptor;
26 29 import org.thingsboard.server.common.data.plugin.ComponentScope;
... ... @@ -28,12 +31,12 @@ import org.thingsboard.server.common.data.plugin.ComponentType;
28 31 import org.thingsboard.server.dao.model.ModelConstants;
29 32 import org.thingsboard.server.dao.model.SearchTextEntity;
30 33
  34 +import java.io.IOException;
31 35 import java.util.UUID;
32 36
33   -/**
34   - * @author Andrew Shvayka
35   - */
36   -//@Entity
  37 +@Data
  38 +@Slf4j
  39 +@Entity
37 40 @Table(name = ModelConstants.COMPONENT_DESCRIPTOR_COLUMN_FAMILY_NAME)
38 41 public class ComponentDescriptorEntity implements SearchTextEntity<ComponentDescriptor> {
39 42
... ... @@ -57,7 +60,7 @@ public class ComponentDescriptorEntity implements SearchTextEntity<ComponentDesc
57 60 private String clazz;
58 61
59 62 @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_CONFIGURATION_DESCRIPTOR_PROPERTY)
60   - private JsonNode configurationDescriptor;
  63 + private String configurationDescriptor;
61 64
62 65 @Column(name = ModelConstants.COMPONENT_DESCRIPTOR_ACTIONS_PROPERTY)
63 66 private String actions;
... ... @@ -77,7 +80,9 @@ public class ComponentDescriptorEntity implements SearchTextEntity<ComponentDesc
77 80 this.scope = component.getScope();
78 81 this.name = component.getName();
79 82 this.clazz = component.getClazz();
80   - this.configurationDescriptor = component.getConfigurationDescriptor();
  83 + if (configurationDescriptor != null) {
  84 + this.configurationDescriptor = component.getConfigurationDescriptor().toString();
  85 + }
81 86 this.searchText = component.getName();
82 87 }
83 88
... ... @@ -89,7 +94,16 @@ public class ComponentDescriptorEntity implements SearchTextEntity<ComponentDesc
89 94 data.setName(this.getName());
90 95 data.setClazz(this.getClazz());
91 96 data.setActions(this.getActions());
92   - data.setConfigurationDescriptor(this.getConfigurationDescriptor());
  97 + if (configurationDescriptor != null) {
  98 + ObjectMapper mapper = new ObjectMapper();
  99 + JsonNode jsonNode = null;
  100 + try {
  101 + jsonNode = mapper.readTree(configurationDescriptor);
  102 + data.setConfigurationDescriptor(jsonNode);
  103 + } catch (IOException e) {
  104 + log.error(e.getMessage(), e);
  105 + }
  106 + }
93 107 return data;
94 108 }
95 109
... ... @@ -103,54 +117,6 @@ public class ComponentDescriptorEntity implements SearchTextEntity<ComponentDesc
103 117 this.id = id;
104 118 }
105 119
106   - public String getActions() {
107   - return actions;
108   - }
109   -
110   - public void setActions(String actions) {
111   - this.actions = actions;
112   - }
113   -
114   - public ComponentType getType() {
115   - return type;
116   - }
117   -
118   - public void setType(ComponentType type) {
119   - this.type = type;
120   - }
121   -
122   - public ComponentScope getScope() {
123   - return scope;
124   - }
125   -
126   - public void setScope(ComponentScope scope) {
127   - this.scope = scope;
128   - }
129   -
130   - public String getName() {
131   - return name;
132   - }
133   -
134   - public void setName(String name) {
135   - this.name = name;
136   - }
137   -
138   - public String getClazz() {
139   - return clazz;
140   - }
141   -
142   - public void setClazz(String clazz) {
143   - this.clazz = clazz;
144   - }
145   -
146   - public JsonNode getConfigurationDescriptor() {
147   - return configurationDescriptor;
148   - }
149   -
150   - public void setConfigurationDescriptor(JsonNode configurationDescriptor) {
151   - this.configurationDescriptor = configurationDescriptor;
152   - }
153   -
154 120 public String getSearchText() {
155 121 return searchText;
156 122 }
... ...
... ... @@ -22,15 +22,21 @@ import javax.persistence.Id;
22 22 import javax.persistence.Table;
23 23 import javax.persistence.Transient;
24 24 import com.fasterxml.jackson.databind.JsonNode;
  25 +import com.fasterxml.jackson.databind.ObjectMapper;
  26 +import lombok.Data;
  27 +import lombok.extern.slf4j.Slf4j;
25 28 import org.thingsboard.server.common.data.Customer;
26 29 import org.thingsboard.server.common.data.id.CustomerId;
27 30 import org.thingsboard.server.common.data.id.TenantId;
28 31 import org.thingsboard.server.dao.model.ModelConstants;
29 32 import org.thingsboard.server.dao.model.SearchTextEntity;
30 33
  34 +import java.io.IOException;
31 35 import java.util.UUID;
32 36
33   -//@Entity
  37 +@Data
  38 +@Slf4j
  39 +@Entity
34 40 @Table(name = ModelConstants.CUSTOMER_COLUMN_FAMILY_NAME)
35 41 public final class CustomerEntity implements SearchTextEntity<Customer> {
36 42
... ... @@ -75,7 +81,7 @@ public final class CustomerEntity implements SearchTextEntity<Customer> {
75 81 private String email;
76 82
77 83 @Column(name = ModelConstants.CUSTOMER_ADDITIONAL_INFO_PROPERTY)
78   - private JsonNode additionalInfo;
  84 + private String additionalInfo;
79 85
80 86 public CustomerEntity() {
81 87 super();
... ... @@ -95,105 +101,21 @@ public final class CustomerEntity implements SearchTextEntity<Customer> {
95 101 this.zip = customer.getZip();
96 102 this.phone = customer.getPhone();
97 103 this.email = customer.getEmail();
98   - this.additionalInfo = customer.getAdditionalInfo();
  104 + if (additionalInfo != null) {
  105 + this.additionalInfo = customer.getAdditionalInfo().toString();
  106 + }
99 107 }
100   -
  108 +
  109 + @Override
101 110 public UUID getId() {
102 111 return id;
103 112 }
104 113
  114 + @Override
105 115 public void setId(UUID id) {
106 116 this.id = id;
107 117 }
108 118
109   - public UUID getTenantId() {
110   - return tenantId;
111   - }
112   -
113   - public void setTenantId(UUID tenantId) {
114   - this.tenantId = tenantId;
115   - }
116   -
117   - public String getTitle() {
118   - return title;
119   - }
120   -
121   - public void setTitle(String title) {
122   - this.title = title;
123   - }
124   -
125   - public String getCountry() {
126   - return country;
127   - }
128   -
129   - public void setCountry(String country) {
130   - this.country = country;
131   - }
132   -
133   - public String getState() {
134   - return state;
135   - }
136   -
137   - public void setState(String state) {
138   - this.state = state;
139   - }
140   -
141   - public String getCity() {
142   - return city;
143   - }
144   -
145   - public void setCity(String city) {
146   - this.city = city;
147   - }
148   -
149   - public String getAddress() {
150   - return address;
151   - }
152   -
153   - public void setAddress(String address) {
154   - this.address = address;
155   - }
156   -
157   - public String getAddress2() {
158   - return address2;
159   - }
160   -
161   - public void setAddress2(String address2) {
162   - this.address2 = address2;
163   - }
164   -
165   - public String getZip() {
166   - return zip;
167   - }
168   -
169   - public void setZip(String zip) {
170   - this.zip = zip;
171   - }
172   -
173   - public String getPhone() {
174   - return phone;
175   - }
176   -
177   - public void setPhone(String phone) {
178   - this.phone = phone;
179   - }
180   -
181   - public String getEmail() {
182   - return email;
183   - }
184   -
185   - public void setEmail(String email) {
186   - this.email = email;
187   - }
188   -
189   - public JsonNode getAdditionalInfo() {
190   - return additionalInfo;
191   - }
192   -
193   - public void setAdditionalInfo(JsonNode additionalInfo) {
194   - this.additionalInfo = additionalInfo;
195   - }
196   -
197 119 @Override
198 120 public String getSearchTextSource() {
199 121 return title;
... ... @@ -204,10 +126,6 @@ public final class CustomerEntity implements SearchTextEntity<Customer> {
204 126 this.searchText = searchText;
205 127 }
206 128
207   - public String getSearchText() {
208   - return searchText;
209   - }
210   -
211 129 @Override
212 130 public int hashCode() {
213 131 final int prime = 31;
... ... @@ -344,8 +262,15 @@ public final class CustomerEntity implements SearchTextEntity<Customer> {
344 262 customer.setZip(zip);
345 263 customer.setPhone(phone);
346 264 customer.setEmail(email);
347   - customer.setAdditionalInfo(additionalInfo);
  265 + if (additionalInfo != null) {
  266 + ObjectMapper mapper = new ObjectMapper();
  267 + try {
  268 + JsonNode jsonNode = mapper.readTree(additionalInfo);
  269 + customer.setAdditionalInfo(jsonNode);
  270 + } catch (IOException e) {
  271 + log.error(e.getMessage(), e);
  272 + }
  273 + }
348 274 return customer;
349 275 }
350   -
351 276 }
\ No newline at end of file
... ...
... ... @@ -22,6 +22,9 @@ import javax.persistence.Id;
22 22 import javax.persistence.Table;
23 23 import javax.persistence.Transient;
24 24 import com.fasterxml.jackson.databind.JsonNode;
  25 +import com.fasterxml.jackson.databind.ObjectMapper;
  26 +import lombok.Data;
  27 +import lombok.extern.slf4j.Slf4j;
25 28 import org.thingsboard.server.common.data.Dashboard;
26 29 import org.thingsboard.server.common.data.id.CustomerId;
27 30 import org.thingsboard.server.common.data.id.DashboardId;
... ... @@ -29,9 +32,12 @@ import org.thingsboard.server.common.data.id.TenantId;
29 32 import org.thingsboard.server.dao.model.ModelConstants;
30 33 import org.thingsboard.server.dao.model.SearchTextEntity;
31 34
  35 +import java.io.IOException;
32 36 import java.util.UUID;
33 37
34   -//@Entity
  38 +@Data
  39 +@Slf4j
  40 +@Entity
35 41 @Table(name = ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME)
36 42 public final class DashboardEntity implements SearchTextEntity<Dashboard> {
37 43
... ... @@ -55,7 +61,7 @@ public final class DashboardEntity implements SearchTextEntity<Dashboard> {
55 61 private String searchText;
56 62
57 63 @Column(name = ModelConstants.DASHBOARD_CONFIGURATION_PROPERTY)
58   - private JsonNode configuration;
  64 + private String configuration;
59 65
60 66 public DashboardEntity() {
61 67 super();
... ... @@ -72,47 +78,18 @@ public final class DashboardEntity implements SearchTextEntity<Dashboard> {
72 78 this.customerId = dashboard.getCustomerId().getId();
73 79 }
74 80 this.title = dashboard.getTitle();
75   - this.configuration = dashboard.getConfiguration();
  81 + if (configuration != null) {
  82 + this.configuration = dashboard.getConfiguration().toString();
  83 + }
76 84 }
77   -
  85 +
  86 + @Override
78 87 public UUID getId() {
79 88 return id;
80 89 }
81 90
  91 + @Override
82 92 public void setId(UUID id) {
83   - this.id = id;
84   - }
85   -
86   - public UUID getTenantId() {
87   - return tenantId;
88   - }
89   -
90   - public void setTenantId(UUID tenantId) {
91   - this.tenantId = tenantId;
92   - }
93   -
94   - public UUID getCustomerId() {
95   - return customerId;
96   - }
97   -
98   - public void setCustomerId(UUID customerId) {
99   - this.customerId = customerId;
100   - }
101   -
102   - public String getTitle() {
103   - return title;
104   - }
105   -
106   - public void setTitle(String title) {
107   - this.title = title;
108   - }
109   -
110   - public JsonNode getConfiguration() {
111   - return configuration;
112   - }
113   -
114   - public void setConfiguration(JsonNode configuration) {
115   - this.configuration = configuration;
116 93 }
117 94
118 95 @Override
... ... @@ -214,8 +191,16 @@ public final class DashboardEntity implements SearchTextEntity<Dashboard> {
214 191 dashboard.setCustomerId(new CustomerId(customerId));
215 192 }
216 193 dashboard.setTitle(title);
217   - dashboard.setConfiguration(configuration);
  194 + if (configuration != null) {
  195 + ObjectMapper mapper = new ObjectMapper();
  196 + JsonNode jsonNode = null;
  197 + try {
  198 + jsonNode = mapper.readTree(configuration);
  199 + dashboard.setConfiguration(jsonNode);
  200 + } catch (IOException e) {
  201 + log.error(e.getMessage(), e);
  202 + }
  203 + }
218 204 return dashboard;
219 205 }
220   -
221 206 }
\ No newline at end of file
... ...
... ... @@ -21,6 +21,8 @@ import javax.persistence.Entity;
21 21 import javax.persistence.Id;
22 22 import javax.persistence.Table;
23 23 import javax.persistence.Transient;
  24 +
  25 +import lombok.Data;
24 26 import org.thingsboard.server.common.data.DashboardInfo;
25 27 import org.thingsboard.server.common.data.id.CustomerId;
26 28 import org.thingsboard.server.common.data.id.DashboardId;
... ... @@ -30,7 +32,8 @@ import org.thingsboard.server.dao.model.SearchTextEntity;
30 32
31 33 import java.util.UUID;
32 34
33   -//@Entity
  35 +@Data
  36 +@Entity
34 37 @Table(name = ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME)
35 38 public class DashboardInfoEntity implements SearchTextEntity<DashboardInfo> {
36 39
... ... @@ -70,38 +73,6 @@ public class DashboardInfoEntity implements SearchTextEntity<DashboardInfo> {
70 73 this.title = dashboardInfo.getTitle();
71 74 }
72 75
73   - public UUID getId() {
74   - return id;
75   - }
76   -
77   - public void setId(UUID id) {
78   - this.id = id;
79   - }
80   -
81   - public UUID getTenantId() {
82   - return tenantId;
83   - }
84   -
85   - public void setTenantId(UUID tenantId) {
86   - this.tenantId = tenantId;
87   - }
88   -
89   - public UUID getCustomerId() {
90   - return customerId;
91   - }
92   -
93   - public void setCustomerId(UUID customerId) {
94   - this.customerId = customerId;
95   - }
96   -
97   - public String getTitle() {
98   - return title;
99   - }
100   -
101   - public void setTitle(String title) {
102   - this.title = title;
103   - }
104   -
105 76 @Override
106 77 public String getSearchTextSource() {
107 78 return title;
... ...
  1 +package org.thingsboard.server.dao.sql.component;
  2 +
  3 +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  4 +import org.springframework.data.jpa.repository.Query;
  5 +import org.springframework.data.repository.CrudRepository;
  6 +import org.springframework.stereotype.Component;
  7 +import org.thingsboard.server.common.data.plugin.ComponentScope;
  8 +import org.thingsboard.server.common.data.plugin.ComponentType;
  9 +import org.thingsboard.server.dao.model.ToData;
  10 +import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity;
  11 +
  12 +import java.util.Collection;
  13 +import java.util.List;
  14 +import java.util.UUID;
  15 +
  16 +/**
  17 + * Created by Valerii Sosliuk on 5/6/2017.
  18 + */
  19 +@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false)
  20 +public interface ComponentDescriptorRepository extends CrudRepository<ComponentDescriptorEntity, UUID> {
  21 +
  22 + ComponentDescriptorEntity findByClazz(String clazz);
  23 +
  24 + @Query(nativeQuery = true, value = "SELECT * FROM COMPONENT_DESCRIPTOR WHERE TYPE = ?2 " +
  25 + "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?3, '%')) " +
  26 + "ORDER BY ID LIMIT ?1")
  27 + List<ComponentDescriptorEntity> findByTypeFirstPage(int limit, int type, String textSearch);
  28 +
  29 + @Query(nativeQuery = true, value = "SELECT * FROM COMPONENT_DESCRIPTOR WHERE TYPE = ?2 " +
  30 + "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?3, '%')) " +
  31 + "AND ID > ?4 ORDER BY ID LIMIT ?1")
  32 + List<ComponentDescriptorEntity> findByTypeNextPage(int limit, int type, String textSearch, UUID idOffset);
  33 +
  34 + @Query(nativeQuery = true, value = "SELECT * FROM COMPONENT_DESCRIPTOR WHERE TYPE = ?2 " +
  35 + "AND SCOPE = ?3 AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?4, '%')) " +
  36 + "ORDER BY ID LIMIT ?1")
  37 + List<ComponentDescriptorEntity> findByScopeAndTypeFirstPage(int limit, int type, int scope, String textSearch);
  38 +
  39 + @Query(nativeQuery = true, value = "SELECT * FROM COMPONENT_DESCRIPTOR WHERE TYPE = ?2 " +
  40 + "AND SCOPE = ?3 AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?4, '%')) " +
  41 + "AND ID > ?5 ORDER BY ID LIMIT ?1")
  42 + List<ComponentDescriptorEntity> findByScopeAndTypeNextPage(int limit, int type, int scope, String textSearch, UUID idOffset);
  43 +
  44 + void deleteByClazz(String clazz);
  45 +}
... ...
  1 +package org.thingsboard.server.dao.sql.component;
  2 +
  3 +import org.springframework.beans.factory.annotation.Autowired;
  4 +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  5 +import org.springframework.data.repository.CrudRepository;
  6 +import org.springframework.stereotype.Component;
  7 +import org.thingsboard.server.common.data.id.ComponentDescriptorId;
  8 +import org.thingsboard.server.common.data.page.TextPageLink;
  9 +import org.thingsboard.server.common.data.plugin.ComponentDescriptor;
  10 +import org.thingsboard.server.common.data.plugin.ComponentScope;
  11 +import org.thingsboard.server.common.data.plugin.ComponentType;
  12 +import org.thingsboard.server.dao.DaoUtil;
  13 +import org.thingsboard.server.dao.component.ComponentDescriptorDao;
  14 +import org.thingsboard.server.dao.model.ModelConstants;
  15 +import org.thingsboard.server.dao.model.sql.ComponentDescriptorEntity;
  16 +import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
  17 +
  18 +import java.util.List;
  19 +import java.util.Optional;
  20 +import java.util.UUID;
  21 +
  22 +/**
  23 + * Created by Valerii Sosliuk on 5/6/2017.
  24 + */
  25 +@Component
  26 +@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false)
  27 +public class JpaBaseComponentDescriptorDao extends JpaAbstractSearchTextDao<ComponentDescriptorEntity, ComponentDescriptor>
  28 + implements ComponentDescriptorDao {
  29 +
  30 + @Autowired
  31 + private ComponentDescriptorRepository componentDescriptorRepository;
  32 +
  33 + @Override
  34 + protected Class<ComponentDescriptorEntity> getEntityClass() {
  35 + return ComponentDescriptorEntity.class;
  36 + }
  37 +
  38 + @Override
  39 + protected String getColumnFamilyName() {
  40 + return ModelConstants.COMPONENT_DESCRIPTOR_COLUMN_FAMILY_NAME;
  41 + }
  42 +
  43 + @Override
  44 + protected CrudRepository<ComponentDescriptorEntity, UUID> getCrudRepository() {
  45 + return componentDescriptorRepository;
  46 + }
  47 +
  48 + @Override
  49 + public Optional<ComponentDescriptor> saveIfNotExist(ComponentDescriptor component) {
  50 + boolean exists = componentDescriptorRepository.findOne(component.getId().getId()) != null;
  51 + if (exists) {
  52 + return Optional.empty();
  53 + }
  54 + return Optional.of(save(component));
  55 + }
  56 +
  57 + @Override
  58 + public ComponentDescriptor findById(ComponentDescriptorId componentId) {
  59 + return findById(componentId.getId());
  60 + }
  61 +
  62 + @Override
  63 + public ComponentDescriptor findByClazz(String clazz) {
  64 + return DaoUtil.getData(componentDescriptorRepository.findByClazz(clazz));
  65 + }
  66 +
  67 + @Override
  68 + public List<ComponentDescriptor> findByTypeAndPageLink(ComponentType type, TextPageLink pageLink) {
  69 + if (pageLink.getIdOffset() == null) {
  70 + return DaoUtil.convertDataList(componentDescriptorRepository.findByTypeFirstPage(pageLink.getLimit(),
  71 + type.ordinal(), pageLink.getTextSearch()));
  72 + } else {
  73 + return DaoUtil.convertDataList(componentDescriptorRepository.findByTypeNextPage(pageLink.getLimit(),
  74 + type.ordinal(), pageLink.getTextSearch(), pageLink.getIdOffset()));
  75 + }
  76 + }
  77 +
  78 + @Override
  79 + public List<ComponentDescriptor> findByScopeAndTypeAndPageLink(ComponentScope scope, ComponentType type, TextPageLink pageLink) {
  80 + if (pageLink.getIdOffset() == null) {
  81 + return DaoUtil.convertDataList(componentDescriptorRepository.findByScopeAndTypeFirstPage(pageLink.getLimit(),
  82 + type.ordinal(), scope.ordinal(), pageLink.getTextSearch()));
  83 + } else {
  84 + return DaoUtil.convertDataList(componentDescriptorRepository.findByScopeAndTypeNextPage(pageLink.getLimit(),
  85 + type.ordinal(), scope.ordinal(), pageLink.getTextSearch(), pageLink.getIdOffset()));
  86 + }
  87 + }
  88 +
  89 + @Override
  90 + public void deleteById(ComponentDescriptorId componentId) {
  91 + removeById(componentId.getId());
  92 + }
  93 +
  94 + @Override
  95 + public void deleteByClazz(String clazz) {
  96 + componentDescriptorRepository.deleteByClazz(clazz);
  97 + }
  98 +}
... ...
  1 +package org.thingsboard.server.dao.sql.customer;
  2 +
  3 +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  4 +import org.springframework.data.jpa.repository.Query;
  5 +import org.springframework.data.repository.CrudRepository;
  6 +import org.thingsboard.server.common.data.Customer;
  7 +import org.thingsboard.server.dao.model.sql.CustomerEntity;
  8 +
  9 +import java.util.List;
  10 +import java.util.UUID;
  11 +
  12 +/**
  13 + * Created by Valerii Sosliuk on 5/6/2017.
  14 + */
  15 +@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false)
  16 +public interface CustomerRepository extends CrudRepository<CustomerEntity, UUID> {
  17 +
  18 + @Query(nativeQuery = true, value = "SELECT * FROM CUSTOMER WHERE TENANT_ID = ?2 " +
  19 + "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?3, '%')) " +
  20 + "ORDER BY ID LIMIT ?1")
  21 + List<CustomerEntity> findByTenantIdFirstPage(int limit, UUID tenantId, String textSearch);
  22 +
  23 + @Query(nativeQuery = true, value = "SELECT * FROM CUSTOMER WHERE TENANT_ID = ?2 " +
  24 + "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?3, '%')) " +
  25 + "AND ID > ?4 ORDER BY ID LIMIT ?1")
  26 + List<CustomerEntity> findByTenantIdNextPage(int limit, UUID tenantId, String textSearch, UUID idOffset);
  27 +
  28 + @Query(nativeQuery = true, value = "SELECT * FROM CUSTOMER WHERE TENANT_ID = ?1")
  29 + List<CustomerEntity> findByTenantId(UUID tenantId);
  30 +}
... ...
  1 +package org.thingsboard.server.dao.sql.customer;
  2 +
  3 +import org.springframework.beans.factory.annotation.Autowired;
  4 +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  5 +import org.springframework.data.repository.CrudRepository;
  6 +import org.springframework.stereotype.Component;
  7 +import org.thingsboard.server.common.data.Customer;
  8 +import org.thingsboard.server.common.data.page.TextPageLink;
  9 +import org.thingsboard.server.dao.DaoUtil;
  10 +import org.thingsboard.server.dao.customer.CustomerDao;
  11 +import org.thingsboard.server.dao.model.ModelConstants;
  12 +import org.thingsboard.server.dao.model.sql.CustomerEntity;
  13 +import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
  14 +
  15 +import java.util.List;
  16 +import java.util.UUID;
  17 +
  18 +/**
  19 + * Created by Valerii Sosliuk on 5/6/2017.
  20 + */
  21 +@Component
  22 +@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false)
  23 +public class JpaCustomerDao extends JpaAbstractSearchTextDao<CustomerEntity, Customer> implements CustomerDao{
  24 +
  25 + @Autowired
  26 + private CustomerRepository customerRepository;
  27 +
  28 + @Override
  29 + protected Class<CustomerEntity> getEntityClass() {
  30 + return CustomerEntity.class;
  31 + }
  32 +
  33 + @Override
  34 + protected String getColumnFamilyName() {
  35 + return ModelConstants.CUSTOMER_COLUMN_FAMILY_NAME;
  36 + }
  37 +
  38 + @Override
  39 + protected CrudRepository<CustomerEntity, UUID> getCrudRepository() {
  40 + return customerRepository;
  41 + }
  42 +
  43 + @Override
  44 + public List<Customer> findCustomersByTenantId(UUID tenantId, TextPageLink pageLink) {
  45 + if (pageLink.getIdOffset() == null) {
  46 + return DaoUtil.convertDataList(customerRepository.findByTenantIdFirstPage(pageLink.getLimit(), tenantId, pageLink.getTextSearch()));
  47 + } else {
  48 + return DaoUtil.convertDataList(customerRepository.findByTenantIdNextPage(pageLink.getLimit(), tenantId,
  49 + pageLink.getTextSearch(), pageLink.getIdOffset()));
  50 + }
  51 + }
  52 +}
... ...
  1 +package org.thingsboard.server.dao.sql.dashboard;
  2 +
  3 +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  4 +import org.springframework.data.jpa.repository.Query;
  5 +import org.springframework.data.repository.CrudRepository;
  6 +import org.thingsboard.server.dao.model.sql.DashboardInfoEntity;
  7 +
  8 +import java.util.List;
  9 +import java.util.UUID;
  10 +
  11 +/**
  12 + * Created by Valerii Sosliuk on 5/6/2017.
  13 + */
  14 +@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false)
  15 +public interface DashboardInfoRepository extends CrudRepository<DashboardInfoEntity, UUID> {
  16 +
  17 + @Query(nativeQuery = true, value = "SELECT * FROM DASHBOARD WHERE TENANT_ID = ?2 " +
  18 + "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?3, '%')) " +
  19 + "ORDER BY ID LIMIT ?1")
  20 + List<DashboardInfoEntity> findByTenantIdFirstPage(int limit, UUID tenantId, String textSearch);
  21 +
  22 + @Query(nativeQuery = true, value = "SELECT * FROM DASHBOARD WHERE TENANT_ID = ?2 " +
  23 + "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?3, '%')) " +
  24 + "AND ID > ?4 ORDER BY ID LIMIT ?1")
  25 + List<DashboardInfoEntity> findByTenantIdNextPage(int limit, UUID tenantId, String textSearch, UUID idOffset);
  26 +
  27 + @Query(nativeQuery = true, value = "SELECT * FROM DASHBOARD WHERE TENANT_ID = ?2 " +
  28 + "AND CUSTOMER_ID = ?3 AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?4, '%')) " +
  29 + "ORDER BY ID LIMIT ?1")
  30 + List<DashboardInfoEntity> findByTenantIdAndCustomerIdFirstPage(int limit, UUID tenantId, UUID customerId, String textSearch);
  31 +
  32 + @Query(nativeQuery = true, value = "SELECT * FROM DASHBOARD WHERE TENANT_ID = ?2 " +
  33 + "AND CUSTOMER_ID = ?3 AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?4, '%')) " +
  34 + "AND ID > ?5 ORDER BY ID LIMIT ?1")
  35 + List<DashboardInfoEntity> findByTenantIdAndCustomerIdNextPage(int limit, UUID tenantId, UUID customerId, String textSearch, UUID idOffset);
  36 +}
... ...
  1 +package org.thingsboard.server.dao.sql.dashboard;
  2 +
  3 +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  4 +import org.springframework.data.repository.CrudRepository;
  5 +import org.thingsboard.server.dao.model.sql.DashboardEntity;
  6 +
  7 +import java.util.UUID;
  8 +
  9 +/**
  10 + * Created by Valerii Sosliuk on 5/6/2017.
  11 + */
  12 +@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false)
  13 +public interface DashboardRepository extends CrudRepository<DashboardEntity, UUID> {
  14 +}
... ...
  1 +package org.thingsboard.server.dao.sql.dashboard;
  2 +
  3 +import org.springframework.beans.factory.annotation.Autowired;
  4 +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  5 +import org.springframework.data.repository.CrudRepository;
  6 +import org.springframework.stereotype.Component;
  7 +import org.thingsboard.server.common.data.Dashboard;
  8 +import org.thingsboard.server.dao.dashboard.DashboardDao;
  9 +import org.thingsboard.server.dao.model.sql.DashboardEntity;
  10 +import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
  11 +
  12 +import java.util.UUID;
  13 +
  14 +import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME;
  15 +
  16 +/**
  17 + * Created by Valerii Sosliuk on 5/6/2017.
  18 + */
  19 +@Component
  20 +@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false)
  21 +public class JpaDashboardDao extends JpaAbstractSearchTextDao<DashboardEntity, Dashboard> implements DashboardDao {
  22 +
  23 + @Autowired
  24 + DashboardRepository dashboardRepository;
  25 +
  26 + @Override
  27 + protected Class<DashboardEntity> getEntityClass() {
  28 + return DashboardEntity.class;
  29 + }
  30 +
  31 + @Override
  32 + protected String getColumnFamilyName() {
  33 + return DASHBOARD_COLUMN_FAMILY_NAME;
  34 + }
  35 +
  36 + @Override
  37 + protected CrudRepository<DashboardEntity, UUID> getCrudRepository() {
  38 + return dashboardRepository;
  39 + }
  40 +}
... ...
  1 +package org.thingsboard.server.dao.sql.dashboard;
  2 +
  3 +import org.springframework.beans.factory.annotation.Autowired;
  4 +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  5 +import org.springframework.data.repository.CrudRepository;
  6 +import org.springframework.stereotype.Component;
  7 +import org.thingsboard.server.common.data.DashboardInfo;
  8 +import org.thingsboard.server.common.data.page.TextPageLink;
  9 +import org.thingsboard.server.dao.DaoUtil;
  10 +import org.thingsboard.server.dao.dashboard.DashboardInfoDao;
  11 +import org.thingsboard.server.dao.model.sql.DashboardInfoEntity;
  12 +import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
  13 +
  14 +import java.util.List;
  15 +import java.util.UUID;
  16 +
  17 +import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME;
  18 +
  19 +/**
  20 + * Created by Valerii Sosliuk on 5/6/2017.
  21 + */
  22 +@Component
  23 +@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false)
  24 +public class JpaDashboardInfoDao extends JpaAbstractSearchTextDao<DashboardInfoEntity, DashboardInfo> implements DashboardInfoDao {
  25 +
  26 + @Autowired
  27 + private DashboardInfoRepository dashboardInfoRepository;
  28 +
  29 + @Override
  30 + protected Class getEntityClass() {
  31 + return DashboardInfoEntity.class;
  32 + }
  33 +
  34 + @Override
  35 + protected String getColumnFamilyName() {
  36 + return DASHBOARD_COLUMN_FAMILY_NAME;
  37 + }
  38 +
  39 + @Override
  40 + protected CrudRepository getCrudRepository() {
  41 + return dashboardInfoRepository;
  42 + }
  43 +
  44 + @Override
  45 + public List<DashboardInfo> findDashboardsByTenantId(UUID tenantId, TextPageLink pageLink) {
  46 + if (pageLink.getIdOffset() == null) {
  47 + return DaoUtil.convertDataList(dashboardInfoRepository.findByTenantIdFirstPage(
  48 + pageLink.getLimit(), tenantId, pageLink.getTextSearch()));
  49 + } else {
  50 + return DaoUtil.convertDataList(dashboardInfoRepository.findByTenantIdNextPage(
  51 + pageLink.getLimit(), tenantId, pageLink.getTextSearch(), pageLink.getIdOffset()));
  52 + }
  53 + }
  54 +
  55 + @Override
  56 + public List<DashboardInfo> findDashboardsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) {
  57 + if (pageLink.getIdOffset() == null) {
  58 + return DaoUtil.convertDataList(dashboardInfoRepository.findByTenantIdAndCustomerIdFirstPage(
  59 + pageLink.getLimit(), tenantId, customerId, pageLink.getTextSearch()));
  60 + } else {
  61 + return DaoUtil.convertDataList(dashboardInfoRepository.findByTenantIdAndCustomerIdNextPage(
  62 + pageLink.getLimit(), tenantId, customerId, pageLink.getTextSearch(), pageLink.getIdOffset()));
  63 + }
  64 + }
  65 +}
... ...
  1 +package org.thingsboard.server.dao.sql.settings;
  2 +
  3 +import org.springframework.data.repository.CrudRepository;
  4 +import org.thingsboard.server.dao.model.ToData;
  5 +import org.thingsboard.server.dao.model.sql.AdminSettingsEntity;
  6 +
  7 +import java.util.UUID;
  8 +
  9 +/**
  10 + * Created by Valerii Sosliuk on 5/6/2017.
  11 + */
  12 +public interface AdminSettingsRepository extends CrudRepository<AdminSettingsEntity, UUID> {
  13 +
  14 + AdminSettingsEntity findByKey(String key);
  15 +}
... ...
  1 +package org.thingsboard.server.dao.sql.settings;
  2 +
  3 +import org.springframework.beans.factory.annotation.Autowired;
  4 +import org.springframework.data.repository.CrudRepository;
  5 +import org.thingsboard.server.common.data.AdminSettings;
  6 +import org.thingsboard.server.dao.DaoUtil;
  7 +import org.thingsboard.server.dao.model.sql.AdminSettingsEntity;
  8 +import org.thingsboard.server.dao.settings.AdminSettingsDao;
  9 +import org.thingsboard.server.dao.sql.JpaAbstractDao;
  10 +
  11 +import java.util.UUID;
  12 +
  13 +import static org.thingsboard.server.dao.model.ModelConstants.ADMIN_SETTINGS_COLUMN_FAMILY_NAME;
  14 +
  15 +/**
  16 + * Created by Valerii Sosliuk on 5/6/2017.
  17 + */
  18 +public class JpaAdminSettingsDao extends JpaAbstractDao<AdminSettingsEntity, AdminSettings> implements AdminSettingsDao{
  19 +
  20 + @Autowired
  21 + private AdminSettingsRepository adminSettingsRepository;
  22 +
  23 + @Override
  24 + protected Class<AdminSettingsEntity> getEntityClass() {
  25 + return AdminSettingsEntity.class;
  26 + }
  27 +
  28 + @Override
  29 + protected String getColumnFamilyName() {
  30 + return ADMIN_SETTINGS_COLUMN_FAMILY_NAME;
  31 + }
  32 +
  33 + @Override
  34 + protected CrudRepository<AdminSettingsEntity, UUID> getCrudRepository() {
  35 + return adminSettingsRepository;
  36 + }
  37 +
  38 + @Override
  39 + public AdminSettings findByKey(String key) {
  40 + return DaoUtil.getData(adminSettingsRepository.findByKey(key));
  41 + }
  42 +}
... ...
  1 +package org.thingsboard.server.dao.sql.component;
  2 +
  3 +import com.datastax.driver.core.utils.UUIDs;
  4 +import org.junit.Test;
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.thingsboard.server.common.data.Customer;
  7 +import org.thingsboard.server.common.data.id.ComponentDescriptorId;
  8 +import org.thingsboard.server.common.data.page.TextPageLink;
  9 +import org.thingsboard.server.common.data.plugin.ComponentDescriptor;
  10 +import org.thingsboard.server.common.data.plugin.ComponentScope;
  11 +import org.thingsboard.server.common.data.plugin.ComponentType;
  12 +import org.thingsboard.server.dao.AbstractJpaDaoTest;
  13 +import org.thingsboard.server.dao.component.ComponentDescriptorDao;
  14 +
  15 +import java.util.List;
  16 +
  17 +import static org.junit.Assert.assertEquals;
  18 +
  19 +/**
  20 + * Created by Valerii Sosliuk on 5/6/2017.
  21 + */
  22 +public class JpaBaseComponentDescriptorDaoTest extends AbstractJpaDaoTest {
  23 +
  24 + @Autowired
  25 + private ComponentDescriptorDao componentDescriptorDao;
  26 +
  27 + @Test
  28 + public void findByType() {
  29 + for (int i = 0; i < 20; i++) {
  30 + createComponentDescriptor(ComponentType.PLUGIN, ComponentScope.SYSTEM, i);
  31 + createComponentDescriptor(ComponentType.ACTION, ComponentScope.TENANT, i + 20);
  32 + }
  33 +
  34 + TextPageLink pageLink1 = new TextPageLink(15, "COMPONENT_");
  35 + List<ComponentDescriptor> components1 = componentDescriptorDao.findByTypeAndPageLink(ComponentType.PLUGIN, pageLink1);
  36 + assertEquals(15, components1.size());
  37 +
  38 + TextPageLink pageLink2 = new TextPageLink(15, "COMPONENT_", components1.get(14).getId().getId(), null);
  39 + List<ComponentDescriptor> components2 = componentDescriptorDao.findByTypeAndPageLink(ComponentType.PLUGIN, pageLink2);
  40 + assertEquals(5, components2.size());
  41 + }
  42 +
  43 + @Test
  44 + public void findByTypeAndSocpe() {
  45 + for (int i = 0; i < 20; i++) {
  46 + createComponentDescriptor(ComponentType.PLUGIN, ComponentScope.SYSTEM, i);
  47 + createComponentDescriptor(ComponentType.ACTION, ComponentScope.TENANT, i + 20);
  48 + createComponentDescriptor(ComponentType.FILTER, ComponentScope.SYSTEM, i + 40);
  49 + }
  50 +
  51 + TextPageLink pageLink1 = new TextPageLink(15, "COMPONENT_");
  52 + List<ComponentDescriptor> components1 = componentDescriptorDao.findByScopeAndTypeAndPageLink(
  53 + ComponentScope.SYSTEM, ComponentType.FILTER, pageLink1);
  54 + assertEquals(15, components1.size());
  55 +
  56 + TextPageLink pageLink2 = new TextPageLink(15, "COMPONENT_", components1.get(14).getId().getId(), null);
  57 + List<ComponentDescriptor> components2 = componentDescriptorDao.findByScopeAndTypeAndPageLink(
  58 + ComponentScope.SYSTEM, ComponentType.FILTER, pageLink2);
  59 + assertEquals(5, components2.size());
  60 + }
  61 +
  62 + private void createComponentDescriptor(ComponentType type, ComponentScope scope, int index) {
  63 + ComponentDescriptor component = new ComponentDescriptor();
  64 + component.setId(new ComponentDescriptorId(UUIDs.timeBased()));
  65 + component.setType(type);
  66 + component.setScope(scope);
  67 + component.setName("COMPONENT_" + index);
  68 + componentDescriptorDao.save(component);
  69 + }
  70 +
  71 +}
... ...
  1 +package org.thingsboard.server.dao.sql.customer;
  2 +
  3 +import com.datastax.driver.core.utils.UUIDs;
  4 +import org.junit.Test;
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.thingsboard.server.common.data.Customer;
  7 +import org.thingsboard.server.common.data.id.CustomerId;
  8 +import org.thingsboard.server.common.data.id.TenantId;
  9 +import org.thingsboard.server.common.data.page.TextPageLink;
  10 +import org.thingsboard.server.dao.AbstractJpaDaoTest;
  11 +import org.thingsboard.server.dao.customer.CustomerDao;
  12 +
  13 +import java.util.List;
  14 +import java.util.UUID;
  15 +
  16 +import static org.junit.Assert.assertEquals;
  17 +
  18 +/**
  19 + * Created by Valerii Sosliuk on 5/6/2017.
  20 + */
  21 +public class JpaCustomerDaoTest extends AbstractJpaDaoTest {
  22 +
  23 + @Autowired
  24 + private CustomerDao customerDao;
  25 +
  26 + @Test
  27 + public void testFindByTenantId() {
  28 + UUID tenantId1 = UUIDs.timeBased();
  29 + UUID tenantId2 = UUIDs.timeBased();
  30 +
  31 + for (int i = 0; i < 20; i++) {
  32 + createCustomer(tenantId1, i);
  33 + createCustomer(tenantId2, i * 2);
  34 + }
  35 +
  36 + TextPageLink pageLink1 = new TextPageLink(15, "CUSTOMER");
  37 + List<Customer> customers1 = customerDao.findCustomersByTenantId(tenantId1, pageLink1);
  38 + assertEquals(15, customers1.size());
  39 +
  40 + TextPageLink pageLink2 = new TextPageLink(15, "CUSTOMER", customers1.get(14).getId().getId(), null);
  41 + List<Customer> customers2 = customerDao.findCustomersByTenantId(tenantId1, pageLink2);
  42 + assertEquals(5, customers2.size());
  43 + }
  44 +
  45 + private void createCustomer(UUID tenantId, int index) {
  46 + Customer customer = new Customer();
  47 + customer.setId(new CustomerId(UUIDs.timeBased()));
  48 + customer.setTenantId(new TenantId(tenantId));
  49 + customer.setTitle("CUSTOMER_" + index);
  50 + customerDao.save(customer);
  51 + }
  52 +}
... ...
  1 +package org.thingsboard.server.dao.sql.dashboard;
  2 +
  3 +import com.datastax.driver.core.utils.UUIDs;
  4 +import org.junit.Test;
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.thingsboard.server.common.data.DashboardInfo;
  7 +import org.thingsboard.server.common.data.id.CustomerId;
  8 +import org.thingsboard.server.common.data.id.DashboardId;
  9 +import org.thingsboard.server.common.data.id.TenantId;
  10 +import org.thingsboard.server.common.data.page.TextPageLink;
  11 +import org.thingsboard.server.dao.AbstractJpaDaoTest;
  12 +import org.thingsboard.server.dao.dashboard.DashboardInfoDao;
  13 +
  14 +import java.util.List;
  15 +import java.util.UUID;
  16 +
  17 +/**
  18 + * Created by Valerii Sosliuk on 5/6/2017.
  19 + */
  20 +public class JpaDashboardInfoDaoTest extends AbstractJpaDaoTest {
  21 +
  22 + @Autowired
  23 + private DashboardInfoDao dashboardInfoDao;
  24 +
  25 + @Test
  26 + public void testFindDashboardsByTenantId() {
  27 + UUID tenantId1 = UUIDs.timeBased();
  28 + UUID customerId1 = UUIDs.timeBased();
  29 + UUID tenantId2 = UUIDs.timeBased();
  30 + UUID customerId2 = UUIDs.timeBased();
  31 +
  32 + for (int i = 0; i < 20; i++) {
  33 + createDashboard(tenantId1, customerId1, i);
  34 + createDashboard(tenantId2, customerId2, i * 2);
  35 + }
  36 +
  37 + TextPageLink pageLink1 = new TextPageLink(15, "DASHBOARD");
  38 + List<DashboardInfo> dashboardInfos1 = dashboardInfoDao.findDashboardsByTenantId(tenantId1, pageLink1);
  39 + assertEquals(15, dashboardInfos1.size());
  40 +
  41 + TextPageLink pageLink2 = new TextPageLink(15, "DASHBOARD", dashboardInfos1.get(14).getId().getId(), null);
  42 + List<DashboardInfo> dashboardInfos2 = dashboardInfoDao.findDashboardsByTenantId(tenantId1, pageLink2);
  43 + assertEquals(5, dashboardInfos2.size());
  44 + }
  45 +
  46 + @Test
  47 + public void testFindDashboardsByTenantAndCustomerId() {
  48 + UUID tenantId1 = UUIDs.timeBased();
  49 + UUID customerId1 = UUIDs.timeBased();
  50 + UUID tenantId2 = UUIDs.timeBased();
  51 + UUID customerId2 = UUIDs.timeBased();
  52 +
  53 + for (int i = 0; i < 20; i++) {
  54 + createDashboard(tenantId1, customerId1, i);
  55 + createDashboard(tenantId2, customerId2, i * 2);
  56 + }
  57 +
  58 + TextPageLink pageLink1 = new TextPageLink(15, "DASHBOARD");
  59 + List<DashboardInfo> dashboardInfos1 = dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(tenantId1, customerId1, pageLink1);
  60 + assertEquals(15, dashboardInfos1.size());
  61 +
  62 + TextPageLink pageLink2 = new TextPageLink(15, "DASHBOARD", dashboardInfos1.get(14).getId().getId(), null);
  63 + List<DashboardInfo> dashboardInfos2 = dashboardInfoDao.findDashboardsByTenantIdAndCustomerId(tenantId1, customerId1, pageLink2);
  64 + assertEquals(5, dashboardInfos2.size());
  65 + }
  66 +
  67 + private void assertEquals(int i, int size) {
  68 + }
  69 +
  70 + private void createDashboard(UUID tenantId, UUID customerId, int index) {
  71 + DashboardInfo dashboardInfo = new DashboardInfo();
  72 + dashboardInfo.setId(new DashboardId(UUIDs.timeBased()));
  73 + dashboardInfo.setTenantId(new TenantId(tenantId));
  74 + dashboardInfo.setCustomerId(new CustomerId(customerId));
  75 + dashboardInfo.setTitle("DASHBOARD_" + index);
  76 + dashboardInfoDao.save(dashboardInfo);
  77 + }
  78 +}
... ...
1 1 package org.thingsboard.server.dao.sql.device;
2 2
3 3 import com.datastax.driver.core.utils.UUIDs;
4   -import com.github.springtestdbunit.annotation.DatabaseOperation;
5   -import com.github.springtestdbunit.annotation.DatabaseSetup;
6   -import com.github.springtestdbunit.annotation.DatabaseTearDown;
7   -import com.google.common.util.concurrent.*;
  4 +import com.google.common.util.concurrent.ListenableFuture;
  5 +import com.google.common.util.concurrent.ListeningExecutorService;
  6 +import com.google.common.util.concurrent.MoreExecutors;
8 7 import org.junit.Test;
9 8 import org.springframework.beans.factory.annotation.Autowired;
10   -import org.springframework.transaction.annotation.Transactional;
11 9 import org.thingsboard.server.common.data.Device;
12 10 import org.thingsboard.server.common.data.id.CustomerId;
13 11 import org.thingsboard.server.common.data.id.DeviceId;
... ... @@ -17,7 +15,6 @@ import org.thingsboard.server.dao.AbstractJpaDaoTest;
17 15 import org.thingsboard.server.dao.device.DeviceDao;
18 16
19 17 import java.util.ArrayList;
20   -import java.util.Arrays;
21 18 import java.util.List;
22 19 import java.util.UUID;
23 20 import java.util.concurrent.ExecutionException;
... ... @@ -29,15 +26,12 @@ import static org.junit.Assert.assertNotNull;
29 26 /**
30 27 * Created by Valerii Sosliuk on 5/6/2017.
31 28 */
32   -@Transactional
33 29 public class JpaDeviceDaoTest extends AbstractJpaDaoTest {
34 30
35 31 @Autowired
36 32 private DeviceDao deviceDao;
37 33
38 34 @Test
39   - @DatabaseSetup(value = "classpath:dbunit/empty_dataset.xml",type = DatabaseOperation.DELETE_ALL)
40   - @DatabaseTearDown(value = "classpath:dbunit/empty_dataset.xml",type = DatabaseOperation.DELETE_ALL)
41 35 public void testFindDevicesByTenantId() {
42 36 UUID tenantId1 = UUIDs.timeBased();
43 37 UUID tenantId2 = UUIDs.timeBased();
... ... @@ -55,8 +49,6 @@ public class JpaDeviceDaoTest extends AbstractJpaDaoTest {
55 49 }
56 50
57 51 @Test
58   - @DatabaseSetup(value = "classpath:dbunit/empty_dataset.xml",type = DatabaseOperation.DELETE_ALL)
59   - @DatabaseTearDown(value = "classpath:dbunit/empty_dataset.xml",type = DatabaseOperation.DELETE_ALL)
60 52 public void testFindAsync() throws ExecutionException, InterruptedException {
61 53 UUID tenantId = UUIDs.timeBased();
62 54 UUID customerId = UUIDs.timeBased();
... ... @@ -75,8 +67,6 @@ public class JpaDeviceDaoTest extends AbstractJpaDaoTest {
75 67 }
76 68
77 69 @Test
78   - @DatabaseSetup(value = "classpath:dbunit/empty_dataset.xml",type = DatabaseOperation.DELETE_ALL)
79   - @DatabaseTearDown(value = "classpath:dbunit/empty_dataset.xml",type = DatabaseOperation.DELETE_ALL)
80 70 public void testFindDevicesByTenantIdAndIdsAsync() throws ExecutionException, InterruptedException {
81 71 UUID tenantId1 = UUIDs.timeBased();
82 72 UUID customerId1 = UUIDs.timeBased();
... ... @@ -100,8 +90,6 @@ public class JpaDeviceDaoTest extends AbstractJpaDaoTest {
100 90 }
101 91
102 92 @Test
103   - @DatabaseSetup(value = "classpath:dbunit/empty_dataset.xml",type = DatabaseOperation.DELETE_ALL)
104   - @DatabaseTearDown(value = "classpath:dbunit/empty_dataset.xml",type = DatabaseOperation.DELETE_ALL)
105 93 public void testFindDevicesByTenantIdAndCustomerIdAndIdsAsync() throws ExecutionException, InterruptedException {
106 94 UUID tenantId1 = UUIDs.timeBased();
107 95 UUID customerId1 = UUIDs.timeBased();
... ...
1 1 cassandra.enabled=false
2 2
3 3 sql.enabled=true
4   -#sql.datasource.url=jdbc:h2:mem:thingsboard
5   -#sql.datasource.username=sa
6   -#sql.datasource.password=
7   -#spring.jpa.hibernate.ddl-auto=create-drop
8 4
9 5 spring.jpa.show-sql=false
10 6 spring.jpa.hibernate.ddl-auto=create-drop
... ...