incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r387947 - in /incubator/graffito/trunk/jcr/jcr-mapping/src: java/org/apache/portals/graffito/jcr/mapper/model/ java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ java/org/apache/portals/graffito/jcr/query/ java/org/apach...
Date Wed, 22 Mar 2006 21:08:51 GMT
Author: clombart
Date: Wed Mar 22 13:08:49 2006
New Revision: 387947

URL: http://svn.apache.org/viewcvs?rev=387947&view=rev
Log:
Still working on the inheritance support (add more unit tests, bug fix and code simplification).
I almost finished the strategy "node type per hierarchy". 
The getObjects method has still some issues with mode advance hierarchy.


Added:
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/SubDescendant.java
Modified:
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/BeanDescriptor.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/mapper/model/CollectionDescriptor.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.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/query/Filter.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/FilterImpl.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-inheritance.xml
    incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping.xml
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
    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/PersistenceManagerSimpleInheritanceTest.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/BeanDescriptorTest.java

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/BeanDescriptor.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/BeanDescriptor.java?rev=387947&r1=387946&r2=387947&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/BeanDescriptor.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/BeanDescriptor.java Wed Mar 22 13:08:49 2006
@@ -239,4 +239,9 @@
     public ClassDescriptor getClassDescriptor() {
         return classDescriptor;
     }
+    
+	public String toString() {
+		
+		return "Bean Descriptor : " +  this.fieldName;
+	}    
 }

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=387947&r1=387946&r2=387947&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 Mar 22 13:08:49 2006
@@ -16,6 +16,7 @@
 package org.apache.portals.graffito.jcr.mapper.model;
 
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -41,6 +42,7 @@
 
     private MappingDescriptor mappingDescriptor;
     private ClassDescriptor superClassDescriptor;
+    private Collection descendantClassDescriptors = new ArrayList();
 
     private String className;
     private String jcrNodeType;
@@ -59,8 +61,8 @@
     private String superClassName;
     private String extendsStrategy;
     private boolean abstractClass = false;
-   // private String discriminatorValue;
-
+    private boolean hasDescendant = false;
+   
     
     public void setAbstract(boolean flag) {
         this.abstractClass = flag;
@@ -70,39 +72,6 @@
         return this.abstractClass;
     }
 
-    /**
-     * @return Returns the discriminatorValue.
-     */
-//    public String getDiscriminatorValue() {
-//        return discriminatorValue;
-//    }
-
-    /**
-     * In case this class is part of an hierarchy which is
-     * using <tt>NODETYPE_PER_HIERARCHY</tt> strategy the returned
-     * value represents the value of the <tt>discriminator</tt>
-     * property than identifies uniquely this type.
-     * 
-     * @param discriminatorValue The discriminatorValue to set.
-     */
-//    public void setDiscriminatorValue(String discriminatorValue) {
-//        this.discriminatorValue= discriminatorValue;
-//    }
-
-    /**
-     * Returns the inheritance strategy used by this descriptor. It can be either
-     * <tt>NODETYPE_PER_CONCRETECLASS</tt>, <tt>NODETYPE_PER_HIERARCHY</tt> or
-     * <tt>null</tt> if no inheritance mechanism is used.
-     *
-     * @return Returns {@link #NODETYPE_PER_HIERARCHY} or {@link #NODETYPE_PER_CONCRETECLASS} or
-     * <tt>null</tt>
-     */
-/*
-    public String getExtendsStrategy() {
-        return extendsStrategy;
-    }
-*/
-
     public boolean usesNodeTypePerHierarchyStrategy() {
         return NODETYPE_PER_HIERARCHY.equals(this.extendsStrategy);
     }
@@ -256,12 +225,20 @@
     
     }
 
