// primary key cant be null, streamkey may be null
// check if the EJBContext/EJBObject exists in the store.
try {
EJBObjectImpl ejbObjImpl = (EJBObjectImpl)
ejbObjectStore.get(primaryKey, incrementRefCount);
if ( (ejbObjImpl != null) && (ejbObjImpl.getStub() != null) ) {
return ejbObjImpl;
}
// check if the EJBContext/EJBObject exists in threadlocal
// This happens if ejbo is in the process of being created.
// This is necessary to prevent infinite recursion
// because PRO.narrow calls is_a which calls the
// ProtocolMgr which calls getEJBObject.
ejbObjImpl = (EJBObjectImpl) ejbServant.get();
if ( ejbObjImpl != null ) {
return ejbObjImpl;
}
// set ejbo in thread local to help recursive calls find the ejbo
ejbServant.set(ejbObjImpl);
// "Connect" the EJBObject to the Protocol Manager
if ( streamKey == null ) {
streamKey = EJBUtils.serializeObject(primaryKey, false);
}
EJBObject ejbStub = (EJBObject)
remoteHomeRefFactory.createRemoteReference(streamKey);
// create the EJBObject and associate it with the stub
// and the primary key
ejbObjImpl = instantiateEJBObjectImpl(ejbStub, primaryKey);
ejbServant.set(null);
if ((incrementRefCount || cacheEJBO)) {
EJBObjectImpl ejbo1 =
(EJBObjectImpl) ejbObjectStore.put(primaryKey, ejbObjImpl,
incrementRefCount);
if ((ejbo1 != null) && (ejbo1 != ejbObjImpl)) {
remoteHomeRefFactory.destroyReference(ejbObjImpl.getStub(),
ejbObjImpl);