incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r393615 [1/2] - in /incubator/graffito/trunk/jcr/jcr-mapping/src: java/org/apache/portals/graffito/jcr/mapper/impl/ java/org/apache/portals/graffito/jcr/mapper/model/ java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ jav...
Date Wed, 12 Apr 2006 21:15:28 GMT
Author: clombart
Date: Wed Apr 12 14:15:26 2006
New Revision: 393615

URL: http://svn.apache.org/viewcvs?rev=393615&view=rev
Log:
Adding proxy support for the collection field

Added:
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/CollectionLazyLoader.java
Modified:
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/CollectionConverter.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/AbstractCollectionConverterImpl.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImpl.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/NTCollectionConverterImpl.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ProxyManager.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/reflection/ReflectionUtils.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-inheritance.xml
    incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-proxy.xml
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerNtConcreteClassTest.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ProxyTest.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/proxy/Main.java

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java?rev=393615&r1=393614&r2=393615&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java
Wed Apr 12 14:15:26 2006
@@ -195,7 +195,7 @@
     /**
      * Validate all class descriptors.
      * This method validates the toplevel ancestors and after the descendants. 
-     * Otherwise, we can have invalid settings in the class descritpors
+     * Otherwise, we can have invalid settings in the class descriptors
      * @param errors all errors found during the validation process
      * @param classDescriptors the ancestor classdescriptors
      * @return

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java?rev=393615&r1=393614&r2=393615&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java
Wed Apr 12 14:15:26 2006
@@ -315,7 +315,8 @@
      * Revisit information in this descriptor and fills in more.
      */
     public void afterPropertiesSet() {
-        validateClassName();        
+        validateClassName();   
+        validateBeanFields();
         lookupSuperDescriptor();
         lookupInheritanceSettings();
         validateInheritanceSettings();
@@ -329,6 +330,20 @@
 		}
 	}
 
