[hibernate-commits] Hibernate SVN: r14894 - core/branches/Branch_3_2/src/org/hibernate/transaction.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Jul 8 11:37:43 EDT 2008


Author: steve.ebersole at jboss.com
Date: 2008-07-08 11:37:42 -0400 (Tue, 08 Jul 2008)
New Revision: 14894

Modified:
   core/branches/Branch_3_2/src/org/hibernate/transaction/JTATransaction.java
Log:
code cleanup

Modified: core/branches/Branch_3_2/src/org/hibernate/transaction/JTATransaction.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/transaction/JTATransaction.java	2008-07-08 15:36:59 UTC (rev 14893)
+++ core/branches/Branch_3_2/src/org/hibernate/transaction/JTATransaction.java	2008-07-08 15:37:42 UTC (rev 14894)
@@ -51,7 +51,7 @@
  */
 public class JTATransaction implements Transaction {
 
-	private static final Log log = LogFactory.getLog(JTATransaction.class);
+	private static final Log log = LogFactory.getLog( JTATransaction.class );
 
 	private final JDBCContext jdbcContext;
 	private final TransactionFactory.Context transactionContext;
@@ -63,35 +63,35 @@
 	private boolean commitSucceeded;
 	private boolean callback;
 
-    public JTATransaction(
+	public JTATransaction(
 			UserTransaction userTransaction,
 			JDBCContext jdbcContext,
 			TransactionFactory.Context transactionContext) {
 		this.jdbcContext = jdbcContext;
 		this.transactionContext = transactionContext;
-        this.userTransaction = userTransaction;
+		this.userTransaction = userTransaction;
 	}
 
 	public void begin() throws HibernateException {
-		if (begun) {
+		if ( begun ) {
 			return;
 		}
-		if (commitFailed) {
-			throw new TransactionException("cannot re-start transaction after failed commit");
+		if ( commitFailed ) {
+			throw new TransactionException( "cannot re-start transaction after failed commit" );
 		}
-		
-		log.debug("begin");
 
+		log.debug( "begin" );
+
 		try {
 			newTransaction = userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION;
-			if (newTransaction) {
+			if ( newTransaction ) {
 				userTransaction.begin();
-				log.debug("Began a new JTA transaction");
+				log.debug( "Began a new JTA transaction" );
 			}
 		}
-		catch (Exception e) {
-			log.error("JTA transaction begin failed", e);
-			throw new TransactionException("JTA transaction begin failed", e);
+		catch ( Exception e ) {
+			log.error( "JTA transaction begin failed", e );
+			throw new TransactionException( "JTA transaction begin failed", e );
 		}
 
 		/*if (newTransaction) {
@@ -104,10 +104,10 @@
 		boolean synchronization = jdbcContext.registerSynchronizationIfPossible();
 
 		if ( !newTransaction && !synchronization ) {
-			log.warn("You should set hibernate.transaction.manager_lookup_class if cache is enabled");
+			log.warn( "You should set hibernate.transaction.manager_lookup_class if cache is enabled" );
 		}
 
-		if (!synchronization) {
+		if ( !synchronization ) {
 			//if we could not register a synchronization,
 			//do the before/after completion callbacks
 			//ourself (but we need to let jdbcContext
@@ -119,40 +119,40 @@
 
 		begun = true;
 		commitSucceeded = false;
-		
-		jdbcContext.afterTransactionBegin(this);
+
+		jdbcContext.afterTransactionBegin( this );
 	}
 
 	public void commit() throws HibernateException {
-		if (!begun) {
-			throw new TransactionException("Transaction not successfully started");
+		if ( !begun ) {
+			throw new TransactionException( "Transaction not successfully started" );
 		}
 
-		log.debug("commit");
+		log.debug( "commit" );
 
 		boolean flush = !transactionContext.isFlushModeNever()
-		        && ( callback || !transactionContext.isFlushBeforeCompletionEnabled() );
+				&& ( callback || !transactionContext.isFlushBeforeCompletionEnabled() );
 
-		if (flush) {
+		if ( flush ) {
 			transactionContext.managedFlush(); //if an exception occurs during flush, user must call rollback()
 		}
 
-		if (callback && newTransaction) {
-			jdbcContext.beforeTransactionCompletion(this);
+		if ( callback && newTransaction ) {
+			jdbcContext.beforeTransactionCompletion( this );
 		}
 
 		closeIfRequired();
 
-		if (newTransaction) {
+		if ( newTransaction ) {
 			try {
 				userTransaction.commit();
 				commitSucceeded = true;
-				log.debug("Committed JTA UserTransaction");
+				log.debug( "Committed JTA UserTransaction" );
 			}
-			catch (Exception e) {
+			catch ( Exception e ) {
 				commitFailed = true; // so the transaction is already rolled back, by JTA spec
-				log.error("JTA commit failed", e);
-				throw new TransactionException("JTA commit failed: ", e);
+				log.error( "JTA commit failed", e );
+				throw new TransactionException( "JTA commit failed: ", e );
 			}
 			finally {
 				afterCommitRollback();
@@ -169,11 +169,11 @@
 	}
 
 	public void rollback() throws HibernateException {
-		if (!begun && !commitFailed) {
-			throw new TransactionException("Transaction not successfully started");
+		if ( !begun && !commitFailed ) {
+			throw new TransactionException( "Transaction not successfully started" );
 		}
 
-		log.debug("rollback");
+		log.debug( "rollback" );
 
 		/*if (!synchronization && newTransaction && !commitFailed) {
 			jdbcContext.beforeTransactionCompletion(this);
@@ -182,26 +182,26 @@
 		try {
 			closeIfRequired();
 		}
-		catch (Exception e) {
-			log.error("could not close session during rollback", e);
+		catch ( Exception e ) {
+			log.error( "could not close session during rollback", e );
 			//swallow it, and continue to roll back JTA transaction
 		}
 
 		try {
-			if (newTransaction) {
-				if (!commitFailed) {
+			if ( newTransaction ) {
+				if ( !commitFailed ) {
 					userTransaction.rollback();
-					log.debug("Rolled back JTA UserTransaction");
+					log.debug( "Rolled back JTA UserTransaction" );
 				}
 			}
 			else {
 				userTransaction.setRollbackOnly();
-				log.debug("set JTA UserTransaction to rollback only");
+				log.debug( "set JTA UserTransaction to rollback only" );
 			}
 		}
-		catch (Exception e) {
-			log.error("JTA rollback failed", e);
-			throw new TransactionException("JTA rollback failed", e);
+		catch ( Exception e ) {
+			log.error( "JTA rollback failed", e );
+			throw new TransactionException( "JTA rollback failed", e );
 		}
 		finally {
 			afterCommitRollback();
@@ -211,28 +211,28 @@
 	private static final int NULL = Integer.MIN_VALUE;
 
 	private void afterCommitRollback() throws TransactionException {
-		
+
 		begun = false;
 
-		if (callback) { // this method is a noop if there is a Synchronization!
+		if ( callback ) { // this method is a noop if there is a Synchronization!
 
-			if (!newTransaction) {
-				log.warn("You should set hibernate.transaction.manager_lookup_class if cache is enabled");
+			if ( !newTransaction ) {
+				log.warn( "You should set hibernate.transaction.manager_lookup_class if cache is enabled" );
 			}
-			int status=NULL;
+			int status = NULL;
 			try {
 				status = userTransaction.getStatus();
 			}
-			catch (Exception e) {
-				log.error("Could not determine transaction status after commit", e);
-				throw new TransactionException("Could not determine transaction status after commit", e);
+			catch ( Exception e ) {
+				log.error( "Could not determine transaction status after commit", e );
+				throw new TransactionException( "Could not determine transaction status after commit", e );
 			}
 			finally {
 				/*if (status!=Status.STATUS_COMMITTED && status!=Status.STATUS_ROLLEDBACK) {
 					log.warn("Transaction not complete - you should set hibernate.transaction.manager_lookup_class if cache is enabled");
 					//throw exception??
 				}*/
-				jdbcContext.afterTransactionCompletion(status==Status.STATUS_COMMITTED, this);
+				jdbcContext.afterTransactionCompletion( status == Status.STATUS_COMMITTED, this );
 			}
 
 		}
@@ -247,15 +247,15 @@
 		try {
 			status = userTransaction.getStatus();
 		}
-		catch (SystemException se) {
-			log.error("Could not determine transaction status", se);
-			throw new TransactionException("Could not determine transaction status", se);
+		catch ( SystemException se ) {
+			log.error( "Could not determine transaction status", se );
+			throw new TransactionException( "Could not determine transaction status", se );
 		}
-		if (status==Status.STATUS_UNKNOWN) {
-			throw new TransactionException("Could not determine transaction status");
+		if ( status == Status.STATUS_UNKNOWN ) {
+			throw new TransactionException( "Could not determine transaction status" );
 		}
 		else {
-			return JTAHelper.isRollback(status);
+			return JTAHelper.isRollback( status );
 		}
 	}
 
@@ -267,48 +267,50 @@
 		try {
 			status = userTransaction.getStatus();
 		}
-		catch (SystemException se) {
-			log.error("Could not determine transaction status", se);
-			throw new TransactionException("Could not determine transaction status: ", se);
+		catch ( SystemException se ) {
+			log.error( "Could not determine transaction status", se );
+			throw new TransactionException( "Could not determine transaction status: ", se );
 		}
-		if (status==Status.STATUS_UNKNOWN) {
-			throw new TransactionException("Could not determine transaction status");
+		if ( status == Status.STATUS_UNKNOWN ) {
+			throw new TransactionException( "Could not determine transaction status" );
 		}
 		else {
-			return status==Status.STATUS_COMMITTED;
+			return status == Status.STATUS_COMMITTED;
 		}
 	}
-	
+
 	public boolean isActive() throws TransactionException {
 
-		if (!begun || commitFailed || commitSucceeded) return false;
+		if ( !begun || commitFailed || commitSucceeded ) {
+			return false;
+		}
 
 		final int status;
 		try {
 			status = userTransaction.getStatus();
 		}
-		catch (SystemException se) {
-			log.error("Could not determine transaction status", se);
-			throw new TransactionException("Could not determine transaction status: ", se);
+		catch ( SystemException se ) {
+			log.error( "Could not determine transaction status", se );
+			throw new TransactionException( "Could not determine transaction status: ", se );
 		}
-		if (status==Status.STATUS_UNKNOWN) {
-			throw new TransactionException("Could not determine transaction status");
+		if ( status == Status.STATUS_UNKNOWN ) {
+			throw new TransactionException( "Could not determine transaction status" );
 		}
 		else {
-			return status==Status.STATUS_ACTIVE;
+			return status == Status.STATUS_ACTIVE;
 		}
 	}
 
 	public void registerSynchronization(Synchronization sync) throws HibernateException {
-		if (getTransactionManager()==null) {
-			throw new IllegalStateException("JTA TransactionManager not available");
+		if ( getTransactionManager() == null ) {
+			throw new IllegalStateException( "JTA TransactionManager not available" );
 		}
 		else {
 			try {
-				getTransactionManager().getTransaction().registerSynchronization(sync);
+				getTransactionManager().getTransaction().registerSynchronization( sync );
 			}
-			catch (Exception e) {
-				throw new TransactionException("could not register synchronization", e);
+			catch ( Exception e ) {
+				throw new TransactionException( "could not register synchronization", e );
 			}
 		}
 	}
@@ -318,8 +320,8 @@
 	}
 
 	private void closeIfRequired() throws HibernateException {
-		boolean close = callback && 
-				transactionContext.shouldAutoClose() && 
+		boolean close = callback &&
+				transactionContext.shouldAutoClose() &&
 				!transactionContext.isClosed();
 		if ( close ) {
 			transactionContext.managedClose();
@@ -328,10 +330,10 @@
 
 	public void setTimeout(int seconds) {
 		try {
-			userTransaction.setTransactionTimeout(seconds);
+			userTransaction.setTransactionTimeout( seconds );
 		}
-		catch (SystemException se) {
-			throw new TransactionException("could not set transaction timeout", se);
+		catch ( SystemException se ) {
+			throw new TransactionException( "could not set transaction timeout", se );
 		}
 	}
 




More information about the hibernate-commits mailing list