openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r618738 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-kernel/src/main/java/org/apache/openjpa/abstractstore/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-kernel/src/main/java/org/...
Date Tue, 05 Feb 2008 18:34:59 GMT
Author: pcl
Date: Tue Feb  5 10:34:55 2008
New Revision: 618738

URL: http://svn.apache.org/viewvc?rev=618738&view=rev
Log:
OPENJPA-147. Changes resulting from tests via Kodo's harness.

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCBrokerFactory.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/abstractstore/AbstractStoreBrokerFactory.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCBrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCBrokerFactory.java?rev=618738&r1=618737&r2=618738&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCBrokerFactory.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCBrokerFactory.java
Tue Feb  5 10:34:55 2008
@@ -22,6 +22,7 @@
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.Properties;
+import java.util.Map;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
@@ -66,28 +67,15 @@
      * Invoked from {@link Bootstrap#getBrokerFactory}.
      */
     public static JDBCBrokerFactory getInstance(ConfigurationProvider cp) {
-        JDBCBrokerFactory factory = (JDBCBrokerFactory) getPooledFactory
-            (cp.getProperties());
+        Map props = cp.getProperties();
+        Object key = toPoolKey(props);
+        JDBCBrokerFactory factory = (JDBCBrokerFactory)
+            getPooledFactoryForKey(key);
         if (factory != null)
             return factory;
 
         factory = newInstance(cp);
-        factory.pool();
-        return factory;
-    }
-
-    /**
-     * Factory method for constructing a factory from a configuration.
-     */
-    public static synchronized JDBCBrokerFactory getInstance
-        (JDBCConfiguration conf) {
-        JDBCBrokerFactory factory = (JDBCBrokerFactory) getPooledFactory
-            (conf.toProperties(false));
-        if (factory != null)
-            return factory;
-
-        factory = new JDBCBrokerFactory(conf);
-        factory.pool();
+        pool(key, factory);
         return factory;
     }
 

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/abstractstore/AbstractStoreBrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/abstractstore/AbstractStoreBrokerFactory.java?rev=618738&r1=618737&r2=618738&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/abstractstore/AbstractStoreBrokerFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/abstractstore/AbstractStoreBrokerFactory.java
Tue Feb  5 10:34:55 2008
@@ -71,15 +71,16 @@
      * Factory method for obtaining a possibly-pooled {@link BrokerFactory}
      * from properties. Invoked from {@link Bootstrap#getBrokerFactory()}.
      */
-    public static AbstractStoreBrokerFactory getInstance
-        (ConfigurationProvider cp) {
+    public static AbstractStoreBrokerFactory getInstance(
+        ConfigurationProvider cp) {
+        Object key = toPoolKey(cp.getProperties());
         AbstractStoreBrokerFactory factory = (AbstractStoreBrokerFactory)
-            getPooledFactory(cp.getProperties());
+            getPooledFactoryForKey(key);
         if (factory != null)
             return factory;
 
         factory = newInstance(cp);
-        factory.pool();
+        factory.pool(key, factory);
         return factory;
     }
 

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java?rev=618738&r1=618737&r2=618738&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
Tue Feb  5 10:34:55 2008
@@ -104,34 +104,33 @@
     // transaction listeners to pass to each broker
     private transient List _transactionListeners = null;
 
-    /**
-     * Return the pooled factory matching the given configuration, or null
-     * if none.
-     */
-    public static AbstractBrokerFactory getPooledFactory(
-        OpenJPAConfiguration conf) {
-        return (AbstractBrokerFactory) _pool.get(toPoolKey(conf));
-    }
+    // key under which this instance can be stored in the broker pool
+    // and later identified
+    private Object _poolKey;
 
     /**
      * Return an internal factory pool key for the given configuration.
+     *
+     * @since 1.1.0
      */
-    private static Object toPoolKey(OpenJPAConfiguration conf) {
-        if (conf.getId() != null)
-            return conf.getId();
+    protected static Object toPoolKey(Map map) {
+        if (Configurations.getProperty("Id", map) != null)
+            return Configurations.getProperty("Id", map);
         else
-            return conf.toProperties(false);
+            return map;
     }
 
     /**
-     * Return the pooled factory matching the given configuration data, or null
-     * if none.
+     * Register <code>factory</code> in the pool under <code>key</code>.
+     *
+     * @since 1.1.0
      */
-    protected static AbstractBrokerFactory getPooledFactory(Map map) {
-        Object key = Configurations.getProperty("Id", map);
-        if (key == null)
-            key = map;
-        return getPooledFactoryForKey(key);
+    protected static void pool(Object key, AbstractBrokerFactory factory) {
+        synchronized(_pool) {
+            _pool.put(key, factory);
+            factory.setPoolKey(key);
+            factory.makeReadOnly();
+        }
     }
 
     /**
@@ -407,10 +406,9 @@
             assertNoActiveTransaction();
 
             // remove from factory pool
-            Object key = toPoolKey(_conf);
             synchronized (_pool) {
-                if (_pool.get(key) == this)
-                    _pool.remove(key);
+                if (_pool.get(_poolKey) == this)
+                    _pool.remove(_poolKey);
             }
 
             // close all brokers
@@ -491,7 +489,7 @@
      */
     protected Object readResolve()
         throws ObjectStreamException {
-        AbstractBrokerFactory factory = getPooledFactory(_conf);
+        AbstractBrokerFactory factory = getPooledFactoryForKey(_poolKey);
         if (factory != null)
             return factory;
 
@@ -614,16 +612,6 @@
     }
 
     /**
-     * Add the factory to the pool.
-     */
-    protected void pool() {
-        synchronized (_pool) {
-            _pool.put(toPoolKey(_conf), this);
-            makeReadOnly();
-        }
-    }
-
-    /**
      * Freezes the configuration of this factory.
      */
     public void makeReadOnly() {
@@ -792,10 +780,21 @@
     /**
      * @return a key that can be used to obtain this broker factory from the
      * pool at a later time.
+     *
      * @since 1.1.0
      */
     public Object getPoolKey() {
-        return toPoolKey(getConfiguration());
+        return _poolKey;
+    }
+
+    /**
+     * Set a key that can be used to obtain this broker factory from the
+     * pool at a later time.
+     *
+     * @since 1.1.0
+     */
+    void setPoolKey(Object key) {
+        _poolKey = key;
     }
 
     /**

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java?rev=618738&r1=618737&r2=618738&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java
Tue Feb  5 10:34:55 2008
@@ -269,6 +269,9 @@
      * Returns ACCESS_FIELD by default.
      */
     protected int getAccessType(ClassMetaData meta) {
+        if (meta.getDescribedType().isInterface())
+            return ClassMetaData.ACCESS_PROPERTY;
+        else
             return ClassMetaData.ACCESS_FIELD;
     }
 



Mime
View raw message