Example usage for javax.transaction Status STATUS_PREPARING

List of usage examples for javax.transaction Status STATUS_PREPARING

Introduction

In this page you can find the example usage for javax.transaction Status STATUS_PREPARING.

Prototype

int STATUS_PREPARING

To view the source code for javax.transaction Status STATUS_PREPARING.

Click Source Link

Document

A transaction is associated with the target object and it is in the process of preparing.

Usage

From source file:org.alfresco.repo.search.impl.lucene.AbstractLuceneIndexerImpl.java

/**
 * Utility method to report errors about invalid state.
 * /*  w w w. j  av a  2s .  com*/
 * @return - an error based on status
 */
private String buildErrorString() {
    StringBuilder buffer = new StringBuilder(128);
    buffer.append("The indexer is unable to accept more work: ");
    switch (getStatus().getStatus()) {
    case Status.STATUS_COMMITTED:
        buffer.append("The indexer has been committed");
        break;
    case Status.STATUS_COMMITTING:
        buffer.append("The indexer is committing");
        break;
    case Status.STATUS_MARKED_ROLLBACK:
        buffer.append("The indexer is marked for rollback");
        break;
    case Status.STATUS_PREPARED:
        buffer.append("The indexer is prepared to commit");
        break;
    case Status.STATUS_PREPARING:
        buffer.append("The indexer is preparing to commit");
        break;
    case Status.STATUS_ROLLEDBACK:
        buffer.append("The indexer has been rolled back");
        break;
    case Status.STATUS_ROLLING_BACK:
        buffer.append("The indexer is rolling back");
        break;
    case Status.STATUS_UNKNOWN:
        buffer.append("The indexer is in an unknown state");
        break;
    default:
        break;
    }
    return buffer.toString();
}

From source file:org.alfresco.repo.search.impl.lucene.AbstractLuceneIndexerImpl.java

/**
 * Commit this index// w w  w .  j  a  v a 2 s.co m
 * 
 * @throws LuceneIndexException
 */
public void commit() throws LuceneIndexException {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug(Thread.currentThread().getName() + " Starting Commit");
    }
    switch (getStatus().getStatus()) {
    case Status.STATUS_COMMITTING:
        throw new LuceneIndexException("Unable to commit: Transaction is committing");
    case Status.STATUS_COMMITTED:
        throw new LuceneIndexException("Unable to commit: Transaction is commited ");
    case Status.STATUS_ROLLING_BACK:
        throw new LuceneIndexException("Unable to commit: Transaction is rolling back");
    case Status.STATUS_ROLLEDBACK:
        throw new LuceneIndexException("Unable to commit: Transaction is aleady rolled back");
    case Status.STATUS_MARKED_ROLLBACK:
        throw new LuceneIndexException("Unable to commit: Transaction is marked for roll back");
    case Status.STATUS_PREPARING:
        throw new LuceneIndexException("Unable to commit: Transaction is preparing");
    case Status.STATUS_ACTIVE:
        // special case - commit from active
        prepare();
        // drop through to do the commit;
    default:
        if (getStatus().getStatus() != Status.STATUS_PREPARED) {
            throw new LuceneIndexException("Index must be prepared to commit");
        }
        try {
            setStatus(TransactionStatus.COMMITTING);
            if (isModified()) {
                doCommit();
            }
            setStatus(TransactionStatus.COMMITTED);
        } catch (LuceneIndexException e) {
            // If anything goes wrong we try and do a roll back
            rollback();
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(Thread.currentThread().getName() + " Commit Failed", e);
            }
            throw new LuceneIndexException("Commit failed", e);
        } catch (Throwable t) {
            // If anything goes wrong we try and do a roll back
            rollback();
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(Thread.currentThread().getName() + " Commit Failed", t);
            }
            throw new LuceneIndexException("Commit failed", t);
        } finally {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(Thread.currentThread().getName() + " Ending Commit");
            }

            // Make sure we tidy up
            // deleteDelta();
        }
        break;
    }
}

From source file:org.alfresco.repo.search.impl.lucene.AbstractLuceneIndexerImpl.java

/**
 * Prepare to commit At the moment this makes sure we have all the locks TODO: This is not doing proper
 * serialisation against the index as would a data base transaction.
 * /*from  w  w w  . j  av a  2  s  . co  m*/
 * @return the tx state
 * @throws LuceneIndexException
 */
public int prepare() throws LuceneIndexException {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug(Thread.currentThread().getName() + " Starting Prepare");
    }
    switch (getStatus().getStatus()) {
    case Status.STATUS_COMMITTING:
        throw new IndexerException("Unable to prepare: Transaction is committing");
    case Status.STATUS_COMMITTED:
        throw new IndexerException("Unable to prepare: Transaction is commited ");
    case Status.STATUS_ROLLING_BACK:
        throw new IndexerException("Unable to prepare: Transaction is rolling back");
    case Status.STATUS_ROLLEDBACK:
        throw new IndexerException("Unable to prepare: Transaction is aleady rolled back");
    case Status.STATUS_MARKED_ROLLBACK:
        throw new IndexerException("Unable to prepare: Transaction is marked for roll back");
    case Status.STATUS_PREPARING:
        throw new IndexerException("Unable to prepare: Transaction is already preparing");
    case Status.STATUS_PREPARED:
        throw new IndexerException("Unable to prepare: Transaction is already prepared");
    default:
        try {
            setStatus(TransactionStatus.PREPARING);
            if (isModified()) {
                doPrepare();
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug(Thread.currentThread().getName() + " Waiting to Finish Preparing");
                }
            }
            setStatus(TransactionStatus.PREPARED);
            return isModified() ? XAResource.XA_OK : XAResource.XA_RDONLY;
        } catch (LuceneIndexException e) {
            setRollbackOnly();
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(Thread.currentThread().getName() + " Prepare Failed", e);
            }
            throw new LuceneIndexException("Index failed to prepare", e);
        } catch (Throwable t) {
            // If anything goes wrong we try and do a roll back
            rollback();
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(Thread.currentThread().getName() + " Prepare Failed", t);
            }
            throw new LuceneIndexException("Prepared failed", t);
        } finally {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(Thread.currentThread().getName() + " Ending Prepare");
            }
        }
    }
}

