make Sequence.sequence a clob (#3325)
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / molecular / Sequence.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.molecular;
11
12
13 import java.util.HashSet;
14 import java.util.Set;
15
16 import javax.persistence.Basic;
17 import javax.persistence.Entity;
18 import javax.persistence.FetchType;
19 import javax.persistence.Lob;
20 import javax.persistence.ManyToOne;
21 import javax.persistence.OneToMany;
22 import javax.persistence.Transient;
23 import javax.xml.bind.annotation.XmlAccessType;
24 import javax.xml.bind.annotation.XmlAccessorType;
25 import javax.xml.bind.annotation.XmlAttribute;
26 import javax.xml.bind.annotation.XmlElement;
27 import javax.xml.bind.annotation.XmlElementWrapper;
28 import javax.xml.bind.annotation.XmlIDREF;
29 import javax.xml.bind.annotation.XmlRootElement;
30 import javax.xml.bind.annotation.XmlSchemaType;
31 import javax.xml.bind.annotation.XmlType;
32 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
33
34 import org.apache.log4j.Logger;
35 import org.hibernate.annotations.Cascade;
36 import org.hibernate.annotations.CascadeType;
37 import org.hibernate.annotations.Index;
38 import org.hibernate.annotations.Table;
39 import org.hibernate.annotations.Type;
40 import org.hibernate.envers.Audited;
41 import org.joda.time.DateTime;
42 import org.springframework.beans.factory.annotation.Configurable;
43
44 import eu.etaxonomy.cdm.jaxb.DateTimeAdapter;
45 import eu.etaxonomy.cdm.model.common.IReferencedEntity;
46 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
47 import eu.etaxonomy.cdm.model.media.IMediaDocumented;
48 import eu.etaxonomy.cdm.model.media.Media;
49 import eu.etaxonomy.cdm.model.reference.Reference;
50 import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
51 import eu.etaxonomy.cdm.strategy.cache.common.IdentifiableEntityDefaultCacheStrategy;
52
53 /**
54 * @author m.doering
55 * @version 1.0
56 * @created 08-Nov-2007 13:06:51
57 */
58 @XmlAccessorType(XmlAccessType.FIELD)
59 @XmlType(name = "Sequence", propOrder = {
60 "sequence",
61 "length",
62 "dateSequenced",
63 "barcode",
64 "citationMicroReference",
65 "publishedIn",
66 "locus",
67 "citations",
68 "genBankAccession",
69 "chromatograms"
70 })
71 @XmlRootElement(name = "Sequence")
72 @Entity
73 @Audited
74 @Configurable
75 @Table(appliesTo="Sequence", indexes = { @Index(name = "sequenceTitleCacheIndex", columnNames = { "titleCache" }) })
76 public class Sequence extends IdentifiableEntity<IIdentifiableEntityCacheStrategy<Sequence>> implements IReferencedEntity, IMediaDocumented{
77 private static final long serialVersionUID = 8298983152731241775L;
78 private static final Logger logger = Logger.getLogger(Sequence.class);
79
80 //the sequence as a string of base pairs. 5'->3'
81 @XmlElement(name = "Sequence")
82 @Lob
83 private String sequence;
84
85 //should be calculated in case sequence is set
86 @XmlElement(name = "Length")
87 private Integer length;
88
89 //should be calculated in case sequence is set
90 @XmlElement (name = "DateSequenced", type= String.class)
91 @XmlJavaTypeAdapter(DateTimeAdapter.class)
92 @Type(type="dateTimeUserType")
93 @Basic(fetch = FetchType.LAZY)
94 private DateTime dateSequenced;
95
96 //should be calculated in case sequence is set
97 @XmlAttribute(name = "isBarcode")
98 private boolean barcode;
99
100 //the sequence as a string of base pairs. 5'->3'
101 @XmlElement(name = "CitationMicroReference")
102 private String citationMicroReference;
103
104 @XmlElement(name = "PublishedIn")
105 @XmlIDREF
106 @XmlSchemaType(name = "IDREF")
107 @ManyToOne(fetch = FetchType.LAZY)
108 @Cascade(CascadeType.SAVE_UPDATE)
109 private Reference<?> publishedIn;
110
111 @XmlElementWrapper(name = "Citations")
112 @XmlElement(name = "Citation")
113 @XmlIDREF
114 @XmlSchemaType(name = "IDREF")
115 @OneToMany(fetch = FetchType.LAZY)
116 private Set<Reference> citations = new HashSet<Reference>();
117
118 @XmlElementWrapper(name = "GenBankAccessions")
119 @XmlElement(name = "GenBankAccession")
120 @OneToMany(fetch = FetchType.LAZY)
121 @Cascade(CascadeType.SAVE_UPDATE)
122 private Set<GenBankAccession> genBankAccession = new HashSet<GenBankAccession>();
123
124 @XmlElement(name = "Locus")
125 @XmlIDREF
126 @XmlSchemaType(name = "IDREF")
127 @ManyToOne(fetch = FetchType.LAZY)
128 @Cascade(CascadeType.SAVE_UPDATE)
129 private Locus locus;
130
131 @XmlElementWrapper(name = "Chromatograms")
132 @XmlElement(name = "Chromatogram")
133 @XmlIDREF
134 @XmlSchemaType(name = "IDREF")
135 @OneToMany(fetch = FetchType.LAZY)
136 private Set<Media> chromatograms = new HashSet<Media>();
137
138 //*********************** FACTORY ****************************************************/
139
140 public static Sequence NewInstance(String sequence){
141 Sequence result = new Sequence();
142 result.setSequence(sequence);
143 return result;
144 }
145
146 //*********************** CONSTRUCTOR ****************************************************/
147
148 protected Sequence() {
149 super(); // FIXME I think this is explicit - do we really need to call this?
150 this.cacheStrategy = new IdentifiableEntityDefaultCacheStrategy<Sequence>();
151 }
152
153 //*********************** GETTER / SETTER ****************************************************/
154
155 public Locus getLocus(){
156 return this.locus;
157 }
158
159 public void setLocus(Locus locus){
160 this.locus = locus;
161 }
162
163 public Reference getPublishedIn(){
164 return this.publishedIn;
165 }
166
167 public void setPublishedIn(Reference publishedIn){
168 this.publishedIn = publishedIn;
169 }
170
171 public Set<Reference> getCitations() {
172 return citations;
173 }
174 protected void setCitations(Set<Reference> citations) {
175 this.citations = citations;
176 }
177 public void addCitation(Reference citation) {
178 this.citations.add(citation);
179 }
180 public void removeCitation(Reference citation) {
181 this.citations.remove(citation);
182 }
183
184 public Set<GenBankAccession> getGenBankAccession() {
185 return genBankAccession;
186 }
187
188 public void addGenBankAccession(GenBankAccession genBankAccession) {
189 this.genBankAccession.add(genBankAccession);
190 }
191
192 public void removeGenBankAccession(GenBankAccession genBankAccession) {
193 this.genBankAccession.remove(genBankAccession);
194 }
195
196 public Set<Media> getChromatograms() {
197 return chromatograms;
198 }
199
200 public void addChromatogram(Media chromatogram) {
201 this.chromatograms.add(chromatogram);
202 }
203
204 public void removeChromatogram(Media chromatogram) {
205 this.chromatograms.remove(chromatogram);
206 }
207
208 @Transient
209 public Set<Media> getMedia() {
210 return getChromatograms();
211 }
212
213 public String getSequence(){
214 return this.sequence;
215 }
216
217 /**
218 *
219 * @param sequence sequence
220 */
221 public void setSequence(String sequence){
222 this.sequence = sequence;
223 }
224
225 public Integer getLength(){
226 return this.length;
227 }
228
229 /**
230 *
231 * @param length length
232 */
233 public void setLength(Integer length){
234 this.length = length;
235 }
236
237 public DateTime getDateSequenced(){
238 return this.dateSequenced;
239 }
240
241 /**
242 *
243 * @param dateSequenced dateSequenced
244 */
245 public void setDateSequenced(DateTime dateSequenced){
246 this.dateSequenced = dateSequenced;
247 }
248
249 public boolean isBarcode(){
250 return this.barcode;
251 }
252
253 /**
254 *
255 * @param isBarcode isBarcode
256 */
257 public void setBarcode(boolean barcode){
258 this.barcode = barcode;
259 }
260
261 public String getCitationMicroReference(){
262 return this.citationMicroReference;
263 }
264
265 /**
266 *
267 * @param citationMicroReference citationMicroReference
268 */
269 public void setCitationMicroReference(String citationMicroReference){
270 this.citationMicroReference = citationMicroReference;
271 }
272
273 public Reference getCitation(){
274 return publishedIn;
275 }
276
277 //*********************** CLONE ********************************************************/
278 /**
279 * Clones <i>this</i> sequence. This is a shortcut that enables to create
280 * a new instance that differs only slightly from <i>this</i> sequence by
281 * modifying only some of the attributes.<BR><BR>
282 *
283 *
284 * @see eu.etaxonomy.cdm.model.media.IdentifiableEntity#clone()
285 * @see java.lang.Object#clone()
286 */
287 @Override
288 public Object clone() {
289 try{
290 Sequence result = (Sequence)super.clone();
291
292 result.citations = new HashSet<Reference>();
293 for (Reference ref: this.citations){
294 result.citations.add((Reference) ref.clone());
295
296 }
297
298 result.genBankAccession = new HashSet<GenBankAccession>();
299 for (GenBankAccession genBankAcc: this.genBankAccession){
300 result.genBankAccession.add((GenBankAccession)genBankAcc.clone());
301 }
302
303 result.chromatograms = new HashSet<Media>();
304
305 for (Media chromatogram: this.chromatograms){
306 result.chromatograms.add((Media)chromatogram.clone());
307 }
308
309 return result;
310 }catch (CloneNotSupportedException e) {
311 logger.warn("Object does not implement cloneable");
312 e.printStackTrace();
313 return null;
314 }
315 }
316 }