hs.hsadmin/hsarback/src/de/hsadmin/mods/pac/BasePac.java

142 lines
3.4 KiB
Java

package de.hsadmin.mods.pac;
import static javax.persistence.CascadeType.ALL;
import static javax.persistence.FetchType.LAZY;
import static javax.persistence.GenerationType.SEQUENCE;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
@javax.persistence.Entity(name = "BasePacs")
@javax.persistence.Table(name = "basepacket")
@javax.persistence.SequenceGenerator(name = "BasePacsSeqGen", sequenceName = "basepacket_basepacket_id_seq")
public class BasePac implements Serializable {
private static final long serialVersionUID = 1491121619195513435L;
public BasePac() {
}
public BasePac(String name, String desc, int sortPos) {
this.name = name;
this.description = desc;
this.sorting = sortPos;
this.valid = true;
}
@javax.persistence.Id
@javax.persistence.GeneratedValue(strategy = SEQUENCE, generator = "BasePacsSeqGen")
@javax.persistence.Column(name = "basepacket_id", columnDefinition = "integer")
private long id;
@javax.persistence.Column(name = "basepacket_code", columnDefinition = "character varying(10)")
private String name;
@javax.persistence.Column(name = "description", columnDefinition = "character varying(100)")
private String description;
@javax.persistence.Column(name = "sorting", columnDefinition = "integer")
private int sorting;
@javax.persistence.Column(name = "valid", columnDefinition = "boolean")
private boolean valid;
@javax.persistence.OneToMany(fetch = LAZY, cascade = ALL)
private Set<Component> components;
@javax.persistence.OneToMany(fetch = LAZY, cascade = ALL)
@javax.persistence.JoinTable(name = "packet_component", joinColumns = @javax.persistence.JoinColumn(name = "packet_id"), inverseJoinColumns = @javax.persistence.JoinColumn(name = "basepacket_id"))
private Set<Pac> pacs;
public long getId() {
return id;
}
public void setId(long id) {
this.id = 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 (id != aOtherBP.id)
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;
}
}