Added integration-test provided by Erik-Berndt Scheper <erik.berndt.scheper@gmail...
[hibernate4-maven-plugin] / src / it / hibernate4-maven-plugin-envers-sample / src / main / java / org / bitbucket / fbascheper / tutorial / envers / AuditRevision.java
1 /**
2  * Copyright 2013 F.B.A. Scheper.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License. *
15  */
16 package org.bitbucket.fbascheper.tutorial.envers;
17
18 import org.hibernate.envers.RevisionEntity;
19 import org.hibernate.envers.RevisionNumber;
20 import org.hibernate.envers.RevisionTimestamp;
21
22 import javax.persistence.Column;
23 import javax.persistence.Entity;
24 import javax.persistence.GeneratedValue;
25 import javax.persistence.GenerationType;
26 import javax.persistence.Id;
27 import javax.persistence.SequenceGenerator;
28 import javax.persistence.Table;
29 import javax.persistence.Temporal;
30 import javax.persistence.TemporalType;
31 import javax.validation.constraints.NotNull;
32 import java.io.Serializable;
33 import java.util.Date;
34
35 /**
36  * The implementation of the {@link org.hibernate.envers.RevisionEntity}.
37  *
38  * @author Erik-Berndt Scheper
39  * @see org.hibernate.envers.RevisionEntity
40  * @since 11-09-2013
41  */
42 @Entity
43 @Table(name = "TTL_AUDIT_REVISION")
44 @RevisionEntity(AuditRevisionListener.class)
45 public class AuditRevision implements Serializable {
46     private static final long serialVersionUID = 1L;
47
48     @Id
49     @Column(name = "ID")
50     @SequenceGenerator(name = "TTL_AUDIT_REVISION_SEQ", sequenceName = "TTL_AUDIT_REVISION_SEQ", allocationSize = 10)
51     @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TTL_AUDIT_REVISION_SEQ")
52     @RevisionNumber
53     private Long id;
54
55     @RevisionTimestamp
56     @Column(name = "ENVERS_TSTAMP", nullable = false)
57     private long timestamp;
58
59     @NotNull
60     @Temporal(TemporalType.TIMESTAMP)
61     @Column(name = "EVENT_DATE")
62     private Date revisionTimeStamp;
63
64     @NotNull
65     @Column(name = "USER_NAME", length = 80, nullable = false)
66     private String userName;
67
68     // ********************** Getters and setters ********************** //
69
70     /**
71      * @return the id of this revision
72      */
73     public Long getId() {
74         return id;
75     }
76
77     /**
78      * @param id the id of this revision
79      */
80     void setId(Long id) {
81         this.id = id;
82     }
83
84     /**
85      * @return the timestamp of this revision
86      */
87     long getTimestamp() {
88         return timestamp;
89     }
90
91     void setTimestamp(long timestamp) {
92         this.timestamp = timestamp;
93     }
94
95     /**
96      * @return the timestamp of this revision
97      */
98     public Date getRevisionTimeStamp() {
99         return revisionTimeStamp;
100     }
101
102     void setRevisionTimeStamp(Date revisionTimeStamp) {
103         this.revisionTimeStamp = revisionTimeStamp;
104     }
105
106     /**
107      * @return name of the user who initiated the change resulting in this revision.
108      */
109     public String getUserName() {
110         return userName;
111     }
112
113     /**
114      * @param userName name of the user who initiated the change resulting in this revision.
115      */
116     void setUserName(String userName) {
117         this.userName = userName;
118     }
119
120     // ********************** Common Methods ********************** //
121
122     @Override
123     public boolean equals(Object o) {
124         if (this == o) return true;
125         if (o == null || getClass() != o.getClass()) return false;
126
127         AuditRevision that = (AuditRevision) o;
128
129         if (id != null ? !id.equals(that.id) : that.id != null) return false;
130
131         return true;
132     }
133
134     @Override
135     public int hashCode() {
136         return id != null ? id.hashCode() : 0;
137     }
138
139     @Override
140     public String toString() {
141         StringBuilder output = new StringBuilder();
142
143         output.append("AuditRevision {");
144         output.append(" id = \"").append(getId()).append("\", ");
145         output.append(" revisionTimeStamp = \"").append(revisionTimeStamp).append("\", ");
146         output.append(" userName = \"").append(userName).append("\"}");
147
148         return output.toString();
149     }
150
151 }