openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r666894 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fetchgroups/ openjpa-per...
Date Wed, 11 Jun 2008 23:22:54 GMT
Author: pcl
Date: Wed Jun 11 16:22:54 2008
New Revision: 666894

URL: http://svn.apache.org/viewvc?rev=666894&view=rev
Log:
OPENJPA-522. Backporting r652026 to trunk.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fetchgroups/TestFetchGroupStacks.java
      - copied unchanged from r652026, openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fetchgroups/TestFetchGroupStacks.java
Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBroker.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StoreContext.java
    openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAEntityManager.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java?rev=666894&r1=666893&r2=666894&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java Wed
Jun 11 16:22:54 2008
@@ -237,6 +237,7 @@
     private int _lifeCallbackMode = 0;
 
     private transient boolean _initializeWasInvoked = false;
+    private LinkedList _fcs;
 
     /**
      * Set the persistence manager's authentication. This is the first
@@ -385,6 +386,20 @@
         return _fc;
     }
 
+    public FetchConfiguration pushFetchConfiguration() {
+        if (_fcs == null)
+            _fcs = new LinkedList();
+        _fcs.add(_fc);
+        _fc = (FetchConfiguration) _fc.clone();
+        return _fc;
+    }
+
+    public void popFetchConfiguration() {
+        if (_fcs == null || _fcs.isEmpty())
+            throw new UserException(_loc.get("fetch-configuration-stack-empty"));
+        _fc = (FetchConfiguration) _fcs.removeLast();
+    }
+
     public int getConnectionRetainMode() {
         return _connRetainMode;
     }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBroker.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBroker.java?rev=666894&r1=666893&r2=666894&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBroker.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBroker.java
Wed Jun 11 16:22:54 2008
@@ -122,6 +122,22 @@
         }
     }
 
+    public FetchConfiguration pushFetchConfiguration() {
+        try {
+            return _broker.pushFetchConfiguration();
+        } catch (RuntimeException re) {
+            throw translate(re);
+        }
+    }
+
+    public void popFetchConfiguration() {
+        try {
+            _broker.popFetchConfiguration();
+        } catch (RuntimeException re) {
+            throw translate(re);
+        }
+    }
+
     public ClassLoader getClassLoader() {
         try {
             return _broker.getClassLoader();

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StoreContext.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StoreContext.java?rev=666894&r1=666893&r2=666894&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StoreContext.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StoreContext.java
Wed Jun 11 16:22:54 2008
@@ -62,6 +62,27 @@
     public FetchConfiguration getFetchConfiguration();
 
     /**
+     * Pushes a new fetch configuration that inherits from the current
+     * fetch configuration onto a stack, and makes the new configuration
+     * the active one.
+     *
+     * @since 1.1.0
+     * @return the new fetch configuration
+     */
+    public FetchConfiguration pushFetchConfiguration();
+
+    /**
+     * Pops the fetch configuration from the top of the stack, making the
+     * next one down the active one. This returns void to avoid confusion,
+     * since fetch configurations tend to be used in method-chaining
+     * patterns often.
+     *
+     * @since 1.1.0
+     * @throws UserException if the fetch configuration stack is empty
+     */
+    public void popFetchConfiguration();
+
+    /**
      * Return the current thread's class loader at the time this context
      * was obtained.
      */

Modified: openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties?rev=666894&r1=666893&r2=666894&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties
Wed Jun 11 16:22:54 2008
@@ -399,3 +399,4 @@
 cant-serialize-connected-broker: Serialization not allowed for brokers with \
     an active connection to the database.
 no-interface-metadata: No metadata was found for managed interface {0}.
+fetch-configuration-stack-empty: Fetch configuration stack is empty.

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java?rev=666894&r1=666893&r2=666894&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
Wed Jun 11 16:22:54 2008
@@ -31,6 +31,8 @@
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.EnumSet;
+import java.util.Map;
+import java.util.HashMap;
 import javax.persistence.EntityManager;
 import javax.persistence.FlushModeType;
 import javax.persistence.LockModeType;
@@ -51,6 +53,7 @@
 import org.apache.openjpa.kernel.QueryFlushModes;
 import org.apache.openjpa.kernel.QueryLanguages;
 import org.apache.openjpa.kernel.Seq;
+import org.apache.openjpa.kernel.FetchConfiguration;
 import org.apache.openjpa.kernel.jpql.JPQLParser;
 import org.apache.openjpa.lib.util.Closeable;
 import org.apache.openjpa.lib.util.Localizer;
@@ -80,7 +83,8 @@
 
     private DelegatingBroker _broker;
     private EntityManagerFactoryImpl _emf;
-    private FetchPlan _fetch = null;
+    private Map<FetchConfiguration,FetchPlan> _plans =
+        new HashMap<FetchConfiguration,FetchPlan>(1);
 
     private RuntimeExceptionTranslator ret =
         PersistenceExceptions.getRollbackTranslator(this);
@@ -122,10 +126,34 @@
         assertNotCloseInvoked();
         _broker.lock();
         try {
-            if (_fetch == null)
-                _fetch = _emf.toFetchPlan(_broker,
-                    _broker.getFetchConfiguration());
-            return _fetch;
+            FetchConfiguration fc = _broker.getFetchConfiguration();
+            FetchPlan fp = _plans.get(fc);
+            if (fp == null) {
+                fp = _emf.toFetchPlan(_broker, fc);
+                _plans.put(fc, fp);
+            }
+            return fp;
+        } finally {
+            _broker.unlock();
+        }
+    }
+
+    public FetchPlan pushFetchPlan() {
+        assertNotCloseInvoked();
+        _broker.lock();
+        try {
+            _broker.pushFetchConfiguration();
+            return getFetchPlan();
+        } finally {
+            _broker.unlock();
+        }
+    }
+
+    public void popFetchPlan() {
+        assertNotCloseInvoked();
+        _broker.lock();
+        try {
+            _broker.popFetchConfiguration();
         } finally {
             _broker.unlock();
         }

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAEntityManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAEntityManager.java?rev=666894&r1=666893&r2=666894&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAEntityManager.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAEntityManager.java
Wed Jun 11 16:22:54 2008
@@ -57,6 +57,24 @@
     public FetchPlan getFetchPlan();
 
     /**
+     * Pushes a new fetch plan that inherits from the current fetch plan onto
+     * a stack, and makes the new plan the active one.
+     *
+     * @since 1.1.0
+     * @return the new fetch plan
+     */
+    public FetchPlan pushFetchPlan();
+
+    /**
+     * Pops the fetch plan from the top of the stack, making the next one down
+     * the active one. This returns void to avoid confusion, since fetch plans
+     * tend to be used in method-chaining patterns often.
+     *
+     * @since 1.1.0
+     */
+    public void popFetchPlan();
+
+    /**
      * Return the connection retain mode for this entity manager.
      */
     public ConnectionRetainMode getConnectionRetainMode();



Mime
View raw message