Project

General

Profile

Download (2.3 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

    
13
import java.util.UUID;
14

    
15
import eu.etaxonomy.cdm.model.common.ReferencedEntityBase;
16
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
17

    
18
import org.apache.log4j.Logger;
19
import org.hibernate.annotations.Cascade;
20
import org.hibernate.annotations.CascadeType;
21

    
22
import javax.persistence.*;
23

    
24
/**
25
 * @author m.doering
26
 */
27
@MappedSuperclass
28
public abstract class RelationshipBase<FROM extends IRelated, TO extends IRelated, TYPE extends RelationshipTermBase> extends ReferencedEntityBase {
29
	static Logger logger = Logger.getLogger(RelationshipBase.class);
30
	private FROM relatedFrom;
31
	private TO relatedTo;
32
	private TYPE type;
33

    
34
	protected RelationshipBase(){
35
		super();
36
	}
37
	
38
	/**
39
	 * creates a relationship between 2 names and adds this relationship object to the respective name relation sets
40
	 * @param toName
41
	 * @param fromName
42
	 * @param type
43
	 * @param ruleConsidered
44
	 */
45
	protected RelationshipBase(FROM from, TO to, TYPE type, ReferenceBase citation, String citationMicroReference) {
46
		super(citation, citationMicroReference, null);
47
		setRelatedFrom(from);
48
		setRelatedTo(to);
49
		setType(type);
50
		from.addRelationship(this);
51
		to.addRelationship(this);
52
	}
53
	
54
	@ManyToOne
55
	public TYPE getType(){
56
		return this.type;
57
	}
58
	protected void setType(TYPE type){
59
		this.type = type;
60
	}
61
	
62
	
63
	@ManyToOne(fetch=FetchType.EAGER)
64
	@Cascade({CascadeType.SAVE_UPDATE})
65
	protected FROM getRelatedFrom() {
66
		return relatedFrom;
67
	}
68
	protected void setRelatedFrom(FROM relatedFrom) {
69
		this.relatedFrom = relatedFrom;
70
	}
71

    
72
	
73
	@ManyToOne(fetch=FetchType.EAGER)
74
	@Cascade({CascadeType.SAVE_UPDATE})
75
	protected TO getRelatedTo() {
76
		return relatedTo;
77
	}
78
	protected void setRelatedTo(TO relatedTo) {
79
		this.relatedTo = relatedTo;
80
	}
81
	
82
// TODO
83
//	UUID toUuid; 
84
//	UUID fromUuid;
85
//	
86
//	@Transient
87
//	public UUID getToUuidCache(){
88
//		return relationTo.getUuid();
89
//	}
90
//	protected void setToUuid(UUID uuid){
91
//		toUuid = uuid;
92
//	}
93
//	
94
//	public UUID getFromUuid(){
95
//		return relationTo.getUuid();
96
//	}
97
//	protected void setFromUuid(UUID uuid){
98
//		fromUuid = uuid;
99
//	}
100
}
(29-29/39)