001package org.biopax.paxtools.impl.level3;
002
003import org.biopax.paxtools.model.level3.NucleicAcid;
004import org.biopax.paxtools.model.level3.PhysicalEntity;
005import org.biopax.paxtools.model.level3.TemplateDirectionType;
006import org.biopax.paxtools.model.level3.TemplateReaction;
007import org.biopax.paxtools.util.BPCollections;
008import org.hibernate.annotations.Cache;
009import org.hibernate.annotations.*;
010import org.hibernate.search.annotations.Indexed;
011
012import javax.persistence.*;
013import java.util.Set;
014
015@javax.persistence.Entity
016@Proxy(proxyClass= TemplateReaction.class)
017@Indexed
018@DynamicUpdate @DynamicInsert
019@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
020public class TemplateReactionImpl extends InteractionImpl implements TemplateReaction {
021    private Set<PhysicalEntity> product;
022    private NucleicAcid template;
023        private TemplateDirectionType templateDirection;
024
025        public TemplateReactionImpl()
026        {
027        this.product = BPCollections.I.createSafeSet();
028    }
029        
030        @Transient
031    public Class<? extends TemplateReaction> getModelInterface()
032        {
033                return TemplateReaction.class;
034        }
035
036    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
037    @ManyToMany(targetEntity = PhysicalEntityImpl.class) //TODO: make sequence entity?
038    @JoinTable(name="product")  
039    public Set<PhysicalEntity> getProduct()
040    {
041        return product;
042    }
043
044    protected void setProduct(Set<PhysicalEntity> product)
045    {
046        this.product = product;
047    }
048
049    public void addProduct(PhysicalEntity product)
050    {
051        if(product != null) {
052                this.product.add(product);
053                super.addParticipant(product);
054        }
055    }
056
057    public void removeProduct(PhysicalEntity product)
058    {
059        if(product != null) {
060                super.removeParticipant(product);
061                this.product.remove(product);
062        }
063    }
064
065        @ManyToOne(targetEntity = NucleicAcidImpl.class)//, cascade = { CascadeType.ALL })
066        protected NucleicAcid getTemplateX() {
067                return this.template;
068        }
069        protected void setTemplateX(NucleicAcid template) {
070                this.template = template;
071        }
072    
073    @Transient
074        public NucleicAcid getTemplate()
075     {
076         return this.template;
077     }
078
079    public void setTemplate(NucleicAcid template)
080    {
081         if(this.template!= null)
082         {
083            super.removeParticipant(this.template);
084         }
085         if(template != null) {
086                 this.template=template;
087                 super.addParticipant(template);
088         }
089    }
090
091    @Enumerated
092        public TemplateDirectionType getTemplateDirection()
093        {
094                return templateDirection;
095        }
096
097        public void setTemplateDirection(TemplateDirectionType templateDirection)
098        {
099                this.templateDirection = templateDirection;
100        }
101
102}