00001 package cedar.hepdata.model;
00002
00003 import java.util.Set;
00004 import java.util.HashSet;
00005
00006 import javax.persistence.*;
00007
00014 @Entity
00015 @Table(name="ReactionGroups")
00016 public class ReactionGroup extends Storeable {
00018 @Id @GeneratedValue
00019 @Column(name="REACTIONGROUP_ID")
00020 private Long _id;
00021
00023 @Column(name="Name", nullable=false, unique=true)
00024 private String _name;
00025
00027 @Column(name="Comment", nullable=false, length=10000)
00028 private String _comment = "";
00029
00031 @ManyToMany
00032 @JoinTable(name="ReactionGroupMembers",
00033 joinColumns=@JoinColumn(name="REACTIONGROUP_ID"),
00034 inverseJoinColumns=@JoinColumn(name="REACTION_ID"))
00035 private Set<Reaction> _reactions = new HashSet<Reaction>();
00036
00037
00039
00040
00042 public ReactionGroup() {}
00043
00045 public ReactionGroup(String name) {
00046 setName(name);
00047 }
00048
00049
00051
00052
00054 public String getName() {
00055 return _name;
00056 }
00058 public ReactionGroup setName(String name) {
00059 _name = name;
00060 return this;
00061 }
00062
00063
00065 public String getComment() {
00066 return _comment;
00067 }
00069 public ReactionGroup setComment(String comment) {
00070 _comment = comment;
00071 return this;
00072 }
00073
00074
00075
00076 public Set<Reaction> getReactions() {
00077 return _reactions;
00078 }
00079 public ReactionGroup setReactions(Set<Reaction> reactions) {
00080 for (Reaction r : getReactions()) removeReaction(r);
00081 for (Reaction r : reactions) addReaction(r);
00082 return this;
00083 }
00084 public ReactionGroup addReaction(Reaction reaction) {
00085 if (reaction != null) {
00086 reaction.getReactionGroups().add(this);
00087 getReactions().add(reaction);
00088 } else {
00089 log().warn("Tried to add a null reaction to a reaction group");
00090 }
00091 return this;
00092 }
00093 public ReactionGroup removeReaction(Reaction reaction) {
00094 if (reaction != null) {
00095 reaction.getReactionGroups().remove(this);
00096 getReactions().remove(reaction);
00097 } else {
00098 log().warn("Tried to remove a null reaction from a reaction group");
00099 }
00100 return this;
00101 }
00102
00103
00105
00106
00107
00108
00109 }