From 5bb9e1b18845edcbca0a1f8c2520a356a0009d73 Mon Sep 17 00:00:00 2001 From: Robin Bygrave Date: Fri, 31 Jul 2015 22:45:32 +1200 Subject: [PATCH] No effective change - format only --- .../server/transaction/JtaTransaction.java | 173 +++++++++--------- 1 file changed, 86 insertions(+), 87 deletions(-) diff --git a/src/main/java/com/avaje/ebeaninternal/server/transaction/JtaTransaction.java b/src/main/java/com/avaje/ebeaninternal/server/transaction/JtaTransaction.java index 1bdb2411b..d1b4f0f29 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/transaction/JtaTransaction.java +++ b/src/main/java/com/avaje/ebeaninternal/server/transaction/JtaTransaction.java @@ -1,112 +1,111 @@ package com.avaje.ebeaninternal.server.transaction; -import java.sql.SQLException; - import javax.persistence.PersistenceException; import javax.sql.DataSource; import javax.transaction.Status; import javax.transaction.UserTransaction; +import java.sql.SQLException; /** * Jta based transaction. */ public class JtaTransaction extends JdbcTransaction { - private final UserTransaction userTransaction; + private final UserTransaction userTransaction; - private boolean commmitted; + private boolean commmitted; - private boolean newTransaction; + private boolean newTransaction; - /** - * Create the JtaTransaction. - */ - public JtaTransaction(String id, boolean explicit, UserTransaction utx, DataSource ds, TransactionManager manager) { - super(id, explicit, null, manager); - userTransaction = utx; + /** + * Create the JtaTransaction. + */ + public JtaTransaction(String id, boolean explicit, UserTransaction utx, DataSource ds, TransactionManager manager) { + super(id, explicit, null, manager); + userTransaction = utx; + try { + newTransaction = userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION; + if (newTransaction) { + userTransaction.begin(); + } + } catch (Exception e) { + throw new PersistenceException(e); + } + + try { + // Open JDBC Connection + this.connection = ds.getConnection(); + if (connection == null) { + throw new PersistenceException("The DataSource returned a null connection."); + } + if (connection.getAutoCommit()) { + connection.setAutoCommit(false); + } + + } catch (SQLException e) { + throw new PersistenceException(e); + } + } + + /** + * Commit the transaction. + */ + public void commit() { + if (commmitted) { + throw new PersistenceException("This transaction has already been committed."); + } + try { + try { + if (newTransaction) { + userTransaction.commit(); + } + notifyCommit(); + } finally { + close(); + } + } catch (Exception e) { + throw new PersistenceException(e); + } + commmitted = true; + } + + public void rollback() { + rollback(null); + } + + /** + * Rollback the transaction. + */ + public void rollback(Throwable e) { + if (!commmitted) { + try { try { - newTransaction = userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION; + if (userTransaction != null) { if (newTransaction) { - userTransaction.begin(); + userTransaction.rollback(); + } else { + userTransaction.setRollbackOnly(); } - } catch (Exception e) { - throw new PersistenceException(e); - } - - try { - // Open JDBC Connection - this.connection = ds.getConnection(); - if (connection == null) { - throw new PersistenceException("The DataSource returned a null connection."); - } - if (connection.getAutoCommit()) { - connection.setAutoCommit(false); - } - - } catch (SQLException e) { - throw new PersistenceException(e); + } + notifyRollback(e); + } finally { + closeConnection(); } + } catch (Exception ex) { + throw new PersistenceException(ex); + } } - /** - * Commit the transaction. - */ - public void commit() { - if (commmitted) { - throw new PersistenceException("This transaction has already been committed."); - } - try { - try { - if (newTransaction) { - userTransaction.commit(); - } - notifyCommit(); - } finally { - close(); - } - } catch (Exception e) { - throw new PersistenceException(e); - } - commmitted = true; - } + } - public void rollback() { - rollback(null); - } - - /** - * Rollback the transaction. - */ - public void rollback(Throwable e) { - if (!commmitted) { - try { - try { - if (userTransaction != null) { - if (newTransaction) { - userTransaction.rollback(); - } else { - userTransaction.setRollbackOnly(); - } - } - notifyRollback(e); - } finally { - closeConnection(); - } - } catch (Exception ex) { - throw new PersistenceException(ex); - } - } - - } - - /** - * Close the underlying connection. - */ - private void closeConnection() throws SQLException { - if (connection != null) { - connection.close(); - connection = null; - } + /** + * Close the underlying connection. + */ + private void closeConnection() throws SQLException { + if (connection != null) { + connection.close(); + connection = null; } + } }