/** * Leaves transaction * * @throws UnifyException * - If an error occurs */ public void leave() throws UnifyException { try { sessionStack.pop(); } catch (RuntimeException e) { throw new UnifyException(e, UnifyCoreErrorConstants.TRANSACTION_IS_ALREADY_COMPLETED); } // Assumes transaction has ended when session stack is empty if (sessionStack.isEmpty()) { commit(true); databaseSessions.clear(); } }
private DatabaseSession getDatabaseSession() throws UnifyException { if (!transactionsThreadLocal.get().isEmpty()) { TransactionalCall tc = transactionsThreadLocal.get().peek(); if (tc.isTransaction()) { return (DatabaseSession) transactionsThreadLocal.get().peek().getDatabaseSession(); } } throw new UnifyException(UnifyCoreErrorConstants.TRANSACTION_IS_REQUIRED); }
@Override public void endTransaction() throws UnifyException { try { transactionsThreadLocal.get().pop().leave(); if (transactionsThreadLocal.get().isEmpty()) { transactionsThreadLocal.remove(); } } catch (RuntimeException e) { throw new UnifyException(e, UnifyCoreErrorConstants.TRANSACTION_IS_ALREADY_COMPLETED); } }
switch (txnType) { case REQUIRED: if (!transactions.isEmpty() && transactions.peek().isTransaction()) { transaction = transactions.peek(); } else { transaction = new TransactionalCall(true); transaction = new TransactionalCall(true); break; case SUPPORTS: transaction = transactions.peek(); } else { transaction = new TransactionalCall(false); if (!transactions.isEmpty()) { transaction = transactions.peek(); if (!transaction.isTransaction()) { throw new UnifyException(UnifyCoreErrorConstants.TRANSACTION_IS_REQUIRED); if (!transactions.isEmpty()) { transaction = transactions.peek(); if (transaction.isTransaction()) { throw new UnifyException(UnifyCoreErrorConstants.TRANSACTION_IS_NEVER_REQUIRED); transaction = new TransactionalCall(false); transaction = new TransactionalCall(false); break;
public void commit() throws UnifyException { commit(false); }
@Override public void commit() throws UnifyException { transactionsThreadLocal.get().peek().commit(); }
@Override public void setRollback() throws UnifyException { try { transactionsThreadLocal.get().peek().setRollback(); } catch (RuntimeException e) { throw new UnifyException(e, UnifyCoreErrorConstants.TRANSACTION_IS_ALREADY_COMPLETED); } }
@Override public boolean isTransactionOpen() { if (!transactionsThreadLocal.get().isEmpty()) { TransactionalCall tc = transactionsThreadLocal.get().peek(); return tc.isTransaction(); } return false; }