83 lines
1.9 KiB
Java
83 lines
1.9 KiB
Java
package ru.ulstu.model;
|
|
|
|
import javax.persistence.GeneratedValue;
|
|
import javax.persistence.GenerationType;
|
|
import javax.persistence.Id;
|
|
import javax.persistence.MappedSuperclass;
|
|
import javax.persistence.Version;
|
|
import javax.validation.constraints.NotNull;
|
|
import java.io.Serializable;
|
|
|
|
@MappedSuperclass
|
|
public abstract class BaseEntity implements Serializable, Comparable<BaseEntity> {
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.TABLE)
|
|
private Integer id;
|
|
|
|
@Version
|
|
private Integer version;
|
|
|
|
public Integer getId() {
|
|
return id;
|
|
}
|
|
|
|
public void setId(Integer id) {
|
|
this.id = id;
|
|
}
|
|
|
|
public Integer getVersion() {
|
|
return version;
|
|
}
|
|
|
|
public void setVersion(Integer version) {
|
|
this.version = version;
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (obj == null) {
|
|
return false;
|
|
}
|
|
if (!getClass().isAssignableFrom(obj.getClass())) {
|
|
return false;
|
|
}
|
|
BaseEntity other = (BaseEntity) obj;
|
|
if (id == null) {
|
|
if (other.id != null) {
|
|
return false;
|
|
}
|
|
} else if (!id.equals(other.id)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
final int prime = 31;
|
|
int result = 1;
|
|
result = prime * result + (id == null ? 0 : id.hashCode());
|
|
return result;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return getClass().getSimpleName() + "{" +
|
|
"id=" + id +
|
|
", version=" + version +
|
|
'}';
|
|
}
|
|
|
|
@Override
|
|
public int compareTo(@NotNull BaseEntity o) {
|
|
return id != null ? id.compareTo(o.getId()) : -1;
|
|
}
|
|
|
|
public void reset() {
|
|
this.id = null;
|
|
this.version = null;
|
|
}
|
|
} |