incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r390516 - in /incubator/graffito/trunk/jcr/jcr-mapping/src: java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ test-config/ test-config/repositor...
Date Fri, 31 Mar 2006 22:01:29 GMT
Author: clombart
Date: Fri Mar 31 14:01:26 2006
New Revision: 390516

URL: http://svn.apache.org/viewcvs?rev=390516&view=rev
Log:
Finalize the node type per concrete class strategy : add more unit tests and bug fixs

Modified:
    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/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/test-config/jcrmapping-inheritance.xml
    incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/repository/repository/nodetypes/custom_nodetypes.xml
    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/testmodel/inheritance/Folder.java

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=390516&r1=390515&r2=390516&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
Fri Mar 31 14:01:26 2006
@@ -57,7 +57,7 @@
     public AbstractCollectionConverterImpl(Map atomicTypeConverters, 
                                            ObjectConverter objectConverter, 
                                            Mapper mapper) {
-    	this.atomicTypeConverters = atomicTypeConverters;
+    	    this.atomicTypeConverters = atomicTypeConverters;
         this.objectConverter = objectConverter;
         this.mapper = mapper;
     }

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=390516&r1=390515&r2=390516&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
Fri Mar 31 14:01:26 2006
@@ -104,10 +104,8 @@
         }
 
         Node collectionNode = parentNode.addNode(jcrName);
-
-        Mapper mapper = collectionDescriptor.getClassDescriptor().getMappingDescriptor().getMapper();
-        ClassDescriptor elementClassDescriptor = mapper.getClassDescriptor(
-                ReflectionUtils.forName(collectionDescriptor.getElementClassName()));
+        
+        ClassDescriptor elementClassDescriptor = mapper.getClassDescriptor( ReflectionUtils.forName(collectionDescriptor.getElementClassName()));

 
         Iterator collectionIterator = collection.getIterator();
         int elementCollectionCount = 0;
@@ -149,10 +147,7 @@
         }
 
         
