From: <pka...@us...> - 2009-07-24 11:53:51
|
Revision: 363 http://cse-ip.svn.sourceforge.net/cse-ip/?rev=363&view=rev Author: pkasprzak Date: 2009-07-24 11:53:42 +0000 (Fri, 24 Jul 2009) Log Message: ----------- * Added EntityManager.updateAttributes() for attribute checks on entities (+ some tests) * Fixed Attribute -> Entity cascades Modified Paths: -------------- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManager.java trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManagerImpl.java trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManagerWS.java trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/Attribute.java Modified: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManager.java =================================================================== --- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManager.java 2009-07-23 21:27:47 UTC (rev 362) +++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManager.java 2009-07-24 11:53:42 UTC (rev 363) @@ -5,6 +5,7 @@ package de.campussource.cse.core; +import de.campussource.cse.core.pdm.Entity; import javax.ejb.Local; /** @@ -14,18 +15,19 @@ @Local public interface EntityManager { - public int exists(String system, String systemId); + public int exists(String system, String systemId); - public int createAccount(de.campussource.cse.core.cdm.AccountType account); + public int createAccount(de.campussource.cse.core.cdm.AccountType account); - public int createCourse(de.campussource.cse.core.cdm.CourseType course); + public int createCourse(de.campussource.cse.core.cdm.CourseType course); - public int createCategory(de.campussource.cse.core.cdm.CategoryType category); + public int createCategory(de.campussource.cse.core.cdm.CategoryType category); - public int createProxy(String type); + public int createProxy(String type); - public void deleteEntity(int cseId); + public boolean updateAttributes(de.campussource.cse.core.cdm.EntityType entity); - public int test(de.campussource.cse.core.cdm.EntityType entity); + public void deleteEntity(int cseId); + public Entity getEntity(int cseId); } Modified: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManagerImpl.java =================================================================== --- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManagerImpl.java 2009-07-23 21:27:47 UTC (rev 362) +++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManagerImpl.java 2009-07-24 11:53:42 UTC (rev 363) @@ -8,6 +8,8 @@ import de.campussource.cse.core.pdm.Attribute; import de.campussource.cse.core.pdm.Entity; import de.campussource.cse.core.pdm.EntityType; +import java.util.HashMap; +import java.util.LinkedList; import java.util.logging.Logger; import javax.ejb.EJB; import javax.ejb.Stateless; @@ -137,4 +139,64 @@ } em.remove(entity); } + + // ---------------------------------------------------------------------------------------------------------------- + public boolean updateAttributes(de.campussource.cse.core.cdm.EntityType xmlEntity) { + + boolean attributesChanged = false; + + /* Build map of attributes from xml for fast access */ + HashMap<String, AttributeType> xmlAttributesMap = new HashMap<String, AttributeType>(); + for (AttributeType xmlAttribute : xmlEntity.getAttribute()) { + xmlAttributesMap.put(xmlAttribute.getName(), xmlAttribute); + } + + Entity entity = em.find(Entity.class, xmlEntity.getBusId()); + + /* Check for changes (value changed, attribute deleted) */ + LinkedList<Attribute> newAttributes = new LinkedList<Attribute>(); + HashMap<String, Attribute> attributesMap = new HashMap<String, Attribute>(); + for (Attribute attribute : entity.getAttributes()) { + /* Build hash for later */ + attributesMap.put(attribute.getName(), attribute); + + if (!xmlAttributesMap.containsKey(attribute.getName())) { + /* Attribute has been deleted => delete in persistence + set update = true */ + em.remove(attribute); + attributesChanged = true; + continue; + } + AttributeType xmlAttribute = xmlAttributesMap.get(attribute.getName()); + newAttributes.add(attribute); + if (!attribute.getValue().equals(xmlAttribute.getValue())) { + /* Attribute value changed */ + attribute.setValue(xmlAttribute.getValue()); + attributesChanged = true; + } + } + + /* Now check, if there are new attributes on the xml side */ + for (AttributeType xmlAttribute : xmlEntity.getAttribute()) { + if (!attributesMap.containsKey(xmlAttribute.getName())) { + /* New attribute */ + Attribute attribute = new Attribute(); + attribute.setName(xmlAttribute.getName()); + attribute.setValue(xmlAttribute.getValue()); + attribute.setEntity(entity); + newAttributes.add(attribute); + attributesChanged = true; + } + } + + /* Set new attribute-list for entity */ + entity.setAttributes(newAttributes); + + return attributesChanged; + } + + // ---------------------------------------------------------------------------------------------------------------- + public Entity getEntity(int cseId) { + Entity entity = em.find(Entity.class, cseId); + return entity; + } } Modified: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManagerWS.java =================================================================== --- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManagerWS.java 2009-07-23 21:27:47 UTC (rev 362) +++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManagerWS.java 2009-07-24 11:53:42 UTC (rev 363) @@ -47,9 +47,4 @@ return ejbRef.createProxy(type); } - @WebMethod(operationName = "test") - public int test( @WebParam(name = "entity") EntityType entity) { - return ejbRef.test(entity); - } - } Modified: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/Attribute.java =================================================================== --- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/Attribute.java 2009-07-23 21:27:47 UTC (rev 362) +++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/Attribute.java 2009-07-24 11:53:42 UTC (rev 363) @@ -1,7 +1,6 @@ package de.campussource.cse.core.pdm; import java.io.Serializable; -import javax.persistence.CascadeType; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @@ -29,7 +28,7 @@ private String value; /* Parent entity */ - @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "entityId") private Entity entity; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |