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 javax
.persistence
.Basic
;
13 import javax
.persistence
.FetchType
;
14 import javax
.persistence
.ManyToOne
;
15 import javax
.persistence
.MappedSuperclass
;
16 import javax
.xml
.bind
.annotation
.XmlAccessType
;
17 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
18 import javax
.xml
.bind
.annotation
.XmlElement
;
19 import javax
.xml
.bind
.annotation
.XmlIDREF
;
20 import javax
.xml
.bind
.annotation
.XmlSchemaType
;
21 import javax
.xml
.bind
.annotation
.XmlType
;
22 import javax
.xml
.bind
.annotation
.adapters
.XmlJavaTypeAdapter
;
24 import org
.apache
.log4j
.Logger
;
25 import org
.hibernate
.annotations
.Type
;
26 import org
.hibernate
.search
.annotations
.Field
;
27 import org
.hibernate
.search
.annotations
.FieldBridge
;
28 import org
.joda
.time
.DateTime
;
30 import eu
.etaxonomy
.cdm
.hibernate
.DateTimeBridge
;
31 import eu
.etaxonomy
.cdm
.jaxb
.DateTimeAdapter
;
32 import eu
.etaxonomy
.cdm
.strategy
.match
.Match
;
33 import eu
.etaxonomy
.cdm
.strategy
.match
.MatchMode
;
36 * 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.
38 * Full versioning allows concrete subclasses to keep track of previous or later versions of an object.
39 * A different version is another (persistent) java object, but with the same UUID.
40 * The version history is established as a linked list of the version objects in time.
41 * If versioning via the linked list is used, updated/updatedBy is the same as created/createdBy (better NULL?).
43 * Versioning can be turned off and in this case this class provides updated/updatedBy to keep track of the latest change event.
46 * @created 08-Nov-2007 13:07:01
50 @XmlAccessorType(XmlAccessType
.FIELD
)
51 @XmlType(name
= "VersionableEntity", propOrder
= {
55 @XmlJavaTypeAdapter(value
=DateTimeAdapter
.class,type
=DateTime
.class)
57 public abstract class VersionableEntity
extends CdmBase
implements IVersionableEntity
{
58 private static final long serialVersionUID
= 1409299200302758513L;
59 @SuppressWarnings("unused")
60 private static final Logger logger
= Logger
.getLogger(VersionableEntity
.class);
62 @XmlElement(name
="Updated", type
= String
.class)
63 @XmlJavaTypeAdapter(DateTimeAdapter
.class)
64 //@XmlElement(name ="Updated")
65 //@XmlElement(name ="Updated")
66 @Type(type
="dateTimeUserType")
67 @Basic(fetch
= FetchType
.LAZY
)
68 @Match(MatchMode
.IGNORE
)
69 @Field(index
= org
.hibernate
.search
.annotations
.Index
.UN_TOKENIZED
)
70 @FieldBridge(impl
= DateTimeBridge
.class)
71 private DateTime updated
;
73 @XmlElement(name
= "UpdatedBy")
75 @XmlSchemaType(name
= "IDREF")
76 @ManyToOne(fetch
=FetchType
.LAZY
)
77 @Match(MatchMode
.IGNORE
)
78 private User updatedBy
;
80 public User
getUpdatedBy(){
81 return this.updatedBy
;
86 * @param updatedBy updatedBy
88 public void setUpdatedBy(User updatedBy
){
89 this.updatedBy
= updatedBy
;
96 public DateTime
getUpdated(){
102 * @param updated updated
104 public void setUpdated(DateTime updated
){
105 this.updated
= updated
;
109 * Is true if UUID and created timestamp are the same for the passed Object and this one.
110 * @see eu.etaxonomy.cdm.model.common.CdmBase#equals(java.lang.Object)
111 * See {@link http://www.hibernate.org/109.html hibernate109}, {@link http://www.geocities.com/technofundo/tech/java/equalhash.html geocities}
112 * or {@link http://www.ibm.com/developerworks/java/library/j-jtp05273.html ibm}
113 * for more information about equals and hashcode.
116 public boolean equals(Object obj
) {
123 if (!CdmBase
.class.isAssignableFrom(obj
.getClass())){
126 ICdmBase cdmObj
= (ICdmBase
)obj
;
127 boolean uuidEqual
= cdmObj
.getUuid().equals(this.getUuid());
128 boolean createdEqual
= cdmObj
.getCreated().equals(this.getCreated());
129 if (! uuidEqual
|| !createdEqual
){
136 //********************** CLONE *****************************************/
139 * Clones this versionable entity.
140 * Set fields for nextVersion, previousVersion, updated, updatedBy and createdBy are set to <tt>null</tt>
141 * The id is set to 0.
142 * The uuid is created new.
143 * The createdWhen is set to the current date.
144 * @see java.lang.Object#clone()
147 public Object
clone() throws CloneNotSupportedException
{
148 VersionableEntity result
= (VersionableEntity
)super.clone();
150 result
.setUpdated(null);
151 result
.setUpdatedBy(null);