[hibernate-commits] Hibernate SVN: r18814 - in core/trunk: testsuite/src/test/java/org/hibernate/test/hql and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Feb 16 16:39:53 EST 2010


Author: steve.ebersole at jboss.com
Date: 2010-02-16 16:39:52 -0500 (Tue, 16 Feb 2010)
New Revision: 18814

Modified:
   core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/MethodNode.java
   core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
Log:
HHH-4917 - Keyword TYPE not supported


Modified: core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/MethodNode.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/MethodNode.java	2010-02-16 19:54:48 UTC (rev 18813)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/MethodNode.java	2010-02-16 21:39:52 UTC (rev 18814)
@@ -63,12 +63,34 @@
 		AST exprList = name.getNextSibling();
 		// If the expression list has exactly one expression, and the type of the expression is a collection
 		// then this might be a collection function, such as index(c) or size(c).
-		if ( ASTUtil.hasExactlyOneChild( exprList ) && isCollectionPropertyMethod() ) {
-			collectionProperty( exprList.getFirstChild(), name );
+		if ( ASTUtil.hasExactlyOneChild( exprList ) ) {
+			if ( "type".equals( methodName ) ) {
+				typeDiscriminator( exprList.getFirstChild() );
+				return;
+			}
+			if ( isCollectionPropertyMethod() ) {
+				collectionProperty( exprList.getFirstChild(), name );
+				return;
+			}
 		}
-		else {
-			dialectFunction( exprList );
+
+		dialectFunction( exprList );
+	}
+
+	private void typeDiscriminator(AST path) throws SemanticException {
+		if ( path == null ) {
+			throw new SemanticException( "type() discriminator reference has no path!" );
 		}
+
+		FromReferenceNode pathAsFromReferenceNode = (FromReferenceNode) path;
+		FromElement typeFromElement = pathAsFromReferenceNode.getFromElement();
+		Type type = typeFromElement.getPropertyType( "class", "class" );
+		setDataType( type );
+
+		String[] columns = typeFromElement.toColumns( typeFromElement.getTableAlias(), "class", inSelect );
+		setText( columns[0] );
+
+		setType( SqlTokenTypes.SQL_TOKEN );
 	}
 
 	public SQLFunction getSQLFunction() {

Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java	2010-02-16 19:54:48 UTC (rev 18813)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java	2010-02-16 21:39:52 UTC (rev 18814)
@@ -106,6 +106,20 @@
 		return new FunctionalTestClassTestSuite( ASTParserLoadingTest.class );
 	}
 
+	public void testJpaTypeOperator() {
+		// just checking syntax here...
+		Session s = openSession();
+		s.beginTransaction();
+
+		// control
+		s.createQuery( "from Animal a where a.class = Dog" ).list();
+
+		s.createQuery( "from Animal a where type(a) = Dog" ).list();
+
+		s.getTransaction().commit();
+		s.close();
+	}
+
 	public void testComponentJoins() {
 		Session s = openSession();
 		s.beginTransaction();



More information about the hibernate-commits mailing list