/** * PUBLIC: * Return if the session is currently in the progress of a database transaction. * Because nested transactions are allowed check if the transaction mutex has been aquired. */ public boolean isInTransaction() { return getTransactionMutex().isAcquired(); }
/** * INTERNAL: * This is internal to the uow, transactions should not be used explictly in a uow. * The uow shares its parents transactions. */ public void commitTransaction() throws DatabaseException { if (this.shouldTerminateTransaction || getParent().getTransactionMutex().isNested()){ super.commitTransaction(); } }
/** * INTERNAL: * This is internal to the uow, transactions should not be used explictly in a uow. * The uow shares its parents transactions. */ public void rollbackTransaction() throws DatabaseException { if (this.shouldTerminateTransaction || getParent().getTransactionMutex().isNested()){ super.rollbackTransaction(); }else{ //rollback called which means txn failed. //but rollback was stopped by entitytransaction which means the //transaction will want to call release later. Make sure release //will rollback transaction. setWasTransactionBegunPrematurely(true); } }
getTransactionMutex().setActiveThread(Thread.currentThread()); getTransactionMutex().acquire(); if (!getTransactionMutex().isNested()) { getEventManager().preBeginTransaction(); basicBeginTransaction();
/** * PUBLIC: * Commit the active database transaction. * This allows a group of database modification to be commited or rolledback as a unit. * All writes/deletes will be sent to the database be will not be visible to other users until commit. * Although databases do not allow nested transaction, * TopLink supports nesting through only committing to the database on the outer commit. * * @exception DatabaseException most databases validate changes as they are done, * normally errors do not occur on commit unless the disk fails or the connection is lost. * @exception ConcurrencyException if this session is not within a transaction. */ public void commitTransaction() throws DatabaseException, ConcurrencyException { // Release mutex and call subclass specific commit. if (!getTransactionMutex().isNested()) { getEventManager().preCommitTransaction(); basicCommitTransaction(); getEventManager().postCommitTransaction(); } // This MUST not be in a try catch or finally as if the commit failed the transaction is still open. getTransactionMutex().release(); // If there is no db transaction in progress // if there is an active external transaction // which was started internally - it should be committed internally, too. if (!isInTransaction()) { commitExternalTransaction(); } }
/** * PUBLIC: * Rollback the active database transaction. * This allows a group of database modification to be commited or rolledback as a unit. * All writes/deletes will be sent to the database be will not be visible to other users until commit. * Although databases do not allow nested transaction, * TopLink supports nesting through only committing to the database on the outer commit. * * @exception DatabaseException if the database connection is lost or the rollback fails. * @exception ConcurrencyException if this session is not within a transaction. */ public void rollbackTransaction() throws DatabaseException, ConcurrencyException { // Ensure release of mutex and call subclass specific release. try { if (!getTransactionMutex().isNested()) { getEventManager().preRollbackTransaction(); basicRollbackTransaction(); getEventManager().postRollbackTransaction(); } } finally { getTransactionMutex().release(); // If there is no db transaction in progress // if there is an active external transaction // which was started internally - it should be rolled back internally, too. if (!isInTransaction()) { rollbackExternalTransaction(); } } }
/** * PROTECTED: * Used in commit and commit-like methods to commit * internally started external transaction */ protected boolean commitInternallyStartedExternalTransaction() { boolean committed = false; if (!getParent().isInTransaction() || (wasTransactionBegunPrematurely() && (getParent().getTransactionMutex().getDepth() == 1))) { committed = getParent().commitExternalTransaction(); } return committed; }
getSession().getTransactionMutex().setActiveThread(Thread.currentThread());