openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r727297 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/
Date Wed, 17 Dec 2008 06:23:01 GMT
Author: ppoddar
Date: Tue Dec 16 22:23:00 2008
New Revision: 727297

URL: http://svn.apache.org/viewvc?rev=727297&view=rev
Log:
OPENJPA-825: Cache unique flag for query to avoid lcoking. Use StateManager's instance lock
rather than acquiring Broker's lock.

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
    openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java?rev=727297&r1=727296&r2=727297&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java
Tue Dec 16 22:23:00 2008
@@ -56,6 +56,7 @@
 import org.apache.openjpa.kernel.Filters;
 import org.apache.openjpa.kernel.OpenJPAStateManager;
 import org.apache.openjpa.kernel.OrderingMergedResultObjectProvider;
+import org.apache.openjpa.kernel.QueryContext;
 import org.apache.openjpa.kernel.QueryHints;
 import org.apache.openjpa.kernel.exps.Constant;
 import org.apache.openjpa.kernel.exps.ExpressionFactory;
@@ -83,6 +84,7 @@
 public class JDBCStoreQuery 
     extends ExpressionStoreQuery {
 
+	private boolean _isUnique = false;
     private static final Table INVALID = new Table();
 
     // add all standard filter and aggregate listeners to these maps
@@ -110,6 +112,11 @@
         _store = store;
     }
 
+    @Override
+    public void setContext(QueryContext ctx) {
+    	super.setContext(ctx);
+    	_isUnique = ctx.isUnique();
+    }
     /**
      * Return the store.
      */
@@ -341,7 +348,7 @@
                 evaluate(ctx, null, null, exps[i], states[i]);
             if (optHint != null)
                sel.setExpectedResultCount(optHint.intValue(), true);
-            else if (this.ctx.isUnique())
+            else if (_isUnique)
                 sel.setExpectedResultCount(1, false);
             for (int j = 0; j < verts.length; j++) {
                 selMappings.add(verts[j]);
@@ -423,7 +430,7 @@
         long end) {
         if (exps.projections.length > 0 || start >= end)
             return EagerFetchModes.EAGER_NONE;
-        if (end - start == 1 || ctx.isUnique())
+        if (end - start == 1 || _isUnique)
             return EagerFetchModes.EAGER_JOIN;
         return EagerFetchModes.EAGER_PARALLEL;
     }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java?rev=727297&r1=727296&r2=727297&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java Tue
Dec 16 22:23:00 2008
@@ -458,8 +458,8 @@
             // no explicit setting; default
             StoreQuery.Executor ex = compileForExecutor();
             if (!ex.isAggregate(_storeQuery))
-                return false;
-            return !ex.hasGrouping(_storeQuery);
+                return _unique = false;
+            return _unique = !ex.hasGrouping(_storeQuery);
         } finally {
             unlock();
         }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java?rev=727297&r1=727296&r2=727297&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
Tue Dec 16 22:23:00 2008
@@ -34,6 +34,7 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.TimeZone;
+import java.util.concurrent.locks.ReentrantLock;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.openjpa.conf.OpenJPAConfiguration;
@@ -147,6 +148,8 @@
     // information about the owner of this instance, if it is embedded
     private StateManagerImpl _owner = null;
     private int _ownerIndex = -1;
+    
+    private transient ReentrantLock _instanceLock = null;
 
     /**
      * Constructor; supply id, type metadata, and owning persistence manager.
@@ -157,6 +160,8 @@
         _meta = meta;
         _broker = broker;
         _single = new SingleFieldManager(this, broker);
+        if (broker.getMultithreaded())
+        	_instanceLock = new ReentrantLock();
 
         if (_meta.getIdentityType() == ClassMetaData.ID_UNKNOWN)
             throw new UserException(_loc.get("meta-unknownid", _meta));
@@ -3184,19 +3189,16 @@
      * Lock the state manager if the multithreaded option is set.
      */
     protected void lock() {
-        // use broker-level lock to avoid deadlock situations with the state
-        // manager lock and broker lock being obtained in different orders
-        _broker.lock();
+        if (_instanceLock != null)
+        	_instanceLock.lock();
     }
 
     /**
      * Unlock the state manager.
      */
-	protected void unlock ()
-	{
-		// use broker-level lock to avoid deadlock situations with the state 
-		// manager lock and broker lock being obtained in different orders
-		_broker.unlock ();
+	protected void unlock () {
+        if (_instanceLock != null)
+        	_instanceLock.unlock();
 	}
 
     private void writeObject(ObjectOutputStream oos) throws IOException {

Modified: openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java?rev=727297&r1=727296&r2=727297&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java
(original)
+++ openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java
Tue Dec 16 22:23:00 2008
@@ -108,7 +108,7 @@
         	super(dsq, meta, subclasses, parser, parsed);
         	owner = dsq;
         	threadPool = dsq.getExecutorServiceInstance();
-        	serialMode = serial;
+        	serialMode = false;//serial;
         }
         
 		public void addExecutor(Executor ex) {



Mime
View raw message