FileDocCategorySizeDatePackage
InstrumentCacheTest.javaAPI DocHibernate 3.2.52458Tue Dec 12 16:22:26 GMT 2006org.hibernate.test.lazycache

InstrumentCacheTest

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

Fields Summary
Constructors Summary
public InstrumentCacheTest(String str)

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

		cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
	
public java.lang.String[]getMappings()

		return new String[] { "lazycache/Documents.hbm.xml" };
	
public static booleanisRunnable()

		// TODO : this could be handled via appliesTo()...
		return FieldInterceptionHelper.isInstrumented( new Document() );
	
public booleanoverrideCacheStrategy()

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

		return new FunctionalTestClassTestSuite( InstrumentCacheTest.class );
	
public voidtestInitFromCache()

		Session s;
		Transaction tx;

		s = getSessions().openSession();
		tx = s.beginTransaction();
		s.persist( new Document("HiA", "Hibernate book", "Hibernate is....") );
		tx.commit();
		s.close();

		s = getSessions().openSession();
		tx = s.beginTransaction();
		s.createQuery("from Document fetch all properties").uniqueResult();
		tx.commit();
		s.close();

		getSessions().getStatistics().clear();

		s = getSessions().openSession();
		tx = s.beginTransaction();
		Document d = (Document) s.createCriteria(Document.class).uniqueResult();
		assertFalse( Hibernate.isPropertyInitialized(d, "text") );
		assertFalse( Hibernate.isPropertyInitialized(d, "summary") );
		assertEquals( "Hibernate is....", d.getText() );
		assertTrue( Hibernate.isPropertyInitialized(d, "text") );
		assertTrue( Hibernate.isPropertyInitialized(d, "summary") );
		tx.commit();
		s.close();

		assertEquals( 2, getSessions().getStatistics().getPrepareStatementCount() );

		s = getSessions().openSession();
		tx = s.beginTransaction();
		d = (Document) s.get(Document.class, d.getId());
		assertFalse( Hibernate.isPropertyInitialized(d, "text") );
		assertFalse( Hibernate.isPropertyInitialized(d, "summary") );
		tx.commit();
		s.close();