use of com.sun.ejb.containers.EJBLocalObjectImpl in project Payara by payara.
the class ActiveTxCache method activateEJBFromPool.
/**
* Called from getContext and getEJBWithIncompleteTx
* Get an EJB in the ready state (i.e. which is not doing any
* invocations and doesnt have any incomplete Tx), for the
* ejbObject provided in the EjbInvocation.
* Concurrent invocations should get *different* instances.
*/
protected EntityContextImpl activateEJBFromPool(Object primaryKey, EjbInvocation inv) {
EntityContextImpl context = null;
// get a pooled EJB and activate it.
context = getPooledEJB();
// set EJBObject/LocalObject for the context
if (inv.isLocal) {
EJBLocalObjectImpl localObjImpl = internalGetEJBLocalObjectImpl(primaryKey, true);
containerStateManager.attachObject(inv, context, null, localObjImpl);
// No need to create/set EJBObject if this EJB isRemote too.
// This saves remote object creation overhead.
// The EJBObject and stub will get created lazily if needed
// when EntityContext.getEJBObjectImpl is called.
} else {
// remote EjbInvocation
EJBObjectImpl ejbObjImpl = internalGetEJBObjectImpl(primaryKey, null, true);
containerStateManager.attachObject(inv, context, ejbObjImpl, null);
if (isLocal) {
// Create EJBLocalObject so EntityContext methods work
containerStateManager.attachObject(inv, context, null, internalGetEJBLocalObjectImpl(primaryKey, true));
}
}
context.setState(BeanState.READY);
EntityBean ejb = (EntityBean) context.getEJB();
EjbInvocation inv2 = super.createEjbInvocation(ejb, context);
inv2.method = ejbActivateMethod;
invocationManager.preInvoke(inv2);
try {
ejb.ejbActivate();
// Note: ejbLoad will be called during preInvokeTx
// since this EJB instance is being associated with
// a Tx for the first time.
} catch (Exception ex) {
// Error during ejbActivate, discard bean: EJB2.0 18.3.3
forceDestroyBean(context);
throw new EJBException(ex);
} finally {
invocationManager.postInvoke(inv2);
}
context.setNewlyActivated(true);
// recycler.initSoftRef(context);
afterNewlyActivated(context);
return context;
}
use of com.sun.ejb.containers.EJBLocalObjectImpl in project Payara by payara.
the class ActiveTxCache method getEJBLocalObjectForPrimaryKey.
/**
* Called only from the Persistence Manager for EJB2.0 CMP EntityBeans.
* Called only during cascade delete......
* This is a private API between the PM and Container because there
* is no standard API defined in EJB2.0 for the PM to get an EJBLocalObject
* for a primary key (findByPrimaryKey cant be used because it may
* not run in the same tx).
*
* Example 1:
* A cascadeDeletes B and B calls getA() (expected return value: null)
*
* In the above case, getA() eventualy calls getEJBLocalObjectForPrimaryKey(PK_of_A, Ctx_of_B)
* We first check if B is in the process of being cascade deleted by checking the
* cascadeDeleteBeforeEJBRemove flag. If this flag is true, only then we bother to check if
* the Context associated with the PK_of_A in this transaction is marked for cascade delete
* which can be figured out by checking isCascadeDeleteAfterSuperEJBRemove() in A's context.
* If A is marked for cascade delete then we return null else the EJBLocalObject associated
* with A.
*
* Example 2:
* C cascadeDeletes B and B calls getA() (expected return value: EJBLocalObject for PK_of_A)
*
* In the above case, getA() eventualy calls getEJBLocalObjectForPrimaryKey(PK_of_A, Ctx_of_B)
* We first check if B is in the process of being cascade deleted by checking the
* cascadeDeleteBeforeEJBRemove flag. This flag will be true, and hence we check if
* the Context associated with the PK_of_A in this transaction is marked for cascade delete
* which can be figured out by checking isCascadeDeleteAfterSuperEJBRemove() in A's context.
* In this case this flag will be false and hcen we return the ejbLocalObject
* Example 2:
* B is *NOT* cascade deleted and B calls getA() (expected return value: EJBLocalObject for PK_of_A)
*
* In the above case, getA() eventualy calls getEJBLocalObjectForPrimaryKey(PK_of_A, Ctx_of_B)
* We first check if B is in the process of being cascade deleted by checking the
* cascadeDeleteBeforeEJBRemove flag. This flag will be FALSE, and hence we do not make
* any further check and return the EJBLocalObject associated with A
*
* @param pkey The primary key for which the EJBLocalObject is required
* @param ctx The context associated with the bean from which the accessor method is invoked
* @return The EJBLocalObject associated with the PK or null if it is cascade deleted.
*/
public EJBLocalObject getEJBLocalObjectForPrimaryKey(Object pkey, EJBContext ctx) {
// EntityContextImpl should always be used in conjunction with EntityContainer so we can always cast
assert ctx instanceof EntityContextImpl;
EntityContextImpl context = (EntityContextImpl) ctx;
EJBLocalObjectImpl ejbLocalObjectImpl = internalGetEJBLocalObjectImpl(pkey);
if (context.isCascadeDeleteBeforeEJBRemove()) {
JavaEETransaction current = null;
try {
current = (JavaEETransaction) transactionManager.getTransaction();
} catch (SystemException ex) {
throw new EJBException(ex);
}
ActiveTxCache activeTxCache = (current == null) ? null : (ActiveTxCache) (ejbContainerUtilImpl.getActiveTxCache(current));
if (activeTxCache != null) {
EntityContextImpl ctx2 = (EntityContextImpl) activeTxCache.get(this, pkey);
if ((ctx2 != null) && (ctx2.isCascadeDeleteAfterSuperEJBRemove())) {
return null;
}
}
return (EJBLocalObject) ejbLocalObjectImpl.getClientObject();
}
return (EJBLocalObject) ejbLocalObjectImpl.getClientObject();
}
use of com.sun.ejb.containers.EJBLocalObjectImpl in project Payara by payara.
the class ActiveTxCache method postCreate.
/**
* This is called from the generated "HelloEJBHomeImpl" create* method,
* after ejb.ejbCreate() has been called and before ejb.ejbPostCreate()
* is called.
* Note: postCreate will not be called if ejbCreate throws an exception
*/
public void postCreate(EjbInvocation inv, Object primaryKey) throws CreateException {
if (primaryKey == null)
throw new EJBException("Null primary key returned by ejbCreate method");
if ((isRemote) && (!inv.isLocal)) {
// remote EjbInvocation: create EJBObject
EJBObjectImpl ejbObjImpl = internalGetEJBObjectImpl(primaryKey, null, true);
// associate the context with the ejbObject
containerStateManager.attachObject(inv, (EJBContextImpl) inv.context, ejbObjImpl, null);
}
if (isLocal) {
// create EJBLocalObject irrespective of local/remote EjbInvocation
// this is necessary to make EntityContext.getPrimaryKey and
// EntityContext.getEJBObject work.
EJBLocalObjectImpl localObjImpl = internalGetEJBLocalObjectImpl(primaryKey, true);
// associate the context with the ejbLocalObject
containerStateManager.attachObject(inv, (EJBContextImpl) inv.context, null, localObjImpl);
}
EntityContextImpl context = (EntityContextImpl) inv.context;
if (context.getTransaction() != null) {
// Add EJB to INCOMPLETE_TX table so that concurrent/loopback
// invocations will be correctly handled
addIncompleteTxEJB(context);
}
// ejbPostCreate could modify state
context.setDirty(true);
}
use of com.sun.ejb.containers.EJBLocalObjectImpl in project Payara by payara.
the class ActiveTxCache method removeBeanUnchecked.
/**
* Remove a bean. Used by the PersistenceManager.
* This is needed because the PM's remove must bypass tx/security checks.
*/
public void removeBeanUnchecked(EJBLocalObject localObj) {
// First convert client EJBLocalObject to EJBLocalObjectImpl
EJBLocalObjectImpl localObjectImpl = EJBLocalObjectImpl.toEJBLocalObjectImpl(localObj);
internalRemoveBeanUnchecked(localObjectImpl, true);
}
Aggregations