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

View File

@ -8,6 +8,7 @@ import javax.persistence.Entity;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.IdClass; import javax.persistence.IdClass;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
@ -27,13 +28,11 @@ public class PacComponent implements Serializable {
@Id @Id
@ManyToOne @ManyToOne
@JoinColumn(name = "basecomponent_id") @JoinColumns({
private BaseComponent baseComponent; @JoinColumn(name = "basecomponent_id"),
@JoinColumn(name = "basepacket_id")
@Id })
@ManyToOne private Component component;
@JoinColumn(name = "basepacket_id")
private BasePac basePac;
@Column(name = "quantity", columnDefinition = "integer") @Column(name = "quantity", columnDefinition = "integer")
private int quantity; private int quantity;
@ -46,33 +45,12 @@ public class PacComponent implements Serializable {
@Temporal(TemporalType.DATE) @Temporal(TemporalType.DATE)
private Date cancelled; 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() { public BasePac getBasePac() {
return basePac; return getComponent().getBasePac();
}
public void setbasePac(BasePac basePac) {
this.basePac = basePac;
} }
public BaseComponent getBaseComponent() { public BaseComponent getBaseComponent() {
return baseComponent; return getComponent().getBaseComponent();
}
public void setBaseComponent(BaseComponent baseComponent) {
this.baseComponent = baseComponent;
} }
public Pac getPac() { public Pac getPac() {
@ -107,4 +85,12 @@ public class PacComponent implements Serializable {
this.cancelled = cancelled; 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; import java.io.Serializable;
public class PacComponentId implements Serializable { public class PacComponentId implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private long pac; private long pac;
private long basePac; private ComponentId component;
private long baseComponent;
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj != null && obj instanceof PacComponentId) { if (obj != null && obj instanceof PacComponentId) {
PacComponentId other = (PacComponentId) obj; PacComponentId other = (PacComponentId) obj;
return getPac() == other.getPac() && getBaseComponent() == other.getBaseComponent() && getBasePac() == other.getBasePac(); return getPac() == other.getPac() && getComponent().equals(other.getComponent());
} }
return false; return false;
} }
@Override @Override
public int hashCode() { 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) { public void setPac(long pacId) {
@ -34,20 +32,12 @@ public class PacComponentId implements Serializable {
return pac; return pac;
} }
public void setBaseComponent(long baseComponentId) { public ComponentId getComponent() {
this.baseComponent = baseComponentId; return component;
} }
public long getBaseComponent() { public void setComponent(ComponentId component) {
return baseComponent; this.component = component;
}
public void setBasePac(long basePacId) {
this.basePac = basePacId;
}
public long getBasePac() {
return basePac;
} }
} }

View File

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