currentTx.registerSynchronization(wrapper);
} catch (javax.transaction.SystemException se) {
logger.error("Transaction Manager registerSynchronization() failed.", se);
throw new SystemException(se);
} catch (RollbackException re) {
throw new ApplicationException(new TransactionRolledbackException(re));
}
txReadyPool.put(key, wrapper);
}
} else {
/*
If there is no transaction associated with the thread OR if the operation was a find or home method (PrimaryKey == null)
Then the bean instance is simply returned to the methodReady pool
*/
if (primaryKey != null && callContext.getCurrentOperation() != Operation.REMOVE) {
/*
* If the bean has a primary key; And its not being returned following a remove operation;
* then the bean is being returned to the method ready pool after successfully executing a business method or create
* method. In this case we need to call the bean instance's ejbPassivate before returning it to the pool per EJB 1.1
* Section 9.1.
*/
Operation currentOp = callContext.getCurrentOperation();
callContext.setCurrentOperation(Operation.PASSIVATE);
BaseContext.State[] originalStates = callContext.setCurrentAllowedStates(EntityContext.getStates());
try {
/*
In the event of an exception, OpenEJB is required to log the exception, evict the instance,
and mark the transaction for rollback. If there is a transaction to rollback, then the a
javax.transaction.TransactionRolledbackException must be throw to the client.
See EJB 1.1 specification, section 12.3.2
*/
bean.ejbPassivate();
} catch (Throwable e) {
try {
Transaction tx = getTransactionManager().getTransaction();
if (tx != null) {
tx.setRollbackOnly();
throw new ApplicationException(new TransactionRolledbackException("Reflection exception thrown while attempting to call ejbPassivate() on the instance", e));
}
} catch (javax.transaction.SystemException se) {
logger.error("Transaction Manager getTransaction() failed.", se);
throw new SystemException(se);
}