You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by an...@apache.org on 2009/11/24 21:29:56 UTC

svn commit: r883858 [1/2] - in /cayenne/main/trunk/framework: cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/r...

Author: andrey
Date: Tue Nov 24 20:29:54 2009
New Revision: 883858

URL: http://svn.apache.org/viewvc?rev=883858&view=rev
Log:
CAY-1230 Refactoring & unification of "ROP" and "classic" class groups
Changing ROP event processing

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ToManyMap.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/Cayenne.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectCollection.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/Continent.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/Country.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/auto/_Continent.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/auto/_Country.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/LightSuperClassTest.java
    cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/light-superclass.vm
Removed:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextGraphAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/PropertyChangeProcessingStrategy.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContextGraphAction.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/BaseContext.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContext.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextChildDiffLoader.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextGraphManager.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextMergeHandler.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneDataObject.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/PersistentObject.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContext.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ToManyMapFault.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/BaseToManyProperty.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ToManyProperty.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/generic/DataObjectToManyProperty.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoMapProperty.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderMapProperty.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/ObjectContextGraphAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectHolder.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectList.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectMap.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectSet.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/testmap.map.xml
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CodeTemplateManager.java
    cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/BaseContext.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/BaseContext.java?rev=883858&r1=883857&r2=883858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/BaseContext.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/BaseContext.java Tue Nov 24 20:29:54 2009
@@ -44,6 +44,7 @@
 import org.apache.cayenne.reflect.PropertyVisitor;
 import org.apache.cayenne.reflect.ToManyProperty;
 import org.apache.cayenne.reflect.ToOneProperty;
+import org.apache.cayenne.util.ObjectContextGraphAction;
 
 /**
  * A common base superclass for Cayenne ObjectContext implementors.
@@ -92,6 +93,12 @@
     // reinjected later if needed
     protected transient DataChannel channel;
     protected QueryCache queryCache;
+    
+    /**
+     * Graph action that handles property changes
+     * @since 3.1
+     */
+    protected ObjectContextGraphAction graphAction;
 
     /**
      * Stores user defined properties associated with this DataContext.
@@ -99,6 +106,10 @@
      * @since 3.0
      */
     protected Map<String, Object> userProperties;
+    
+    protected BaseContext() {
+        graphAction = new ObjectContextGraphAction(this);
+    }
 
     public abstract void commitChanges();
 
@@ -232,11 +243,14 @@
         }
     }
 
