Search in sources :

Example 1 with TransactionRequiredLocalException

use of javax.ejb.TransactionRequiredLocalException in project Payara by payara.

the class SafeProperties method mapLocal3xException.

private Throwable mapLocal3xException(Throwable t) {
    Throwable mappedException = null;
    if (t instanceof TransactionRolledbackLocalException) {
        mappedException = new EJBTransactionRolledbackException();
        mappedException.initCause(t);
    } else if (t instanceof TransactionRequiredLocalException) {
        mappedException = new EJBTransactionRequiredException();
        mappedException.initCause(t);
    } else if (t instanceof NoSuchObjectLocalException) {
        mappedException = new NoSuchEJBException();
        mappedException.initCause(t);
    } else if (t instanceof AccessLocalException) {
        mappedException = new EJBAccessException();
        mappedException.initCause(t);
    }
    return (mappedException != null) ? mappedException : t;
}
Also used : NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException) NoSuchEJBException(javax.ejb.NoSuchEJBException) TransactionRolledbackLocalException(javax.ejb.TransactionRolledbackLocalException) AccessLocalException(javax.ejb.AccessLocalException) EJBTransactionRolledbackException(javax.ejb.EJBTransactionRolledbackException) TransactionRequiredLocalException(javax.ejb.TransactionRequiredLocalException) EJBTransactionRequiredException(javax.ejb.EJBTransactionRequiredException) EJBAccessException(javax.ejb.EJBAccessException)

Example 2 with TransactionRequiredLocalException

use of javax.ejb.TransactionRequiredLocalException in project Payara by payara.

the class EJBContainerTransactionManager method preInvokeTx.

/**
 * Handle transaction requirements, if any, before invoking bean method
 */
final void preInvokeTx(EjbInvocation inv) throws Exception {
    // Get existing Tx status: this tells us if the client
    // started a transaction which was propagated on this invocation.
    Integer preInvokeTxStatus = inv.getPreInvokeTxStatus();
    int status = (preInvokeTxStatus != null) ? preInvokeTxStatus.intValue() : transactionManager.getStatus();
    // For EntityBeans, ejbCreate/ejbRemove/ejbFind must be called with a Tx so no special work needed.
    if (container.suspendTransaction(inv)) {
        if (status != Status.STATUS_NO_TRANSACTION) {
            // client request is associated with a Tx
            try {
                inv.clientTx = transactionManager.suspend();
            } catch (SystemException ex) {
                throw new EJBException(ex);
            }
        }
        return;
    }
    // isNullTx is true if the client sent a null tx context
    // (i.e. a tx context with a null Coordinator objref)
    // or if this server's tx interop mode flag is false.
    // Follow the tables in EJB2.0 sections 19.6.2.2.1 and 19.6.2.2.2.
    boolean isNullTx = false;
    if (inv.isRemote) {
        isNullTx = transactionManager.isNullTransaction();
    }
    int txAttr = container.getTxAttr(inv);
    EJBContextImpl context = (EJBContextImpl) inv.context;
    // Note: in the code below, inv.clientTx is set ONLY if the
    // client's Tx is actually suspended.
    // get the Tx associated with the EJB from previous invocation,
    // if any.
    Transaction prevTx = context.getTransaction();
    switch(txAttr) {
        case Container.TX_BEAN_MANAGED:
            // Note: only MDBs and SessionBeans can be TX_BEAN_MANAGED
            if (status != Status.STATUS_NO_TRANSACTION) {
                // client request associated with a Tx, always suspend
                inv.clientTx = transactionManager.suspend();
            }
            if (container.isStatefulSession && prevTx != null && prevTx.getStatus() != Status.STATUS_NO_TRANSACTION) {
                // Note: if prevTx != null , then it means
                // afterCompletion was not called yet for the
                // previous transaction on the EJB.
                // The EJB was previously associated with a Tx which was
                // begun by the EJB itself in a previous invocation.
                // This is only possible for stateful SessionBeans
                // not for StatelessSession or Entity.
                transactionManager.resume(prevTx);
                // This allows the TM to enlist resources
                // used by the EJB with the transaction
                transactionManager.enlistComponentResources();
            }
            break;
        case Container.TX_NOT_SUPPORTED:
            if (status != Status.STATUS_NO_TRANSACTION) {
                inv.clientTx = transactionManager.suspend();
            }
            container.checkUnfinishedTx(prevTx, inv);
            container.preInvokeNoTx(inv);
            break;
        case Container.TX_MANDATORY:
            if (isNullTx || status == Status.STATUS_NO_TRANSACTION) {
                throw new TransactionRequiredLocalException();
            }
            useClientTx(prevTx, inv);
            break;
        case Container.TX_REQUIRED:
            if (isNullTx) {
                throw new TransactionRequiredLocalException();
            }
            if (status == Status.STATUS_NO_TRANSACTION) {
                inv.clientTx = null;
                startNewTx(prevTx, inv);
            } else {
                // There is a client Tx
                inv.clientTx = transactionManager.getTransaction();
                useClientTx(prevTx, inv);
            }
            break;
        case Container.TX_REQUIRES_NEW:
            if (status != Status.STATUS_NO_TRANSACTION) {
                inv.clientTx = transactionManager.suspend();
            }
            startNewTx(prevTx, inv);
            break;
        case Container.TX_SUPPORTS:
            if (isNullTx) {
                throw new TransactionRequiredLocalException();
            }
            if (status != Status.STATUS_NO_TRANSACTION) {
                useClientTx(prevTx, inv);
            } else {
                // we need to invoke the EJB with no Tx.
                container.checkUnfinishedTx(prevTx, inv);
                container.preInvokeNoTx(inv);
            }
            break;
        case Container.TX_NEVER:
            if (isNullTx || status != Status.STATUS_NO_TRANSACTION) {
                throw new EJBException("EJB cannot be invoked in global transaction");
            } else {
                // we need to invoke the EJB with no Tx.
                container.checkUnfinishedTx(prevTx, inv);
                container.preInvokeNoTx(inv);
            }
            break;
        default:
            throw new EJBException("Bad transaction attribute");
    }
}
Also used : SystemException(javax.transaction.SystemException) Transaction(javax.transaction.Transaction) UserTransaction(javax.transaction.UserTransaction) JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) ContainerTransaction(org.glassfish.ejb.deployment.descriptor.ContainerTransaction) EJBException(javax.ejb.EJBException) TransactionRequiredLocalException(javax.ejb.TransactionRequiredLocalException)

