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;
}
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");
}
}
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;
}
Aggregations