-    public abstract void propertyChanged(
+    public void propertyChanged(
             Persistent object,
             String property,
             Object oldValue,
-            Object newValue);
+            Object newValue) {
+
+        graphAction.handlePropertyChange(object, property, oldValue, newValue);
+    }
 
     public abstract void rollbackChanges();
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContext.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContext.java?rev=883858&r1=883857&r2=883858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContext.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContext.java Tue Nov 24 20:29:54 2009
@@ -45,27 +45,10 @@
  */
 public class CayenneContext extends BaseContext {
 
-    /**
-     * @since 3.0
-     */
-    private static ThreadLocal<PropertyChangeProcessingStrategy> PROPERTY_CHANGE_PROCESSING_STRATEGY = new ThreadLocal<PropertyChangeProcessingStrategy>() {
-
-        @Override
-        protected PropertyChangeProcessingStrategy initialValue() {
-            return PropertyChangeProcessingStrategy.RECORD_AND_PROCESS_REVERSE_ARCS;
-        }
-    };
-
     protected EntityResolver entityResolver;
 
     CayenneContextGraphManager graphManager;
 
-    // note that it is important to reuse the same action within the property change
-    // thread to avoid a loop of "propertyChange" calls on handling reverse relationships.
-    // Here we go further and make action a thread-safe ivar that tracks its own thread
-    // state.
-    CayenneContextGraphAction graphAction;
-
     // object that merges "backdoor" changes that come from the channel.
     CayenneContextMergeHandler mergeHandler;
 
@@ -92,8 +75,7 @@
      */
     public CayenneContext(DataChannel channel, boolean changeEventsEnabled,
             boolean syncEventsEnabled) {
-
-        this.graphAction = new CayenneContextGraphAction(this);
+        
         this.graphManager = new CayenneContextGraphManager(
                 this,
                 changeEventsEnabled,
@@ -103,24 +85,6 @@
     }
 
     /**
-     * @since 3.0
-     */
-    // accesses a static thread local variable... still keeping the method non-static for
-    // better future portability...
-    PropertyChangeProcessingStrategy getPropertyChangeProcessingStrategy() {
-        return PROPERTY_CHANGE_PROCESSING_STRATEGY.get();
-    }
-
-    /**
-     * @since 3.0
-     */
-    // accesses a static thread local variable... still keeping the method non-static for
-    // better future portability...
-    void setPropertyChangeProcessingStrategy(PropertyChangeProcessingStrategy strategy) {
-        PROPERTY_CHANGE_PROCESSING_STRATEGY.set(strategy);
-    }
-
-    /**
      * Sets the context channel, setting up a listener for channel events.
      */
     public void setChannel(DataChannel channel) {
@@ -198,10 +162,6 @@
         return graphManager;
     }
 
-    CayenneContextGraphAction internalGraphAction() {
-        return graphAction;
-    }
-
     /**
      * Commits changes to uncommitted objects. First checks if there are changes in this
      * context and if any changes are detected, sends a commit message to remote Cayenne
@@ -451,18 +411,6 @@
     }
 
     @Override
-    public void propertyChanged(
-            Persistent object,
-            String property,
-            Object oldValue,
-            Object newValue) {
-
-        if (getPropertyChangeProcessingStrategy() != PropertyChangeProcessingStrategy.IGNORE) {
-            graphAction.handlePropertyChange(object, property, oldValue, newValue);
-        }
-    }
-
-    @Override
     public Collection<?> uncommittedObjects() {
         synchronized (graphManager) {
             return graphManager.dirtyNodes();
@@ -549,13 +497,13 @@
 
         if (childContext) {
 
-            PropertyChangeProcessingStrategy oldStrategy = getPropertyChangeProcessingStrategy();
-            setPropertyChangeProcessingStrategy(PropertyChangeProcessingStrategy.RECORD);
+//            PropertyChangeProcessingStrategy oldStrategy = getPropertyChangeProcessingStrategy();
+//            setPropertyChangeProcessingStrategy(PropertyChangeProcessingStrategy.RECORD);
             try {
                 changes.apply(new CayenneContextChildDiffLoader(this));
             }
             finally {
-                setPropertyChangeProcessingStrategy(oldStrategy);
+//                setPropertyChangeProcessingStrategy(oldStrategy);
             }
             
             fireDataChannelChanged(originatingContext, changes);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextChildDiffLoader.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextChildDiffLoader.java?rev=883858&r1=883857&r2=883858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextChildDiffLoader.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextChildDiffLoader.java Tue Nov 24 20:29:54 2009
@@ -67,40 +67,22 @@
                 ((ObjectId) nodeId).getEntityName());
         ArcProperty property = (ArcProperty) descriptor.getProperty(arcId.toString());
 
-        // TODO: context strategy reset here still hides the difference between to-one and
-        // to-many per CAY-1204... hopefully it will go away if we do refactoring around
-        // property change strategy instead of using "changeX vs. changeXDirectly".
-        PropertyChangeProcessingStrategy oldStrategy = ((CayenneContext) context)
-                .getPropertyChangeProcessingStrategy();
-        ((CayenneContext) context)
-                .setPropertyChangeProcessingStrategy(PropertyChangeProcessingStrategy.IGNORE);
-        try {
-            property.visit(new PropertyVisitor() {
-
-                public boolean visitAttribute(AttributeProperty property) {
-                    return false;
-                }
-
-                public boolean visitToMany(ToManyProperty property) {
-                    // connect reverse arc if the relationship is marked as "runtime"
-                    ArcProperty reverseArc = property.getComplimentaryReverseArc();
-                    boolean autoConnectReverse = reverseArc != null
-                            && reverseArc.getRelationship().isRuntime();
-
-                    property.addTarget(source, target, autoConnectReverse);
-                    return false;
-                }
-
-                public boolean visitToOne(ToOneProperty property) {
-                    property.setTarget(source, target, false);
-                    return false;
-                }
-            });
-        }
-        finally {
-            ((CayenneContext) context).setPropertyChangeProcessingStrategy(oldStrategy);
-        }
+        property.visit(new PropertyVisitor() {
 
+            public boolean visitAttribute(AttributeProperty property) {
+                return false;
+            }
+
+            public boolean visitToMany(ToManyProperty property) {
+                property.addTargetDirectly(source, target);
+                return false;
+            }
+
+            public boolean visitToOne(ToOneProperty property) {
+                property.setTarget(source, target, false);
+                return false;
+            }
+        });
         context.propertyChanged(source, (String) arcId, null, target);
     }
 
@@ -118,58 +100,43 @@
                 ((ObjectId) nodeId).getEntityName());
         Property property = descriptor.getProperty(arcId.toString());
 
-        // TODO: context strategy reset here still hides the difference between to-one and
-        // to-many per CAY-1204... hopefully it will go away if we do refactoring around
-        // property change strategy instead of using "changeX vs. changeXDirectly".
-        PropertyChangeProcessingStrategy oldStrategy = ((CayenneContext) context)
-                .getPropertyChangeProcessingStrategy();
-        ((CayenneContext) context)
-                .setPropertyChangeProcessingStrategy(PropertyChangeProcessingStrategy.IGNORE);
         final Persistent[] target = new Persistent[1];
         target[0] = findObject(targetNodeId);
         
-        try {
-            property.visit(new PropertyVisitor() {
+        property.visit(new PropertyVisitor() {
 
-                public boolean visitAttribute(AttributeProperty property) {
-                    return false;
-                }
+            public boolean visitAttribute(AttributeProperty property) {
+                return false;
+            }
 
-                public boolean visitToMany(ToManyProperty property) {
-                    // connect reverse arc if the relationship is marked as "runtime"
-                    ArcProperty reverseArc = property.getComplimentaryReverseArc();
-                    boolean autoConnectReverse = reverseArc != null
-                            && reverseArc.getRelationship().isRuntime();
-
-                    if (target[0] == null) {
-
-                        // this is usually the case when a NEW object was deleted and then
-                        // its relationships were manipulated; so try to locate the object
-                        // in the collection ... the performance of this is rather dubious
-                        // of course...
-                        target[0] = findObjectInCollection(targetNodeId, property
-                                .readProperty(source));
-                    }
-
-                    if (target[0] == null) {
-                        // ignore?
-                    }
-                    else {
-                        property.removeTarget(source, target[0], autoConnectReverse);
-                    }
+            public boolean visitToMany(ToManyProperty property) {
+                ArcProperty reverseArc = property.getComplimentaryReverseArc();
+                
+                if (target[0] == null) {
 
-                    return false;
+                    // this is usually the case when a NEW object was deleted and then
+                    // its relationships were manipulated; so try to locate the object
+                    // in the collection ... the performance of this is rather dubious
+                    // of course...
+                    target[0] = findObjectInCollection(targetNodeId, property
+                            .readProperty(source));
                 }
 
-                public boolean visitToOne(ToOneProperty property) {
-                    property.setTarget(source, null, false);
-                    return false;
+                if (target[0] == null) {
+                    // ignore?
                 }
-            });
-        }
-        finally {
-            ((CayenneContext) context).setPropertyChangeProcessingStrategy(oldStrategy);
-        }
+                else {
+                    property.removeTargetDirectly(source, target[0]);
+                }
+
+                return false;
+            }
+
+            public boolean visitToOne(ToOneProperty property) {
+                property.setTarget(source, null, false);
+                return false;
+            }
+        });
 
         context.propertyChanged(source, (String) arcId, target[0], null);
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextGraphManager.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextGraphManager.java?rev=883858&r1=883857&r2=883858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextGraphManager.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextGraphManager.java Tue Nov 24 20:29:54 2009
@@ -157,39 +157,28 @@
 
         EntityResolver resolver = context.getEntityResolver();
 
-        // avoid processing callbacks when updating the map...
-        PropertyChangeProcessingStrategy oldChangeStrategy = context
-                .getPropertyChangeProcessingStrategy();
-        context
-                .setPropertyChangeProcessingStrategy(PropertyChangeProcessingStrategy.IGNORE);
-
-        try {
-            while (it.hasNext()) {
-                ObjectId id = (ObjectId) it.next();
-                ClassDescriptor descriptor = resolver.getClassDescriptor(id
-                        .getEntityName());
-
-                Iterator<ArcProperty> mapArcProperties = descriptor.getMapArcProperties();
-                if (mapArcProperties.hasNext()) {
-
-                    Object object = getNode(id);
-
-                    while (mapArcProperties.hasNext()) {
-                        ArcProperty arc = mapArcProperties.next();
-                        ToManyMapProperty reverseArc = (ToManyMapProperty) arc
-                                .getComplimentaryReverseArc();
-
-                        Object source = arc.readPropertyDirectly(object);
-                        if (source != null && !reverseArc.isFault(source)) {
-                            remapTarget(reverseArc, source, object);
-                        }
+        while (it.hasNext()) {
+            ObjectId id = (ObjectId) it.next();
+            ClassDescriptor descriptor = resolver.getClassDescriptor(id
+                    .getEntityName());
+
+            Iterator<ArcProperty> mapArcProperties = descriptor.getMapArcProperties();
+            if (mapArcProperties.hasNext()) {
+
+                Object object = getNode(id);
+
+                while (mapArcProperties.hasNext()) {
+                    ArcProperty arc = mapArcProperties.next();
+                    ToManyMapProperty reverseArc = (ToManyMapProperty) arc
+                            .getComplimentaryReverseArc();
+
+                    Object source = arc.readPropertyDirectly(object);
+                    if (source != null && !reverseArc.isFault(source)) {
+                        remapTarget(reverseArc, source, object);
                     }
                 }
             }
         }
-        finally {
-            context.setPropertyChangeProcessingStrategy(oldChangeStrategy);
-        }
     }
 
     // clone of DataDomainSyncBucket.remapTarget

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextMergeHandler.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextMergeHandler.java?rev=883858&r1=883857&r2=883858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextMergeHandler.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextMergeHandler.java Tue Nov 24 20:29:54 2009
@@ -187,17 +187,15 @@
             target = context.createFault((ObjectId) targetNodeId);
         }
 
-        context.internalGraphAction().setArcChangeInProcess(true);
         try {
             if (p instanceof ToManyProperty) {
-                ((ToManyProperty) p).addTarget(source, target, false);
+                ((ToManyProperty) p).addTargetDirectly(source, target);
             }
             else {
                 p.writePropertyDirectly(source, null, target);
             }
         }
         finally {
-            context.internalGraphAction().setArcChangeInProcess(false);
         }
     }
 
@@ -223,17 +221,15 @@
             target = context.createFault((ObjectId) targetNodeId);
         }
 
-        context.internalGraphAction().setArcChangeInProcess(true);
         try {
             if (p instanceof ToManyProperty) {
-                ((ToManyProperty) p).removeTarget(source, target, false);
+                ((ToManyProperty) p).removeTargetDirectly(source, target);
             }
             else {
                 p.writePropertyDirectly(source, target, null);
             }
         }
         finally {
-            context.internalGraphAction().setArcChangeInProcess(false);
         }
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneDataObject.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneDataObject.java?rev=883858&r1=883857&r2=883858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneDataObject.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneDataObject.java Tue Nov 24 20:29:54 2009
@@ -23,14 +23,11 @@
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.lang.reflect.Array;
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.StringTokenizer;
 
 import org.apache.cayenne.conf.Configuration;
 import org.apache.cayenne.map.DbAttribute;
@@ -41,7 +38,7 @@
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
-import org.apache.cayenne.reflect.PropertyUtils;
+import org.apache.cayenne.util.Cayenne;
 import org.apache.cayenne.validation.BeanValidationFailure;
 import org.apache.cayenne.validation.ValidationFailure;
 import org.apache.cayenne.validation.ValidationResult;
@@ -69,116 +66,51 @@
         }
     }
 
-    public Object readNestedProperty(String path) {
-        return readNestedProperty(this, path, tokenizePath(path), 0, 0);
-    }
-
     /**
-     * Recursively resolves nested property path
+     * Returns a value of the property identified by a property path. Supports reading
+     * both mapped and unmapped properties. Unmapped properties are accessed in a manner
+     * consistent with JavaBeans specification.
+     * <p>
+     * Property path (or nested property) is a dot-separated path used to traverse object
+     * relationships until the final object is found. If a null object found while
+     * traversing path, null is returned. If a list is encountered in the middle of the
+     * path, CayenneRuntimeException is thrown. Unlike
+     * {@link #readPropertyDirectly(String)}, this method will resolve an object if it is
+     * HOLLOW.
+     * <p>
+     * Examples:
+     * </p>
+     * <ul>
+     * <li>Read this object property:<br>
+     * <code>String name = (String)artist.readNestedProperty("name");</code><br>
+     * <br>
+     * </li>
+     * <li>Read an object related to this object:<br>
+     * <code>Gallery g = (Gallery)paintingInfo.readNestedProperty("toPainting.toGallery");</code>
+     * <br>
+     * <br>
+     * </li>
+     * <li>Read a property of an object related to this object: <br>
+     * <code>String name = (String)painting.readNestedProperty("toArtist.artistName");</code>
+     * <br>
+     * <br>
+     * </li>
+     * <li>Read to-many relationship list:<br>
+     * <code>List exhibits = (List)painting.readNestedProperty("toGallery.exhibitArray");</code>
+     * <br>
+     * <br>
+     * </li>
+     * <li>Read to-many relationship in the middle of the path:<br>
+     * <code>List<String> names = (List<String>)artist.readNestedProperty("paintingArray.paintingName");</code>
+     * <br>
+     * <br>
+     * </li>
+     * </ul>
+     * 
+     * @since 1.0.5
      */
-    private static Object readNestedProperty(
-            CayenneDataObject dataObject,
-            String path,
-            String[] tokenizedPath,
-            int tokenIndex,
-            int pathIndex) {
-
-        Object property = dataObject.readSimpleProperty(tokenizedPath[tokenIndex]);
-
-        if (tokenIndex == tokenizedPath.length - 1) { // last component
-            return property;
-        }
-
-        pathIndex += tokenizedPath[tokenIndex].length() + 1;
-        if (property == null) {
-            return null;
-        }
-        else if (property instanceof CayenneDataObject) {
-            return readNestedProperty(
-                    (CayenneDataObject) property,
-                    path,
-                    tokenizedPath,
-                    tokenIndex + 1,
-                    tokenIndex);
-        }
-        else if (property instanceof Collection) {
-            /**
-             * Support for collection property in the middle of the path
-             */
-            Collection<Object> result = property instanceof List
-                    ? new ArrayList<Object>()
-                    : new HashSet<Object>();
-            for (Object obj : (Collection<?>) property) {
-                if (obj instanceof CayenneDataObject) {
-                    Object rest = readNestedProperty(
-                            (CayenneDataObject) obj,
-                            path,
-                            tokenizedPath,
-                            tokenIndex + 1,
-                            tokenIndex);
-                    if (rest instanceof Collection) {
-                        /**
-                         * We don't want nested collections. E.g.
-                         * readNestedProperty("paintingArray.paintingTitle") should return
-                         * List<String>
-                         */
-                        result.addAll((Collection<?>) rest);
-                    }
-                    else {
-                        result.add(rest);
-                    }
-                }
-            }
-            return result;
-        }
-        else {
-            // read the rest of the path via introspection
-            return PropertyUtils.getProperty(property, path.substring(pathIndex));
-        }
-    }
-
-    private static final String[] tokenizePath(String path) {
-        if (path == null) {
-            throw new NullPointerException("Null property path.");
-        }
-
-        if (path.length() == 0) {
-            throw new IllegalArgumentException("Empty property path.");
-        }
-
-        // take a shortcut for simple properties
-        if (!path.contains(".")) {
-            return new String[] {
-                path
-            };
-        }
-
-        StringTokenizer tokens = new StringTokenizer(path, ".");
-        int length = tokens.countTokens();
-        String[] tokenized = new String[length];
-        for (int i = 0; i < length; i++) {
-            String temp = tokens.nextToken();
-            if (temp.endsWith("+")) {
-                tokenized[i] = temp.substring(0, temp.length() - 1);
-            }
-            else {
-                tokenized[i] = temp;
-            }
-        }
-        return tokenized;
-    }
-
-    private final Object readSimpleProperty(String property) {
-        // side effect - resolves HOLLOW object
-        Object object = readProperty(property);
-
-        // if a null value is returned, there is still a chance to
-        // find a non-persistent property via reflection
-        if (object == null && !values.containsKey(property)) {
-            object = PropertyUtils.getProperty(this, property);
-        }
-
-        return object;
+    public Object readNestedProperty(String path) {
+        return Cayenne.readNestedProperty(this, path);
     }
 
     public Object readProperty(String propertyName) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/PersistentObject.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/PersistentObject.java?rev=883858&r1=883857&r2=883858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/PersistentObject.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/PersistentObject.java Tue Nov 24 20:29:54 2009
@@ -24,6 +24,7 @@
 import org.apache.cayenne.reflect.ClassDescriptor;
 import org.apache.cayenne.reflect.Property;
 import org.apache.cayenne.reflect.ToManyMapProperty;
+import org.apache.cayenne.util.Cayenne;
 
 /**
  * A convenience base superclass for concrete Persistent objects. Provides implementation
@@ -130,10 +131,10 @@
      * mapped returns null.
      * 
      * @since 1.2
+     * @deprecated since 3.1 {@link org.apache.cayenne.util.Cayenne#getObjEntity(Persistent)} is used
      */
+    @Deprecated
     public ObjEntity getObjEntity() {
-        return (getObjectContext() != null) ? getObjectContext()
-                .getEntityResolver()
-                .lookupObjEntity(this) : null;
+        return Cayenne.getObjEntity(this);
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContext.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContext.java?rev=883858&r1=883857&r2=883858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContext.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContext.java Tue Nov 24 20:29:54 2009
@@ -66,7 +66,6 @@
 import org.apache.cayenne.reflect.ToOneProperty;
 import org.apache.cayenne.util.EventUtil;
 import org.apache.cayenne.util.GenericResponse;
-import org.apache.cayenne.util.ObjectContextGraphAction;
 import org.apache.cayenne.util.Util;
 
 /**
@@ -90,8 +89,6 @@
 
     protected transient DataContextMergeHandler mergeHandler;
 
-    ObjectContextGraphAction graphAction;
-
     /**
      * Stores the name of parent DataDomain. Used to defer initialization of the parent
      * QueryEngine after deserialization. This helps avoid an issue with certain servlet
@@ -179,8 +176,6 @@
             this.usingSharedSnaphsotCache = domain != null
                     && objectStore.getDataRowCache() == domain.getSharedSnapshotCache();
         }
-
-        this.graphAction = new DataContextGraphAction(this);
     }
 
     /**
@@ -1255,18 +1250,6 @@
     }
 
     /**
-     * @since 1.2
-     */
-    @Override
-    public void propertyChanged(
-            Persistent object,
-            String property,
-            Object oldValue,
-            Object newValue) {
-        graphAction.handlePropertyChange(object, property, oldValue, newValue);
-    }
-
-    /**
      * Returns this context's ObjectStore.
      * 
      * @since 1.2

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ToManyMap.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ToManyMap.java?rev=883858&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ToManyMap.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ToManyMap.java Tue Nov 24 20:29:54 2009
@@ -0,0 +1,53 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.cayenne.access;
+
+import java.util.Collection;
+
+import org.apache.cayenne.Persistent;
+import org.apache.cayenne.reflect.Accessor;
+import org.apache.cayenne.util.PersistentObjectMap;
+
+class ToManyMap extends PersistentObjectMap {
+
+    public ToManyMap(Persistent relationshipOwner, String relationshipName,
+            Accessor mapKeyAccessor) {
+        super(relationshipOwner, relationshipName, mapKeyAccessor);
+    }
+    
+    @Override
+    protected void postprocessAdd(Collection collection) {
+        // no need for this operation for DataObjects...
+    }
+    
+    @Override
+    protected void postprocessAdd(Object addedObject) {
+        // no need for this operation for DataObjects...
+    }
+    
+    @Override
+    protected void postprocessRemove(Collection collection) {
+        // no need for this operation for DataObjects...
+    }
+    
+    @Override
+    protected void postprocessRemove(Object removedObject) {
+        // no need for this operation for DataObjects...
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ToManyMapFault.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ToManyMapFault.java?rev=883858&r1=883857&r2=883858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ToManyMapFault.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ToManyMapFault.java Tue Nov 24 20:29:54 2009
@@ -21,7 +21,6 @@
 import org.apache.cayenne.Fault;
 import org.apache.cayenne.Persistent;
 import org.apache.cayenne.reflect.Accessor;
-import org.apache.cayenne.util.PersistentObjectMap;
 
 /**
  * @since 3.0
@@ -36,6 +35,6 @@
 
     @Override
     public Object resolveFault(Persistent sourceObject, String relationshipName) {
-        return new PersistentObjectMap(sourceObject, relationshipName, mapKeyAccessor);
+        return new ToManyMap(sourceObject, relationshipName, mapKeyAccessor);
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/BaseToManyProperty.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/BaseToManyProperty.java?rev=883858&r1=883857&r2=883858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/BaseToManyProperty.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/BaseToManyProperty.java Tue Nov 24 20:29:54 2009
@@ -23,6 +23,7 @@
 
 import org.apache.cayenne.Fault;
 import org.apache.cayenne.ValueHolder;
+import org.apache.cayenne.util.PersistentObjectCollection;
 
 /**
  * A generic superclass of CollectionProperty implementations.
@@ -79,6 +80,14 @@
             setReverse(source, null, target);
         }
     }
+    
+    public void addTargetDirectly(Object source, Object target) throws PropertyException {
+        ((PersistentObjectCollection) readProperty(source)).addDirectly(target);
+    }
+    
+    public void removeTargetDirectly(Object source, Object target) throws PropertyException {
+        ((PersistentObjectCollection) readProperty(source)).removeDirectly(target);
+    }
 
     public void removeTarget(Object source, Object target, boolean setReverse) {
 
@@ -131,4 +140,5 @@
      */
     protected abstract ValueHolder createCollectionValueHolder(Object object)
             throws PropertyException;
+    
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ToManyProperty.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ToManyProperty.java?rev=883858&r1=883857&r2=883858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ToManyProperty.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ToManyProperty.java Tue Nov 24 20:29:54 2009
@@ -32,4 +32,20 @@
 
     void removeTarget(Object source, Object target, boolean setReverse)
             throws PropertyException;
+    
+    /**
+     * Adds value to collection, without triggering changing events
+     * This method is mostly for internal use
+     * @since 3.1
+     */
+    void addTargetDirectly(Object source, Object target)
+        throws PropertyException;
+
+    /**
+     * Removes value from collection, without triggering changing events
+     * This method is mostly for internal use
+     * @since 3.1
+     */
+    void removeTargetDirectly(Object source, Object target)
+        throws PropertyException;
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/generic/DataObjectToManyProperty.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/generic/DataObjectToManyProperty.java?rev=883858&r1=883857&r2=883858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/generic/DataObjectToManyProperty.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/generic/DataObjectToManyProperty.java Tue Nov 24 20:29:54 2009
@@ -123,4 +123,14 @@
             writePropertyDirectly(object, null, fault);
         }
     }
+
+    public void addTargetDirectly(Object source, Object target)
+            throws PropertyException {
+        addTarget(source, target, false);
+    }
+
+    public void removeTargetDirectly(Object source, Object target)
+            throws PropertyException {
+        removeTarget(source, target, false);
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoMapProperty.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoMapProperty.java?rev=883858&r1=883857&r2=883858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoMapProperty.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoMapProperty.java Tue Nov 24 20:29:54 2009
@@ -63,6 +63,12 @@
             setReverse(source, null, target);
         }
     }
+    
+    @Override
+    public void addTargetDirectly(Object source, Object target) throws PropertyException {
+        PersistentObjectMap collection = (PersistentObjectMap) readProperty(source);
+        collection.putDirectly(getMapKey(target), target);
+    }
 
     @Override
     public void removeTarget(Object source, Object target, boolean setReverse) {
@@ -76,6 +82,12 @@
             setReverse(source, target, null);
         }
     }
