2 * Copyright 2013 F.B.A. Scheper.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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. *
16 package org.bitbucket.fbascheper.tutorial.envers;
18 import org.hibernate.envers.RevisionEntity;
19 import org.hibernate.envers.RevisionNumber;
20 import org.hibernate.envers.RevisionTimestamp;
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;
36 * The implementation of the {@link org.hibernate.envers.RevisionEntity}.
38 * @author Erik-Berndt Scheper
39 * @see org.hibernate.envers.RevisionEntity
43 @Table(name = "TTL_AUDIT_REVISION")
44 @RevisionEntity(AuditRevisionListener.class)
45 public class AuditRevision implements Serializable {
46 private static final long serialVersionUID = 1L;
50 @SequenceGenerator(name = "TTL_AUDIT_REVISION_SEQ", sequenceName = "TTL_AUDIT_REVISION_SEQ", allocationSize = 10)
51 @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TTL_AUDIT_REVISION_SEQ")
56 @Column(name = "ENVERS_TSTAMP", nullable = false)
57 private long timestamp;
60 @Temporal(TemporalType.TIMESTAMP)
61 @Column(name = "EVENT_DATE")
62 private Date revisionTimeStamp;
65 @Column(name = "USER_NAME", length = 80, nullable = false)
66 private String userName;
68 // ********************** Getters and setters ********************** //
71 * @return the id of this revision
78 * @param id the id of this revision
85 * @return the timestamp of this revision
91 void setTimestamp(long timestamp) {
92 this.timestamp = timestamp;
96 * @return the timestamp of this revision
98 public Date getRevisionTimeStamp() {
99 return revisionTimeStamp;
102 void setRevisionTimeStamp(Date revisionTimeStamp) {
103 this.revisionTimeStamp = revisionTimeStamp;
107 * @return name of the user who initiated the change resulting in this revision.
109 public String getUserName() {
114 * @param userName name of the user who initiated the change resulting in this revision.
116 void setUserName(String userName) {
117 this.userName = userName;
120 // ********************** Common Methods ********************** //
123 public boolean equals(Object o) {
124 if (this == o) return true;
125 if (o == null || getClass() != o.getClass()) return false;
127 AuditRevision that = (AuditRevision) o;
129 if (id != null ? !id.equals(that.id) : that.id != null) return false;
135 public int hashCode() {
136 return id != null ? id.hashCode() : 0;
140 public String toString() {
141 StringBuilder output = new StringBuilder();
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("\"}");
148 return output.toString();