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 / Event.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.Audited;
19 import org.hibernate.envers.RevisionNumber;
20
21 import javax.persistence.Column;
22 import javax.persistence.Entity;
23 import javax.persistence.GeneratedValue;
24 import javax.persistence.GenerationType;
25 import javax.persistence.Id;
26 import javax.persistence.SequenceGenerator;
27 import javax.persistence.Table;
28 import javax.persistence.Temporal;
29 import javax.persistence.TemporalType;
30 import javax.validation.constraints.NotNull;
31 import java.util.Date;
32
33 /**
34  * A random event registered, based on the original hibernate tutorial by Steve Ebersole.
35  *
36  * @author Erik-Berndt Scheper
37  * @see AuditRevision
38  * @since 11-09-2013
39  */
40 @Entity
41 @Table(name = "TTL_EVENT")
42 @Audited
43 public class Event {
44
45     @Id
46     @Column(name = "ID")
47     @SequenceGenerator(name = "TTL_EVENT_SEQ", sequenceName = "TTL_EVENT_SEQ", allocationSize = 10)
48     @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TTL_EVENT_SEQ")
49     @RevisionNumber
50     private Long id;
51
52     @NotNull
53     @Column(name = "TITLE", length = 80, nullable = false)
54     private String title;
55
56     @NotNull
57     @Column(name = "EVENT_DATE", nullable = false)
58     @Temporal(TemporalType.TIMESTAMP)
59     private Date date;
60
61     /**
62      * Default constructor, mandated by JPA.
63      */
64     Event() {
65         // do nothing
66     }
67
68     /**
69      * Initializing constructor.
70      *
71      * @param title title of the event
72      * @param date  date of the event
73      */
74     public Event(String title, Date date) {
75         this.title = title;
76         this.date = date;
77     }
78
79     // ********************** Getters and setters ********************** //
80
81     public Long getId() {
82         return id;
83     }
84
85     void setId(Long id) {
86         this.id = id;
87     }
88
89     public Date getDate() {
90         return date;
91     }
92
93     public void setDate(Date date) {
94         this.date = date;
95     }
96
97     public String getTitle() {
98         return title;
99     }
100
101     public void setTitle(String title) {
102         this.title = title;
103     }
104
105     // ********************** Common Methods ********************** //
106
107     @Override
108     public boolean equals(Object o) {
109         if (this == o) return true;
110         if (o == null || getClass() != o.getClass()) return false;
111
112         Event event = (Event) o;
113
114         if (date != null ? !date.equals(event.date) : event.date != null) return false;
115         if (title != null ? !title.equals(event.title) : event.title != null) return false;
116
117         return true;
118     }
119
120     @Override
121     public int hashCode() {
122         int result = title != null ? title.hashCode() : 0;
123         result = 31 * result + (date != null ? date.hashCode() : 0);
124         return result;
125     }
126
127     @Override
128     public String toString() {
129         StringBuilder output = new StringBuilder();
130
131         output.append("Event {");
132         output.append(" id = \"").append(getId()).append("\", ");
133         output.append(" title = \"").append(title).append("\", ");
134         output.append(" date = \"").append(date).append("\"}");
135
136         return output.toString();
137     }
138
139
140 }