public Object invokeHome(Invocation mi)
throws Exception
{
// Get context
EntityContainer container = (EntityContainer) getContainer();
EntityEnterpriseContext ctx = (EntityEnterpriseContext) container.getInstancePool().get();
ctx.setTxAssociation(GlobalTxEntityMap.NOT_READY);
InstancePool pool = container.getInstancePool();
// Pass it to the method invocation
mi.setEnterpriseContext(ctx);
// Give it the transaction
ctx.setTransaction(mi.getTransaction());
// Set the current security information
ctx.setPrincipal(mi.getPrincipal());
AllowedOperationsAssociation.pushInMethodFlag(IN_EJB_HOME);
// Invoke through interceptors
Object obj = null;
Exception exception = null;
try
{
obj = getNext().invokeHome(mi);
// Is the context now with an identity? in which case we need to insert
if (ctx.getId() != null)
{
BeanLock lock = container.getLockManager().getLock(ctx.getCacheKey());
lock.sync(); // lock all access to BeanLock
try
{
// Check there isn't a context already in the cache
// e.g. commit-option B where the entity was
// created then removed externally
InstanceCache cache = container.getInstanceCache();
cache.remove(ctx.getCacheKey());
// marcf: possible race on creation and usage
// insert instance in cache,
cache.insert(ctx);
}
finally
{
lock.releaseSync();
container.getLockManager().removeLockRef(ctx.getCacheKey());
}
// we are all done
return obj;
}
}
catch (Exception e)
{
exception = e;
}
finally
{
AllowedOperationsAssociation.popInMethodFlag();
}
ctx.setTransaction(null);
// EntityCreateInterceptor will access ctx if it is not null and call postCreate
mi.setEnterpriseContext(null);
// if we get to here with a null exception then our invocation is
// just a home invocation. Return our instance to the instance pool
if (exception == null)
{
container.getInstancePool().free(ctx);
return obj;
}
if (exception instanceof RuntimeException)
{