From 3b61da9c17f4b403b455fd6ccdc35910ec14bb98 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Thu, 2 May 2013 16:59:13 +0200 Subject: [PATCH] better mapping of paccomponent --- hsarback/src/de/hsadmin/mods/pac/Pac.java | 9 ++-- .../src/de/hsadmin/mods/pac/PacComponent.java | 46 +++++++------------ .../de/hsadmin/mods/pac/PacComponentId.java | 24 +++------- .../de/hsadmin/mods/pac/PacModuleImpl.java | 3 +- 4 files changed, 29 insertions(+), 53 deletions(-) diff --git a/hsarback/src/de/hsadmin/mods/pac/Pac.java b/hsarback/src/de/hsadmin/mods/pac/Pac.java index db1f988..c4eedb3 100644 --- a/hsarback/src/de/hsadmin/mods/pac/Pac.java +++ b/hsarback/src/de/hsadmin/mods/pac/Pac.java @@ -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(); 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); } } diff --git a/hsarback/src/de/hsadmin/mods/pac/PacComponent.java b/hsarback/src/de/hsadmin/mods/pac/PacComponent.java index a33bb32..02d60f7 100644 --- a/hsarback/src/de/hsadmin/mods/pac/PacComponent.java +++ b/hsarback/src/de/hsadmin/mods/pac/PacComponent.java @@ -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 - @JoinColumn(name = "basepacket_id") - private BasePac basePac; + @JoinColumns({ + @JoinColumn(name = "basecomponent_id"), + @JoinColumn(name = "basepacket_id") + }) + 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; + } + } diff --git a/hsarback/src/de/hsadmin/mods/pac/PacComponentId.java b/hsarback/src/de/hsadmin/mods/pac/PacComponentId.java index b98dd0d..832e31f 100644 --- a/hsarback/src/de/hsadmin/mods/pac/PacComponentId.java +++ b/hsarback/src/de/hsadmin/mods/pac/PacComponentId.java @@ -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; } } diff --git a/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java b/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java index 6b472b2..ef377cd 100644 --- a/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java @@ -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();