OPENJPA-2507. Committing a variation of Thomas Darimont's patch that utilizes ThreadLocal storage to safeguard the _contexts in CriteriaQueryImpl.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1601778 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Kevin W. Sutter 2014-06-10 21:47:31 +00:00
parent e48cd3e59d
commit da48a0ad53
1 changed files with 17 additions and 8 deletions

View File

@ -95,8 +95,13 @@ class CriteriaQueryImpl<T> implements OpenJPACriteriaQuery<T>, AliasContext {
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 OpenJPACriteriaQuery<T>, AliasContext {
* 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 OpenJPACriteriaQuery<T>, AliasContext {
* 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 OpenJPACriteriaQuery<T>, AliasContext {
// SubqueryContext
//
void setContexts(Stack<Context> contexts) {
_contexts = contexts;
_contexts.set(contexts);
}
/**
@ -461,7 +469,8 @@ class CriteriaQueryImpl<T> implements OpenJPACriteriaQuery<T>, AliasContext {
* 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();
}
//