cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1486125 [1/3] - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/ main/java/org/apache/cayenne/access/ main/java/org/apache/cayenne/access/jdbc/ main/java/org/apache/cayenne/access/util/ test/ja...
Date Fri, 24 May 2013 17:31:14 GMT
Author: aadamchik
Date: Fri May 24 17:31:14 2013
New Revision: 1486125

URL: http://svn.apache.org/r1486125
Log:
CAY-1829 Make ResultIterator implement Iterable<T>, create ObjectContext.iterate method

(lots of generics ugliness under the hood... hope this compiles on Java 7..)

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/CollectionResultIterator.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/ObjectContext.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/DataDomainFlushObserver.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataPort.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ResultIterator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/TransactionResultIteratorDecorator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BaseRowReader.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BaseSQLAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/CompoundRowReader.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/DistinctResultIterator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EntityRowReader.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/FullRowReader.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/IdRowReader.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/JDBCResultIterator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/LimitResultIterator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/RowReader.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ScalarRowReader.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/util/DefaultOperationObserver.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/MockBaseContext.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=1486125&r1=1486124&r2=1486125&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 Fri May 24 17:31:14 2013
@@ -25,6 +25,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
+import org.apache.cayenne.access.ResultIterator;
 import org.apache.cayenne.cache.NestedQueryCache;
 import org.apache.cayenne.cache.QueryCache;
 import org.apache.cayenne.configuration.CayenneRuntime;
@@ -282,7 +283,6 @@ public abstract class BaseContext implem
 
     public abstract QueryResponse performGenericQuery(Query query);
 
-    @SuppressWarnings("unchecked")
     public abstract List performQuery(Query query);
 
     @SuppressWarnings("unchecked")
@@ -290,6 +290,11 @@ public abstract class BaseContext implem
     	return performQuery(query);
     }
     
