cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1164787 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/BaseContext.java main/java/org/apache/cayenne/ObjectContext.java test/java/org/apache/cayenne/MockObjectContext.java
Date Sat, 03 Sep 2011 01:59:31 GMT
Author: aadamchik
Date: Sat Sep  3 01:59:31 2011
New Revision: 1164787

URL: http://svn.apache.org/viewvc?rev=1164787&view=rev
Log:
CAY-1610 ObjectContext API to use varargs

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/ObjectContext.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/MockObjectContext.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=1164787&r1=1164786&r2=1164787&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
Sat Sep  3 01:59:31 2011
@@ -19,6 +19,7 @@
 package org.apache.cayenne;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
@@ -421,8 +422,25 @@ public abstract class BaseContext implem
         }
     }
 
-    public void invalidateObjects(Collection objects) {
-        performGenericQuery(new RefreshQuery(objects));
+    public void invalidateObjects(Collection<?> objects) {
+
+        // don't allow null collections as a matter of coding discipline
+        if (objects == null) {
+            throw new NullPointerException("Null collection of objects to invalidate");
+        }
+
+        if (!objects.isEmpty()) {
+            performGenericQuery(new RefreshQuery(objects));
+        }
+    }
+
+    /**
+     * @since 3.1
+     */
+    public void invalidateObjects(Object... objects) {
+        if (objects != null && objects.length > 0) {
+            performGenericQuery(new RefreshQuery(Arrays.asList(objects)));
+        }
     }
 
     /**
@@ -510,20 +528,39 @@ public abstract class BaseContext implem
      * @throws DeleteDenyException if a DENY delete rule is applicable for object
      *             deletion.
      * @throws NullPointerException if object is null.
+     * @deprecated since 3.1 use {@link #deleteObjects(Object...)} method instead. This
+     *             method is redundant.
      */
     public void deleteObject(Object object) {
-        new ObjectContextDeleteAction(this).performDelete((Persistent) object);
+        deleteObjects(object);
+    }
+
+    /**
+     * @since 3.1
+     */
+    public void deleteObjects(Object... objects) throws DeleteDenyException {
+        if (objects == null || objects.length == 0) {
+            return;
+        }
+
+        ObjectContextDeleteAction action = new ObjectContextDeleteAction(this);
+
+        for (Object object : objects) {
+            action.performDelete((Persistent) object);
+        }
     }
 
     public void deleteObjects(Collection<?> objects) throws DeleteDenyException {
-        if (objects.isEmpty())
+        if (objects.isEmpty()) {
             return;
+        }
 
-        // Don't call deleteObject() directly since it would be less efficient.
-        ObjectContextDeleteAction ocda = new ObjectContextDeleteAction(this);
+        ObjectContextDeleteAction action = new ObjectContextDeleteAction(this);
 
         // Make a copy to iterate over to avoid ConcurrentModificationException.
-        for (Persistent object : (ArrayList<Persistent>) new ArrayList(objects))
-            ocda.performDelete(object);
+        List<Object> copy = new ArrayList<Object>(objects);
+        for (Object object : copy) {
+            action.performDelete((Persistent) object);
+        }
     }
 }
\ No newline at end of file

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=1164787&r1=1164786&r2=1164787&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
Sat Sep  3 01:59:31 2011
@@ -26,7 +26,6 @@ import java.util.List;
 import org.apache.cayenne.graph.GraphManager;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.query.Query;
-import org.apache.cayenne.query.RefreshQuery;
 
 /**
  * A Cayenne object facade to a persistent store. Instances of ObjectContext are used in
@@ -98,16 +97,31 @@ public interface ObjectContext extends S
      * 
      * @throws DeleteDenyException if a {@link org.apache.cayenne.map.DeleteRule#DENY}
      *             delete rule is applicable for object deletion.
+     * @deprecated since 3.1 use {@link #deleteObjects(Object...)} method instead. This
+     *             method is redundant.
      */
     void deleteObject(Object object) throws DeleteDenyException;
 
     /**
-     * Deletes a collection of objects by repeatedly calling deleteObject safely
-     * (avoiding a concurrent modification exception).
+     * Schedules deletion of a collection of persistent objects.
+     * 
+     * @throws DeleteDenyException if a {@link org.apache.cayenne.map.DeleteRule#DENY}
+     *             delete rule is applicable for object deletion.
      */
     void deleteObjects(Collection<?> objects) throws DeleteDenyException;
 
     /**
+     * Schedules deletion of one or more persistent objects. Same as
+     * {@link #deleteObjects(Collection)} only with a vararg argument list for easier
+     * deletion of individual objects.
+     * 
+     * @throws DeleteDenyException if a {@link org.apache.cayenne.map.DeleteRule#DENY}
+     *             delete rule is applicable for object deletion.
+     * @since 3.1
+     */
+    void deleteObjects(Object... 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
@@ -195,10 +209,18 @@ public interface ObjectContext extends S
      * objects already committed to the database and does nothing to the NEW objects. It
      * would remove each object's snapshot from caches and change object's state to
      * HOLLOW. On the next access to this object, the object will be refetched.
+     */
+    void invalidateObjects(Collection<?> objects);
+
+    /**
+     * Invalidates one or more persistent objects. Same as
+     * {@link #invalidateObjects(Collection)} only with a vararg argument list for easier
+     * invalidation of individual objects. If no arguments are passed to this method, it
+     * does nothing.
      * 
-     * @see RefreshQuery
+     * @since 3.1
      */
-    void invalidateObjects(Collection objects);
+    void invalidateObjects(Object... objects);
 
     /**
      * Returns a user-defined property previously set via 'setUserProperty'. Note that it

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=1164787&r1=1164786&r2=1164787&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
Sat Sep  3 01:59:31 2011
@@ -90,11 +90,17 @@ public class MockObjectContext implement
 
     }
 
+    /**
+     * @deprecated since 3.1
+     */
     public void deleteObject(Object object) {
     }
 
     public void deleteObjects(Collection<?> objects) {
     }
+    
+    public void deleteObjects(Object... objects) throws DeleteDenyException {
+    }
 
     public void registerNewObject(Object object) {
     }
@@ -141,7 +147,10 @@ public class MockObjectContext implement
         return false;
     }
 
-    public void invalidateObjects(Collection objects) {
+    public void invalidateObjects(Collection<?> objects) {
+    }
+    
+    public void invalidateObjects(Object... objects) {
     }
 
     public Object getUserProperty(String key) {



Mime
View raw message