-    public FieldDescriptor getDiscriminatorFieldDescriptor() {
-        return this.discriminatorFieldDescriptor;
+    public FieldDescriptor getDiscriminatorFieldDescriptor() {       
+        if (null != this.discriminatorFieldDescriptor) {
+            return this.discriminatorFieldDescriptor;
+        }
+
+        if (null != this.superClassDescriptor) {
+            return this.superClassDescriptor.getDiscriminatorFieldDescriptor();
+        }
+
+        return null;        
     }
 
     public boolean hasDiscriminatorField() {
-        return this.discriminatorFieldDescriptor != null;
+        return this.getDiscriminatorFieldDescriptor() != null;
     }
 
     /**
@@ -280,6 +257,11 @@
     public String getJcrName(String fieldName) {
         return (String) this.fieldNames.get(fieldName);
     }
+    
+    public Map getFieldNames()
+    {
+        return this.fieldNames;
+    }
 
     /** Get the JCR node super types.
      *
@@ -342,22 +324,20 @@
      */
     public void afterPropertiesSet() {
         lookupSuperDescriptor();
-
         lookupInheritanceSettings();
-
         validateInheritanceSettings();
     }
 
     private void validateInheritanceSettings() {
         if (NODETYPE_PER_CONCRETECLASS.equals(this.extendsStrategy)) {
-            this.discriminatorFieldDescriptor = findDiscriminatorField();
+            this.discriminatorFieldDescriptor = getDiscriminatorFieldDescriptor();
 
             if (null != this.discriminatorFieldDescriptor) {
                 throw new JcrMappingException("");
             }
         }
         else if (NODETYPE_PER_HIERARCHY.equals(this.extendsStrategy)) {
-            this.discriminatorFieldDescriptor = findDiscriminatorField();
+            this.discriminatorFieldDescriptor = getDiscriminatorFieldDescriptor();
 
             if (null == this.discriminatorFieldDescriptor) {
                 throw new JcrMappingException("");
@@ -365,27 +345,28 @@
         }
     }
 
-    private FieldDescriptor findDiscriminatorField() {
-        if (null != this.discriminatorFieldDescriptor) {
-            return this.discriminatorFieldDescriptor;
-        }
-
-        if (null != this.superClassDescriptor) {
-            return this.superClassDescriptor.findDiscriminatorField();
-        }
 
-        return null;
-    }
 
     private void lookupInheritanceSettings() {
-        if (null != this.superClassDescriptor) {
-            if (this.jcrNodeType.equals(this.superClassDescriptor.jcrNodeType)) {
-                this.extendsStrategy = NODETYPE_PER_HIERARCHY;
-            }
-            else {
-                this.extendsStrategy = NODETYPE_PER_CONCRETECLASS;
-            }
-        }
+//        if (null != this.superClassDescriptor) {
+//            if (this.jcrNodeType.equals(this.superClassDescriptor.jcrNodeType)) {
+//                this.extendsStrategy = NODETYPE_PER_HIERARCHY;
+//            }
+//            else {
+//                this.extendsStrategy = NODETYPE_PER_CONCRETECLASS;
+//            }
+//        }
+    	     if ((null != this.superClassDescriptor) || (this.hasDescendants() ))
+    	     {
+    	    	       if (this.hasDiscriminatorField())
+    	    	       {
+    	    	    	        this.extendsStrategy = NODETYPE_PER_HIERARCHY;
+    	    	       }
+    	    	       else
+    	    	       {
+    	    	    	       this.extendsStrategy = NODETYPE_PER_CONCRETECLASS;
+    	    	       }
+    	     }
     }
 
     private void lookupSuperDescriptor() {
@@ -393,6 +374,9 @@
             this.fieldDescriptors = merge(this.fieldDescriptors, this.superClassDescriptor.getFieldDescriptors());
             this.beanDescriptors = merge(this.beanDescriptors, this.superClassDescriptor.getBeanDescriptors());
             this.collectionDescriptors = merge(this.collectionDescriptors, this.superClassDescriptor.getCollectionDescriptors());
+            this.fieldNames.putAll(this.superClassDescriptor.getFieldNames());
+            
+            
         }
     }
 
@@ -417,12 +401,30 @@
     public ClassDescriptor getSuperClassDescriptor() {
         return superClassDescriptor;
     }
+    
+    public Collection getDescendantClassDescriptors()
+    {
+    	     return this.descendantClassDescriptors;
+    }
+    
+    public void addDescendantClassDescriptor(ClassDescriptor classDescriptor)
+    {
+    	     this.descendantClassDescriptors.add(classDescriptor);
+    	     this.hasDescendant = true;
+    }
+    
+    public boolean hasDescendants()
+    {
+    	    return this.hasDescendant;
+    }
 
     /**
      * @param superClassDescriptor The superClassDescriptor to set.
      */
     public void setSuperClassDescriptor(ClassDescriptor superClassDescriptor) {
         this.superClassDescriptor= superClassDescriptor;
+        superClassDescriptor.addDescendantClassDescriptor(this);
+        
     }
 
     private Map merge(Map existing, Collection superSource) {
@@ -444,4 +446,11 @@
 
         return merged;
     }
+
+	public String toString() {
+		
+		return "Class Descriptor : " +  this.getClassName();
+	}
+    
+    
 }

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/CollectionDescriptor.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/CollectionDescriptor.java?rev=387947&r1=387946&r2=387947&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/CollectionDescriptor.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/CollectionDescriptor.java Wed Mar 22 13:08:49 2006
@@ -262,5 +262,10 @@
     public void setJcrSameNameSiblings(boolean value)
     {
         this.jcrSameNameSiblings = value;
-    }    
+    }
+    
+	public String toString() {
+		
+		return "Collection Descriptor : " +  this.getFieldName();
+	}    
 }

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java?rev=387947&r1=387946&r2=387947&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java Wed Mar 22 13:08:49 2006
@@ -295,4 +295,9 @@
 
         return null;
     }
+    
+	public String toString() {
+		
+		return "Field Descriptor : " +  this.getFieldName();
+	}    
 }

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=387947&r1=387946&r2=387947&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 Wed Mar 22 13:08:49 2006
@@ -238,11 +238,6 @@
 
             ClassDescriptor classDescriptor = getClassDescriptor(clazz);
 
-//            if (classDescriptor.isAbstract()) {
-//                throw new PersistenceException("Cannot fetch declared abstract object of type "
-//                + clazz.getName());
-//            }
-
             checkNodeType(session, classDescriptor);
 
             Node node = (Node) session.getItem(path);
@@ -259,6 +254,7 @@
                 }
                 
                 String className = node.getProperty(discriminatorProperty).getValue().getString();