-        Mapper mapper = collectionDescriptor.getClassDescriptor().getMappingDescriptor().getMapper();
-        ClassDescriptor elementClassDescriptor = mapper.getClassDescriptor(
-                ReflectionUtils.forName(collectionDescriptor.getElementClassName()));
-        
+        ClassDescriptor elementClassDescriptor = mapper.getClassDescriptor( 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
         if (!elementClassDescriptor.hasIdField()) {

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=390516&r1=390515&r2=390516&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
Fri Mar 31 14:01:26 2006
@@ -101,10 +101,8 @@
         if (collection == null) {
             return;
         }
-
-        Mapper mapper = collectionDescriptor.getClassDescriptor().getMappingDescriptor().getMapper();
-        ClassDescriptor elementClassDescriptor = mapper.getClassDescriptor(
-                ReflectionUtils.forName(collectionDescriptor.getElementClassName()));
+        
+        ClassDescriptor elementClassDescriptor = mapper.getClassDescriptor( ReflectionUtils.forName(collectionDescriptor.getElementClassName()));
 
         Iterator collectionIterator = collection.getIterator();
         int elementCollectionCount = 0;
@@ -201,9 +199,7 @@
                                                    Node parentNode,
                                                    CollectionDescriptor collectionDescriptor,
                                                    Class collectionFieldClass) throws RepositoryException
{
-        Mapper mapper = collectionDescriptor.getClassDescriptor().getMappingDescriptor().getMapper();
-        ClassDescriptor elementClassDescriptor = mapper.getClassDescriptor(
-                ReflectionUtils.forName(collectionDescriptor.getElementClassName()));
+    	    ClassDescriptor elementClassDescriptor = mapper.getClassDescriptor( ReflectionUtils.forName(collectionDescriptor.getElementClassName()));

         ManageableCollection collection = ManageableCollectionUtil.getManageableCollection(collectionFieldClass);
         Class elementClass = ReflectionUtils.forName(collectionDescriptor.getElementClassName());
         Iterator children = this.getCollectionNodes(session, parentNode,

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java?rev=390516&r1=390515&r2=390516&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
Fri Mar 31 14:01:26 2006
@@ -168,9 +168,6 @@
             }
         }
 
-        if (classDescriptor.usesNodeTypePerHierarchyStrategy()) {
-
-        }
 
         storeSimpleFields(session, object, classDescriptor, objectNode);
         insertBeanFields(session, object, classDescriptor, objectNode);
@@ -646,12 +643,8 @@
                 collectionDescriptorIterator.next();
             CollectionConverter collectionConverter = this.getCollectionConverter(session,
collectionDescriptor);
             Object collection = ReflectionUtils.getNestedProperty(object, collectionDescriptor.getFieldName());
-            ManageableCollection manageableCollection = ManageableCollectionUtil
-                .getManageableCollection(collection);
-            collectionConverter.insertCollection(session,
-                                                 objectNode,
-                                                 collectionDescriptor,
-                                                 manageableCollection);
+            ManageableCollection manageableCollection = ManageableCollectionUtil.getManageableCollection(collection);
+            collectionConverter.insertCollection(session,objectNode,   collectionDescriptor,
manageableCollection);
         }
     }
 

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-inheritance.xml
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-inheritance.xml?rev=390516&r1=390515&r2=390516&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-inheritance.xml (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-inheritance.xml Fri
Mar 31 14:01:26 2006
@@ -32,7 +32,7 @@
 
 	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.CmsObject"
jcrNodeType="graffito:cmsobject"  abstract="true" >
 		<field-descriptor fieldName="path" path="true" />
-		<field-descriptor fieldName="name" jcrName="graffito:name" />
+		<field-descriptor fieldName="name" jcrName="graffito:name" id="true" />
 		<!--  bean-descriptor  fieldName="parentFolder" 						 
 						  converter="org.apache.portals.graffito.jcr.persistence.objectconverter.impl.ParentBeanConverterImpl"
/ -->
 
@@ -40,10 +40,9 @@
 
 	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.Folder"
jcrNodeType="graffito:folder" 
 	                                   extends="org.apache.portals.graffito.jcr.testmodel.inheritance.CmsObject"
>
-		<collection-descriptor fieldName="children" jcrName="graffito:children" proxy="false"
-                                                   elementClassName="org.apache.portals.graffito.jcr.testmodel.inheritance.CmsObject"
/>
-	                                   
-
+		<collection-descriptor fieldName="children" proxy="false" 
+		                       elementClassName="org.apache.portals.graffito.jcr.testmodel.inheritance.CmsObject"

+		                       collectionConverter="org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.NTCollectionConverterImpl"
/>
 	</class-descriptor >	
 
 	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.Content"
jcrNodeType="graffito:content" abstract="true"

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/repository/repository/nodetypes/custom_nodetypes.xml
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/repository/repository/nodetypes/custom_nodetypes.xml?rev=390516&r1=390515&r2=390516&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/repository/repository/nodetypes/custom_nodetypes.xml
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/repository/repository/nodetypes/custom_nodetypes.xml
Fri Mar 31 14:01:26 2006
@@ -97,12 +97,11 @@
   
   <nodeType name="graffito:folder" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
     <supertypes>
-      <supertype>graffito:cmsobject</supertype>
-       <supertype>mix:referenceable</supertype>
+      <supertype>graffito:cmsobject</supertype>       
     </supertypes>    
-    <childNodeDefinition name="*" defaultPrimaryType="graffito:cmsobject" autoCreated="false"
mandatory="false" onParentVersion="COPY" protected="false" sameNameSiblings="false">
+    <childNodeDefinition name="*" defaultPrimaryType="graffito:cmsobject" autoCreated="false"
mandatory="false" onParentVersion="COPY" protected="false" sameNameSiblings="true">
       <requiredPrimaryTypes>
-        <requiredPrimaryType>graffito:cmsobject</requiredPrimaryType>
+        <requiredPrimaryType>graffito:cmsobject</requiredPrimaryType>       
 
       </requiredPrimaryTypes>
     </childNodeDefinition>        
   </nodeType>

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerNtConcreteClassTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerNtConcreteClassTest.java?rev=390516&r1=390515&r2=390516&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerNtConcreteClassTest.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerNtConcreteClassTest.java
Fri Mar 31 14:01:26 2006
@@ -133,7 +133,7 @@
 		PersistenceManager persistenceManager = this.getPersistenceManager();
 
 		//---------------------------------------------------------------------------------------------------------
-		// Insert descendant objects
+		// Insert cmsobjects
 		//---------------------------------------------------------------------------------------------------------
		
         Document document = new Document();
         document.setPath("/document1");
@@ -170,11 +170,26 @@
         folder.setName("folder1");
         persistenceManager.insert(folder);
  
-         folder = new Folder();
+
+        document = new Document();        
+        document.setName("document4");
+        document.setContentType("plain/text"); 
+        documentStream = new DocumentStream();
+        documentStream.setEncoding("utf-8");
+        documentStream.setContent("Test Content 4".getBytes());
+        document.setDocumentStream(documentStream);       
+
+        Folder subFolder = new Folder();
+        subFolder.setName("subfolder");
+        
+        folder = new Folder();
         folder.setPath("/folder2");
-        folder.setName("folder2");
+        folder.setName("folder2");        
+        folder.addChild(document);
+        folder.addChild(subFolder);
         persistenceManager.insert(folder);               		
-
+        
+        
 		Atomic a = new Atomic();
 		a.setPath("/atomic");
 		a.setBooleanPrimitive(true);
@@ -183,12 +198,12 @@
 		persistenceManager.save();
 
 		//---------------------------------------------------------------------------------------------------------

-		// Retrieve Folders
+		// Retrieve Folders found on the root level
 		//---------------------------------------------------------------------------------------------------------
		
 		QueryManager queryManager = persistenceManager.getQueryManager();
 		Filter filter = queryManager.createFilter(Folder.class);
 		Query query = queryManager.createQuery(filter);
-
+		filter.setScope("/");
 		Collection result = persistenceManager.getObjects(query);
 		assertEquals("Invalid number of folders found", result.size(), 2);
 		assertTrue("Invalid item in the collection", this.contains(result, "/folder1",Folder.class));
@@ -200,6 +215,7 @@
 		//---------------------------------------------------------------------------------------------------------
		
 		queryManager = persistenceManager.getQueryManager();
 		filter = queryManager.createFilter(Document.class);
+		
 		filter.addLike("name", "document name%");
 		query = queryManager.createQuery(filter);
 
@@ -208,6 +224,24 @@
 		assertTrue("Invalid item in the collection", this.contains(result, "/document1", Document.class));
 		assertTrue("Invalid item in the collection", this.contains(result, "/document2", Document.class));
 
+		
+		//---------------------------------------------------------------------------------------------------------

+		// Retrieve folder2 
+		//---------------------------------------------------------------------------------------------------------

+		Folder folder2 = (Folder) persistenceManager.getObject(Folder.class, "/folder2");
+		assertNotNull("folder 2 is null", folder2);
+		assertEquals("Invalid number of cms object  found in folder2 children", folder2.getChildren().size()
,2);
+		assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/document4",
Document.class));
+		assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/subfolder",
Folder.class));
+		
+		
+		CmsObject cmsObject = (CmsObject) persistenceManager.getObject(CmsObject.class, "/folder2");
+		assertNotNull("folder 2 is null", cmsObject);
+		assertTrue("Invalid instance for folder 2",  cmsObject instanceof Folder);
+		assertEquals("Invalid number of documents  found in folder2 children",  folder2.getChildren().size(),2);
+		assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/document4",
Document.class));
+		assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/subfolder",
Folder.class));
+		
 		//---------------------------------------------------------------------------------------------------------

 		// Retrieve Contents (ancestor of Documents) 
 		//---------------------------------------------------------------------------------------------------------
		