+    
+    @Override
+    public void removeTargetDirectly(Object source, Object target) throws PropertyException {
+        PersistentObjectMap collection = (PersistentObjectMap) readProperty(source);
+        collection.removeDirectly(getMapKey(target));
+    }
 
     public Object getMapKey(Object target) throws PropertyException {
         return mapKeyAccessor.getValue(target);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderMapProperty.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderMapProperty.java?rev=883858&r1=883857&r2=883858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderMapProperty.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderMapProperty.java Tue Nov 24 20:29:54 2009
@@ -58,6 +58,12 @@
             setReverse(source, null, target);
         }
     }
+    
+    @Override
+    public void addTargetDirectly(Object source, Object target) throws PropertyException {
+        PersistentObjectMap collection = (PersistentObjectMap) readProperty(source);
+        collection.putDirectly(getMapKey(target), target);
+    }
 
     @Override
     public void removeTarget(Object source, Object target, boolean setReverse) {
@@ -71,6 +77,12 @@
             setReverse(source, target, null);
         }
     }
+    
+    @Override
+    public void removeTargetDirectly(Object source, Object target) throws PropertyException {
+        PersistentObjectMap collection = (PersistentObjectMap) readProperty(source);
+        collection.removeDirectly(getMapKey(target));
+    }
 
     @Override
     protected ValueHolder createCollectionValueHolder(Object object)

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/Cayenne.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/Cayenne.java?rev=883858&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/Cayenne.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/Cayenne.java Tue Nov 24 20:29:54 2009
@@ -0,0 +1,331 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.cayenne.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.apache.cayenne.CayenneDataObject;
+import org.apache.cayenne.DataObject;
+import org.apache.cayenne.PersistenceState;
+import org.apache.cayenne.Persistent;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.reflect.ArcProperty;
+import org.apache.cayenne.reflect.AttributeProperty;
+import org.apache.cayenne.reflect.ClassDescriptor;
+import org.apache.cayenne.reflect.Property;
+import org.apache.cayenne.reflect.PropertyUtils;
+import org.apache.cayenne.reflect.PropertyVisitor;
+import org.apache.cayenne.reflect.ToManyProperty;
+import org.apache.cayenne.reflect.ToOneProperty;
+
+/**
+ * Various utils for processing persistent objects and their properties
+ * @since 3.1 
+ */
+public final class Cayenne {
+
+    /**
+     * Returns mapped ObjEntity for object. If an object is transient or is not
+     * mapped returns null.
+     */
+    public static ObjEntity getObjEntity(Persistent p) {
+        return (p.getObjectContext() != null) ? p.getObjectContext()
+                .getEntityResolver()
+                .lookupObjEntity(p) : null;
+    }
+    
+    /**
+     * Returns class descriptor for the object, <code>null</code> if the object is
+     * transient or descriptor was not found
+     */
+    public static ClassDescriptor getClassDescriptor(Persistent object) {
+        if (object.getPersistenceState() == PersistenceState.TRANSIENT) {
+            return null;
+         }
+         
+         return object.getObjectContext().getEntityResolver().getClassDescriptor(
+                 object.getObjectId().getEntityName());
+    }
+    
+    /**
+     * Returns property desctiptor for specified property
+     * @param properyName path to the property
+     * @return property descriptor, <code>null</code> if not found
+     */
+    public static Property getProperty(Persistent object, String properyName) {
+        ClassDescriptor descriptor = getClassDescriptor(object);
+        if (descriptor == null) {
+            return null;
+        }
+        return descriptor.getProperty(properyName);
+    }   
+    
+    /**
+     * Returns a value of the property identified by a property path. Supports reading
+     * both mapped and unmapped properties. Unmapped properties are accessed in a manner
+     * consistent with JavaBeans specification.
+     * <p>
+     * Property path (or nested property) is a dot-separated path used to traverse object
+     * relationships until the final object is found. If a null object found while
+     * traversing path, null is returned. If a list is encountered in the middle of the
+     * path, CayenneRuntimeException is thrown. Unlike
+     * {@link #readPropertyDirectly(String)}, this method will resolve an object if it is
+     * HOLLOW.
+     * <p>
+     * Examples:
+     * </p>
+     * <ul>
+     * <li>Read this object property:<br>
+     * <code>String name = (String)CayenneUtils.readNestedProperty(artist, "name");</code><br>
+     * <br>
+     * </li>
+     * <li>Read an object related to this object:<br>
+     * <code>Gallery g = (Gallery)CayenneUtils.readNestedProperty(paintingInfo, "toPainting.toGallery");</code>
+     * <br>
+     * <br>
+     * </li>
+     * <li>Read a property of an object related to this object: <br>
+     * <code>String name = (String)CayenneUtils.readNestedProperty(painting, "toArtist.artistName");</code>
+     * <br>
+     * <br>
+     * </li>
+     * <li>Read to-many relationship list:<br>
+     * <code>List exhibits = (List)CayenneUtils.readNestedProperty(painting, "toGallery.exhibitArray");</code>
+     * <br>
+     * <br>
+     * </li>
+     * <li>Read to-many relationship in the middle of the path:<br>
+     * <code>List<String> names = (List<String>)CayenneUtils.readNestedProperty(artist, "paintingArray.paintingName");</code>
+     * <br>
+     * <br>
+     * </li>
+     * </ul>
+     */
+    public static Object readNestedProperty(Persistent p, String path) {
+        return readNestedProperty(p, path, tokenizePath(path), 0, 0);
+    }
+
+    /**
+     * Recursively resolves nested property path
+     */
+    private static Object readNestedProperty(
+            Persistent p,
+            String path,
+            String[] tokenizedPath,
+            int tokenIndex,
+            int pathIndex) {
+
+        Object property = readSimpleProperty(p, tokenizedPath[tokenIndex]);
+
+        if (tokenIndex == tokenizedPath.length - 1) { // last component
+            return property;
+        }
+
+        pathIndex += tokenizedPath[tokenIndex].length() + 1;
+        if (property == null) {
+            return null;
+        }
+        else if (property instanceof Persistent) {
+            return readNestedProperty(
+                    (Persistent) property,
+                    path,
+                    tokenizedPath,
+                    tokenIndex + 1,
+                    tokenIndex);
+        }
+        else if (property instanceof Collection) {
+            /**
+             * Support for collection property in the middle of the path
+             */
+            Collection<Object> result = property instanceof List
+                    ? new ArrayList<Object>()
+                    : new HashSet<Object>();
+            for (Object obj : (Collection<?>) property) {
+                if (obj instanceof CayenneDataObject) {
+                    Object rest = readNestedProperty(
+                            (CayenneDataObject) obj,
+                            path,
+                            tokenizedPath,
+                            tokenIndex + 1,
+                            tokenIndex);
+                    if (rest instanceof Collection) {
+                        /**
+                         * We don't want nested collections. E.g.
+                         * readNestedProperty("paintingArray.paintingTitle") should return
+                         * List<String>
+                         */
+                        result.addAll((Collection<?>) rest);
+                    }
+                    else {
+                        result.add(rest);
+                    }
+                }
+            }
+            return result;
+        }
+        else {
+            // read the rest of the path via introspection
+            return PropertyUtils.getProperty(property, path.substring(pathIndex));
+        }
+    }
+
+    private static final String[] tokenizePath(String path) {
+        if (path == null) {
+            throw new NullPointerException("Null property path.");
+        }
+
+        if (path.length() == 0) {
+            throw new IllegalArgumentException("Empty property path.");
+        }
+
+        // take a shortcut for simple properties
+        if (!path.contains(".")) {
+            return new String[] {
+                path
+            };
+        }
+
+        StringTokenizer tokens = new StringTokenizer(path, ".");
+        int length = tokens.countTokens();
+        String[] tokenized = new String[length];
+        for (int i = 0; i < length; i++) {
+            String temp = tokens.nextToken();
+            if (temp.endsWith("+")) {
+                tokenized[i] = temp.substring(0, temp.length() - 1);
+            }
+            else {
+                tokenized[i] = temp;
+            }
+        }
+        return tokenized;
+    }
+
+    private static final Object readSimpleProperty(Persistent p, String propertyName) {
+        Property property = getProperty(p, propertyName);
+
+        if (property != null) {
+            // side effect - resolves HOLLOW object
+            return property.readProperty(p);
+        }
+        
+        //handling non-persistent property
+        Object result = null;
+        if (p instanceof DataObject) {
+            result = ((DataObject) p).readPropertyDirectly(propertyName);
+        }
+        
+        if (result != null) {
+            return result;
+        }
+     
+        //there is still a change to return a property via introspection
+        return PropertyUtils.getProperty(p, propertyName);
+    }
+    
+    static void setReverse(
+            final Persistent sourceObject,
+            String propertyName,
+            final Persistent targetObject) {
+        
+        ArcProperty property = (ArcProperty) getClassDescriptor(sourceObject).
+            getProperty(propertyName);
+        ArcProperty reverseArc = property.getComplimentaryReverseArc();
+        if (reverseArc != null) {
+            reverseArc.visit(new PropertyVisitor() {
+
+                public boolean visitToMany(ToManyProperty property) {
+                    property.addTargetDirectly(targetObject, sourceObject);
+                    return false;
+                }
+
+                public boolean visitToOne(ToOneProperty property) {
+                    property.setTarget(targetObject, sourceObject, false);
+                    return false;
+                }
+
+                public boolean visitAttribute(AttributeProperty property) {
+                    return false;
+                }
+
+            });
+            
+            sourceObject.getObjectContext().getGraphManager().arcCreated(
+                    targetObject.getObjectId(),
+                    sourceObject.getObjectId(),
+                    reverseArc.getName());
+    
+            markAsDirty(targetObject);
+        }
+    }
+
+    static void unsetReverse(
+            final Persistent sourceObject,
+            String propertyName,
+            final Persistent targetObject) {
+        
+        ArcProperty property = (ArcProperty) getClassDescriptor(sourceObject).
+            getProperty(propertyName);
+        ArcProperty reverseArc = property.getComplimentaryReverseArc();
+        if (reverseArc != null) {
+            reverseArc.visit(new PropertyVisitor() {
+
+                public boolean visitToMany(ToManyProperty property) {
+                    property.removeTargetDirectly(targetObject, sourceObject);
+                    return false;
+                }
+
+                public boolean visitToOne(ToOneProperty property) {
+                    property.setTarget(targetObject, null, false);
+                    return false;
+                }
+
+                public boolean visitAttribute(AttributeProperty property) {
+                    return false;
+                }
+
+            });
+            
+            sourceObject.getObjectContext().getGraphManager().arcDeleted(
+                    targetObject.getObjectId(),
+                    sourceObject.getObjectId(),
+                    reverseArc.getName());
+
+            markAsDirty(targetObject);
+        }
+    }
+    
+    /**
+     * Changes object state to MODIFIED if needed, returning true if the change has
+     * occurred, false if not.
+     */
+    static boolean markAsDirty(Persistent object) {
+        if (object.getPersistenceState() == PersistenceState.COMMITTED) {
+            object.setPersistenceState(PersistenceState.MODIFIED);
+            return true;
+        }
+
+        return false;
+    }
+    
+    private Cayenne() {}
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/ObjectContextGraphAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/ObjectContextGraphAction.java?rev=883858&r1=883857&r2=883858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/ObjectContextGraphAction.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/ObjectContextGraphAction.java Tue Nov 24 20:29:54 2009
@@ -33,8 +33,9 @@
  * processing on behalf of an ObjectContext.
  * 
  * @since 3.0
+ * TODO: make this non-public! 
  */
-public abstract class ObjectContextGraphAction implements Serializable {
+public class ObjectContextGraphAction implements Serializable {
 
     protected ObjectContext context;
 
@@ -68,11 +69,29 @@
         }
     }
 
-    protected abstract void handleArcPropertyChange(
+    protected void handleArcPropertyChange(
             Persistent object,
             ArcProperty property,
             Object oldValue,
-            Object newValue);
+            Object newValue) {
+        if (oldValue != newValue) {
+            markAsDirty(object);
+
+            if (oldValue instanceof Persistent) {
+                context.getGraphManager().arcDeleted(
+                        object.getObjectId(),
+                        ((Persistent) oldValue).getObjectId(),
+                        property.getName());
+            }
+
+            if (newValue instanceof Persistent) {
+                context.getGraphManager().arcCreated(
+                        object.getObjectId(),
+                        ((Persistent) newValue).getObjectId(),
+                        property.getName());
+            }
+        }
+    }
 
     protected void handleSimplePropertyChange(
             Persistent object,

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectCollection.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectCollection.java?rev=883858&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectCollection.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectCollection.java Tue Nov 24 20:29:54 2009
@@ -0,0 +1,39 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.cayenne.util;
+
+import java.util.Collection;
+
+/**
+ * Simple interface to unify PersistentObject* collections in way of
+ * setting properties directly
+ * @see org.apache.cayenne.reflect.ToManyMapProperty
+ * @since 3.1
+ */
+public interface PersistentObjectCollection extends Collection {
+    /**
+     * Adds an object without triggering an event 
+     */
+    public void addDirectly(Object target);
+    
+    /**
+     * Removes an object without triggering an event 
+     */
+    public void removeDirectly(Object target);
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectHolder.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectHolder.java?rev=883858&r1=883857&r2=883858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectHolder.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectHolder.java Tue Nov 24 20:29:54 2009
@@ -86,18 +86,16 @@
         }
 
         Object oldValue = setValueDirectly(value);
-
         if (oldValue != value) {
-            // notify ObjectContext
-            if (relationshipOwner.getObjectContext() != null) {
-                relationshipOwner.getObjectContext().propertyChanged(
-                        relationshipOwner,
-                        relationshipName,
-                        oldValue,
-                        value);
+            relationshipOwner.getObjectContext().propertyChanged(relationshipOwner, relationshipName, oldValue, value);
+    
+            if (oldValue instanceof Persistent) {
+                Cayenne.unsetReverse(relationshipOwner, relationshipName, (Persistent) oldValue);
+            }
+            if (value instanceof Persistent) {
+                Cayenne.setReverse(relationshipOwner, relationshipName, (Persistent) value);
             }
         }
-
         return oldValue;
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectList.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectList.java?rev=883858&r1=883857&r2=883858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectList.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectList.java Tue Nov 24 20:29:54 2009
@@ -35,7 +35,8 @@
  * 
  * @since 1.2
  */
-public class PersistentObjectList extends RelationshipFault implements List, ValueHolder {
+public class PersistentObjectList extends RelationshipFault 
+    implements List, ValueHolder, PersistentObjectCollection {
 
     // wrapped objects list
     protected List objectList;
@@ -414,6 +415,10 @@
                     relationshipName,
                     null,
                     addedObject);
+            if (addedObject instanceof Persistent) {
+                Cayenne.setReverse(relationshipOwner, relationshipName,
+                        (Persistent) addedObject);
+            }
         }
     }
 
@@ -426,6 +431,10 @@
                     relationshipName,
                     removedObject,
                     null);
+            if (removedObject instanceof Persistent) {
+                Cayenne.unsetReverse(relationshipOwner, relationshipName,
+                        (Persistent) removedObject);
+            }
         }
     }
 
