mirror of https://github.com/apache/openjpa.git
OPENJPA-2320: Remove static initializers because recursive Predicate constructor deadlocks
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1430117 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
58f24badcc
commit
0ca38be727
|
@ -332,7 +332,7 @@ public class CriteriaBuilderImpl implements OpenJPACriteriaBuilder, ExpressionPa
|
||||||
if (x instanceof PredicateImpl) {
|
if (x instanceof PredicateImpl) {
|
||||||
PredicateImpl predicate = (PredicateImpl)x;
|
PredicateImpl predicate = (PredicateImpl)x;
|
||||||
if (predicate.isEmpty()) {
|
if (predicate.isEmpty()) {
|
||||||
return predicate.getOperator() == BooleanOperator.AND ? PredicateImpl.TRUE : PredicateImpl.FALSE;
|
return predicate.getOperator() == BooleanOperator.AND ? PredicateImpl.TRUE() : PredicateImpl.FALSE();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Expressions.Equal(x, true);
|
return new Expressions.Equal(x, true);
|
||||||
|
@ -403,9 +403,9 @@ public class CriteriaBuilderImpl implements OpenJPACriteriaBuilder, ExpressionPa
|
||||||
|
|
||||||
public <T> Expression<T> literal(T value) {
|
public <T> Expression<T> literal(T value) {
|
||||||
if (Boolean.TRUE.equals(value))
|
if (Boolean.TRUE.equals(value))
|
||||||
return (Expression<T>)PredicateImpl.TRUE;
|
return (Expression<T>)PredicateImpl.TRUE();
|
||||||
if (Boolean.FALSE.equals(value))
|
if (Boolean.FALSE.equals(value))
|
||||||
return (Expression<T>)PredicateImpl.FALSE;
|
return (Expression<T>)PredicateImpl.FALSE();
|
||||||
return new Expressions.Constant<T>(value);
|
return new Expressions.Constant<T>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,17 +45,13 @@ import org.apache.openjpa.kernel.exps.Literal;
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
abstract class PredicateImpl extends ExpressionImpl<Boolean> implements Predicate {
|
abstract class PredicateImpl extends ExpressionImpl<Boolean> implements Predicate {
|
||||||
private static final ExpressionImpl<Integer> ONE = new Expressions.Constant<Integer>(1);
|
private static Predicate TRUE;
|
||||||
public static final Predicate TRUE = new Expressions.Equal(ONE,ONE);
|
private static Predicate FALSE;
|
||||||
public static final Predicate FALSE = new Expressions.NotEqual(ONE,ONE);
|
|
||||||
|
|
||||||
protected final List<Predicate> _exps = Collections.synchronizedList(new ArrayList<Predicate>());
|
protected final List<Predicate> _exps = Collections.synchronizedList(new ArrayList<Predicate>());
|
||||||
private final BooleanOperator _op;
|
private final BooleanOperator _op;
|
||||||
private boolean _negated = false;
|
private boolean _negated = false;
|
||||||
|
|
||||||
static {
|
|
||||||
System.err.println("WARNING: You are using a unofficial version of PredicateImpl.class");
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* An AND predicate with no arguments.
|
* An AND predicate with no arguments.
|
||||||
*/
|
*/
|
||||||
|
@ -76,8 +72,9 @@ abstract class PredicateImpl extends ExpressionImpl<Boolean> implements Predicat
|
||||||
*/
|
*/
|
||||||
protected PredicateImpl(BooleanOperator op, Predicate...restrictions) {
|
protected PredicateImpl(BooleanOperator op, Predicate...restrictions) {
|
||||||
this(op);
|
this(op);
|
||||||
if (restrictions != null) {
|
if (restrictions == null || restrictions.length == 0) return;
|
||||||
for (Predicate p : restrictions)
|
|
||||||
|
for (Predicate p : restrictions) {
|
||||||
add(p);
|
add(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,7 +83,9 @@ abstract class PredicateImpl extends ExpressionImpl<Boolean> implements Predicat
|
||||||
* Adds the given predicate expression.
|
* Adds the given predicate expression.
|
||||||
*/
|
*/
|
||||||
public PredicateImpl add(Expression<Boolean> s) {
|
public PredicateImpl add(Expression<Boolean> s) {
|
||||||
|
synchronized (_exps) {
|
||||||
_exps.add((Predicate)s); // all boolean expressions are Predicate
|
_exps.add((Predicate)s); // all boolean expressions are Predicate
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,6 +129,22 @@ abstract class PredicateImpl extends ExpressionImpl<Boolean> implements Predicat
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Predicate TRUE() {
|
||||||
|
if (TRUE == null) {
|
||||||
|
ExpressionImpl<Integer> ONE = new Expressions.Constant<Integer>(1);
|
||||||
|
TRUE = new Expressions.Equal(ONE, ONE);
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Predicate FALSE() {
|
||||||
|
if (FALSE == null) {
|
||||||
|
ExpressionImpl<Integer> ONE = new Expressions.Constant<Integer>(1);
|
||||||
|
FALSE = new Expressions.NotEqual(ONE, ONE);
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
org.apache.openjpa.kernel.exps.Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
|
org.apache.openjpa.kernel.exps.Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
|
||||||
if (_exps.isEmpty()) {
|
if (_exps.isEmpty()) {
|
||||||
|
@ -141,7 +156,7 @@ abstract class PredicateImpl extends ExpressionImpl<Boolean> implements Predicat
|
||||||
@Override
|
@Override
|
||||||
org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
|
org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
|
||||||
if (_exps.isEmpty()) {
|
if (_exps.isEmpty()) {
|
||||||
Predicate nil = _op == BooleanOperator.AND ? TRUE : FALSE;
|
Predicate nil = _op == BooleanOperator.AND ? TRUE() : FALSE();
|
||||||
return ((PredicateImpl)nil).toKernelExpression(factory, q);
|
return ((PredicateImpl)nil).toKernelExpression(factory, q);
|
||||||
}
|
}
|
||||||
if (_exps.size() == 1) {
|
if (_exps.size() == 1) {
|
||||||
|
|
Loading…
Reference in New Issue