openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r832552 - in /openjpa/sandboxes/perf: openjpa-kernel/src/main/java/org/apache/openjpa/conf/ openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-kernel/src/main/java/org/ap...
Date Tue, 03 Nov 2009 20:56:12 GMT
Author: curtisr7
Date: Tue Nov  3 20:56:10 2009
New Revision: 832552

URL: http://svn.apache.org/viewvc?rev=832552&view=rev
Log:
MDR preload refactoring. Added openjpa.Performance property. New testcase.

Added:
    openjpa/sandboxes/perf/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestPerformanceConfiguration.java
  (with props)
Modified:
    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/enhance/PCRegistry.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-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestBrokerImpl.java
    openjpa/sandboxes/perf/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
    openjpa/sandboxes/perf/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java

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=832552&r1=832551&r2=832552&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
Tue Nov  3 20:56:10 2009
@@ -135,6 +135,7 @@
     public QueryCompilationCacheValue queryCompilationCachePlugin;
     public IntValue runtimeUnenhancedClasses;
     public CacheMarshallersValue cacheMarshallerPlugins;
+    public StringValue performance;
 
     // custom values
     public BrokerFactoryValue brokerFactoryPlugin;
@@ -504,6 +505,9 @@
         runtimeUnenhancedClasses.setDefault("supported");
         runtimeUnenhancedClasses.setString("supported");
         runtimeUnenhancedClasses.setAliasListComprehensive(true);
+        
+        // Not used for anything. Handled in PersistenceProductDerivation.
+        performance = addString("Performance");
 
         cacheMarshallerPlugins = (CacheMarshallersValue)
             addValue(new CacheMarshallersValue(this));

Modified: openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java?rev=832552&r1=832551&r2=832552&view=diff
==============================================================================
--- openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java
(original)
+++ openjpa/sandboxes/perf/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java
Tue Nov  3 20:56:10 2009
@@ -28,7 +28,6 @@
 import org.apache.openjpa.lib.util.ReferenceMap;
 import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap;
 import org.apache.openjpa.util.UserException;
