better mapping of paccomponent

This commit is contained in:
Peter Hormanns 2013-05-02 16:59:13 +02:00
parent 85be33e6a1
commit 3b61da9c17
4 changed files with 29 additions and 53 deletions

View File

@ -10,7 +10,6 @@ import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
@ -97,9 +96,11 @@ public class Pac extends AbstractEntity implements Serializable {
pacComponents = new HashSet<PacComponent>();
Date today = new Date();
for (Component comp : basepac.getComponents()) {
PacComponent pacComp = new PacComponent(basepac,
comp.getBaseComponent(), this, comp.getDefaultQuantity(),
today, null);
PacComponent pacComp = new PacComponent();
pacComp.setCreated(today);
pacComp.setComponent(comp);
pacComp.setPac(this);
pacComp.setQuantity(comp.getDefaultQuantity());
pacComponents.add(pacComp);
}
}

View File

@ -8,6 +8,7 @@ import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
@ -27,13 +28,11 @@ public class PacComponent implements Serializable {
@Id
@ManyToOne
@JoinColumn(name = "basecomponent_id")
private BaseComponent baseComponent;
@Id
@ManyToOne
@JoinColumns({
@JoinColumn(name = "basecomponent_id"),
@JoinColumn(name = "basepacket_id")
private BasePac basePac;
})
private Component component;
@Column(name = "quantity", columnDefinition = "integer")
private int quantity;
@ -46,33 +45,12 @@ public class PacComponent implements Serializable {
@Temporal(TemporalType.DATE)
private Date cancelled;
public PacComponent() {
}
public PacComponent(BasePac basePac, BaseComponent baseComp, Pac pac,
int quantity, Date created, Date cancelled) {
this.basePac = basePac;
this.pac = pac;
this.baseComponent = baseComp;
this.quantity = quantity;
this.created = created;
this.cancelled = cancelled;
}
public BasePac getBasePac() {
return basePac;
}
public void setbasePac(BasePac basePac) {
this.basePac = basePac;
return getComponent().getBasePac();
}
public BaseComponent getBaseComponent() {
return baseComponent;
}
public void setBaseComponent(BaseComponent baseComponent) {
this.baseComponent = baseComponent;
return getComponent().getBaseComponent();
}
public Pac getPac() {
@ -107,4 +85,12 @@ public class PacComponent implements Serializable {
this.cancelled = cancelled;
}
public Component getComponent() {
return component;
}
public void setComponent(Component component) {
this.component = component;
}
}

View File

@ -3,27 +3,25 @@ package de.hsadmin.mods.pac;
import java.io.Serializable;
public class PacComponentId implements Serializable {
private static final long serialVersionUID = 1L;
private long pac;
private long basePac;
private long baseComponent;
private ComponentId component;
@Override
public boolean equals(Object obj) {
if (obj != null && obj instanceof PacComponentId) {
PacComponentId other = (PacComponentId) obj;
return getPac() == other.getPac() && getBaseComponent() == other.getBaseComponent() && getBasePac() == other.getBasePac();
return getPac() == other.getPac() && getComponent().equals(other.getComponent());
}
return false;
}
@Override
public int hashCode() {
return (new Long(getPac() ^ getBaseComponent() ^ getBasePac() % Integer.MAX_VALUE)).intValue();
return (new Long(getPac() ^ component.hashCode() % Integer.MAX_VALUE)).intValue();
}
public void setPac(long pacId) {
@ -34,20 +32,12 @@ public class PacComponentId implements Serializable {
return pac;
}
public void setBaseComponent(long baseComponentId) {
this.baseComponent = baseComponentId;
public ComponentId getComponent() {
return component;
}
public long getBaseComponent() {
return baseComponent;
}
public void setBasePac(long basePacId) {
this.basePac = basePacId;
}
public long getBasePac() {
return basePac;
public void setComponent(ComponentId component) {
this.component = component;
}
}

View File

@ -79,8 +79,7 @@ public class PacModuleImpl extends AbstractModuleImpl {
Component comp = (Component) cObj;
PacComponent pacComponent = new PacComponent();
BaseComponent baseComponent = comp.getBaseComponent();
pacComponent.setBaseComponent(baseComponent);
pacComponent.setbasePac(comp.getBasePac());
pacComponent.setComponent(comp);
pacComponent.setCreated(now);
pacComponent.setPac(pac);
String feature = baseComponent.getFeature();