package de.hsadmin.mods.pac; import static javax.persistence.CascadeType.ALL; import static javax.persistence.GenerationType.SEQUENCE; import java.io.Serializable; import java.util.HashSet; import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.SequenceGenerator; import javax.persistence.Table; @Entity(name = "BasePacs") @Table(name = "basepacket") @SequenceGenerator(name = "BasePacsSeqGen", sequenceName = "basepacket_basepacket_id_seq") public class BasePac implements Serializable { private static final long serialVersionUID = 1491121619195513435L; public BasePac() { components = new HashSet(); } @Id @GeneratedValue(strategy = SEQUENCE, generator = "BasePacsSeqGen") @Column(name = "basepacket_id", columnDefinition = "integer") private long basePacId; @Column(name = "basepacket_code", columnDefinition = "character varying(10)") private String name; @Column(name = "description", columnDefinition = "character varying(100)") private String description; @Column(name = "article_number", columnDefinition = "integer", nullable=false) private int articleNumber; @Column(name = "sorting", columnDefinition = "integer") private int sorting; @Column(name = "valid", columnDefinition = "boolean") private boolean valid; @OneToMany(fetch = FetchType.LAZY, cascade=ALL, mappedBy="basePac") private Set components; public long id() { return basePacId; } public long getBasePacId() { return basePacId; } public void setBasePacId(long id) { this.basePacId = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public int getSorting() { return sorting; } public void setSorting(int sorting) { this.sorting = sorting; } public boolean isValid() { return valid; } public void setValid(boolean valid) { this.valid = valid; } public Set getComponents() { return components != null ? components : (components = new HashSet()); } public void setComponents(Set components) { this.components = components; } public Component getComponent(String feature) { for (Component comp : getComponents()) if (feature.equals(comp.getBaseComponent().getFeature())) return comp; return null; } public void addComponent(Component comp) { getComponents().add(comp); } public void removeComponent(Component comp) { getComponents().remove(comp); } // generic public boolean equals(Object aOther) { if (aOther == null || aOther.getClass() != getClass()) return false; BasePac aOtherBP = (BasePac) aOther; if (basePacId != aOtherBP.basePacId) return false; if (name != null && !name.equals(aOtherBP.name)) return false; if (description != null && description.equals(aOtherBP.description)) return false; if (sorting != aOtherBP.sorting) return false; if (valid != aOtherBP.valid) return false; return true; } public int getArticleNumber() { return articleNumber; } public void setArticleNumber(int articleNumber) { this.articleNumber = articleNumber; } @Override public String toString() { return "BasePac \"" + getName() + "\""; } }