6632ad7d8b6f9b1d02c750c57de9fc52adbefd31
[cdmlib.git] / cdmlibrary / src / main / java / eu / etaxonomy / cdm / model / common / VersionableEntity.java
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
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;
18
19 import java.util.*;
20 import javax.persistence.*;
21
22 /**
23 * @author m.doering
24 * @version 1.0
25 * @created 08-Nov-2007 13:07:01
26 */
27 @MappedSuperclass
28 public abstract class VersionableEntity<T extends VersionableEntity> extends CdmBase {
29 static Logger logger = Logger.getLogger(VersionableEntity.class);
30 //the globally unique identifier
31 private String uuid;
32 private Calendar created;
33 private Person createdBy;
34 //time of last update for this object
35 private Calendar updated;
36 private Person updatedBy;
37 private T nextVersion;
38 private T previousVersion;
39
40 public VersionableEntity() {
41 super();
42 this.uuid = UUID.randomUUID().toString();
43 this.created = Calendar.getInstance();
44 }
45
46
47 //@OneToOne(mappedBy="previousVersion")
48 @Transient
49 public T getNextVersion(){
50 return this.nextVersion;
51 }
52 public void setNextVersion(T nextVersion){
53 this.nextVersion = nextVersion;
54 }
55
56 //@OneToOne
57 @Transient
58 public T getPreviousVersion(){
59 return this.previousVersion;
60 }
61 public void setPreviousVersion(T previousVersion){
62 this.previousVersion = previousVersion;
63 }
64
65
66 @ManyToOne
67 @Cascade({CascadeType.SAVE_UPDATE})
68 public Person getUpdatedBy(){
69 return this.updatedBy;
70 }
71
72 /**
73 *
74 * @param updatedBy updatedBy
75 */
76 public void setUpdatedBy(Person updatedBy){
77 this.updatedBy = updatedBy;
78 }
79
80 @ManyToOne
81 @Cascade({CascadeType.SAVE_UPDATE})
82 public Person getCreatedBy(){
83 return this.createdBy;
84 }
85
86 /**
87 *
88 * @param createdBy createdBy
89 */
90 public void setCreatedBy(Person createdBy){
91 this.createdBy = createdBy;
92 }
93
94 public String getUuid(){
95 return this.uuid;
96 }
97 /**
98 *
99 * @param uuid uuid
100 */
101 protected void setUuid(String uuid){
102 this.uuid = uuid;
103 }
104
105 @Temporal(TemporalType.TIMESTAMP)
106 public Calendar getCreated(){
107 return this.created;
108 }
109 /**
110 *
111 * @param created created
112 */
113 public void setCreated(Calendar created){
114 this.created = created;
115 }
116
117 @Temporal(TemporalType.TIMESTAMP)
118 public Calendar getUpdated(){
119 return this.updated;
120 }
121
122 /**
123 *
124 * @param updated updated
125 */
126 public void setUpdated(Calendar updated){
127 this.updated = updated;
128 }
129
130 /**
131 * based on created
132 */
133 @Transient
134 public Calendar getValidFrom(){
135 return null;
136 }
137
138 /**
139 * based on updated
140 */
141 @Transient
142 public Calendar getValidTo(){
143 return null;
144 }
145
146 }