Entities version refactoring
This commit is contained in:
parent
7fb5f268c7
commit
1dcb64d298
@ -1587,18 +1587,24 @@ public class DeviceControllerTest extends AbstractControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSaveDeviceWithOutdatedVersion() throws Exception {
|
public void testSaveDeviceWithOutdatedVersion() throws Exception {
|
||||||
Device device = createDevice("Device v1");
|
Device device = createDevice("Device v1.0");
|
||||||
assertThat(device.getVersion()).isOne();
|
assertThat(device.getVersion()).isOne();
|
||||||
|
|
||||||
device.setName("Device v2");
|
device.setName("Device v2.0");
|
||||||
device = doPost("/api/device", device, Device.class);
|
device = doPost("/api/device", device, Device.class);
|
||||||
assertThat(device.getVersion()).isEqualTo(2);
|
assertThat(device.getVersion()).isEqualTo(2);
|
||||||
|
|
||||||
device.setVersion(1);
|
device.setName("Device v1.1");
|
||||||
|
device.setVersion(1L);
|
||||||
String response = doPost("/api/device", device).andExpect(status().isConflict())
|
String response = doPost("/api/device", device).andExpect(status().isConflict())
|
||||||
.andReturn().getResponse().getContentAsString();
|
.andReturn().getResponse().getContentAsString();
|
||||||
assertThat(JacksonUtil.toJsonNode(response).get("message").asText())
|
assertThat(JacksonUtil.toJsonNode(response).get("message").asText())
|
||||||
.containsIgnoringCase("already changed by someone else");
|
.containsIgnoringCase("already changed by someone else");
|
||||||
|
|
||||||
|
device.setVersion(null); // overriding entity
|
||||||
|
device = doPost("/api/device", device, Device.class);
|
||||||
|
assertThat(device.getName()).isEqualTo("Device v1.1");
|
||||||
|
assertThat(device.getVersion()).isEqualTo(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Device createDevice(String name) {
|
private Device createDevice(String name) {
|
||||||
|
|||||||
@ -44,7 +44,7 @@ public class Customer extends ContactBased<CustomerId> implements HasTenantId, E
|
|||||||
@Getter @Setter
|
@Getter @Setter
|
||||||
private CustomerId externalId;
|
private CustomerId externalId;
|
||||||
@Getter @Setter
|
@Getter @Setter
|
||||||
private Integer version;
|
private Long version;
|
||||||
|
|
||||||
public Customer() {
|
public Customer() {
|
||||||
super();
|
super();
|
||||||
|
|||||||
@ -46,7 +46,7 @@ public class DashboardInfo extends BaseData<DashboardId> implements HasName, Has
|
|||||||
private Integer mobileOrder;
|
private Integer mobileOrder;
|
||||||
|
|
||||||
@Getter @Setter
|
@Getter @Setter
|
||||||
private Integer version;
|
private Long version;
|
||||||
|
|
||||||
public DashboardInfo() {
|
public DashboardInfo() {
|
||||||
super();
|
super();
|
||||||
|
|||||||
@ -68,7 +68,7 @@ public class Device extends BaseDataWithAdditionalInfo<DeviceId> implements HasL
|
|||||||
@Getter @Setter
|
@Getter @Setter
|
||||||
private DeviceId externalId;
|
private DeviceId externalId;
|
||||||
@Getter @Setter
|
@Getter @Setter
|
||||||
private Integer version;
|
private Long version;
|
||||||
|
|
||||||
public Device() {
|
public Device() {
|
||||||
super();
|
super();
|
||||||
|
|||||||
@ -97,7 +97,7 @@ public class DeviceProfile extends BaseData<DeviceProfileId> implements HasName,
|
|||||||
private RuleChainId defaultEdgeRuleChainId;
|
private RuleChainId defaultEdgeRuleChainId;
|
||||||
|
|
||||||
private DeviceProfileId externalId;
|
private DeviceProfileId externalId;
|
||||||
private Integer version;
|
private Long version;
|
||||||
|
|
||||||
public DeviceProfile() {
|
public DeviceProfile() {
|
||||||
super();
|
super();
|
||||||
|
|||||||
@ -60,7 +60,7 @@ public class EntityView extends BaseDataWithAdditionalInfo<EntityViewId>
|
|||||||
private long endTimeMs;
|
private long endTimeMs;
|
||||||
|
|
||||||
private EntityViewId externalId;
|
private EntityViewId externalId;
|
||||||
private Integer version;
|
private Long version;
|
||||||
|
|
||||||
public EntityView() {
|
public EntityView() {
|
||||||
super();
|
super();
|
||||||
|
|||||||
@ -19,6 +19,7 @@ public interface HasVersion {
|
|||||||
|
|
||||||
Long getVersion();
|
Long getVersion();
|
||||||
|
|
||||||
void setVersion(Integer version);
|
default void setVersion(Long version) {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,7 +53,7 @@ public class User extends BaseDataWithAdditionalInfo<UserId> implements HasName,
|
|||||||
private String phone;
|
private String phone;
|
||||||
|
|
||||||
@Getter @Setter
|
@Getter @Setter
|
||||||
private Integer version;
|
private Long version;
|
||||||
|
|
||||||
public User() {
|
public User() {
|
||||||
super();
|
super();
|
||||||
|
|||||||
@ -58,7 +58,7 @@ public class Asset extends BaseDataWithAdditionalInfo<AssetId> implements HasLab
|
|||||||
@Getter @Setter
|
@Getter @Setter
|
||||||
private AssetId externalId;
|
private AssetId externalId;
|
||||||
@Getter @Setter
|
@Getter @Setter
|
||||||
private Integer version;
|
private Long version;
|
||||||
|
|
||||||
public Asset() {
|
public Asset() {
|
||||||
super();
|
super();
|
||||||
|
|||||||
@ -75,7 +75,7 @@ public class AssetProfile extends BaseData<AssetProfileId> implements HasName, H
|
|||||||
private RuleChainId defaultEdgeRuleChainId;
|
private RuleChainId defaultEdgeRuleChainId;
|
||||||
|
|
||||||
private AssetProfileId externalId;
|
private AssetProfileId externalId;
|
||||||
private Integer version;
|
private Long version;
|
||||||
|
|
||||||
public AssetProfile() {
|
public AssetProfile() {
|
||||||
super();
|
super();
|
||||||
|
|||||||
@ -60,7 +60,7 @@ public class Edge extends BaseDataWithAdditionalInfo<EdgeId> implements HasLabel
|
|||||||
private String secret;
|
private String secret;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private Integer version;
|
private Long version;
|
||||||
|
|
||||||
public Edge() {
|
public Edge() {
|
||||||
super();
|
super();
|
||||||
|
|||||||
@ -59,7 +59,7 @@ public class RuleChain extends BaseDataWithAdditionalInfo<RuleChainId> implement
|
|||||||
private transient JsonNode configuration;
|
private transient JsonNode configuration;
|
||||||
|
|
||||||
private RuleChainId externalId;
|
private RuleChainId externalId;
|
||||||
private Integer version;
|
private Long version;
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private byte[] configurationBytes;
|
private byte[] configurationBytes;
|
||||||
|
|||||||
@ -35,7 +35,7 @@ public class DeviceCredentials extends BaseData<DeviceCredentialsId> implements
|
|||||||
private String credentialsValue;
|
private String credentialsValue;
|
||||||
|
|
||||||
@Getter @Setter
|
@Getter @Setter
|
||||||
private Integer version;
|
private Long version;
|
||||||
|
|
||||||
public DeviceCredentials() {
|
public DeviceCredentials() {
|
||||||
super();
|
super();
|
||||||
|
|||||||
@ -47,7 +47,7 @@ public class BaseWidgetType extends BaseData<WidgetTypeId> implements HasName, H
|
|||||||
@Schema(description = "Whether widget type is deprecated.", example = "true")
|
@Schema(description = "Whether widget type is deprecated.", example = "true")
|
||||||
private boolean deprecated;
|
private boolean deprecated;
|
||||||
|
|
||||||
private Integer version;
|
private Long version;
|
||||||
|
|
||||||
public BaseWidgetType() {
|
public BaseWidgetType() {
|
||||||
super();
|
super();
|
||||||
|
|||||||
@ -79,7 +79,7 @@ public class WidgetsBundle extends BaseData<WidgetsBundleId> implements HasName,
|
|||||||
private WidgetsBundleId externalId;
|
private WidgetsBundleId externalId;
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
private Integer version;
|
private Long version;
|
||||||
|
|
||||||
public WidgetsBundle() {
|
public WidgetsBundle() {
|
||||||
super();
|
super();
|
||||||
|
|||||||
@ -209,7 +209,7 @@ message DeviceProto {
|
|||||||
optional int64 softwareIdLSB = 18;
|
optional int64 softwareIdLSB = 18;
|
||||||
optional int64 externalIdMSB = 19;
|
optional int64 externalIdMSB = 19;
|
||||||
optional int64 externalIdLSB = 20;
|
optional int64 externalIdLSB = 20;
|
||||||
optional int32 version = 21;
|
optional int64 version = 21;
|
||||||
}
|
}
|
||||||
|
|
||||||
message DeviceProfileProto {
|
message DeviceProfileProto {
|
||||||
@ -240,7 +240,7 @@ message DeviceProfileProto {
|
|||||||
optional int64 defaultEdgeRuleChainIdLSB = 25;
|
optional int64 defaultEdgeRuleChainIdLSB = 25;
|
||||||
optional int64 externalIdMSB = 26;
|
optional int64 externalIdMSB = 26;
|
||||||
optional int64 externalIdLSB = 27;
|
optional int64 externalIdLSB = 27;
|
||||||
optional int32 version = 28;
|
optional int64 version = 28;
|
||||||
}
|
}
|
||||||
|
|
||||||
message TenantProto {
|
message TenantProto {
|
||||||
@ -670,7 +670,7 @@ message DeviceCredentialsProto {
|
|||||||
CredentialsType credentialsType = 6;
|
CredentialsType credentialsType = 6;
|
||||||
string credentialsId = 7;
|
string credentialsId = 7;
|
||||||
optional string credentialsValue = 8;
|
optional string credentialsValue = 8;
|
||||||
optional int32 version = 9;
|
optional int64 version = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CredentialsDataProto {
|
message CredentialsDataProto {
|
||||||
|
|||||||
@ -15,6 +15,47 @@
|
|||||||
*/
|
*/
|
||||||
package org.thingsboard.server.dao.model;
|
package org.thingsboard.server.dao.model;
|
||||||
|
|
||||||
public interface BaseVersionedEntity {
|
import jakarta.persistence.Column;
|
||||||
long getVersion();
|
import jakarta.persistence.MappedSuperclass;
|
||||||
|
import jakarta.persistence.Version;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.thingsboard.server.common.data.BaseData;
|
||||||
|
import org.thingsboard.server.common.data.HasVersion;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@MappedSuperclass
|
||||||
|
public abstract class BaseVersionedEntity<D extends BaseData & HasVersion> extends BaseSqlEntity<D> implements HasVersion {
|
||||||
|
|
||||||
|
@Getter @Setter
|
||||||
|
@Version
|
||||||
|
@Column(name = ModelConstants.VERSION_PROPERTY)
|
||||||
|
protected Long version;
|
||||||
|
|
||||||
|
public BaseVersionedEntity() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BaseVersionedEntity(D domain) {
|
||||||
|
super(domain);
|
||||||
|
this.version = domain.getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BaseVersionedEntity(BaseVersionedEntity<?> entity) {
|
||||||
|
super(entity);
|
||||||
|
this.version = entity.version;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "BaseVersionedEntity{" +
|
||||||
|
"id=" + id +
|
||||||
|
", createdTime=" + createdTime +
|
||||||
|
", version=" + version +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,61 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright © 2016-2024 The Thingsboard Authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.thingsboard.server.dao.model;
|
|
||||||
|
|
||||||
import jakarta.persistence.Column;
|
|
||||||
import jakarta.persistence.MappedSuperclass;
|
|
||||||
import jakarta.persistence.Version;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import org.thingsboard.server.common.data.BaseData;
|
|
||||||
import org.thingsboard.server.common.data.HasVersion;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@MappedSuperclass
|
|
||||||
public abstract class BaseVersionedSqlEntity<D extends BaseData & HasVersion> extends BaseSqlEntity<D> implements HasVersion {
|
|
||||||
|
|
||||||
@Getter @Setter
|
|
||||||
@Version
|
|
||||||
@Column(name = ModelConstants.VERSION_PROPERTY)
|
|
||||||
protected Integer version;
|
|
||||||
|
|
||||||
public BaseVersionedSqlEntity() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public BaseVersionedSqlEntity(D domain) {
|
|
||||||
super(domain);
|
|
||||||
this.version = domain.getVersion();
|
|
||||||
}
|
|
||||||
|
|
||||||
public BaseVersionedSqlEntity(BaseVersionedSqlEntity<?> entity) {
|
|
||||||
super(entity);
|
|
||||||
this.version = entity.version;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "BaseVersionedSqlEntity{" +
|
|
||||||
"id=" + id +
|
|
||||||
", createdTime=" + createdTime +
|
|
||||||
", version=" + version +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -26,7 +26,7 @@ import org.thingsboard.server.common.data.id.AssetId;
|
|||||||
import org.thingsboard.server.common.data.id.AssetProfileId;
|
import org.thingsboard.server.common.data.id.AssetProfileId;
|
||||||
import org.thingsboard.server.common.data.id.CustomerId;
|
import org.thingsboard.server.common.data.id.CustomerId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
|
import org.thingsboard.server.dao.model.BaseVersionedEntity;
|
||||||
import org.thingsboard.server.dao.model.ModelConstants;
|
import org.thingsboard.server.dao.model.ModelConstants;
|
||||||
import org.thingsboard.server.dao.util.mapping.JsonConverter;
|
import org.thingsboard.server.dao.util.mapping.JsonConverter;
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.EXTERNAL_ID_PROPER
|
|||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@MappedSuperclass
|
@MappedSuperclass
|
||||||
public abstract class AbstractAssetEntity<T extends Asset> extends BaseVersionedSqlEntity<T> {
|
public abstract class AbstractAssetEntity<T extends Asset> extends BaseVersionedEntity<T> {
|
||||||
|
|
||||||
@Column(name = ASSET_TENANT_ID_PROPERTY)
|
@Column(name = ASSET_TENANT_ID_PROPERTY)
|
||||||
private UUID tenantId;
|
private UUID tenantId;
|
||||||
|
|||||||
@ -32,7 +32,7 @@ import org.thingsboard.server.common.data.id.DeviceId;
|
|||||||
import org.thingsboard.server.common.data.id.DeviceProfileId;
|
import org.thingsboard.server.common.data.id.DeviceProfileId;
|
||||||
import org.thingsboard.server.common.data.id.OtaPackageId;
|
import org.thingsboard.server.common.data.id.OtaPackageId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
|
import org.thingsboard.server.dao.model.BaseVersionedEntity;
|
||||||
import org.thingsboard.server.dao.model.ModelConstants;
|
import org.thingsboard.server.dao.model.ModelConstants;
|
||||||
import org.thingsboard.server.dao.util.mapping.JsonConverter;
|
import org.thingsboard.server.dao.util.mapping.JsonConverter;
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ import java.util.UUID;
|
|||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@MappedSuperclass
|
@MappedSuperclass
|
||||||
public abstract class AbstractDeviceEntity<T extends Device> extends BaseVersionedSqlEntity<T> {
|
public abstract class AbstractDeviceEntity<T extends Device> extends BaseVersionedEntity<T> {
|
||||||
|
|
||||||
@Column(name = ModelConstants.DEVICE_TENANT_ID_PROPERTY, columnDefinition = "uuid")
|
@Column(name = ModelConstants.DEVICE_TENANT_ID_PROPERTY, columnDefinition = "uuid")
|
||||||
private UUID tenantId;
|
private UUID tenantId;
|
||||||
|
|||||||
@ -26,7 +26,7 @@ import org.thingsboard.server.common.data.id.CustomerId;
|
|||||||
import org.thingsboard.server.common.data.id.EdgeId;
|
import org.thingsboard.server.common.data.id.EdgeId;
|
||||||
import org.thingsboard.server.common.data.id.RuleChainId;
|
import org.thingsboard.server.common.data.id.RuleChainId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
|
import org.thingsboard.server.dao.model.BaseVersionedEntity;
|
||||||
import org.thingsboard.server.dao.model.ModelConstants;
|
import org.thingsboard.server.dao.model.ModelConstants;
|
||||||
import org.thingsboard.server.dao.util.mapping.JsonConverter;
|
import org.thingsboard.server.dao.util.mapping.JsonConverter;
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.EDGE_TYPE_PROPERTY
|
|||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@MappedSuperclass
|
@MappedSuperclass
|
||||||
public abstract class AbstractEdgeEntity<T extends Edge> extends BaseVersionedSqlEntity<T> {
|
public abstract class AbstractEdgeEntity<T extends Edge> extends BaseVersionedEntity<T> {
|
||||||
|
|
||||||
@Column(name = EDGE_TENANT_ID_PROPERTY, columnDefinition = "uuid")
|
@Column(name = EDGE_TENANT_ID_PROPERTY, columnDefinition = "uuid")
|
||||||
private UUID tenantId;
|
private UUID tenantId;
|
||||||
|
|||||||
@ -32,7 +32,7 @@ import org.thingsboard.server.common.data.id.EntityIdFactory;
|
|||||||
import org.thingsboard.server.common.data.id.EntityViewId;
|
import org.thingsboard.server.common.data.id.EntityViewId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.common.data.objects.TelemetryEntityView;
|
import org.thingsboard.server.common.data.objects.TelemetryEntityView;
|
||||||
import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
|
import org.thingsboard.server.dao.model.BaseVersionedEntity;
|
||||||
import org.thingsboard.server.dao.model.ModelConstants;
|
import org.thingsboard.server.dao.model.ModelConstants;
|
||||||
import org.thingsboard.server.dao.util.mapping.JsonConverter;
|
import org.thingsboard.server.dao.util.mapping.JsonConverter;
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_TYPE_PROPER
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@MappedSuperclass
|
@MappedSuperclass
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public abstract class AbstractEntityViewEntity<T extends EntityView> extends BaseVersionedSqlEntity<T> {
|
public abstract class AbstractEntityViewEntity<T extends EntityView> extends BaseVersionedEntity<T> {
|
||||||
|
|
||||||
@Column(name = ModelConstants.ENTITY_VIEW_ENTITY_ID_PROPERTY)
|
@Column(name = ModelConstants.ENTITY_VIEW_ENTITY_ID_PROPERTY)
|
||||||
private UUID entityId;
|
private UUID entityId;
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import lombok.EqualsAndHashCode;
|
|||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.common.data.id.WidgetTypeId;
|
import org.thingsboard.server.common.data.id.WidgetTypeId;
|
||||||
import org.thingsboard.server.common.data.widget.BaseWidgetType;
|
import org.thingsboard.server.common.data.widget.BaseWidgetType;
|
||||||
import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
|
import org.thingsboard.server.dao.model.BaseVersionedEntity;
|
||||||
import org.thingsboard.server.dao.model.ModelConstants;
|
import org.thingsboard.server.dao.model.ModelConstants;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -30,7 +30,7 @@ import java.util.UUID;
|
|||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@MappedSuperclass
|
@MappedSuperclass
|
||||||
public abstract class AbstractWidgetTypeEntity<T extends BaseWidgetType> extends BaseVersionedSqlEntity<T> {
|
public abstract class AbstractWidgetTypeEntity<T extends BaseWidgetType> extends BaseVersionedEntity<T> {
|
||||||
|
|
||||||
@Column(name = ModelConstants.WIDGET_TYPE_TENANT_ID_PROPERTY)
|
@Column(name = ModelConstants.WIDGET_TYPE_TENANT_ID_PROPERTY)
|
||||||
private UUID tenantId;
|
private UUID tenantId;
|
||||||
|
|||||||
@ -25,7 +25,7 @@ import org.thingsboard.server.common.data.id.AssetProfileId;
|
|||||||
import org.thingsboard.server.common.data.id.DashboardId;
|
import org.thingsboard.server.common.data.id.DashboardId;
|
||||||
import org.thingsboard.server.common.data.id.RuleChainId;
|
import org.thingsboard.server.common.data.id.RuleChainId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
|
import org.thingsboard.server.dao.model.BaseVersionedEntity;
|
||||||
import org.thingsboard.server.dao.model.ModelConstants;
|
import org.thingsboard.server.dao.model.ModelConstants;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -34,7 +34,7 @@ import java.util.UUID;
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = ModelConstants.ASSET_PROFILE_TABLE_NAME)
|
@Table(name = ModelConstants.ASSET_PROFILE_TABLE_NAME)
|
||||||
public final class AssetProfileEntity extends BaseVersionedSqlEntity<AssetProfile> {
|
public final class AssetProfileEntity extends BaseVersionedEntity<AssetProfile> {
|
||||||
|
|
||||||
@Column(name = ModelConstants.ASSET_PROFILE_TENANT_ID_PROPERTY)
|
@Column(name = ModelConstants.ASSET_PROFILE_TENANT_ID_PROPERTY)
|
||||||
private UUID tenantId;
|
private UUID tenantId;
|
||||||
|
|||||||
@ -25,8 +25,7 @@ import lombok.EqualsAndHashCode;
|
|||||||
import org.thingsboard.server.common.data.Customer;
|
import org.thingsboard.server.common.data.Customer;
|
||||||
import org.thingsboard.server.common.data.id.CustomerId;
|
import org.thingsboard.server.common.data.id.CustomerId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.dao.model.BaseSqlEntity;
|
import org.thingsboard.server.dao.model.BaseVersionedEntity;
|
||||||
import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
|
|
||||||
import org.thingsboard.server.dao.model.ModelConstants;
|
import org.thingsboard.server.dao.model.ModelConstants;
|
||||||
import org.thingsboard.server.dao.util.mapping.JsonConverter;
|
import org.thingsboard.server.dao.util.mapping.JsonConverter;
|
||||||
|
|
||||||
@ -36,7 +35,7 @@ import java.util.UUID;
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = ModelConstants.CUSTOMER_TABLE_NAME)
|
@Table(name = ModelConstants.CUSTOMER_TABLE_NAME)
|
||||||
public final class CustomerEntity extends BaseVersionedSqlEntity<Customer> {
|
public final class CustomerEntity extends BaseVersionedEntity<Customer> {
|
||||||
|
|
||||||
@Column(name = ModelConstants.CUSTOMER_TENANT_ID_PROPERTY)
|
@Column(name = ModelConstants.CUSTOMER_TENANT_ID_PROPERTY)
|
||||||
private UUID tenantId;
|
private UUID tenantId;
|
||||||
|
|||||||
@ -30,7 +30,7 @@ import org.thingsboard.server.common.data.ShortCustomerInfo;
|
|||||||
import org.thingsboard.server.common.data.StringUtils;
|
import org.thingsboard.server.common.data.StringUtils;
|
||||||
import org.thingsboard.server.common.data.id.DashboardId;
|
import org.thingsboard.server.common.data.id.DashboardId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
|
import org.thingsboard.server.dao.model.BaseVersionedEntity;
|
||||||
import org.thingsboard.server.dao.model.ModelConstants;
|
import org.thingsboard.server.dao.model.ModelConstants;
|
||||||
import org.thingsboard.server.dao.util.mapping.JsonConverter;
|
import org.thingsboard.server.dao.util.mapping.JsonConverter;
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ import java.util.UUID;
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = ModelConstants.DASHBOARD_TABLE_NAME)
|
@Table(name = ModelConstants.DASHBOARD_TABLE_NAME)
|
||||||
public final class DashboardEntity extends BaseVersionedSqlEntity<Dashboard> {
|
public final class DashboardEntity extends BaseVersionedEntity<Dashboard> {
|
||||||
|
|
||||||
private static final JavaType assignedCustomersType =
|
private static final JavaType assignedCustomersType =
|
||||||
JacksonUtil.constructCollectionType(HashSet.class, ShortCustomerInfo.class);
|
JacksonUtil.constructCollectionType(HashSet.class, ShortCustomerInfo.class);
|
||||||
|
|||||||
@ -28,7 +28,7 @@ import org.thingsboard.server.common.data.ShortCustomerInfo;
|
|||||||
import org.thingsboard.server.common.data.StringUtils;
|
import org.thingsboard.server.common.data.StringUtils;
|
||||||
import org.thingsboard.server.common.data.id.DashboardId;
|
import org.thingsboard.server.common.data.id.DashboardId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
|
import org.thingsboard.server.dao.model.BaseVersionedEntity;
|
||||||
import org.thingsboard.server.dao.model.ModelConstants;
|
import org.thingsboard.server.dao.model.ModelConstants;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -39,7 +39,7 @@ import java.util.UUID;
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = ModelConstants.DASHBOARD_TABLE_NAME)
|
@Table(name = ModelConstants.DASHBOARD_TABLE_NAME)
|
||||||
public class DashboardInfoEntity extends BaseVersionedSqlEntity<DashboardInfo> {
|
public class DashboardInfoEntity extends BaseVersionedEntity<DashboardInfo> {
|
||||||
|
|
||||||
private static final JavaType assignedCustomersType =
|
private static final JavaType assignedCustomersType =
|
||||||
JacksonUtil.constructCollectionType(HashSet.class, ShortCustomerInfo.class);
|
JacksonUtil.constructCollectionType(HashSet.class, ShortCustomerInfo.class);
|
||||||
|
|||||||
@ -26,7 +26,7 @@ import org.thingsboard.server.common.data.id.DeviceCredentialsId;
|
|||||||
import org.thingsboard.server.common.data.id.DeviceId;
|
import org.thingsboard.server.common.data.id.DeviceId;
|
||||||
import org.thingsboard.server.common.data.security.DeviceCredentials;
|
import org.thingsboard.server.common.data.security.DeviceCredentials;
|
||||||
import org.thingsboard.server.common.data.security.DeviceCredentialsType;
|
import org.thingsboard.server.common.data.security.DeviceCredentialsType;
|
||||||
import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
|
import org.thingsboard.server.dao.model.BaseVersionedEntity;
|
||||||
import org.thingsboard.server.dao.model.ModelConstants;
|
import org.thingsboard.server.dao.model.ModelConstants;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -35,7 +35,7 @@ import java.util.UUID;
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = ModelConstants.DEVICE_CREDENTIALS_TABLE_NAME)
|
@Table(name = ModelConstants.DEVICE_CREDENTIALS_TABLE_NAME)
|
||||||
public final class DeviceCredentialsEntity extends BaseVersionedSqlEntity<DeviceCredentials> {
|
public final class DeviceCredentialsEntity extends BaseVersionedEntity<DeviceCredentials> {
|
||||||
|
|
||||||
@Column(name = ModelConstants.DEVICE_CREDENTIALS_DEVICE_ID_PROPERTY)
|
@Column(name = ModelConstants.DEVICE_CREDENTIALS_DEVICE_ID_PROPERTY)
|
||||||
private UUID deviceId;
|
private UUID deviceId;
|
||||||
|
|||||||
@ -38,7 +38,7 @@ import org.thingsboard.server.common.data.id.DeviceProfileId;
|
|||||||
import org.thingsboard.server.common.data.id.OtaPackageId;
|
import org.thingsboard.server.common.data.id.OtaPackageId;
|
||||||
import org.thingsboard.server.common.data.id.RuleChainId;
|
import org.thingsboard.server.common.data.id.RuleChainId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
|
import org.thingsboard.server.dao.model.BaseVersionedEntity;
|
||||||
import org.thingsboard.server.dao.model.ModelConstants;
|
import org.thingsboard.server.dao.model.ModelConstants;
|
||||||
import org.thingsboard.server.dao.util.mapping.JsonConverter;
|
import org.thingsboard.server.dao.util.mapping.JsonConverter;
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ import java.util.UUID;
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = ModelConstants.DEVICE_PROFILE_TABLE_NAME)
|
@Table(name = ModelConstants.DEVICE_PROFILE_TABLE_NAME)
|
||||||
public final class DeviceProfileEntity extends BaseVersionedSqlEntity<DeviceProfile> {
|
public final class DeviceProfileEntity extends BaseVersionedEntity<DeviceProfile> {
|
||||||
|
|
||||||
@Column(name = ModelConstants.DEVICE_PROFILE_TENANT_ID_PROPERTY)
|
@Column(name = ModelConstants.DEVICE_PROFILE_TENANT_ID_PROPERTY)
|
||||||
private UUID tenantId;
|
private UUID tenantId;
|
||||||
|
|||||||
@ -30,7 +30,7 @@ import org.thingsboard.server.common.data.id.TenantId;
|
|||||||
import org.thingsboard.server.common.data.rule.RuleChain;
|
import org.thingsboard.server.common.data.rule.RuleChain;
|
||||||
import org.thingsboard.server.common.data.rule.RuleChainType;
|
import org.thingsboard.server.common.data.rule.RuleChainType;
|
||||||
import org.thingsboard.server.dao.DaoUtil;
|
import org.thingsboard.server.dao.DaoUtil;
|
||||||
import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
|
import org.thingsboard.server.dao.model.BaseVersionedEntity;
|
||||||
import org.thingsboard.server.dao.model.ModelConstants;
|
import org.thingsboard.server.dao.model.ModelConstants;
|
||||||
import org.thingsboard.server.dao.util.mapping.JsonConverter;
|
import org.thingsboard.server.dao.util.mapping.JsonConverter;
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ import java.util.UUID;
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = ModelConstants.RULE_CHAIN_TABLE_NAME)
|
@Table(name = ModelConstants.RULE_CHAIN_TABLE_NAME)
|
||||||
public class RuleChainEntity extends BaseVersionedSqlEntity<RuleChain> {
|
public class RuleChainEntity extends BaseVersionedEntity<RuleChain> {
|
||||||
|
|
||||||
@Column(name = ModelConstants.RULE_CHAIN_TENANT_ID_PROPERTY)
|
@Column(name = ModelConstants.RULE_CHAIN_TENANT_ID_PROPERTY)
|
||||||
private UUID tenantId;
|
private UUID tenantId;
|
||||||
|
|||||||
@ -29,7 +29,7 @@ import org.thingsboard.server.common.data.id.CustomerId;
|
|||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.common.data.id.UserId;
|
import org.thingsboard.server.common.data.id.UserId;
|
||||||
import org.thingsboard.server.common.data.security.Authority;
|
import org.thingsboard.server.common.data.security.Authority;
|
||||||
import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
|
import org.thingsboard.server.dao.model.BaseVersionedEntity;
|
||||||
import org.thingsboard.server.dao.model.ModelConstants;
|
import org.thingsboard.server.dao.model.ModelConstants;
|
||||||
import org.thingsboard.server.dao.util.mapping.JsonConverter;
|
import org.thingsboard.server.dao.util.mapping.JsonConverter;
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ import java.util.UUID;
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = ModelConstants.USER_PG_HIBERNATE_TABLE_NAME)
|
@Table(name = ModelConstants.USER_PG_HIBERNATE_TABLE_NAME)
|
||||||
public class UserEntity extends BaseVersionedSqlEntity<User> {
|
public class UserEntity extends BaseVersionedEntity<User> {
|
||||||
|
|
||||||
@Column(name = ModelConstants.USER_TENANT_ID_PROPERTY)
|
@Column(name = ModelConstants.USER_TENANT_ID_PROPERTY)
|
||||||
private UUID tenantId;
|
private UUID tenantId;
|
||||||
|
|||||||
@ -27,4 +27,5 @@ public abstract class VersionedEntity {
|
|||||||
|
|
||||||
@Column(name = VERSION_COLUMN)
|
@Column(name = VERSION_COLUMN)
|
||||||
protected Long version;
|
protected Long version;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,7 @@ import lombok.EqualsAndHashCode;
|
|||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.common.data.id.WidgetsBundleId;
|
import org.thingsboard.server.common.data.id.WidgetsBundleId;
|
||||||
import org.thingsboard.server.common.data.widget.WidgetsBundle;
|
import org.thingsboard.server.common.data.widget.WidgetsBundle;
|
||||||
import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
|
import org.thingsboard.server.dao.model.BaseVersionedEntity;
|
||||||
import org.thingsboard.server.dao.model.ModelConstants;
|
import org.thingsboard.server.dao.model.ModelConstants;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -33,7 +33,7 @@ import java.util.UUID;
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = ModelConstants.WIDGETS_BUNDLE_TABLE_NAME)
|
@Table(name = ModelConstants.WIDGETS_BUNDLE_TABLE_NAME)
|
||||||
public final class WidgetsBundleEntity extends BaseVersionedSqlEntity<WidgetsBundle> {
|
public final class WidgetsBundleEntity extends BaseVersionedEntity<WidgetsBundle> {
|
||||||
|
|
||||||
@Column(name = ModelConstants.WIDGETS_BUNDLE_TENANT_ID_PROPERTY)
|
@Column(name = ModelConstants.WIDGETS_BUNDLE_TENANT_ID_PROPERTY)
|
||||||
private UUID tenantId;
|
private UUID tenantId;
|
||||||
|
|||||||
@ -87,7 +87,7 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D>
|
|||||||
protected E doSave(E entity, boolean isNew) {
|
protected E doSave(E entity, boolean isNew) {
|
||||||
if (isNew) {
|
if (isNew) {
|
||||||
if (entity instanceof HasVersion versionedEntity) {
|
if (entity instanceof HasVersion versionedEntity) {
|
||||||
versionedEntity.setVersion(1);
|
versionedEntity.setVersion(1L);
|
||||||
}
|
}
|
||||||
entityManager.persist(entity);
|
entityManager.persist(entity);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user