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
;
13 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
14 import eu
.etaxonomy
.cdm
.model
.view
.View
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.hibernate
.annotations
.Cascade
;
17 import org
.hibernate
.annotations
.CascadeType
;
20 import javax
.persistence
.*;
23 * 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.
25 * Full versioning allows concrete subclasses to keep track of previous or later versions of an object.
26 * A different version is another (persistent) java object, but with the same UUID.
27 * The version history is established as a linked list of the version objects in time.
28 * If versioning via the linked list is used, updated/updatedBy is the same as created/createdBy (better NULL?).
30 * Versioning can be turned off and in this case this class provides updated/updatedBy to keep track of the latest change event.
33 * @created 08-Nov-2007 13:07:01
38 public abstract class VersionableEntity
<T
extends VersionableEntity
> extends CdmBase
{
39 static Logger logger
= Logger
.getLogger(VersionableEntity
.class);
40 //time of last update for this object
41 private Calendar updated
;
42 private Person updatedBy
;
43 private T nextVersion
;
44 private T previousVersion
;
48 * Returns the succeeding version of this object with the same UUID
49 * @return next, i.e. succeeding version of this object
51 //@OneToOne(mappedBy="previousVersion")
53 public T
getNextVersion(){
54 return this.nextVersion
;
56 public void setNextVersion(T nextVersion
){
57 this.nextVersion
= nextVersion
;
62 public T
getPreviousVersion(){
63 return this.previousVersion
;
65 public void setPreviousVersion(T previousVersion
){
66 this.previousVersion
= previousVersion
;
70 @ManyToOne(fetch
=FetchType
.LAZY
)
71 @Cascade({CascadeType
.SAVE_UPDATE
})
72 public Person
getUpdatedBy(){
73 return this.updatedBy
;
78 * @param updatedBy updatedBy
80 public void setUpdatedBy(Person updatedBy
){
81 this.updatedBy
= updatedBy
;
88 @Temporal(TemporalType
.TIMESTAMP
)
90 @Basic(fetch
= FetchType
.LAZY
)
91 public Calendar
getUpdated(){
97 * @param updated updated
99 public void setUpdated(Calendar updated
){
100 this.updated
= updated
;
107 public Calendar
getValidFrom(){
115 public Calendar
getValidTo(){
120 * Is true if UUID and created timestamp are the same for the passed Object and this one.
121 * @see eu.etaxonomy.cdm.model.common.CdmBase#equals(java.lang.Object)
122 * See {@link http://www.hibernate.org/109.html hibernate109}, {@link http://www.geocities.com/technofundo/tech/java/equalhash.html geocities}
123 * or {@link http://www.ibm.com/developerworks/java/library/j-jtp05273.html ibm}
124 * for more information about equals and hashcode.
127 public boolean equals(Object obj
) {
134 if (!CdmBase
.class.isAssignableFrom(obj
.getClass())){
137 ICdmBase cdmObj
= (ICdmBase
)obj
;
138 boolean uuidEqual
= cdmObj
.getUuid().equals(this.getUuid());
139 boolean createdEqual
= cdmObj
.getCreated().equals(this.getCreated());
140 if (! uuidEqual
|| !createdEqual
){
147 /** Overrides {@link eu.etaxonomy.cdm.model.common.CdmBase#hashCode()}
148 * See {@link http://www.hibernate.org/109.html}, {@link http://www.geocities.com/technofundo/tech/java/equalhash.html}
149 * or {@link http://www.ibm.com/developerworks/java/library/j-jtp05273.html}
150 * for more information about equals and hashcode.
153 public int hashCode() {
155 hashCode
= 29 * hashCode
+ this.getUuid().hashCode();
156 //hashCode = 29 * hashCode + this.getCreated().hashCode();