Project

General

Profile

Download (4.73 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9

    
10
package eu.etaxonomy.cdm.model.common;
11

    
12
import java.util.HashMap;
13
import java.util.Map;
14

    
15
import javax.persistence.Basic;
16
import javax.persistence.FetchType;
17
import javax.persistence.ManyToOne;
18
import javax.persistence.MappedSuperclass;
19
import javax.xml.bind.annotation.XmlAccessType;
20
import javax.xml.bind.annotation.XmlAccessorType;
21
import javax.xml.bind.annotation.XmlElement;
22
import javax.xml.bind.annotation.XmlIDREF;
23
import javax.xml.bind.annotation.XmlSchemaType;
24
import javax.xml.bind.annotation.XmlType;
25
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
26

    
27
import org.apache.log4j.Logger;
28
import org.hibernate.annotations.Type;
29
import org.hibernate.envers.Audited;
30
import org.hibernate.search.annotations.Analyze;
31
import org.hibernate.search.annotations.Field;
32
import org.hibernate.search.annotations.FieldBridge;
33
import org.joda.time.DateTime;
34

    
35
import eu.etaxonomy.cdm.hibernate.search.DateTimeBridge;
36
import eu.etaxonomy.cdm.jaxb.DateTimeAdapter;
37
import eu.etaxonomy.cdm.strategy.match.Match;
38
import eu.etaxonomy.cdm.strategy.match.MatchMode;
39

    
40
/**
41
 * 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.
42
 *
43
 * Full versioning allows concrete subclasses to keep track of previous or later versions of an object.
44
 * A different version is another (persistent) java object, but with the same UUID.
45
 * The version history is established as a linked list of the version objects in time.
46
 * If versioning via the linked list is used, updated/updatedBy is the same as created/createdBy (better NULL?).
47
 *
48
 * Versioning can be turned off and in this case this class provides updated/updatedBy to
49
 * keep track of the latest change event.
50
 *
51
 * @author m.doering
52
 * @since 08-Nov-2007 13:07:01
53
 *
54
 * @param <T>
55
 */
56
@XmlAccessorType(XmlAccessType.FIELD)
57
@XmlType(name = "VersionableEntity", propOrder = {
58
    "updated",
59
    "updatedBy"
60
})
61
@XmlJavaTypeAdapter(value=DateTimeAdapter.class,type=DateTime.class)
62
@MappedSuperclass
63
@Audited
64
public abstract class VersionableEntity extends CdmBase implements IVersionableEntity{
65
	private static final long serialVersionUID = 1409299200302758513L;
66
	@SuppressWarnings("unused")
67
	private static final Logger logger = Logger.getLogger(VersionableEntity.class);
68

    
69
	@XmlElement(name ="Updated", type = String.class)
70
	@XmlJavaTypeAdapter(DateTimeAdapter.class)
71
	//@XmlElement(name ="Updated")
72
	//@XmlElement(name ="Updated")
73
	@Type(type="dateTimeUserType")
74
	@Basic(fetch = FetchType.LAZY)
75
	@Match(MatchMode.IGNORE)
76
	@Field(analyze = Analyze.NO)
77
	@FieldBridge(impl = DateTimeBridge.class)
78
	private DateTime updated;
79

    
80
	@XmlElement(name = "UpdatedBy")
81
	@XmlIDREF
82
	@XmlSchemaType(name = "IDREF")
83
	@ManyToOne(fetch=FetchType.LAZY)
84
	@Match(MatchMode.IGNORE)
85
	private User updatedBy;
86

    
87
	@Override
88
    public User getUpdatedBy(){
89
		return this.updatedBy;
90
	}
91
	@Override
92
    public void setUpdatedBy(User updatedBy){
93
		this.updatedBy = updatedBy;
94
	}
95

    
96
	@Override
97
    public DateTime getUpdated(){
98
		return this.updated;
99
	}
100
	@Override
101
    public void setUpdated(DateTime updated){
102
		this.updated = updated;
103
	}
104

    
105
	/**
106
	 * {@inheritDoc}.
107
	 * <BR><BR>
108
	 * Override CdmBase implementation here to set the method final.
109
	 * For discussion on final see {@link CdmBase#equals(Object)}.
110
	 */
111
	@Override
112
    public final boolean equals(Object obj) {
113
	    return super.equals(obj);
114
	}
115

    
116
//********************** CLONE *****************************************/
117

    
118
	/**
119
	 * Clones this versionable entity.
120
	 * Set fields for nextVersion, previousVersion, updated, updatedBy and createdBy are set to <tt>null</tt>
121
	 * The id is set to 0.
122
	 * The uuid is created new.
123
	 * The createdWhen is set to the current date.
124
	 * @see java.lang.Object#clone()
125
	 */
126
	@Override
127
	public Object clone() throws CloneNotSupportedException{
128
		VersionableEntity result = (VersionableEntity)super.clone();
129

    
130
		result.setUpdated(null);
131
		result.setUpdatedBy(null);
132

    
133
		//no changes to: -
134
		return result;
135
	}
136

    
137

    
138
    /**
139
     * Convenience method to clone a LanguageString map
140
     * @param oldMap
141
     * @return
142
     * @throws CloneNotSupportedException
143
     */
144
    protected Map<Language,LanguageString> cloneLanguageString(Map<Language,LanguageString> oldMap) throws CloneNotSupportedException{
145
        Map<Language,LanguageString> result = new HashMap<>();
146
        for (Language language : oldMap.keySet()){
147
            LanguageString newLanguageString = (LanguageString)oldMap.get(language).clone();
148
            result.put(language, newLanguageString);
149
        }
150
        return result;
151
    }
152
}
(75-75/79)