public static Connection getConnection() { Connection conn = currentConnection.get(); if (conn == null) { throw new IllegalTransactionStateException("No connection is associated with the current transaction. " + "This might have ideally been caused by not properly initiating the transaction via " + "'beginTransaction'/'openConnection' methods"); } return conn; }
public static void openConnection() throws SQLException { Connection conn = currentConnection.get(); if (conn != null) { throw new IllegalTransactionStateException("A transaction is already active within the context of " + "this particular thread. Therefore, calling 'beginTransaction/openConnection' while another " + "transaction is already active is a sign of improper transaction handling"); } conn = dataSource.getConnection(); currentConnection.set(conn); }
public static void commitTransaction() { Connection conn = currentConnection.get(); if (conn == null) { throw new IllegalTransactionStateException("No connection is associated with the current transaction. " + "This might have ideally been caused by not properly initiating the transaction via " + "'beginTransaction'/'openConnection' methods"); } try { conn.commit(); } catch (SQLException e) { log.error("Error occurred while committing the transaction", e); } }
public static void rollbackTransaction() { Connection conn = currentConnection.get(); if (conn == null) { throw new IllegalTransactionStateException("No connection is associated with the current transaction. " + "This might have ideally been caused by not properly initiating the transaction via " + "'beginTransaction'/'openConnection' methods"); } try { conn.rollback(); } catch (SQLException e) { log.warn("Error occurred while roll-backing the transaction", e); } }
public static void closeConnection() { Connection conn = currentConnection.get(); if (conn == null) { throw new IllegalTransactionStateException("No connection is associated with the current transaction. " + "This might have ideally been caused by not properly initiating the transaction via " + "'beginTransaction'/'openConnection' methods"); } try { conn.close(); } catch (SQLException e) { log.warn("Error occurred while close the connection", e); } currentConnection.remove(); }
public static void beginTransaction() throws PolicyManagerDAOException { Connection conn = currentConnection.get(); if (conn != null) { throw new IllegalTransactionStateException("A transaction is already active within the context of " + "this particular thread. Therefore, calling 'beginTransaction/openConnection' while another " + "transaction is already active is a sign of improper transaction handling"); } try { conn = dataSource.getConnection(); conn.setAutoCommit(false); currentConnection.set(conn); } catch (SQLException e) { throw new PolicyManagerDAOException("Error occurred while retrieving config.datasource connection", e); } }