@@ -433,4 +442,22 @@
     public String toString() {
         return (objectList != null) ? objectList.toString() : "[<unresolved>]";
     }
+
+    public void addDirectly(Object target) {
+        if (isFault()) {
+            addLocal(target);
+        }
+        else {
+            objectList.add(target);
+        }
+    }
+
+    public void removeDirectly(Object target) {
+        if (isFault()) {
+            removeLocal(target);
+        }
+        else {
+            objectList.remove(target);
+        }
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectMap.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectMap.java?rev=883858&r1=883857&r2=883858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectMap.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectMap.java Tue Nov 24 20:29:54 2009
@@ -181,7 +181,7 @@
         return (objectMap != null) ? objectMap.toString() : "{<unresolved>}";
     }
 
-    void postprocessAdd(Object addedObject) {
+    protected void postprocessAdd(Object addedObject) {
 
         // notify ObjectContext
         if (relationshipOwner.getObjectContext() != null) {
@@ -190,17 +190,22 @@
                     relationshipName,
                     null,
                     addedObject);
+            
+            if (addedObject instanceof Persistent) {
+                Cayenne.setReverse(relationshipOwner, relationshipName,
+                        (Persistent) addedObject);
+            }
         }
     }
 
-    void postprocessAdd(Collection collection) {
+    protected void postprocessAdd(Collection collection) {
         Iterator it = collection.iterator();
         while (it.hasNext()) {
             postprocessAdd(it.next());
         }
     }
 
-    void postprocessRemove(Object removedObject) {
+    protected void postprocessRemove(Object removedObject) {
 
         // notify ObjectContext
         if (relationshipOwner.getObjectContext() != null) {
@@ -209,10 +214,14 @@
                     relationshipName,
                     removedObject,
                     null);
+            if (removedObject instanceof Persistent) {
+                Cayenne.unsetReverse(relationshipOwner, relationshipName,
+                        (Persistent) removedObject);
+            }
         }
     }
 
-    void postprocessRemove(Collection collection) {
+    protected void postprocessRemove(Collection collection) {
         Iterator it = collection.iterator();
         while (it.hasNext()) {
             postprocessRemove(it.next());
@@ -286,4 +295,14 @@
     public Collection values() {
         return resolvedObjectMap().values();
     }
+    
+    public void putDirectly(Object key, Object value) {
+        //TODO: should not resolve manually
+        resolvedObjectMap().put(key, value);
+    }
+    
+    public void removeDirectly(Object key) {
+        //TODO: should not resolve manually
+        resolvedObjectMap().remove(key);
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectSet.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectSet.java?rev=883858&r1=883857&r2=883858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectSet.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/PersistentObjectSet.java Tue Nov 24 20:29:54 2009
@@ -32,7 +32,8 @@
 /**
  * @since 3.0
  */
-public class PersistentObjectSet extends RelationshipFault implements Set, ValueHolder {
+public class PersistentObjectSet extends RelationshipFault 
+    implements Set, ValueHolder, PersistentObjectCollection {
 
     // wrapped objects set
     protected Set objectSet;
@@ -341,6 +342,10 @@
                     relationshipName,
                     null,
                     addedObject);
+            if (addedObject instanceof Persistent) {
+                Cayenne.setReverse(relationshipOwner, relationshipName,
+                        (Persistent) addedObject);
+            }
         }
     }
 
@@ -353,6 +358,10 @@
                     relationshipName,
                     removedObject,
                     null);
+            if (removedObject instanceof Persistent) {
+                Cayenne.unsetReverse(relationshipOwner, relationshipName,
+                        (Persistent) removedObject);
+            }
         }
     }
 
@@ -361,4 +370,21 @@
         return (objectSet != null) ? objectSet.toString() : "[<unresolved>]";
     }
 
