HHH-4917 - Keyword TYPE not supported

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18814 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2010-02-16 21:39:52 +00:00
parent 6a2843f98a
commit 6acf72f54a
2 changed files with 40 additions and 4 deletions

View File

@ -63,12 +63,34 @@ public class MethodNode extends AbstractSelectExpression implements SelectExpres
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() {

View File

@ -106,6 +106,20 @@ public class ASTParserLoadingTest extends FunctionalTestCase {
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();