-import org.apache.openjpa.util.InvalidStateException;
 
 /**
  * Tracks registered persistence-capable classes.
@@ -55,10 +54,13 @@
     public static void addRegisterClassListener(RegisterClassListener rcl) {
         if (rcl == null)
             return;
-
+        
         // we have to be positive that every listener gets notified for
         // every class, so lots of locking
         synchronized (_listeners) {
+            if (_listeners.contains(rcl) == true) {
+                return;
+            }
             _listeners.add(rcl);
         }
         synchronized (_metas) {

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=832552&r1=832551&r2=832552&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
Tue Nov  3 20:56:10 2009
@@ -259,7 +259,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/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=832552&r1=832551&r2=832552&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
Tue Nov  3 20:56:10 2009
@@ -28,6 +28,7 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -115,15 +116,15 @@
     private final Map _seqs = new HashMap();
 
     // these are set in endConfiguration()
-    private Map _oids;
-    private Map _impls;
-    private Map _ifaces;
-    private Map _aliases;
-    private Map _pawares;
-    private Map _nonMapped;
+    private Map _oids = Collections.synchronizedMap(new HashMap());
+    private Map _impls = Collections.synchronizedMap(new HashMap());
+    private Map _ifaces = Collections.synchronizedMap(new HashMap());
+    private Map _aliases = Collections.synchronizedMap(new HashMap());
+    private Map _pawares = Collections.synchronizedMap(new HashMap());
+    private Map _nonMapped = Collections.synchronizedMap(new HashMap());
     
     // map of classes to lists of their subclasses
-    private Map _subs;
+    private Map _subs = Collections.synchronizedMap(new HashMap());
 
     // xml mapping
     protected final XMLMetaData[] EMPTY_XMLMETAS;
@@ -140,8 +141,9 @@
 
     // we buffer up any classes that register themselves to prevent
     // reentrancy errors if classes register during a current parse (common)
-    private final Collection _registered = new HashSet();
-
+    private final Collection<Class<?>> _registered = new HashSet<Class<?>>();
+    private boolean _registeredEmpty = true;
+    
     // set of metadatas we're in the process of resolving
     private final InheritanceOrderedMetaDataList _resolving =
         new InheritanceOrderedMetaDataList();
@@ -153,13 +155,10 @@
     private LifecycleEventManager.ListenerList _listeners =
         new LifecycleEventManager.ListenerList(3);
 
-    private ReentrantLock _lock = null;
-    // If true, all configured persistent classes will be eagerly loaded.
-    protected boolean _eagerPersistentTypes = false;
+    private ReentrantLock _lock = new ReentrantLock();
     protected boolean _eagerPersistentMetaData = false;
     protected boolean _noLock = false;
     
-    private static final String EAGER_PERSISTENT_TYPES = "EagerPersistentTypes";
     private static final String EAGER_PERSISTENT_META_DATA = "EagerPersistentMetaData";
 
     /**
@@ -287,23 +286,7 @@
         else
             _sourceMode &= ~mode;
     }
-
-    /**
-     * Sets whether this repository will load all known persistent classes at initialization.
-     * Defaults to false.
-     */
-    public void setEagerPersistentTypes(boolean b) {
-        _eagerPersistentTypes = b;
-    }
-
-    /**
-     * Sets whether this repository will load all known persistent classes at initialization.
-     * Defaults to false.
-     */
-    public boolean getEagerPersistentTypes() {
-        return _eagerPersistentTypes;
-    }
-    
+  
     /**
      * Sets whether this repository will load all MetaData for all known persistent classes
at initialization.
      * Defaults to false.
@@ -327,40 +310,25 @@
         return _noLock;
     }
     /**
-     * If the openjpa.MetaDataRepository plugin value EagerPersistentMetaData=false and
-     * EagerPersistentTypes=false , this method will noop. If EagerPersistentTypes=true this
method
-     * gets the list of persistent classes and loads them (Class.forName(..)). If EagerPersistentMetaData=true,
this
+     * If the openjpa.MetaDataRepository plugin value EagerPersistentMetaData=false , this
method will noop. If EagerPersistentMetaData=true, this
      * method will load all persistent classes and ALL MetaData for those persistent classes.
      * <p>
-     * EagerPersistentMetaData=true implies EagerPersistentTypes=true.
+     * If noLock=true, calling this method will remove ALL locking from this class if EagerPersistentMetaData=true.
      * <p>
      * 
-     * If noLock=true, calling this method will also remove ALL locking from this class.
-     * <p>
-     * 
-     * NOTE : This method is not thread safe and should ONLY be called by the AbstractBrokerFactory
-     * constructor.
+     * NOTE : This method is not thread safe and should ONLY be called by the PersistenceProviderImpl.
      */
     public void initializeEager() {
-        if (_eagerPersistentMetaData == false && _eagerPersistentTypes == false)
{
+        if (_eagerPersistentMetaData == false) {
             return;
         }
-
-        if (_log.isTraceEnabled()) {
-            _log.trace("MetaDataRepository NoLock=" + _noLock + ", EagerPersistentTypes="
+ _eagerPersistentTypes
-                + ", EagerPersistentMetaData=" + _eagerPersistentMetaData);
+        // If pooling EMFs, this method may be invoked more than once. Only perform this
work once.
+        if (_eagerProcessingComplete == true) {
+            return;
         }
-
-        // Remove locking and use unsynchronized maps if we're loading all MetaData
-        if (_noLock == true && _eagerPersistentMetaData == true) {
-            _oids = new HashMap();
-            _impls = new HashMap();
-            _ifaces = new HashMap();
-            _aliases = new HashMap();
-            _pawares = new HashMap();
-            _nonMapped = new HashMap();
-            _subs = new HashMap();
-            _lock = null;
+        
+        if (_log.isTraceEnabled()) {
+            _log.trace("MetaDataRepository NoLock=" + _noLock + ", EagerPersistentMetaData="
+ _eagerPersistentMetaData);
         }
 
         MultiClassLoader multi = AccessController.doPrivileged(J2DoPrivHelper.newMultiClassLoaderAction());
@@ -377,25 +345,26 @@
                 .trace(MetaDataRepository.class.getName() + " found the following classes
: " + classes.toString());
         }
 
+        List<Class> loaded = new ArrayList<Class>();
         for (String c : classes) {
             try {
                 Class<?> cls = AccessController.doPrivileged((J2DoPrivHelper.getForNameAction(c,
true, multi)));
-                if (_eagerPersistentMetaData == true) {
-                    // TODO -- need to test this
-                    // resolveAll(multi);
-                    // // Load query metadata
-                    // _factory.load(cls, MODE_QUERY, multi);
-                    _factory.load(cls, MODE_ALL, multi);
-                }
+                loaded.add(cls);
+                // This call may be unnecessary?
+                _factory.load(cls, MODE_ALL, multi);
             } catch (PrivilegedActionException pae) {
                 throw new MetaDataException(_loc.get("repos-initializeEager-error"), pae);
             }
-        }// end for
-
-        // 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);
+        if (_noLock == true) {
+            _lock = null;
+        }
+        _eagerProcessingComplete = true;
     }
     
     protected void lock() {
@@ -472,7 +441,7 @@
         // check cache
         processRegisteredClasses(envLoader);
         List classList = (List) _aliases.get(alias);
-
+            
         // multiple classes may have been defined with the same alias: we
         // will filter by checking against the current list of the
         // persistent types and filter based on which classes are loadable
@@ -1151,6 +1120,7 @@
      * @param mustExist if true, throws a {@link MetaDataException}
      * if no metadata is found
      */
+    boolean _eagerProcessingComplete = false;
     public ClassMetaData getMetaData(Object oid, ClassLoader envLoader,
         boolean mustExist) {
         if (oid == null && mustExist)
@@ -1563,7 +1533,7 @@
             }
         }
     }
-
+            
     /**
      * Updates our datastructures with the latest registered classes.
      */
@@ -1685,8 +1655,9 @@
                     classList = new ArrayList(3);
                     _aliases.put(alias, classList);
                 }
-                if (!classList.contains(cls))
+                if (!classList.contains(cls)){
                     classList.add(cls);
+                }
             } finally {
                 unlock();
             }
