mirror of https://github.com/bvn13/VoidForum.git
80 lines
1.6 KiB
Java
80 lines
1.6 KiB
Java
package ru.bvn13.voidforum.models;
|
|
|
|
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
|
|
|
import javax.persistence.*;
|
|
import java.io.Serializable;
|
|
import java.util.Date;
|
|
|
|
/**
|
|
* An abstract base model class for entities
|
|
*
|
|
* @author bvn13 <mail4bvn@gmail.com>
|
|
*/
|
|
@MappedSuperclass
|
|
public abstract class BaseModel implements Comparable<BaseModel>, Serializable {
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
@Column(name = "id")
|
|
private Long id;
|
|
|
|
@Column(nullable = false)
|
|
private Date createdAt;
|
|
|
|
@Column(nullable = false)
|
|
private Date updatedAt;
|
|
|
|
@PrePersist
|
|
public void prePersist(){
|
|
createdAt = updatedAt = new Date();
|
|
}
|
|
|
|
@PreUpdate
|
|
public void preUpdate(){
|
|
updatedAt = new Date();
|
|
}
|
|
|
|
@Override
|
|
public int compareTo(BaseModel o) {
|
|
return this.getId().compareTo(o.getId());
|
|
}
|
|
|
|
public boolean equals(Object other) {
|
|
if (other == null || other.getClass() != this.getClass())
|
|
return false;
|
|
|
|
return this.getId().equals(((BaseModel) other).getId());
|
|
}
|
|
|
|
|
|
public int hashCode() {
|
|
return new HashCodeBuilder().append(getId()).toHashCode();
|
|
}
|
|
|
|
|
|
public Long getId() {
|
|
return id;
|
|
}
|
|
|
|
public void setId(Long _id) {
|
|
id = _id;
|
|
}
|
|
|
|
public Date getCreatedAt() {
|
|
return createdAt;
|
|
}
|
|
|
|
public void setCreatedAt(Date createdAt) {
|
|
this.createdAt = createdAt;
|
|
}
|
|
|
|
public Date getUpdatedAt() {
|
|
return updatedAt;
|
|
}
|
|
|
|
public void setUpdatedAt(Date updatedAt) {
|
|
this.updatedAt = updatedAt;
|
|
}
|
|
|
|
} |