FileDocCategorySizeDatePackage
ASTQueryTranslatorTest.javaAPI DocHibernate 3.2.57223Tue Dec 20 10:35:54 GMT 2005org.hibernate.test.hql

ASTQueryTranslatorTest

public class ASTQueryTranslatorTest extends QueryTranslatorTestCase
Tests cases where the AST based QueryTranslator does not generate identical SQL.
author
josh Dec 6, 2004 9:07:58 AM

Fields Summary
Constructors Summary
public ASTQueryTranslatorTest(String x)

		super( x );
	
Methods Summary
protected booleandropAfterFailure()

		return false;
	
public static junit.framework.Testsuite()

		return new TestSuite( ASTQueryTranslatorTest.class );
	
public voidtestComplexWhereExpression()

		// classic QT generates lots of extra parens and some extra theta joins.
		assertTranslation( "select distinct s from Simple s\n" +
				"where ( ( s.other.count + 3 ) = (15*2)/2 and s.count = 69) or ( ( s.other.count + 2 ) / 7 ) = 2" );
	
public voidtestComponent3()

		// The old translator generates duplicate inner joins *and* duplicate theta join clauses in the where statement in this case.
		assertTranslation( "from Dog dog where dog.owner.name.first = 'Gavin' and dog.owner.name.last='King' and dog.owner.bodyWeight<70" );
	
public voidtestDuplicateImplicitJoin()

		// old qt generates an extra theta join
		assertTranslation( "from Animal an where an.mother.bodyWeight > 10 and an.mother.bodyWeight < 20" );
	
public voidtestDuplicateImplicitJoinInWhere()

		//new qt has more organized joins
		assertTranslation("from Human h where h.mother.bodyWeight>10 and h.mother.bodyWeight<10");
	
public voidtestFetch()

		//SQL is correct, new qt is not throwing an exception when it should be (minor issue)
		assertTranslation("from Customer cust left join fetch cust.billingAddress where cust.customerId='abc123'");
	
public voidtestFetchProperties()

		//not implemented in old qt
		assertTranslation("from Animal a fetch all properties join a.offspring o fetch all properties");
	
public voidtestImplicitJoin()

		//old qt generates an exception, the new one doesnt 
		//this is actually invalid HQL, an implicit join on a many-valued association
		assertTranslation( "from Animal an where an.offspring.mother.bodyWeight > 10" );
	
public voidtestImplicitJoinInSelect()

		//slightly diff select clause, both correct
		assertTranslation("select foo.long, foo.foo from Foo foo");
	
public voidtestImplicitJoinInsideOutsideSubselect()

		// new qt re-uses the joins defined by 's.other.count' path when referenced in the subquery,
		// whereas the old qt reuses only the "root table" (not the already defined join to 'other'):
		//   OLD SQL :
		//      select  simple0_.id_ as col_0_0_
		//      from    Simple simple0_,
		//              Simple simple1_
		//      where   (simple1_.count_>0
		//      and     simple0_.other=simple1_.id_)
		//      and     (simple0_.id_=some(
		//                  select  simple2_.id_
		//                  from    Simple simple2_,
		//                          Simple simple3_,
		//                          Simple simple4_
		//                  where   (simple3_.count_=simple4_.count_
		//                  and     simple2_.other=simple3_.id_
		//                  and     simple0_.other=simple4_.id_)
		//              ))
		//   NEW SQL :
		//      select  simple0_.id_ as col_0_0_
		//      from    Simple simple0_,
		//              Simple simple1_
		//      where   (simple1_.count_>0
		//      and     simple0_.id_=some(
		//                  select  simple2_.id_
		//                  from    Simple simple2_,
		//                          Simple simple3_
		//                  where   (simple3_.count_=simple1_.count_
		//                  and     simple2_.other=simple3_.id_)
		//            )
		//        and simple0_.other=simple1_.id_)
		assertTranslation( "from Simple s where s = some( from Simple sim where sim.other.count=s.other.count ) and s.other.count > 0" );
		assertTranslation( "from Simple s where s.other.count > 0 and s = some( from Simple sim where sim.other.count=s.other.count )" );
	
public voidtestKeywordClassNameAndAlias()

		// The old QT throws an exception, the new one doesn't, which is better
		assertTranslation( "from Order order" );
	
public voidtestNakedComponentPropertyRef()

		// this is needed for ejb3 selects and bulk statements
		//      Note: these all fail because the old parser did not have this
		//      feature, it just "passes the tokens through" to the SQL.
		assertTranslation( "from Human where name.first = 'Gavin'" );
		assertTranslation( "select name from Human" );
		assertTranslation( "select upper(h.name.first) from Human as h" );
		assertTranslation( "select upper(name.first) from Human" );
	
public voidtestNakedImplicitJoins()

		assertTranslation( "from Animal where mother.father = ?" );
	
public voidtestNakedMapIndex()

		assertTranslation( "from Zoo where mammals['dog'].description like '%black%'" );
	
public voidtestNakedPropertyRef()

		// this is needed for ejb3 selects and bulk statements
		//      Note: these all fail because the old parser did not have this
		//      feature, it just "passes the tokens through" to the SQL.
		assertTranslation( "from Animal where bodyWeight = bodyWeight" );
		assertTranslation( "select bodyWeight from Animal" );
		assertTranslation( "select max(bodyWeight) from Animal" );
	
public voidtestOldSyntax()

		//generates ANSI join instead of theta join
		assertTranslation("from a in class Animal, o in elements(a.offspring), h in class Human");
	
public voidtestSelectClauseImplicitJoin()

		//the old query translator has a bug which results in the wrong return type!
		assertTranslation( "select d.owner.mother from Dog d" );
	
public voidtestSelectExpression()

		//old qt cant handle select-clause expressions
		assertTranslation("select a.bodyWeight + m.bodyWeight from Animal a join a.mother m");
	
public voidtestSelectManyToOne()

		assertTranslation("select distinct a.zoo from Animal a where a.zoo is not null");
		assertTranslation("select a.zoo from Animal a");
	
public voidtestSelectStandardFunctions()

		//old parser throws an exception
		assertTranslation( "select current_date(), current_time(), current_timestamp() from Animal" );
	
public voidtestUncorrelatedSubselectWithJoin()

		// The old translator generates unnecessary inner joins for the Animal subclass of zoo.mammals
		// The new one is working fine now!
		assertTranslation( "from Animal a where a in (select mam from Zoo zoo join zoo.mammals mam)" );
	
public voidtestWhereExpressions()

		assertTranslation("from User u where u.userName='gavin' and u.human.name.first='Gavin'");
		//new qt has more organized joins
		assertTranslation("from User u where u.human.name.last='King' and u.human.name.first='Gavin'");
		assertTranslation("from Bar bar where bar.baz.name='josh'");
		assertTranslation("from Bar bar where bar.baz.name='josh' and not bar.baz.name='gavin'");