HHH-4583 - Incorrect handling of empty conjunction and disjunction

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18826 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2010-02-18 05:07:20 +00:00
parent 5a4e37495e
commit 32cd3b4359
2 changed files with 32 additions and 1 deletions

View File

@ -314,6 +314,17 @@ public class CriteriaBuilderImpl implements CriteriaBuilder, Serializable {
* {@inheritDoc}
*/
public Predicate isTrue(Expression<Boolean> expression) {
if ( CompoundPredicate.class.isInstance( expression ) ) {
final CompoundPredicate predicate = (CompoundPredicate) expression;
if ( predicate.getOperator() == Predicate.BooleanOperator.OR
&& predicate.getExpressions().size() == 0 ) {
predicate.not();
}
return predicate;
}
else if ( Predicate.class.isInstance( expression ) ) {
return (Predicate) expression;
}
return new BooleanAssertionPredicate( this, expression, Boolean.TRUE );
}
@ -321,6 +332,22 @@ public class CriteriaBuilderImpl implements CriteriaBuilder, Serializable {
* {@inheritDoc}
*/
public Predicate isFalse(Expression<Boolean> expression) {
if ( CompoundPredicate.class.isInstance( expression ) ) {
final CompoundPredicate predicate = (CompoundPredicate) expression;
if ( predicate.getOperator() == Predicate.BooleanOperator.OR
&& predicate.getExpressions().size() == 0 ) {
// nothing to do
}
else {
predicate.not();
}
return predicate;
}
else if ( Predicate.class.isInstance( expression ) ) {
final Predicate predicate = (Predicate) expression;
predicate.not();
return predicate;
}
return new BooleanAssertionPredicate( this, expression, Boolean.FALSE );
}

View File

@ -116,7 +116,11 @@ public class CompoundPredicate
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
if ( getExpressions().size() == 0 ) {
return getOperator() == BooleanOperator.AND
boolean implicitTrue = getOperator() == BooleanOperator.AND;
if ( isNegated() ) {
implicitTrue = !implicitTrue;
}
return implicitTrue
? "1=1" // true
: "0=1"; // false
}