cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mgen...@apache.org
Subject svn commit: r823656 - in /cayenne/main/trunk/framework: cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/ cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/ cayenn...
Date Fri, 09 Oct 2009 18:38:52 GMT
Author: mgentry
Date: Fri Oct  9 18:38:51 2009
New Revision: 823656

URL: http://svn.apache.org/viewvc?rev=823656&view=rev
Log:
Updates for CAY-1288 (adding deleteObjects() to ObjectContext).

Modified:
    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/ObjectContext.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/MockObjectContext.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DeleteObjectTest.java
    cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/test/java/org/apache/cayenne/jpa/MockObjectContext.java

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=823656&r1=823655&r2=823656&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
Fri Oct  9 18:38:51 2009
@@ -316,6 +316,18 @@
         new ObjectContextDeleteAction(this).performDelete((Persistent) object);
     }
 
+    public void deleteObjects(Collection<?> objects) throws DeleteDenyException {
+        if (objects.isEmpty())
+            return;
+
+        // Don't call deleteObject() directly since it would be less efficient.
+        ObjectContextDeleteAction ocda = new ObjectContextDeleteAction(this);
+
+        // Make a copy to iterate over to avoid ConcurrentModificationException.
+        for (Persistent object : (ArrayList<Persistent>) new ArrayList(objects))
+            ocda.performDelete(object);
+    }
+
     /**
      * Creates and registers a new Persistent object instance.
      */

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectContext.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectContext.java?rev=823656&r1=823655&r2=823656&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectContext.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectContext.java
Fri Oct  9 18:38:51 2009
@@ -102,6 +102,12 @@
     void deleteObject(Object object) throws DeleteDenyException;
 
     /**
+     * Deletes a collection of objects by repeatedly calling deleteObject safely
+     * (avoiding a concurrent modification exception).
+     */
+    void deleteObjects(Collection<?> objects) throws DeleteDenyException;
+
+    /**
      * A callback method that child Persistent objects are expected to call before
      * accessing property values. This callback allows ObjectContext to "inflate"
      * unresolved objects on demand and also resolve properties that rely on lazy

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/MockObjectContext.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/MockObjectContext.java?rev=823656&r1=823655&r2=823656&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/MockObjectContext.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/MockObjectContext.java
Fri Oct  9 18:38:51 2009
@@ -94,6 +94,9 @@
     public void deleteObject(Object object) {
     }
 
+    public void deleteObjects(Collection<?> objects) {
+    }
+
     public void registerNewObject(Object object) {
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DeleteObjectTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DeleteObjectTest.java?rev=823656&r1=823655&r2=823656&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DeleteObjectTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DeleteObjectTest.java
Fri Oct  9 18:38:51 2009
@@ -59,7 +59,7 @@
         assertNull(artist.getObjectContext());
     }
 
-    public void testDeleteObjects() throws Exception {
+    public void testDeleteObjects1() throws Exception {
         createTestData("testDeleteObjects");
 
         List artists = context.performQuery(new SelectQuery(Artist.class));
@@ -80,6 +80,27 @@
         }
     }
 
+    // Similar to testDeleteObjects2, but extract ObjectContext instead of DataContext.
+    public void testDeleteObjects2() throws Exception {
+        createTestData("testDeleteObjects");
+
+        List<Artist> artists = context.performQuery(new SelectQuery(Artist.class));
+        assertEquals(2, artists.size());
+
+        for (Artist object : artists)
+            assertEquals(PersistenceState.COMMITTED, object.getPersistenceState());
+
+        artists.get(0).getObjectContext().deleteObjects(artists);
+
+        for (Artist object : artists)
+            assertEquals(PersistenceState.DELETED, object.getPersistenceState());
+
+        artists.get(0).getObjectContext().commitChanges();
+
+        for (Artist object : artists)
+            assertEquals(PersistenceState.TRANSIENT, object.getPersistenceState());
+    }
+
     public void testDeleteObjectsRelationshipCollection() throws Exception {
         createTestData("testDeleteObjectsRelationshipCollection");
 

Modified: cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/test/java/org/apache/cayenne/jpa/MockObjectContext.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/test/java/org/apache/cayenne/jpa/MockObjectContext.java?rev=823656&r1=823655&r2=823656&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/test/java/org/apache/cayenne/jpa/MockObjectContext.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/test/java/org/apache/cayenne/jpa/MockObjectContext.java
Fri Oct  9 18:38:51 2009
@@ -42,6 +42,9 @@
     public void deleteObject(Object object) throws DeleteDenyException {
     }
 
+    public void deleteObjects(Collection<?> objects) {
+    }
+
     public Collection<?> deletedObjects() {
         return null;
     }



Mime
View raw message