2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.model
.molecular
;
13 import java
.util
.HashSet
;
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
;
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
;
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
;
56 * @created 08-Nov-2007 13:06:51
58 @XmlAccessorType(XmlAccessType
.FIELD
)
59 @XmlType(name
= "Sequence", propOrder
= {
64 "citationMicroReference",
71 @XmlRootElement(name
= "Sequence")
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);
80 //the sequence as a string of base pairs. 5'->3'
81 @XmlElement(name
= "Sequence")
83 private String sequence
;
85 //should be calculated in case sequence is set
86 @XmlElement(name
= "Length")
87 private Integer length
;
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
;
96 //should be calculated in case sequence is set
97 @XmlAttribute(name
= "isBarcode")
98 private boolean barcode
;
100 //the sequence as a string of base pairs. 5'->3'
101 @XmlElement(name
= "CitationMicroReference")
102 private String citationMicroReference
;
104 @XmlElement(name
= "PublishedIn")
106 @XmlSchemaType(name
= "IDREF")
107 @ManyToOne(fetch
= FetchType
.LAZY
)
108 @Cascade(CascadeType
.SAVE_UPDATE
)
109 private Reference
<?
> publishedIn
;
111 @XmlElementWrapper(name
= "Citations")
112 @XmlElement(name
= "Citation")
114 @XmlSchemaType(name
= "IDREF")
115 @OneToMany(fetch
= FetchType
.LAZY
)
116 private Set
<Reference
> citations
= new HashSet
<Reference
>();
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
>();
124 @XmlElement(name
= "Locus")
126 @XmlSchemaType(name
= "IDREF")
127 @ManyToOne(fetch
= FetchType
.LAZY
)
128 @Cascade(CascadeType
.SAVE_UPDATE
)
131 @XmlElementWrapper(name
= "Chromatograms")
132 @XmlElement(name
= "Chromatogram")
134 @XmlSchemaType(name
= "IDREF")
135 @OneToMany(fetch
= FetchType
.LAZY
)
136 private Set
<Media
> chromatograms
= new HashSet
<Media
>();
138 //*********************** FACTORY ****************************************************/
140 public static Sequence
NewInstance(String sequence
){
141 Sequence result
= new Sequence();
142 result
.setSequence(sequence
);
146 //*********************** CONSTRUCTOR ****************************************************/
148 protected Sequence() {
149 super(); // FIXME I think this is explicit - do we really need to call this?
150 this.cacheStrategy
= new IdentifiableEntityDefaultCacheStrategy
<Sequence
>();
153 //*********************** GETTER / SETTER ****************************************************/
155 public Locus
getLocus(){
159 public void setLocus(Locus locus
){
163 public Reference
getPublishedIn(){
164 return this.publishedIn
;
167 public void setPublishedIn(Reference publishedIn
){
168 this.publishedIn
= publishedIn
;
171 public Set
<Reference
> getCitations() {
174 protected void setCitations(Set
<Reference
> citations
) {
175 this.citations
= citations
;
177 public void addCitation(Reference citation
) {
178 this.citations
.add(citation
);
180 public void removeCitation(Reference citation
) {
181 this.citations
.remove(citation
);
184 public Set
<GenBankAccession
> getGenBankAccession() {
185 return genBankAccession
;
188 public void addGenBankAccession(GenBankAccession genBankAccession
) {
189 this.genBankAccession
.add(genBankAccession
);
192 public void removeGenBankAccession(GenBankAccession genBankAccession
) {
193 this.genBankAccession
.remove(genBankAccession
);
196 public Set
<Media
> getChromatograms() {
197 return chromatograms
;
200 public void addChromatogram(Media chromatogram
) {
201 this.chromatograms
.add(chromatogram
);
204 public void removeChromatogram(Media chromatogram
) {
205 this.chromatograms
.remove(chromatogram
);
209 public Set
<Media
> getMedia() {
210 return getChromatograms();
213 public String
getSequence(){
214 return this.sequence
;
219 * @param sequence sequence
221 public void setSequence(String sequence
){
222 this.sequence
= sequence
;
225 public Integer
getLength(){
231 * @param length length
233 public void setLength(Integer length
){
234 this.length
= length
;
237 public DateTime
getDateSequenced(){
238 return this.dateSequenced
;
243 * @param dateSequenced dateSequenced
245 public void setDateSequenced(DateTime dateSequenced
){
246 this.dateSequenced
= dateSequenced
;
249 public boolean isBarcode(){
255 * @param isBarcode isBarcode
257 public void setBarcode(boolean barcode
){
258 this.barcode
= barcode
;
261 public String
getCitationMicroReference(){
262 return this.citationMicroReference
;
267 * @param citationMicroReference citationMicroReference
269 public void setCitationMicroReference(String citationMicroReference
){
270 this.citationMicroReference
= citationMicroReference
;
273 public Reference
getCitation(){
277 //*********************** CLONE ********************************************************/
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>
284 * @see eu.etaxonomy.cdm.model.media.IdentifiableEntity#clone()
285 * @see java.lang.Object#clone()
288 public Object
clone() {
290 Sequence result
= (Sequence
)super.clone();
292 result
.citations
= new HashSet
<Reference
>();
293 for (Reference ref
: this.citations
){
294 result
.citations
.add((Reference
) ref
.clone());
298 result
.genBankAccession
= new HashSet
<GenBankAccession
>();
299 for (GenBankAccession genBankAcc
: this.genBankAccession
){
300 result
.genBankAccession
.add((GenBankAccession
)genBankAcc
.clone());
303 result
.chromatograms
= new HashSet
<Media
>();
305 for (Media chromatogram
: this.chromatograms
){
306 result
.chromatograms
.add((Media
)chromatogram
.clone());
310 }catch (CloneNotSupportedException e
) {
311 logger
.warn("Object does not implement cloneable");