@@ -1773,19 +1744,20 @@
     }
 
     public void endConfiguration() {
-        _oids = Collections.synchronizedMap(new HashMap());
-        _impls = Collections.synchronizedMap(new HashMap());
-        _ifaces = Collections.synchronizedMap(new HashMap());
-        _aliases = Collections.synchronizedMap(new HashMap());
-        _pawares = Collections.synchronizedMap(new HashMap());
-        _nonMapped = Collections.synchronizedMap(new HashMap());
-        _subs = Collections.synchronizedMap(new HashMap());
-        _lock = new ReentrantLock();
-
         initializeMetaDataFactory();
         if (_implGen == null) {
             _implGen = new InterfaceImplGenerator(this);
         }
+        if (_eagerPersistentMetaData == true && _noLock == true) {
+            _oids = new HashMap();
+            _impls = new HashMap();
+            _ifaces = new HashMap();
+            _aliases = new HashMap();
+            _pawares = new HashMap();
+            _nonMapped = new HashMap();
+            _subs = new HashMap();
+            // Wait till we're done loading MetaData to remove lock.
+        }
     }
 
     private void initializeMetaDataFactory() {
@@ -2300,8 +2272,7 @@
      * EagerPersistentMetaData set to true.
      */
     public static boolean needsInitializeEager(Options o) {
-        if (o.getBooleanProperty(EAGER_PERSISTENT_TYPES) == true
-            || o.getBooleanProperty(EAGER_PERSISTENT_META_DATA) == true) {
+        if (o.getBooleanProperty(EAGER_PERSISTENT_META_DATA) == true) {
             return true;
         }
         return false;

Added: openjpa/sandboxes/perf/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestPerformanceConfiguration.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/perf/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestPerformanceConfiguration.java?rev=832552&view=auto
==============================================================================
--- openjpa/sandboxes/perf/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestPerformanceConfiguration.java
(added)
+++ openjpa/sandboxes/perf/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestPerformanceConfiguration.java
Tue Nov  3 20:56:10 2009
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.conf;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.openjpa.lib.conf.Configurations;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
+import org.apache.openjpa.persistence.test.PersistenceTestCase;
+
+public class TestPerformanceConfiguration extends PersistenceTestCase {
+
+    public void testPerformanceLevel1() throws Exception {
+        OpenJPAEntityManagerFactorySPI emf = null;
+        try {
+            // Pass in an Entity because one of the properties requires one.
+            emf = createEMF(RuntimeTest1.class, "openjpa.Performance", "1");
+            OpenJPAConfiguration conf = emf.getConfiguration();
+
+            Map<String, Boolean> props =
+                stringPropertiesToMap(Configurations.getProperties(conf.getMetaDataRepository()));
+            assertTrue(props.get("EagerPersistentMetaData"));
+            assertTrue(props.get("NoLock"));
+
+            props = stringPropertiesToMap(Configurations.getProperties(conf.getBrokerImpl()));
+            assertTrue(props.get("SuppressBatchOleLogging"));
+
+            // Test Dianne's stuff
+        } finally {
+            emf.close();
+        }
+    }
+
+    public void testPerformanceLevel1MDRCollision() throws Exception {
+        OpenJPAEntityManagerFactorySPI emf = null;
+        try {
+            // Pass in an Entity because one of the properties requires one.
+            emf =
+                createEMF(RuntimeTest1.class, "openjpa.Performance", "1", "openjpa.MetaDataRepository",
"NoLock=false");
+            OpenJPAConfiguration conf = emf.getConfiguration();
+
+            // Make sure that we didn't wipe the user specified data.
+            Map<String, Boolean> props =
+                stringPropertiesToMap(Configurations.getProperties(conf.getMetaDataRepository()));
+            assertTrue(props.get("EagerPersistentMetaData") == null);
+            assertFalse(props.get("NoLock"));
+
+            props = stringPropertiesToMap(Configurations.getProperties(conf.getBrokerImpl()));
+            assertTrue(props.get("SuppressBatchOleLogging"));
+
+        } finally {
+            emf.close();
+        }
+    }
+
+    public void testPerformanceLevel1BrokerImplCollision() throws Exception {
+        OpenJPAEntityManagerFactorySPI emf = null;
+        try {
+            // Pass in an Entity because one of the properties requires one.
+            emf =
+                createEMF(RuntimeTest1.class, "openjpa.Performance", "1", "openjpa.BrokerImpl",
+                    "SuppressBatchOleLogging=false");
+            OpenJPAConfiguration conf = emf.getConfiguration();
+
+            // Make sure that we didn't wipe the user specified data.
+            Map<String, Boolean> props =
+                stringPropertiesToMap(Configurations.getProperties(conf.getMetaDataRepository()));
+            assertTrue(props.get("EagerPersistentMetaData"));
+            assertTrue(props.get("NoLock"));
+
+            props = stringPropertiesToMap(Configurations.getProperties(conf.getBrokerImpl()));
+            assertFalse(props.get("SuppressBatchOleLogging"));
+
+        } finally {
+            emf.close();
+        }
+    }
+
+    static Map<String, Boolean> stringPropertiesToMap(String str) {
+        List<String> properties = Arrays.asList(str.split("[,]"));
+        Map<String, Boolean> res = new HashMap<String, Boolean>();
+        for (String p : properties) {
+            String[] t = p.split("[=]");
+            res.put(t[0], Boolean.parseBoolean(t[1]));
+        }
+        return res;
+    }
+}

Propchange: openjpa/sandboxes/perf/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestPerformanceConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/sandboxes/perf/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestBrokerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/perf/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestBrokerImpl.java?rev=832552&r1=832551&r2=832552&view=diff
==============================================================================
--- openjpa/sandboxes/perf/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestBrokerImpl.java
(original)
+++ openjpa/sandboxes/perf/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestBrokerImpl.java
Tue Nov  3 20:56:10 2009
@@ -31,15 +31,18 @@
 
     public void setUp() {
         setUp(CLEAR_TABLES, NamedEntity.class, "openjpa.FetchBatchSize", 100, "openjpa.BrokerImpl",
-            "SuppressBatchOleLogging=true");
+            "SuppressBatchOleLogging=true",NamedEntity.class);
     }
 
     public void test() {
+        
+    }
+    public void testSuppressBatchOleLogging() {
         EntityManager em1 = emf.createEntityManager();
         EntityManager em2 = emf.createEntityManager();
         List<NamedEntity> entities = new ArrayList<NamedEntity>();
         em1.getTransaction().begin();
-        for (int i = 0; i < 75; i++) {
+        for (int i = 0; i < 5; i++) {
             NamedEntity e = new NamedEntity();
             entities.add(e);
             em1.persist(e);
@@ -58,7 +61,6 @@
             em1.getTransaction().commit();
             em2.getTransaction().commit();
         } catch (RollbackException ole) {
-            ole.printStackTrace();
             String msg = ole.getCause().getMessage();
             if (msg.contains("NamedEntity")) {
                 fail("Shouldn't have found any Entity information in the OLE message");

Modified: openjpa/sandboxes/perf/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/perf/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java?rev=832552&r1=832551&r2=832552&view=diff
==============================================================================
--- openjpa/sandboxes/perf/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
(original)
+++ openjpa/sandboxes/perf/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
Tue Nov  3 20:56:10 2009
@@ -30,6 +30,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.MissingResourceException;
+
 import javax.persistence.spi.PersistenceUnitInfo;
 import javax.persistence.spi.PersistenceUnitTransactionType;
 
@@ -453,6 +454,8 @@
             _source = source;
         }
 
+        static final int MAX_PERF_LEVEL = 1;
+        
         @Override
         public void setInto(Configuration conf) {
             if (conf instanceof OpenJPAConfiguration) {
@@ -473,6 +476,49 @@
                         addProperty(key, Configurations.combinePlugins(orig, 
                             (String) override));
                 }
+                
+                // Setup Performance configuration properties. 
+                Map props = getProperties();
+                Object perfLevel = props.get(ProductDerivations.getConfigurationKey("Performance",
getProperties()));
+                if (perfLevel instanceof String) {
+                    int level = 0;
+                    try {
+                        level = Integer.parseInt((String) perfLevel);
+                        if(level > MAX_PERF_LEVEL){
+                            level = MAX_PERF_LEVEL;
+                            Log log = oconf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
+                            // We missed translation. What to do about this?
+                            if(log.isInfoEnabled()){
+                                // LOG ME
+                            }
+                        }
+                    } catch (NumberFormatException nfe) {
+                        if (Boolean.parseBoolean((String) perfLevel) == true) {
+                            // If true, set to maximum perfLevel.
+                            level = MAX_PERF_LEVEL;
+                        } else {
+                            level = 0;
+                        }
+                    }// end catch
+                    
+                    // The reason that there is a switch here is that in the future when(if)
there is another
+                    // performance level, the new level will include the older(lower) levels.
ie: Level 2 would include
+                    // changes that were a part of Level 1.
+                    switch (level) {
+                        case 1:
+                            // TODO -- add a trace point if we found a user property conflicting
with
+                            // the performance prop?
+                            String key = ProductDerivations.getConfigurationKey("MetaDataRepository",
getProperties());
+                            if (props.containsKey(key) == false) {
+                                addProperty(key, "NoLock=true,EagerPersistentMetaData=true");
+                            }
+                            key = ProductDerivations.getConfigurationKey("BrokerImpl", getProperties());
+                            if (props.containsKey(key) == false) {
+                                addProperty(key, "SuppressBatchOleLogging=true");
+                            }
+                            break;
+                    }
+                }
             }
 
             super.setInto(conf, null);

Modified: openjpa/sandboxes/perf/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/perf/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java?rev=832552&r1=832551&r2=832552&view=diff
==============================================================================
--- openjpa/sandboxes/perf/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java
(original)
+++ openjpa/sandboxes/perf/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java
Tue Nov  3 20:56:10 2009
@@ -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;
 
@@ -33,12 +34,14 @@
 import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.conf.OpenJPAConfigurationImpl;
 import org.apache.openjpa.enhance.PCClassFileTransformer;
+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;
@@ -90,7 +93,12 @@
             // any exceptions here because we want to fail-fast.
             OpenJPAConfiguration conf = factory.getConfiguration();
             Options o = Configurations.parseProperties(Configurations.getProperties(conf.getMetaDataRepository()));
-            if(MetaDataRepository.needsInitializeEager(o) == true){
+            if (MetaDataRepository.needsInitializeEager(o) == true) {
+                MetaDataRepository mdr = conf.getMetaDataRepositoryInstance(); 
+                mdr.setValidate(MetaDataRepository.VALIDATE_RUNTIME, true);
+                mdr.setResolve(MetaDataRepository.MODE_MAPPING_INIT, true);
+                ((AbstractBrokerFactory) factory).loadPersistentTypes((ClassLoader) AccessController.doPrivileged(
+                    J2DoPrivHelper.getContextClassLoaderAction()));
                 conf.getMetaDataRepositoryInstance().initializeEager();
             }
             
@@ -175,7 +183,12 @@
             // any exceptions here because we want to fail-fast.
             OpenJPAConfiguration conf = factory.getConfiguration();
             Options o = Configurations.parseProperties(Configurations.getProperties(conf.getMetaDataRepository()));
-            if(MetaDataRepository.needsInitializeEager(o) == true){
+            if (MetaDataRepository.needsInitializeEager(o) == true) {
+                MetaDataRepository mdr = conf.getMetaDataRepositoryInstance(); 
+                mdr.setValidate(MetaDataRepository.VALIDATE_RUNTIME, true);
+                mdr.setResolve(MetaDataRepository.MODE_MAPPING_INIT, true);
+                ((AbstractBrokerFactory) factory).loadPersistentTypes((ClassLoader) AccessController
+                    .doPrivileged(J2DoPrivHelper.getContextClassLoaderAction()));
                 conf.getMetaDataRepositoryInstance().initializeEager();
             }
             



Mime
View raw message