Author: steve.ebersole(a)jboss.com
Date: 2009-12-18 15:04:44 -0500 (Fri, 18 Dec 2009)
New Revision: 18269
Modified:
core/trunk/core/src/main/antlr/hql-sql.g
core/trunk/core/src/main/antlr/hql.g
core/trunk/core/src/main/antlr/sql-gen.g
core/trunk/core/src/main/java/org/hibernate/hql/ast/SqlASTFactory.java
core/trunk/testsuite/src/test/java/org/hibernate/test/hql/HQLTest.java
Log:
HHH-4719 - Support modulo operator
Modified: core/trunk/core/src/main/antlr/hql-sql.g
===================================================================
--- core/trunk/core/src/main/antlr/hql-sql.g 2009-12-18 15:32:39 UTC (rev 18268)
+++ core/trunk/core/src/main/antlr/hql-sql.g 2009-12-18 20:04:44 UTC (rev 18269)
@@ -558,6 +558,7 @@
: #(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 ); }
Modified: core/trunk/core/src/main/antlr/hql.g
===================================================================
--- core/trunk/core/src/main/antlr/hql.g 2009-12-18 15:32:39 UTC (rev 18268)
+++ core/trunk/core/src/main/antlr/hql.g 2009-12-18 20:04:44 UTC (rev 18269)
@@ -559,7 +559,7 @@
// 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 @@
MINUS: '-';
STAR: '*';
DIV: '/';
+MOD: '%';
COLON: ':';
PARAM: '?';
Modified: core/trunk/core/src/main/antlr/sql-gen.g
===================================================================
--- core/trunk/core/src/main/antlr/sql-gen.g 2009-12-18 15:32:39 UTC (rev 18268)
+++ core/trunk/core/src/main/antlr/sql-gen.g 2009-12-18 20:04:44 UTC (rev 18269)
@@ -377,6 +377,7 @@
multiplicativeExpr
: #(STAR nestedExpr { out("*"); } nestedExpr)
| #(DIV nestedExpr { out("/"); } nestedExprAfterMinusDiv)
+ | #(MOD nestedExpr { out(" % "); } nestedExprAfterMinusDiv)
;
nestedExpr
Modified: core/trunk/core/src/main/java/org/hibernate/hql/ast/SqlASTFactory.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/SqlASTFactory.java 2009-12-18
15:32:39 UTC (rev 18268)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/SqlASTFactory.java 2009-12-18
20:04:44 UTC (rev 18269)
@@ -158,6 +158,7 @@
case MINUS:
case STAR:
case DIV:
+ case MOD:
return BinaryArithmeticOperatorNode.class;
case UNARY_MINUS:
case UNARY_PLUS:
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/hql/HQLTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/hql/HQLTest.java 2009-12-18
15:32:39 UTC (rev 18268)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/hql/HQLTest.java 2009-12-18
20:04:44 UTC (rev 18269)
@@ -85,6 +85,10 @@
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'" );
Show replies by date