FileDocCategorySizeDatePackage
CacheSynchronization.javaAPI DocHibernate 3.2.52682Wed Feb 08 15:34:34 GMT 2006org.hibernate.transaction

CacheSynchronization

public final class CacheSynchronization extends Object implements Synchronization
author
Gavin King

Fields Summary
private static final Log
log
private final TransactionFactory.Context
ctx
private org.hibernate.jdbc.JDBCContext
jdbcContext
private final Transaction
transaction
private final org.hibernate.Transaction
hibernateTransaction
Constructors Summary
public CacheSynchronization(TransactionFactory.Context ctx, org.hibernate.jdbc.JDBCContext jdbcContext, Transaction transaction, org.hibernate.Transaction tx)


	 
			  
			  
			  
			 
	 
		this.ctx = ctx;
		this.jdbcContext = jdbcContext;
		this.transaction = transaction;
		this.hibernateTransaction = tx;
	
Methods Summary
public voidafterCompletion(int status)

		if ( log.isTraceEnabled() ) {
			log.trace("transaction after completion callback, status: " + status);
		}
		try {
			jdbcContext.afterTransactionCompletion(status==Status.STATUS_COMMITTED, hibernateTransaction);
		}
		finally {
			if ( ctx.shouldAutoClose() && !ctx.isClosed() ) {
				log.trace("automatically closing session");
				ctx.managedClose();
			}
		}
	
public voidbeforeCompletion()

		log.trace("transaction before completion callback");

		boolean flush;
		try {
			flush = !ctx.isFlushModeNever() &&
			        ctx.isFlushBeforeCompletionEnabled() && 
			        !JTAHelper.isRollback( transaction.getStatus() ); 
					//actually, this last test is probably unnecessary, since 
					//beforeCompletion() doesn't get called during rollback
		}
		catch (SystemException se) {
			log.error("could not determine transaction status", se);
			setRollbackOnly();
			throw new TransactionException("could not determine transaction status in beforeCompletion()", se);
		}
		
		try {
			if (flush) {
				log.trace("automatically flushing session");
				ctx.managedFlush();
			}
		}
		catch (RuntimeException re) {
			setRollbackOnly();
			throw re;
		}
		finally {
			jdbcContext.beforeTransactionCompletion(hibernateTransaction);
		}
	
private voidsetRollbackOnly()

		try {
			transaction.setRollbackOnly();
		}
		catch (SystemException se) {
			log.error("could not set transaction to rollback only", se);
		}
	
public java.lang.StringtoString()

		return CacheSynchronization.class.getName();