Author: ppoddar
Date: Wed Aug 27 08:49:53 2008
New Revision: 689503

URL: http://svn.apache.org/viewvc?rev=689503&view=rev
Log:
OPENJPA-620: An eagerly initialized configuration with fail-fast behavior on 
persistent class resolution

Modified:
    
openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java
    
openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.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/MetaDataRepository.java
    
openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties
    openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_conf.xml

Modified: 
openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java
URL: 
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java?rev=689503&r1=689502&r2=689503&view=diff
==============================================================================
--- 
openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java
 (original)
+++ 
openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java
 Wed Aug 27 08:49:53 2008
@@ -1510,4 +1510,20 @@
      * @since 1.1.0 
      */
     public Map getCacheMarshallerInstances();
+    
+    /**
+     * Affirms if all configured elements are initialized eagerly as opposed
+     * to lazily on-demand.
+     * 
+     * @since 1.3.0
+     */
+    public boolean isInitializeEagerly();
+    
+    /**
+     * Sets whether all configured elements will be initialized eagerly or
+     * lazily on-demand.
+     * 
+     * @since 1.3.0
+     */
+    public void setInitializeEagerly(boolean flag);
 }

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=689503&r1=689502&r2=689503&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
 Wed Aug 27 08:49:53 2008
@@ -135,6 +135,7 @@
     public QueryCompilationCacheValue queryCompilationCachePlugin;
     public IntValue runtimeUnenhancedClasses;
     public CacheMarshallersValue cacheMarshallerPlugins;
+    public BooleanValue eagerInitialization;
 
     // custom values
     public BrokerFactoryValue brokerFactoryPlugin;
@@ -507,6 +508,8 @@
 
         cacheMarshallerPlugins = (CacheMarshallersValue)
             addValue(new CacheMarshallersValue(this));
+        
+        eagerInitialization = addBoolean("InitializeEagerly");
 
         // initialize supported options that some runtimes may not support
         supportedOptions.add(OPTION_NONTRANS_READ);
@@ -1427,12 +1430,24 @@
     public Map getCacheMarshallerInstances() {
         return cacheMarshallerPlugins.getInstancesAsMap();
     }
