CoreDeploymentInfo deploymentInfo = callContext.getDeploymentInfo();
EntityBean bean = null;
Object primaryKey = null;
TransactionPolicy txPolicy = deploymentInfo.getTransactionPolicy(callMethod);
TransactionContext txContext = new TransactionContext(callContext, transactionManager);
txPolicy.beforeInvoke(bean, txContext);
try {
// Obtain a bean instance from the method ready pool
bean = createNewInstance(callContext);
// set the entity context
setEntityContext(bean);
// Obtain the proper ejbCreate() method
Method ejbCreateMethod = deploymentInfo.getMatchingBeanMethod(callMethod);
// Set current operation for allowed operations
callContext.setCurrentOperation(Operation.CREATE);
callContext.setCurrentAllowedStates(EntityContext.getStates());
// Invoke the proper ejbCreate() method on the instance
ejbCreateMethod.invoke(bean, args);
// create the new bean
CmpEngine cmpEngine = getCmpEngine(deploymentInfo);
primaryKey = cmpEngine.createBean(bean, callContext);
// determine post create callback method
Method ejbPostCreateMethod = deploymentInfo.getMatchingPostCreateMethod(ejbCreateMethod);
// create a new context containing the pk for the post create call
ThreadContext postCreateContext = new ThreadContext(deploymentInfo, primaryKey);
postCreateContext.setCurrentOperation(Operation.POST_CREATE);
postCreateContext.setCurrentAllowedStates(EntityContext.getStates());
ThreadContext oldContext = ThreadContext.enter(postCreateContext);
try {
// Invoke the ejbPostCreate method on the bean instance
ejbPostCreateMethod.invoke(bean, args);
// According to section 9.1.5.1 of the EJB 1.1 specification, the "ejbPostCreate(...)
// method executes in the same transaction context as the previous ejbCreate(...) method."
//
// The bean is first insterted using db.create( ) and then after ejbPostCreate( ) its
// updated using db.update(). This protocol allows for visablity of the bean after ejbCreate
// within the current trasnaction.
} finally {
ThreadContext.exit(oldContext);
}
// when there is not transaction, merge the data from the bean back into the cmp engine
cmpEngine.storeBeanIfNoTx(callContext, bean);
} catch (InvocationTargetException ite) {// handle enterprise bean exceptions
ExceptionType type = callContext.getDeploymentInfo().getExceptionType(ite.getTargetException());
if (type == ExceptionType.SYSTEM) {
/* System Exception ****************************/
txPolicy.handleSystemException(ite.getTargetException(), bean, txContext);
} else {
/* Application Exception ***********************/
txPolicy.handleApplicationException(ite.getTargetException(), type == ExceptionType.APPLICATION_ROLLBACK, txContext);
}
} catch (CreateException e) {
txPolicy.handleSystemException(e, bean, txContext);
} catch (Throwable e) {
txPolicy.handleSystemException(e, bean, txContext);
} finally {
txPolicy.afterInvoke(bean, txContext);
}
return new ProxyInfo(deploymentInfo, primaryKey);
}