You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by cu...@apache.org on 2010/05/03 17:55:16 UTC

svn commit: r940490 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java

Author: curtisr7
Date: Mon May  3 15:55:16 2010
New Revision: 940490

URL: http://svn.apache.org/viewvc?rev=940490&view=rev
Log:
OPENJPA-1646: Move DataCacheManager initialization to EMF creation time to close timing window.

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java?rev=940490&r1=940489&r2=940490&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java Mon May  3 15:55:16 2010
@@ -679,24 +679,15 @@ public class OpenJPAConfigurationImpl
         dataCacheManagerPlugin.set(dcm);
     }
 
-    // This boolean is used for double checked locking. We want to minimize the amount of time that
-    // we're locking here.
-    private boolean dataCacheManagerInitialized = false;
     public DataCacheManager getDataCacheManagerInstance() {
-        if (dataCacheManagerInitialized == false) {
-            synchronized (this) {
-                if (dataCacheManagerInitialized == false) {
-                    DataCacheManager dcm = (DataCacheManager) dataCacheManagerPlugin.get();
-                    if (dcm == null) {
-                        dcm = (DataCacheManager) dataCacheManagerPlugin.instantiate(DataCacheManager.class, this);
-                        dcm.initialize(this, dataCachePlugin, queryCachePlugin);
-                    }
-                    dataCacheManagerInitialized = true;
-                    return dcm;
-                }
+        DataCacheManager dcm = (DataCacheManager) dataCacheManagerPlugin.get();
+        if (dcm == null) {
+            dcm = (DataCacheManager) dataCacheManagerPlugin.instantiate(DataCacheManager.class, this);
+            if (dcm != null) {
+                dcm.initialize(this, dataCachePlugin, queryCachePlugin);
             }
         }
-        return (DataCacheManager) dataCacheManagerPlugin.get();
+        return dcm;
     }
 
     public void setDataCache(String dataCache) {

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java?rev=940490&r1=940489&r2=940490&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java Mon May  3 15:55:16 2010
@@ -102,12 +102,8 @@ public class PersistenceProviderImpl
             // Create appropriate LifecycleEventManager
             loadValidator(factory);
             
-            // We need to wait to preload until after we get back a fully configured/instantiated
-            // BrokerFactory. This is because it is possible that someone has extended OpenJPA
-            // functions and they need to be allowed time to configure themselves before we go off and
-            // start instanting configurable objects (ie:openjpa.MetaDataRepository). Don't catch
-            // any exceptions here because we want to fail-fast.
-            preloadMetaDataRepository(factory);
+            // Perform post BrokerFactory initialization.
+            postBrokerFactoryInitialization(factory);
             
             return JPAFacadeHelper.toEntityManagerFactory(factory);
         } catch (Exception e) {
@@ -203,12 +199,8 @@ public class PersistenceProviderImpl
             // Create appropriate LifecycleEventManager
             loadValidator(factory);
             
-            // We need to wait to preload until after we get back a fully configured/instantiated
-            // BrokerFactory. This is because it is possible that someone has extended OpenJPA
-            // functions and they need to be allowed time to configure themselves before we go off and
-            // start instanting configurable objects (ie:openjpa.MetaDataRepository). Don't catch
-            // any exceptions here because we want to fail-fast.
-            preloadMetaDataRepository(factory);
+            // Perform post BrokerFactory initialization.
+            postBrokerFactoryInitialization(factory);
             
             return JPAFacadeHelper.toEntityManagerFactory(factory);
         } catch (Exception e) {
@@ -258,10 +250,9 @@ public class PersistenceProviderImpl
     }
 
     /**
-     * Private worker method that will call to the MetaDataRepository to preload if the provided
-     * BrokerFactory is configured to do so.
+     * Private worker method that will perform initialization that needs to happen AFTER BrokerFactory creation.
      */
-    private void preloadMetaDataRepository(BrokerFactory factory){
+    private void postBrokerFactoryInitialization(BrokerFactory factory){
         // We need to wait to preload until after we get back a fully configured/instantiated
         // BrokerFactory. This is because it is possible that someone has extended OpenJPA
         // functions and they need to be allowed time to configure themselves before we go off and
@@ -279,6 +270,9 @@ public class PersistenceProviderImpl
                 .doPrivileged(J2DoPrivHelper.getContextClassLoaderAction()));
             mdr.preload();
         }
+        
+        // Get a DataCacheManager instance up front to avoid threading concerns on first call.
+        conf.getDataCacheManagerInstance();
     }
     
     /**