openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hthom...@apache.org
Subject svn commit: r1431746 - in /openjpa/branches/2.2.1.x: ./ openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaBuilderImpl.java openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PredicateImpl.java
Date Fri, 11 Jan 2013 00:05:04 GMT
Author: hthomann
Date: Fri Jan 11 00:05:03 2013
New Revision: 1431746

URL: http://svn.apache.org/viewvc?rev=1431746&view=rev
Log:
OPENJPA-2320: Remove static initializers because recursive Predicate constructor deadlocks
- back ported Pinaki Poddar's trunk changes to 2.2.1.x - this issue also depends upon OPENJPA-2304.

Modified:
    openjpa/branches/2.2.1.x/   (props changed)
    openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaBuilderImpl.java
    openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PredicateImpl.java

Propchange: openjpa/branches/2.2.1.x/
------------------------------------------------------------------------------
  Merged /openjpa/trunk:r1430117

Modified: openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaBuilderImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaBuilderImpl.java?rev=1431746&r1=1431745&r2=1431746&view=diff
==============================================================================
--- openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaBuilderImpl.java
(original)
+++ openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaBuilderImpl.java
Fri Jan 11 00:05:03 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/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PredicateImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PredicateImpl.java?rev=1431746&r1=1431745&r2=1431746&view=diff
==============================================================================
--- openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PredicateImpl.java
(original)
+++ openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PredicateImpl.java
Fri Jan 11 00:05:03 2013
@@ -45,9 +45,8 @@ 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;
@@ -73,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;
     }
 
@@ -127,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()) {
@@ -138,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