Kann Pakete in HSDB anlegen

This commit is contained in:
Peter Hormanns 2011-03-23 12:12:13 +00:00
parent 6abee84d81
commit 39c0c3b8c2
3 changed files with 24 additions and 6 deletions

View File

@ -39,7 +39,7 @@ public class Pac extends AbstractEntity implements Serializable {
@Id
@GeneratedValue(strategy = SEQUENCE, generator = "PacsSeqGen")
@Column(name = "packet_id")
@Column(name = "packet_id", columnDefinition = "integer")
private long id;
@Column(name = "packet_name", unique = true)

View File

@ -58,8 +58,17 @@ public class PacComponent {
public PacComponent(BasePac basePac, BaseComponent baseComp, Pac pac,
int quantity, Date created, Date cancelled) {
this.basePac = basePac;
if (basePac != null) {
this.basePacId = basePac.id();
}
this.pac = pac;
if (pac != null) {
this.pacId = pac.id();
}
this.baseComponent = baseComp;
if (baseComponent != null) {
this.baseComponentId = baseComp.id();
}
this.quantity = quantity;
this.created = created;
this.cancelled = cancelled;
@ -71,6 +80,9 @@ public class PacComponent {
public void setbasePac(BasePac basePac) {
this.basePac = basePac;
if (basePac != null) {
this.basePacId = basePac.id();
}
}
public BaseComponent getBaseComponent() {
@ -79,6 +91,9 @@ public class PacComponent {
public void setBaseComponent(BaseComponent baseComponent) {
this.baseComponent = baseComponent;
if (baseComponent != null) {
this.baseComponentId = baseComponent.id();
}
}
public Pac getPac() {
@ -87,6 +102,9 @@ public class PacComponent {
public void setPac(Pac pac) {
this.pac = pac;
if (pac != null) {
this.pacId = pac.id();
}
}
public int getQuantity() {

View File

@ -26,9 +26,10 @@ public class PacModuleImpl extends AbstractModuleImpl {
@Override
public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException {
Date now = new Date();
EntityManager em = getTransaction().getEntityManager();
Pac pac = (Pac) newEntity;
Date now = new Date();
pac.setCreated(now);
BasePac basepac = pac.getBasepac();
if (basepac == null || basepac.getName() == null || basepac.getName().length() == 0) {
throw new HSAdminException("basepac required");
@ -38,8 +39,6 @@ public class PacModuleImpl extends AbstractModuleImpl {
qBasepac.setParameter("valid", Boolean.TRUE);
basepac = (BasePac) qBasepac.getSingleResult();
pac.setBasepac(basepac);
Query qComponents = em.createQuery("SELECT c FROM Components c WHERE c.basePacId = :basepac");
qComponents.setParameter("basepac", basepac.id());
INetAddress curINetAddr = pac.getCurINetAddr();
if (curINetAddr == null || curINetAddr.getInetAddr() == null || curINetAddr.getInetAddr().length() == 0) {
throw new HSAdminException("curinetaddr required");
@ -63,7 +62,8 @@ public class PacModuleImpl extends AbstractModuleImpl {
qHive.setParameter("name", hive.getName());
hive = (Hive) qHive.getSingleResult();
pac.setHive(hive);
// em.persist(newEntity);
Query qComponents = em.createQuery("SELECT c FROM Components c WHERE c.basePacId = :basepac");
qComponents.setParameter("basepac", basepac.id());
List<?> componentsList = qComponents.getResultList();
Set<PacComponent> pacComponents = new HashSet<PacComponent>();
for (Object cObj : componentsList) {
@ -74,7 +74,7 @@ public class PacModuleImpl extends AbstractModuleImpl {
pacComponent.setCreated(now);
pacComponent.setPac(pac);
pacComponent.setQuantity(comp.getDefaultQuantity());
// em.persist(pacComponent);
pacComponents.add(pacComponent);
}
pac.setPacComponents(pacComponents);
return super.add(newEntity);