+                classDescriptor = getClassDescriptor(Class.forName(className));
                 object = ReflectionUtils.newInstance(className);
             }
             else {
@@ -270,7 +266,10 @@
             retrieveCollectionFields(session, classDescriptor, node, object);
 
             return object;
-        }         
+        } 
+        catch(ClassNotFoundException clnf) {
+           	throw new PersistenceException("Impossible to instantiate the object at " + path, clnf);
+        }
         catch(PathNotFoundException pnfe) {
             // HINT should never get here
             throw new PersistenceException("Impossible to get the object at " + path, pnfe);
@@ -402,7 +401,7 @@
                                         ClassDescriptor classDescriptor, 
                                         Node node, 
                                         Object object) {
-       // Object initializedBean = object;
+       Object initializedBean = object;
         try {
             Iterator fieldDescriptorIterator = classDescriptor.getFieldDescriptors().iterator();
     
@@ -413,21 +412,21 @@
                 String propertyName = fieldDescriptor.getJcrName();
     
                 if (fieldDescriptor.isPath()) {
-//                    if (null == initializedBean) { // HINT: lazy initialize target bean
-//                        initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName());
-//                    }
+                    if (null == initializedBean) { // HINT: lazy initialize target bean
+                     initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName());
+                   }
                     
-//                    ReflectionUtils.setNestedProperty(initializedBean, fieldName, node.getPath());
-                	      ReflectionUtils.setNestedProperty(object, fieldName, node.getPath());                 
+                    ReflectionUtils.setNestedProperty(initializedBean, fieldName, node.getPath());
+                 
                 }
                 else if (classDescriptor.usesNodeTypePerHierarchyStrategy() && fieldDescriptor.isDiscriminator()) {                	    
                 	    
                     if (node.hasProperty( classDescriptor.getDiscriminatorFieldDescriptor().getJcrName())) {
-//                        if (null == initializedBean) {
-//                            initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName());
-//                        }
+                        if (null == initializedBean) {
+                            initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName());
+                        }
                         String value = node.getProperty( classDescriptor.getDiscriminatorFieldDescriptor().getJcrName()).getValue().getString();
-                        ReflectionUtils.setNestedProperty(object, fieldName, value);
+                        ReflectionUtils.setNestedProperty(initializedBean, fieldName, value);
                     }
                     else {
                         throw new PersistenceException("Class '" + classDescriptor.getClassName() + "' have not a discriminator property.");
@@ -436,16 +435,16 @@
                 else {
                     if (node.hasProperty(propertyName)) {
                         Value propValue = node.getProperty(propertyName).getValue();
-//                        if (null != propValue && null == initializedBean) { // HINT: lazy initialize target bean
-//                            initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName());
-//                        }
+                        if (null != propValue && null == initializedBean) { // HINT: lazy initialize target bean
+                            initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName());
+                        }
 
                         AtomicTypeConverter converter= getAtomicTypeConverter(fieldDescriptor, 
-                                                                              object, 
+                                                                              initializedBean, 
                                                                               fieldName);
                         
                         Object fieldValue = converter.getObject(propValue);
-                        ReflectionUtils.setNestedProperty(object, fieldName, fieldValue);
+                        ReflectionUtils.setNestedProperty(initializedBean, fieldName, fieldValue);
                     }
                     else
                     {
@@ -470,7 +469,7 @@
                     re);
         }
         
-        return object;
+        return initializedBean;
     }
     
     /**
@@ -487,8 +486,7 @@
             String beanName = beanDescriptor.getFieldName();
             Class beanClass = ReflectionUtils.getPropertyType(object, beanName);
             Object bean = null;
-            if (beanDescriptor.isInline()) {
-            	    bean = ReflectionUtils.newInstance(beanClass);
+            if (beanDescriptor.isInline()) {            	    
                 bean = this.retrieveSimpleFields(session, getClassDescriptor(beanClass), node, bean);
             }
             else if (null != beanDescriptor.getBeanConverter()) {

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/Filter.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/Filter.java?rev=387947&r1=387946&r2=387947&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/Filter.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/Filter.java Wed Mar 22 13:08:49 2006
@@ -78,6 +78,8 @@
 	Filter addIsNull(String arg0);
 	
 	Filter addOrFilter(Filter arg0);
+
+	Filter addAndFilter(Filter filter);
 	
 	Filter addJCRExpression(String jcrExpression);
 	

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/FilterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/FilterImpl.java?rev=387947&r1=387946&r2=387947&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/FilterImpl.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/FilterImpl.java Wed Mar 22 13:08:49 2006
@@ -40,13 +40,11 @@
 
     private Class claszz;
     private String scope = "";
-    private List jcrExpressions = new ArrayList();
+    private String jcrExpression = "";
 
     private ClassDescriptor classDescriptor;
     private Map atomicTypeConverters;
 
-    private String orJcrExpression;
-
     /**
      * Constructor
      *
@@ -95,7 +93,7 @@
                 + "')";
         }
 
-        jcrExpressions.add(jcrExpression);
+        addExpression(jcrExpression);
 
         return this;
     }
@@ -109,7 +107,7 @@
             + " and @" + this.getJcrFieldName(fieldAttributeName) + " <= "
             + this.getStringValue(value2) + ")";
 
-        jcrExpressions.add(jcrExpression);
+        addExpression(jcrExpression);
 
         return this;
     }
@@ -120,7 +118,7 @@
     public Filter addEqualTo(String fieldAttributeName, Object value) {
         String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " = "
             + this.getStringValue(value);
-        jcrExpressions.add(jcrExpression);
+        addExpression(jcrExpression);
 
         return this;
     }
@@ -131,7 +129,7 @@
     public Filter addGreaterOrEqualThan(String fieldAttributeName, Object value) {
         String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " >= "
             + this.getStringValue(value);
-        jcrExpressions.add(jcrExpression);
+        addExpression(jcrExpression);
 
         return this;
     }
@@ -142,7 +140,7 @@
     public Filter addGreaterThan(String fieldAttributeName, Object value) {
         String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " > "
             + this.getStringValue(value);
-        jcrExpressions.add(jcrExpression);
+        addExpression(jcrExpression);
 
         return this;
     }
@@ -153,7 +151,7 @@
     public Filter addLessOrEqualThan(String fieldAttributeName, Object value) {
         String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " <= "
             + this.getStringValue(value);
-        jcrExpressions.add(jcrExpression);
+        addExpression(jcrExpression);
 
         return this;
     }
@@ -164,7 +162,7 @@
     public Filter addLessThan(String fieldAttributeName, Object value) {
         String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " < "
             + this.getStringValue(value);
-        jcrExpressions.add(jcrExpression);
+        addExpression(jcrExpression);
 
         return this;
     }
@@ -175,7 +173,7 @@
     public Filter addLike(String fieldAttributeName, Object value) {
         String jcrExpression = "jcr:like(" + "@" + this.getJcrFieldName(fieldAttributeName) + ", '"
             + value + "')";
-        jcrExpressions.add(jcrExpression);
+        addExpression(jcrExpression);
 
         return this;
     }
@@ -186,7 +184,7 @@
     public Filter addNotEqualTo(String fieldAttributeName, Object value) {
         String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " != "
             + this.getStringValue(value);
-        jcrExpressions.add(jcrExpression);
+        addExpression(jcrExpression);
 
         return this;
     }
@@ -196,7 +194,7 @@
      */
     public Filter addNotNull(String fieldAttributeName) {
         String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName);