+	private void validateBeanFields()
+	{
+	         Iterator beanDescriptorIterator  =  beanDescriptors.values().iterator();
+	         while (beanDescriptorIterator.hasNext()) {
+              	        BeanDescriptor beanDescriptor = (BeanDescriptor) beanDescriptorIterator.next();
+              	        if (beanDescriptor.isProxy() && beanDescriptor.isInline())
+              	        {
+              	        	     throw new JcrMappingException("Bean field can not be proxy and
inline - class : " + this.className + " - bean field :" + beanDescriptor.getFieldName());

+              	        }
+				       
+			}
+
+	}
+	
 	private void lookupSuperDescriptor() {
         if (null != superClassDescriptor) {
             this.fieldDescriptors = mergeFields(this.fieldDescriptors, this.superClassDescriptor.getFieldDescriptors());

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/CollectionConverter.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/CollectionConverter.java?rev=393615&r1=393614&r2=393615&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/CollectionConverter.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/CollectionConverter.java
Wed Apr 12 14:15:26 2006
@@ -68,4 +68,20 @@
 	public ManageableCollection getCollection(Session session, Node parentNode, 
 			                                  CollectionDescriptor collectionDescriptor, Class collectionFieldClass)
throws PersistenceException;
 
+	
+	/**
+	 * Check if the collection is null. This method is mainly used in the Proxy manager to return
a null value or a proxy object
+	 * Without proxy proxy, this method is never called. 
+	 * 
+	 * @param session The JCR session 
+	 * @param parentNode the node which contains the collection element
+	 * @param collectionDescriptor The collection descriptor
+	 * @param collectionFieldClass The collection class to used (ArrayList, Vector, ..) 
+	 * @return true if the collection contains elements.
+	 * 
+	 * 
+	 * @throws PersistenceException when it is not possible to retrieve the collection 
+	 */	
+	public boolean isNull(Session session, Node parentNode, 
+                                      CollectionDescriptor collectionDescriptor, Class collectionFieldClass)
throws PersistenceException;
 }

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/AbstractCollectionConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/AbstractCollectionConverterImpl.java?rev=393615&r1=393614&r2=393615&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/AbstractCollectionConverterImpl.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/AbstractCollectionConverterImpl.java
Wed Apr 12 14:15:26 2006
@@ -34,6 +34,7 @@
 import org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter;
 import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection;
 import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
+import org.apache.portals.graffito.jcr.reflection.ReflectionUtils;
 
 /** 
  * Abstract class used for all CollectionConverter
@@ -42,162 +43,123 @@
  * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
  */
 public abstract class AbstractCollectionConverterImpl implements CollectionConverter {
-    protected Map atomicTypeConverters;
-	protected ObjectConverter objectConverter;    
-    // NOT USED
-    protected Mapper mapper;
-    
-    /**
-     * Constructor
-     * 
-     * @param atomicTypeConverters The atomic type converter to used
-     * @param objectConverter The object converter to used
-     * @param mapper The mapper to used
-     */
-    public AbstractCollectionConverterImpl(Map atomicTypeConverters, 
-                                           ObjectConverter objectConverter, 
-                                           Mapper mapper) {
-	    this.atomicTypeConverters = atomicTypeConverters;
-        this.objectConverter = objectConverter;
-        this.mapper = mapper;
-    }
-
-    protected abstract void doInsertCollection(Session session,
-                                               Node parentNode,
-                                               CollectionDescriptor descriptor,
-                                               ManageableCollection collection) throws RepositoryException;
-    
-    protected abstract void doUpdateCollection(Session session,
-                                               Node parentNode,
-                                               CollectionDescriptor descriptor,
-                                               ManageableCollection collection) throws RepositoryException;
-    
-    protected abstract ManageableCollection  doGetCollection(Session session,
-                                                             Node parentNode,
-                                                             CollectionDescriptor collectionDescriptor,
-                                                             Class collectionFieldClass)
throws RepositoryException;
-    
-   /**
-    * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter#insertCollection(javax.jcr.Session,
javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor, org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection)
-    */
-   public void insertCollection(Session session,
-                                Node parentNode,
-                                CollectionDescriptor collectionDescriptor,
-                                ManageableCollection collection) {
-       try {
-           doInsertCollection(session, parentNode, collectionDescriptor, collection);
-       }
-       catch(ItemExistsException iee) {
-           throw new PersistenceException("Cannot insert collection field : " 
-                   + collectionDescriptor.getFieldName() + " of class " 
-                   + collectionDescriptor.getClassDescriptor().getClassName()
-                   + ". An item already exists.", iee);
-       }
-       catch(PathNotFoundException pnfe) {
-           throw new PersistenceException("Cannot insert collection field : " 
-                   + collectionDescriptor.getFieldName()
-                   + " of class "
-                   + collectionDescriptor.getClassDescriptor().getClassName(), pnfe);
-       }
-       catch(VersionException ve) {
-           throw new PersistenceException("Cannot insert collection field : " 
-                   + collectionDescriptor.getFieldName()
-                   + " of class "
-                   + collectionDescriptor.getClassDescriptor().getClassName(), ve);
-       }
-       catch(ConstraintViolationException cve) {
-           throw new PersistenceException("Cannot insert collection field : " 
-                   + collectionDescriptor.getFieldName() 
-                   + " of class "
-                   + collectionDescriptor.getClassDescriptor().getClassName()
-                   + ". Constraint violation.", cve);
-       }
-       catch(LockException le) {
-           throw new PersistenceException("Cannot insert collection field : " 
-                   + collectionDescriptor.getFieldName() 
-                   + " of class "
-                   + collectionDescriptor.getClassDescriptor().getClassName() 
-                   + " on locked parent.", le);
-       }
-       catch(RepositoryException re) {
-           throw new org.apache.portals.graffito.jcr.exception.RepositoryException(
-                   "Cannot insert collection field : " 
-                   + collectionDescriptor.getFieldName()
-                   + " of class "
-                   + collectionDescriptor.getClassDescriptor().getClassName(), re);
-       }
-   }
-   
-    /**
-    *
-    * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter#updateCollection(javax.jcr.Session,
javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor, org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection)
-    */
-   public void updateCollection(Session session,
-                                Node parentNode,
-                                CollectionDescriptor collectionDescriptor,
-                                ManageableCollection collection) {
-       try {
-           doUpdateCollection(session, parentNode, collectionDescriptor, collection);
-       }
-       catch(VersionException ve) {
-           throw new PersistenceException("Cannot insert collection field : " 
-                   + collectionDescriptor.getFieldName() 
-                   + " of class " 
-                   + collectionDescriptor.getClassDescriptor().getClassName(), 
-                   ve);
-       }
-       catch(LockException le) {
-           throw new PersistenceException("Cannot insert collection field : " 
-                   + collectionDescriptor.getFieldName() 
-                   + " of class " 
-                   + collectionDescriptor.getClassDescriptor().getClassName()
-                   + " on locked node", 
-                   le);
-       }
-       catch(ConstraintViolationException cve) {
-           throw new PersistenceException("Cannot insert collection field : " 
-                   + collectionDescriptor.getFieldName() 
-                   + " of class " 
-                   + collectionDescriptor.getClassDescriptor().getClassName()
-                   + " Constraint violation.", 
-                   cve);
-       }
-       catch(RepositoryException re) {
-           throw new org.apache.portals.graffito.jcr.exception.RepositoryException(
-                   "Cannot insert collection field : " 
-                   + collectionDescriptor.getFieldName() 
-                   + " of class " 
-                   + collectionDescriptor.getClassDescriptor().getClassName(), 
-                   re);
-       }
-   }
-   
-   /**
-    * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter#getCollection(javax.jcr.Session,
javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor, java.lang.Class)
-    */
-   public ManageableCollection getCollection(Session session,
-                                             Node parentNode,
-                                             CollectionDescriptor collectionDescriptor,
-                                             Class collectionFieldClass) {
-       try {
-           return doGetCollection(session, parentNode, collectionDescriptor, collectionFieldClass);
-       }
-       catch(RepositoryException re) {
-           throw new org.apache.portals.graffito.jcr.exception.RepositoryException(
-                   "Cannot get collection field : " + collectionDescriptor.getFieldName()
-                   + "for " + collectionDescriptor.getClassDescriptor().getClassName(),
-                   re);
-       }
-   }
-
-   protected String getCollectionJcrName(CollectionDescriptor descriptor) {
-        String jcrName = descriptor.getJcrName();
-        
-        if (null == jcrName) {
-            throw new JcrMappingException("The JcrName attribute is not defined for the CollectionDescriptor
: "
-                    + descriptor.getFieldName());
-        }
-        
-        return jcrName;
-    }
+	protected Map atomicTypeConverters;
+	protected ObjectConverter objectConverter;
+	// NOT USED
+	protected Mapper mapper;
+
+	/**
+	 * Constructor
+	 * 
+	 * @param atomicTypeConverters The atomic type converter to used
+	 * @param objectConverter The object converter to used
+	 * @param mapper The mapper to used
+	 */
+	public AbstractCollectionConverterImpl(Map atomicTypeConverters, ObjectConverter objectConverter,
Mapper mapper) {
+		this.atomicTypeConverters = atomicTypeConverters;
+		this.objectConverter = objectConverter;
+		this.mapper = mapper;
+	}
+
+	protected abstract void doInsertCollection(Session session, Node parentNode, CollectionDescriptor
descriptor,
+			ManageableCollection collection) throws RepositoryException;
+
+	protected abstract void doUpdateCollection(Session session, Node parentNode, CollectionDescriptor
descriptor,
+			ManageableCollection collection) throws RepositoryException;
+
+	protected abstract ManageableCollection doGetCollection(Session session, Node parentNode,
+			CollectionDescriptor collectionDescriptor, Class collectionFieldClass) throws RepositoryException;
+
+	protected abstract boolean doIsNull(Session session, Node parentNode, CollectionDescriptor
collectionDescriptor,
+			Class collectionFieldClass) throws RepositoryException;
+
+	/**
+	 * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter#insertCollection(javax.jcr.Session,
javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor, org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection)
+	 */
+	public void insertCollection(Session session, Node parentNode, CollectionDescriptor collectionDescriptor,
+			ManageableCollection collection) {
+		try {
+			doInsertCollection(session, parentNode, collectionDescriptor, collection);
+		} catch (ItemExistsException iee) {
+			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
+					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName() + ". An item
already exists.", iee);
+		} catch (PathNotFoundException pnfe) {
+			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
+					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName(), pnfe);
+		} catch (VersionException ve) {
+			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
+					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName(), ve);
+		} catch (ConstraintViolationException cve) {
+			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
+					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName() + ". Constraint
violation.", cve);
+		} catch (LockException le) {
+			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
+					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName() + " on locked
parent.", le);
+		} catch (RepositoryException re) {
+			throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Cannot insert
collection field : "
+					+ collectionDescriptor.getFieldName() + " of class "
+					+ collectionDescriptor.getClassDescriptor().getClassName(), re);
+		}
+	}
+
+	/**
+	 *
+	 * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter#updateCollection(javax.jcr.Session,
javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor, org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection)
+	 */
+	public void updateCollection(Session session, Node parentNode, CollectionDescriptor collectionDescriptor,
+			ManageableCollection collection) {
+		try {
+
+				doUpdateCollection(session, parentNode, collectionDescriptor, collection);
+		} catch (VersionException ve) {
+			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
+					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName(), ve);
+		} catch (LockException le) {
+			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
+					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName() + " on locked
node", le);
+		} catch (ConstraintViolationException cve) {
+			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
+					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName() + " Constraint
violation.", cve);
+		} catch (RepositoryException re) {
+			throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Cannot insert
collection field : "
+					+ collectionDescriptor.getFieldName() + " of class "
+					+ collectionDescriptor.getClassDescriptor().getClassName(), re);
+		}
+	}
+
+	/**
+	 * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter#getCollection(javax.jcr.Session,
javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor, java.lang.Class)
+	 */
+	public ManageableCollection getCollection(Session session, Node parentNode, CollectionDescriptor
collectionDescriptor,
+			Class collectionFieldClass) {
+		try {
+			return doGetCollection(session, parentNode, collectionDescriptor, collectionFieldClass);
+		} catch (RepositoryException re) {
+			throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Cannot get collection
field : "
+					+ collectionDescriptor.getFieldName() + "for " + collectionDescriptor.getClassDescriptor().getClassName(),
re);
+		}
+	}
+
+	/**
+	 * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter#isNull(Session,
Node, CollectionDescriptor, Class)
+	 */
+	public boolean isNull(Session session, Node parentNode, CollectionDescriptor collectionDescriptor,
+			Class collectionFieldClass) {
+		try {
+			return doIsNull(session, parentNode, collectionDescriptor, collectionFieldClass);
+		} catch (RepositoryException re) {
+			throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Cannot  check
if the collections has elements : "
+					+ collectionDescriptor.getFieldName() + "for " + collectionDescriptor.getClassDescriptor().getClassName(),
re);
+		}
+	}
+	protected String getCollectionJcrName(CollectionDescriptor descriptor) {
+		String jcrName = descriptor.getJcrName();
+
+		if (null == jcrName) {
+			throw new JcrMappingException("The JcrName attribute is not defined for the CollectionDescriptor
: "
+					+ descriptor.getFieldName());
+		}
+
+		return jcrName;
+	}
 }

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java?rev=393615&r1=393614&r2=393615&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java
Wed Apr 12 14:15:26 2006
@@ -136,13 +136,14 @@
                                  Node parentNode,
                                  CollectionDescriptor collectionDescriptor,
                                  ManageableCollection collection) throws RepositoryException
{
-        String jcrName = getCollectionJcrName(collectionDescriptor);
-
-        if (collection == null) {
-            if (parentNode.hasNode(jcrName)) {
+        
+    	    String jcrName = getCollectionJcrName(collectionDescriptor);
+        if (collection == null)
+        {
+            if (parentNode.hasNode(jcrName)) 
+            {
                 parentNode.getNode(jcrName).remove();
             }
-
             return;
         }
 
@@ -213,7 +214,7 @@
                                               Class collectionFieldClass) throws RepositoryException
{
         String jcrName = getCollectionJcrName(collectionDescriptor);
 
-        if (!parentNode.hasNode(jcrName)) {
+        if (parentNode == null || !parentNode.hasNode(jcrName)) {
             return null;
         }
 
@@ -230,4 +231,19 @@
 
         return collection;
     }
+    
+    /**
+     * @see AbstractCollectionConverterImpl#doIsNull(Session, Node, CollectionDescriptor,
Class)
+     */
+    protected boolean doIsNull(Session session,
+                                              Node parentNode,
+                                              CollectionDescriptor collectionDescriptor,
+                                              Class collectionFieldClass) throws RepositoryException
{
+        String jcrName = getCollectionJcrName(collectionDescriptor);
+
+        if (parentNode == null || !parentNode.hasNode(jcrName)) {
+            return true;
+        }
+        return false;
+    }    
 }

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImpl.java?rev=393615&r1=393614&r2=393615&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImpl.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImpl.java
Wed Apr 12 14:15:26 2006
@@ -161,4 +161,19 @@
                   vfe);
         }
     }
