Repository navigation
Expand file tree
/
Copy pathBaseModel.java
More file actions
79 lines (59 loc) · 1.58 KB
/
Copy pathBaseModel.java
File metadata and controls
79 lines (59 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.raysmond.blog.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 Raysmond<i@raysmond.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;
}
}