jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r705010 - in /jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter: ObjectConverter.java impl/ObjectConverterImpl.java
Date Wed, 15 Oct 2008 19:57:31 GMT
Author: clombart
Date: Wed Oct 15 12:57:31 2008
New Revision: 705010

URL: http://svn.apache.org/viewvc?rev=705010&view=rev
Log:
this is the second patch provided by Boni Gopalan for issue JCR-1784 (The UUID of the collection
elements changes on update). 

Modified:
    jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/ObjectConverter.java
    jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java

Modified: jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/ObjectConverter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/ObjectConverter.java?rev=705010&r1=705009&r2=705010&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/ObjectConverter.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/ObjectConverter.java
Wed Oct 15 12:57:31 2008
@@ -108,6 +108,16 @@
 	 * Update the object
 	 *
 	 * @param session the JCR session
+	 * @param objectNode The node to store the object
+	 * @param object the object to update
+	 * @throws ObjectContentManagerException when it is not possible to update the object
+	 */
+    public void update(Session session, Node objectNode, Object object) throws ObjectContentManagerException;
+    
+	/**
+	 * Update the object
+	 *
+	 * @param session the JCR session
 	 * @param parentNode The parent node used to store the new JCR element (object)
 	 * @param nodeName The node name used to store the object
 	 * @param object the object to update

Modified: jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java?rev=705010&r1=705009&r2=705010&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java
Wed Oct 15 12:57:31 2008
@@ -21,6 +21,7 @@
 import java.util.Map;
 
 import javax.jcr.Node;
+import javax.jcr.NodeIterator;
 import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
@@ -64,6 +65,7 @@
  *
  * @author <a href="mailto:christophe.lombart@gmail.com">Lombart  Christophe </a>
  * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
+ * @author <a href='mailto:boni.g@bioimagene.com'>Boni Gopalan</a>
  */
 public class ObjectConverterImpl implements ObjectConverter {
 
@@ -275,32 +277,21 @@
 		try {
 			ClassDescriptor classDescriptor = mapper.getClassDescriptorByClass(ReflectionUtils.getBeanClass(object));
 			Node objectNode = session.getNodeByUUID(uuId);
-
-			checkNodeType(session, classDescriptor);
-
-			checkCompatiblePrimaryNodeTypes(session, objectNode, classDescriptor, false);
-
-			simpleFieldsHelp.storeSimpleFields(session, object, classDescriptor, objectNode);
-			updateBeanFields(session, object, classDescriptor, objectNode);
-			updateCollectionFields(session, object, classDescriptor, objectNode);
-			simpleFieldsHelp.refreshUuidPath(session, classDescriptor, objectNode, object);
+			update(session, objectNode, object);
 		} catch (PathNotFoundException pnfe) {
 			throw new ObjectContentManagerException("Impossible to update the object with UUID: "
+ uuId , pnfe);
 		} catch (RepositoryException re) {
 			throw new org.apache.jackrabbit.ocm.exception.RepositoryException("Impossible to update
the object with UUID: " + uuId, re);
 		}
 	}
-	
-	
+
 	/**
 	 *
 	 * @see org.apache.jackrabbit.ocm.manager.objectconverter.ObjectConverter#update(javax.jcr.Session,
-	 *      javax.jcr.Node, java.lang.String, java.lang.Object)
+	 *      javax.jcr.Node, java.lang.Object)
 	 */
-	public void update(Session session, Node parentNode, String nodeName, Object object) {
-		try {
+	public void update(Session session, Node objectNode, Object object) {
 			ClassDescriptor classDescriptor = mapper.getClassDescriptorByClass(ReflectionUtils.getBeanClass(object));
-			Node objectNode = parentNode.getNode(nodeName);
 
 			checkNodeType(session, classDescriptor);
 
@@ -310,6 +301,19 @@
 			updateBeanFields(session, object, classDescriptor, objectNode);
 			updateCollectionFields(session, object, classDescriptor, objectNode);
 			simpleFieldsHelp.refreshUuidPath(session, classDescriptor, objectNode, object);
+	}
+	
+
+	/**
+	 *
+	 * @see org.apache.jackrabbit.ocm.manager.objectconverter.ObjectConverter#update(javax.jcr.Session,
+	 *      javax.jcr.Node, java.lang.String, java.lang.Object)
+	 */
+	public void update(Session session, Node parentNode, String nodeName, Object object) {
+		try {
+			ClassDescriptor classDescriptor = mapper.getClassDescriptorByClass(ReflectionUtils.getBeanClass(object));
+			Node objectNode = getNode(parentNode,classDescriptor,nodeName,object);
+			update(session, objectNode, object);
 		} catch (PathNotFoundException pnfe) {
 			throw new ObjectContentManagerException("Impossible to update the object: " + nodeName
+ " at node : " + parentNode, pnfe);
 		} catch (RepositoryException re) {
@@ -319,6 +323,36 @@
 	}
 
 	/**
+	 * 
+	 * @param parentNode the parent node at which to look for the node element.
+	 * @param nodeName the node name to look for
+	 * @param object the data.
+	 * @param classDescriptor
+	 * @return The child node we are interested in.
+	 */
+	private Node getNode(Node parentNode, ClassDescriptor classDescriptor, String nodeName,
Object object) throws RepositoryException{
+		if (parentNode == null) return null;
+		NodeIterator nodes = parentNode.getNodes(nodeName);
+		if (nodes.getSize() == 1) return nodes.nextNode();
+		if (classDescriptor.hasUUIdField()){
+            String uuidFieldName = classDescriptor.getUuidFieldDescriptor().getFieldName();
+            Object objUuid = ReflectionUtils.getNestedProperty(object, uuidFieldName);
+        	String currentItemUuid = (objUuid == null) ? null : objUuid.toString();
+        	if (currentItemUuid != null){
+        		//The Node already exists so we need to update the existing node 
+        		//rather than to replace it.
+        		return parentNode.getSession().getNodeByUUID(currentItemUuid);
+        	}
+        	else{
+        		throw new NullPointerException("Cannot locate the node to update since there is
no UUID provided even though, " + classDescriptor.getClassName() + " has been mapped with
a UUID field , " + uuidFieldName );
+        	}
+        		
+		}
+		return parentNode.getNode(nodeName);
+		
+	}
+	
+	/**
 	 * @see org.apache.jackrabbit.ocm.manager.objectconverter.ObjectConverter#getObject(javax.jcr.Session,
 	 *      java.lang.Class, java.lang.String)
 	 */



Mime
View raw message