openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awh...@apache.org
Subject svn commit: r428069 - in /incubator/openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ openjpa-kernel/src/main/java/org/apache/openjpa/util/ openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/ openjpa...
Date Wed, 02 Aug 2006 17:51:46 GMT
Author: awhite
Date: Wed Aug  2 10:51:43 2006
New Revision: 428069

URL: http://svn.apache.org/viewvc?rev=428069&view=rev
Log:
Fix StoreFacadeTypeRegistry to work when multiple stores are available.  Fix
problems with creating a persistence FetchPlan, and with getting max depth.


Modified:
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreFacadeTypeRegistry.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/Extent.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/FetchPlan.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java?rev=428069&r1=428068&r2=428069&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
(original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
Wed Aug  2 10:51:43 2006
@@ -492,8 +492,8 @@
                 long id = res.getLong(cols[0]);
                 if (!res.wasNull())
                     oid = store.newDataStoreId(id, relMapping, true);
-            } else // application id
-            {
+            } else { 
+                // application id
                 if (cols.length == 1) {
                     Object val = res.getObject(cols[0], null, null);
                     if (val != null)

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreFacadeTypeRegistry.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreFacadeTypeRegistry.java?rev=428069&r1=428068&r2=428069&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreFacadeTypeRegistry.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreFacadeTypeRegistry.java
Wed Aug  2 10:51:43 2006
@@ -13,11 +13,60 @@
 
     private Map _impls = new ConcurrentHashMap();
 
-    public void registerImplementation(Class facadeType, Class implType) {
-        _impls.put(facadeType, implType);
+    /**
+     * Register a facade implementation.
+     *
+     * @param facadeType the facade interface
+     * @param storeType the store's 
+     * {@link org.apache.openjpa.kernel.StoreManager} type, or null for generic
+     * @param implType the class implementing the facade
+     */
+    public void registerImplementation(Class facadeType, Class storeType, 
+        Class implType) {
+        Object key = (storeType == null) ? (Object)facadeType 
+            : new Key(facadeType, storeType);
+        _impls.put(key, implType);
     }
     
-    public Class getImplementation(Class facadeType) {
-        return (Class) _impls.get(facadeType);
+    /**
+     * Return the implementation for the given facade and store.
+     *
+     * @param facadeType the facade interface
+     * @param storeType the store's 
+     * {@link org.apache.openjpa.kernel.StoreManager} type, or null for generic
+     * @param implType the registered implementor
+     */
+    public Class getImplementation(Class facadeType, Class storeType) {
+        Object key = (storeType == null) ? (Object)facadeType 
+            : new Key(facadeType, storeType);
+        Class c = (Class) _impls.get(key);
+        // if no store-specific type, see if there is a generic avaialble
+        if (c == null && storeType != null)
+            c = (Class) _impls.get(facadeType);
+        return c; 
+    }
+
+    /**
+     * Lookup key for facade+store hash.
+     */
+    private static class Key {
+        private final Class _facadeType;
+        private final Class _storeType;
+
+        public Key(Class facadeType, Class storeType) {
+            _facadeType = facadeType;
+            _storeType = storeType;
+        }
+
+        public int hashCode() {
+            return _facadeType.hashCode() ^ _storeType.hashCode();
+        }
+
+        public boolean equals(Object other) {
+            if (other == this)
+                return true;
+            Key k = (Key) other;
+            return _facadeType == k._facadeType && _storeType == k._storeType;
+        }
     }
 }

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java?rev=428069&r1=428068&r2=428069&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java
(original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java
Wed Aug  2 10:51:43 2006
@@ -18,6 +18,7 @@
 import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.conf.ProductDerivation;
 import org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl;
+import org.apache.openjpa.jdbc.kernel.JDBCStoreManager;
 import org.apache.openjpa.lib.conf.ConfigurationProvider;
 import org.apache.openjpa.persistence.FetchPlan;
 import org.apache.openjpa.persistence.PersistenceProductDerivation;
@@ -39,8 +40,8 @@
     }
 
     public void beforeConfigurationLoad(OpenJPAConfiguration c) {
-        c.getStoreFacadeTypeRegistry().registerImplementation(
-            FetchPlan.class, JDBCFetchPlan.class);
+        c.getStoreFacadeTypeRegistry().registerImplementation(FetchPlan.class, 
+            JDBCStoreManager.class, JDBCFetchPlan.class);
         if (!(c instanceof JDBCConfigurationImpl))
             return;
 

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java?rev=428069&r1=428068&r2=428069&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java
(original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java
Wed Aug  2 10:51:43 2006
@@ -22,6 +22,7 @@
 
 import junit.framework.TestCase;
 import junit.textui.TestRunner;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
 
 /**
  * Simple test case to get an EntityManager and perform some basic operations.
@@ -68,6 +69,12 @@
         t.begin();
         t.setRollbackOnly();
         t.rollback();
+
+        // openjpa-facade test
+        assertTrue(em instanceof OpenJPAEntityManager);
+        OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
+        ojem.getFetchPlan().setMaxFetchDepth(-1);
+        assertEquals(-1, ojem.getFetchPlan().getMaxFetchDepth());
 
         em.close();
     }

Modified: incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java?rev=428069&r1=428068&r2=428069&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java
(original)
+++ incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java
Wed Aug  2 10:51:43 2006
@@ -259,7 +259,7 @@
      * Create a store-specific facade for the given fetch configuration.
 	 * If no facade class exists, we use the default {@link FetchPlan}.
      */
-    FetchPlan toFetchPlan(FetchConfiguration fetch) {
+    FetchPlan toFetchPlan(Broker broker, FetchConfiguration fetch) {
         if (fetch == null)
             return null;
 
@@ -268,15 +268,16 @@
             inner = ((DelegatingFetchConfiguration) inner).
                 getInnermostDelegate();
 
-        _factory.lock();
         try {
             if (_plan == null) {
-                Class cls = _factory.getConfiguration()
-                    .getStoreFacadeTypeRegistry().getImplementation(
-                        FetchPlan.class);
+                Class storeType = (broker == null) ? null : broker.
+                    getStoreManager().getInnermostDelegate().getClass();
+                Class cls = _factory.getConfiguration().
+                    getStoreFacadeTypeRegistry().
+                    getImplementation(FetchPlan.class, storeType);
                 if (cls == null)
                     cls = FetchPlan.class;
-                _plan = cls.getConstructor(FetchPlan.class);
+                _plan = cls.getConstructor(FetchConfiguration.class);
             }
             return _plan.newInstance(fetch);
         } catch (InvocationTargetException ite) {
@@ -284,8 +285,6 @@
                 (ite.getTargetException());
         } catch (Exception e) {
             throw PersistenceExceptions.toPersistenceException(e);
-        } finally {
-            _factory.unlock();
         }
 	}
 }

Modified: incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java?rev=428069&r1=428068&r2=428069&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
(original)
+++ incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
Wed Aug  2 10:51:43 2006
@@ -119,7 +119,8 @@
         _broker.lock();
         try {
             if (_fetch == null)
-                _fetch = _emf.toFetchPlan(_broker.getFetchConfiguration());
+                _fetch = _emf.toFetchPlan(_broker, 
+                    _broker.getFetchConfiguration());
             return _fetch;
         } finally {
             _broker.unlock();

Modified: incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/Extent.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/Extent.java?rev=428069&r1=428068&r2=428069&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/Extent.java
(original)
+++ incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/Extent.java
Wed Aug  2 10:51:43 2006
@@ -79,8 +79,8 @@
         try {
             if (_fetch == null)
                 _fetch = ((EntityManagerFactoryImpl) _em.
-                    getEntityManagerFactory()).toFetchPlan(_extent.
-                    getFetchConfiguration());
+                    getEntityManagerFactory()).toFetchPlan(_extent.getBroker(),
+                    _extent.getFetchConfiguration());
             return _fetch;
         } finally {
             _extent.unlock();

Modified: incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/FetchPlan.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/FetchPlan.java?rev=428069&r1=428068&r2=428069&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/FetchPlan.java
(original)
+++ incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/FetchPlan.java
Wed Aug  2 10:51:43 2006
@@ -83,7 +83,7 @@
     /**
      * The maximum fetch depth when loading an object.
      */
-    public int getMaxFetchDepth(int depth) {
+    public int getMaxFetchDepth() {
         return _fetch.getMaxFetchDepth();
     }
 

Modified: incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java?rev=428069&r1=428068&r2=428069&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java
(original)
+++ incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java
Wed Aug  2 10:51:43 2006
@@ -99,8 +99,8 @@
         try {
             if (_fetch == null)
                 _fetch = ((EntityManagerFactoryImpl) _em.
-                    getEntityManagerFactory()).toFetchPlan(_query.
-                    getFetchConfiguration());
+                    getEntityManagerFactory()).toFetchPlan(_query.getBroker(),
+                    _query.getFetchConfiguration());
             return _fetch;
         } finally {
             _query.unlock();



Mime
View raw message