List of usage examples for javax.transaction Status STATUS_COMMITTING
int STATUS_COMMITTING
To view the source code for javax.transaction Status STATUS_COMMITTING.
Click Source Link
From source file:org.apache.ojb.odmg.TransactionImpl.java
/** * Determine whether the transaction is open or not. A transaction is open if * a call has been made to <code>begin</code> , but a subsequent call to * either <code>commit</code> or <code>abort</code> has not been made. * @return True if the transaction is open, otherwise false. *//*from www . ja v a 2s . com*/ public boolean isOpen() { return (getStatus() == Status.STATUS_ACTIVE || getStatus() == Status.STATUS_MARKED_ROLLBACK || getStatus() == Status.STATUS_PREPARED || getStatus() == Status.STATUS_PREPARING || getStatus() == Status.STATUS_COMMITTING); }
From source file:org.apache.ojb.odmg.TransactionImpl.java
/** * Commit and close the transaction. Calling <code>commit</code> commits to * the database all persistent object modifications within the transaction and * releases any locks held by the transaction. A persistent object * modification is an update of any field of an existing persistent object, or * an update or creation of a new named object in the database. If a * persistent object modification results in a reference from an existing * persistent object to a transient object, the transient object is moved to * the database, and all references to it updated accordingly. Note that the * act of moving a transient object to the database may create still more * persistent references to transient objects, so its referents must be * examined and moved as well. This process continues until the database * contains no references to transient objects, a condition that is guaranteed * as part of transaction commit. Committing a transaction does not remove * from memory transient objects created during the transaction. * * The updateObjectList contains a list of all objects for which this transaction * has write privledge to. We need to update these objects. *///from ww w . j av a 2s. c o m public void commit() { checkOpen(); try { prepareCommit(); checkForCommit(); txStatus = Status.STATUS_COMMITTING; if (log.isDebugEnabled()) log.debug("Commit transaction " + this); // now do real commit on broker if (hasBroker()) getBroker().commitTransaction(); // Now, we notify everything the commit is done. performTransactionAwareAfterCommit(); doClose(); txStatus = Status.STATUS_COMMITTED; } catch (Exception ex) { log.error("Error while commit objects, do abort tx " + this + ", " + ex.getMessage(), ex); txStatus = Status.STATUS_MARKED_ROLLBACK; abort(); if (!(ex instanceof ODMGRuntimeException)) { throw new TransactionAbortedExceptionOJB("Can't commit objects: " + ex.getMessage(), ex); } else { throw (ODMGRuntimeException) ex; } } }
From source file:org.bytesoft.bytejta.TransactionRecoveryImpl.java
private void recoverCoordinator(Transaction transaction) throws CommitRequiredException, RollbackRequiredException, SystemException { switch (transaction.getTransactionStatus()) { case Status.STATUS_ACTIVE: case Status.STATUS_MARKED_ROLLBACK: case Status.STATUS_PREPARING: case Status.STATUS_ROLLING_BACK: case Status.STATUS_UNKNOWN: transaction.recoveryRollback();// ww w . jav a 2s .c o m transaction.forgetQuietly(); break; case Status.STATUS_PREPARED: case Status.STATUS_COMMITTING: transaction.recoveryCommit(); transaction.forgetQuietly(); break; case Status.STATUS_COMMITTED: case Status.STATUS_ROLLEDBACK: transaction.forgetQuietly(); break; default: logger.debug("Current transaction has already been completed."); } }
From source file:org.bytesoft.bytejta.TransactionRecoveryImpl.java
private void recoverParticipant(Transaction transaction) throws CommitRequiredException, RollbackRequiredException, SystemException { TransactionImpl transactionImpl = (TransactionImpl) transaction; switch (transaction.getTransactionStatus()) { case Status.STATUS_PREPARED: case Status.STATUS_COMMITTING: break;/* w w w.ja va 2 s . c o m*/ case Status.STATUS_COMMITTED: case Status.STATUS_ROLLEDBACK: break; case Status.STATUS_ACTIVE: case Status.STATUS_MARKED_ROLLBACK: case Status.STATUS_PREPARING: case Status.STATUS_UNKNOWN: case Status.STATUS_ROLLING_BACK: default: transactionImpl.recoveryRollback(); transactionImpl.forgetQuietly(); } }
From source file:org.bytesoft.bytetcc.CompensableTransactionImpl.java
public synchronized void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException { CompensableLogger compensableLogger = this.beanFactory.getCompensableLogger(); this.transactionContext.setCompensating(true); this.transactionStatus = Status.STATUS_COMMITTING; compensableLogger.updateTransaction(this.getTransactionArchive()); SystemException systemEx = null; try {//from w ww.j a va 2 s. c o m this.fireNativeParticipantConfirm(); } catch (SystemException ex) { systemEx = ex; logger.info("{}| confirm native branchs failed!", ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ex); } catch (RuntimeException ex) { systemEx = new SystemException(ex.getMessage()); logger.info("{}| confirm native branchs failed!", ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ex); } try { this.fireRemoteParticipantConfirm(); } catch (HeuristicMixedException ex) { logger.info("{}| confirm remote branchs failed!", ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ex); throw ex; } catch (HeuristicRollbackException ex) { logger.info("{}| confirm remote branchs failed!", ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ex); throw ex; } catch (SystemException ex) { logger.info("{}| confirm remote branchs failed!", ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ex); throw ex; } catch (RuntimeException ex) { logger.info("{}| confirm remote branchs failed!", ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ex); throw ex; } if (systemEx != null) { throw systemEx; } else { this.transactionStatus = Status.STATUS_COMMITTED; compensableLogger.updateTransaction(this.getTransactionArchive()); logger.info("{}| compensable transaction committed!", ByteUtils.byteArrayToString(transactionContext.getXid().getGlobalTransactionId())); } }
From source file:org.bytesoft.bytetcc.CompensableTransactionImpl.java
public void onCommitSuccess(TransactionXid xid) { CompensableLogger compensableLogger = this.beanFactory.getCompensableLogger(); if (this.transactionContext.isCompensating()) { if (this.positive == null) { // ignore } else if (this.positive) { this.archive.setConfirmed(true); logger.info("{}| confirm: identifier= {}, resourceKey= {}, resourceXid= {}.", ByteUtils.byteArrayToString(transactionContext.getXid().getGlobalTransactionId()), ByteUtils.byteArrayToString(this.archive.getIdentifier().getGlobalTransactionId()), this.archive.getCompensableResourceKey(), this.archive.getCompensableXid()); } else {// ww w.j a va 2s . co m this.archive.setCancelled(true); logger.info("{}| cancel: identifier= {}, resourceKey= {}, resourceXid= {}.", ByteUtils.byteArrayToString(transactionContext.getXid().getGlobalTransactionId()), ByteUtils.byteArrayToString(this.archive.getIdentifier().getGlobalTransactionId()), this.archive.getCompensableResourceKey(), this.archive.getCompensableXid()); } compensableLogger.updateCompensable(this.archive); } else if (this.transactionContext.isCoordinator()) { for (Iterator<CompensableArchive> itr = this.transientArchiveList.iterator(); itr.hasNext();) { CompensableArchive compensableArchive = itr.next(); itr.remove(); // remove compensableArchive.setTried(true); // compensableLogger.updateCompensable(compensableArchive); logger.info("{}| try: identifier= {}, resourceKey= {}, resourceXid= {}.", ByteUtils.byteArrayToString(transactionContext.getXid().getGlobalTransactionId()), ByteUtils.byteArrayToString(compensableArchive.getIdentifier().getGlobalTransactionId()), compensableArchive.getTransactionResourceKey(), compensableArchive.getTransactionXid()); } TransactionArchive transactionArchive = this.getTransactionArchive(); transactionArchive.setCompensableStatus(Status.STATUS_COMMITTING); compensableLogger.updateTransaction(transactionArchive); logger.info("{}| try completed.", ByteUtils.byteArrayToString(transactionContext.getXid().getGlobalTransactionId())); } else { for (Iterator<CompensableArchive> itr = this.transientArchiveList.iterator(); itr.hasNext();) { CompensableArchive compensableArchive = itr.next(); itr.remove(); // remove compensableArchive.setTried(true); compensableLogger.updateCompensable(compensableArchive); logger.info("{}| try: identifier= {}, resourceKey= {}, resourceXid= {}.", ByteUtils.byteArrayToString(transactionContext.getXid().getGlobalTransactionId()), ByteUtils.byteArrayToString(compensableArchive.getIdentifier().getGlobalTransactionId()), compensableArchive.getTransactionResourceKey(), compensableArchive.getTransactionXid()); } } }
From source file:org.bytesoft.bytetcc.CompensableTransactionImpl.java
public synchronized void recoveryCommit() throws CommitRequiredException, SystemException { CompensableLogger compensableLogger = this.beanFactory.getCompensableLogger(); this.transactionContext.setCompensating(true); this.transactionStatus = Status.STATUS_COMMITTING; compensableLogger.updateTransaction(this.getTransactionArchive()); SystemException systemEx = null; try {//from ww w . ja v a 2 s .c o m this.fireNativeParticipantRecoveryConfirm(); } catch (SystemException ex) { systemEx = ex; logger.info("{}| recovery-confirm native branchs failed!", ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ex); } catch (RuntimeException ex) { systemEx = new SystemException(ex.getMessage()); logger.info("{}| recovery-confirm native branchs failed!", ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ex); } try { this.fireRemoteParticipantRecoveryConfirm(); } catch (HeuristicMixedException ex) { logger.info("{}| recovery-confirm remote branchs failed!", ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ex); throw new SystemException(ex.getMessage()); } catch (HeuristicRollbackException ex) { logger.info("{}| recovery-confirm remote branchs failed!", ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ex); throw new SystemException(ex.getMessage()); } catch (SystemException ex) { logger.info("{}| recovery-confirm remote branchs failed!", ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ex); throw ex; } catch (RuntimeException ex) { logger.info("{}| recovery-confirm remote branchs failed!", ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ex); throw new SystemException(ex.getMessage()); } if (systemEx != null) { throw systemEx; } else { this.transactionStatus = Status.STATUS_COMMITTED; compensableLogger.updateTransaction(this.getTransactionArchive()); logger.info("{}| compensable transaction recovery committed!", ByteUtils.byteArrayToString(transactionContext.getXid().getGlobalTransactionId())); } }
From source file:org.bytesoft.bytetcc.TransactionRecoveryImpl.java
private void recoverStatusIfNecessary(Transaction transaction) { CompensableTransactionImpl compensable = (CompensableTransactionImpl) transaction; List<CompensableArchive> archiveList = compensable.getCompensableArchiveList(); XAResourceDeserializer resourceDeserializer = this.beanFactory.getResourceDeserializer(); CompensableLogger compensableLogger = this.beanFactory.getCompensableLogger(); Map<TransactionBranchKey, Boolean> triedMap = new HashMap<TransactionBranchKey, Boolean>(); for (int i = 0; i < archiveList.size(); i++) { CompensableArchive archive = archiveList.get(i); if (archive.isTried()) { switch (transaction.getTransactionStatus()) { case Status.STATUS_ACTIVE: case Status.STATUS_MARKED_ROLLBACK: case Status.STATUS_PREPARING: case Status.STATUS_ROLLING_BACK: case Status.STATUS_UNKNOWN: transaction.setTransactionStatus(Status.STATUS_PREPARED); transaction.getTransactionContext().setCompensating(true); compensableLogger.updateTransaction(compensable.getTransactionArchive()); break; case Status.STATUS_PREPARED: case Status.STATUS_COMMITTING: case Status.STATUS_COMMITTED: case Status.STATUS_ROLLEDBACK: default: // ignore }//from w w w . j a v a 2s. com } else { Xid transactionXid = archive.getTransactionXid(); String resourceKey = archive.getTransactionResourceKey(); TransactionBranchKey recordKey = new TransactionBranchKey(); recordKey.xid = transactionXid; recordKey.resource = resourceKey; if (StringUtils.isBlank(resourceKey)) { logger.warn( "There is no valid resource participated in the trying branch transaction, the status of the branch transaction is unknown!"); } else if (triedMap.containsKey(recordKey)) { Boolean tried = triedMap.get(recordKey); if (Boolean.TRUE.equals(tried)) { transaction.setTransactionStatus(Status.STATUS_COMMITTING); // TODO } else { transaction.setTransactionStatus(Status.STATUS_MARKED_ROLLBACK); } transaction.getTransactionContext().setCompensating(true); compensableLogger.updateTransaction(compensable.getTransactionArchive()); } else { XAResource xares = resourceDeserializer.deserialize(resourceKey); if (RecoveredResource.class.isInstance(xares)) { RecoveredResource resource = (RecoveredResource) xares; try { resource.recoverable(archive.getTransactionXid()); archive.setTried(true); triedMap.put(recordKey, Boolean.TRUE); transaction.setTransactionStatus(Status.STATUS_COMMITTING); // TODO transaction.getTransactionContext().setCompensating(true); compensableLogger.updateTransaction(compensable.getTransactionArchive()); } catch (XAException xaex) { switch (xaex.errorCode) { case XAException.XAER_NOTA: triedMap.put(recordKey, Boolean.FALSE); transaction.setTransactionStatus(Status.STATUS_MARKED_ROLLBACK); transaction.getTransactionContext().setCompensating(true); compensableLogger.updateTransaction(compensable.getTransactionArchive()); break; case XAException.XAER_RMERR: logger.warn( "The database table 'bytejta' cannot found, the status of the trying branch transaction is unknown!"); break; case XAException.XAER_RMFAIL: logger.error("Error occurred while recovering the branch transaction service: {}", ByteUtils.byteArrayToString(transactionXid.getGlobalTransactionId()), xaex); break; default: logger.error( "Illegal state, the status of the trying branch transaction is unknown!"); } } } else { logger.error("Illegal resources, the status of the trying branch transaction is unknown!"); } } } // end-else-if (archive.isTried()) } // end-for }
From source file:org.bytesoft.bytetcc.TransactionRecoveryImpl.java
public synchronized void recoverCoordinator(Transaction transaction) throws CommitRequiredException, RollbackRequiredException, SystemException { switch (transaction.getTransactionStatus()) { case Status.STATUS_ACTIVE: case Status.STATUS_MARKED_ROLLBACK: case Status.STATUS_PREPARING: case Status.STATUS_ROLLING_BACK: case Status.STATUS_UNKNOWN: transaction.recoveryRollback();// w w w. j av a2 s. c o m transaction.recoveryForget(); break; case Status.STATUS_PREPARED: case Status.STATUS_COMMITTING: transaction.recoveryCommit(); transaction.recoveryForget(); break; case Status.STATUS_COMMITTED: case Status.STATUS_ROLLEDBACK: default: // ignore } }
From source file:org.castor.persist.AbstractTransactionContext.java
/** * {@inheritDoc}// w w w . j a va 2 s.c o m * @see org.castor.persist.TransactionContext#commit() */ public final synchronized void commit() throws TransactionAbortedException { // Never commit transaction that has been marked for rollback if (_status == Status.STATUS_MARKED_ROLLBACK) { throw new TransactionAbortedException("persist.markedRollback"); } if (_status != Status.STATUS_PREPARED) { throw new IllegalStateException(Messages.message("persist.missingPrepare")); } try { _status = Status.STATUS_COMMITTING; // Go through all the connections opened in this transaction, // commit and close them one by one. commitConnections(); } catch (Exception except) { // Any error that happens, we're going to rollback the transaction. _status = Status.STATUS_MARKED_ROLLBACK; throw new TransactionAbortedException(Messages.format("persist.nested", except), except); } // Assuming all went well in the connection department, // no deadlocks, etc. clean all the transaction locks with // regards to the persistence engine. Collection readWriteObjects = _tracker.getReadWriteObjects(); Iterator it = readWriteObjects.iterator(); while (it.hasNext()) { Object toCommit = it.next(); ClassMolder molder = _tracker.getMolderForObject(toCommit); LockEngine engine = molder.getLockEngine(); OID oid = _tracker.getOIDForObject(toCommit); if (_tracker.isDeleted(toCommit)) { // Object has been deleted inside transaction, // engine must forget about it. engine.forgetObject(this, oid); } else { // Object has been created/accessed inside the // transaction, release its lock. if (_tracker.isUpdateCacheNeeded(toCommit)) { engine.updateCache(this, oid, toCommit); } engine.releaseLock(this, oid); } // Call our release callback on all processed objects. if (_callback != null) { _callback.releasing(toCommit, true); } else if (molder.getCallback() != null) { molder.getCallback().releasing(toCommit, true); } } // Call txcommited() before objects are removed to allow // TxSynchronizable to iterate through the objects. txcommitted(); // Forget about all the objects in this transaction, // and mark it as completed. _tracker.clear(); _status = Status.STATUS_COMMITTED; }