[hibernate-commits] Hibernate SVN: r20197 - in core/trunk: core/src/main/java/org/hibernate/sql/ordering/antlr and 1 other directories.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Thu Aug 19 19:06:33 EDT 2010
Author: gbadner
Date: 2010-08-19 19:06:32 -0400 (Thu, 19 Aug 2010)
New Revision: 20197
Modified:
core/trunk/core/src/main/java/org/hibernate/sql/Template.java
core/trunk/core/src/main/java/org/hibernate/sql/ordering/antlr/OrderByFragmentParser.java
core/trunk/testsuite/src/test/java/org/hibernate/test/hql/FunctionNameAsColumnTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/hql/FunctionNamesAsColumns.hbm.xml
Log:
HHH-5225 : Cannot parse order-by fragment if it contains a registered function without parentheses
Modified: core/trunk/core/src/main/java/org/hibernate/sql/Template.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/sql/Template.java 2010-08-19 21:18:31 UTC (rev 20196)
+++ core/trunk/core/src/main/java/org/hibernate/sql/Template.java 2010-08-19 23:06:32 UTC (rev 20197)
@@ -717,11 +717,9 @@
// lcToken does not refer to a function
return false;
}
- // if function.hasArguments() and function.hasParenthesesIfNoArguments() is true,
- // then assume that lcToken is not a function, since it is not followed by "(";
- // can't seem to use function.hasParenthesesIfNoArguments() alone because
- // function definitions may return true if "()" is optional when there are no arguments.
- return function.hasArguments() && function.hasParenthesesIfNoArguments() ? false : true;
+ // if function.hasParenthesesIfNoArguments() is true, then assume
+ // lcToken is not a function (since it is not followed by '(')
+ return ! function.hasParenthesesIfNoArguments();
}
private static boolean isIdentifier(String token, Dialect dialect) {
Modified: core/trunk/core/src/main/java/org/hibernate/sql/ordering/antlr/OrderByFragmentParser.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/sql/ordering/antlr/OrderByFragmentParser.java 2010-08-19 21:18:31 UTC (rev 20196)
+++ core/trunk/core/src/main/java/org/hibernate/sql/ordering/antlr/OrderByFragmentParser.java 2010-08-19 23:06:32 UTC (rev 20197)
@@ -103,7 +103,20 @@
* {@inheritDoc}
*/
protected boolean isFunctionName(AST ast) {
- return context.getSqlFunctionRegistry().hasFunction( ast.getText() );
+ AST child = ast.getFirstChild();
+ // assume it is a function if it has parameters
+ if ( child != null && "{param list}".equals( child.getText() ) ) {
+ return true;
+ }
+
+ final SQLFunction function = context.getSqlFunctionRegistry().findSQLFunction( ast.getText() );
+ if ( function == null ) {
+ return false;
+ }
+
+ // if function.hasParenthesesIfNoArguments() is true, then assume
+ // ast.getText() is not a function.
+ return ! function.hasParenthesesIfNoArguments();
}
/**
@@ -111,8 +124,10 @@
*/
protected AST resolveFunction(AST ast) {
AST child = ast.getFirstChild();
- assert "{param list}".equals( child.getText() );
- child = child.getFirstChild();
+ if ( child != null ) {
+ assert "{param list}".equals( child.getText() );
+ child = child.getFirstChild();
+ }
final String functionName = ast.getText();
final SQLFunction function = context.getSqlFunctionRegistry().findSQLFunction( functionName );
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/hql/FunctionNameAsColumnTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/hql/FunctionNameAsColumnTest.java 2010-08-19 21:18:31 UTC (rev 20196)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/hql/FunctionNameAsColumnTest.java 2010-08-19 23:06:32 UTC (rev 20197)
@@ -37,6 +37,8 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.criterion.Restrictions;
+import org.hibernate.dialect.function.SQLFunction;
+import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.testing.junit.functional.FunctionalTestCase;
import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite;
@@ -196,6 +198,13 @@
}
public void testGetMultiColumnSameNameAsNoArgFunctionHQL() throws Exception {
+ SQLFunction function =
+ ( ( SessionFactoryImplementor ) getSessions() ).getSqlFunctionRegistry().findSQLFunction( "current_date" );
+ if ( function == null || function.hasParenthesesIfNoArguments() ) {
+ reportSkip( "current_date reuires ()", "tests noarg function that does not require ()" );
+ return;
+ }
+
Session s = openSession();
Transaction t = s.beginTransaction();
EntityWithNoArgFunctionAsColumn e1 = new EntityWithNoArgFunctionAsColumn();
@@ -235,6 +244,13 @@
}
public void testGetMultiColumnSameNameAsNoArgFunctionCriteria() {
+ SQLFunction function =
+ ( ( SessionFactoryImplementor ) getSessions() ).getSqlFunctionRegistry().findSQLFunction( "current_date" );
+ if ( function == null || function.hasParenthesesIfNoArguments() ) {
+ reportSkip( "current_date reuires ()", "tests noarg function that does not require ()" );
+ return;
+ }
+
Session s = openSession();
Transaction t = s.beginTransaction();
EntityWithNoArgFunctionAsColumn e1 = new EntityWithNoArgFunctionAsColumn();
@@ -274,6 +290,13 @@
}
public void testNoArgFcnAndColumnSameNameAsNoArgFunctionHQL() {
+ SQLFunction function =
+ ( ( SessionFactoryImplementor ) getSessions() ).getSqlFunctionRegistry().findSQLFunction( "current_date" );
+ if ( function == null || function.hasParenthesesIfNoArguments() ) {
+ reportSkip( "current_date reuires ()", "tests noarg function that does not require ()" );
+ return;
+ }
+
Session s = openSession();
Transaction t = s.beginTransaction();
EntityWithNoArgFunctionAsColumn e1 = new EntityWithNoArgFunctionAsColumn();
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/hql/FunctionNamesAsColumns.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/hql/FunctionNamesAsColumns.hbm.xml 2010-08-19 21:18:31 UTC (rev 20196)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/hql/FunctionNamesAsColumns.hbm.xml 2010-08-19 23:06:32 UTC (rev 20197)
@@ -9,11 +9,13 @@
<generator class="increment"/>
</id>
<many-to-one name="nextHolder" cascade="all"/>
- <set name="entityWithArgFunctionAsColumns" inverse="false" lazy="true" cascade="all-delete-orphan">
+ <set name="entityWithArgFunctionAsColumns" inverse="false" lazy="true" cascade="all-delete-orphan"
+ order-by="lower,lower( upper )">
<key column="HOLDER_ID"/>
<one-to-many class="EntityWithArgFunctionAsColumn"/>
</set>
- <set name="entityWithNoArgFunctionAsColumns" inverse="false" lazy="true" cascade="all-delete-orphan">
+ <set name="entityWithNoArgFunctionAsColumns" inverse="false" lazy="true" cascade="all-delete-orphan"
+ order-by="current_date, `current_date`">
<key column="HOLDER_ID"/>
<one-to-many class="EntityWithNoArgFunctionAsColumn"/>
</set>
@@ -31,7 +33,7 @@
<id name="id" column="ID" type="long">
<generator class="increment"/>
</id>
- <property name="currentDate" column="`current_date`" type="string"/>
+ <property name="currentDate" column="`current_date`" type="string"/>
</class>
</hibernate-mapping>
\ No newline at end of file
More information about the hibernate-commits
mailing list