【Java开源代码栏目提醒】:网学会员Java开源代码为您提供ASTParserLoadingTest.java参考,解决您在ASTParserLoadingTest.java学习中工作中的难题,参考学习。
// $Id: ASTParserLoadingTest.java 9531 2006-03-02 03:14:31Z steve.3710167@qq.com $
package org.hibernate.test.hql;
import java.math.BigDecimal;
import java.sql.Date;
import java.sql.Time;
import java.
sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.ScrollableResults;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.QueryException;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.DB2Dialect;
import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.Oracle9Dialect;
import org.hibernate.test.TestCase;
import org.hibernate.test.cid.Customer;
import org.hibernate.test.cid.LineItem;
import org.hibernate.test.cid.Order;
import org.hibernate.test.cid.Product;
import org.hibernate.type.ManyToOneType;
import org.hibernate.type.Type;
import org.hibernate.util.StringHelper;
/**
* Tests the integration of the new AST parser into the loading of query results using
* the Hibernate persisters and loaders.
* <p/>
* Also used to test the syntax of the resulting sql against the underlying
* database, specifically for functionality not supported by the classic
* parser.
*
* @author Steve
*/
public class ASTParserLoadingTest extends TestCase {
public ASTParserLoadingTest(String name) {
super( name );
}
private List createdAnimalIds = new ArrayList();
protected String[] getMappings() {
// Make sure we are using the new AST parser translator...
System.setProperty( Environment.QUERY_TRANSLATOR, "org.hibernate.hql.ast.ASTQueryTranslatorFactory" );
return new String[]{
"hql/Animal.hbm.xml",
"hql/FooBarCopy.hbm.xml",
"batchfetch/ProductLine.hbm.xml",
"cid/Customer.hbm.
xml",
"cid/Order.hbm.xml",
"cid/LineItem.hbm.xml",
"cid/Product.hbm.xml"
};
}
public void testCollectionJoinsInSubselect() {
// HHH-1248 : initially FromElementFactory treated any explicit join
// as an implied join so that theta-style joins would always be used.
// This was because correlated subqueries cannot use ANSI-style joins
// for the correlation. However, this special treatment was not limited
// to only correlated subqueries; it was applied to any subqueries ->
// which in-and-of-itself is not necessarily bad. But somewhere later
// the choices made there caused joins to be dropped.
Session s = openSession();
String qryString =
"select a.id, a.description" +
" from Animal a" +
" left join a.offspring" +
" where a in (" +
" select a1 from Animal a1" +
" left join a1.offspring o" +
" where a1.id=1" +
")";
s.createQuery( qryString ).list();
qryString =
"select h.id, h.description" +
" from Human h" +
" left join h.friends" +
" where h in (" +
" select h1" +
" from Human h1" +
" left join h1.friends f" +
" where h1.id=1" +
")";
s.createQuery( qryString ).list();
qryString =
"select h.id, h.description" +
" from Human h" +
" left join h.friends f" +
" where f in (" +
" select h1" +
" from Human h1" +
" left join h1.friends f1" +
" where h = f1" +
")";
s.createQuery( qryString ).list();
s.close();
}
public void testQueryMetadataRetrievalWithFetching() {
// HHH-1464 : there was a problem due to the fact they we polled
// the shallow version of the query plan to get the metadata.
Session s = openSession();
Query query = s.createQuery( "from Animal a inner join fetch a.mother" );
assertEquals( 1, query.getReturnTypes().length );
assertNull( query.getReturnAliases() );
s.close();
}
public void testSuperclassPropertyReferenceAfterCollectionIndexedAccess() {
// note: simply performing syntax checking in the db
// test for HHH-429
Session s = openSession();
s.beginTransaction();
Mammal tiger = new Mammal();
tiger.setDescription( "Tiger" );
s.persist( tiger );
Mammal mother = new Mammal();
mother.setDescription( "Tiger's mother" );
mother.setBodyWeight( 4.0f );
mother.addOffspring( tiger );
s.persist( mother );
Zoo zoo = new Zoo();
zoo.setName( "Austin Zoo" );
zoo.setMammals( new HashMap() );
zo