Example usage for javax.transaction Transaction setRollbackOnly

List of usage examples for javax.transaction Transaction setRollbackOnly

Introduction

In this page you can find the example usage for javax.transaction Transaction setRollbackOnly.

Prototype

public void setRollbackOnly() throws IllegalStateException, SystemException;

Source Link

Document

Modify the transaction associated with the target object such that the only possible outcome of the transaction is to roll back the transaction.

Usage

From source file:com.impetus.kundera.persistence.jta.KunderaJTAUserTransaction.java

@Override
public void setRollbackOnly() throws IllegalStateException, SystemException {
    Transaction tx = threadLocal.get();
    if (tx == null) {
        throw new IllegalStateException("Cannot get Transaction for setRollbackOnly");
    }/*  www  .jav a2s . c  o m*/
    tx.setRollbackOnly();

}

From source file:org.apache.ojb.broker.core.PersistenceBrokerFactorySyncImpl.java

protected PersistenceBrokerInternal wrapRequestedBrokerInstance(PersistenceBrokerInternal broker) {
    // all PB instance should be of this type
    if (!(broker instanceof PersistenceBrokerSyncImpl)) {
        throw new PBFactoryException(
                "Expect instance of " + PersistenceBrokerSyncImpl.class + ", found " + broker.getClass());
    }//from   ww w .  jav  a2s. co  m
    /*
    Before we return the PB handle, we jump into the running JTA tx
    */
    PersistenceBrokerSyncImpl pb = (PersistenceBrokerSyncImpl) broker;
    try {
        // search for an active tx
        Transaction tx = searchForValidTx();
        if (tx != null) {
            txRegistry.register(tx, pb);
            try {
                pb.internBegin();
            } catch (Exception e) {
                /*
                if something going wrong with pb-tx, we rollback the
                whole JTA tx
                */
                log.error("Unexpected exception when start intern pb-tx", e);
                try {
                    tx.setRollbackOnly();
                } catch (Throwable ignore) {
                }
                throw new PBFactoryException("Unexpected exception when start intern pb-tx", e);
            }
        }
    } catch (Exception e) {
        if (e instanceof PBFactoryException) {
            throw (PBFactoryException) e;
        } else {
            throw new PBFactoryException("Error while try to participate in JTA transaction", e);
        }
    }
    return new PersistenceBrokerSyncHandle(pb);
}

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

/**
 * Abort an active extern transaction associated with the given PB.
 *//*from  ww w .  j  av a 2s .  co  m*/
public void abortExternalTx(TransactionImpl odmgTrans) {
    if (log.isDebugEnabled())
        log.debug("abortExternTransaction was called");
    if (odmgTrans == null)
        return;
    TxBuffer buf = (TxBuffer) txRepository.get();
    Transaction extTx = buf != null ? buf.getExternTx() : null;
    try {
        if (extTx != null && extTx.getStatus() == Status.STATUS_ACTIVE) {
            if (log.isDebugEnabled()) {
                log.debug("Set extern transaction to rollback");
            }
            extTx.setRollbackOnly();
        }
    } catch (Exception ignore) {
    }
    txRepository.set(null);
}

From source file:org.eclipse.ecr.automation.core.operations.execution.RunInNewTransaction.java

private void handleRollbackOnlyOnGlobal(Transaction mainTx, Throwable e)
        throws SystemException, OperationException {
    TransactionHelper.setTransactionRollbackOnly();
    if (rollbackGlobalOnError == true) {
        mainTx.setRollbackOnly();
        throw new OperationException("Catching error on new transaction, rollbacking global tx", e);
    } else {/*from   w ww.ja v  a2  s  . co m*/
        log.error("Caught error on new transaction, continuing global tx", e);
    }
}

From source file:org.wso2.carbon.attachment.mgt.core.dao.impl.TransactionManagerProvider.java

public void doNonTransactionalWork(java.lang.Runnable runnable) throws NotSupportedException {
    TransactionManager transactionManager = null;
    Transaction transaction = null;

    try {//from   w w  w  .  j  a  v  a2s .c  o  m
        transactionManager = getTransactionManager();
        transaction = transactionManager.suspend();
    } catch (Exception e) {
        NotSupportedException nse = new NotSupportedException(e.getMessage());
        nse.initCause(e);
        log.error(nse.getLocalizedMessage(), nse);
        throw nse;
    }

    runnable.run();

    try {
        transactionManager.resume(transaction);
    } catch (Exception e) {
        log.error(e.getLocalizedMessage(), e);
        try {
            transaction.setRollbackOnly();
        } catch (SystemException se2) {
            throw new GeneralException(se2);
        }
        NotSupportedException nse = new NotSupportedException(e.getMessage());
        nse.initCause(e);
        throw nse;
    }
}