FileDocCategorySizeDatePackage
RefreshTest.javaAPI DocHibernate 3.2.52096Tue Dec 12 16:22:26 GMT 2006org.hibernate.test.cascade

RefreshTest

public class RefreshTest extends org.hibernate.junit.functional.FunctionalTestCase
Implementation of RefreshTest.
author
Steve Ebersole

Fields Summary
Constructors Summary
public RefreshTest(String name)

		super( name );
	
Methods Summary
public java.lang.String[]getMappings()

		return new String[] { "cascade/Job.hbm.xml", "cascade/JobBatch.hbm.xml" };
	
public static junit.framework.Testsuite()

		return new FunctionalTestClassTestSuite( RefreshTest.class );
	
public voidtestRefreshCascade()

		Session session = openSession();
		Transaction txn = session.beginTransaction();

		JobBatch batch = new JobBatch( new Date() );
		batch.createJob().setProcessingInstructions( "Just do it!" );
		batch.createJob().setProcessingInstructions( "I know you can do it!" );

		// write the stuff to the database; at this stage all job.status values are zero
		session.persist( batch );
		session.flush();

		// behind the session's back, let's modify the statuses
		updateStatuses( session.connection() );

		// Now lets refresh the persistent batch, and see if the refresh cascaded to the jobs collection elements
		session.refresh( batch );

		Iterator itr = batch.getJobs().iterator();
		while( itr.hasNext() ) {
			Job job = ( Job ) itr.next();
			assertEquals( "Jobs not refreshed!", 1, job.getStatus() );
		}

		txn.rollback();
		session.close();
	
private voidupdateStatuses(java.sql.Connection connection)

		PreparedStatement stmnt = null;
		try {
			stmnt = connection.prepareStatement( "UPDATE T_JOB SET JOB_STATUS = 1" );
			stmnt.executeUpdate();
		}
		finally {
			if ( stmnt != null ) {
				try {
					stmnt.close();
				}
				catch( Throwable ignore ) {
				}
			}
		}