openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r953760 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/
Date Fri, 11 Jun 2010 16:37:31 GMT
Author: curtisr7
Date: Fri Jun 11 16:37:30 2010
New Revision: 953760

URL: http://svn.apache.org/viewvc?rev=953760&view=rev
Log:
OPENJPA-1692: Add post creation callback to BrokerFactory

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestBrokerFactory.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestInitializeEagerly.java
  (with props)
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/kernel/AbstractBrokerFactory.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Bootstrap.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerFactory.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBrokerFactory.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=953760&r1=953759&r2=953760&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
Fri Jun 11 16:37:30 2010
@@ -66,14 +66,14 @@ public class JDBCBrokerFactory
      * Invoked from {@link Bootstrap#getBrokerFactory}.
      */
     public static JDBCBrokerFactory getInstance(ConfigurationProvider cp) {
-        Map<String,Object> props = cp.getProperties();
+        Map<String, Object> props = cp.getProperties();
         Object key = toPoolKey(props);
-        JDBCBrokerFactory factory = (JDBCBrokerFactory)
-            getPooledFactoryForKey(key);
+        JDBCBrokerFactory factory = (JDBCBrokerFactory) getPooledFactoryForKey(key);
         if (factory != null)
             return factory;
-
-        factory = newInstance(cp);
+        
+        // The creation of all BrokerFactories should be driven through Bootstrap.
+        factory = (JDBCBrokerFactory) Bootstrap.newBrokerFactory(cp, null);
         pool(key, factory);
         return factory;
     }
@@ -99,6 +99,11 @@ public class JDBCBrokerFactory
 
         return props;
     }
+    
+    @Override
+    public void postCreationCallback() {
+        super.postCreationCallback();
+    }
 
     protected StoreManager newStoreManager() {
         return new JDBCStoreManager();

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=953760&r1=953759&r2=953760&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
Fri Jun 11 16:37:30 2010
@@ -19,6 +19,7 @@
 package org.apache.openjpa.kernel;
 
 import java.io.ObjectStreamException;
+import java.security.AccessController;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -55,6 +56,7 @@ import org.apache.openjpa.lib.conf.Confi
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.lib.util.Options;
 import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashSet;
 import org.apache.openjpa.meta.MetaDataModes;
 import org.apache.openjpa.meta.MetaDataRepository;
@@ -151,12 +153,6 @@ public abstract class AbstractBrokerFact
         _conf = config;
         _brokers = newBrokerSet();
         getPcClassLoaders();
-        if (config.isInitializeEagerly()) {
-            newBroker(_conf.getConnectionUserName(), 
-            	_conf.getConnectionPassword(), 
-            	_conf.isConnectionFactoryModeManaged(),
-                _conf.getConnectionRetainModeConstant(), false).close(); 
-        }
     }
 
     /**
@@ -835,5 +831,30 @@ public abstract class AbstractBrokerFact
         
         return dsm;
     }
+    
+    /**
+     * This method is invoked AFTER a BrokerFactory has been instantiated. 
+     */
+    public void postCreationCallback() {
+        if (_conf.isInitializeEagerly()) {
+            newBroker(_conf.getConnectionUserName(), _conf.getConnectionPassword(),
+                _conf.isConnectionFactoryModeManaged(), _conf.getConnectionRetainModeConstant(),
false).close();
+        }
+        // Don't catch any exceptions here because we want to fail-fast if something bad
happens when we're preloading.
+        Options o = Configurations.parseProperties(Configurations.getProperties(_conf.getMetaDataRepository()));
+        if (MetaDataRepository.needsPreload(o) == true) {
+            MetaDataRepository mdr = _conf.getMetaDataRepositoryInstance();
+            mdr.setValidate(MetaDataRepository.VALIDATE_RUNTIME, true);
+            mdr.setResolve(MetaDataRepository.MODE_MAPPING_INIT, true);
+
+            // Load persistent classes and hook in subclasser
+            loadPersistentTypes((ClassLoader) AccessController.doPrivileged(J2DoPrivHelper
+                .getContextClassLoaderAction()));
+            mdr.preload();
+        }
+
+        // Get a DataCacheManager instance up front to avoid threading concerns on first
call.
+        _conf.getDataCacheManagerInstance();
+    }
 }
 

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Bootstrap.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Bootstrap.java?rev=953760&r1=953759&r2=953760&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Bootstrap.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Bootstrap.java Fri
Jun 11 16:37:30 2010
@@ -59,7 +59,9 @@ public class Bootstrap {
     public static BrokerFactory newBrokerFactory(ConfigurationProvider conf,
         ClassLoader loader) {
         try {
-            return invokeFactory(conf, loader, "newInstance");
+            BrokerFactory factory = invokeFactory(conf, loader, "newInstance");
+            factory.postCreationCallback();
+            return factory;
         } catch (InvocationTargetException ite) {
             Throwable cause = ite.getTargetException();
             if (cause instanceof OpenJPAException)

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerFactory.java?rev=953760&r1=953759&r2=953760&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerFactory.java
Fri Jun 11 16:37:30 2010
@@ -156,4 +156,9 @@ public interface BrokerFactory
      * with information on when the broker was closed. 
      */
     public void assertOpen(); 
+    
+    /**
+     * This method is invoked AFTER a BrokerFactory has been instantiated. 
+     */
+    public void postCreationCallback();
 }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBrokerFactory.java?rev=953760&r1=953759&r2=953760&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBrokerFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBrokerFactory.java
Fri Jun 11 16:37:30 2010
@@ -231,4 +231,12 @@ public class DelegatingBrokerFactory
             throw translate(re);
         }
     }
+    
+    public void postCreationCallback() {
+        try {
+            _factory.postCreationCallback();
+        } catch (RuntimeException re) {
+            throw translate(re);
+        }
+    }
 }

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestBrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestBrokerFactory.java?rev=953760&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestBrokerFactory.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestBrokerFactory.java
Fri Jun 11 16:37:30 2010
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.kernel;
+
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl;
+import org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory;
+import org.apache.openjpa.kernel.StoreManager;
+import org.apache.openjpa.lib.conf.ConfigurationProvider;
+
+@SuppressWarnings("serial")
+public class TestBrokerFactory extends JDBCBrokerFactory {
+    JDBCConfiguration _conf;
+    public TestBrokerFactory(JDBCConfiguration conf) {
+        super(conf);
+        _conf = conf;
+    }
+    
+    public static TestBrokerFactory newInstance(ConfigurationProvider cp) {
+        JDBCConfiguration conf = new JDBCConfigurationImpl();
+        cp.setInto(conf);
+        return new TestBrokerFactory(conf);
+    }   
+    
+    @Override
+    protected StoreManager newStoreManager() {
+        // Do something with the config.
+        _conf.getLog();
+        
+        return super.newStoreManager();
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestBrokerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestInitializeEagerly.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestInitializeEagerly.java?rev=953760&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestInitializeEagerly.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestInitializeEagerly.java
Fri Jun 11 16:37:30 2010
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.kernel;
+
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestInitializeEagerly extends SingleEMFTestCase {
+
+    public void setUp() throws Exception {
+        super.setUp(RuntimeTest1.class, 
+            "openjpa.InitializeEagerly", "true", 
+            "openjpa.BrokerFactory", TestBrokerFactory.class.getName()
+            );
+    }
+    
+    // Smoke test to ensure that the EMF is created properly when using this property. 
+    public void test(){
+        assertNotNull(emf);
+    }
+       
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestInitializeEagerly.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message