wrapper.disassociate();
/*
* If the bean has been removed then the bean instance is no longer needed and can return to the methodReadyPool
* to service another identity.
*/
Stack methodReadyPool = poolMap.get(callContext.getDeploymentInfo().getDeploymentID());
methodReadyPool.push(bean);
} else {
if (callContext.getCurrentOperation() == Operation.CREATE) {
// Bean is being recreated (new-delete-new) so we need to reassociate it
wrapper.associate();
}
wrapper.setEntityBean(bean);
}
} else {
/*
A wrapper will not exist if the bean is being returned after a create operation.
In this case the transaction scope is broader then the create method itself; its a client
initiated transaction, so the bean must be registered with the tranaction and moved to the
tx ready pool
*/
wrapper = new SynchronizationWrapper(callContext.getDeploymentInfo(), primaryKey, bean, true, key, txPolicy);
txPolicy.registerSynchronization(wrapper);
txPolicy.putResource(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) {
if (txPolicy.isTransactionActive()) {
txPolicy.setRollbackOnly();
throw new ApplicationException(new TransactionRolledbackException("Reflection exception thrown while attempting to call ejbPassivate() on the instance", e));
}
throw new ApplicationException(new RemoteException("Reflection exception thrown while attempting to call ejbPassivate() on the instance. Exception message = " + e.getMessage(), e));
} finally {
callContext.setCurrentOperation(currentOp);
callContext.setCurrentAllowedStates(originalStates);
}
}
/*
* The bean is returned to the method ready pool if its returned after servicing a find, ejbHome, business or create
* method and is not still part of a tx. While in the method ready pool the bean instance is not associated with a
* primary key and may be used to service a request for any bean of the same class.
*/
Stack methodReadyPool = poolMap.get(callContext.getDeploymentInfo().getDeploymentID());
methodReadyPool.push(bean);
}
}