hs.hsadmin/hsarback/src/de/hsadmin/mods/pac/BasePac.java
2013-04-25 12:08:39 +02:00

167 lines
4.0 KiB
Java

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.JoinColumn;
import javax.persistence.JoinTable;
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<Component>();
}
@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)
@JoinTable(name = "component", joinColumns = @JoinColumn(name = "basepacket_id"), inverseJoinColumns = @JoinColumn(name = "basecomponent_id"))
private Set<Component> components;
@OneToMany(fetch = FetchType.LAZY, cascade = ALL)
@JoinTable(name = "packet_component", joinColumns = @JoinColumn(name = "packet_id"), inverseJoinColumns = @JoinColumn(name = "basepacket_id"))
private Set<Pac> pacs;
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<Component> getComponents() {
return components != null ? components
: (components = new HashSet<Component>());
}
public void setComponents(Set<Component> 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);
}
public Set<Pac> getPacs() {
return pacs;
}
public void setPacs(Set<Pac> pacs) {
this.pacs = pacs;
}
// 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() + "\"";
}
}