jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r537947 - in /jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence: beanconverter/impl/DefaultBeanConverterImpl.java collectionconverter/impl/DefaultCollectionConverterImpl.java
Date Mon, 14 May 2007 18:48:16 GMT
Author: clombart
Date: Mon May 14 11:48:16 2007
New Revision: 537947

URL: http://svn.apache.org/viewvc?view=rev&rev=537947
Log:
Better management for null values 

Modified:
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/beanconverter/impl/DefaultBeanConverterImpl.java
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java

Modified: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/beanconverter/impl/DefaultBeanConverterImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/beanconverter/impl/DefaultBeanConverterImpl.java?view=diff&rev=537947&r1=537946&r2=537947
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/beanconverter/impl/DefaultBeanConverterImpl.java
(original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/beanconverter/impl/DefaultBeanConverterImpl.java
Mon May 14 11:48:16 2007
@@ -60,7 +60,22 @@
 	public void update(Session session, Node parentNode, BeanDescriptor beanDescriptor, ClassDescriptor
beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
 			throws PersistenceException, RepositoryException,	JcrMappingException 
 	{
-		objectConverter.update(session, parentNode, beanDescriptor.getJcrName(), object);
+		try 
+		{
+			String jcrNodeName = beanDescriptor.getJcrName(); 
+			if (parentNode.hasNode(jcrNodeName))
+			{		
+			   objectConverter.update(session, parentNode, beanDescriptor.getJcrName() , object);
+			}
+			else 
+			{
+			   objectConverter.insert(session, parentNode, beanDescriptor.getJcrName() , object);
+			}
+		} 
+		catch (javax.jcr.RepositoryException e) 
+		{
+			throw new RepositoryException(e);	
+		}
 	}
 
 	public Object getObject(Session session, Node parentNode, BeanDescriptor beanDescriptor,
ClassDescriptor beanClassDescriptor, Class beanClass, Object parent)

Modified: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java?view=diff&rev=537947&r1=537946&r2=537947
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java
(original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java
Mon May 14 11:48:16 2007
@@ -136,17 +136,27 @@
                                  CollectionDescriptor collectionDescriptor,
                                  ManageableCollection collection) throws RepositoryException
{
         
-    	    String jcrName = getCollectionJcrName(collectionDescriptor);
-        if (collection == null)
+    	String jcrName = getCollectionJcrName(collectionDescriptor);
+    	boolean hasNode = parentNode.hasNode(jcrName);
+        // If the new value for the collection is null, drop the node matching to the collection
+    	if (collection == null)
         {
-            if (parentNode.hasNode(jcrName)) 
+            if (hasNode) 
             {
                 parentNode.getNode(jcrName).remove();
             }
             return;
         }
 
+    	// If there is not yet a node matching to the collection, insert the collection 
+    	if (! hasNode)
+    	{
+    		this.doInsertCollection(session, parentNode, collectionDescriptor, collection);
+    		return;
+    	}
         
+    	// update process
+    	
         ClassDescriptor elementClassDescriptor = mapper.getClassDescriptorByClass( ReflectionUtils.forName(collectionDescriptor.getElementClassName()));
        
         Node collectionNode = parentNode.getNode(jcrName);
         //  If the collection elements have not an id, it is not possible to find the matching
JCR nodes => delete the complete collection
@@ -221,7 +231,7 @@
         
         while (children.hasNext()) {
             Node itemNode = children.nextNode();
-            Object item = objectConverter.getObject(session, itemNode.getPath());
+            Object item = objectConverter.getObject(session, elementClass, itemNode.getPath());
             collection.addObject(item);
         }
 



Mime
View raw message