HHH-6856 RowValueConstructorSyntax with In syntax is not working

This commit is contained in:
Strong Liu 2011-11-28 17:56:33 +08:00 committed by Steve Ebersole
parent 9a7924d9bc
commit eca04896c9
3 changed files with 31 additions and 10 deletions

View File

@ -309,7 +309,12 @@ inList
; ;
simpleExprList simpleExprList
: { out("("); } (e:simpleExpr { separator(e," , "); } )* { out(")"); } : { out("("); } (e:simpleExprWithVectorExpr { separator(e," , "); } )* { out(")"); }
;
simpleExprWithVectorExpr
: simpleExpr
| #( VECTOR_EXPR { out("("); } (e:expr { separator(e," , "); } )* { out(")"); } )
; ;
// A simple expression, or a sub-select with parens around it. // A simple expression, or a sub-select with parens around it.

View File

@ -1696,7 +1696,7 @@ public class CriteriaQueryTest extends BaseCoreFunctionalTestCase {
session.close(); session.close();
} }
@Test @Test
public void testCriteriaCollectionOfValue() { public void testCriteriaCollectionOfValue() {
Session session = openSession(); Session session = openSession();
Transaction t = session.beginTransaction(); Transaction t = session.beginTransaction();
@ -1806,7 +1806,7 @@ public class CriteriaQueryTest extends BaseCoreFunctionalTestCase {
session.close(); session.close();
} }
@Test @Test
public void testCriteriaCollectionOfComponent() { public void testCriteriaCollectionOfComponent() {
Session session = openSession(); Session session = openSession();
Transaction t = session.beginTransaction(); Transaction t = session.beginTransaction();

View File

@ -139,8 +139,7 @@ public class HQLTest extends QueryTranslatorTestCase {
} }
@Test @Test
@RequiresDialectFeature( DialectChecks.SupportsRowValueConstructorSyntaxInInListCheck .class ) public void testRowValueConstructorSyntaxInInListBeingTranslated() {
public void testRowValueConstructorSyntaxInInList() {
QueryTranslatorImpl translator = createNewQueryTranslator("from LineItem l where l.id in (?)"); QueryTranslatorImpl translator = createNewQueryTranslator("from LineItem l where l.id in (?)");
assertInExist("'in' should be translated to 'and'", false, translator); assertInExist("'in' should be translated to 'and'", false, translator);
translator = createNewQueryTranslator("from LineItem l where l.id in ?"); translator = createNewQueryTranslator("from LineItem l where l.id in ?");
@ -148,19 +147,36 @@ public class HQLTest extends QueryTranslatorTestCase {
translator = createNewQueryTranslator("from LineItem l where l.id in (('a1',1,'b1'),('a2',2,'b2'))"); translator = createNewQueryTranslator("from LineItem l where l.id in (('a1',1,'b1'),('a2',2,'b2'))");
assertInExist("'in' should be translated to 'and'", false, translator); assertInExist("'in' should be translated to 'and'", false, translator);
translator = createNewQueryTranslator("from Animal a where a.id in (?)"); translator = createNewQueryTranslator("from Animal a where a.id in (?)");
assertInExist("only translate tuple with 'in' syntax", true, translator); assertInExist("only translated tuple has 'in' syntax", true, translator);
translator = createNewQueryTranslator("from Animal a where a.id in ?"); translator = createNewQueryTranslator("from Animal a where a.id in ?");
assertInExist("only translate tuple with 'in' syntax", true, translator); assertInExist("only translated tuple has 'in' syntax", true, translator);
translator = createNewQueryTranslator("from LineItem l where l.id in (select a1 from Animal a1 left join a1.offspring o where a1.id = 1)"); translator = createNewQueryTranslator("from LineItem l where l.id in (select a1 from Animal a1 left join a1.offspring o where a1.id = 1)");
assertInExist("do not translate subqueries", true, translator); assertInExist("do not translate sub-queries", true, translator);
}
@Test
@RequiresDialectFeature( DialectChecks.SupportsRowValueConstructorSyntaxInInListCheck.class )
public void testRowValueConstructorSyntaxInInList() {
QueryTranslatorImpl translator = createNewQueryTranslator("from LineItem l where l.id in (?)");
assertInExist(" 'in' should be kept, since the dialect supports this syntax", true, translator);
translator = createNewQueryTranslator("from LineItem l where l.id in ?");
assertInExist(" 'in' should be kept, since the dialect supports this syntax", true, translator);
translator = createNewQueryTranslator("from LineItem l where l.id in (('a1',1,'b1'),('a2',2,'b2'))");
assertInExist(" 'in' should be kept, since the dialect supports this syntax", true,translator);
translator = createNewQueryTranslator("from Animal a where a.id in (?)");
assertInExist("only translated tuple has 'in' syntax", true, translator);
translator = createNewQueryTranslator("from Animal a where a.id in ?");
assertInExist("only translated tuple has 'in' syntax", true, translator);
translator = createNewQueryTranslator("from LineItem l where l.id in (select a1 from Animal a1 left join a1.offspring o where a1.id = 1)");
assertInExist("do not translate sub-queries", true, translator);
} }
private void assertInExist( String message, boolean expected, QueryTranslatorImpl translator ) { private void assertInExist( String message, boolean expected, QueryTranslatorImpl translator ) {
AST ast = translator.getSqlAST().getWalker().getAST(); AST ast = translator.getSqlAST().getWalker().getAST();
QueryNode queryNode = (QueryNode) ast; QueryNode queryNode = (QueryNode) ast;
AST inNode = ASTUtil.findTypeInChildren( queryNode, HqlTokenTypes.IN ); AST whereNode = ASTUtil.findTypeInChildren( queryNode, HqlTokenTypes.WHERE );
assertEquals( message, expected, inNode != null ); AST inNode = whereNode.getFirstChild();
assertEquals( message, expected, inNode != null && inNode.getType() == HqlTokenTypes.IN );
} }
@Test @Test