001package org.biopax.paxtools.impl.level3; 002 003import org.biopax.paxtools.model.level3.*; 004import org.biopax.paxtools.model.level3.Process; 005import org.biopax.paxtools.util.BPCollections; 006import org.biopax.paxtools.util.IllegalBioPAXArgumentException; 007import org.hibernate.annotations.Cache; 008import org.hibernate.annotations.*; 009import org.hibernate.search.annotations.Indexed; 010 011import javax.persistence.Entity; 012import javax.persistence.*; 013import java.util.Collections; 014import java.util.HashSet; 015import java.util.Set; 016 017@Entity 018@Proxy(proxyClass= Control.class) 019@Indexed 020@DynamicUpdate @DynamicInsert 021@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) 022public class ControlImpl extends InteractionImpl 023 implements Control 024{ 025// ------------------------------ FIELDS ------------------------------ 026 027 private ControlType controlType; 028 private Set<Pathway> pathwayController; 029 private Set<PhysicalEntity> peController; 030 private Set<Process> controlled; 031 032// --------------------------- CONSTRUCTORS --------------------------- 033 034 public ControlImpl() 035 { 036 pathwayController = BPCollections.I.createSafeSet(); 037 peController = BPCollections.I.createSafeSet(); 038 controlled = BPCollections.I.createSafeSet(); 039 } 040 041// ------------------------ INTERFACE METHODS ------------------------ 042 043 @Transient 044 public Class<? extends Control> getModelInterface() 045 { 046 return Control.class; 047 } 048 049// --------------------- Interface Control --------------------- 050 051// --------------------- ACCESORS and MUTATORS--------------------- 052 053 @Enumerated 054 public ControlType getControlType() 055 { 056 return controlType; 057 } 058 059 public void setControlType(ControlType ControlType) 060 { 061 this.controlType = ControlType; 062 } 063 064 @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) 065 @ManyToMany(targetEntity = ProcessImpl.class) 066 @JoinTable(name="controlled") 067 public Set<Process> getControlled() 068 { 069 return this.controlled; 070 } 071 072 protected void setControlled(Set<Process> controlled) 073 { 074 this.controlled = controlled; 075 } 076 077 public void addControlled(Process controlled) 078 { 079 if (controlled != null) { 080 if (!checkControlled(controlled)) { 081 throw new IllegalBioPAXArgumentException( 082 "Illegal argument. Attempting to set " 083 + controlled.getRDFId() + " to " 084 + this.getRDFId()); 085 086 } 087 if (controlled != null) { 088 this.controlled.add(controlled); 089 controlled.getControlledOf().add(this); 090 super.addParticipant(controlled); 091 } 092 } 093 } 094 095 public void removeControlled(Process controlled) 096 { 097 if(controlled != null) { 098 super.removeParticipant(controlled); 099 controlled.getControlledOf().remove(this); 100 this.controlled.remove(controlled); 101 } 102 } 103 104 @Transient 105 public Set<Controller> getController() 106 { 107 Set<Controller> controller = new HashSet<Controller>(this.getPeController()); 108 controller.addAll(getPathwayController()); 109 return Collections.unmodifiableSet(controller); 110 } 111 112 public void addController(Controller controller) 113 { 114 if (controller != null) { 115 if (controller instanceof Pathway) { 116 pathwayController.add((Pathway) controller); 117 } else { 118 peController.add((PhysicalEntity) controller); 119 } 120 controller.getControllerOf().add(this); 121 super.addParticipant(controller); 122 } 123 } 124 125 public void removeController(Controller controller) 126 { 127 if (controller != null) { 128 super.removeParticipant(controller); 129 controller.getControllerOf().remove(this); 130 if (controller instanceof Pathway) { 131 pathwayController.remove(controller); 132 } else { 133 peController.remove(controller); 134 } 135 } 136 } 137 138 139 // -------------------------- OTHER METHODS -------------------------- 140 protected boolean checkControlled(Process Controlled) 141 { 142 return true; 143 } 144 145 146 @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) 147 @ManyToMany(targetEntity = PathwayImpl.class)//, cascade={CascadeType.ALL}) 148 @JoinTable(name="pathwayController") 149 protected Set<Pathway> getPathwayController() 150 { 151 return pathwayController; 152 } 153 154 protected void setPathwayController(Set<Pathway> pathwayController) 155 { 156 this.pathwayController = pathwayController; 157 } 158 159 @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) 160 @ManyToMany(targetEntity = PhysicalEntityImpl.class) 161 @JoinTable(name="peController") 162 protected Set<PhysicalEntity> getPeController() 163 { 164 return peController; 165 } 166 167 protected void setPeController(Set<PhysicalEntity> peController) 168 { 169 this.peController = peController; 170 } 171 172}