+    public void addDirectly(Object target) {
+        if (isFault()) {
+            addLocal(target);
+        }
+        else {
+            objectSet.add(target);
+        }
+    }
+
+    public void removeDirectly(Object target) {
+        if (isFault()) {
+            removeLocal(target);
+        }
+        else {
+            objectSet.remove(target);
+        }
+    }
 }

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/Continent.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/Continent.java?rev=883858&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/Continent.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/Continent.java Tue Nov 24 20:29:54 2009
@@ -0,0 +1,7 @@
+package org.apache.art;
+
+import org.apache.art.auto._Continent;
+
+public class Continent extends _Continent {
+
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/Country.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/Country.java?rev=883858&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/Country.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/Country.java Tue Nov 24 20:29:54 2009
@@ -0,0 +1,7 @@
+package org.apache.art;
+
+import org.apache.art.auto._Country;
+
+public class Country extends _Country {
+
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/auto/_Continent.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/auto/_Continent.java?rev=883858&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/auto/_Continent.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/auto/_Continent.java Tue Nov 24 20:29:54 2009
@@ -0,0 +1,64 @@
+package org.apache.art.auto;
+
+import java.util.List;
+
+import org.apache.art.Country;
+import org.apache.cayenne.PersistentObject;
+
+/**
+ * A generated persistent class mapped as "Continent" Cayenne entity. It is a good idea to
+ * avoid changing this class manually, since it will be overwritten next time code is
+ * regenerated. If you need to make any customizations, put them in a subclass.
+ */
+public abstract class _Continent extends PersistentObject {
+
+    public static final String NAME_PROPERTY = "name";
+    public static final String COUNTRIES_PROPERTY = "countries";
+
+    protected String name;
+    protected List<Country> countries;
+
+    public String getName() {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "name", false);
+        }
+
+        return name;
+    }
+    public void setName(String name) {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "name", false);
+        }
+
+        Object oldValue = this.name;
+        this.name = name;
+
+        // notify objectContext about simple property change
+        if(objectContext != null) {
+            objectContext.propertyChanged(this, "name", oldValue, name);
+        }
+    }
+
+    public List<Country> getCountries() {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "countries", true);
+        }
+
+        return countries;
+    }
+    public void addToCountries(Country object) {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "countries", true);
+        }
+
+        this.countries.add(object);
+    }
+    public void removeFromCountries(Country object) {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "countries", true);
+        }
+
+        this.countries.remove(object);
+    }
+
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/auto/_Country.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/auto/_Country.java?rev=883858&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/auto/_Country.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/auto/_Country.java Tue Nov 24 20:29:54 2009
@@ -0,0 +1,56 @@
+package org.apache.art.auto;
+
+import org.apache.art.Continent;
+import org.apache.cayenne.PersistentObject;
+import org.apache.cayenne.ValueHolder;
+
+/**
+ * A generated persistent class mapped as "Country" Cayenne entity. It is a good idea to
+ * avoid changing this class manually, since it will be overwritten next time code is
+ * regenerated. If you need to make any customizations, put them in a subclass.
+ */
+public abstract class _Country extends PersistentObject {
+
+    public static final String NAME_PROPERTY = "name";
+    public static final String CONTINENT_PROPERTY = "continent";
+
+    protected String name;
+    protected ValueHolder continent;
+
+    public String getName() {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "name", false);
+        }
+
+        return name;
+    }
+    public void setName(String name) {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "name", false);
+        }
+
+        Object oldValue = this.name;
+        this.name = name;
+
+        // notify objectContext about simple property change
+        if(objectContext != null) {
+            objectContext.propertyChanged(this, "name", oldValue, name);
+        }
+    }
+
+    public Continent getContinent() {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "continent", true);
+        }
+
+        return (Continent) continent.getValue();
+    }
+    public void setContinent(Continent continent) {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "continent", true);
+        }
+
+        this.continent.setValue(continent);
+    }
+
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/LightSuperClassTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/LightSuperClassTest.java?rev=883858&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/LightSuperClassTest.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/LightSuperClassTest.java Tue Nov 24 20:29:54 2009
@@ -0,0 +1,55 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.cayenne;
+
+import org.apache.art.Continent;
+import org.apache.art.Country;
+import org.apache.cayenne.query.RefreshQuery;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.unit.CayenneCase;
+
+public class LightSuperClassTest extends CayenneCase {
+    public void testServer() {
+        doTest(createDataContext());
+    }
+    
+    private void doTest(ObjectContext context) {
+        Continent continent = context.newObject(Continent.class);
+        continent.setName("Europe");
+        
+        Country country = new Country();
+        country.setName("Russia");
+        context.registerNewObject(country);
+        
+        country.setContinent(continent);
+        assertEquals(continent.getCountries().size(), 1);
+        
+        context.commitChanges();
+        
+        context.deleteObject(country);
+        assertEquals(continent.getCountries().size(), 0);
+        continent.setName("Australia");
+        
+        context.commitChanges();
+        context.performQuery(new RefreshQuery());
+        
+        assertEquals(context.performQuery(new SelectQuery(Country.class)).size(), 0);
+        assertEquals(context.performQuery(new SelectQuery(Continent.class)).size(), 1);
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/testmap.map.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/testmap.map.xml?rev=883858&r1=883857&r2=883858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/testmap.map.xml (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/testmap.map.xml Tue Nov 24 20:29:54 2009
@@ -117,6 +117,15 @@
 		<db-attribute name="KEY2" type="VARCHAR" isPrimaryKey="true" isMandatory="true" length="20"/>
 		<db-attribute name="NAME" type="VARCHAR" length="255"/>
 	</db-entity>
+	<db-entity name="CONTINENT">
+		<db-attribute name="CONTINENTD" type="BIGINT" isPrimaryKey="true" isMandatory="true"/>
+		<db-attribute name="NAME" type="VARCHAR" isMandatory="true" length="100"/>
+	</db-entity>
+	<db-entity name="COUNTRY">
+		<db-attribute name="CONTINENTID" type="BIGINT" isMandatory="true"/>
+		<db-attribute name="COUNTRYID" type="BIGINT" isPrimaryKey="true" isMandatory="true"/>
+		<db-attribute name="NAME" type="VARCHAR" isMandatory="true" length="100"/>
+	</db-entity>
 	<db-entity name="DATE_TEST">
 		<db-attribute name="DATE_COLUMN" type="DATE"/>
 		<db-attribute name="DATE_TEST_ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
@@ -332,6 +341,12 @@
 		<obj-attribute name="key2" type="java.lang.String" db-attribute-path="KEY2"/>
 		<obj-attribute name="name" type="java.lang.String" db-attribute-path="NAME"/>
 	</obj-entity>
+	<obj-entity name="Continent" className="org.apache.art.Continent" dbEntityName="CONTINENT" superClassName="org.apache.cayenne.PersistentObject">
+		<obj-attribute name="name" type="java.lang.String" db-attribute-path="NAME"/>
+	</obj-entity>
+	<obj-entity name="Country" className="org.apache.art.Country" dbEntityName="COUNTRY" superClassName="org.apache.cayenne.PersistentObject">
+		<obj-attribute name="name" type="java.lang.String" db-attribute-path="NAME"/>
+	</obj-entity>
 	<obj-entity name="DateTestEntity" className="org.apache.art.DateTestEntity" dbEntityName="DATE_TEST">
 		<obj-attribute name="dateColumn" type="java.util.Date" db-attribute-path="DATE_COLUMN"/>
 		<obj-attribute name="timeColumn" type="java.util.Date" db-attribute-path="TIME_COLUMN"/>
@@ -498,6 +513,12 @@
 		<db-attribute-pair source="KEY1" target="F_KEY1"/>
 		<db-attribute-pair source="KEY2" target="F_KEY2"/>
 	</db-relationship>
+	<db-relationship name="countries" source="CONTINENT" target="COUNTRY" toMany="true">
+		<db-attribute-pair source="CONTINENTD" target="CONTINENTID"/>
+	</db-relationship>
+	<db-relationship name="continent" source="COUNTRY" target="CONTINENT" toMany="false">
+		<db-attribute-pair source="CONTINENTID" target="CONTINENTD"/>
+	</db-relationship>
 	<db-relationship name="artistExhibitArray" source="EXHIBIT" target="ARTIST_EXHIBIT" toDependentPK="true" toMany="true">
 		<db-attribute-pair source="EXHIBIT_ID" target="EXHIBIT_ID"/>
 	</db-relationship>
@@ -568,6 +589,8 @@
 	<obj-relationship name="toGallery" source="CompoundPainting" target="Gallery" deleteRule="Nullify" db-relationship-path="toGallery"/>
 	<obj-relationship name="toPaintingInfo" source="CompoundPainting" target="PaintingInfo" deleteRule="Cascade" db-relationship-path="toPaintingInfo"/>
 	<obj-relationship name="compoundFkArray" source="CompoundPkTestEntity" target="CompoundFkTestEntity" db-relationship-path="compoundFkArray"/>
+	<obj-relationship name="countries" source="Continent" target="Country" deleteRule="Cascade" db-relationship-path="countries"/>
+	<obj-relationship name="continent" source="Country" target="Continent" deleteRule="Nullify" db-relationship-path="continent"/>
 	<obj-relationship name="artistExhibitArray" source="Exhibit" target="ArtistExhibit" deleteRule="Cascade" db-relationship-path="artistExhibitArray"/>
 	<obj-relationship name="toGallery" source="Exhibit" target="Gallery" deleteRule="Nullify" db-relationship-path="toGallery"/>
 	<obj-relationship name="exhibitArray" source="Gallery" target="Exhibit" deleteRule="Cascade" db-relationship-path="exhibitArray"/>

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CodeTemplateManager.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CodeTemplateManager.java?rev=883858&r1=883857&r2=883858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CodeTemplateManager.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CodeTemplateManager.java Tue Nov 24 20:29:54 2009
@@ -38,6 +38,8 @@
     public static final String STANDARD_SERVER_SUBCLASS = "Standard Server Subclass";
     static final String STANDARD_CLIENT_SUPERCLASS = "Standard Client Superclass";
     static final String STANDARD_CLIENT_SUBCLASS = "Standard Client Subclass";
+    
+    static final String LIGHT_SERVER_SUPERCLASS = "Light Server Superclass";
 
     protected List<String> standardSubclassTemplates;
     protected List<String> standardSuperclassTemplates;
@@ -53,6 +55,7 @@
 
         standardSuperclassTemplates.add(STANDARD_SERVER_SUPERCLASS);
         standardSuperclassTemplates.add(STANDARD_CLIENT_SUPERCLASS);
+        standardSuperclassTemplates.add(LIGHT_SERVER_SUPERCLASS);
 
         standardSubclassTemplates = new ArrayList<String>(3);
         standardSubclassTemplates.add(STANDARD_SERVER_SUBCLASS);
@@ -73,6 +76,9 @@
         standardTemplates.put(
                 STANDARD_CLIENT_SUBCLASS,
                 ClientClassGenerationAction.SUBCLASS_TEMPLATE);
+        standardTemplates.put(
+                LIGHT_SERVER_SUPERCLASS,
+                ClientClassGenerationAction.LIGHT_SUPERCLASS_TEMPLATE);
     }
 
     /**

Modified: cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java?rev=883858&r1=883857&r2=883858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java (original)
+++ cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java Tue Nov 24 20:29:54 2009
@@ -58,6 +58,9 @@
     public static final String DATAMAP_SINGLE_CLASS_TEMPLATE = TEMPLATES_DIR_NAME + "datamap-singleclass.vm";
     public static final String DATAMAP_SUBCLASS_TEMPLATE = TEMPLATES_DIR_NAME + "datamap-subclass.vm";
     public static final String DATAMAP_SUPERCLASS_TEMPLATE = TEMPLATES_DIR_NAME + "datamap-superclass.vm";
+    
+    //light classes template - it is for server, but extends PeristentObject
+    public static final String LIGHT_SUPERCLASS_TEMPLATE = TEMPLATES_DIR_NAME + "light-superclass.vm";
 
     public static final String SUPERCLASS_PREFIX = "_";
     private static final String WILDCARD = "*";