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
;
18 import javax
.persistence
.*;
21 * 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.
23 * Full versioning allows concrete subclasses to keep track of previous or later versions of an object.
24 * A different version is another (persistent) java object, but with the same UUID.
25 * The version history is established as a linked list of the version objects in time.
26 * If versioning via the linked list is used, updated/updatedBy is the same as created/createdBy (better NULL?).
28 * Versioning can be turned off and in this case this class provides updated/updatedBy to keep track of the latest change event.
31 * @created 08-Nov-2007 13:07:01
36 public abstract class VersionableEntity
<T
extends VersionableEntity
> extends CdmBase
{
37 private static final Logger logger
= Logger
.getLogger(VersionableEntity
.class);
39 //time of last update for this object
40 private Calendar updated
;
41 private Person updatedBy
;
42 private T nextVersion
;
43 private T previousVersion
;
47 * Returns the succeeding version of this object with the same UUID
48 * @return next, i.e. succeeding version of this object
50 //@OneToOne(mappedBy="previousVersion")
52 public T
getNextVersion(){
53 return this.nextVersion
;
55 public void setNextVersion(T nextVersion
){
56 this.nextVersion
= nextVersion
;
61 public T
getPreviousVersion(){
62 return this.previousVersion
;
64 public void setPreviousVersion(T previousVersion
){
65 this.previousVersion
= previousVersion
;
69 @ManyToOne(fetch
=FetchType
.LAZY
)
70 @Cascade({CascadeType
.SAVE_UPDATE
})
71 public Person
getUpdatedBy(){
72 return this.updatedBy
;
77 * @param updatedBy updatedBy
79 public void setUpdatedBy(Person updatedBy
){
80 this.updatedBy
= updatedBy
;
87 @Temporal(TemporalType
.TIMESTAMP
)
89 @Basic(fetch
= FetchType
.LAZY
)
90 public Calendar
getUpdated(){
96 * @param updated updated
98 public void setUpdated(Calendar updated
){
99 this.updated
= updated
;
106 public Calendar
getValidFrom(){
114 public Calendar
getValidTo(){
119 * Is true if UUID and created timestamp are the same for the passed Object and this one.
120 * @see eu.etaxonomy.cdm.model.common.CdmBase#equals(java.lang.Object)
121 * See {@link http://www.hibernate.org/109.html hibernate109}, {@link http://www.geocities.com/technofundo/tech/java/equalhash.html geocities}
122 * or {@link http://www.ibm.com/developerworks/java/library/j-jtp05273.html ibm}
123 * for more information about equals and hashcode.
126 public boolean equals(Object obj
) {
133 if (!CdmBase
.class.isAssignableFrom(obj
.getClass())){
136 ICdmBase cdmObj
= (ICdmBase
)obj
;
137 boolean uuidEqual
= cdmObj
.getUuid().equals(this.getUuid());
138 boolean createdEqual
= cdmObj
.getCreated().equals(this.getCreated());
139 if (! uuidEqual
|| !createdEqual
){
146 /** Overrides {@link eu.etaxonomy.cdm.model.common.CdmBase#hashCode()}
147 * See {@link http://www.hibernate.org/109.html}, {@link http://www.geocities.com/technofundo/tech/java/equalhash.html}
148 * or {@link http://www.ibm.com/developerworks/java/library/j-jtp05273.html}
149 * for more information about equals and hashcode.
152 public int hashCode() {
154 hashCode
= 29 * hashCode
+ this.getUuid().hashCode();
155 //hashCode = 29 * hashCode + this.getCreated().hashCode();