+    
+    /**
+     * @see AbstractCollectionConverterImpl#doIsNull(Session, Node, CollectionDescriptor,
Class)
+     */
+    protected boolean doIsNull(Session session,
+                                              Node parentNode,
+                                              CollectionDescriptor collectionDescriptor,
+                                              Class collectionFieldClass) throws RepositoryException
{
+        String jcrName = getCollectionJcrName(collectionDescriptor);
+
+         if (!parentNode.hasProperty(jcrName)) {
+            return true;
+        }
+        return false;
+    }     
 }

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/NTCollectionConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/NTCollectionConverterImpl.java?rev=393615&r1=393614&r2=393615&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/NTCollectionConverterImpl.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/NTCollectionConverterImpl.java
Wed Apr 12 14:15:26 2006
@@ -214,6 +214,18 @@
 
         return collection;
     }
+    
+    /**
+     * @see AbstractCollectionConverterImpl#doIsNull(Session, Node, CollectionDescriptor,
Class)
+     */
+    protected boolean doIsNull(Session session,
+                                              Node parentNode,
+                                              CollectionDescriptor collectionDescriptor,
+                                              Class collectionFieldClass) throws RepositoryException
{
+
+    	    // This collection converter returns at least a empty collection (see in doGetCollection)

+        return false;
+    }         
 
     private Collection getCollectionNodes(Session session, Node parentNode, String itemNodeType)
     throws PathNotFoundException, ValueFormatException, RepositoryException {

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/CollectionLazyLoader.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/CollectionLazyLoader.java?rev=393615&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/CollectionLazyLoader.java
(added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/CollectionLazyLoader.java
Wed Apr 12 14:15:26 2006
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2000-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.portals.graffito.jcr.persistence.objectconverter.impl;
+
+import javax.jcr.Node;
+import javax.jcr.Session;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor;
+import org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter;
+import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection;
+import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
+
+import net.sf.cglib.proxy.LazyLoader;
+
+public class CollectionLazyLoader implements LazyLoader {
+
+	private final static Log log = LogFactory.getLog(CollectionLazyLoader.class);
+
+	private CollectionConverter collectionConverter;
+	private Session session;
+	private Node collectionParentNode;
+	private CollectionDescriptor collectionDescriptor; 
+	private Class collectionFieldClass;
+	
+	public CollectionLazyLoader(CollectionConverter collectionConverter, Session session, Node
parentNode, 
+			                                               CollectionDescriptor collectionDescriptor,
Class collectionFieldClass ) {
+		this.collectionConverter = collectionConverter;
+		this.session = session;
+		this.collectionParentNode = parentNode;
+		this.collectionDescriptor = collectionDescriptor;
+		this.collectionFieldClass = collectionFieldClass;
+	}
+
+	public Object loadObject() {
+	
+		
+		ManageableCollection collection = collectionConverter.getCollection(session, collectionParentNode,
collectionDescriptor, collectionFieldClass);
+		return collection;
+	}
+}



Mime
View raw message