From source file:org.apache.ofbiz.entity.transaction.TransactionUtil.java

public static String getTransactionStateString(int state) {
    /*//from  w  w  w  . j av a 2s  .  c  o  m
     * javax.transaction.Status
     * STATUS_ACTIVE           0
     * STATUS_MARKED_ROLLBACK  1
     * STATUS_PREPARED         2
     * STATUS_COMMITTED        3
     * STATUS_ROLLEDBACK       4
     * STATUS_UNKNOWN          5
     * STATUS_NO_TRANSACTION   6
     * STATUS_PREPARING        7
     * STATUS_COMMITTING       8
     * STATUS_ROLLING_BACK     9
     */
    switch (state) {
    case Status.STATUS_ACTIVE:
        return "Transaction Active (" + state + ")";
    case Status.STATUS_COMMITTED:
        return "Transaction Committed (" + state + ")";
    case Status.STATUS_COMMITTING:
        return "Transaction Committing (" + state + ")";
    case Status.STATUS_MARKED_ROLLBACK:
        return "Transaction Marked Rollback (" + state + ")";
    case Status.STATUS_NO_TRANSACTION:
        return "No Transaction (" + state + ")";
    case Status.STATUS_PREPARED:
        return "Transaction Prepared (" + state + ")";
    case Status.STATUS_PREPARING:
        return "Transaction Preparing (" + state + ")";
    case Status.STATUS_ROLLEDBACK:
        return "Transaction Rolledback (" + state + ")";
    case Status.STATUS_ROLLING_BACK:
        return "Transaction Rolling Back (" + state + ")";
    case Status.STATUS_UNKNOWN:
        return "Transaction Status Unknown (" + state + ")";
    default:
        return "Not a valid state code (" + state + ")";
    }
}

From source file:org.apache.ojb.odmg.JTATxManager.java

private static String getStatusString(int status) {
    switch (status) {
    case Status.STATUS_ACTIVE:
        return "STATUS_ACTIVE";
    case Status.STATUS_COMMITTED:
        return "STATUS_COMMITTED";
    case Status.STATUS_COMMITTING:
        return "STATUS_COMMITTING";
    case Status.STATUS_MARKED_ROLLBACK:
        return "STATUS_MARKED_ROLLBACK";
    case Status.STATUS_NO_TRANSACTION:
        return "STATUS_NO_TRANSACTION";
    case Status.STATUS_PREPARED:
        return "STATUS_PREPARED";
    case Status.STATUS_PREPARING:
        return "STATUS_PREPARING";
    case Status.STATUS_ROLLEDBACK:
        return "STATUS_ROLLEDBACK";
    case Status.STATUS_ROLLING_BACK:
        return "STATUS_ROLLING_BACK";
    case Status.STATUS_UNKNOWN:
        return "STATUS_UNKNOWN";
    default:/* ww w .j a  v  a  2s.com*/
        return "NO STATUS FOUND";
    }
}

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  2 s. co m*/
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

/**
 * 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 ww  w  .  j  a v  a  2s .c  o m*/
 *
 * @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.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 . j  a  v  a  2  s  . 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;//from  w w w.  java2 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.TransactionRecoveryImpl.java

private void fireCompensableStartRecovery() {
    final TransactionRepository transactionRepository = this.beanFactory.getCompensableRepository();
    CompensableLogger compensableLogger = this.beanFactory.getCompensableLogger();

    compensableLogger.recover(new TransactionRecoveryCallback() {
        public void recover(TransactionArchive archive) {
            this.recover((org.bytesoft.compensable.archive.TransactionArchive) archive);
        }//from   www  .ja  va2s.co m

        public void recover(org.bytesoft.compensable.archive.TransactionArchive archive) {
            XidFactory transactionXidFactory = beanFactory.getTransactionXidFactory();

            CompensableTransactionImpl transaction = reconstructTransaction(archive);
            TransactionContext transactionContext = transaction.getTransactionContext();

            TransactionXid compensableXid = transactionContext.getXid();
            if (transactionContext.isCompensable()) {
                switch (transaction.getTransactionStatus()) {
                case Status.STATUS_ACTIVE:
                case Status.STATUS_MARKED_ROLLBACK:
                case Status.STATUS_PREPARING:
                case Status.STATUS_UNKNOWN:
                    recoverStatusIfNecessary(transaction);
                    break;
                default: // ignore
                }
            } else {
                TransactionXid transactionXid = transactionXidFactory
                        .createGlobalXid(compensableXid.getGlobalTransactionId());
                Transaction tx = recovered.get(transactionXid);
                if (tx != null) {
                    tx.setTransactionalExtra(transaction);
                    transaction.setTransactionalExtra(tx);
                }
            } // end-if (transactionContext.isCompensable())

            transactionRepository.putTransaction(compensableXid, transaction);
            transactionRepository.putErrorTransaction(compensableXid, transaction);
        }
    });
}