cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r454052 - in /incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src: main/java/org/apache/cayenne/ main/java/org/apache/cayenne/access/ main/java/org/apache/cayenne/intercept/ test/java/org/apache/cayenne/
Date Sun, 08 Oct 2006 00:54:17 GMT
Author: aadamchik
Date: Sat Oct  7 17:54:16 2006
New Revision: 454052

URL: http://svn.apache.org/viewvc?view=rev&rev=454052
Log:
CAY-679 - ObjectContext.registerNewObject() added

Modified:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/BaseContext.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/CayenneContext.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/ObjectContext.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContext.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/ObjectContextDecorator.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/MockObjectContext.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/BaseContext.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/BaseContext.java?view=diff&rev=454052&r1=454051&r2=454052
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/BaseContext.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/BaseContext.java
Sat Oct  7 17:54:16 2006
@@ -58,6 +58,8 @@
     public abstract Collection modifiedObjects();
 
     public abstract Persistent newObject(Class persistentClass);
+    
+    public abstract void registerNewObject(Persistent object);
 
     public abstract Collection newObjects();
 

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/CayenneContext.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/CayenneContext.java?view=diff&rev=454052&r1=454051&r2=454052
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/CayenneContext.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/CayenneContext.java
Sat Oct  7 17:54:16 2006
@@ -309,9 +309,25 @@
                     + persistentClass);
         }
 
-        synchronized (graphManager) {
-            return createNewObject(new ObjectId(entity.getName()));
+        ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(
+                entity.getName());
+        Persistent object = (Persistent) descriptor.createObject();
+        registerNewObject(object, entity.getName(), descriptor);
+        return object;
+    }
+
+    /**
+     * @since 3.0
+     */
+    public void registerNewObject(Persistent object) {
+        if (object == null) {
+            throw new NullPointerException("An attempt to register null object.");
         }
+
+        ObjEntity entity = getEntityResolver().lookupObjEntity(object.getClass());
+        ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(
+                entity.getName());
+        registerNewObject(object, entity.getName(), descriptor);
     }
 
     /**
@@ -468,11 +484,11 @@
 
     // ****** non-public methods ******
 
-    Persistent createNewObject(ObjectId id) {
-        ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(
-                id.getEntityName());
-
-        Persistent object = (Persistent) descriptor.createObject();
+    void registerNewObject(
+            Persistent object,
+            String entityName,
+            ClassDescriptor descriptor) {
+        ObjectId id = new ObjectId(entityName);
 
         // must follow this exact order of property initialization per CAY-653, i.e. have
         // the id and the context in place BEFORE setPersistence is called
@@ -481,10 +497,11 @@
         object.setPersistenceState(PersistenceState.NEW);
 
         descriptor.injectValueHolders(object);
-        graphManager.registerNode(object.getObjectId(), object);
-        graphManager.nodeCreated(object.getObjectId());
 
-        return object;
+        synchronized (graphManager) {
+            graphManager.registerNode(object.getObjectId(), object);
+            graphManager.nodeCreated(object.getObjectId());
+        }
     }
 
     Persistent createFault(ObjectId id) {

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/ObjectContext.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/ObjectContext.java?view=diff&rev=454052&r1=454051&r2=454052
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/ObjectContext.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/ObjectContext.java
Sat Oct  7 17:54:16 2006
@@ -84,11 +84,20 @@
     Persistent newObject(Class persistentClass);
 
     /**
+     * Registers a transient object with the context. The difference with
+     * {@link #newObject(Class)} is that a user creates an object herself, before
+     * attaching it to the context, instead of relying on Cayenne to do that.
+     * 
+     * @param object new object that needs to be made persistent.
+     * @since 3.0
+     */
+    void registerNewObject(final Persistent object);
+
+    /**
      * Schedules a persistent object for deletion on next commit.
      * 
-     * @throws DeleteDenyException if a
-     *             {@link org.apache.cayenne.map.DeleteRule#DENY} delete rule is
-     *             applicable for object deletion.
+     * @throws DeleteDenyException if a {@link org.apache.cayenne.map.DeleteRule#DENY}
+     *             delete rule is applicable for object deletion.
      */
     void deleteObject(Persistent object) throws DeleteDenyException;
 

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContext.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContext.java?view=diff&rev=454052&r1=454051&r2=454052
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContext.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContext.java
Sat Oct  7 17:54:16 2006
@@ -398,7 +398,7 @@
         awakeFromDeserialization();
         return super.getChannel();
     }
-    
+
     /**
      * Returns a DataDomain used by this DataContext. DataDomain is looked up in the
      * DataChannel hierarchy. If a channel is not a DataDomain or a DataContext, null is
@@ -776,11 +776,13 @@
 
     /**
      * Registers a transient object with the context, recursively registering all
-     * transient DataObjects attached to this object via relationships.
+     * transient DataObjects attached to this object via relationships. <p/><i>Note
that
+     * since 3.0 this method takes {@link Persistent} as an argument instead of a
+     * {@link DataObject}.</i>
      * 
      * @param object new object that needs to be made persistent.
      */
-    public void registerNewObject(final DataObject object) {
+    public void registerNewObject(final Persistent object) {
         if (object == null) {
             throw new NullPointerException("Can't register null object.");
         }
@@ -795,11 +797,11 @@
 
         // sanity check - maybe already registered
         if (object.getObjectId() != null) {
-            if (object.getDataContext() == this) {
+            if (object.getObjectContext() == this) {
                 // already registered, just ignore
                 return;
             }
-            else if (object.getDataContext() != null) {
+            else if (object.getObjectContext() != null) {
                 throw new IllegalStateException(
                         "DataObject is already registered with another DataContext. "
                                 + "Try using 'localObjects()' instead.");
@@ -809,7 +811,7 @@
             object.setObjectId(new ObjectId(entity.getName()));
         }
 
-        object.setDataContext(this);
+        object.setObjectContext(this);
         object.setPersistenceState(PersistenceState.NEW);
 
         getObjectStore().recordObjectCreated(object);

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/ObjectContextDecorator.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/ObjectContextDecorator.java?view=diff&rev=454052&r1=454051&r2=454052
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/ObjectContextDecorator.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/ObjectContextDecorator.java
Sat Oct  7 17:54:16 2006
@@ -81,6 +81,10 @@
     public Persistent newObject(Class persistentClass) {
         return context.newObject(persistentClass);
     }
+    
+    public void registerNewObject(Persistent object) {
+        context.registerNewObject(object);
+    }
 
     public Collection newObjects() {
         return context.newObjects();

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/MockObjectContext.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/MockObjectContext.java?view=diff&rev=454052&r1=454051&r2=454052
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/MockObjectContext.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/MockObjectContext.java
Sat Oct  7 17:54:16 2006
@@ -98,6 +98,9 @@
     public Persistent newObject(Class persistentClass) {
         return null;
     }
+    
+    public void registerNewObject(Persistent object) {
+    }
 
     public void prepareForAccess(Persistent persistent, String property) {
     }



Mime
View raw message