FileDocCategorySizeDatePackage
DummyTransaction.javaAPI DocHibernate 3.2.53790Fri Oct 14 18:29:04 BST 2005org.hibernate.test.tm

DummyTransaction

public class DummyTransaction extends Object implements Transaction
author
Gavin King

Fields Summary
int
status
private Connection
connection
List
synchronizations
private DummyTransactionManager
transactionManager
Constructors Summary
DummyTransaction(DummyTransactionManager transactionManager)

	
	  
		status = Status.STATUS_NO_TRANSACTION;
		this.transactionManager = transactionManager;
	
Methods Summary
public voidbegin()

		try {
			connection = transactionManager.connections.getConnection();
		}
		catch (SQLException sqle) {
			
			sqle.printStackTrace();
			throw new SystemException(sqle.toString());
		}
		status = Status.STATUS_ACTIVE;
	
public voidcommit()

		
		if (status == Status.STATUS_MARKED_ROLLBACK) {
			rollback();
		}
		else {
			status = Status.STATUS_PREPARING;
			
			for ( int i=0; i<synchronizations.size(); i++ ) {
				Synchronization s = (Synchronization) synchronizations.get(i);
				s.beforeCompletion();
			}
			
			status = Status.STATUS_COMMITTING;
			
			try {
				connection.commit();
				connection.close();
			}
			catch (SQLException sqle) {
				status = Status.STATUS_UNKNOWN;
				throw new SystemException();
			}
			
			status = Status.STATUS_COMMITTED;

			for ( int i=0; i<synchronizations.size(); i++ ) {
				Synchronization s = (Synchronization) synchronizations.get(i);
				s.afterCompletion(status);
			}
			
			//status = Status.STATUS_NO_TRANSACTION;
			transactionManager.endCurrent(this);
		}

	
public booleandelistResource(javax.transaction.xa.XAResource arg0, int arg1)

		// TODO Auto-generated method stub
		return false;
	
public booleanenlistResource(javax.transaction.xa.XAResource arg0)

		// TODO Auto-generated method stub
		return false;
	
public java.sql.ConnectiongetConnection()

		return connection;
	
public intgetStatus()

		return status;
	
public voidregisterSynchronization(javax.transaction.Synchronization sync)

		synchronizations.add(sync);
	
public voidrollback()


		status = Status.STATUS_ROLLING_BACK;

// Synch.beforeCompletion() should *not* be called for rollbacks
//		for ( int i=0; i<synchronizations.size(); i++ ) {
//			Synchronization s = (Synchronization) synchronizations.get(i);
//			s.beforeCompletion();
//		}
		
		status = Status.STATUS_ROLLEDBACK;
		
		try {
			connection.rollback();
			connection.close();
		}
		catch (SQLException sqle) {
			status = Status.STATUS_UNKNOWN;
			throw new SystemException();
		}
		
		for ( int i=0; i<synchronizations.size(); i++ ) {
			Synchronization s = (Synchronization) synchronizations.get(i);
			s.afterCompletion(status);
		}
		
		//status = Status.STATUS_NO_TRANSACTION;
		transactionManager.endCurrent(this);
	
voidsetConnection(java.sql.Connection connection)

		this.connection = connection;
	
public voidsetRollbackOnly()

		status = Status.STATUS_MARKED_ROLLBACK;