+    /**
+     * @since 3.2
+     */
+    public abstract <T> ResultIterator<T> iterate(Select<T> query);
+    
     public void prepareForAccess(Persistent object, String property, boolean lazyFaulting) {
         if (object.getPersistenceState() == PersistenceState.HOLLOW) {
 

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=1486125&r1=1486124&r2=1486125&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 May 24 17:31:14 2013
@@ -24,20 +24,23 @@ import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.cayenne.access.ResultIterator;
+import org.apache.cayenne.access.jdbc.CollectionResultIterator;
 import org.apache.cayenne.event.EventManager;
 import org.apache.cayenne.graph.CompoundDiff;
 import org.apache.cayenne.graph.GraphDiff;
 import org.apache.cayenne.graph.GraphManager;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.query.Query;
+import org.apache.cayenne.query.Select;
 import org.apache.cayenne.reflect.ClassDescriptor;
 import org.apache.cayenne.util.EventUtil;
 import org.apache.cayenne.validation.ValidationException;
 import org.apache.cayenne.validation.ValidationResult;
 
 /**
- * A default generic implementation of ObjectContext suitable for accessing Cayenne from
- * either an ORM or a client tiers. Communicates with Cayenne via a
+ * A default generic implementation of ObjectContext suitable for accessing
+ * Cayenne from either an ORM or a client tiers. Communicates with Cayenne via a
  * {@link org.apache.cayenne.DataChannel}.
  * 
  * @since 1.2
@@ -58,8 +61,8 @@ public class CayenneContext extends Base
 
     /**
      * Creates a new CayenneContext, initializing it with a channel instance.
-     * CayenneContext created using this constructor WILL NOT broadcast graph change
-     * events.
+     * CayenneContext created using this constructor WILL NOT broadcast graph
+     * change events.
      */
     public CayenneContext(DataChannel channel) {
         this(channel, false, false);
@@ -68,13 +71,9 @@ public class CayenneContext extends Base
     /**
      * Creates a new CayenneContext, initializing it with a channel.
      */
-    public CayenneContext(DataChannel channel, boolean changeEventsEnabled,
-            boolean lifecyleEventsEnabled) {
+    public CayenneContext(DataChannel channel, boolean changeEventsEnabled, boolean lifecyleEventsEnabled) {
 
-        graphManager = new CayenneContextGraphManager(
-                this,
-                changeEventsEnabled,
-                lifecyleEventsEnabled);
+        graphManager = new CayenneContextGraphManager(this, changeEventsEnabled, lifecyleEventsEnabled);
 
         if (channel != null) {
             attachToChannel(channel);
@@ -98,23 +97,25 @@ public class CayenneContext extends Base
             mergeHandler = new CayenneContextMergeHandler(this);
 
             // listen to our channel events...
-            // note that we must reset listener on channel switch, as there is no
+            // note that we must reset listener on channel switch, as there is
+            // no
             // guarantee that a new channel uses the same EventManager.
             EventUtil.listenForChannelEvents(channel, mergeHandler);
         }
     }
 
     /**
-     * Returns true if this context posts individual object modification events. Subject
-     * used for these events is <code>ObjectContext.GRAPH_CHANGED_SUBJECT</code>.
+     * Returns true if this context posts individual object modification events.
+     * Subject used for these events is
+     * <code>ObjectContext.GRAPH_CHANGED_SUBJECT</code>.
      */
     public boolean isChangeEventsEnabled() {
         return graphManager.changeEventsEnabled;
     }
 
     /**
-     * Returns true if this context posts lifecycle events. Subjects used for these events
-     * are
+     * Returns true if this context posts lifecycle events. Subjects used for
+     * these events are
      * <code>ObjectContext.GRAPH_COMMIT_STARTED_SUBJECT, ObjectContext.GRAPH_COMMITTED_SUBJECT,
      * ObjectContext.GRAPH_COMMIT_ABORTED_SUBJECT, ObjectContext.GRAPH_ROLLEDBACK_SUBJECT.</code>
      * .
@@ -133,9 +134,9 @@ public class CayenneContext extends Base
     }
 
     /**
-     * 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
-     * service via an internal instance of CayenneConnector.
+     * 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 service via an internal instance of CayenneConnector.
      */
     @Override
     public void commitChanges() {
@@ -144,9 +145,7 @@ public class CayenneContext extends Base
 
     GraphDiff doCommitChanges(boolean cascade) {
 
-        int syncType = cascade
-                ? DataChannel.FLUSH_CASCADE_SYNC
-                : DataChannel.FLUSH_NOCASCADE_SYNC;
+        int syncType = cascade ? DataChannel.FLUSH_CASCADE_SYNC : DataChannel.FLUSH_NOCASCADE_SYNC;
 
         GraphDiff commitDiff = null;
 
@@ -161,15 +160,15 @@ public class CayenneContext extends Base
                         Persistent p = (Persistent) it.next();
                         if (p instanceof Validating) {
                             switch (p.getPersistenceState()) {
-                                case PersistenceState.NEW:
-                                    ((Validating) p).validateForInsert(result);
-                                    break;
-                                case PersistenceState.MODIFIED:
-                                    ((Validating) p).validateForUpdate(result);
-                                    break;
-                                case PersistenceState.DELETED:
-                                    ((Validating) p).validateForDelete(result);
-                                    break;
+                            case PersistenceState.NEW:
+                                ((Validating) p).validateForInsert(result);
+                                break;
+                            case PersistenceState.MODIFIED:
+                                ((Validating) p).validateForUpdate(result);
+                                break;
+                            case PersistenceState.DELETED:
+                                ((Validating) p).validateForDelete(result);
+                                break;
                             }
                         }
                     }
@@ -185,21 +184,20 @@ public class CayenneContext extends Base
 
                 try {
                     commitDiff = channel.onSync(this, changes, syncType);
-                }
-                catch (Throwable th) {
+                } catch (Throwable th) {
                     graphManager.graphCommitAborted();
 
                     if (th instanceof CayenneRuntimeException) {
                         throw (CayenneRuntimeException) th;
-                    }
-                    else {
+                    } else {
                         throw new CayenneRuntimeException("Commit error", th);
                     }
                 }
 
                 graphManager.graphCommitted(commitDiff);
 
-                // this event is caught by peer nested ObjectContexts to synchronize the
+                // this event is caught by peer nested ObjectContexts to
+                // synchronize the
                 // state
                 fireDataChannelCommitted(this, changes);
             }
@@ -250,12 +248,10 @@ public class CayenneContext extends Base
 
         ObjEntity entity = getEntityResolver().lookupObjEntity(persistentClass);
         if (entity == null) {
-            throw new CayenneRuntimeException("No entity mapped for class: "
-                    + persistentClass);
+            throw new CayenneRuntimeException("No entity mapped for class: " + persistentClass);
         }
 
-        ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(
-                entity.getName());
+        ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(entity.getName());
         T object = (T) descriptor.createObject();
         descriptor.injectValueHolders(object);
         registerNewObject((Persistent) object, entity.getName(), descriptor);
@@ -272,8 +268,7 @@ public class CayenneContext extends Base
         }
 
         ObjEntity entity = getEntityResolver().lookupObjEntity(object.getClass());
-        ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(
-                entity.getName());
+        ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(entity.getName());
         registerNewObject((Persistent) object, entity.getName(), descriptor);
     }
 
@@ -326,13 +321,10 @@ public class CayenneContext extends Base
 
     // ****** non-public methods ******
 
-    void registerNewObject(
-            Persistent object,
-            String entityName,
-            ClassDescriptor descriptor) {
+    void registerNewObject(Persistent object, String entityName, ClassDescriptor descriptor) {
         /**
-         * We should create new id only if it is not set for this object. It could have
-         * been created, for instance, in child context
+         * We should create new id only if it is not set for this object. It
+         * could have been created, for instance, in child context
          */
         ObjectId id = object.getObjectId();
         if (id == null) {
@@ -344,8 +336,7 @@ public class CayenneContext extends Base
     }
 
     Persistent createFault(ObjectId id) {
-        ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(
-                id.getEntityName());
+        ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(id.getEntityName());
 
         Persistent object;
         synchronized (graphManager) {
@@ -362,10 +353,7 @@ public class CayenneContext extends Base
     }
 
     @Override
-    protected GraphDiff onContextFlush(
-            ObjectContext originatingContext,
-            GraphDiff changes,
-            boolean cascade) {
+    protected GraphDiff onContextFlush(ObjectContext originatingContext, GraphDiff changes, boolean cascade) {
 
         boolean childContext = this != originatingContext && changes != null;
 
@@ -376,8 +364,7 @@ public class CayenneContext extends Base
             // setPropertyChangeProcessingStrategy(PropertyChangeProcessingStrategy.RECORD);
             try {
                 changes.apply(new CayenneContextChildDiffLoader(this));
-            }
-            finally {
+            } finally {
                 // setPropertyChangeProcessingStrategy(oldStrategy);
             }
 
@@ -388,10 +375,23 @@ public class CayenneContext extends Base
     }
 
     /**
-     * Returns <code>true</code> if there are any modified, deleted or new objects
-     * registered with this CayenneContext, <code>false</code> otherwise.
+     * Returns <code>true</code> if there are any modified, deleted or new
+     * objects registered with this CayenneContext, <code>false</code>
+     * otherwise.
      */
     public boolean hasChanges() {
         return graphManager.hasChanges();
     }
+
+    /**
+     * This method simply returns an iterator over a list of selected objects.
+     * There's no performance benefit of using it vs. regular "select".
+     * 
+     * @since 3.2
+     */
+    @Override
+    public <T> ResultIterator<T> iterate(Select<T> query) {
+        List<T> objects = select(query);
+        return new CollectionResultIterator<T>(objects);
+    }
 }

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=1486125&r1=1486124&r2=1486125&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 May 24 17:31:14 2013
@@ -23,40 +23,41 @@ import java.io.Serializable;
 import java.util.Collection;
 import java.util.List;
 
+import org.apache.cayenne.access.ResultIterator;
 import org.apache.cayenne.graph.GraphManager;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.Select;
 
 /**
- * A Cayenne object facade to a persistent store. Instances of ObjectContext are used in
- * the application code to access Cayenne persistence features.
+ * A Cayenne object facade to a persistent store. Instances of ObjectContext are
+ * used in the application code to access Cayenne persistence features.
  * 
  * @since 1.2
  */
 public interface ObjectContext extends Serializable {
 
     /**
-     * Returns EntityResolver that stores all mapping information accessible by this
-     * ObjectContext.
+     * Returns EntityResolver that stores all mapping information accessible by
+     * this ObjectContext.
      */
     EntityResolver getEntityResolver();
 
     /**
-     * Returns a collection of objects that are registered with this ObjectContext and
-     * have a state PersistenceState.NEW
+     * Returns a collection of objects that are registered with this
+     * ObjectContext and have a state PersistenceState.NEW
      */
     Collection<?> newObjects();
 
     /**
-     * Returns a collection of objects that are registered with this ObjectContext and
-     * have a state PersistenceState.DELETED
+     * Returns a collection of objects that are registered with this
+     * ObjectContext and have a state PersistenceState.DELETED
      */
     Collection<?> deletedObjects();
 
     /**
-     * Returns a collection of objects that are registered with this ObjectContext and
-     * have a state PersistenceState.MODIFIED
+     * Returns a collection of objects that are registered with this
+     * ObjectContext and have a state PersistenceState.MODIFIED
      */
     Collection<?> modifiedObjects();
 
@@ -66,10 +67,11 @@ public interface ObjectContext extends S
     Collection<?> uncommittedObjects();
 
     /**
-     * Returns a local copy of 'objectFromAnotherContext' object. "Local" means that the
-     * returned object is registered in this context. If the local object hasn't been
-     * previously cached in this context, a hollow object is created and returned to the
-     * caller. No DB query is performed to resolve an object.
+     * Returns a local copy of 'objectFromAnotherContext' object. "Local" means
+     * that the returned object is registered in this context. If the local
+     * object hasn't been previously cached in this context, a hollow object is
+     * created and returned to the caller. No DB query is performed to resolve
+     * an object.
      * <p>
      * Note that passing an object with a non-existing id, may later result in
      * FaultFailureException on attempt to read returned object properties.
@@ -79,17 +81,19 @@ public interface ObjectContext extends S
     <T> T localObject(T objectFromAnotherContext);
 
     /**
-     * Creates a new persistent object of a given class scheduled to be inserted to the
-     * database on next commit.
+     * Creates a new persistent object of a given class scheduled to be inserted
+     * to the database on next commit.
      */
     <T> T newObject(Class<T> 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.
+     * {@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.
+     * @param object
+     *            new object that needs to be made persistent.
      * @since 3.0
      */
     void registerNewObject(Object object);
@@ -97,86 +101,97 @@ public interface ObjectContext extends S
     /**
      * 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.
+     * @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.
+     * {@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.
+     * @throws DeleteDenyException
+     *             if a {@link org.apache.cayenne.map.DeleteRule#DENY} delete
+     *             rule is applicable for object deletion.
      * @since 3.1
      */
     <T> void deleteObjects(T... 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
-     * faulting.
+     * 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 faulting.
      * 
      * @since 3.0
      */
     void prepareForAccess(Persistent object, String property, boolean lazyFaulting);
 
     /**
-     * A callback method that child Persistent objects are expected to call from inside
-     * the setter after modifying a value of a persistent property, including "simple" and
-     * "arc" properties.
-     */
-    void propertyChanged(
-            Persistent object,
-            String property,
-            Object oldValue,
-            Object newValue);
+     * A callback method that child Persistent objects are expected to call from
+     * inside the setter after modifying a value of a persistent property,
+     * including "simple" and "arc" properties.
+     */
+    void propertyChanged(Persistent object, String property, Object oldValue, Object newValue);
 
     /**
-     * Flushes all changes to objects in this context to the parent DataChannel, cascading
-     * flush operation all the way through the stack, ultimately saving data in the
-     * database.
+     * Flushes all changes to objects in this context to the parent DataChannel,
+     * cascading flush operation all the way through the stack, ultimately
+     * saving data in the database.
      */
     void commitChanges();
 
     /**
-     * Flushes all changes to objects in this context to the parent DataChannel. Same as
-     * {@link #commitChanges()}, but no cascading flush occurs.
+     * Flushes all changes to objects in this context to the parent DataChannel.
+     * Same as {@link #commitChanges()}, but no cascading flush occurs.
      */
     void commitChangesToParent();
 
     /**
-     * Resets all uncommitted changes made to the objects in this ObjectContext, cascading
-     * rollback operation all the way through the stack.
+     * Resets all uncommitted changes made to the objects in this ObjectContext,
+     * cascading rollback operation all the way through the stack.
      */
     void rollbackChanges();
 
     /**
-     * Resets all uncommitted changes made to the objects in this ObjectContext. Same as
-     * {@link #rollbackChanges()()}, but rollback is local to this context and no
-     * cascading changes undoing occurs.
+     * Resets all uncommitted changes made to the objects in this ObjectContext.
+     * Same as {@link #rollbackChanges()()}, but rollback is local to this
+     * context and no cascading changes undoing occurs.
      */
     void rollbackChangesLocally();
 
     /**
-     * Executes a selecting query, returning a list of persistent objects or data rows.
+     * Executes a selecting query, returning a list of persistent objects or
+     * data rows.
      */
     List performQuery(Query query);
 
     /**
-     * Executes a selecting query, returning a list of persistent objects or data rows.
+     * Executes a selecting query, returning a list of persistent objects or
+     * data rows.
      */
     <T> List<T> select(Select<T> query);
-    
+
+    /**
+     * Returns an iterable object over the open result set. Note that teration
+     * must be wrapped in try/finally, and ResultIterator must be explicitly
+     * closed when iteration is finished.
+     * 
+     * @since 3.2
+     */
+    <T> ResultIterator<T> iterate(Select<T> query);
+
     /**
-     * Executes any kind of query providing the result in a form of QueryResponse.
+     * Executes any kind of query providing the result in a form of
+     * QueryResponse.
      */
     QueryResponse performGenericQuery(Query query);
 
     /**
-     * Returns GraphManager that manages object graph associated with this context.
+     * Returns GraphManager that manages object graph associated with this
+     * context.
      */
     GraphManager getGraphManager();
 
@@ -186,42 +201,44 @@ public interface ObjectContext extends S
     DataChannel getChannel();
 
     /**
-     * Returns <code>true</code> if there are any modified, deleted or new objects
-     * registered with this ObjectContext, <code>false</code> otherwise.
+     * Returns <code>true</code> if there are any modified, deleted or new
+     * objects registered with this ObjectContext, <code>false</code> otherwise.
      * 
      * @since 3.0
      */
     boolean hasChanges();
 
     /**
-     * Invalidates a Collection of persistent objects. This operation only applies to the
-     * 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.
+     * Invalidates a Collection of persistent objects. This operation only
+     * applies to the 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.
+     * {@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.
      * 
      * @since 3.1
      */
     <T> void invalidateObjects(T... objects);
 
     /**
-     * Returns a user-defined property previously set via 'setUserProperty'. Concurrent
-     * access to properties does not require any special synchronization
+     * Returns a user-defined property previously set via 'setUserProperty'.
+     * Concurrent access to properties does not require any special
+     * synchronization
      * 
      * @since 3.0
      */
     Object getUserProperty(String key);
 
     /**
-     * Sets a user-defined property. Concurrent access to properties does not require any
-     * special synchronization
+     * Sets a user-defined property. Concurrent access to properties does not
+     * require any special synchronization
      * 
      * @since 3.0
      */

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=1486125&r1=1486124&r2=1486125&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 Fri May 24 17:31:14 2013
@@ -55,6 +55,7 @@ import org.apache.cayenne.map.ObjRelatio
 import org.apache.cayenne.query.NamedQuery;
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.QueryMetadata;
+import org.apache.cayenne.query.Select;
 import org.apache.cayenne.reflect.AttributeProperty;
 import org.apache.cayenne.reflect.ClassDescriptor;
 import org.apache.cayenne.reflect.PropertyVisitor;
@@ -65,10 +66,10 @@ import org.apache.cayenne.util.GenericRe
 import org.apache.cayenne.util.Util;
 
 /**
- * The most common implementation of {@link ObjectContext}. DataContext is an isolated
- * container of an object graph, in a sense that any uncommitted changes to persistent
- * objects that are registered with the context, are not visible to the users of other
- * contexts.
+ * The most common implementation of {@link ObjectContext}. DataContext is an
+ * isolated container of an object graph, in a sense that any uncommitted
+ * changes to persistent objects that are registered with the context, are not
+ * visible to the users of other contexts.
  */
 public class DataContext extends BaseContext {
 
@@ -128,7 +129,8 @@ public class DataContext extends BaseCon
             mergeHandler = new DataContextMergeHandler(this);
 
             // listen to our channel events...
-            // note that we must reset listener on channel switch, as there is no
+            // note that we must reset listener on channel switch, as there is
+            // no
             // guarantee that a new channel uses the same EventManager.
             EventUtil.listenForChannelEvents(channel, mergeHandler);
         }
@@ -143,12 +145,12 @@ public class DataContext extends BaseCon
     }
 
     /**
-     * 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
-     * returned.
+     * 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 returned.
      * 
-     * @return DataDomain that is a direct or indirect parent of this DataContext in the
-     *         DataChannel hierarchy.
+     * @return DataDomain that is a direct or indirect parent of this
+     *         DataContext in the DataChannel hierarchy.
      * @since 1.1
      */
     public DataDomain getParentDataDomain() {
@@ -164,9 +166,7 @@ public class DataContext extends BaseCon
 
         List response = channel.onQuery(this, new DataDomainQuery()).firstList();
 
-        if (response != null
-                && response.size() > 0
-                && response.get(0) instanceof DataDomain) {
+        if (response != null && response.size() > 0 && response.get(0) instanceof DataDomain) {
             return (DataDomain) response.get(0);
         }
 
@@ -174,8 +174,9 @@ public class DataContext extends BaseCon
     }
 
     /**
-     * Sets a DataContextDelegate for this context. Delegate is notified of certain events
-     * in the DataContext lifecycle and can customize DataContext behavior.
+     * Sets a DataContextDelegate for this context. Delegate is notified of
+     * certain events in the DataContext lifecycle and can customize DataContext
+     * behavior.
      * 
      * @since 1.1
      */
@@ -193,9 +194,9 @@ public class DataContext extends BaseCon
     }
 
     /**
-     * @return a delegate instance if it is initialized, or a shared noop implementation
-     *         the context has no delegate. Useful to prevent extra null checks and
-     *         conditional logic in the code.
+     * @return a delegate instance if it is initialized, or a shared noop
+     *         implementation the context has no delegate. Useful to prevent
+     *         extra null checks and conditional logic in the code.
      * @since 1.1
      */
     DataContextDelegate nonNullDelegate() {
@@ -210,16 +211,16 @@ public class DataContext extends BaseCon
     }
 
     /**
-     * Returns <code>true</code> if there are any modified, deleted or new objects
-     * registered with this DataContext, <code>false</code> otherwise.
+     * Returns <code>true</code> if there are any modified, deleted or new
+     * objects registered with this DataContext, <code>false</code> otherwise.
      */
     public boolean hasChanges() {
         return getObjectStore().hasChanges();
     }
 
     /**
-     * Returns a list of objects that are registered with this DataContext and have a
-     * state PersistenceState.NEW
+     * Returns a list of objects that are registered with this DataContext and
+     * have a state PersistenceState.NEW
      */
     @Override
     public Collection<?> newObjects() {
@@ -227,8 +228,8 @@ public class DataContext extends BaseCon
     }
 
     /**
-     * Returns a list of objects that are registered with this DataContext and have a
-     * state PersistenceState.DELETED
+     * Returns a list of objects that are registered with this DataContext and
+     * have a state PersistenceState.DELETED
      */
     @Override
     public Collection<?> deletedObjects() {
@@ -236,8 +237,8 @@ public class DataContext extends BaseCon
     }
 
     /**
-     * Returns a list of objects that are registered with this DataContext and have a
-     * state PersistenceState.MODIFIED
+     * Returns a list of objects that are registered with this DataContext and
+     * have a state PersistenceState.MODIFIED
      */
     @Override
     public Collection<?> modifiedObjects() {
@@ -264,8 +265,7 @@ public class DataContext extends BaseCon
         while (it.hasNext()) {
             Persistent object = (Persistent) it.next();
             int state = object.getPersistenceState();
-            if (state == PersistenceState.MODIFIED
-                    || state == PersistenceState.NEW
+            if (state == PersistenceState.MODIFIED || state == PersistenceState.NEW
                     || state == PersistenceState.DELETED) {
 
                 objects.add(object);
@@ -278,10 +278,10 @@ public class DataContext extends BaseCon
     /**
      * Returns a DataRow reflecting current, possibly uncommitted, object state.
      * <p>
-     * <strong>Warning:</strong> This method will return a partial snapshot if an object
-     * or one of its related objects that propagate their keys to this object have
-     * temporary ids. DO NOT USE this method if you expect a DataRow to represent a
-     * complete object state.
+     * <strong>Warning:</strong> This method will return a partial snapshot if
+     * an object or one of its related objects that propagate their keys to this
+     * object have temporary ids. DO NOT USE this method if you expect a DataRow
+     * to represent a complete object state.
      * </p>
      * 
      * @since 1.1
@@ -289,15 +289,13 @@ public class DataContext extends BaseCon
     public DataRow currentSnapshot(final Persistent object) {
 
         // for a HOLLOW object return snapshot from cache
-        if (object.getPersistenceState() == PersistenceState.HOLLOW
-                && object.getObjectContext() != null) {
+        if (object.getPersistenceState() == PersistenceState.HOLLOW && object.getObjectContext() != null) {
 
             return getObjectStore().getSnapshot(object.getObjectId());
         }
 
         ObjEntity entity = getEntityResolver().lookupObjEntity(object);
-        final ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(
-                entity.getName());
+        final ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(entity.getName());
         final DataRow snapshot = new DataRow(10);
 
         descriptor.visitProperties(new PropertyVisitor() {
@@ -306,9 +304,7 @@ public class DataContext extends BaseCon
                 ObjAttribute objAttr = property.getAttribute();
 
                 // processing compound attributes correctly
-                snapshot.put(
-                        objAttr.getDbAttributePath(),
-                        property.readPropertyDirectly(object));
+                snapshot.put(objAttr.getDbAttributePath(), property.readPropertyDirectly(object));
                 return true;
             }
 
@@ -333,13 +329,10 @@ public class DataContext extends BaseCon
                 // if target is Fault, get id attributes from stored snapshot
                 // to avoid unneeded fault triggering
                 if (targetObject instanceof Fault) {
-                    DataRow storedSnapshot = getObjectStore().getSnapshot(
-                            object.getObjectId());
+                    DataRow storedSnapshot = getObjectStore().getSnapshot(object.getObjectId());
                     if (storedSnapshot == null) {
-                        throw new CayenneRuntimeException(
-                                "No matching objects found for ObjectId "
-                                        + object.getObjectId()
-                                        + ". Object may have been deleted externally.");
+                        throw new CayenneRuntimeException("No matching objects found for ObjectId "
+                                + object.getObjectId() + ". Object may have been deleted externally.");
                     }
 
                     DbRelationship dbRel = rel.getDbRelationships().get(0);
@@ -356,7 +349,8 @@ public class DataContext extends BaseCon
                 Persistent target = (Persistent) targetObject;
                 Map<String, Object> idParts = target.getObjectId().getIdSnapshot();
 
-                // this may happen in uncommitted objects - see the warning in the JavaDoc
+                // this may happen in uncommitted objects - see the warning in
+                // the JavaDoc
                 // of
                 // this method.
                 if (idParts.isEmpty()) {
@@ -395,26 +389,22 @@ public class DataContext extends BaseCon
      * 
      * @since 3.0
      */
-    public List objectsFromDataRows(
-            ClassDescriptor descriptor,
-            List<? extends DataRow> dataRows) {
-        // TODO: If data row cache is not available it means that current data context is
-        // child. We need to redirect this method call to parent data context as an
-        // internal query. It is not obvious and has some overhead. Redesign for nested
+    public List objectsFromDataRows(ClassDescriptor descriptor, List<? extends DataRow> dataRows) {
+        // TODO: If data row cache is not available it means that current data
+        // context is
+        // child. We need to redirect this method call to parent data context as
+        // an
+        // internal query. It is not obvious and has some overhead. Redesign for
+        // nested
         // contexts should be done.
         if (getObjectStore().getDataRowCache() == null) {
             return objectsFromDataRowsFromParentContext(descriptor, dataRows);
         }
-        return new ObjectResolver(this, descriptor, true)
-                .synchronizedObjectsFromDataRows(dataRows);
+        return new ObjectResolver(this, descriptor, true).synchronizedObjectsFromDataRows(dataRows);
     }
 
-    private List objectsFromDataRowsFromParentContext(
-            ClassDescriptor descriptor,
-            List<? extends DataRow> dataRows) {
-        return getChannel().onQuery(
-                this,
-                new ObjectsFromDataRowsQuery(descriptor, dataRows)).firstList();
+    private List objectsFromDataRowsFromParentContext(ClassDescriptor descriptor, List<? extends DataRow> dataRows) {
+        return getChannel().onQuery(this, new ObjectsFromDataRowsQuery(descriptor, dataRows)).firstList();
     }
 
     /**
@@ -423,24 +413,21 @@ public class DataContext extends BaseCon
      * @see DataRow
      * @since 3.1
      */
-    public <T extends DataObject> T objectFromDataRow(
-            Class<T> objectClass,
-            DataRow dataRow) {
+    public <T extends DataObject> T objectFromDataRow(Class<T> objectClass, DataRow dataRow) {
         ObjEntity entity = this.getEntityResolver().lookupObjEntity(objectClass);
 
         if (entity == null) {
             throw new CayenneRuntimeException("Unmapped Java class: " + objectClass);
         }
 
-        ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(
-                entity.getName());
+        ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(entity.getName());
         List<T> list = objectsFromDataRows(descriptor, Collections.singletonList(dataRow));
         return list.get(0);
     }
 
     /**
-     * Creates a DataObject from DataRow. This variety of the 'objectFromDataRow' method
-     * is normally used for generic classes.
+     * Creates a DataObject from DataRow. This variety of the
+     * 'objectFromDataRow' method is normally used for generic classes.
      * 
      * @see DataRow
      * @since 3.1
@@ -465,19 +452,20 @@ public class DataContext extends BaseCon
 
         ObjEntity entity = getEntityResolver().lookupObjEntity(persistentClass);
         if (entity == null) {
-            throw new IllegalArgumentException("Class is not mapped with Cayenne: "
-                    + persistentClass.getName());
+            throw new IllegalArgumentException("Class is not mapped with Cayenne: " + persistentClass.getName());
         }
 
         return (T) newObject(entity.getName());
     }
 
     /**
-     * Instantiates a new object and registers it with this context. Object class is
-     * determined from the mapped entity. Object class must have a default constructor.
+     * Instantiates a new object and registers it with this context. Object
+     * class is determined from the mapped entity. Object class must have a
+     * default constructor.
      * <p/>
-     * <i>Note: in most cases {@link #newObject(Class)} method should be used, however
-     * this method is helpful when generic persistent classes are used.</i>
+     * <i>Note: in most cases {@link #newObject(Class)} method should be used,
+     * however this method is helpful when generic persistent classes are
+     * used.</i>
      * 
      * @since 3.0
      */
@@ -490,8 +478,7 @@ public class DataContext extends BaseCon
         Persistent object;
         try {
             object = (Persistent) descriptor.createObject();
-        }
-        catch (Exception ex) {
+        } catch (Exception ex) {
             throw new CayenneRuntimeException("Error instantiating object.", ex);
         }
 
@@ -500,7 +487,8 @@ public class DataContext extends BaseCon
 
         ObjectId id = new ObjectId(entityName);
 
-        // note that the order of initialization of persistence artifacts below is
+        // note that the order of initialization of persistence artifacts below
+        // is
         // important - do not change it lightly
         object.setObjectId(id);
 
@@ -510,13 +498,15 @@ public class DataContext extends BaseCon
     }
 
     /**
-     * Registers a transient object with the context, recursively registering all
-     * transient persistent objects attached to this object via relationships.
+     * Registers a transient object with the context, recursively registering
+     * all transient persistent objects attached to this object via
+     * relationships.
      * <p/>
-     * <i>Note that since 3.0 this method takes Object as an argument instead of a
-     * {@link DataObject}.</i>
+     * <i>Note that since 3.0 this method takes Object as an argument instead of
+     * a {@link DataObject}.</i>
      * 
-     * @param object new object that needs to be made persistent.
+     * @param object
+     *            new object that needs to be made persistent.
      */
     @Override
     public void registerNewObject(Object object) {
@@ -526,10 +516,8 @@ public class DataContext extends BaseCon
 
         ObjEntity entity = getEntityResolver().lookupObjEntity(object);
         if (entity == null) {
-            throw new IllegalArgumentException(
-                    "Can't find ObjEntity for Persistent class: "
-                            + object.getClass().getName()
-                            + ", class is likely not mapped.");
+            throw new IllegalArgumentException("Can't find ObjEntity for Persistent class: "
+                    + object.getClass().getName() + ", class is likely not mapped.");
         }
 
         final Persistent persistent = (Persistent) object;
@@ -539,26 +527,23 @@ public class DataContext extends BaseCon
             if (persistent.getObjectContext() == this) {
                 // already registered, just ignore
                 return;
+            } else if (persistent.getObjectContext() != null) {
+                throw new IllegalStateException("Persistent is already registered with another DataContext. "
+                        + "Try using 'localObjects()' instead.");
             }
-            else if (persistent.getObjectContext() != null) {
-                throw new IllegalStateException(
-                        "Persistent is already registered with another DataContext. "
-                                + "Try using 'localObjects()' instead.");
-            }
-        }
-        else {
+        } else {
             persistent.setObjectId(new ObjectId(entity.getName()));
         }
 
-        ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(
-                entity.getName());
+        ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(entity.getName());
         if (descriptor == null) {
             throw new IllegalArgumentException("Invalid entity name: " + entity.getName());
         }
 
         injectInitialValue(object);
 
-        // now we need to find all arc changes, inject missing value holders and pull in
+        // now we need to find all arc changes, inject missing value holders and
+        // pull in
         // all transient connected objects
 
         descriptor.visitProperties(new PropertyVisitor() {
@@ -569,8 +554,7 @@ public class DataContext extends BaseCon
                 if (!property.isFault(persistent)) {
 
                     Object value = property.readProperty(persistent);
-                    Collection<Map.Entry> collection = (value instanceof Map)
-                            ? ((Map) value).entrySet()
+                    Collection<Map.Entry> collection = (value instanceof Map) ? ((Map) value).entrySet()
                             : (Collection) value;
 
                     Iterator<Map.Entry> it = collection.iterator();
@@ -582,9 +566,7 @@ public class DataContext extends BaseCon
 
                             // make sure it is registered
                             registerNewObject(targetDO);
-                            getObjectStore().arcCreated(
-                                    persistent.getObjectId(),
-                                    targetDO.getObjectId(),
+                            getObjectStore().arcCreated(persistent.getObjectId(), targetDO.getObjectId(),
                                     property.getName());
                         }
                     }
@@ -601,10 +583,7 @@ public class DataContext extends BaseCon
 
                     // make sure it is registered
                     registerNewObject(targetDO);
-                    getObjectStore().arcCreated(
-                            persistent.getObjectId(),
-                            targetDO.getObjectId(),
-                            property.getName());
+                    getObjectStore().arcCreated(persistent.getObjectId(), targetDO.getObjectId(), property.getName());
                 }
                 return true;
             }
@@ -616,9 +595,9 @@ public class DataContext extends BaseCon
     }
 
     /**
-     * Unregisters a Collection of DataObjects from the DataContext and the underlying
-     * ObjectStore. This operation also unsets DataContext and ObjectId for each object
-     * and changes its state to TRANSIENT.
+     * Unregisters a Collection of DataObjects from the DataContext and the
+     * underlying ObjectStore. This operation also unsets DataContext and
+     * ObjectId for each object and changes its state to TRANSIENT.
      * 
      * @see #invalidateObjects(Collection)
      */
@@ -627,8 +606,9 @@ public class DataContext extends BaseCon
     }
 
     /**
-     * If the parent channel is a DataContext, reverts local changes to make this context
-     * look like the parent, if the parent channel is a DataDomain, reverts all changes.
+     * If the parent channel is a DataContext, reverts local changes to make
+     * this context look like the parent, if the parent channel is a DataDomain,
+     * reverts all changes.
      * 
      * @since 1.2
      */
@@ -643,8 +623,8 @@ public class DataContext extends BaseCon
     }
 
     /**
-     * Reverts any changes that have occurred to objects registered with DataContext; also
-     * performs cascading rollback of all parent DataContexts.
+     * Reverts any changes that have occurred to objects registered with
+     * DataContext; also performs cascading rollback of all parent DataContexts.
      */
     @Override
     public void rollbackChanges() {
@@ -652,7 +632,8 @@ public class DataContext extends BaseCon
         if (objectStore.hasChanges()) {
             GraphDiff diff = getObjectStore().getChanges();
 
-            // call channel with changes BEFORE reverting them, so that any interceptors
+            // call channel with changes BEFORE reverting them, so that any
+            // interceptors
             // could record them
 
             if (channel != null) {
@@ -661,24 +642,21 @@ public class DataContext extends BaseCon
 
             getObjectStore().objectsRolledBack();
             fireDataChannelRolledback(this, diff);
-        }
-        else {
+        } else {
             if (channel != null) {
-                channel.onSync(
-                        this,
-                        new CompoundDiff(),
-                        DataChannel.ROLLBACK_CASCADE_SYNC);
+                channel.onSync(this, new CompoundDiff(), DataChannel.ROLLBACK_CASCADE_SYNC);
             }
         }
 
     }
 
     /**
-     * "Flushes" the changes to the parent {@link DataChannel}. If the parent channel is a
-     * DataContext, it updates its objects with this context's changes, without a database
-     * update. If it is a DataDomain (the most common case), the changes are written to
-     * the database. To cause cascading commit all the way to the database, one must use
-     * {@link #commitChanges()}.
+     * "Flushes" the changes to the parent {@link DataChannel}. If the parent
+     * channel is a DataContext, it updates its objects with this context's
+     * changes, without a database update. If it is a DataDomain (the most
+     * common case), the changes are written to the database. To cause cascading
+     * commit all the way to the database, one must use {@link #commitChanges()}
+     * .
      * 
      * @since 1.2
      * @see #commitChanges()
@@ -689,8 +667,8 @@ public class DataContext extends BaseCon
     }
 
     /**
-     * Synchronizes object graph with the database. Executes needed insert, update and
-     * delete queries (generated internally).
+     * Synchronizes object graph with the database. Executes needed insert,
+     * update and delete queries (generated internally).
      */
     @Override
     public void commitChanges() throws CayenneRuntimeException {
@@ -698,10 +676,7 @@ public class DataContext extends BaseCon
     }
 
     @Override
-    protected GraphDiff onContextFlush(
-            ObjectContext originatingContext,
-            GraphDiff changes,
-            boolean cascade) {
+    protected GraphDiff onContextFlush(ObjectContext originatingContext, GraphDiff changes, boolean cascade) {
 
         boolean childContext = this != originatingContext && changes != null;
 
@@ -713,8 +688,7 @@ public class DataContext extends BaseCon
             }
 
             return (cascade) ? flushToParent(true) : new CompoundDiff();
-        }
-        finally {
+        } finally {
             if (childContext) {
                 getObjectStore().childContextSyncStopped();
             }
@@ -729,13 +703,10 @@ public class DataContext extends BaseCon
     GraphDiff flushToParent(boolean cascade) {
 
         if (this.getChannel() == null) {
-            throw new CayenneRuntimeException(
-                    "Cannot commit changes - channel is not set.");
+            throw new CayenneRuntimeException("Cannot commit changes - channel is not set.");
         }
 
-        int syncType = cascade
-                ? DataChannel.FLUSH_CASCADE_SYNC
-                : DataChannel.FLUSH_NOCASCADE_SYNC;
+        int syncType = cascade ? DataChannel.FLUSH_CASCADE_SYNC : DataChannel.FLUSH_NOCASCADE_SYNC;
 
         ObjectStore objectStore = getObjectStore();
         GraphDiff parentChanges = null;
@@ -744,34 +715,36 @@ public class DataContext extends BaseCon
         synchronized (objectStore) {
 
             ObjectStoreGraphDiff changes = objectStore.getChanges();
-            boolean noop = isValidatingObjectsOnCommit()
-                    ? changes.validateAndCheckNoop()
-                    : changes.isNoop();
+            boolean noop = isValidatingObjectsOnCommit() ? changes.validateAndCheckNoop() : changes.isNoop();
 
             if (noop) {
                 // need to clear phantom changes
                 objectStore.postprocessAfterPhantomCommit();
-            }
-            else {
+            } else {
 
                 try {
                     parentChanges = getChannel().onSync(this, changes, syncType);
 
-                    // note that this is a hack resulting from a fix to CAY-766... To
+                    // note that this is a hack resulting from a fix to
+                    // CAY-766... To
                     // support
                     // valid object state in PostPersist callback,
                     // 'postprocessAfterCommit' is
-                    // invoked by DataDomain.onSync(..). Unless the parent is DataContext,
+                    // invoked by DataDomain.onSync(..). Unless the parent is
+                    // DataContext,
                     // and
-                    // this method is not invoked!! As a result, PostPersist will contain
+                    // this method is not invoked!! As a result, PostPersist
+                    // will contain
                     // temp
-                    // ObjectIds in nested contexts and perm ones in flat contexts.
+                    // ObjectIds in nested contexts and perm ones in flat
+                    // contexts.
                     // Pending better callback design .....
                     if (objectStore.hasChanges()) {
                         objectStore.postprocessAfterCommit(parentChanges);
                     }
 
-                    // this event is caught by peer nested DataContexts to synchronize the
+                    // this event is caught by peer nested DataContexts to
+                    // synchronize the
                     // state
                     fireDataChannelCommitted(this, changes);
                 }
@@ -781,14 +754,14 @@ public class DataContext extends BaseCon
 
                     if (unwound instanceof CayenneRuntimeException) {
                         throw (CayenneRuntimeException) unwound;
-                    }
-                    else {
+                    } else {
                         throw new CayenneRuntimeException("Commit Exception", unwound);
                     }
                 }
             }
 
-            // merge changes from parent as well as changes caused by lifecycle event
+            // merge changes from parent as well as changes caused by lifecycle
+            // event
             // callbacks/listeners...
 
             CompoundDiff diff = new CompoundDiff();
@@ -809,21 +782,35 @@ public class DataContext extends BaseCon
 
     }
 
+    @SuppressWarnings("unchecked")
+    public <T> ResultIterator<T> iterate(Select<T> query) {
+        try {
+            return performIteratedQuery(query);
+        } catch (CayenneException e) {
+            throw new CayenneRuntimeException(e);
+        }
+    }
+
     /**
-     * Performs a single database select query returning result as a ResultIterator. It is
-     * caller's responsibility to explicitly close the ResultIterator. A failure to do so
-     * will result in a database connection not being released. Another side effect of an
-     * open ResultIterator is that an internal Cayenne transaction that originated in this
-     * method stays open until the iterator is closed. So users should normally close the
-     * iterator within the same thread that opened it.
+     * Performs a single database select query returning result as a
+     * ResultIterator. It is caller's responsibility to explicitly close the
+     * ResultIterator. A failure to do so will result in a database connection
+     * not being released. Another side effect of an open ResultIterator is that
+     * an internal Cayenne transaction that originated in this method stays open
+     * until the iterator is closed. So users should normally close the iterator
+     * within the same thread that opened it.
      */
+    // TODO: deprecate once all selecting queries start implementing Select<T>
+    // interface
+    @SuppressWarnings({ "rawtypes" })
     public ResultIterator performIteratedQuery(Query query) throws CayenneException {
+        // TODO: use 3.2 TransactionManager
         if (Transaction.getThreadTransaction() != null) {
             return internalPerformIteratedQuery(query);
-        }
-        else {
+        } else {
 
-            // manually manage a transaction, so that a ResultIterator wrapper could close
+            // manually manage a transaction, so that a ResultIterator wrapper
+            // could close
             // it when it is done.
             Transaction tx = getParentDataDomain().createTransaction();
             Transaction.bindThreadTransaction(tx);
@@ -831,22 +818,21 @@ public class DataContext extends BaseCon
             ResultIterator result;
             try {
                 result = internalPerformIteratedQuery(query);
-            }
-            catch (Exception e) {
+            } catch (Exception e) {
                 Transaction.bindThreadTransaction(null);
                 tx.setRollbackOnly();
                 throw new CayenneException(e);
-            }
-            finally {
-                // note: we are keeping the transaction bound to the current thread on
-                // success - iterator will unbind it. Unsetting a transaction here would
+            } finally {
+                // note: we are keeping the transaction bound to the current
+                // thread on
+                // success - iterator will unbind it. Unsetting a transaction
+                // here would
                 // result in some strangeness, at least on Ingres
 
                 if (tx.getStatus() == Transaction.STATUS_MARKED_ROLLEDBACK) {
                     try {
                         tx.rollback();
-                    }
-                    catch (Exception rollbackEx) {
+                    } catch (Exception rollbackEx) {
                     }
                 }
             }
@@ -856,9 +842,7 @@ public class DataContext extends BaseCon
     }
 
     /**
-     * Runs an iterated query in transactional context provided by the caller.
-     * 
-     * @since 1.2
+     * Runs an iterated query in a transactional context provided by the caller.
      */
     ResultIterator internalPerformIteratedQuery(Query query) throws CayenneException {
         // note that for now DataChannel API does not support cursors (aka
@@ -882,31 +866,30 @@ public class DataContext extends BaseCon
         }
 
         if (this.getChannel() == null) {
-            throw new CayenneRuntimeException(
-                    "Can't run query - parent DataChannel is not set.");
+            throw new CayenneRuntimeException("Can't run query - parent DataChannel is not set.");
         }
 
         return onQuery(this, query);
     }
 
     /**
-     * Performs a single selecting query. Various query setting control the behavior of
-     * this method and the results returned:
+     * Performs a single selecting query. Various query setting control the
+     * behavior of this method and the results returned:
      * <ul>
-     * <li>Query caching policy defines whether the results are retrieved from cache or
-     * fetched from the database. Note that queries that use caching must have a name that
-     * is used as a caching key.</li>
-     * <li>Query refreshing policy controls whether to refresh existing data objects and
-     * ignore any cached values.</li>
-     * <li>Query data rows policy defines whether the result should be returned as
-     * DataObjects or DataRows.</li>
+     * <li>Query caching policy defines whether the results are retrieved from
+     * cache or fetched from the database. Note that queries that use caching
+     * must have a name that is used as a caching key.</li>
+     * <li>Query refreshing policy controls whether to refresh existing data
+     * objects and ignore any cached values.</li>
+     * <li>Query data rows policy defines whether the result should be returned
+     * as DataObjects or DataRows.</li>
      * </ul>
      * <p>
      * <i>Since 1.2 takes any Query parameter, not just GenericSelectQuery</i>
      * </p>
      * 
-     * @return A list of DataObjects or a DataRows, depending on the value returned by
-     *         {@link QueryMetadata#isFetchingDataRows()}.
+     * @return A list of DataObjects or a DataRows, depending on the value
+     *         returned by {@link QueryMetadata#isFetchingDataRows()}.
      */
     @Override
     @SuppressWarnings("unchecked")
@@ -921,8 +904,8 @@ public class DataContext extends BaseCon
     }
 
     /**
-     * An implementation of a {@link DataChannel} method that is used by child contexts to
-     * execute queries. Not intended for direct use.
+     * An implementation of a {@link DataChannel} method that is used by child
+     * contexts to execute queries. Not intended for direct use.
      * 
      * @since 1.2
      */
@@ -931,8 +914,8 @@ public class DataContext extends BaseCon
     }
 
     /**
-     * Performs a single database query that does not select rows. Returns an array of
-     * update counts.
+     * Performs a single database query that does not select rows. Returns an
+     * array of update counts.
      * 
      * @since 1.1
      */
@@ -942,8 +925,8 @@ public class DataContext extends BaseCon
     }
 
     /**
-     * Performs a named mapped query that does not select rows. Returns an array of update
-     * counts.
+     * Performs a named mapped query that does not select rows. Returns an array
+     * of update counts.
      * 
      * @since 1.1
      */
@@ -952,8 +935,8 @@ public class DataContext extends BaseCon
     }
 
     /**
-     * Performs a named mapped non-selecting query using a map of parameters. Returns an
-     * array of update counts.
+     * Performs a named mapped non-selecting query using a map of parameters.
+     * Returns an array of update counts.
      * 
      * @since 1.1
      */
@@ -962,15 +945,18 @@ public class DataContext extends BaseCon
     }
 
     /**
-     * Returns a list of objects or DataRows for a named query stored in one of the
-     * DataMaps. Internally Cayenne uses a caching policy defined in the named query. If
-     * refresh flag is true, a refresh is forced no matter what the caching policy is.
-     * 
-     * @param queryName a name of a GenericSelectQuery defined in one of the DataMaps. If
-     *            no such query is defined, this method will throw a
+     * Returns a list of objects or DataRows for a named query stored in one of
+     * the DataMaps. Internally Cayenne uses a caching policy defined in the
+     * named query. If refresh flag is true, a refresh is forced no matter what
+     * the caching policy is.
+     * 
+     * @param queryName
+     *            a name of a GenericSelectQuery defined in one of the DataMaps.
+     *            If no such query is defined, this method will throw a
      *            CayenneRuntimeException.
-     * @param expireCachedLists A flag that determines whether refresh of <b>cached
-     *            lists</b> is required in case a query uses caching.
+     * @param expireCachedLists
+     *            A flag that determines whether refresh of <b>cached lists</b>
+     *            is required in case a query uses caching.
      * @since 1.1
      */
     public List<?> performQuery(String queryName, boolean expireCachedLists) {
@@ -978,30 +964,31 @@ public class DataContext extends BaseCon
     }
 
     /**
-     * Returns a list of objects or DataRows for a named query stored in one of the
-     * DataMaps. Internally Cayenne uses a caching policy defined in the named query. If
-     * refresh flag is true, a refresh is forced no matter what the caching policy is.
-     * 
-     * @param queryName a name of a GenericSelectQuery defined in one of the DataMaps. If
-     *            no such query is defined, this method will throw a
+     * Returns a list of objects or DataRows for a named query stored in one of
+     * the DataMaps. Internally Cayenne uses a caching policy defined in the
+     * named query. If refresh flag is true, a refresh is forced no matter what
+     * the caching policy is.
+     * 
+     * @param queryName
+     *            a name of a GenericSelectQuery defined in one of the DataMaps.
+     *            If no such query is defined, this method will throw a
      *            CayenneRuntimeException.
-     * @param parameters A map of parameters to use with stored query.
-     * @param expireCachedLists A flag that determines whether refresh of <b>cached
-     *            lists</b> is required in case a query uses caching.
+     * @param parameters
+     *            A map of parameters to use with stored query.
+     * @param expireCachedLists
+     *            A flag that determines whether refresh of <b>cached lists</b>
+     *            is required in case a query uses caching.
      * @since 1.1
      */
-    public List<?> performQuery(
-            String queryName,
-            Map parameters,
-            boolean expireCachedLists) {
+    public List<?> performQuery(String queryName, Map parameters, boolean expireCachedLists) {
         NamedQuery query = new NamedQuery(queryName, parameters);
         query.setForceNoCache(expireCachedLists);
         return performQuery(query);
     }
 
     /**
-     * Returns <code>true</code> if the ObjectStore uses shared cache of a parent
-     * DataDomain.
+     * Returns <code>true</code> if the ObjectStore uses shared cache of a
+     * parent DataDomain.
      * 
      * @since 1.1
      */
@@ -1030,10 +1017,10 @@ public class DataContext extends BaseCon
     }
 
     // serialization support
-    private void readObject(ObjectInputStream in) throws IOException,
-            ClassNotFoundException {
+    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
 
-        // TODO: most of this should be in the superclass, especially the code connecting
+        // TODO: most of this should be in the superclass, especially the code
+        // connecting
         // super transient ivars
 
         // read non-transient properties
@@ -1049,7 +1036,8 @@ public class DataContext extends BaseCon
         // because at deserialize time the datacontext may need to be different
         // than the one at serialize time (for programmer defined reasons).
         // So, when a DataObject is resurrected because it's DataContext was
-        // serialized, it will then set the objects DataContext to the correct one
+        // serialized, it will then set the objects DataContext to the correct
+        // one
         // If deserialized "otherwise", it will not have a DataContext.
 
         synchronized (getObjectStore()) {
@@ -1060,8 +1048,10 @@ public class DataContext extends BaseCon
             }
         }
 
-        // ... deferring initialization of transient properties of this context till first
-        // access, so that it can attach to Cayenne runtime using appropriate thread
+        // ... deferring initialization of transient properties of this context
+        // till first
+        // access, so that it can attach to Cayenne runtime using appropriate
+        // thread
         // injector.
     }
 
@@ -1076,9 +1066,9 @@ public class DataContext extends BaseCon
     }
 
     /**
-     * An internal version of {@link #localObject(Object)} that operates on ObjectId
-     * instead of Persistent, and wouldn't attempt to look up an object in the parent
-     * channel.
+     * An internal version of {@link #localObject(Object)} that operates on
+     * ObjectId instead of Persistent, and wouldn't attempt to look up an object
+     * in the parent channel.
      * 
      * @since 3.1
      */
@@ -1088,9 +1078,12 @@ public class DataContext extends BaseCon
             throw new IllegalArgumentException("Null ObjectId");
         }
 
-        // have to synchronize almost the entire method to prevent multiple threads from
-        // messing up dataobjects per CAY-845. Originally only parts of "else" were
-        // synchronized, but we had to expand the lock scope to ensure consistent
+        // have to synchronize almost the entire method to prevent multiple
+        // threads from
+        // messing up dataobjects per CAY-845. Originally only parts of "else"
+        // were
+        // synchronized, but we had to expand the lock scope to ensure
+        // consistent
         // behavior.
         synchronized (getGraphManager()) {
             Persistent cachedObject = (Persistent) getGraphManager().getNode(id);
@@ -1100,12 +1093,11 @@ public class DataContext extends BaseCon
 
                 int state = cachedObject.getPersistenceState();
 
-                // TODO: Andrus, 1/24/2006 implement smart merge for modified objects...
-                if (state != PersistenceState.MODIFIED
-                        && state != PersistenceState.DELETED) {
+                // TODO: Andrus, 1/24/2006 implement smart merge for modified
+                // objects...
+                if (state != PersistenceState.MODIFIED && state != PersistenceState.DELETED) {
 
-                    ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(
-                            id.getEntityName());
+                    ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(id.getEntityName());
 
                     descriptor.injectValueHolders(cachedObject);
                 }
@@ -1114,8 +1106,7 @@ public class DataContext extends BaseCon
             }
 
             // create and register a hollow object
-            ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(
-                    id.getEntityName());
+            ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(id.getEntityName());
             Persistent localObject = (Persistent) descriptor.createObject();
 
             localObject.setObjectContext(this);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainFlushObserver.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainFlushObserver.java?rev=1486125&r1=1486124&r2=1486125&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainFlushObserver.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainFlushObserver.java Fri May 24 17:31:14 2013
@@ -21,7 +21,6 @@ package org.apache.cayenne.access;
 
 import java.util.List;
 
-import org.apache.cayenne.CayenneException;
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.DataRow;
 import org.apache.cayenne.ObjectId;
@@ -38,7 +37,7 @@ import org.apache.cayenne.util.Util;
  * @since 1.2
  */
 class DataDomainFlushObserver implements OperationObserver {
-    
+
     /**
      * @since 3.1
      */
@@ -49,14 +48,11 @@ class DataDomainFlushObserver implements
     }
 
     public void nextQueryException(Query query, Exception ex) {
-        throw new CayenneRuntimeException("Raising from query exception.", Util
-                .unwindException(ex));
+        throw new CayenneRuntimeException("Raising from query exception.", Util.unwindException(ex));
     }
 
     public void nextGlobalException(Exception ex) {
-        throw new CayenneRuntimeException(
-                "Raising from underlyingQueryEngine exception.",
-                Util.unwindException(ex));
+        throw new CayenneRuntimeException("Raising from underlyingQueryEngine exception.", Util.unwindException(ex));
     }
 
     /**
@@ -64,32 +60,20 @@ class DataDomainFlushObserver implements
      * 
      * @since 1.2
      */
+    @SuppressWarnings({ "rawtypes", "unchecked" })
     public void nextGeneratedRows(Query query, ResultIterator keysIterator) {
 
         // read and close the iterator before doing anything else
         List<DataRow> keys;
         try {
             keys = (List<DataRow>) keysIterator.allRows();
-        }
-        catch (CayenneException ex) {
-            throw new CayenneRuntimeException("Error reading primary key", Util
-                    .unwindException(ex));
-        }
-        finally {
-            try {
-                keysIterator.close();
-            }
-            catch (CayenneException e) {
-                throw new CayenneRuntimeException(
-                        "Error closing primary key result set",
-                        Util.unwindException(e));
-            }
+        } finally {
+            keysIterator.close();
         }
 
         if (!(query instanceof InsertBatchQuery)) {
-            throw new CayenneRuntimeException(
-                    "Generated keys only supported for InsertBatchQuery, instead got "
-                            + query);
+            throw new CayenneRuntimeException("Generated keys only supported for InsertBatchQuery, instead got "
+                    + query);
         }
 
         BatchQuery batch = (BatchQuery) query;
@@ -101,8 +85,7 @@ class DataDomainFlushObserver implements
         }
 
         if (keys.size() != 1) {
-            throw new CayenneRuntimeException(
-                    "One and only one PK row is expected, instead got " + keys.size());
+            throw new CayenneRuntimeException("One and only one PK row is expected, instead got " + keys.size());
         }
 
         DataRow key = keys.get(0);
@@ -114,20 +97,22 @@ class DataDomainFlushObserver implements
 
         // determine DbAttribute name...
 
-        // As of now (01/2005) all tested drivers don't provide decent descriptors of
-        // identity result sets, so a data row will contain garbage labels. Also most
-        // DBs only support one autogenerated key per table... So here we will have to
+        // As of now (01/2005) all tested drivers don't provide decent
+        // descriptors of
+        // identity result sets, so a data row will contain garbage labels. Also
+        // most
+        // DBs only support one autogenerated key per table... So here we will
+        // have to
         // infer the key name and currently will only support a single column...
         if (key.size() > 1) {
-            throw new CayenneRuntimeException(
-                    "Only a single column autogenerated PK is supported. "
-                            + "Generated key: "
-                            + key);
+            throw new CayenneRuntimeException("Only a single column autogenerated PK is supported. "
+                    + "Generated key: " + key);
         }
 
         for (DbAttribute attribute : batch.getDbEntity().getGeneratedAttributes()) {
 
-            // batch can have generated attributes that are not PKs, e.g. columns with
+            // batch can have generated attributes that are not PKs, e.g.
+            // columns with
             // DB DEFAULT values. Ignore those.
             if (attribute.isPrimaryKey()) {
                 Object value = key.values().iterator().next();
@@ -142,11 +127,11 @@ class DataDomainFlushObserver implements
             }
         }
     }
-    
+
     public void setJdbcEventLogger(JdbcEventLogger logger) {
         this.logger = logger;
     }
-    
+
     public JdbcEventLogger getJdbcEventLogger() {
         return this.logger;
     }
@@ -160,6 +145,7 @@ class DataDomainFlushObserver implements
     public void nextRows(Query query, List<?> dataRows) {
     }
 
+    @SuppressWarnings("rawtypes")
     public void nextRows(Query q, ResultIterator it) {
         throw new UnsupportedOperationException(
                 "'nextDataRows(Query,ResultIterator)' is unsupported (and unexpected) on commit.");



Mime
View raw message