001package org.biopax.paxtools.impl.level3;
002
003import org.biopax.paxtools.impl.BioPAXElementImpl;
004import org.biopax.paxtools.model.level3.BioSource;
005import org.biopax.paxtools.model.level3.Level3Element;
006import org.biopax.paxtools.model.level3.Pathway;
007import org.biopax.paxtools.model.level3.Provenance;
008import org.biopax.paxtools.util.*;
009import org.hibernate.annotations.Cache;
010import org.hibernate.annotations.*;
011import org.hibernate.search.annotations.Analyze;
012import org.hibernate.search.annotations.Field;
013import org.hibernate.search.annotations.FieldBridge;
014import org.hibernate.search.annotations.Store;
015
016import javax.persistence.*;
017import javax.persistence.Entity;
018import java.util.Set;
019
020import static org.hibernate.annotations.FetchProfile.FetchOverride;
021
022/**
023 * Base BioPAX Level3 element.
024 *
025 */
026@Entity
027@Proxy(proxyClass= Level3Element.class)
028@DynamicUpdate @DynamicInsert
029@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
030@FetchProfiles({
031@FetchProfile(name = "mul_properties_join", fetchOverrides = {
032 @FetchOverride(entity = EvidenceImpl.class, association = "experimentalForm", mode = FetchMode.JOIN),
033 @FetchOverride(entity = EntityFeatureImpl.class, association = "memberFeature", mode = FetchMode.JOIN),
034 @FetchOverride(entity = CatalysisImpl.class, association = "cofactor", mode = FetchMode.JOIN),
035 @FetchOverride(entity = EntityReferenceImpl.class, association = "memberEntityReference", mode = FetchMode.JOIN),
036 @FetchOverride(entity = ComplexImpl.class, association = "componentStoichiometry", mode = FetchMode.JOIN),
037 @FetchOverride(entity = BiochemicalReactionImpl.class, association = "ECNumber", mode = FetchMode.JOIN),
038 @FetchOverride(entity = ExperimentalFormImpl.class, association = "experimentalFormDescription", mode = FetchMode.JOIN),
039 @FetchOverride(entity = ComplexImpl.class, association = "component", mode = FetchMode.JOIN),
040 @FetchOverride(entity = ConversionImpl.class, association = "participantStoichiometry", mode = FetchMode.JOIN),
041 @FetchOverride(entity = PhysicalEntityImpl.class, association = "feature", mode = FetchMode.JOIN),
042 @FetchOverride(entity = ConversionImpl.class, association = "right", mode = FetchMode.JOIN),
043 @FetchOverride(entity = PathwayStepImpl.class, association = "stepProcessX", mode = FetchMode.JOIN),
044 @FetchOverride(entity = ExperimentalFormImpl.class, association = "experimentalFeature", mode = FetchMode.JOIN),
045 @FetchOverride(entity = ControlImpl.class, association = "controlled", mode = FetchMode.JOIN),
046 @FetchOverride(entity = PublicationXrefImpl.class, association = "url", mode = FetchMode.JOIN),
047 @FetchOverride(entity = InteractionImpl.class, association = "participant", mode = FetchMode.JOIN),
048 @FetchOverride(entity = PathwayImpl.class, association = "pathwayOrder", mode = FetchMode.JOIN),
049 @FetchOverride(entity = ControlImpl.class, association = "pathwayController", mode = FetchMode.JOIN),
050 @FetchOverride(entity = ControlImpl.class, association = "peController", mode = FetchMode.JOIN),
051 @FetchOverride(entity = L3ElementImpl.class, association = "comment", mode = FetchMode.JOIN),
052 @FetchOverride(entity = InteractionImpl.class, association = "interactionType", mode = FetchMode.JOIN),
053 @FetchOverride(entity = PathwayStepImpl.class, association = "nextStep", mode = FetchMode.JOIN),
054 @FetchOverride(entity = EntityImpl.class, association = "dataSource", mode = FetchMode.JOIN),
055 @FetchOverride(entity = BioSourceImpl.class, association = "cellType", mode = FetchMode.JOIN),
056 @FetchOverride(entity = EntityReferenceImpl.class, association = "entityFeature", mode = FetchMode.JOIN),
057 @FetchOverride(entity = EntityImpl.class, association = "evidence", mode = FetchMode.JOIN),
058 @FetchOverride(entity = EntityReferenceImpl.class, association = "evidence", mode = FetchMode.JOIN),
059 @FetchOverride(entity = PathwayStepImpl.class, association = "evidence", mode = FetchMode.JOIN),
060 @FetchOverride(entity = EntityFeatureImpl.class, association = "evidence", mode = FetchMode.JOIN),
061 @FetchOverride(entity = PathwayImpl.class, association = "pathwayComponent", mode = FetchMode.JOIN),
062 @FetchOverride(entity = EntityReferenceImpl.class, association = "entityReferenceType", mode = FetchMode.JOIN),
063 @FetchOverride(entity = PublicationXrefImpl.class, association = "author", mode = FetchMode.JOIN),
064 @FetchOverride(entity = NucleicAcidReferenceImpl.class, association = "subRegion", mode = FetchMode.JOIN),
065 @FetchOverride(entity = NamedImpl.class, association = "name", mode = FetchMode.JOIN),
066 @FetchOverride(entity = ConversionImpl.class, association = "left", mode = FetchMode.JOIN),
067 @FetchOverride(entity = BiochemicalReactionImpl.class, association = "KEQ", mode = FetchMode.JOIN),
068 @FetchOverride(entity = EntityImpl.class, association = "availability", mode = FetchMode.JOIN),
069 @FetchOverride(entity = BiochemicalReactionImpl.class, association = "deltaG", mode = FetchMode.JOIN),
070 @FetchOverride(entity = EvidenceImpl.class, association = "confidence", mode = FetchMode.JOIN),
071 @FetchOverride(entity = PhysicalEntityImpl.class, association = "notFeature", mode = FetchMode.JOIN),
072 @FetchOverride(entity = PhysicalEntityImpl.class, association = "memberPhysicalEntity", mode = FetchMode.JOIN),
073 @FetchOverride(entity = TemplateReactionImpl.class, association = "product", mode = FetchMode.JOIN),
074 @FetchOverride(entity = EvidenceImpl.class, association = "evidenceCode", mode = FetchMode.JOIN),
075 @FetchOverride(entity = PublicationXrefImpl.class, association = "source", mode = FetchMode.JOIN),
076 @FetchOverride(entity = BiochemicalReactionImpl.class, association = "deltaS", mode = FetchMode.JOIN),
077 @FetchOverride(entity = ControlledVocabularyImpl.class, association = "term", mode = FetchMode.JOIN),
078 @FetchOverride(entity = XReferrableImpl.class, association = "xref", mode = FetchMode.JOIN),
079 @FetchOverride(entity = BiochemicalReactionImpl.class, association = "deltaH", mode = FetchMode.JOIN)
080 }),
081@FetchProfile(name = "inverse_mul_properties_join", fetchOverrides = {
082 @FetchProfile.FetchOverride(entity = PhysicalEntityImpl.class, association = "memberPhysicalEntityOf", mode = FetchMode.JOIN),
083 @FetchProfile.FetchOverride(entity = PhysicalEntityImpl.class, association = "controllerOf", mode = FetchMode.JOIN),
084 @FetchProfile.FetchOverride(entity = PhysicalEntityImpl.class, association = "componentOf", mode = FetchMode.JOIN),
085 @FetchProfile.FetchOverride(entity = EntityImpl.class, association = "participantOf", mode = FetchMode.JOIN),
086 @FetchProfile.FetchOverride(entity = EntityReferenceImpl.class, association = "memberEntityReferenceOf", mode = FetchMode.JOIN),
087 @FetchProfile.FetchOverride(entity = EntityReferenceImpl.class, association = "entityReferenceOf", mode = FetchMode.JOIN),
088 @FetchProfile.FetchOverride(entity = ProcessImpl.class, association = "pathwayComponentOf", mode = FetchMode.JOIN),
089 @FetchProfile.FetchOverride(entity = ProcessImpl.class, association = "stepProcessOf", mode = FetchMode.JOIN),
090 @FetchProfile.FetchOverride(entity = ProcessImpl.class, association = "controlledOf", mode = FetchMode.JOIN),
091 @FetchProfile.FetchOverride(entity = PathwayImpl.class, association = "controllerOf", mode = FetchMode.JOIN)
092 })
093})
094public abstract class L3ElementImpl extends BioPAXElementImpl
095        implements Level3Element
096{
097    private Set<String> comment;
098    
099    private final Set<Pathway> pathways;
100    private final Set<Provenance> datasources;
101    private final Set<BioSource> organisms;
102    private final Set<String> keywords;
103
104    public L3ElementImpl()
105    {
106        this.comment = BPCollections.I.createSet();
107        this.pathways = BPCollections.I.createSet();
108        this.datasources = BPCollections.I.createSet();
109        this.organisms = BPCollections.I.createSet();
110        this.keywords =  BPCollections.I.createSet();
111    }
112
113    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
114    @ElementCollection
115    @JoinTable(name="comment")
116    @Field(name=FIELD_COMMENT, analyze=Analyze.YES, bridge=@FieldBridge(impl=SetStringBridge.class))
117        @Column(columnDefinition="LONGTEXT")
118    public Set<String> getComment()
119    {
120        return this.comment;
121    }
122
123    public void setComment(Set<String> comment)
124    {
125        this.comment = comment;
126    }
127
128    public void addComment(String COMMENT)
129    {
130        if(COMMENT != null && COMMENT.length() > 0)
131                this.comment.add(COMMENT);
132    }
133
134    public void removeComment(String COMMENT)
135    {
136        if(COMMENT != null)
137                this.comment.remove(COMMENT);
138    }
139
140        
141    /**
142     * A non-public transient method (not stored in the db table)
143         * to create the 'keyword' full-text index field by aggregating 
144         * biopax data field values from all child elements.
145         * 
146         * This method may be called once per biopax element
147         * by the Hibernate Search framework (indexer), if it is used, 
148         * or never called.
149     * 
150     * @return keywords, annotations associated with the biopax element
151     * @deprecated use getAnnotations() instead
152     */
153    @Deprecated
154        @Transient
155        @Field(name=FIELD_KEYWORD, store=Store.YES, analyze=Analyze.YES)
156        @FieldBridge(impl=SetStringBridge.class)
157        public Set<String> getKeywords() {
158                return this.keywords;
159        }
160        
161    /**
162     * A transient method (not stored in the db table)
163         * to create the 'organism' full-text index field 
164         * used then both for searching and filtering (important).
165         * 
166         * This method may be called once per biopax element
167         * by the Hibernate Search framework (indexer),
168         * or never called.
169     * 
170     * @return organisms (if any set/inferred explicitly by some external app.)
171     * @deprecated use getAnnotations() instead
172     */
173    @Deprecated
174        @Transient
175        @Field(name=FIELD_ORGANISM, store=Store.YES, analyze=Analyze.NO)
176        @FieldBridge(impl=OrganismFieldBridge.class)
177        public Set<BioSource> getOrganisms() {
178                return this.organisms;
179        }
180        
181    /**
182     * A transient method (not stored in the db table)
183         * to create the 'datasource' full-text index field 
184         * used then both for searching and filtering (important).
185         * 
186         * This method may be called once per biopax element
187         * by the Hibernate Search framework (indexer), if used, 
188         * or never called otherwise.
189         *   
190     * @return data sources (if set/inferred by some external app.)
191     * @deprecated use getAnnotations() instead
192     */
193    @Deprecated
194        @Transient
195        @Field(name=FIELD_DATASOURCE, store=Store.YES, analyze=Analyze.NO)
196        @FieldBridge(impl=DataSourceFieldBridge.class)
197        public Set<Provenance> getDatasources() {
198                return this.datasources;
199        }
200
201        
202    /**
203     * An transient method (not stored in the db table),
204     * not trivial one, to create the 'pathway' full-text index field
205         * used then both for searching and especially annotating search
206         * hits. 
207         * 
208         * Parent pathways can be inferred and updated once the BioPAX model
209         * is built and complete.
210         * 
211         * This method may be called once per biopax element
212         * by the Hibernate Search framework (indexer), 
213         * or never called.
214         *   
215     * @return parent pathways (if explicitly inferred and set by some external tool)
216     * @deprecated use getAnnotations() instead
217     */
218    @Deprecated
219        @Transient
220        @Field(name=FIELD_PATHWAY, store=Store.YES, analyze=Analyze.NO)
221        //this bridge simply adds pathways URIs and names to the 'pathway' index field.
222        @FieldBridge(impl=ParentPathwayFieldBridge.class)
223        public Set<Pathway> getParentPathways() {
224                return this.pathways;
225        }
226        
227}