Example usage for javax.transaction Status STATUS_UNKNOWN

List of usage examples for javax.transaction Status STATUS_UNKNOWN

Introduction

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

Prototype

int STATUS_UNKNOWN

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

Click Source Link

Document

A transaction is associated with the target object but its current status cannot be determined.

Usage

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

/**
 * Utility method to report errors about invalid state.
 * /*  w  w  w . j a  v a 2 s  . c o m*/
 * @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.apache.ode.daohib.JotmTransaction.java

/**
 * {@inheritDoc}//from  ww w  .j  av a2s  . c  o m
 */
public boolean wasRolledBack() throws TransactionException {
    final int status;
    try {
        status = userTransaction.getStatus();
    } catch (SystemException se) {
        log.error("Could not determine transaction status", se);
        throw new TransactionException("Could not determine transaction status", se);
    }
    if (status == Status.STATUS_UNKNOWN) {
        throw new TransactionException("Could not determine transaction status");
    } else {
        return JTAHelper.isRollback(status);
    }
}

From source file:org.apache.ode.daohib.JotmTransaction.java

/**
 * {@inheritDoc}//  w  w  w.  j a  va  2s.c  om
 */
public boolean wasCommitted() throws TransactionException {
    final int status;
    try {
        status = userTransaction.getStatus();
    } catch (SystemException se) {
        log.error("Could not determine transaction status", se);
        throw new TransactionException("Could not determine transaction status: ", se);
    }
    if (status == Status.STATUS_UNKNOWN) {
        throw new TransactionException("Could not determine transaction status");
    } else {
        return status == Status.STATUS_COMMITTED;
    }
}

From source file:org.apache.ode.daohib.JotmTransaction.java

/**
 * {@inheritDoc}/*  w  ww.  j ava2  s.  c  om*/
 */
public boolean isActive() throws TransactionException {
    if (!begun || commitFailed || commitSucceeded) {
        return false;
    }

    final int status;
    try {
        status = userTransaction.getStatus();
    } catch (SystemException se) {
        log.error("Could not determine transaction status", se);
        throw new TransactionException("Could not determine transaction status: ", se);
    }
    if (status == Status.STATUS_UNKNOWN) {
        throw new TransactionException("Could not determine transaction status");
    } else {
        return status == Status.STATUS_ACTIVE;
    }
}

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

public static String getTransactionStateString(int state) {
    /*//from w  w w  . jav  a2  s  . c  om
     * 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://  w  w  w . ja  v a2  s. c o m
        return "NO STATUS FOUND";
    }
}

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
 *///ww  w . j a v  a2s .co 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.AbstractBrokerFactory.java

/**
 * Find a managed runtime broker associated with the
 * current transaction, or returns null if none.
 *///  w  ww.  ja  v  a 2s  .co  m
protected Broker findTransactionalBroker(String user, String pass) {
    Transaction trans;
    ManagedRuntime mr = _conf.getManagedRuntimeInstance();
    Object txKey;
    try {
        trans = mr.getTransactionManager().getTransaction();
        txKey = mr.getTransactionKey();

        if (trans == null || trans.getStatus() == Status.STATUS_NO_TRANSACTION
                || trans.getStatus() == Status.STATUS_UNKNOWN)
            return null;
    } catch (OpenJPAException ke) {
        throw ke;
    } catch (Exception e) {
        throw new GeneralException(e);
    }

    Collection<Broker> brokers = _transactional.get(txKey);
    if (brokers != null) {
        // we don't need to synchronize on brokers since one JTA transaction
        // can never be active on multiple concurrent threads.
        for (Broker broker : brokers) {
            if (StringUtils.equals(broker.getConnectionUserName(), user)
                    && StringUtils.equals(broker.getConnectionPassword(), pass))
                return broker;
        }
    }
    return null;
}

From source file:org.apache.openjpa.kernel.AbstractBrokerFactory.java

/**
 * Synchronize the given broker with a managed transaction,
 * optionally starting one if none is in progress.
 *
 * @return true if synched with transaction, false otherwise
 *//*  w  ww . j  a  v  a2 s  .c  om*/
boolean syncWithManagedTransaction(BrokerImpl broker, boolean begin) {
    Transaction trans;
    try {
        ManagedRuntime mr = broker.getManagedRuntime();
        TransactionManager tm = mr.getTransactionManager();
        if (tm == null) {
            throw new InternalException(_loc.get("null-transactionmanager", mr));
        }
        trans = tm.getTransaction();
        if (trans != null && (trans.getStatus() == Status.STATUS_NO_TRANSACTION
                || trans.getStatus() == Status.STATUS_UNKNOWN))
            trans = null;

        if (trans == null && begin) {
            tm.begin();
            trans = tm.getTransaction();
        } else if (trans == null)
            return false;

        // synch broker and trans
        trans.registerSynchronization(broker);

        // we don't need to synchronize on brokers or guard against multiple
        // threads using the same trans since one JTA transaction can never
        // be active on multiple concurrent threads.
        Object txKey = mr.getTransactionKey();
        Collection<Broker> brokers = _transactional.get(txKey);

        if (brokers == null) {
            brokers = new ArrayList<Broker>(2);
            _transactional.put(txKey, brokers);
            trans.registerSynchronization(new RemoveTransactionSync(txKey));
        }
        brokers.add(broker);

        return true;
    } catch (OpenJPAException ke) {
        throw ke;
    } catch (Exception e) {
        throw new GeneralException(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();/*w  w  w . java 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.");
    }
}