-        jcrExpressions.add(jcrExpression);
+        addExpression(jcrExpression);
 
         return this;
     }
@@ -206,7 +204,7 @@
      */
     public Filter addIsNull(String fieldAttributeName) {
         String jcrExpression = "not(@" + this.getJcrFieldName(fieldAttributeName) + ")";
-        jcrExpressions.add(jcrExpression);
+        addExpression(jcrExpression);
 
         return this;
     }
@@ -215,13 +213,36 @@
      * @see org.apache.portals.graffito.jcr.query.Filter#addOrFilter(org.apache.portals.graffito.jcr.query.Filter)
      */
     public Filter addOrFilter(Filter filter) {
-        orJcrExpression = ((FilterImpl) filter).getJcrExpression();
-
+    	   if ( null == jcrExpression || "".equals(jcrExpression) )
+    	   {
+    		   jcrExpression =    ((FilterImpl) filter).getJcrExpression() ;    		   
+    	   }
+    	   else
+    	   {
+    	         jcrExpression =   "(" + jcrExpression + ")  or ( "  +  ((FilterImpl) filter).getJcrExpression() + ")";
+    	   }
         return this;
     }
 
+    /**
+     * @see org.apache.portals.graffito.jcr.query.Filter#addAndFilter(Filter)
+     */
+    public Filter addAndFilter(Filter filter) {
+ 	   if ( null == jcrExpression || "".equals(jcrExpression) )
+	   {
+		   jcrExpression =    ((FilterImpl) filter).getJcrExpression() ;    		   
+	   }
+	   else
+	   {
+	         jcrExpression =   "(" + jcrExpression + ") and  ( "  +  ((FilterImpl) filter).getJcrExpression() + ")";
+	   }
+       return this;
+
+    }
+    
+
     public Filter addJCRExpression(String jcrExpression) {
-        jcrExpressions.add(jcrExpression);
+       addExpression(jcrExpression);
 
         return this;
     }
@@ -244,28 +265,20 @@
     }
 
     public String getJcrExpression() {
-        if ((orJcrExpression == null) || orJcrExpression.equals("")) {
-            return buildJcrExpression();
-        }
-        else {
-            return "(" + buildJcrExpression() + ") or (" + this.orJcrExpression + ")";
-        }
+    	     return this.jcrExpression;
     }
 