@@ -223,20 +257,39 @@
 		
 				
 		//---------------------------------------------------------------------------------------------------------

-		// Retrieve all cmsobjects
+		// Retrieve all cmsobjects found on the root level
 		//---------------------------------------------------------------------------------------------------------
				
 		queryManager = persistenceManager.getQueryManager();
-		filter = queryManager.createFilter(CmsObject.class);		
+		filter = queryManager.createFilter(CmsObject.class);
+		filter.setScope("/");
 		query = queryManager.createQuery(filter);
 
 		result = persistenceManager.getObjects(query);
 		assertEquals("Invalid ancestor object found", result.size(),5);
 		assertTrue("Invalid item in the collection", this.contains(result, "/document1", Document.class));
 		assertTrue("Invalid item in the collection", this.contains(result, "/document2", Document.class));

+		assertTrue("Invalid item in the collection", this.contains(result, "/document3", Document.class));
	
+		assertTrue("Invalid item in the collection", this.contains(result, "/folder1",Folder.class));

+		assertTrue("Invalid item in the collection", this.contains(result, "/folder2",Folder.class));
+
+		
+		//---------------------------------------------------------------------------------------------------------

+		// Retrieve all cmsobjects found anywhere
+		//---------------------------------------------------------------------------------------------------------
				
+		queryManager = persistenceManager.getQueryManager();
+		filter = queryManager.createFilter(CmsObject.class);		
+		query = queryManager.createQuery(filter);
+
+		result = persistenceManager.getObjects(query);
+		assertEquals("Invalid ancestor object found", result.size(),7);
+		assertTrue("Invalid item in the collection", this.contains(result, "/document1", Document.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/document2", Document.class));

 		assertTrue("Invalid item in the collection", this.contains(result, "/document3", Document.class));
+		assertTrue("Invalid item in the collection", this.contains(result, "/folder2/document4",
Document.class));		
 		assertTrue("Invalid item in the collection", this.contains(result, "/folder1",Folder.class));

 		assertTrue("Invalid item in the collection", this.contains(result, "/folder2",Folder.class));
-	
+		assertTrue("Invalid item in the collection", this.contains(result, "/folder2/subfolder",Folder.class));
+		
 	}
 	    
 }

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/Folder.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/Folder.java?rev=390516&r1=390515&r2=390516&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/Folder.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/Folder.java
Fri Mar 31 14:01:26 2006
@@ -15,6 +15,7 @@
  */
 package org.apache.portals.graffito.jcr.testmodel.inheritance;
 
+import java.util.ArrayList;
 import java.util.List;
 
 
@@ -29,7 +30,7 @@
 public class Folder extends CmsObject 
 {
 
-    protected List children;
+    protected List children = new ArrayList();
 
 	public List getChildren() {
 		return children;



Mime
View raw message