fix or-mapping of pac-components

This commit is contained in:
Peter Hormanns 2013-01-21 13:38:31 +01:00
parent 75a68d707a
commit 5056e46610
3 changed files with 23 additions and 5 deletions

View File

@ -53,6 +53,7 @@ public class BasePac implements Serializable {
private boolean valid; private boolean valid;
@OneToMany(fetch = FetchType.LAZY, cascade = ALL) @OneToMany(fetch = FetchType.LAZY, cascade = ALL)
@JoinTable(name = "component", joinColumns = @JoinColumn(name = "basepacket_id"), inverseJoinColumns = @JoinColumn(name = "basecomponent_id"))
private Set<Component> components; private Set<Component> components;
@OneToMany(fetch = FetchType.LAZY, cascade = ALL) @OneToMany(fetch = FetchType.LAZY, cascade = ALL)

View File

@ -8,6 +8,7 @@ import static javax.persistence.GenerationType.SEQUENCE;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
import javax.persistence.Column; import javax.persistence.Column;
@ -18,6 +19,7 @@ import javax.persistence.Id;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Query;
import javax.persistence.SequenceGenerator; import javax.persistence.SequenceGenerator;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
@ -98,7 +100,10 @@ public class Pac extends AbstractEntity implements Serializable {
this.created = new Date(); this.created = new Date();
this.webserverGroup = "httpd"; this.webserverGroup = "httpd";
this.curINetAddr = hive.getInetAddr(); this.curINetAddr = hive.getInetAddr();
initPacComponents(basePac);
}
private void initPacComponents(BasePac basePac) {
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()) {
@ -109,6 +114,16 @@ public class Pac extends AbstractEntity implements Serializable {
} }
} }
@Override
public void initialize(EntityManager em, UnixUser loginUser) {
super.initialize(em, loginUser);
Query qBasepac = em.createQuery("SELECT b FROM BasePacs b WHERE b.valid = :valid ORDER BY b.name");
qBasepac.setParameter("valid", Boolean.TRUE);
List<?> resultList = qBasepac.getResultList();
basepac = (BasePac) resultList.get(0);
initPacComponents(basepac);
}
public static String createQueryFromStringKey(String humanKey) { public static String createQueryFromStringKey(String humanKey) {
return "obj.name='" + humanKey + "'"; return "obj.name='" + humanKey + "'";
} }
@ -226,9 +241,13 @@ public class Pac extends AbstractEntity implements Serializable {
} }
public PacComponent getPacComponent(String feature) { public PacComponent getPacComponent(String feature) {
for (PacComponent pc : getPacComponents()) if (pacComponents != null) {
if (feature.equals(pc.getBaseComponent().getFeature())) for (PacComponent pc : pacComponents) {
return pc; if (feature.equals(pc.getBaseComponent().getFeature())) {
return pc;
}
}
}
return null; return null;
} }

View File

@ -115,8 +115,6 @@ public class PacModuleImpl extends AbstractModuleImpl {
UnixUser loginUser = getTransaction().getLoginUser(); UnixUser loginUser = getTransaction().getLoginUser();
if (!(entity instanceof Pac)) { if (!(entity instanceof Pac)) {
throw new AuthorisationException(loginUser, "update", entity); throw new AuthorisationException(loginUser, "update", entity);
// } else {
// Pac pac = (Pac) entity;
} }
needsWriteAccessOn(entity, "update"); needsWriteAccessOn(entity, "update");
return super.update(entity); return super.update(entity);