openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r811403 - in /openjpa/sandboxes/perf: 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/ap...
Date Fri, 04 Sep 2009 13:49:30 GMT
Author: curtisr7
Date: Fri Sep  4 13:49:29 2009
New Revision: 811403

URL: http://svn.apache.org/viewvc?rev=811403&view=rev
Log:
OPENJPA-250: Changed config props, preloading, Java 2 security checks, and MultiClassLoader.

Modified:
    openjpa/sandboxes/perf/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
    openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/conf/MetaDataRepositoryValue.java
    openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
    openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
    openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
    openjpa/sandboxes/perf/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java

Modified: openjpa/sandboxes/perf/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/perf/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java?rev=811403&r1=811402&r2=811403&view=diff
==============================================================================
--- openjpa/sandboxes/perf/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
(original)
+++ openjpa/sandboxes/perf/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
Fri Sep  4 13:49:29 2009
@@ -1304,7 +1304,13 @@
             ((Configurable) _schema).setConfiguration(conf);
             ((Configurable) _schema).startConfiguration();
             ((Configurable) _schema).endConfiguration();
-        }            
+        }
+        // The call to preload needs to happen here because we need to wait for the
+        // MetaDataRepository and this class to be fully configured before we attempt
+        // to use them.
+        if (_preload == true) {
+            preload();
+        }
     }
     
     /**

Modified: openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/conf/MetaDataRepositoryValue.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/conf/MetaDataRepositoryValue.java?rev=811403&r1=811402&r2=811403&view=diff
==============================================================================
--- openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/conf/MetaDataRepositoryValue.java
(original)
+++ openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/conf/MetaDataRepositoryValue.java
Fri Sep  4 13:49:29 2009
@@ -22,7 +22,6 @@
 
 import org.apache.openjpa.lib.conf.Configuration;
 import org.apache.openjpa.lib.conf.PluginValue;
-import org.apache.openjpa.conf.CacheMarshallersValue;
 import org.apache.openjpa.meta.MetaDataRepository;
 
 /**
@@ -35,7 +34,9 @@
     extends PluginValue {
 
     private static final String KEY = "MetaDataRepository";
-
+    private static final String PRELOAD_STR = "Preload=true";
+    private static final String NOLOCK_STR = "NoLock=true";
+      
     public MetaDataRepositoryValue() {
         super(KEY, false);
         String[] aliases = new String[] {
@@ -47,6 +48,25 @@
         setString(aliases[0]);
     }
 
+    public boolean getPreload() {
+        String p = getProperties();
+        if (p != null && p.indexOf(PRELOAD_STR) >= 0) {
+            return true;
+        } else if (getNoLock() == true) {
+            // No locking implies that we need to also preload.
+            // Return true regardless of the value of the
+            // preload flag.
+            return true;
+        }
+        return false;
+    }
+    public boolean getNoLock(){
+        String p = getProperties();
+        if (p != null && p.indexOf(NOLOCK_STR) >= 0) {
+            return true;
+        }
+        return false;
+    }
     public Object instantiate(Class type, Configuration c, boolean fatal) {
         MetaDataRepository repos = null;
         OpenJPAConfiguration conf = (OpenJPAConfiguration) c;

Modified: openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java?rev=811403&r1=811402&r2=811403&view=diff
==============================================================================
--- openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
(original)
+++ openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
Fri Sep  4 13:49:29 2009
@@ -126,7 +126,7 @@
     public BooleanValue multithreaded;
     public StringValue mapping;
     public PluginValue metaFactoryPlugin;
-    public ObjectValue metaRepositoryPlugin;
+    public MetaDataRepositoryValue metaRepositoryPlugin;
     public ObjectValue lockManagerPlugin;
     public ObjectValue inverseManagerPlugin;
     public ObjectValue savepointManagerPlugin;
@@ -303,7 +303,7 @@
         mapping = addString("Mapping");
         metaFactoryPlugin = addPlugin("MetaDataFactory", false);
 
-        metaRepositoryPlugin = (ObjectValue)
+        metaRepositoryPlugin = (MetaDataRepositoryValue)
             addValue(new MetaDataRepositoryValue());
 
         connectionFactory = addObject("ConnectionFactory");

Modified: openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java?rev=811403&r1=811402&r2=811403&view=diff
==============================================================================
--- openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
(original)
+++ openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
Fri Sep  4 13:49:29 2009
@@ -29,22 +29,26 @@
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.ReentrantLock;
+
 import javax.transaction.Status;
 import javax.transaction.Synchronization;
 import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
 
-import org.apache.commons.lang.StringUtils;
 import org.apache.commons.collections.set.MapBackedSet;
-import org.apache.openjpa.conf.OpenJPAConfiguration;
-import org.apache.openjpa.conf.OpenJPAVersion;
+import org.apache.commons.lang.StringUtils;
 import org.apache.openjpa.conf.BrokerValue;
+import org.apache.openjpa.conf.MetaDataRepositoryValue;
+import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.conf.OpenJPAConfigurationImpl;
+import org.apache.openjpa.conf.OpenJPAVersion;
 import org.apache.openjpa.datacache.DataCacheStoreManager;
 import org.apache.openjpa.ee.ManagedRuntime;
+import org.apache.openjpa.enhance.ManagedClassSubclasser;
 import org.apache.openjpa.enhance.PCRegistry;
 import org.apache.openjpa.enhance.PersistenceCapable;
-import org.apache.openjpa.enhance.ManagedClassSubclasser;
 import org.apache.openjpa.event.BrokerFactoryEvent;
 import org.apache.openjpa.event.RemoteCommitEventManager;
 import org.apache.openjpa.lib.conf.Configuration;
@@ -52,9 +56,7 @@
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
-import java.util.concurrent.ConcurrentHashMap;
 import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashSet;
-import java.util.concurrent.locks.ReentrantLock;
 import org.apache.openjpa.meta.MetaDataRepository;
 import org.apache.openjpa.util.GeneralException;
 import org.apache.openjpa.util.InvalidStateException;
@@ -147,6 +149,13 @@
         _conf = config;
         _brokers = newBrokerSet();
         getPcClassLoaders();
+
+        OpenJPAConfigurationImpl impl = (OpenJPAConfigurationImpl) config;
+        MetaDataRepositoryValue m = impl.metaRepositoryPlugin;
+        if (m.getPreload() == true) {
+            // Obtain a reference to the MetaDataRepository to trigger the preload
+            MetaDataRepository mdr = config.getMetaDataRepositoryInstance();
+        }
     }
 
     /**

Modified: openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java?rev=811403&r1=811402&r2=811403&view=diff
==============================================================================
--- openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
(original)
+++ openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
Fri Sep  4 13:49:29 2009
@@ -20,6 +20,7 @@
 
 import java.io.Serializable;
 import java.security.AccessController;
+import java.security.PrivilegedActionException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -47,6 +48,7 @@
 import org.apache.openjpa.lib.util.Closeable;
 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.StringDistance;
 import org.apache.openjpa.util.ImplHelper;
 import org.apache.openjpa.util.InternalException;
@@ -151,7 +153,8 @@
         new LifecycleEventManager.ListenerList(3);
 
     private ReentrantLock _lock = null;
-    private boolean _preloadNoLock = false;
+    protected boolean _preload = false;
+    protected boolean _noLock = false;
 
     /**
      * Default constructor.  Configure via {@link Configurable}.
@@ -279,20 +282,51 @@
             _sourceMode &= ~mode;
     }
 
-    public void setPreloadNoLock(boolean l) {
-		_preloadNoLock = l;
-	}
+    public void setPreload(boolean l) {
+        _preload = l;
+    }
+    public void setNoLock(boolean l) {
+        _noLock = l;
+    }
     
-    private void preload() {
-		Set<String> classes = getPersistentTypeNames(false, null);
-		if (classes == null || classes.size() == 0) {
-			throw new RuntimeException(
-					"No persistent classes listed when trying to preload the MetaDataRepository");
-		}
-		for (String c : classes) {
-			getMetaData(c, null, false);
-		}
-	}
+    
+    /**
+     * This worker method gets the list of persistent classes and calls
+     * to the MetaDataFactory to load ALL metadata.
+     */
+    protected void preload() {
+        MultiClassLoader multi =
+            AccessController.doPrivileged(J2DoPrivHelper.newMultiClassLoaderAction());
+        multi.addClassLoader(AccessController.doPrivileged(J2DoPrivHelper
+            .getContextClassLoaderAction()));
+        multi.addClassLoader(AccessController.doPrivileged(J2DoPrivHelper
+            .getClassLoaderAction(MetaDataRepository.class)));
+
+        Set<String> classes = getPersistentTypeNames(false, multi);
+        if (classes == null || classes.size() == 0) {
+            throw new RuntimeException(
+                "No persistent classes listed when trying to preload the MetaDataRepository");
+        }
+        if (_log.isTraceEnabled() == true) {
+            _log.trace(MetaDataRepository.class.getName() + " preloading the following classes
: "
+                + classes.toString());
+        }
+
+        for (String c : classes) {
+            try {
+                Class<?> cls =
+                    AccessController
+                        .doPrivileged((J2DoPrivHelper.getForNameAction(c, true, multi)));
+                _factory.load(cls, MODE_ALL, multi);
+            } catch (PrivilegedActionException pae) {
+                // Unexpected!
+                if (_log.isTraceEnabled() == true) {
+                    _log.trace(MetaDataRepository.class.getName()
+                        + " encountered an unexpected exception ", pae);
+                }
+            }
+        }// end for
+    }
     
     protected void lock() {
         if (_lock != null) {
@@ -341,7 +375,7 @@
 
                 throw new MetaDataException(_loc.get("no-meta", cls));
             }
-            resolve(meta);
+            resolve(meta);            
             return meta;
         } finally {
             unlock();
@@ -1669,7 +1703,7 @@
     }
 
     public void endConfiguration() {
-        if (_preloadNoLock == false) {
+        if (_noLock == false) {
             _oids = Collections.synchronizedMap(new HashMap());
             _impls = Collections.synchronizedMap(new HashMap());
             _ifaces = Collections.synchronizedMap(new HashMap());
@@ -1696,9 +1730,6 @@
         if (_implGen == null) {
             _implGen = new InterfaceImplGenerator(this);
         }
-        if (_preloadNoLock == true) {
-            preload();
-        }
     }
 
     private void initializeMetaDataFactory() {

Modified: openjpa/sandboxes/perf/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/perf/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java?rev=811403&r1=811402&r2=811403&view=diff
==============================================================================
--- openjpa/sandboxes/perf/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java
(original)
+++ openjpa/sandboxes/perf/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java
Fri Sep  4 13:49:29 2009
@@ -905,9 +905,9 @@
      *   
      * @return MultiClassLoader
      */
-    public static final PrivilegedAction newMultiClassLoaderAction() {
+    public static final PrivilegedAction<MultiClassLoader> newMultiClassLoaderAction()
{
         return new PrivilegedAction() {
-            public Object run() {
+            public MultiClassLoader run() {
                 return new MultiClassLoader();
             }
         };



Mime
View raw message