openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r1430117 - in /openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria: CriteriaBuilderImpl.java PredicateImpl.java
Date Tue, 08 Jan 2013 02:40:07 GMT
Author: ppoddar
Date: Tue Jan  8 02:40:07 2013
New Revision: 1430117

URL: http://svn.apache.org/viewvc?rev=1430117&view=rev
Log:
OPENJPA-2320: Remove static initializers because recursive Predicate constructor deadlocks

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

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaBuilderImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaBuilderImpl.java?rev=1430117&r1=1430116&r2=1430117&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaBuilderImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaBuilderImpl.java
Tue Jan  8 02:40:07 2013
@@ -332,7 +332,7 @@ public class CriteriaBuilderImpl impleme
         if (x instanceof PredicateImpl) {
             PredicateImpl predicate = (PredicateImpl)x; 
             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);
@@ -403,9 +403,9 @@ public class CriteriaBuilderImpl impleme
 
     public <T> Expression<T> literal(T value) {
         if (Boolean.TRUE.equals(value))
-            return (Expression<T>)PredicateImpl.TRUE;
+            return (Expression<T>)PredicateImpl.TRUE();
         if (Boolean.FALSE.equals(value))
-            return (Expression<T>)PredicateImpl.FALSE;
+            return (Expression<T>)PredicateImpl.FALSE();
         return new Expressions.Constant<T>(value);
     }
 

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PredicateImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PredicateImpl.java?rev=1430117&r1=1430116&r2=1430117&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PredicateImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PredicateImpl.java
Tue Jan  8 02:40:07 2013
@@ -45,17 +45,13 @@ import org.apache.openjpa.kernel.exps.Li
  * @since 2.0.0
  */
 abstract class PredicateImpl extends ExpressionImpl<Boolean> implements Predicate {
-    private static final ExpressionImpl<Integer> ONE  = new Expressions.Constant<Integer>(1);
-    public static final Predicate TRUE  = new Expressions.Equal(ONE,ONE);
-    public static final Predicate FALSE = new Expressions.NotEqual(ONE,ONE);
+    private static Predicate TRUE;
+    private static Predicate FALSE;
     
     protected final List<Predicate> _exps = Collections.synchronizedList(new ArrayList<Predicate>());
     private final BooleanOperator _op;
     private boolean _negated = false;
     
-    static {
-    	System.err.println("WARNING: You are using a unofficial version of PredicateImpl.class");
-    }
     /**
      * An AND predicate with no arguments.
      */
@@ -76,17 +72,20 @@ abstract class PredicateImpl extends Exp
      */
     protected PredicateImpl(BooleanOperator op, Predicate...restrictions) {
         this(op);
-        if (restrictions != null) {
-            for (Predicate p : restrictions)
-                add(p);
-        }
+        if (restrictions == null || restrictions.length == 0) return;
+        
+    	for (Predicate p : restrictions) {
+   			add(p);
+    	}
     }
 
     /**
      * Adds the given predicate expression.
      */
     public PredicateImpl add(Expression<Boolean> s) {
-        _exps.add((Predicate)s); // all boolean expressions are Predicate
+    	synchronized (_exps) {
+        	_exps.add((Predicate)s); // all boolean expressions are Predicate
+		}
         return this;
     }
 
@@ -130,6 +129,22 @@ abstract class PredicateImpl extends Exp
         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
     org.apache.openjpa.kernel.exps.Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?>
q) {
         if (_exps.isEmpty()) {
@@ -141,7 +156,7 @@ abstract class PredicateImpl extends Exp
     @Override
     org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory,
CriteriaQueryImpl<?> q) {
         if (_exps.isEmpty()) {
-            Predicate nil = _op == BooleanOperator.AND ? TRUE : FALSE;
+            Predicate nil = _op == BooleanOperator.AND ? TRUE() : FALSE();
             return ((PredicateImpl)nil).toKernelExpression(factory, q);
         }
         if (_exps.size() == 1) {



Mime
View raw message