Example 3 with TransactionRequiredLocalException

use of javax.ejb.TransactionRequiredLocalException in project Payara by payara.

the class POAProtocolMgr method mapException.

/**
 * Map the EJB/RMI exception to a protocol-specific (e.g. CORBA) exception
 */
@Override
public Throwable mapException(Throwable exception) {
    boolean initCause = true;
    Throwable mappedException = exception;
    if (exception instanceof java.rmi.NoSuchObjectException || exception instanceof NoSuchObjectLocalException) {
        mappedException = new OBJECT_NOT_EXIST(MAPEXCEPTION_CODE, CompletionStatus.COMPLETED_MAYBE);
    } else if (exception instanceof java.rmi.AccessException || exception instanceof javax.ejb.AccessLocalException) {
        mappedException = new NO_PERMISSION(MAPEXCEPTION_CODE, CompletionStatus.COMPLETED_MAYBE);
    } else if (exception instanceof java.rmi.MarshalException) {
        mappedException = new MARSHAL(MAPEXCEPTION_CODE, CompletionStatus.COMPLETED_MAYBE);
    } else if (exception instanceof javax.transaction.TransactionRolledbackException || exception instanceof TransactionRolledbackLocalException) {
        mappedException = new TRANSACTION_ROLLEDBACK(MAPEXCEPTION_CODE, CompletionStatus.COMPLETED_MAYBE);
    } else if (exception instanceof javax.transaction.TransactionRequiredException || exception instanceof TransactionRequiredLocalException) {
        mappedException = new TRANSACTION_REQUIRED(MAPEXCEPTION_CODE, CompletionStatus.COMPLETED_MAYBE);
    } else if (exception instanceof javax.transaction.InvalidTransactionException) {
        mappedException = new INVALID_TRANSACTION(MAPEXCEPTION_CODE, CompletionStatus.COMPLETED_MAYBE);
    } else {
        initCause = false;
    }
    if (initCause) {
        mappedException.initCause(exception);
    }
    return mappedException;
}
Also used : NO_PERMISSION(org.omg.CORBA.NO_PERMISSION) TransactionRolledbackLocalException(javax.ejb.TransactionRolledbackLocalException) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) MARSHAL(org.omg.CORBA.MARSHAL) NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException) OBJECT_NOT_EXIST(org.omg.CORBA.OBJECT_NOT_EXIST) TRANSACTION_REQUIRED(org.omg.CORBA.TRANSACTION_REQUIRED) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) TransactionRequiredLocalException(javax.ejb.TransactionRequiredLocalException)

Aggregations

TransactionRequiredLocalException (javax.ejb.TransactionRequiredLocalException)3 NoSuchObjectLocalException (javax.ejb.NoSuchObjectLocalException)2 TransactionRolledbackLocalException (javax.ejb.TransactionRolledbackLocalException)2 JavaEETransaction (com.sun.enterprise.transaction.api.JavaEETransaction)1 AccessLocalException (javax.ejb.AccessLocalException)1 EJBAccessException (javax.ejb.EJBAccessException)1 EJBException (javax.ejb.EJBException)1 EJBTransactionRequiredException (javax.ejb.EJBTransactionRequiredException)1 EJBTransactionRolledbackException (javax.ejb.EJBTransactionRolledbackException)1 NoSuchEJBException (javax.ejb.NoSuchEJBException)1 SystemException (javax.transaction.SystemException)1 Transaction (javax.transaction.Transaction)1 UserTransaction (javax.transaction.UserTransaction)1 ContainerTransaction (org.glassfish.ejb.deployment.descriptor.ContainerTransaction)1 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)1 MARSHAL (org.omg.CORBA.MARSHAL)1 NO_PERMISSION (org.omg.CORBA.NO_PERMISSION)1 OBJECT_NOT_EXIST (org.omg.CORBA.OBJECT_NOT_EXIST)1 TRANSACTION_REQUIRED (org.omg.CORBA.TRANSACTION_REQUIRED)1 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)1