-    private String buildJcrExpression() {
-        int count = 1;
-        String jcrExp = "";
-
-        Iterator criteriaIterator = jcrExpressions.iterator();
-        while (criteriaIterator.hasNext()) {
-            if (count > 1) {
-                jcrExp += " and ";
-            }
-            jcrExp += (String) criteriaIterator.next();
-            count++;
-
+    private void addExpression(String jcrExpression) {
+            
+    	     if (this.jcrExpression.length() >0) {
+              	this.jcrExpression += " and ";
         }
-
-        return jcrExp;
+        this.jcrExpression += jcrExpression ;
     }
+
+	public String toString() {
+		return getJcrExpression();
+	}
+    
+   
 }

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java?rev=387947&r1=387946&r2=387947&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java Wed Mar 22 13:08:49 2006
@@ -16,10 +16,12 @@
  */
 package org.apache.portals.graffito.jcr.query.impl;
 
+import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.portals.graffito.jcr.mapper.Mapper;
 import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
+import org.apache.portals.graffito.jcr.mapper.model.FieldDescriptor;
 import org.apache.portals.graffito.jcr.query.Filter;
 import org.apache.portals.graffito.jcr.query.Query;
 import org.apache.portals.graffito.jcr.query.QueryManager;
@@ -51,7 +53,45 @@
 	{
 
 		Filter filter = query.getFilter();
+		
+        // Check if the class has  an inheritance discriminator field		
+		ClassDescriptor classDescriptor = mapper.getClassDescriptor(filter.getFilterClass()); 
+		if (classDescriptor.hasDiscriminatorField())
+		{
+			Filter discrininatorFilter = this.createFilter(query.getFilter().getFilterClass());
+			if ( ! classDescriptor.isAbstract())
+			{
+			    FieldDescriptor fieldDescriptor = classDescriptor.getDiscriminatorFieldDescriptor();
+		        discrininatorFilter.addEqualTo(fieldDescriptor.getFieldName(), filter.getFilterClass().getName());
+			}
+			
+			if (classDescriptor.hasDescendants())
+			{
+				
+			    	
+				Iterator  descendantDescriptorIterator = classDescriptor.getDescendantClassDescriptors().iterator();
+				ClassDescriptor descendantClassDescriptor = (ClassDescriptor)descendantDescriptorIterator.next();
+				FieldDescriptor fieldDescriptor = descendantClassDescriptor.getDiscriminatorFieldDescriptor();
+				 Filter descendantFilter = this.createFilter(query.getFilter().getFilterClass());				 
+				 descendantFilter.addEqualTo(fieldDescriptor.getFieldName(), descendantClassDescriptor.getClassName());
+				 discrininatorFilter = discrininatorFilter.addOrFilter(descendantFilter);
+				 
+				while (descendantDescriptorIterator.hasNext())
+				{
+					 descendantFilter = this.createFilter(query.getFilter().getFilterClass());
 					
+					 descendantClassDescriptor = (ClassDescriptor)descendantDescriptorIterator.next();
+					  fieldDescriptor = descendantClassDescriptor.getDiscriminatorFieldDescriptor();
+					 descendantFilter.addEqualTo(fieldDescriptor.getFieldName(), descendantClassDescriptor.getClassName());
+					 discrininatorFilter =  discrininatorFilter.addOrFilter(descendantFilter);
+				}
+				
+			}
+			
+			
+			 filter = filter.addAndFilter(discrininatorFilter);
+		}
+		
 		String jcrExp = "";
 		
 		// Add scope
@@ -69,6 +109,8 @@
 
         // Add filter criteria
 		String filterExp = ((FilterImpl)filter).getJcrExpression();
+			
+		// Build the jcr filter
 		if ((filterExp != null) && ( ! filterExp.equals("")))
 		{
 		    jcrExp += "[" + filterExp + "]";

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=387947&r1=387946&r2=387947&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 Wed Mar 22 13:08:49 2006
@@ -1,8 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
 <!DOCTYPE graffito-jcr PUBLIC "-//The Apache Software Foundation//DTD Repository//EN" "./src/dtd/graffito-jcr-mapping.dtd">
-<graffito-jcr>
-    
+<graffito-jcr>    
 	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.Ancestor" jcrNodeType="nt:unstructured"  abstract="true" >
 		<field-descriptor fieldName="path" path="true" />
 		<field-descriptor fieldName="ancestorField" jcrName="ancestorField" />
@@ -20,8 +19,10 @@
 
 	</class-descriptor>
 
+	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.SubDescendant" jcrNodeType="nt:unstructured" 
+	                                   extends="org.apache.portals.graffito.jcr.testmodel.inheritance.Descendant"  >                               
+		<field-descriptor fieldName="subDescendantField" jcrName="subDescendantField" />  
 
-
-
+	</class-descriptor>
 </graffito-jcr>
  

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping.xml
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping.xml?rev=387947&r1=387946&r2=387947&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping.xml (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping.xml Wed Mar 22 13:08:49 2006
@@ -58,8 +58,8 @@
 		<field-descriptor fieldName="b1" jcrName="b1" jcrType="String" jcrAutoCreated="false" jcrMandatory="false"
         jcrOnParentVersion="IGNORE" jcrProtected="false" jcrMultiple="false" />
 		
-        <field-descriptor fieldName="b2" jcrName="b2" jcrType="String" jcrAutoCreated="true" jcrMandatory="true"
-        jcrOnParentVersion="COPY" jcrProtected="true" jcrMultiple="true" />
+        <field-descriptor fieldName="b2" jcrName="b2" jcrType="String" jcrAutoCreated="false" jcrMandatory="false"
+        jcrOnParentVersion="IGNORE" jcrProtected="false" jcrMultiple="false" />
 
 	</class-descriptor>
 

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java?rev=387947&r1=387946&r2=387947&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java Wed Mar 22 13:08:49 2006
@@ -30,6 +30,8 @@
 import java.util.Map;
 
 import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
 import javax.jcr.Repository;
 import javax.jcr.Session;
 import javax.jcr.UnsupportedRepositoryOperationException;
@@ -39,6 +41,8 @@
 
 import junit.framework.TestCase;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException;
 import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
 import org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl;
@@ -60,6 +64,7 @@
 import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl.TimestampTypeConverterImpl;
 import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl.UtilDateTypeConverterImpl;
 import org.apache.portals.graffito.jcr.persistence.impl.PersistenceManagerImpl;
+import org.apache.portals.graffito.jcr.persistence.impl.PersistenceManagerSimpleInheritanceTest;
 import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
 import org.apache.portals.graffito.jcr.persistence.objectconverter.impl.ObjectConverterImpl;
 import org.apache.portals.graffito.jcr.query.QueryManager;
@@ -78,6 +83,8 @@
 public abstract class TestBase extends TestCase
 {
 
+	private final static Log log = LogFactory.getLog(TestBase.class);
+	
 	protected Session session;
 
 	private PersistenceManager persistenceManager;
@@ -249,5 +256,29 @@
 	{
 		return this.queryManager;
 	}
+	
+	public void cleanUpRepisotory() {
+		try 
+		{
+				Session session = this.getSession();		
+				NodeIterator nodeIterator = session.getRootNode().getNodes();
+		
+				while (nodeIterator.hasNext())
+				{
+					Node node = nodeIterator.nextNode();
+					if (! node.getName().startsWith("jcr:"))
+					{
+					    log.debug("tearDown - remove : " + node.getPath());
+					    node.remove();
+					}
+				}
+				session.save();
+		}
+		catch(Exception e)
+		{
+			e.printStackTrace();
+		}
+	}
+
 
 }

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java?rev=387947&r1=387946&r2=387947&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java Wed Mar 22 13:08:49 2006
@@ -16,6 +16,8 @@
  */
 package org.apache.portals.graffito.jcr.mapper;
 
+import java.util.Collection;
+
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -31,6 +33,7 @@
 import org.apache.portals.graffito.jcr.testmodel.B;
 import org.apache.portals.graffito.jcr.testmodel.inheritance.Ancestor;
 import org.apache.portals.graffito.jcr.testmodel.inheritance.Descendant;
+import org.apache.portals.graffito.jcr.testmodel.inheritance.SubDescendant;
 
 /**
  * Test Mapper
@@ -62,6 +65,8 @@
     {
         try
         {
+
+    		
             Mapper mapper = new DigesterMapperImpl("./src/test-config/jcrmapping-testmappings.xml")
                 .buildMapper();
             assertNotNull("Mapper is null", mapper);
@@ -126,11 +131,11 @@
             assertNotNull("FieldDescriptor is null", b2Field);
             assertEquals(b2Field.getFieldName(), "b2");
             assertEquals(b2Field.getJcrType(), "String");
-            assertTrue(b2Field.isJcrAutoCreated());
-            assertTrue(b2Field.isJcrMandatory());
-            assertTrue(b2Field.isJcrProtected());
-            assertTrue(b2Field.isJcrMultiple());
-            assertEquals(b2Field.getJcrOnParentVersion(), "COPY");
+            assertFalse(b2Field.isJcrAutoCreated());
+            assertFalse(b2Field.isJcrMandatory());
+            assertFalse(b2Field.isJcrProtected());
+            assertFalse(b2Field.isJcrMultiple());
+            assertEquals(b2Field.getJcrOnParentVersion(), "IGNORE");
             
             ClassDescriptor classDescriptor2 = mapper.getClassDescriptor(A.class);
             assertNotNull("ClassDescriptor is null", classDescriptor2);
@@ -170,24 +175,58 @@
     {
         try
         {
-            Mapper mapper = new DigesterMapperImpl("./src/test-config/jcrmapping-inheritance.xml").buildMapper();
+    		String[] files = { "./src/test-config/jcrmapping.xml", 
+                    "./src/test-config/jcrmapping-atomic.xml",
+                    "./src/test-config/jcrmapping-beandescriptor.xml",
+                    "./src/test-config/jcrmapping-inheritance.xml"};
+    		    Mapper mapper = new DigesterMapperImpl(files) .buildMapper();            	
+           
             assertNotNull("Mapper is null", mapper);
             
             ClassDescriptor classDescriptor = mapper.getClassDescriptor(Ancestor.class);
-            assertNotNull("Mapper is null", classDescriptor);
+            assertNotNull("Classdescriptor is null", classDescriptor);
             assertEquals("Incorrect path field", classDescriptor.getPathFieldDescriptor().getFieldName(), "path");
             assertEquals("Incorrect discriminator field", classDescriptor.getDiscriminatorFieldDescriptor().getFieldName(), "discriminator");
+            assertTrue("The ancestor class has no discriminator", classDescriptor.hasDiscriminatorField());
             assertTrue("The ancestor class is not abstract", classDescriptor.isAbstract());
             assertNull("The ancestor class has an ancestor", classDescriptor.getSuperClassDescriptor());
+            assertEquals("Incorrect JcrName", classDescriptor.getJcrName("discriminator"),"discriminator");
+            assertTrue("Ancestor class doesn't have a node type per hierarchy strategy", classDescriptor.usesNodeTypePerHierarchyStrategy());
+            assertFalse("Ancestor class  have a node type per hierarchy strategy", classDescriptor.usesNodeTypePerConcreteClassStrategy());
+            
+            Collection descendandDescriptors = classDescriptor.getDescendantClassDescriptors();
+            assertEquals("Invalid number of descendants", descendandDescriptors.size(), 2);
             
             classDescriptor = mapper.getClassDescriptor(Descendant.class);
-            assertNotNull("Mapper is null", classDescriptor);
+            assertNotNull("Classdescriptor is null", classDescriptor);
             assertEquals("Incorrect path field", classDescriptor.getPathFieldDescriptor().getFieldName(), "path");
             assertEquals("Incorrect discriminator field", classDescriptor.getDiscriminatorFieldDescriptor().getFieldName(), "discriminator");
+            assertTrue("The descendant  class has no discriminator", classDescriptor.hasDiscriminatorField());
             assertNotNull("ancerstorField is null in the descendant class", classDescriptor.getFieldDescriptor("ancestorField"));
             assertFalse("The descendant class is abstract", classDescriptor.isAbstract());
             assertNotNull("The descendant class has not an ancestor", classDescriptor.getSuperClassDescriptor());
             assertEquals("Invalid ancestor class for the descendant class", classDescriptor.getSuperClassDescriptor().getClassName(), "org.apache.portals.graffito.jcr.testmodel.inheritance.Ancestor");
+            assertEquals("Incorrect JcrName", classDescriptor.getJcrName("discriminator"),"discriminator");
+             descendandDescriptors = classDescriptor.getDescendantClassDescriptors();
+            assertEquals("Invalid number of descendants", descendandDescriptors.size(), 1);
+            assertTrue("Descendant  class doesn't have a node type per hierarchy strategy", classDescriptor.usesNodeTypePerHierarchyStrategy());
+            assertFalse("Descendant class  have a node type per hierarchy strategy", classDescriptor.usesNodeTypePerConcreteClassStrategy());
+
+            
+            classDescriptor = mapper.getClassDescriptor(SubDescendant.class);
+            assertNotNull("Classdescriptor is null", classDescriptor);
+            assertEquals("Incorrect path field", classDescriptor.getPathFieldDescriptor().getFieldName(), "path");
+            assertEquals("Incorrect discriminator field", classDescriptor.getDiscriminatorFieldDescriptor().getFieldName(), "discriminator");
+            assertTrue("The subdescendant  class has no discriminator", classDescriptor.hasDiscriminatorField());
+            assertNotNull("ancestorField is null in the descendant class", classDescriptor.getFieldDescriptor("ancestorField"));
+            assertFalse("The subdescendant class is abstract", classDescriptor.isAbstract());
+            assertNotNull("The subdescendant class has not an ancestor", classDescriptor.getSuperClassDescriptor());
+            assertEquals("Invalid ancestor class for the descendant class", classDescriptor.getSuperClassDescriptor().getClassName(), "org.apache.portals.graffito.jcr.testmodel.inheritance.Descendant");
+            assertEquals("Incorrect JcrName", classDescriptor.getJcrName("discriminator"),"discriminator");
+             descendandDescriptors = classDescriptor.getDescendantClassDescriptors();
+            assertEquals("Invalid number of descendants", descendandDescriptors.size(), 0);
+            assertTrue("SubDescendant  class doesn't have a node type per hierarchy strategy", classDescriptor.usesNodeTypePerHierarchyStrategy());
+            assertFalse("SubDescendant class  have a node type per hierarchy strategy", classDescriptor.usesNodeTypePerConcreteClassStrategy());
             
         }
         catch (JcrMappingException e)

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerSimpleInheritanceTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerSimpleInheritanceTest.java?rev=387947&r1=387946&r2=387947&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerSimpleInheritanceTest.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerSimpleInheritanceTest.java Wed Mar 22 13:08:49 2006
@@ -16,11 +16,11 @@
  */
 package org.apache.portals.graffito.jcr.persistence.impl;
 
-import java.io.ByteArrayInputStream;
-import java.sql.Timestamp;
-import java.util.Calendar;
 import java.util.Collection;
-import java.util.Date;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Session;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -34,11 +34,9 @@
 import org.apache.portals.graffito.jcr.query.Query;
 import org.apache.portals.graffito.jcr.query.QueryManager;
 import org.apache.portals.graffito.jcr.testmodel.Atomic;
-import org.apache.portals.graffito.jcr.testmodel.Paragraph;
 import org.apache.portals.graffito.jcr.testmodel.inheritance.Ancestor;
 import org.apache.portals.graffito.jcr.testmodel.inheritance.AnotherDescendant;
 import org.apache.portals.graffito.jcr.testmodel.inheritance.Descendant;
-import org.apache.portals.graffito.jcr.testmodel.inheritance.Folder;
 
 /**
  * Test inheritance with node type per hierarchy stategy (with discreminator field)
@@ -65,9 +63,12 @@
 
 	public void tearDown() throws Exception {
 
+		cleanUpRepisotory();
 		super.tearDown();
+		
 	}
 
+
 	public void testRetrieveSingleton() {
 
 		try {
@@ -109,12 +110,20 @@
 			assertEquals("Descendant descendantField is invalid", descendant	.getDescendantField(), "descendantValue");
 
 
-// UNCOMMENT
-//			Ancestor ancestor = (Ancestor) persistenceManager.getObject(Ancestor.class,"/test");
-//			assertTrue("Invalid object instance", ancestor instanceof Descendant );
-//		    assertEquals("ancestor path is invalid", ancestor.getPath(), "/test");
-//   		    assertEquals("Desancestorcendant ancestorField is invalid", ancestor.getAncestorField(), "ancestorValue");
 
+			Ancestor ancestor = (Ancestor) persistenceManager.getObject(Ancestor.class,"/test");
+			assertTrue("Invalid object instance", ancestor instanceof Descendant );
+			assertEquals("Ancestor  path is invalid", ancestor.getPath(), "/test");
+			assertEquals("Ancestor ancestorField is invalid", ancestor.getAncestorField(), "anotherAncestorValue");
+			
+			
+			//---------------------------------------------------------------------------------------------------------
+			// Remove Descendant
+			//---------------------------------------------------------------------------------------------------------						
+//			persistenceManager.remove("/test");
+//			persistenceManager.save();
+			
+			
 		} catch (Exception e) {
 			e.printStackTrace();
 			fail();
@@ -122,7 +131,7 @@
 
 	}
 
-	/*
+	
 	public void testRetrieveCollection() {
 		PersistenceManager persistenceManager = this.getPersistenceManager();
 
@@ -154,7 +163,7 @@
 		persistenceManager.insert(anotherDescendant);
 
 		anotherDescendant = new AnotherDescendant();
-		anotherDescendant.setAnotherDescendantField("anotherDescendantValue");
+		anotherDescendant.setAnotherDescendantField("anotherDescendantValue2");
 		anotherDescendant.setAncestorField("ancestorValue5");
 		anotherDescendant.setPath("/anotherdescendant3");
 		persistenceManager.insert(anotherDescendant);
@@ -166,6 +175,9 @@
 
 		persistenceManager.save();
 
+		//---------------------------------------------------------------------------------------------------------	
+		// Retrieve Descendant class
+		//---------------------------------------------------------------------------------------------------------			
 		QueryManager queryManager = persistenceManager.getQueryManager();
 		Filter filter = queryManager.createFilter(Descendant.class);
 		Query query = queryManager.createQuery(filter);
@@ -173,7 +185,36 @@
 		Collection result = persistenceManager.getObjects(query);
 		assertEquals("Invalid number of Descendant found", result.size(), 2);
 
+		//---------------------------------------------------------------------------------------------------------	
+		// Retrieve AnotherDescendant class
+		//---------------------------------------------------------------------------------------------------------			
+		queryManager = persistenceManager.getQueryManager();
+		filter = queryManager.createFilter(AnotherDescendant.class);
+		filter.addEqualTo("anotherDescendantField", "anotherDescendantValue");
+		query = queryManager.createQuery(filter);
+
+		result = persistenceManager.getObjects(query);
+		assertEquals("Invalid number of AnotherDescendant found", result.size(),2);
+		
+		//---------------------------------------------------------------------------------------------------------	
+		// Retrieve AnotherDescendant class
+		//---------------------------------------------------------------------------------------------------------			
+		queryManager = persistenceManager.getQueryManager();
+		filter = queryManager.createFilter(Ancestor.class);		
+		query = queryManager.createQuery(filter);
+
+		result = persistenceManager.getObjects(query);
+		assertEquals("Invalid ancestor object found", result.size(),5);
+		
+		
+//		persistenceManager.remove("/descendant1");
+//		persistenceManager.remove("/descendant2");
+//		persistenceManager.remove("/anotherdescendant1");
+//		persistenceManager.remove("/anotherdescendant2");
+//		persistenceManager.remove("/anotherdescendant3");
+//		persistenceManager.remove("/atomic");
+//		persistenceManager.save();
 	}
-	*/
+	
 
 }

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/BeanDescriptorTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/BeanDescriptorTest.java?rev=387947&r1=387946&r2=387947&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/BeanDescriptorTest.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/BeanDescriptorTest.java Wed Mar 22 13:08:49 2006
@@ -86,7 +86,7 @@
     }
     
     public void testInlined() throws Exception {
-        System.out.println(".inlined");
+        System.out.println("inlined");
         
         B expB = new B();
         expB.setB1("b1value");
@@ -103,13 +103,13 @@
         
         assertEquals(expD.getD1(), actD.getD1());
         assertEquals(expB.getB1(), actD.getB1().getB1());
-        assertNull("B.b2 is protected", actD.getB1().getB2());
+        assertEquals(expB.getB2(), actD.getB1().getB2());
         
         DFull actDFull = (DFull) this.objectConverter.getObject(getSession(), DFull.class, "/someD");
         
         assertEquals(expD.getD1(), actDFull.getD1());
         assertEquals(expB.getB1(), actDFull.getB1());
-        assertNull("B.b2 is protected", actDFull.getB2());
+        assertEquals(expB.getB2(), actDFull.getB2());
         
         expB.setB1("updatedvalue1");
         
@@ -120,34 +120,29 @@
         
         assertEquals(expD.getD1(), actD.getD1());
         assertEquals(expB.getB1(), actD.getB1().getB1());
-        assertNull("B.b2 is protected", actD.getB1().getB2());
+        assertEquals(expB.getB2(), actD.getB1().getB2());
         
         actDFull = (DFull) this.objectConverter.getObject(getSession(), DFull.class, "/someD");
         
         assertEquals(expD.getD1(), actDFull.getD1());
         assertEquals(expB.getB1(), actDFull.getB1());
-        assertNull("B.b2 is protected", actDFull.getB2());
+        assertEquals(expB.getB2(), actDFull.getB2());
         
-//  Comment from Christophe : 
-// The following code breaks the unit test : D has an inner bean (b1) which contains a protected field (b2) . If b1 is set to null, 
-//        it is not possible to drop the inner bean because property  b2 is never set to null
-//   I'm wondering why to authorize a null value to a inner bean if this one contains a mandatory/protected property
-        
-        
-//        expD.setB1(null);
-//        this.objectConverter.update(getSession(), expD);
-//        getSession().save();
-//        
-//        actD = (D) this.objectConverter.getObject(getSession(), D.class, "/someD");
-//        
-//        assertEquals(expD.getD1(), actD.getD1());
-//        assertNull("b1 was removed", actD.getB1());
-//        
-//        actDFull = (DFull) this.objectConverter.getObject(getSession(), DFull.class, "/someD");
-//        
-//        assertEquals(expD.getD1(), actDFull.getD1());
-//        assertNull("b1 was removed", actDFull.getB1());
-//        assertNull("B.b2 is protected", actDFull.getB2());
+            
+        expD.setB1(null);
+        this.objectConverter.update(getSession(), expD);
+        getSession().save();
+        
+        actD = (D) this.objectConverter.getObject(getSession(), D.class, "/someD");
+        
+        assertEquals(expD.getD1(), actD.getD1());
+        assertNull("b1 was not  removed", actD.getB1());
+        
+        actDFull = (DFull) this.objectConverter.getObject(getSession(), DFull.class, "/someD");
+        
+        assertEquals(expD.getD1(), actDFull.getD1());
+        assertNull("b1 was not  removed", actDFull.getB1());
+        assertNull("b2 wan not remove", actDFull.getB2());
 
     }
     

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/SubDescendant.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/SubDescendant.java?rev=387947&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/SubDescendant.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/SubDescendant.java Wed Mar 22 13:08:49 2006
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2000-2004 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.testmodel.inheritance;
+
+public class SubDescendant extends Descendant {
+
+	protected String subDescendantField;
+
+	public String getSubDescendantField() {
+		return subDescendantField;
+	}
+
+	public void setSubDescendantField(String subDescendantField) {
+		this.subDescendantField = subDescendantField;
+	}
+
+	
+}



Mime
View raw message