FileDocCategorySizeDatePackage
PaginationTest.javaAPI DocHibernate 3.2.52001Tue Dec 12 16:22:26 GMT 2006org.hibernate.test.pagination

PaginationTest

public class PaginationTest extends org.hibernate.junit.functional.FunctionalTestCase
author
Gavin King

Fields Summary
Constructors Summary
public PaginationTest(String str)

		super(str);
	
Methods Summary
public voidconfigure(org.hibernate.cfg.Configuration cfg)

		cfg.setProperty(Environment.STATEMENT_BATCH_SIZE, "20");
	
public java.lang.StringgetCacheConcurrencyStrategy()

		return null;
	
public java.lang.String[]getMappings()

		return new String[] { "pagination/DataPoint.hbm.xml" };
	
public static junit.framework.Testsuite()

		return new FunctionalTestClassTestSuite( PaginationTest.class );
	
public voidtestPagination()

		Session s = openSession();
		Transaction t = s.beginTransaction();		
		for ( int i=0; i<10; i++ ) {
			DataPoint dp = new DataPoint();
			dp.setX( new BigDecimal(i * 0.1d).setScale(19, BigDecimal.ROUND_DOWN) );
			dp.setY( new BigDecimal( Math.cos( dp.getX().doubleValue() ) ).setScale(19, BigDecimal.ROUND_DOWN) );
			s.persist(dp);
		}
		t.commit();
		s.close();
		
		s = openSession();
		t = s.beginTransaction();
		int size = s.createSQLQuery("select id, xval, yval, description from DataPoint order by xval, yval")
			.addEntity(DataPoint.class)
			.setMaxResults(5)
			.list().size();
		assertEquals(size, 5);
		size = s.createQuery("from DataPoint order by x, y")
			.setFirstResult(5)
			.setMaxResults(2)
			.list().size();
		assertEquals(size, 2);
		size = s.createCriteria(DataPoint.class)
			.addOrder( Order.asc("x") )
			.addOrder( Order.asc("y") )
			.setFirstResult(8)
			.list().size();
		assertEquals(size, 2);
		t.commit();
		s.close();