List of usage examples for javax.transaction Status STATUS_MARKED_ROLLBACK
int STATUS_MARKED_ROLLBACK
To view the source code for javax.transaction Status STATUS_MARKED_ROLLBACK.
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 ww w .j a v a 2 s. c om 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 the transaction, but reopen the transaction, retaining all locks. * Calling <code>checkpoint</code> commits persistent object modifications * made within the transaction since the last checkpoint to the database. The * transaction retains all locks it held on those objects at the time the * checkpoint was invoked.// w w w.ja v a 2 s . c o m */ public void checkpoint() { if (log.isDebugEnabled()) log.debug("Checkpoint was called, commit changes hold locks on tx " + this); try { checkOpen(); doWriteObjects(true); // do commit on PB if (hasBroker() && broker.isInTransaction()) broker.commitTransaction(); } catch (Throwable t) { log.error("Checkpoint call failed, do abort transaction", t); txStatus = Status.STATUS_MARKED_ROLLBACK; abort(); if (!(t instanceof ODMGRuntimeException)) { throw new TransactionAbortedExceptionOJB("Can't tx.checkpoint() objects: " + t.getMessage(), t); } else { throw (ODMGRuntimeException) t; } } }
From source file:org.apache.ojb.odmg.TransactionImpl.java
/** * @see org.apache.ojb.odmg.TransactionExt#flush *//*from w w w. ja va2 s . c o m*/ public void flush() { if (log.isDebugEnabled()) { log.debug("Flush was called - write changes to database, do not commit, hold locks on tx " + this); } try { checkOpen(); doWriteObjects(true); } catch (Throwable t) { log.error("Calling method 'tx.flush()' failed", t); txStatus = Status.STATUS_MARKED_ROLLBACK; abort(); if (!(t instanceof ODMGRuntimeException)) { throw new TransactionAbortedExceptionOJB("Can't tx.flush() objects: " + t.getMessage(), t); } else { throw (ODMGRuntimeException) t; } } }
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. *//*ww w.ja v a2 s .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.apache.ojb.odmg.TransactionImpl.java
protected void checkForCommit() { // Never commit transaction that has been marked for rollback if (txStatus == Status.STATUS_MARKED_ROLLBACK) throw new TransactionAbortedExceptionOJB("Illegal tx-status: tx is already markedRollback"); // Don't commit if not prepared if (txStatus != Status.STATUS_PREPARED) throw new IllegalStateException("Illegal tx-status: Do prepare commit before commit"); }
From source file:org.apache.ojb.odmg.TransactionImpl.java
/** * Prepare does the actual work of moving the changes at the object level * into storage (the underlying rdbms for instance). prepare Can be called multiple times, and * does not release locks./*from w w w.j a v a 2 s. com*/ * * @throws TransactionAbortedException if the transaction has been aborted * for any reason. * @throws IllegalStateException Method called if transaction is * not in the proper state to perform this operation * @throws TransactionNotInProgressException if the transaction is closed. */ protected void prepareCommit() throws TransactionAbortedException, LockNotGrantedException { if (txStatus == Status.STATUS_MARKED_ROLLBACK) { throw new TransactionAbortedExceptionOJB("Prepare Transaction: tx already marked for rollback"); } if (txStatus != Status.STATUS_ACTIVE) { throw new IllegalStateException("Prepare Transaction: tx status is not 'active', status is " + TxUtil.getStatusString(txStatus)); } try { txStatus = Status.STATUS_PREPARING; doWriteObjects(false); txStatus = Status.STATUS_PREPARED; } catch (RuntimeException e) { log.error("Could not prepare for commit", e); txStatus = Status.STATUS_MARKED_ROLLBACK; throw e; } }
From source file:org.apache.ojb.odmg.TransactionImpl.java
/** * Abort and close the transaction. Calling abort abandons all persistent * object modifications and releases the associated locks. Aborting a * transaction does not restore the state of modified transient objects *///from w ww. j av a2 s. c o m public void abort() { /* do nothing if already rolledback */ if (txStatus == Status.STATUS_NO_TRANSACTION || txStatus == Status.STATUS_UNKNOWN || txStatus == Status.STATUS_ROLLEDBACK) { log.info("Nothing to abort, tx is not active - status is " + TxUtil.getStatusString(txStatus)); return; } // check status of tx if (txStatus != Status.STATUS_ACTIVE && txStatus != Status.STATUS_PREPARED && txStatus != Status.STATUS_MARKED_ROLLBACK) { throw new IllegalStateException( "Illegal state for abort call, state was '" + TxUtil.getStatusString(txStatus) + "'"); } if (log.isEnabledFor(Logger.INFO)) { log.info("Abort transaction was called on tx " + this); } try { try { doAbort(); } catch (Exception e) { log.error("Error while abort transaction, will be skipped", e); } // used in managed environments, ignored in non-managed this.implementation.getTxManager().abortExternalTx(this); try { if (hasBroker() && getBroker().isInTransaction()) { getBroker().abortTransaction(); } } catch (Exception e) { log.error("Error while do abort used broker instance, will be skipped", e); } } finally { txStatus = Status.STATUS_ROLLEDBACK; // cleanup things, e.g. release all locks doClose(); } }
From source file:org.apache.openjpa.kernel.BrokerImpl.java
public boolean getRollbackOnly() { beginOperation(true);/* w ww.j av a 2 s . com*/ try { if ((_flags & FLAG_ACTIVE) == 0) return false; javax.transaction.Transaction trans = _runtime.getTransactionManager().getTransaction(); if (trans == null) return false; return trans.getStatus() == Status.STATUS_MARKED_ROLLBACK; } catch (OpenJPAException ke) { throw ke; } catch (Exception e) { throw new GeneralException(e); } finally { endOperation(); } }
From source file:org.apache.openjpa.kernel.BrokerImpl.java
public Throwable getRollbackCause() { beginOperation(true);//from ww w . jav a2s. c o m try { if ((_flags & FLAG_ACTIVE) == 0) return null; javax.transaction.Transaction trans = _runtime.getTransactionManager().getTransaction(); if (trans == null) return null; if (trans.getStatus() == Status.STATUS_MARKED_ROLLBACK) return _runtime.getRollbackCause(); return null; } catch (OpenJPAException ke) { throw ke; } catch (Exception e) { throw new GeneralException(e); } finally { endOperation(); } }
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();//from w ww . ja va 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."); } }