Java Mailing List Archive

http://www.gg3721.com/

Home » Hibernate Commits List »

[hibernate-commits] Hibernate SVN: r20198 - in
 core/branches/Branch_3_5:
 core/src/main/java/org/hibernate/sql/ordering/antlr and 1
 other directories.

hibernate-commits

2010-08-19


Author LoginPost Reply
Author: gbadner
Date: 2010-08-19 19:34:26 -0400 (Thu, 19 Aug 2010)
New Revision: 20198

Modified:
 core/branches/Branch_3_5/core/src/main/java/org/hibernate/sql/Template.java
 core/branches/Branch_3_5/core/src/main/java/org/hibernate/sql/ordering/antlr/OrderByFragmentParser.java
 core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/hql/FunctionNameAsColumnTest.java
 core/branches/Branch_3_5/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/branches/Branch_3_5/core/src/main/java/org/hibernate/sql/Template.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/sql/Template.java  2010-08-19 23:06:32 UTC (rev 20197)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/sql/Template.java  2010-08-19 23:34:26 UTC (rev 20198)
@@(protected) @@
     // 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/branches/Branch_3_5/core/src/main/java/org/hibernate/sql/ordering/antlr/OrderByFragmentParser.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/sql/ordering/antlr/OrderByFragmentParser.java  2010-08-19 23:06:32 UTC (rev 20197)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/sql/ordering/antlr/OrderByFragmentParser.java  2010-08-19 23:34:26 UTC (rev 20198)
@@(protected) @@
  * {@(protected)}
  */
 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();
 }

 /**
@@(protected) @@
  */
 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/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/hql/FunctionNameAsColumnTest.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/hql/FunctionNameAsColumnTest.java  2010-08-19 23:06:32 UTC (rev 20197)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/hql/FunctionNameAsColumnTest.java  2010-08-19 23:34:26 UTC (rev 20198)
@@(protected) @@
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.junit.functional.FunctionalTestCase;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;

@@(protected) @@
 }

 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();
@@(protected) @@
 }

 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();
@@(protected) @@
 }

 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/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/hql/FunctionNamesAsColumns.hbm.xml
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/hql/FunctionNamesAsColumns.hbm.xml  2010-08-19 23:06:32 UTC (rev 20197)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/hql/FunctionNamesAsColumns.hbm.xml  2010-08-19 23:34:26 UTC (rev 20198)
@@(protected) @@
        <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>
@@(protected) @@
     <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

_______________________________________________
hibernate-commits mailing list
hibernate-commits@(protected)
https://lists.jboss.org/mailman/listinfo/hibernate-commits
©2008 gg3721.com - Jax Systems, LLC, U.S.A.