+    
+    public boolean isInitializeEagerly() {
+       return eagerInitialization.get();
+    }
+    
+    public void setInitializeEagerly(boolean retry) {
+       eagerInitialization.set(retry);
+    }
 
     public void instantiateAll() {
         super.instantiateAll();
         getMetaDataRepositoryInstance();
         getRemoteCommitEventManager();
         cacheMarshallerPlugins.initialize();
+        if (isInitializeEagerly()) {
+               getConnectionFactory();
+               getConnectionFactory2();
+        }
     }
 
     protected void preClose() {

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=689503&r1=689502&r2=689503&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
 Wed Aug 27 08:49:53 2008
@@ -147,6 +147,13 @@
         _conf = config;
         _brokers = newBrokerSet();
         getPcClassLoaders();
+        if (config.isInitializeEagerly()) {
+            newBroker(_conf.getConnectionUserName(), 
+               _conf.getConnectionPassword(), 
+               _conf.isConnectionFactoryModeManaged(),
+                _conf.getConnectionRetainModeConstant(), false).close(); 
+        }
+
     }
 
     /**
@@ -274,7 +281,7 @@
         Collection toRedefine = new ArrayList();
         if (!_persistentTypesLoaded) {
             Collection clss = _conf.getMetaDataRepositoryInstance().
-                loadPersistentTypes(false, loader);
+                loadPersistentTypes(false, loader, 
_conf.isInitializeEagerly());
             if (clss.isEmpty())
                 _pcClassNames = Collections.EMPTY_SET;
             else {
@@ -644,7 +651,8 @@
             // avoid synchronization
             _conf.setReadOnly(Configuration.INIT_STATE_FREEZING);
             _conf.instantiateAll();
-
+            if (_conf.isInitializeEagerly())
+               _conf.setReadOnly(Configuration.INIT_STATE_FROZEN);
             // fire an event for all the broker factory listeners
             // registered on the configuration.
             _conf.getBrokerFactoryEventManager().fireEvent(

Modified: 
openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
URL: 
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java?rev=689503&r1=689502&r2=689503&view=diff
==============================================================================
--- 
openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
 (original)
+++ 
openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
 Wed Aug 27 08:49:53 2008
@@ -1252,6 +1252,11 @@
         ClassLoader envLoader) {
         return _factory.getPersistentTypeNames(devpath, envLoader);
     }
+    
+    public synchronized Collection loadPersistentTypes(boolean devpath,
+            ClassLoader envLoader) {
+       return loadPersistentTypes(devpath, envLoader, false);
+    }
 
     /**
      * Load the persistent classes named in configuration.
@@ -1263,13 +1268,19 @@
      * @param devpath if true, search for metadata files in directories
      * in the classpath if the no classes are configured explicitly
      * @param envLoader the class loader to use, or null for default
+     * @param mustExist if true then empty list of classes or any unloadable
+     * but specified class will raise an exception. 
      * @return the loaded classes, or empty collection if none
      */
     public synchronized Collection loadPersistentTypes(boolean devpath,
-        ClassLoader envLoader) {
+        ClassLoader envLoader, boolean mustExist) {
         Set names = getPersistentTypeNames(devpath, envLoader);
-        if (names == null || names.isEmpty())
-            return Collections.EMPTY_LIST;
+        if (names == null || names.isEmpty()) {
+               if (!mustExist)
+                       return Collections.EMPTY_LIST;
+               else
+                       throw new 
MetaDataException(_loc.get("eager-no-class-found"));
+        }
 
         // attempt to load classes so that they get processed
         ClassLoader clsLoader = _conf.getClassResolverInstance().
@@ -1277,7 +1288,8 @@
         List classes = new ArrayList(names.size());
         Class cls;
         for (Iterator itr = names.iterator(); itr.hasNext();) {
-            cls = classForName((String) itr.next(), clsLoader);
+               String className = (String) itr.next();
+            cls = classForName(className, clsLoader);
             if (cls != null) {
                 classes.add(cls);
 
@@ -1285,6 +1297,9 @@
                 // off the impl generator
                 if (cls.isInterface())
                     getMetaData(cls, clsLoader, false);
+            } else if (cls == null && mustExist) {
+                       throw new 
MetaDataException(_loc.get("eager-class-not-found", 
+                                       className));
             }
         }
         return classes;

Modified: 
openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties
URL: 
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties?rev=689503&r1=689502&r2=689503&view=diff
==============================================================================
--- 
openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties
 (original)
+++ 
openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties
 Wed Aug 27 08:49:53 2008
@@ -316,3 +316,7 @@
 interface-badenhance: Dynamic implementation of "{0}" can not be enhanced.
 bad-externalized-value: Value "{0}" was not found in the list of \
        ExternalValues for field "{2}". Valid values are {1}
+eager-no-class-found: No persistent class is specified in eager \
+       initialization mode.
+eager-class-not-found: Specified persistent class "{0}" can not be loaded in \
+       eager initialization mode.
\ No newline at end of file

Modified: openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_conf.xml
URL: 
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_conf.xml?rev=689503&r1=689502&r2=689503&view=diff
==============================================================================
--- openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_conf.xml (original)
+++ openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_conf.xml Wed Aug 27 
08:49:53 2008
@@ -1890,7 +1890,60 @@
             might correspond to a JPA persistence-unit name, or to some other
             more-unique value available in the current environment.
             </para>
-        </section>
+        </section>
+        
+InitializeEagerly
+        <section id="openjpa.InitializeEagerly">
+            <title>
+                openjpa.InitializeEagerly
+            </title>
+            <indexterm zone="openjpa.InitializeEagerly">
+                <primary>
+                    InverseManager
+                </primary>
+            </indexterm>
+            <indexterm zone="openjpa.InitializeEagerly">
+                <primary>
+                    Initialization
+                </primary>
+                <secondary>
+                    Configuration
+                </secondary>
+            </indexterm>
+            <para>
+<emphasis role="bold">Property name: 
</emphasis><literal>openjpa.InitializeEagerly
+</literal>
+            </para>
+            <para>
+<emphasis role="bold">Configuration API:</emphasis>
+<ulink 
url="../javadoc/org/apache/openjpa/conf/OpenJPAConfiguration.html#isInitializeEagerly()">
+<methodname>org.apache.openjpa.conf.OpenJPAConfiguration.isInitializeEagerly
+</methodname></ulink>
+            </para>
+            <para>
+<emphasis role="bold">Resource adaptor config-property: </emphasis><literal>
+InitializeEagerly</literal>
+            </para>
+            <para>
+<emphasis role="bold">Default: </emphasis><literal>false</literal>
+            </para>
+            <para>
+<emphasis role="bold">Possible values: </emphasis><literal>false</literal>,
+<literal>true</literal>
+            </para>
+            <para>
+<emphasis role="bold">Description:</emphasis> Controls whether initialization
+is eager or lazy. Eager initialization imply all persistent classes, their 
+mapping information, database connectivity and all other resources specified in
+the configuration of a persistence unit will be initialized when a persistent 
+unit is constructed. The default behavior is
+lazy i.e. persistent classes, database and other resources are initialized only
+when the application refers to a resource for the first time.
+            </para>
+        </section>
+
+
+        
         <section id="openjpa.InverseManager">
             <title>
                 openjpa.InverseManager


Reply via email to