1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.cdm.model.common;
|
11
|
|
12
|
import javax.persistence.Column;
|
13
|
import javax.persistence.Entity;
|
14
|
import javax.persistence.FetchType;
|
15
|
import javax.persistence.JoinColumn;
|
16
|
import javax.persistence.ManyToOne;
|
17
|
import javax.xml.bind.annotation.XmlAccessType;
|
18
|
import javax.xml.bind.annotation.XmlAccessorType;
|
19
|
import javax.xml.bind.annotation.XmlElement;
|
20
|
import javax.xml.bind.annotation.XmlIDREF;
|
21
|
import javax.xml.bind.annotation.XmlSchemaType;
|
22
|
import javax.xml.bind.annotation.XmlType;
|
23
|
|
24
|
import org.apache.log4j.Logger;
|
25
|
import org.hibernate.annotations.Any;
|
26
|
import org.hibernate.annotations.Index;
|
27
|
import org.hibernate.annotations.Table;
|
28
|
import org.hibernate.envers.Audited;
|
29
|
import org.hibernate.envers.NotAudited;
|
30
|
import org.hibernate.search.annotations.Field;
|
31
|
|
32
|
import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty;
|
33
|
|
34
|
/**
|
35
|
* @author a.mueller
|
36
|
* @date 2014-06-30
|
37
|
*/
|
38
|
|
39
|
@XmlAccessorType(XmlAccessType.FIELD)
|
40
|
@XmlType(name = "Identifier", propOrder = {
|
41
|
"identifier",
|
42
|
"identifierType"
|
43
|
})
|
44
|
@Entity
|
45
|
@Audited
|
46
|
@Table(appliesTo="Identifier", indexes = { @Index(name = "identifierIndex", columnNames = { "identifier" }) })
|
47
|
public class Identifier<T extends IdentifiableEntity> extends VersionableEntity {
|
48
|
private static final long serialVersionUID = -798893563577142030L;
|
49
|
private static final Logger logger = Logger.getLogger(IdentifiableSource.class);
|
50
|
|
51
|
@XmlElement(name ="Identifier" )
|
52
|
@Column(length=800, name="identifier")
|
53
|
@Field
|
54
|
@NullOrNotEmpty
|
55
|
private String identifier;
|
56
|
|
57
|
@XmlElement(name = "Type")
|
58
|
@XmlIDREF
|
59
|
@XmlSchemaType(name = "IDREF")
|
60
|
@ManyToOne(fetch = FetchType.LAZY)
|
61
|
// @IndexedEmbedded(depth=1)
|
62
|
private DefinedTerm type;
|
63
|
|
64
|
@XmlElement(name = "IdentifiedObject")
|
65
|
@XmlIDREF
|
66
|
@XmlSchemaType(name = "IDREF")
|
67
|
@Any(metaDef = "CdmBase",
|
68
|
metaColumn=@Column(name = "identifiedObj_type"),
|
69
|
fetch = FetchType.LAZY,
|
70
|
optional = false)
|
71
|
@JoinColumn(name = "identifiedObj_id")
|
72
|
@NotAudited
|
73
|
private T identifiedObj;
|
74
|
|
75
|
// **************************** FACTORY ******************************/
|
76
|
|
77
|
public static Identifier NewInstance(IdentifiableEntity entity, String identifier, DefinedTerm type){
|
78
|
return new Identifier(entity, identifier, type);
|
79
|
}
|
80
|
|
81
|
// ************************* CONSTRUCTOR ************************************
|
82
|
|
83
|
@Deprecated //for hibernate use only
|
84
|
protected Identifier(){};
|
85
|
|
86
|
public Identifier (IdentifiableEntity<?> entity, String identifier, DefinedTerm type){
|
87
|
this.identifier = identifier;
|
88
|
this.type = type;
|
89
|
logger.warn("Identified object not yet implemented");
|
90
|
// this.identifiedObj = entity;
|
91
|
}
|
92
|
|
93
|
|
94
|
// ****************** GETTER / SETTER **********************/
|
95
|
|
96
|
public String getIdentifier() {
|
97
|
return identifier;
|
98
|
}
|
99
|
|
100
|
|
101
|
public void setIdentifier(String identifier) {
|
102
|
this.identifier = identifier;
|
103
|
}
|
104
|
|
105
|
|
106
|
public DefinedTerm getType() {
|
107
|
return type;
|
108
|
}
|
109
|
|
110
|
|
111
|
public void setType(DefinedTerm identifierType) {
|
112
|
this.type = identifierType;
|
113
|
}
|
114
|
|
115
|
public T getIdentifiedObj() {
|
116
|
return identifiedObj;
|
117
|
}
|
118
|
protected void setIdentifiedObj(T identifiedObj) {
|
119
|
this.identifiedObj = identifiedObj;
|
120
|
}
|
121
|
|
122
|
}
|