openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r817429 [1/2] - 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/apach...
Date Mon, 21 Sep 2009 21:59:22 GMT
Author: curtisr7
Date: Mon Sep 21 21:59:21 2009
New Revision: 817429

URL: http://svn.apache.org/viewvc?rev=817429&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/MetaDataRepositoryValue.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

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=817429&r1=817428&r2=817429&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 Sep 21 21:59:21 2009
@@ -149,7 +149,7 @@
     /**
      * Representation of the database schema.
      */
-    public synchronized SchemaGroup getSchemaGroup() {
+    public SchemaGroup getSchemaGroup() {
         if (_schema == null)
             _schema = ((JDBCConfiguration) getConfiguration()).
                 getSchemaFactoryInstance().readSchema();
@@ -159,14 +159,14 @@
     /**
      * Representation of the database schema.
      */
-    public synchronized void setSchemaGroup(SchemaGroup schema) {
+    public void setSchemaGroup(SchemaGroup schema) {
         _schema = schema;
     }
 
     /**
      * Installs mapping strategies on components.
      */
-    public synchronized StrategyInstaller getStrategyInstaller() {
+    public StrategyInstaller getStrategyInstaller() {
         if (_installer == null)
             _installer = new RuntimeStrategyInstaller(this);
         return _installer;
@@ -175,20 +175,24 @@
     /**
      * Installs mapping strategies on components.
      */
-    public synchronized void setStrategyInstaller(StrategyInstaller installer) {
+    public void setStrategyInstaller(StrategyInstaller installer) {
         _installer = installer;
     }
 
     /**
      * Return the query result mapping for the given name.
      */
-    public synchronized QueryResultMapping getQueryResultMapping(Class cls,
+    public QueryResultMapping getQueryResultMapping(Class cls,
         String name, ClassLoader envLoader, boolean mustExist) {
-        QueryResultMapping res = getQueryResultMappingInternal(cls, name,
-            envLoader);
-        if (res == null && mustExist)
-            throw new MetaDataException(_loc.get("no-query-res", cls, name));
-        return res;
+        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();
+        }
     }
 
     /**
@@ -226,47 +230,71 @@
      * Return all cached query result mappings.
      */
     public synchronized QueryResultMapping[] getQueryResultMappings() {
-        Collection values = _results.values();
-        return (QueryResultMapping[]) values.toArray
-            (new QueryResultMapping[values.size()]);
+        lock();
+        try {
+            Collection values = _results.values();
+            return (QueryResultMapping[]) values.toArray(new QueryResultMapping[values.size()]);
+        } finally {
+            unlock();
+        }
     }
 
     /**
      * Return the cached query result mapping with the given name, or null if
      * none.
      */
-    public synchronized QueryResultMapping getCachedQueryResultMapping
+    public QueryResultMapping getCachedQueryResultMapping
         (Class cls, String name) {
-        return (QueryResultMapping) _results.get(getQueryResultKey(cls, name));
+        lock();
+        try {
+            return (QueryResultMapping) _results.get(getQueryResultKey(cls, name));
+        } finally {
+            unlock();
+        }
     }
 
     /**
      * Add a query result mapping.
      */
-    public synchronized QueryResultMapping addQueryResultMapping(Class cls,
+    public QueryResultMapping addQueryResultMapping(Class cls,
         String name) {
-        QueryResultMapping res = new QueryResultMapping(name, this);
-        res.setDefiningType(cls);
-        _results.put(getQueryResultKey(res), res);
-        return res;
+        lock();
+        try {
+            QueryResultMapping res = new QueryResultMapping(name, this);
+            res.setDefiningType(cls);
+            _results.put(getQueryResultKey(res), res);
+            return res;
+        } finally {
+            unlock();
+        }
     }
 
     /**
      * Remove a query result mapping.
      */
-    public synchronized boolean removeQueryResultMapping
+    public boolean removeQueryResultMapping
         (QueryResultMapping res) {
-        return _results.remove(getQueryResultKey(res)) != null;
+        lock();
+        try {
+            return _results.remove(getQueryResultKey(res)) != null;
+        } finally {
+            unlock();
+        }
     }
 
     /**
      * Remove a query result mapping.
      */
-    public synchronized boolean removeQueryResultMapping(Class cls,
+    public boolean removeQueryResultMapping(Class cls,
         String name) {
-        if (name == null)
-            return false;
-        return _results.remove(getQueryResultKey(cls, name)) != null;
+        lock();
+        try {
+            if (name == null)
+                return false;
+            return _results.remove(getQueryResultKey(cls, name)) != null;
+        } finally {
+            unlock();
+        }
     }
 
     /**
@@ -307,9 +335,14 @@
     }
 
     public synchronized void clear() {
-        super.clear();
-        _schema = null;
-        _results.clear();
+        lock();
+        try {
+            super.clear();
+            _schema = null;
+            _results.clear();
+        } finally {
+            unlock();
+        }
     }
 
     protected void prepareMapping(ClassMetaData meta) {

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/MetaDataRepositoryValue.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/MetaDataRepositoryValue.java?rev=817429&r1=817428&r2=817429&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/MetaDataRepositoryValue.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/MetaDataRepositoryValue.java
Mon Sep 21 21:59:21 2009
@@ -35,7 +35,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 +49,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/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=817429&r1=817428&r2=817429&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 Sep 21 21:59:21 2009
@@ -42,7 +42,6 @@
 import org.apache.openjpa.kernel.InverseManager;
 import org.apache.openjpa.kernel.LockLevels;
 import org.apache.openjpa.kernel.LockManager;
-import org.apache.openjpa.kernel.MixedLockLevels;
 import org.apache.openjpa.kernel.PreparedQueryCache;
 import org.apache.openjpa.kernel.QueryFlushModes;
 import org.apache.openjpa.kernel.RestoreState;
@@ -149,7 +148,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;
@@ -335,8 +334,7 @@
         mapping = addString("Mapping");
         metaFactoryPlugin = addPlugin("MetaDataFactory", false);
 
-        metaRepositoryPlugin = (ObjectValue)
-            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=817429&r1=817428&r2=817429&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 Sep 21 21:59:21 2009
@@ -40,6 +40,7 @@
 import org.apache.commons.collections.set.MapBackedSet;
 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;
@@ -163,6 +164,20 @@
                 _conf.getConnectionRetainModeConstant(), false).close(); 
         }
 
+        // This logic needs to happen here for a reason! The preloading of the MDR
+        // can not happen during the configuration of the MDR because when running
+        // in a container environment we need to be able to get an uninitialized
+        // MDR to pass to the PCClassFileTransformer. If we preload before registering
+        // the class transformer, we miss the class being defined by the JVM and in turn
+        // we fail to enhance our entities.
+        OpenJPAConfigurationImpl impl = (OpenJPAConfigurationImpl) config;
+        MetaDataRepositoryValue m = impl.metaRepositoryPlugin;
+        if (m.getPreload() == true) {
+            // Obtain a reference to the MetaDataRepository and trigger the preload
+            MetaDataRepository mdr = config.getMetaDataRepositoryInstance();
+            mdr.preload();
+        }
+        
         initWriteBehindCallback();
     }
 



Mime
View raw message