HHH-4719 - Support modulo operator

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18269 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2009-12-18 20:04:44 +00:00
parent c1da5f1e3c
commit 3748f29945
5 changed files with 9 additions and 1 deletions

View File

@ -558,6 +558,7 @@ arithmeticExpr
: #(PLUS expr expr) { prepareArithmeticOperator( #arithmeticExpr ); }
| #(MINUS expr expr) { prepareArithmeticOperator( #arithmeticExpr ); }
| #(DIV expr expr) { prepareArithmeticOperator( #arithmeticExpr ); }
| #(MOD expr expr) { prepareArithmeticOperator( #arithmeticExpr ); }
| #(STAR expr expr) { prepareArithmeticOperator( #arithmeticExpr ); }
// | #(CONCAT expr (expr)+ ) { prepareArithmeticOperator( #arithmeticExpr ); }
| #(UNARY_MINUS expr) { prepareArithmeticOperator( #arithmeticExpr ); }

View File

@ -559,7 +559,7 @@ additiveExpression
// level 2 - binary multiply and divide
multiplyExpression
: unaryExpression ( ( STAR^ | DIV^ ) unaryExpression )*
: unaryExpression ( ( STAR^ | DIV^ | MOD^ ) unaryExpression )*
;
// level 1 - unary minus, unary plus, not
@ -769,6 +769,7 @@ PLUS: '+';
MINUS: '-';
STAR: '*';
DIV: '/';
MOD: '%';
COLON: ':';
PARAM: '?';

View File

@ -377,6 +377,7 @@ additiveExpr
multiplicativeExpr
: #(STAR nestedExpr { out("*"); } nestedExpr)
| #(DIV nestedExpr { out("/"); } nestedExprAfterMinusDiv)
| #(MOD nestedExpr { out(" % "); } nestedExprAfterMinusDiv)
;
nestedExpr

View File

@ -158,6 +158,7 @@ public class SqlASTFactory extends ASTFactory implements HqlSqlTokenTypes {
case MINUS:
case STAR:
case DIV:
case MOD:
return BinaryArithmeticOperatorNode.class;
case UNARY_MINUS:
case UNARY_PLUS:

View File

@ -85,6 +85,10 @@ public class HQLTest extends QueryTranslatorTestCase {
super.cleanupTest();
}
public void testModulo() {
assertTranslation( "from Animal a where a.bodyWeight % 2 = 0" );
}
public void testInvalidCollectionDereferencesFail() {
// should fail with the same exceptions (because of the DotNode.ILLEGAL_COLL_DEREF_EXCP_BUILDER injection)
assertTranslation( "from Animal a where a.offspring.description = 'xyz'" );