openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwsut...@apache.org
Subject svn commit: r1601778 - /openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java
Date Tue, 10 Jun 2014 21:47:31 GMT
Author: kwsutter
Date: Tue Jun 10 21:47:31 2014
New Revision: 1601778

URL: http://svn.apache.org/r1601778
Log:
OPENJPA-2507.  Committing a variation of Thomas Darimont's patch that utilizes ThreadLocal
storage to safeguard the _contexts in CriteriaQueryImpl.

Modified:
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java?rev=1601778&r1=1601777&r2=1601778&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java
Tue Jun 10 21:47:31 2014
@@ -95,8 +95,13 @@ class CriteriaQueryImpl<T> implements Op
     private Map<Selection<?>,Value> _rootVariables = new HashMap<Selection<?>,
Value>();
     
     // SubqueryContext
-    private Stack<Context> _contexts = null;
-    
+    private ThreadLocal<Stack<Context>> _contexts = new  ThreadLocal<Stack<Context>>(){
+        @Override
+        protected Stack<Context> initialValue() {
+            return new Stack<Context>();
+        }
+    };
+
     public CriteriaQueryImpl(MetamodelImpl model, Class<T> resultClass) {
         this._model = model;
         this._resultClass = resultClass;
@@ -135,7 +140,7 @@ class CriteriaQueryImpl<T> implements Op
      * Gets the stack of contexts used by this query.
      */
     Stack<Context> getContexts() {
-        return _contexts;
+        return _contexts.get();
     }
     
     /**
@@ -412,10 +417,13 @@ class CriteriaQueryImpl<T> implements Op
      * receiver with the help of the given {@link ExpressionFactory}.
      */
     QueryExpressions getQueryExpressions(ExpressionFactory factory) {
-        _contexts = new Stack<Context>();
         Context context = new Context(null, null, null);
-        _contexts.push(context);
-        return new CriteriaExpressionBuilder().getQueryExpressions(factory, this);
+        _contexts.get().push(context);
+        try {
+            return new CriteriaExpressionBuilder().getQueryExpressions(factory, this);
+        }finally{
+            _contexts.remove();
+        }
     }    
     
     public void assertRoot() {
@@ -432,7 +440,7 @@ class CriteriaQueryImpl<T> implements Op
     // SubqueryContext
     //
     void setContexts(Stack<Context> contexts) {
-        _contexts = contexts;
+        _contexts.set(contexts);
     }
     
     /**
@@ -461,7 +469,8 @@ class CriteriaQueryImpl<T> implements Op
      * Gets the current context.
      */
     Context ctx() {
-        return _contexts == null || _contexts.isEmpty() ? null :  _contexts.peek();
+        Stack<Context> ctxt = _contexts.get();
+        return ctxt == null || ctxt.isEmpty() ? null :  ctxt.peek();
     }
     
     //



Mime
View raw message