117 lines
2.8 KiB
Java
117 lines
2.8 KiB
Java
package im.rosetta.database.entity;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import im.rosetta.database.CreateUpdateEntity;
|
|
import jakarta.persistence.CascadeType;
|
|
import jakarta.persistence.Column;
|
|
import jakarta.persistence.Entity;
|
|
import jakarta.persistence.FetchType;
|
|
import jakarta.persistence.GeneratedValue;
|
|
import jakarta.persistence.GenerationType;
|
|
import jakarta.persistence.Id;
|
|
import jakarta.persistence.Index;
|
|
import jakarta.persistence.OneToMany;
|
|
import jakarta.persistence.Table;
|
|
|
|
@Entity
|
|
@Table(name = "devices", indexes = {
|
|
@Index(name = "idx_public_key", columnList = "publicKey, deviceId", unique = true)
|
|
})
|
|
public class Device extends CreateUpdateEntity {
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
private Long id;
|
|
|
|
@Column(name = "publicKey", nullable = false)
|
|
private String publicKey;
|
|
|
|
@Column(name = "deviceId", nullable = false)
|
|
private String deviceId;
|
|
|
|
@Column(name = "deviceName", nullable = false)
|
|
private String deviceName;
|
|
|
|
@Column(name = "deviceOs", nullable = false)
|
|
private String deviceOs;
|
|
|
|
/**
|
|
* Время завершения сессии устройства
|
|
*/
|
|
@Column(name = "syncTime", nullable = true, columnDefinition = "bigint default 0")
|
|
private Long syncTime;
|
|
|
|
@OneToMany(mappedBy = "device", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
|
private List<PushToken> tokens = new ArrayList<>();
|
|
|
|
public Long getId() {
|
|
return id;
|
|
}
|
|
|
|
public String getPublicKey() {
|
|
return publicKey;
|
|
}
|
|
|
|
public String getDeviceId() {
|
|
return deviceId;
|
|
}
|
|
|
|
public String getDeviceName() {
|
|
return deviceName;
|
|
}
|
|
|
|
public String getDeviceOs() {
|
|
return deviceOs;
|
|
}
|
|
|
|
public Long getSyncTime() {
|
|
return syncTime;
|
|
}
|
|
|
|
public List<PushToken> getTokens() {
|
|
return tokens;
|
|
}
|
|
|
|
public void setSyncTime(Long syncTime) {
|
|
this.syncTime = syncTime;
|
|
}
|
|
|
|
public void setPublicKey(String publicKey) {
|
|
this.publicKey = publicKey;
|
|
}
|
|
|
|
public void setDeviceId(String deviceId) {
|
|
this.deviceId = deviceId;
|
|
}
|
|
|
|
public void setDeviceName(String deviceName) {
|
|
this.deviceName = deviceName;
|
|
}
|
|
|
|
public void setDeviceOs(String deviceOs) {
|
|
this.deviceOs = deviceOs;
|
|
}
|
|
|
|
public void setTokens(List<PushToken> tokens) {
|
|
this.tokens = tokens;
|
|
}
|
|
|
|
public void addToken(PushToken token) {
|
|
if (token == null) {
|
|
return;
|
|
}
|
|
this.tokens.add(token);
|
|
token.setDevice(this);
|
|
}
|
|
|
|
public void removeToken(PushToken token) {
|
|
if (token == null) {
|
|
return;
|
|
}
|
|
this.tokens.remove(token);
|
|
token.setDevice(null);
|
|
}
|
|
|
|
} |