openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r898024 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-kernel/src/main/java/org/apache/openjpa/conf/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-kernel/src/main/java/org/apache/open...
Date Mon, 11 Jan 2010 19:34:24 GMT
Author: curtisr7
Date: Mon Jan 11 19:34:23 2010
New Revision: 898024

URL: http://svn.apache.org/viewvc?rev=898024&view=rev
Log:
OPENJPA-250: Committing to trunk. Submitted by Patrick Linskey, Simon Droscher, and Rick Curtis.

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.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-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java?rev=898024&r1=898023&r2=898024&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java Mon Jan 11 19:34:23 2010
@@ -104,8 +104,7 @@
  *
  * @author Abe White
  */
-public class MappingRepository
-    extends MetaDataRepository {
+public class MappingRepository extends MetaDataRepository {
 
     private static final Localizer _loc = Localizer.forPackage
         (MappingRepository.class);
@@ -150,56 +149,83 @@
      * Representation of the database schema.
      */
     public SchemaGroup getSchemaGroup() {
-        if (_schema == null)
-            _schema = ((JDBCConfiguration) getConfiguration()).
-                getSchemaFactoryInstance().readSchema();
-        return _schema;
+        if (_locking) {
+            synchronized (this) {
+                if (_schema == null)
+                    _schema = ((JDBCConfiguration) getConfiguration()).getSchemaFactoryInstance().readSchema();
+                return _schema;
+            }
+        } else {
+            if (_schema == null)
+                _schema = ((JDBCConfiguration) getConfiguration()).getSchemaFactoryInstance().readSchema();
+            return _schema;
+        }
     }
 
     /**
      * Representation of the database schema.
      */
     public void setSchemaGroup(SchemaGroup schema) {
-        _schema = schema;
+        if (_locking) {
+            synchronized (this) {
+                _schema = schema;
+            }
+        } else {
+            _schema = schema;
+        }
     }
 
     /**
      * Installs mapping strategies on components.
      */
     public StrategyInstaller getStrategyInstaller() {
-        if (_installer == null)
-            _installer = new RuntimeStrategyInstaller(this);
-        return _installer;
+        if (_locking) {
+            synchronized (this) {
+                if (_installer == null)
+                    _installer = new RuntimeStrategyInstaller(this);
+                return _installer;
+            }
+        } else {
+            if (_installer == null)
+                _installer = new RuntimeStrategyInstaller(this);
+            return _installer;
+        }
     }
 
     /**
      * Installs mapping strategies on components.
      */
     public void setStrategyInstaller(StrategyInstaller installer) {
-        _installer = installer;
+        if (_locking) {
+            synchronized (this) {
+                _installer = installer;
+            }
+        } else {
+            _installer = installer;
+        }
     }
 
     /**
      * Return the query result mapping for the given name.
      */
-    public QueryResultMapping getQueryResultMapping(Class cls,
-        String name, ClassLoader envLoader, boolean mustExist) {
-        lock();
-        try {
-            QueryResultMapping res = getQueryResultMappingInternal(cls, name, envLoader);
-            if (res == null && mustExist)
-                throw new MetaDataException(_loc.get("no-query-res", cls, name));
-            return res;
-        } finally {
-            unlock();
+    public QueryResultMapping getQueryResultMapping(Class<?> cls, String name, ClassLoader loader, boolean mustExist) {
+        QueryResultMapping res = null;
+        if (_locking) {
+            synchronized (this) {
+                res = getQueryResultMappingInternal(cls, name, loader);
+            }
+        } else {
+            res = getQueryResultMappingInternal(cls, name, loader);
         }
+        if (res == null && mustExist)
+            throw new MetaDataException(_loc.get("no-query-res", cls, name));
+        return res;
     }
 
     /**
      * Returned the query result mapping with the given name.
      */
-    private QueryResultMapping getQueryResultMappingInternal(Class cls,
-        String name, ClassLoader envLoader) {
+    private QueryResultMapping getQueryResultMappingInternal(Class<?> cls, String name, ClassLoader envLoader) {
         if (name == null)
             return null;
 
@@ -229,13 +255,15 @@
     /**
      * Return all cached query result mappings.
      */
-    public synchronized QueryResultMapping[] getQueryResultMappings() {
-        lock();
-        try {
+    public QueryResultMapping[] getQueryResultMappings() {
+        if (_locking) {
+            synchronized (this) {
+                Collection values = _results.values();
+                return (QueryResultMapping[]) values.toArray(new QueryResultMapping[values.size()]);
+            }
+        } else {
             Collection values = _results.values();
             return (QueryResultMapping[]) values.toArray(new QueryResultMapping[values.size()]);
-        } finally {
-            unlock();
         }
     }
 
@@ -243,57 +271,63 @@
      * Return the cached query result mapping with the given name, or null if
      * none.
      */
-    public QueryResultMapping getCachedQueryResultMapping
-        (Class cls, String name) {
-        lock();
-        try {
+    public QueryResultMapping getCachedQueryResultMapping(Class cls, String name) {
+        if (_locking) {
+            synchronized (this) {
+                return (QueryResultMapping) _results.get(getQueryResultKey(cls, name));
+            }
+        } else {
             return (QueryResultMapping) _results.get(getQueryResultKey(cls, name));
-        } finally {
-            unlock();
         }
     }
 
     /**
      * Add a query result mapping.
      */
-    public QueryResultMapping addQueryResultMapping(Class cls,
-        String name) {
-        lock();
-        try {
-            QueryResultMapping res = new QueryResultMapping(name, this);
-            res.setDefiningType(cls);
-            _results.put(getQueryResultKey(res), res);
-            return res;
-        } finally {
-            unlock();
+    public QueryResultMapping addQueryResultMapping(Class cls, String name) {
+        if (_locking) {
+            synchronized (this) {
+                return addQueryResultMappingInternal(cls, name);
+            }
+        } else {
+            return addQueryResultMappingInternal(cls, name);
         }
     }
 
+    private QueryResultMapping addQueryResultMappingInternal(Class cls, String name) {
+        QueryResultMapping res = new QueryResultMapping(name, this);
+        res.setDefiningType(cls);
+        _results.put(getQueryResultKey(res), res);
+        return res;
+    }
+
     /**
      * Remove a query result mapping.
      */
-    public boolean removeQueryResultMapping
-        (QueryResultMapping res) {
-        lock();
-        try {
+    public boolean removeQueryResultMapping(QueryResultMapping res) {
+        if (_locking) {
+            synchronized (this) {
+                return _results.remove(getQueryResultKey(res)) != null;
+            }
+        } else {
             return _results.remove(getQueryResultKey(res)) != null;
-        } finally {
-            unlock();
         }
     }
 
     /**
      * Remove a query result mapping.
      */
-    public boolean removeQueryResultMapping(Class cls,
-        String name) {
-        lock();
-        try {
+    public boolean removeQueryResultMapping(Class cls, String name) {
+        if (_locking) {
+            synchronized (this) {
+                if (name == null)
+                    return false;
+                return _results.remove(getQueryResultKey(cls, name)) != null;
+            }
+        } else {
             if (name == null)
                 return false;
             return _results.remove(getQueryResultKey(cls, name)) != null;
-        } finally {
-            unlock();
         }
     }
 
@@ -334,14 +368,17 @@
             mustExist);
     }
 
-    public synchronized void clear() {
-        lock();
-        try {
+    public void clear() {
+        if (_locking) {
+            synchronized (this) {
+                super.clear();
+                _schema = null;
+                _results.clear();
+            }
+        } else {
             super.clear();
             _schema = null;
             _results.clear();
-        } finally {
-            unlock();
         }
     }
 
@@ -1208,7 +1245,7 @@
                 val, name), e);
         }
     }
-
+    
     /**
      * Determine the default handler to use for the given value. Does
      * not take into account the named handler, if any.

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=898024&r1=898023&r2=898024&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 Jan 11 19:34:23 2010
@@ -335,7 +335,7 @@
         mapping = addString("Mapping");
         metaFactoryPlugin = addPlugin("MetaDataFactory", false);
 
-        metaRepositoryPlugin = addValue(new MetaDataRepositoryValue());
+        metaRepositoryPlugin = (MetaDataRepositoryValue) addValue(new MetaDataRepositoryValue());
 
         connectionFactory = addObject("ConnectionFactory");
         connectionFactory.setInstantiatingGetter("getConnectionFactory");

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=898024&r1=898023&r2=898024&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 Mon Jan 11 19:34:23 2010
@@ -264,7 +264,7 @@
      * Load the configured persistent classes list. Performed automatically
      * whenever a broker is created.
      */
-    private void loadPersistentTypes(ClassLoader envLoader) {
+    public void loadPersistentTypes(ClassLoader envLoader) {
         // if we've loaded the persistent types and the class name list
         // is empty, then we can simply return. Note that there is a
         // potential threading scenario in which _persistentTypesLoaded is

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=898024&r1=898023&r2=898024&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 Mon Jan 11 19:34:23 2010
@@ -33,7 +33,6 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
-import java.util.concurrent.locks.ReentrantLock;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.openjpa.conf.OpenJPAConfiguration;
@@ -49,6 +48,7 @@
 import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.lib.util.MultiClassLoader;
+import org.apache.openjpa.lib.util.Options;
 import org.apache.openjpa.lib.util.StringDistance;
 import org.apache.openjpa.util.ImplHelper;
 import org.apache.openjpa.util.InternalException;
@@ -148,9 +148,10 @@
     // system listeners
     private LifecycleEventManager.ListenerList _listeners = new LifecycleEventManager.ListenerList(3);
 
-    private ReentrantLock _lock = null;
     protected boolean _preload = false;
-    protected boolean _noLock = false;
+    protected boolean _preloadComplete = false;
+    protected boolean _locking = true;
+    private static final String PRELOAD_STR = "Preload";
     
     private boolean _reorderMetaDataResolution = false;
 
@@ -292,96 +293,54 @@
         _preload = l;
     }
 
-    /**
-     * Sets whether this repository will use unguarded access. Unguarded access
-     * can be safe if all metadata has been loaded at initialization.
-     */
-    public void setNoLock(boolean l) {
-        _noLock = l;
-    }
-    
-    /**
-     * Affirms whether this repository will use unguarded access. Unguarded access
-     * can be safe if all metadata has been loaded at initialization.
-     */
-    public boolean getNoLock() {
-        return _noLock;
-    }
 
-    /**
-     * Loads all the known persistent classes if {@linkplain #setPreload(boolean) early loading} 
-     * initialization has been set. The configuration must enlist all classes.
-     * 
-     * <br>
-     * If {@linkplain #setNoLock(boolean) no lock} has been set then uses unguarded access to
-     * all internal data container structures.
-     * If the openjpa.MetaDataRepository plugin value preload=false is set, this method will noop.
-     * <p>
-     * NOTE : This method is not thread safe and should ONLY be called by PersistenceProviderImpl.
-     * 
-     * @see #getPersistentTypeNames(boolean, ClassLoader)
+     /**
+     * If the openjpa.MetaDataRepository plugin value Preload=true is set, this method will load all
+     * MetaData for all persistent classes and will remove locking from this class. 
      */
-    public void preload() {
-        if (!_preload) {
+    public synchronized void preload() {
+        if (_preload == false) {
             return;
         }
-        if (_log.isInfoEnabled()) {
-            _log.info(_loc.get(_noLock ? "repos-preload" : "repos-preload-nolock"));
-        }
-
-        // Remove locking and use unsynchronized maps.
-        if (_noLock == true) {
-            _oids = new HashMap<Class<?>, Class<?>>();
-            _impls = new HashMap<Class<?>, Collection<Class<?>>>();
-            _ifaces = new HashMap<Class<?>, Class<?>>();
-            _aliases = new HashMap<String, List<Class<?>>>();
-            _pawares = new HashMap<Class<?>, NonPersistentMetaData>();
-            _nonMapped = new HashMap<Class<?>, NonPersistentMetaData>();
-            _subs = new HashMap<Class<?>, List<Class<?>>>();
-            _metamodel = new HashMap<Class<?>, Class<?>>();
-
-            _lock = null;
+        // If pooling EMFs, this method may be invoked more than once. Only perform this work once.
+        if (_preloadComplete == true) {
+            return;
         }
 
         MultiClassLoader multi = AccessController.doPrivileged(J2DoPrivHelper.newMultiClassLoaderAction());
         multi.addClassLoader(AccessController.doPrivileged(J2DoPrivHelper.getContextClassLoaderAction()));
         multi.addClassLoader(AccessController.doPrivileged(J2DoPrivHelper
-             .getClassLoaderAction(MetaDataRepository.class)));
+            .getClassLoaderAction(MetaDataRepository.class)));
 
         Set<String> classes = getPersistentTypeNames(false, multi);
         if (classes == null || classes.size() == 0) {
-            throw new MetaDataException(_loc.get("repos-preload-none"));
+            throw new MetaDataException(_loc.get("repos-initializeEager-none"));
         }
-        if (_log.isTraceEnabled()) {
-            _log.trace(_loc.get("repos-preloading", this.getClass().getName(), classes.toString()));
+        if (_log.isTraceEnabled() == true) {
+            _log.trace(_loc.get("repos-initializeEager-found", classes));
         }
 
+        List<Class<?>> loaded = new ArrayList<Class<?>>();
         for (String c : classes) {
             try {
                 Class<?> cls = AccessController.doPrivileged((J2DoPrivHelper.getForNameAction(c, true, multi)));
+                loaded.add(cls);
+                // This call may be unnecessary?
                 _factory.load(cls, MODE_ALL, multi);
             } catch (PrivilegedActionException pae) {
-                throw new MetaDataException(_loc.get("repos-preload-error"), pae);
+                throw new MetaDataException(_loc.get("repos-initializeEager-error"), pae);
             }
         }
-        
-        // Hook this class in early so we can process registered classes and add them 
-        // to _aliases list.
+        resolveAll(multi);
+
+        // Hook in this class as a listener and process registered classes list to populate _aliases
+        // list.
         PCRegistry.addRegisterClassListener(this);
         processRegisteredClasses(multi);
+        _locking = false;
+        _preloadComplete = true;
     }
 
-    protected void lock() {
-        if (_lock != null) {
-            _lock.lock();
-        }
-    }
-    
-    protected void unlock() {
-        if (_lock != null) {
-            _lock.unlock();
-        }
-    }
     
     /**
      * Return the metadata for the given class.
@@ -393,9 +352,17 @@
      * @param mustExist
      *            if true, throws a {@link MetaDataException} if no metadata is found
      */
-    public ClassMetaData getMetaData(Class cls, ClassLoader envLoader, boolean mustExist) {
-        lock();
-        try {
+    public ClassMetaData getMetaData(Class<?> cls, ClassLoader envLoader, boolean mustExist) {
+        if (_locking) {
+            synchronized(this){
+                return getMetaDataInternal(cls, envLoader, mustExist);    
+            }
+        } else {
+            return getMetaDataInternal(cls, envLoader, mustExist);
+        }
+    }
+
+    private ClassMetaData getMetaDataInternal(Class<?> cls, ClassLoader envLoader, boolean mustExist) {
             if (cls != null && DynamicPersistenceCapable.class.isAssignableFrom(cls))
                 cls = cls.getSuperclass();
 
@@ -417,9 +384,6 @@
             }
             resolve(meta);
             return meta;
-        } finally {
-            unlock();
-        }
     }
 
     /**
@@ -515,13 +479,21 @@
      * @since 1.1.0
      */
     public Collection<String> getAliasNames() {
+        if (_locking) {
+            synchronized (_aliases) {
+                return getAliasNamesInternal();
+            }
+        } else {
+            return getAliasNamesInternal();
+        }
+    }
+
+    private final Collection<String> getAliasNamesInternal() {
         Collection<String> aliases = new HashSet<String>();
-        synchronized (_aliases) {
             for (Iterator<Map.Entry<String, List<Class<?>>>> iter = _aliases.entrySet().iterator(); iter.hasNext();) {
                 Map.Entry<String, List<Class<?>>> e = iter.next();
                 if (e.getValue() != null)
                     aliases.add(e.getKey());
-            }
         }
         return aliases;
     }
@@ -844,8 +816,16 @@
      * Return all the metadata instances currently in the repository.
      */
     public ClassMetaData[] getMetaDatas() {
-        lock();
-        try {
+        if (_locking) {
+            synchronized(this){
+                return getMetaDatasInternal();    
+            }
+        } else {
+            return getMetaDatasInternal();
+        }
+    }
+    
+    private ClassMetaData[] getMetaDatasInternal() {
             // prevent concurrent mod errors when resolving one metadata
             // introduces others
             ClassMetaData[] metas = (ClassMetaData[]) _metas.values().toArray(new ClassMetaData[_metas.size()]);
@@ -861,9 +841,6 @@
             metas = resolved.toArray(newClassMetaDataArray(resolved.size()));
             Arrays.sort(metas);
             return metas;
-        } finally {
-            unlock();
-        }
     }
 
     /**
@@ -908,14 +885,20 @@
 
         // synchronize on this rather than the map, because all other methods
         // that access _metas are synchronized on this
-        lock();
-        try {
+        if (_locking) {
+            synchronized(this){
+                return metasPutInternal(cls, meta);
+            }
+        } else {
+            return metasPutInternal(cls, meta);
+        }
+            
+    }
+
+    private ClassMetaData metasPutInternal(Class<?> cls, ClassMetaData meta){
             if (_pawares.containsKey(cls))
                 throw new MetaDataException(_loc.get("pc-and-aware", cls));
             _metas.put(cls, meta);
-        } finally {
-            unlock();
-        }
         return meta;
     }
 
@@ -1048,9 +1031,17 @@
      * 
      * @return true if removed, false if not in this repository
      */
-    public boolean removeMetaData(Class cls) {
-        lock();
-        try {
+    public boolean removeMetaData(Class<?> cls) {
+        if(_locking){
+            synchronized(this){
+                return removeMetaDataInternal(cls);
+            }
+        }else{
+            return removeMetaDataInternal(cls);
+        }
+    }
+
+    private boolean removeMetaDataInternal(Class<?> cls) {
             if (cls == null)
                 return false;
             if (_metas.remove(cls) != null) {
@@ -1060,16 +1051,21 @@
                 return true;
             }
             return false;
-        } finally {
-            unlock();
-        }
     }
-
     /**
      * Add the given metadata as declared interface implementation.
      */
     void addDeclaredInterfaceImpl(ClassMetaData meta, Class<?> iface) {
-        synchronized (_impls) {
+        if (_locking) {
+            synchronized (_impls) {
+                addDeclaredInterfaceImplInternal(meta, iface);
+            }
+        } else {
+            addDeclaredInterfaceImplInternal(meta, iface);
+        }
+    }
+
+   private void addDeclaredInterfaceImplInternal(ClassMetaData meta, Class<?> iface) {
             Collection<Class<?>> vals = _impls.get(iface);
 
             // check to see if the superclass already declares to avoid dups
@@ -1081,14 +1077,20 @@
             }
             addToCollection(_impls, iface, meta.getDescribedType(), false);
         }
-    }
-
     /**
      * Set the implementation for the given managed interface.
      */
     void setInterfaceImpl(ClassMetaData meta, Class<?> impl) {
-        lock();
-        try {
+        if (_locking) {
+            synchronized (this) {
+                setInterfaceImplInternal(meta, impl);
+            }
+        } else {
+            setInterfaceImplInternal(meta, impl);
+        }
+    }
+
+    private void setInterfaceImplInternal(ClassMetaData meta, Class<?> impl) {
             if (!meta.isManagedInterface())
                 throw new MetaDataException(_loc.get("not-managed-interface", meta, impl));
             _ifaces.put(meta.getDescribedType(), impl);
@@ -1100,9 +1102,6 @@
                 sup.clearSubclassCache();
                 addToCollection(_subs, sup.getDescribedType(), impl, true);
                 sup = (ClassMetaData) sup.getPCSuperclassMetaData();
-            }
-        } finally {
-            unlock();
         }
     }
 
@@ -1222,21 +1221,14 @@
         // get impls of given interface / abstract class
         loadRegisteredClassMetaData(envLoader);
         Collection<Class<?>> vals = _impls.get(cls);
-        ClassMetaData meta;
-        Collection<ClassMetaData> mapped = null;
+        ClassMetaData[] mapped = null;
         if (vals != null) {
-            lock();
-            try {
-                for (Iterator<Class<?>> itr = vals.iterator(); itr.hasNext();) {
-                    meta = getMetaData(itr.next(), envLoader, true);
-                    if (meta.isMapped() || meta.getMappedPCSubclassMetaDatas().length > 0) {
-                        if (mapped == null)
-                            mapped = new ArrayList<ClassMetaData>(vals.size());
-                        mapped.add(meta);
-                    }
+            if (_locking) {
+                synchronized (vals) {
+                    mapped = getImplementorMetaDatasInternal(vals, envLoader, mustExist);
                 }
-            } finally {
-                unlock();
+            } else {
+                mapped = getImplementorMetaDatasInternal(vals, envLoader, mustExist);
             }
         }
 
@@ -1244,9 +1236,21 @@
             throw new MetaDataException(_loc.get("no-meta", cls));
         if (mapped == null)
             return EMPTY_METAS;
-        return mapped.toArray(newClassMetaDataArray(mapped.size()));
+        return mapped;
     }
 
+    private ClassMetaData[] getImplementorMetaDatasInternal(Collection<Class<?>> classes, ClassLoader envLoader,
+        boolean mustExist) {
+        Collection<ClassMetaData> mapped = new ArrayList<ClassMetaData>(classes.size());
+        ClassMetaData meta = null;
+        for (Class<?> c : classes) {
+            meta = getMetaData(c, envLoader, true);
+            if (meta.isMapped() || meta.getMappedPCSubclassMetaDatas().length > 0) {
+                mapped.add(meta);
+            }
+        }
+        return mapped.toArray(new ClassMetaData[]{});
+    }
     /**
      * Gets the metadata corresponding to the given persistence-aware class. Returns null, if the
      * given class is not registered as persistence-aware.
@@ -1261,14 +1265,19 @@
      * @return empty array if no class has been registered as pers-aware
      */
     public NonPersistentMetaData[] getPersistenceAwares() {
-        lock();
-        try {
+        if (_locking) {
+            synchronized (_pawares) {
+                return getPersistenceAwaresInternal();
+            }
+        } else {
+            return getPersistenceAwaresInternal();
+        }
+    }
+
+    private NonPersistentMetaData[] getPersistenceAwaresInternal() {
             if (_pawares.isEmpty())
                 return EMPTY_NON_PERSISTENT;
             return (NonPersistentMetaData[]) _pawares.values().toArray(new NonPersistentMetaData[_pawares.size()]);
-        } finally {
-            unlock();
-        }
     }
 
     /**
@@ -1280,8 +1289,16 @@
     public NonPersistentMetaData addPersistenceAware(Class<?> cls) {
         if (cls == null)
             return null;
-        lock();
-        try {
+        if (_locking) {
+            synchronized (this) {
+                return addPersistenceAwareInternal(cls);
+            }
+        } else {
+            return addPersistenceAwareInternal(cls);
+        }
+    }
+
+    private NonPersistentMetaData addPersistenceAwareInternal(Class<?> cls) {
             if (_pawares.containsKey(cls))
                 return (NonPersistentMetaData) _pawares.get(cls);
             if (getCachedMetaData(cls) != null)
@@ -1290,9 +1307,6 @@
                 new NonPersistentMetaData(cls, this, NonPersistentMetaData.TYPE_PERSISTENCE_AWARE);
             _pawares.put(cls, meta);
             return meta;
-        } finally {
-            unlock();
-        }
     }
 
     /**
@@ -1318,14 +1332,19 @@
      * @return empty array if no non-mapped interface has been registered.
      */
     public NonPersistentMetaData[] getNonMappedInterfaces() {
-        lock();
-        try {
+        if (_locking) {
+            synchronized (_nonMapped) {
+                return getNonMappedInterfacesInternal();
+            }
+        } else {
+            return getNonMappedInterfacesInternal();
+        }
+    }
+
+    private NonPersistentMetaData[] getNonMappedInterfacesInternal() {
             if (_nonMapped.isEmpty())
                 return EMPTY_NON_PERSISTENT;
             return (NonPersistentMetaData[]) _nonMapped.values().toArray(new NonPersistentMetaData[_nonMapped.size()]);
-        } finally {
-            unlock();
-        }
     }
 
     /**
@@ -1339,8 +1358,16 @@
             return null;
         if (!iface.isInterface())
             throw new MetaDataException(_loc.get("not-non-mapped", iface));
-        lock();
-        try {
+        if (_locking) {
+            synchronized (this) {
+                return addNonMappedInterfaceInternal(iface);
+            }
+        } else {
+            return addNonMappedInterfaceInternal(iface);
+        }
+    }
+    
+    private NonPersistentMetaData addNonMappedInterfaceInternal(Class<?> iface) {
             if (_nonMapped.containsKey(iface))
                 return (NonPersistentMetaData) _nonMapped.get(iface);
             if (getCachedMetaData(iface) != null)
@@ -1349,10 +1376,7 @@
                 new NonPersistentMetaData(iface, this, NonPersistentMetaData.TYPE_NON_MAPPED_INTERFACE);
             _nonMapped.put(iface, meta);
             return meta;
-        } finally {
-            unlock();
         }
-    }
 
     /**
      * Remove a non-mapped interface from the repository
@@ -1368,11 +1392,19 @@
      * {@link MetaDataFactory MetaDataFactory}'s cache.
      */
     public void clear() {
-        lock();
-        try {
             if (_log.isTraceEnabled())
-                _log.trace(_loc.get("clear-repos", this));
+            _log.trace(_loc.get("clear-repos", this));
+        if (_locking) {
+            synchronized (this) {
+                clearInternal();
+            }
+        } else {
+            clearInternal();
+        }
+    }
 
+    private void clearInternal(){
+        // Recreating these datastructures is probably faster than calling clear. Future change?
             _metas.clear();
             _oids.clear();
             _subs.clear();
@@ -1384,11 +1416,7 @@
             _aliases.clear();
             _pawares.clear();
             _nonMapped.clear();
-        } finally {
-            unlock();
-        }
     }
-
     /**
      * Return the set of configured persistent classes, or null if the user did not configure any.
      * 
@@ -1399,18 +1427,33 @@
      *            the class loader to use, or null for default
      */
     public Set<String> getPersistentTypeNames(boolean devpath, ClassLoader envLoader) {
-        lock();
-        try {
-            return _factory.getPersistentTypeNames(devpath, envLoader);
-        } finally {
-            unlock();
+        if (_locking) {
+            synchronized (this) {
+                return getPersistentTypeNamesInternal(devpath, envLoader);
+            }
+        } else {
+            return getPersistentTypeNamesInternal(devpath, envLoader);
         }
     }
 
-    public synchronized Collection<Class<?>> loadPersistentTypes(boolean devpath, ClassLoader envLoader) {
+    private Set<String> getPersistentTypeNamesInternal(boolean devpath, ClassLoader envLoader) {
+        return _factory.getPersistentTypeNames(devpath, envLoader);
+    }
+    /**
+     * Load the persistent classes named in configuration.
+     * This ensures that all subclasses and application identity classes of
+     * each type are known in advance, without having to rely on the
+     * application loading the classes before performing operations that
+     * might involve them.
+     *
+     * @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
+     * @return the loaded classes, or empty collection if none
+     */
+    public Collection<Class<?>> loadPersistentTypes(boolean devpath, ClassLoader envLoader) {
         return loadPersistentTypes(devpath, envLoader, false);
     }
-
     /**
      * Load the persistent classes named in configuration. This ensures that all subclasses and
      * application identity classes of each type are known in advance, without having to rely on the
@@ -1427,12 +1470,21 @@
      * @return the loaded classes, or empty collection if none
      */
     public Collection<Class<?>> loadPersistentTypes(boolean devpath, ClassLoader envLoader, boolean mustExist) {
-        lock();
-        try {
+        if (_locking) {
+            synchronized (this) {
+                return loadPersistentTypesInternal(devpath, envLoader, mustExist);
+            }
+        } else {
+            return loadPersistentTypesInternal(devpath, envLoader, mustExist);
+        }
+    }
+
+    private Collection<Class<?>> loadPersistentTypesInternal(boolean devpath, ClassLoader envLoader, 
+        boolean mustExist) {
             Set<String> names = getPersistentTypeNames(devpath, envLoader);
             if (names == null || names.isEmpty()) {
                 if (!mustExist)
-                    return Collections.EMPTY_LIST;
+                    return Collections.emptyList();
                 else
                     throw new MetaDataException(_loc.get("eager-no-class-found"));
             }
@@ -1459,9 +1511,6 @@
                 }
             }
             return classes;
-        } finally {
-            unlock();
-        }
     }
 
     /**
@@ -1503,7 +1552,7 @@
     Collection<Class<?>> getPCSubclasses(Class<?> cls) {
         Collection<Class<?>> subs = _subs.get(cls);
         if (subs == null)
-            return Collections.EMPTY_LIST;
+            return Collections.emptyList();
         return subs;
     }
 
@@ -1511,15 +1560,15 @@
     // RegisterClassListener implementation
     // //////////////////////////////////////
 
-    public void register(Class cls) {
+    public void register(Class<?> cls) {
         // buffer registered classes until an oid metadata request is made,
         // at which point we'll parse everything in the buffer
-        lock();
-        try {
+        if (_locking) {
+            synchronized (_registered) {
+                _registered.add(cls);
+            }
+        } else {
             _registered.add(cls);
-            registerAlias(cls);
-        } finally {
-            unlock();
         }
     }
 
@@ -1548,12 +1597,14 @@
         // copy into new collection to avoid concurrent mod errors on reentrant
         // registrations
         Class<?>[] reg;
-        lock();
-        try {
+        if (_locking) {
+            synchronized (_registered) {
+                reg = _registered.toArray(new Class[_registered.size()]);
+                _registered.clear();
+            }
+        } else {
             reg = _registered.toArray(new Class[_registered.size()]);
             _registered.clear();
-        } finally {
-            unlock();
         }
         
 
@@ -1579,11 +1630,12 @@
             }
         }
         if (failed != null) {
-            lock();
-            try {
+            if (_locking) {
+                synchronized (_registered) {
+                    _registered.addAll(failed);
+                }
+            } else {
                 _registered.addAll(failed);
-            } finally {
-                unlock();
             }
         }
         return reg;
@@ -1601,8 +1653,7 @@
         // update subclass lists; synchronize on this because accessing _metas
         // requires it
         Class<?> leastDerived = cls;
-        lock();
-        try {
+        synchronized (this) {
             ClassMetaData meta;
             for (Class<?> anc = cls; (anc = PCRegistry.getPersistentSuperclass(anc)) != null;) {
                 addToCollection(_subs, anc, cls, true);
@@ -1611,10 +1662,8 @@
                     meta.clearSubclassCache();
                 leastDerived = anc;
             }
-        } finally {
-            unlock();
         }
-
+        
         // update oid mappings if this is a base concrete class
         Object oid = null;
         try {
@@ -1642,7 +1691,11 @@
 
         // update mappings from interfaces and non-pc superclasses to
         // pc implementing types
-        synchronized (_impls) {
+        if (_locking) {
+            synchronized (_impls) {
+                updateImpls(cls, leastDerived, cls);
+            }
+        } else {
             updateImpls(cls, leastDerived, cls);
         }
 
@@ -1664,7 +1717,6 @@
         if (alias == null)
             return;
         try {
-            lock();
             if (alias != null) {
                 List<Class<?>> classes = _aliases.get(alias);
                 if (classes == null)
@@ -1676,8 +1728,6 @@
             }
         } catch (IllegalStateException ise) {
             // the class has not been registered to PCRegistry
-        } finally {
-            unlock();
         }
     }
 
@@ -1728,24 +1778,29 @@
      * Add the given value to the collection cached in the given map under the given key.
      */
     private void addToCollection(Map map, Class<?> key, Class<?> value, boolean inheritance) {
-        lock();
-        try {
-            Collection coll = (Collection) map.get(key);
-            if (coll == null) {
-                if (inheritance) {
-                    InheritanceComparator comp = new InheritanceComparator();
-                    comp.setBase(key);
-                    coll = new TreeSet<Class<?>>(comp);
-                } else
-                    coll = new LinkedList<Class<?>>();
-                map.put(key, coll);
-            }
-            coll.add(value);
-        } finally {
-            unlock();
+        if (_locking) {
+            synchronized (map) {
+                addToCollectionInternal(map, key, value, inheritance);
+            }
+        } else {
+            addToCollectionInternal(map, key, value, inheritance);
         }
     }
 
+    private void addToCollectionInternal(Map map, Class<?> key, Class<?> value, boolean inheritance) {
+        Collection coll = (Collection) map.get(key);
+        if (coll == null) {
+            if (inheritance) {
+                InheritanceComparator comp = new InheritanceComparator();
+                comp.setBase(key);
+                coll = new TreeSet<Class<?>>(comp);
+            } else
+                coll = new LinkedList<Class<?>>();
+            map.put(key, coll);
+        }
+        coll.add(value);
+    }
+
     /**
      * Puts the meta class corresponding to the given entity class.
      */
@@ -1804,11 +1859,19 @@
     }
 
     public void endConfiguration() {
-        _lock = new ReentrantLock();
-        
         initializeMetaDataFactory();
         if (_implGen == null)
             _implGen = new InterfaceImplGenerator(this);
+        if (_preload == true) {
+            _oids = new HashMap<Class<?>, Class<?>>();
+            _impls = new HashMap<Class<?>, Collection<Class<?>>>();
+            _ifaces = new HashMap<Class<?>, Class<?>>();
+            _aliases = new HashMap<String, List<Class<?>>>();
+            _pawares = new HashMap<Class<?>, NonPersistentMetaData>();
+            _nonMapped = new HashMap<Class<?>, NonPersistentMetaData>();
+            _subs = new HashMap<Class<?>, List<Class<?>>>();
+            // Wait till we're done loading MetaData to flip _lock boolean.
+        }            
     }
 
     private void initializeMetaDataFactory() {
@@ -1828,8 +1891,17 @@
      * Return query metadata for the given class, name, and classloader.
      */
     public QueryMetaData getQueryMetaData(Class<?> cls, String name, ClassLoader envLoader, boolean mustExist) {
-        lock();
-        try {
+        if (_locking) {
+            synchronized (this) {
+                return getQueryMetaDataInternal(cls, name, envLoader, mustExist);
+            }
+        } else {
+            return getQueryMetaDataInternal(cls, name, envLoader, mustExist);
+        }
+    }
+
+    private QueryMetaData getQueryMetaDataInternal(Class<?> cls, String name, ClassLoader envLoader, 
+        boolean mustExist) {
             QueryMetaData meta = getQueryMetaDataInternal(cls, name, envLoader);
             if (meta == null) {
                 // load all the metadatas for all the known classes so that
@@ -1848,9 +1920,6 @@
             }
 
             return meta;
-        } finally {
-            unlock();
-        }
     }
 
     /**
@@ -1903,11 +1972,12 @@
      * Return the cached query metadata.
      */
     public QueryMetaData[] getQueryMetaDatas() {
-        lock();
-        try {
-            return _queries.values().toArray(new QueryMetaData[_queries.size()]);
-        } finally {
-            unlock();
+        if (_locking) {
+            synchronized (this) {
+                return (QueryMetaData[]) _queries.values().toArray(new QueryMetaData[_queries.size()]);
+            }
+        } else {
+            return (QueryMetaData[]) _queries.values().toArray(new QueryMetaData[_queries.size()]);
         }
     }
 
@@ -1915,11 +1985,12 @@
      * Return the cached query metadata for the given name.
      */
     public QueryMetaData getCachedQueryMetaData(Class<?> cls, String name) {
-        lock();
-        try {
-            return _queries.get(getQueryKey(cls, name));
-        } finally {
-            unlock();
+        if (_locking) {
+            synchronized (this) {
+                return (QueryMetaData) _queries.get(getQueryKey(cls, name));
+            }
+        } else {
+            return (QueryMetaData) _queries.get(getQueryKey(cls, name));
         }
     }
 
@@ -1927,13 +1998,16 @@
      * Add a new query metadata to the repository and return it.
      */
     public QueryMetaData addQueryMetaData(Class<?> cls, String name) {
-        lock();
-        try{
+        if (_locking) {
+            synchronized (this) {
+                QueryMetaData meta = newQueryMetaData(cls, name);
+                _queries.put(getQueryKey(meta), meta);
+                return meta;
+            }
+        }else{
             QueryMetaData meta = newQueryMetaData(cls, name);
             _queries.put(getQueryKey(meta), meta);
-            return meta;
-        }finally{
-            unlock();
+            return meta;   
         }
     }
 
@@ -1941,29 +2015,23 @@
      * Create a new query metadata instance.
      */
     protected QueryMetaData newQueryMetaData(Class<?> cls, String name) {
-        lock();
-        try {
-            QueryMetaData meta = new QueryMetaData(name);
-            meta.setDefiningType(cls);
-            return meta;
-        } finally {
-            unlock();
-        }
+        QueryMetaData meta = new QueryMetaData(name);
+        meta.setDefiningType(cls);
+        return meta;
     }
 
     /**
      * Remove the given query metadata from the repository.
      */
     public boolean removeQueryMetaData(QueryMetaData meta) {
-        lock();
-        try {
-            if (meta == null) {
-                return false;
+        if (meta == null)
+            return false;
+        if (_locking) {
+            synchronized (this) {
+                return _queries.remove(getQueryKey(meta)) != null;
             }
-
+        } else {
             return _queries.remove(getQueryKey(meta)) != null;
-        } finally {
-            unlock();
         }
     }
 
@@ -1971,13 +2039,16 @@
      * Remove query metadata for the given class name if in the repository.
      */
     public boolean removeQueryMetaData(Class<?> cls, String name) {
-        lock();
-        try {
+        if (_locking) {
+            synchronized (this) {
+                if (name == null)
+                    return false;
+                return _queries.remove(getQueryKey(cls, name)) != null;
+            }
+        } else {
             if (name == null)
                 return false;
             return _queries.remove(getQueryKey(cls, name)) != null;
-        } finally {
-            unlock();
         }
     }
 
@@ -2022,8 +2093,16 @@
      * Return sequence metadata for the given name and classloader.
      */
     public SequenceMetaData getSequenceMetaData(String name, ClassLoader envLoader, boolean mustExist) {
-        lock();
-        try {
+        if (_locking) {
+            synchronized (this) {
+                return getSequenceMetaDataInternal(name, envLoader, mustExist);
+            }
+        } else {
+            return getSequenceMetaDataInternal(name, envLoader, mustExist);
+        }
+    }
+
+    private SequenceMetaData getSequenceMetaDataInternal(String name, ClassLoader envLoader, boolean mustExist) {
             SequenceMetaData meta = getSequenceMetaDataInternal(name, envLoader);
             if (meta == null && SequenceMetaData.NAME_SYSTEM.equals(name)) {
                 if (_sysSeq == null)
@@ -2033,9 +2112,6 @@
             if (meta == null && mustExist)
                 throw new MetaDataException(_loc.get("no-named-sequence", name));
             return meta;
-        } finally {
-            unlock();
-        }
     }
 
     /**
@@ -2094,11 +2170,12 @@
      * Return the cached sequence metadata.
      */
     public SequenceMetaData[] getSequenceMetaDatas() {
-        lock();
-        try {
-            return _seqs.values().toArray(new SequenceMetaData[_seqs.size()]);
-        } finally {
-            unlock();
+        if (_locking) {
+            synchronized (this) {
+                return (SequenceMetaData[]) _seqs.values().toArray(new SequenceMetaData[_seqs.size()]);
+            }
+        } else {
+            return (SequenceMetaData[]) _seqs.values().toArray(new SequenceMetaData[_seqs.size()]);
         }
     }
 
@@ -2106,11 +2183,12 @@
      * Return the cached a sequence metadata for the given name.
      */
     public SequenceMetaData getCachedSequenceMetaData(String name) {
-        lock();
-        try {
-            return _seqs.get(name);
-        } finally {
-            unlock();
+        if (_locking) {
+            synchronized (this) {
+                return (SequenceMetaData) _seqs.get(name);
+            }
+        } else {
+            return (SequenceMetaData) _seqs.get(name);
         }
     }
 
@@ -2118,13 +2196,16 @@
      * Add a new sequence metadata to the repository and return it.
      */
     public SequenceMetaData addSequenceMetaData(String name) {
-        lock();
-        try {
+        if (_locking) {
+            synchronized (this) {
+                SequenceMetaData meta = newSequenceMetaData(name);
+                _seqs.put(name, meta);
+                return meta;
+            }
+        } else {
             SequenceMetaData meta = newSequenceMetaData(name);
             _seqs.put(name, meta);
             return meta;
-        } finally {
-            unlock();
         }
     }
 
@@ -2139,13 +2220,14 @@
      * Remove the given sequence metadata from the repository.
      */
     public boolean removeSequenceMetaData(SequenceMetaData meta) {
-        lock();
-        try {
-            if (meta == null)
-                return false;
+        if (meta == null)
+            return false;
+        if (_locking) {
+            synchronized (this) {
+                return _seqs.remove(meta.getName()) != null;
+            }
+        } else {
             return _seqs.remove(meta.getName()) != null;
-        } finally {
-            unlock();
         }
     }
 
@@ -2153,13 +2235,14 @@
      * Remove sequence metadata for the name if in the repository.
      */
     public boolean removeSequenceMetaData(String name) {
-        lock();
-        try {
-            if (name == null)
-                return false;
+        if (name == null)
+            return false;
+        if (_locking) {
+            synchronized (this) {
+                return _seqs.remove(name) != null;
+            }
+        } else {
             return _seqs.remove(name) != null;
-        } finally {
-            unlock();
         }
     }
 
@@ -2167,15 +2250,18 @@
      * Add the given system lifecycle listener.
      */
     public void addSystemListener(Object listener) {
-        lock();
-        try {
-            // copy to avoid issues with ListenerList and avoid unncessary
-            // locking on the list during runtime
+        if (_locking) {
+            synchronized (this) {
+                // copy to avoid issues with ListenerList and avoid unncessary
+                // locking on the list during runtime
+                LifecycleEventManager.ListenerList listeners = new LifecycleEventManager.ListenerList(_listeners);
+                listeners.add(listener);
+                _listeners = listeners;
+            }
+        } else {
             LifecycleEventManager.ListenerList listeners = new LifecycleEventManager.ListenerList(_listeners);
             listeners.add(listener);
             _listeners = listeners;
-        } finally {
-            unlock();
         }
     }
 
@@ -2183,8 +2269,16 @@
      * Remove the given system lifecycle listener.
      */
     public boolean removeSystemListener(Object listener) {
-        lock();
-        try {
+        if (_locking) {
+            synchronized (this) {
+                return removeSystemListenerInternal(listener);
+            }
+        } else {
+            return removeSystemListenerInternal(listener);
+        }
+    }
+
+    private boolean removeSystemListenerInternal(Object listener) {
             if (!_listeners.contains(listener))
                 return false;
 
@@ -2194,9 +2288,6 @@
             listeners.remove(listener);
             _listeners = listeners;
             return true;
-        } finally {
-            unlock();
-        }
     }
 
     /**
@@ -2210,15 +2301,20 @@
      * Free the resources used by this repository. Closes all user sequences.
      */
     public void close() {
-        lock();
-        try {
+        if (_locking) {
+            synchronized (this) {
+                closeInternal();
+            }
+        } else {
+            closeInternal();
+        }
+    }
+
+    private void closeInternal() {
             SequenceMetaData[] smds = getSequenceMetaDatas();
             for (int i = 0; i < smds.length; i++)
                 smds[i].close();
             clear();
-        } finally {
-            unlock();
-        }
     }
 
     /**
@@ -2253,23 +2349,28 @@
      * @return XML metadata
      */
     public XMLMetaData getXMLMetaData(FieldMetaData fmd) {
-        lock();
-        try {
-            Class<?> cls = fmd.getDeclaredType();
-            // check if cached before
-            XMLMetaData xmlmeta = _xmlmetas.get(cls);
-            if (xmlmeta != null)
-                return xmlmeta;
+        if (_locking) {
+            synchronized (this) {
+                return getXMLMetaDataInternal(fmd);
+            }
+        } else {
+            return getXMLMetaDataInternal(fmd);
+        }
+    }
+    
+    private XMLMetaData getXMLMetaDataInternal(FieldMetaData fmd) {
+        Class<?> cls = fmd.getDeclaredType();
+        // check if cached before
+        XMLMetaData xmlmeta = _xmlmetas.get(cls);
+        if (xmlmeta != null)
+            return xmlmeta;
 
-            // load JAXB XML metadata
-            _factory.loadXMLMetaData(fmd);
+        // load JAXB XML metadata
+        _factory.loadXMLMetaData(fmd);
 
-            xmlmeta = (XMLClassMetaData) _xmlmetas.get(cls);
+        xmlmeta = (XMLClassMetaData) _xmlmetas.get(cls);
 
-            return xmlmeta;
-        } finally {
-            unlock();
-        }
+        return xmlmeta;
     }
 
     /**
@@ -2281,11 +2382,12 @@
      */
     public XMLClassMetaData addXMLMetaData(Class<?> type, String name) {
         XMLClassMetaData meta = newXMLClassMetaData(type, name);
-        lock();
-        try {
+        if(_locking){
+            synchronized(this){
+                _xmlmetas.put(type, meta);                
+            }
+        }else{
             _xmlmetas.put(type, meta);
-        } finally {
-            unlock();
         }
         return meta;
     }
@@ -2509,4 +2611,12 @@
             return false;
         }
     }
+
+    public static boolean needsPreload(Options o) {
+        if (o.getBooleanProperty(PRELOAD_STR) == true) {
+            return true;
+        }
+        return false;
+    }
+
 }

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=898024&r1=898023&r2=898024&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 Mon Jan 11 19:34:23 2010
@@ -350,4 +350,9 @@
 	See nested stacktrace for details. 	  
 cmd-discover-cycle: A cycle was detected while resolving the identity \
     references for type "{0}".  The original process buffer ordering \
-    will be used.
\ No newline at end of file
+    will be used.
+repos-initializeEager-none: No persistent metadata found for loading during initialization. \
+    The persistent classes must be listed in persistence unit configuration to be loaded during initialization.
+repos-initializeEager-found: The following classes are being preloaded "{0}".	   
+repos-initializeEager-error: Unexpected error during early loading of entity metadata during initialization. \
+    See nested stacktrace for details.	  

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java?rev=898024&r1=898023&r2=898024&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java Mon Jan 11 19:34:23 2010
@@ -988,9 +988,8 @@
      *   
      * @return MultiClassLoader
      */
-    public static final PrivilegedAction<MultiClassLoader>
-        newMultiClassLoaderAction() {
-        return new PrivilegedAction<MultiClassLoader>() {
+    public static final PrivilegedAction<MultiClassLoader> newMultiClassLoaderAction() {
+        return new PrivilegedAction() {
             public MultiClassLoader run() {
                 return new MultiClassLoader();
             }

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=898024&r1=898023&r2=898024&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 Jan 11 19:34:23 2010
@@ -20,6 +20,7 @@
 
 import java.lang.instrument.ClassFileTransformer;
 import java.lang.instrument.IllegalClassFormatException;
+import java.security.AccessController;
 import java.security.ProtectionDomain;
 import java.util.Map;
 
@@ -35,12 +36,14 @@
 import org.apache.openjpa.conf.OpenJPAConfigurationImpl;
 import org.apache.openjpa.enhance.PCClassFileTransformer;
 import org.apache.openjpa.enhance.PCEnhancerAgent;
+import org.apache.openjpa.kernel.AbstractBrokerFactory;
 import org.apache.openjpa.kernel.Bootstrap;
 import org.apache.openjpa.kernel.BrokerFactory;
 import org.apache.openjpa.lib.conf.Configuration;
 import org.apache.openjpa.lib.conf.ConfigurationProvider;
 import org.apache.openjpa.lib.conf.Configurations;
 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.meta.MetaDataModes;
@@ -87,7 +90,7 @@
 
             BrokerFactory factory = getBrokerFactory(cp, poolValue, null);
             OpenJPAConfiguration conf = factory.getConfiguration();
-            _log = conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
+            _log = conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);            
             pd.checkPuNameCollisions(_log,name);
             
             loadAgent(_log, conf);
@@ -95,16 +98,8 @@
             // TODO - Can this be moved back to BrokerImpl.initialize()?
             // Create appropriate LifecycleEventManager
             loadValidator(_log, conf);
-
-            // 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.
-            Options o = Configurations.parseProperties(Configurations.getProperties(conf.getMetaDataRepository()));
-            if(o.getBooleanProperty("Preload")){
-                conf.getMetaDataRepositoryInstance().preload();
-            }
+            
+            preloadMetaDataRepository(factory);
             
             return JPAFacadeHelper.toEntityManagerFactory(factory);
         } catch (Exception e) {
@@ -186,21 +181,17 @@
                     log.warn(_loc.get("transformer-registration-error", pui));
                 }
             }
-            
             // Create appropriate LifecycleEventManager
             OpenJPAConfiguration conf = factory.getConfiguration();
             _log = conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
             loadValidator(_log, conf);
+            
             // 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.
-            Options o = Configurations.parseProperties(Configurations.getProperties(conf.getMetaDataRepository()));
-            if(o.getBooleanProperty("Preload")){
-                conf.getMetaDataRepositoryInstance().preload();
-            }
-            
+            preloadMetaDataRepository(factory);           
             return JPAFacadeHelper.toEntityManagerFactory(factory);
         } catch (Exception e) {
             throw PersistenceExceptions.toPersistenceException(e);
@@ -233,7 +224,31 @@
     protected OpenJPAConfiguration newConfigurationImpl() {
         return new OpenJPAConfigurationImpl();
     }
-        
+
+    /**
+     * Private worker method that will call to the MetaDataRepository to preload if the provided
+     * BrokerFactory is configured to do so.
+     */
+    private void preloadMetaDataRepository(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
+        // start instanting configurable objects (ie:openjpa.MetaDataRepository). Don't catch
+        // any exceptions here because we want to fail-fast.
+        OpenJPAConfiguration conf = factory.getConfiguration();
+        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
+            ((AbstractBrokerFactory) factory).loadPersistentTypes((ClassLoader) AccessController
+                .doPrivileged(J2DoPrivHelper.getContextClassLoaderAction()));
+            mdr.preload();
+        }
+    }
+    
     /**
      * Java EE 5 class transformer.
      */



Mime
View raw message