001package org.biopax.paxtools.impl.level3;
002
003import org.biopax.paxtools.model.level3.XReferrable;
004import org.biopax.paxtools.model.level3.Xref;
005import org.biopax.paxtools.util.BPCollections;
006import org.biopax.paxtools.util.XrefFieldBridge;
007import org.hibernate.annotations.*;
008import org.hibernate.search.annotations.Analyze;
009import org.hibernate.search.annotations.Boost;
010import org.hibernate.search.annotations.Field;
011import org.hibernate.search.annotations.FieldBridge;
012
013import javax.persistence.Entity;
014import javax.persistence.JoinTable;
015import javax.persistence.ManyToMany;
016import java.util.Set;
017
018/**
019 * This class helps with managing the bidirectional xref links.
020 *
021 * @author Emek Demir
022 */
023@Entity
024@Proxy(proxyClass= XReferrable.class)
025@DynamicUpdate @DynamicInsert
026@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
027public abstract class XReferrableImpl extends L3ElementImpl implements XReferrable
028{
029// ------------------------------ FIELDS ------------------------------
030
031        /**
032         * This variable stores the external references to the owner object.
033         */
034        private Set<Xref> xref;
035
036// --------------------------- CONSTRUCTORS ---------------------------
037
038        /**
039         * Default constructor.
040         */
041
042        public XReferrableImpl()
043        {
044                this.xref = BPCollections.I.createSafeSet();
045        }
046
047// -------------------------- OTHER METHODS --------------------------
048
049        
050        @Field(name=FIELD_XREFID, analyze=Analyze.NO, bridge = @FieldBridge(impl=XrefFieldBridge.class), boost=@Boost(1.5f))
051        @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
052        @ManyToMany(targetEntity = XrefImpl.class)
053        @JoinTable(name="xref")
054        public Set<Xref> getXref()
055        {
056                return xref;
057        }
058
059        public void removeXref(Xref xref)
060        {
061                if (xref != null) {
062                        this.xref.remove(xref);
063                        synchronized (xref) {
064                                xref.getXrefOf().remove(this);
065                        }
066                }
067        }
068
069        protected void setXref(Set<Xref> xref)
070        {
071                this.xref = xref;
072        }
073
074        public void addXref(Xref xref)
075        {
076                if (xref != null) {
077                        this.xref.add(xref);
078                        synchronized (xref) {
079                                xref.getXrefOf().add(this);
080                        }
081                }
082        }
083
084
085        @Override
086        public int equivalenceCode()
087        {
088                return 1;
089        }
090
091}