2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.model
.common
;
12 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
13 import org
.apache
.log4j
.Logger
;
14 import org
.hibernate
.annotations
.Cascade
;
15 import org
.hibernate
.annotations
.CascadeType
;
19 import javax
.persistence
.*;
20 import javax
.xml
.bind
.annotation
.XmlAccessType
;
21 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
22 import javax
.xml
.bind
.annotation
.XmlElement
;
23 import javax
.xml
.bind
.annotation
.XmlRootElement
;
24 import javax
.xml
.bind
.annotation
.XmlTransient
;
25 import javax
.xml
.bind
.annotation
.XmlType
;
28 * The class keeps track of versions via a full linked list to different version objects, or a simple updated/updatedBy property in the same object.
30 * Full versioning allows concrete subclasses to keep track of previous or later versions of an object.
31 * A different version is another (persistent) java object, but with the same UUID.
32 * The version history is established as a linked list of the version objects in time.
33 * If versioning via the linked list is used, updated/updatedBy is the same as created/createdBy (better NULL?).
35 * Versioning can be turned off and in this case this class provides updated/updatedBy to keep track of the latest change event.
38 * @created 08-Nov-2007 13:07:01
42 @XmlAccessorType(XmlAccessType
.FIELD
)
43 @XmlType(name
= "VersionableEntity", propOrder
= {
49 @XmlRootElement(name
= "VersionableEntity")
51 public abstract class VersionableEntity
<T
extends VersionableEntity
> extends CdmBase
{
52 private static final Logger logger
= Logger
.getLogger(VersionableEntity
.class);
54 //time of last update for this object
55 // There is a problem with "updated" during deserialization because of the @Version annotation.
57 //@XmlElement(name ="Updated")
58 private Calendar updated
;
60 @XmlElement(name
= "UpdatedBy")
61 private Person updatedBy
;
63 @XmlElement(name
= "NextVersion")
64 private T nextVersion
;
66 @XmlElement(name
= "PreviousVersion")
67 private T previousVersion
;
71 * Returns the succeeding version of this object with the same UUID
72 * @return next, i.e. succeeding version of this object
74 //@OneToOne(mappedBy="previousVersion")
76 public T
getNextVersion(){
77 return this.nextVersion
;
79 public void setNextVersion(T nextVersion
){
80 this.nextVersion
= nextVersion
;
85 public T
getPreviousVersion(){
86 return this.previousVersion
;
88 public void setPreviousVersion(T previousVersion
){
89 this.previousVersion
= previousVersion
;
93 @ManyToOne(fetch
=FetchType
.LAZY
)
94 @Cascade({CascadeType
.SAVE_UPDATE
})
95 public Person
getUpdatedBy(){
96 return this.updatedBy
;
101 * @param updatedBy updatedBy
103 public void setUpdatedBy(Person updatedBy
){
104 this.updatedBy
= updatedBy
;
111 @Temporal(TemporalType
.TIMESTAMP
)
113 @Basic(fetch
= FetchType
.LAZY
)
114 public Calendar
getUpdated(){
120 * @param updated updated
122 public void setUpdated(Calendar updated
){
123 this.updated
= updated
;
130 public Calendar
getValidFrom(){
138 public Calendar
getValidTo(){
143 * Is true if UUID and created timestamp are the same for the passed Object and this one.
144 * @see eu.etaxonomy.cdm.model.common.CdmBase#equals(java.lang.Object)
145 * See {@link http://www.hibernate.org/109.html hibernate109}, {@link http://www.geocities.com/technofundo/tech/java/equalhash.html geocities}
146 * or {@link http://www.ibm.com/developerworks/java/library/j-jtp05273.html ibm}
147 * for more information about equals and hashcode.
150 public boolean equals(Object obj
) {
157 if (!CdmBase
.class.isAssignableFrom(obj
.getClass())){
160 ICdmBase cdmObj
= (ICdmBase
)obj
;
161 boolean uuidEqual
= cdmObj
.getUuid().equals(this.getUuid());
162 boolean createdEqual
= cdmObj
.getCreated().equals(this.getCreated());
163 if (! uuidEqual
|| !createdEqual
){
170 /** Overrides {@link eu.etaxonomy.cdm.model.common.CdmBase#hashCode()}
171 * See {@link http://www.hibernate.org/109.html}, {@link http://www.geocities.com/technofundo/tech/java/equalhash.html}
172 * or {@link http://www.ibm.com/developerworks/java/library/j-jtp05273.html}
173 * for more information about equals and hashcode.
176 public int hashCode() {
178 hashCode
= 29 * hashCode
+ this.getUuid().hashCode();
179 //hashCode = 29 * hashCode + this.getCreated().hashCode();
183 //********************** CLONE *****************************************/
186 * Clones this versionable entity.
187 * Set fields for nextVersion, previousVersion, updated, updatedBy and createdBy are set to <tt>null</tt>
188 * The id is set to 0.
189 * The uuid is created new.
190 * The createdWhen is set to the current date.
191 * @see java.lang.Object#clone()
193 public Object
clone() throws CloneNotSupportedException
{
194 VersionableEntity result
= (VersionableEntity
)super.clone();
197 result
.setNextVersion(null);
198 result
.setPreviousVersion(null);
199 result
.setUpdated(null);
200 result
.setUpdatedBy(null);