mirror of https://github.com/apache/openjpa.git
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:
parent
e48cd3e59d
commit
da48a0ad53
|
@ -95,8 +95,13 @@ class CriteriaQueryImpl<T> implements OpenJPACriteriaQuery<T>, AliasContext {
|
||||||
private Map<Selection<?>,Value> _rootVariables = new HashMap<Selection<?>, Value>();
|
private Map<Selection<?>,Value> _rootVariables = new HashMap<Selection<?>, Value>();
|
||||||
|
|
||||||
// SubqueryContext
|
// 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) {
|
public CriteriaQueryImpl(MetamodelImpl model, Class<T> resultClass) {
|
||||||
this._model = model;
|
this._model = model;
|
||||||
this._resultClass = resultClass;
|
this._resultClass = resultClass;
|
||||||
|
@ -135,7 +140,7 @@ class CriteriaQueryImpl<T> implements OpenJPACriteriaQuery<T>, AliasContext {
|
||||||
* Gets the stack of contexts used by this query.
|
* Gets the stack of contexts used by this query.
|
||||||
*/
|
*/
|
||||||
Stack<Context> getContexts() {
|
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}.
|
* receiver with the help of the given {@link ExpressionFactory}.
|
||||||
*/
|
*/
|
||||||
QueryExpressions getQueryExpressions(ExpressionFactory factory) {
|
QueryExpressions getQueryExpressions(ExpressionFactory factory) {
|
||||||
_contexts = new Stack<Context>();
|
|
||||||
Context context = new Context(null, null, null);
|
Context context = new Context(null, null, null);
|
||||||
_contexts.push(context);
|
_contexts.get().push(context);
|
||||||
return new CriteriaExpressionBuilder().getQueryExpressions(factory, this);
|
try {
|
||||||
|
return new CriteriaExpressionBuilder().getQueryExpressions(factory, this);
|
||||||
|
}finally{
|
||||||
|
_contexts.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void assertRoot() {
|
public void assertRoot() {
|
||||||
|
@ -432,7 +440,7 @@ class CriteriaQueryImpl<T> implements OpenJPACriteriaQuery<T>, AliasContext {
|
||||||
// SubqueryContext
|
// SubqueryContext
|
||||||
//
|
//
|
||||||
void setContexts(Stack<Context> contexts) {
|
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.
|
* Gets the current context.
|
||||||
*/
|
*/
|
||||||
Context ctx() {
|
Context ctx() {
|
||||||
return _contexts == null || _contexts.isEmpty() ? null : _contexts.peek();
|
Stack<Context> ctxt = _contexts.get();
|
||||||
|
return ctxt == null || ctxt.isEmpty() ? null : ctxt.peek();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in New Issue