use of javax.ejb.EntityBean in project Payara by payara.
the class ActiveTxCache method removeBean.
/**
* container.preInvoke() must already be done.
* So this will be called with the proper Tx context.
* @exception RemoveException if an error occurs while removing the bean
*/
protected void removeBean(EjbInvocation inv) throws RemoveException {
try {
ejbProbeNotifier.ejbBeanDestroyedEvent(getContainerId(), containerInfo.appName, containerInfo.modName, containerInfo.ejbName);
// Note: if there are concurrent invocations/transactions in
// progress for this ejbObject, they will be serialized along with
// this remove by the database. So we optimistically do ejbRemove.
// call ejbRemove on the EJB
// the EJB is allowed to veto the remove by throwing RemoveException
EntityBean ejb = (EntityBean) inv.ejb;
EntityContextImpl context = (EntityContextImpl) inv.context;
callEJBRemove(ejb, context);
// inv.ejbObject could be a EJBObject or a EJBLocalObject
Object primaryKey = getInvocationKey(inv);
if (isRemote) {
removeEJBObjectFromStore(primaryKey);
}
if (isLocal) {
// Remove the EJBLocalObject from ejbLocalObjectStore
ejbLocalObjectStore.remove(primaryKey);
}
// Mark EJB as removed. Now releaseContext will add bean to pool
containerStateManager.markObjectRemoved(context, true);
// Remove any timers for this entity bean identity.
cancelTimers(primaryKey);
} catch (RemoveException ex) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "entitybean.container.local_remove_exception", logParams);
_logger.log(Level.FINE, "", ex);
}
throw ex;
} catch (Exception ex) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "entitybean.container.remove_bean_exception", logParams);
_logger.log(Level.FINE, "", ex);
}
throw new EJBException(ex);
}
}
use of javax.ejb.EntityBean in project Payara by payara.
the class ActiveTxCache method passivateEJB.
// Called from AbstractCache
protected boolean passivateEJB(ComponentContext ctx) {
if (containerState != CONTAINER_STARTED) {
return false;
}
EntityContextImpl context = (EntityContextImpl) ctx;
if (!context.isInState(BeanState.READY)) {
return false;
}
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, "EntityContainer.passivateEJB(): context = (" + ctx + ")");
}
EntityBean ejb = (EntityBean) context.getEJB();
EjbInvocation inv = super.createEjbInvocation(ejb, context);
inv.method = ejbPassivateMethod;
Object pkey = context.getPrimaryKey();
boolean wasPassivated = false;
// check state after locking ctx
if (!context.isInState(BeanState.READY))
return false;
try {
invocationManager.preInvoke(inv);
// remove EJB from readyStore
removeContextFromReadyStore(pkey, context);
// no Tx needed for ejbPassivate
ejb.ejbPassivate();
wasPassivated = true;
} catch (Exception ex) {
_logger.log(Level.FINE, "Exception in passivateEJB()", ex);
// Error during ejbStore/Passivate, discard bean: EJB2.0 18.3.3
forceDestroyBean(context);
return false;
} finally {
invocationManager.postInvoke(inv);
}
// If a future EjbInvocation arrives for them, they'll get recreated.
if (isRemote) {
removeEJBObjectFromStore(pkey);
}
if (isLocal) {
ejbLocalObjectStore.remove(pkey);
}
// after calling ejbStore and ejbPassivate.
synchronized (context) {
addPooledEJB(context);
}
return wasPassivated;
}
use of javax.ejb.EntityBean 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 javax.ejb.EntityBean in project Payara by payara.
the class ReadOnlyBeanContainer method preInvokeNoTx.
// Called from BaseContainer just before invoking a business method
// whose tx attribute is TX_NEVER / TX_NOT_SUPPORTED / TX_SUPPORTS
// without a client tx.
protected void preInvokeNoTx(EjbInvocation inv) {
EntityContextImpl context = (EntityContextImpl) inv.context;
if (context.isInState(BeanState.DESTROYED))
return;
if (!inv.invocationInfo.isCreateHomeFinder) {
// follow EJB2.0 section 12.1.6.1
EntityBean e = (EntityBean) context.getEJB();
try {
callEJBLoad(e, context, false);
} catch (NoSuchEntityException ex) {
_logger.log(Level.FINE, "Exception in preInvokeNoTx()", ex);
// Error during ejbLoad, so discard bean: EJB2.0 18.3.3
forceDestroyBean(context);
throw new NoSuchObjectLocalException("NoSuchEntityException thrown by ejbLoad, " + "EJB instance discarded");
} catch (Exception ex) {
// Error during ejbLoad, so discard bean: EJB2.0 18.3.3
forceDestroyBean(context);
throw new EJBException(ex);
}
context.setNewlyActivated(false);
}
}
use of javax.ejb.EntityBean in project Payara by payara.
the class ActiveTxCache method enlistResourcesAndStore.
// Called from beforeCompletion and preFind
private void enlistResourcesAndStore(EntityContextImpl context) {
EntityBean e = (EntityBean) context.getEJB();
// NOTE : Use EjbInvocation instead of ComponentInvocation since
// the context is available. It is needed in case ejbStore/ejbLoad
// makes use of EJB timer service in order to perform operations allowed
// checks
EjbInvocation inv = super.createEjbInvocation(e, context);
invocationManager.preInvoke(inv);
try {
transactionManager.enlistComponentResources();
callEJBStore(e, context);
} catch (NoSuchEntityException ex) {
// Error during ejbStore, so discard bean: EJB2.0 18.3.3
forceDestroyBean(context);
throw new NoSuchObjectLocalException("NoSuchEntityException thrown by ejbStore, EJB instance discarded", ex);
} catch (Exception ex) {
// Error during ejbStore, so discard bean: EJB2.0 18.3.3
forceDestroyBean(context);
throw new EJBException(ex);
} finally {
invocationManager.postInvoke(inv);
}
}
Aggregations