From 48210916c2013417fb2825bca34df0cf8bf07926 Mon Sep 17 00:00:00 2001 From: Etienne Miret Date: Sun, 24 Aug 2014 10:45:19 +0200 Subject: [PATCH] HHH-9356 All arguments of a between are now given the same expected type. --- .../ast/tree/BetweenOperatorNode.java | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/BetweenOperatorNode.java b/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/BetweenOperatorNode.java index 01efbcebcc..63a704724b 100644 --- a/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/BetweenOperatorNode.java +++ b/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/BetweenOperatorNode.java @@ -34,9 +34,26 @@ public class BetweenOperatorNode extends SqlNode implements OperatorNode { throw new SemanticException( "high operand of a between operator was null" ); } - check( fixture, low, high ); - check( low, high, fixture ); - check( high, fixture, low ); + Type expectedType = null; + if ( fixture instanceof SqlNode ) { + expectedType = ( (SqlNode) fixture ).getDataType(); + } + if ( expectedType == null && low instanceof SqlNode ) { + expectedType = ( (SqlNode) low ).getDataType(); + } + if ( expectedType == null && high instanceof SqlNode ) { + expectedType = ( (SqlNode) high ).getDataType(); + } + + if ( fixture instanceof ExpectedTypeAwareNode ) { + ( (ExpectedTypeAwareNode) fixture ).setExpectedType( expectedType ); + } + if ( low instanceof ExpectedTypeAwareNode ) { + ( (ExpectedTypeAwareNode) low ).setExpectedType( expectedType ); + } + if ( high instanceof ExpectedTypeAwareNode ) { + ( (ExpectedTypeAwareNode) high ).setExpectedType( expectedType ); + } } @Override @@ -57,16 +74,4 @@ public class BetweenOperatorNode extends SqlNode implements OperatorNode { return (Node) getFirstChild().getNextSibling().getNextSibling(); } - private void check(Node check, Node first, Node second) { - if ( ExpectedTypeAwareNode.class.isAssignableFrom( check.getClass() ) ) { - Type expectedType = null; - if ( SqlNode.class.isAssignableFrom( first.getClass() ) ) { - expectedType = ( (SqlNode) first ).getDataType(); - } - if ( expectedType == null && SqlNode.class.isAssignableFrom( second.getClass() ) ) { - expectedType = ( (SqlNode) second ).getDataType(); - } - ( (ExpectedTypeAwareNode) check ).setExpectedType( expectedType ); - } - } }