mirror of https://github.com/bvn13/JIrcBot.git
71 lines
1.3 KiB
Java
71 lines
1.3 KiB
Java
package ru.bvn13.jircbot.database.entities;
|
|
|
|
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
|
|
|
import javax.persistence.*;
|
|
import java.io.Serializable;
|
|
import java.util.Date;
|
|
|
|
/**
|
|
* Created by bvn13 on 31.01.2018.
|
|
*/
|
|
@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 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;
|
|
}
|
|
|
|
}
|