Project

General

Profile

Download (4.89 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
package eu.etaxonomy.cdm.model.molecular;
10

    
11
import javax.persistence.Column;
12
import javax.persistence.Entity;
13
import javax.persistence.FetchType;
14
import javax.persistence.ManyToOne;
15
import javax.xml.bind.annotation.XmlAccessType;
16
import javax.xml.bind.annotation.XmlAccessorType;
17
import javax.xml.bind.annotation.XmlElement;
18
import javax.xml.bind.annotation.XmlIDREF;
19
import javax.xml.bind.annotation.XmlRootElement;
20
import javax.xml.bind.annotation.XmlSchemaType;
21
import javax.xml.bind.annotation.XmlType;
22

    
23
import org.apache.log4j.Logger;
24
import org.hibernate.annotations.Cascade;
25
import org.hibernate.annotations.CascadeType;
26
import org.hibernate.envers.Audited;
27

    
28
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
29
import eu.etaxonomy.cdm.model.common.DefinedTerm;
30
import eu.etaxonomy.cdm.model.reference.Reference;
31

    
32
/**
33
 * A primer is a (short) DNA Sequence used for replication and extraction
34
 * of DNA parts during e.g. {@link Amplification amplification} or
35
 * {@link SingleRead sequence reading}.
36
 *
37
 * @author a.mueller
38
 * @created 2013-07-08
39
 *
40
 */
41
@XmlAccessorType(XmlAccessType.FIELD)
42
@XmlType(name = "Primer", propOrder = {
43
	"label",
44
	"sequence",
45
	"dnaMarker",
46
	"publishedIn"
47
})
48
@XmlRootElement(name = "Primer")
49
@Entity
50
@Audited
51
//TODO which base class  (..., identifiable, definedTerm, ...)
52
public class Primer extends AnnotatableEntity {
53
	private static final long serialVersionUID = 6179007910988646989L;
54
	private static final Logger logger = Logger.getLogger(Primer.class);
55

    
56
	/** @see #getLabel() */
57
	@XmlElement(name = "Label")
58
    @Column(length=255)
59
	private String label;
60

    
61
	/** @see #getSequence() */
62
	//(see #4139)
63
	@XmlElement(name = "Sequence")
64
 	private SequenceString sequence = SequenceString.NewInstance();
65

    
66

    
67
    /** @see #getDnaMarker()*/
68
    @XmlElement(name = "DnaMarker")
69
    @XmlIDREF
70
    @XmlSchemaType(name = "IDREF")
71
    @ManyToOne(fetch=FetchType.LAZY)
72
    private DefinedTerm dnaMarker;
73

    
74
	/** @see #getPublishedIn() */
75
	@XmlElement(name = "PublishedIn")
76
    @XmlIDREF
77
    @XmlSchemaType(name = "IDREF")
78
    @ManyToOne(fetch=FetchType.LAZY)
79
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
80
	private Reference publishedIn;
81

    
82

    
83

    
84
	// ******************** FACTORY METHOD ******************/
85

    
86
	public static Primer NewInstance(String label){
87
		Primer result = new Primer();
88
		result.setLabel(label);
89
		return result;
90
	}
91

    
92
	// ********************* CONSTRUCTOR ********************/
93

    
94
	//made protected to fix a java.lang.InstantiationException which occurred while loading an Amplification
95
	//and its primer. see https://stackoverflow.com/questions/7273125/hibernate-envers-and-javassist-enhancement-failed-exception
96
	protected Primer(){}
97

    
98
// ********************* GETTER / SETTER ********************/
99

    
100

    
101
	/**
102
	 * The name of this primer, usually given by the producers.
103
	 * @return the label of this primer.
104
	 */
105
	public String getLabel() {
106
		return label;
107
	}
108

    
109
	/**
110
	 * @see #getLabel()
111
	 */
112
	public void setLabel(String label) {
113
		this.label = label;
114
	}
115

    
116
	/**
117
	 * The DNA {@link Sequence} of this primer. A primer is usually a
118
	 * small piece of DNA and therefore can be expressed as a sequence.
119
	 */
120
	public SequenceString getSequence() {
121
		return sequence;
122
	}
123

    
124
	/**
125
	 * @see Primer#getSequence()
126
	 */
127
	public void setSequence(SequenceString sequence) {
128
		if (sequence == null){
129
			sequence = SequenceString.NewInstance();
130
		}
131
		this.sequence = sequence;
132
	}
133

    
134

    
135
	/**
136
	 * #4470
137
	 */
138
	public DefinedTerm getDnaMarker() {
139
		return dnaMarker;
140
	}
141

    
142
	public void setDnaMarker(DefinedTerm dnaMarker) {
143
		this.dnaMarker = dnaMarker;
144
	}
145

    
146
	/**
147
	 * The reference in which this primer was published and described
148
	 * for the first time. It is not a reference or citation for the
149
	 * sequence of this primer.<BR>
150
	 * Links to this reference are stored with the reference itself.
151
	 * @return the describing publication of this primer
152
	 */
153
	public Reference getPublishedIn() {
154
		return publishedIn;
155
	}
156

    
157
	/**
158
	 * @see #getPublishedIn()
159
	 */
160
	public void setPublishedIn(Reference publishedIn) {
161
		this.publishedIn = publishedIn;
162
	}
163

    
164
	// ********************* CLONE ********************/
165
	/**
166
	 * Clones <i>this</i> primer. This is a shortcut that enables to create
167
	 * a new instance that differs only slightly from <i>this</i> primer by
168
	 * modifying only some of the attributes.<BR><BR>
169
	 *
170
	 *
171
	 * @see eu.etaxonomy.cdm.model.media.IdentifiableEntity#clone()
172
	 * @see java.lang.Object#clone()
173
	 */
174
	@Override
175
	public Object clone()  {
176
		try{
177
		Primer result = (Primer)super.clone();
178

    
179
//		don't change label, sequence
180
		result.publishedIn = this.publishedIn;
181

    
182
		return result;
183
		}catch (CloneNotSupportedException e) {
184
			logger.warn("Object does not implement cloneable");
185
			e.printStackTrace();
186
			return null;
187
		}
188
	}
189
}
(7-7/14)