use of javax.ejb.EntityBean in project Payara by payara.
the class ActiveTxCache 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.
@Override
protected void preInvokeNoTx(EjbInvocation inv) {
EntityContextImpl context = (EntityContextImpl) inv.context;
if (context.isInState(BeanState.DESTROYED)) {
return;
}
if (context.isNewlyActivated() && !inv.invocationInfo.isCreateHomeFinder) {
// follow EJB2.0 section 12.1.6.1
EntityBean e = (EntityBean) context.getEJB();
try {
callEJBLoad(e, context, false);
} catch (NoSuchEntityException ex) {
// Error during ejbLoad, so discard bean: EJB2.0 18.3.3
forceDestroyBean(context);
throw new NoSuchObjectLocalException("NoSuchEntityException thrown by ejbLoad, EJB instance discarded", ex);
} 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 afterBegin.
// Called from BaseContainer.SyncImpl
protected void afterBegin(EJBContextImpl ctx) {
EntityContextImpl context = (EntityContextImpl) ctx;
// Note: EntityBeans are not allowed to be TX_BEAN_MANAGED
if (context.isInState(BeanState.DESTROYED))
return;
if (!containerStateManager.isNullEJBObject(context) || !containerStateManager.isNullEJBLocalObject(context)) {
// invocations will be correctly handled
if (context.getTransaction() != null) {
addIncompleteTxEJB(context);
}
// need to call ejbLoad since there can be more than
// one active EJB instance per primaryKey. (Option B in 9.11.5).
EntityBean e = (EntityBean) context.getEJB();
try {
callEJBLoad(e, context, true);
} catch (NoSuchEntityException ex) {
_logger.log(Level.FINE, "Exception in afterBegin()", ex);
// Error during ejbLoad, so discard bean: EJB2.0 18.3.3
forceDestroyBean(context);
throw new NoSuchObjectLocalException("NoSuchEntityException thrown by ejbLoad, EJB instance discarded", ex);
} 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 passivateAndPoolEJB.
// called from addReadyEJB and afterCompletion
protected void passivateAndPoolEJB(EntityContextImpl context) {
if (context.isInState(BeanState.DESTROYED) || context.isInState(BeanState.POOLED))
return;
// if ( context.isPooled() ) {
// context.isPooled(false);
// return;
// }
EntityBean ejb = (EntityBean) context.getEJB();
synchronized (context) {
EjbInvocation inv = super.createEjbInvocation(ejb, context);
inv.method = ejbPassivateMethod;
invocationManager.preInvoke(inv);
try {
ejb.ejbPassivate();
} catch (Exception ex) {
_logger.log(Level.FINE, "Exception in passivateAndPoolEJB()", ex);
forceDestroyBean(context);
return;
} finally {
invocationManager.postInvoke(inv);
}
// remove EJB(Local)Object from ejb(Local)ObjectStore
Object primaryKey = context.getPrimaryKey();
if (isRemote) {
removeEJBObjectFromStore(primaryKey);
}
if (isLocal) {
ejbLocalObjectStore.remove(primaryKey);
}
addPooledEJB(context);
}
}
use of javax.ejb.EntityBean in project tomee by apache.
the class CmpContainer method select.
public Object select(final BeanContext beanContext, final String methodSignature, final String returnType, final Object... args) throws FinderException {
final String signature = beanContext.getAbstractSchemaName() + "." + methodSignature;
try {
// execute the select query
final Collection<Object> results = cmpEngine.queryBeans(beanContext, signature, args);
//
// process the results
//
// If we need to return a set...
final Collection<Object> proxies;
if (returnType.equals("java.util.Set")) {
// we collect values into a LinkedHashSet to preserve ordering
proxies = new LinkedHashSet<Object>();
} else {
// otherwise use a simple array list
proxies = new ArrayList<Object>();
}
final boolean isSingleValued = !returnType.equals("java.util.Collection") && !returnType.equals("java.util.Set");
ProxyFactory proxyFactory = null;
for (Object value : results) {
// if this is a single valued query and we already have results, throw FinderException
if (isSingleValued && !proxies.isEmpty()) {
throw new FinderException("The single valued query " + methodSignature + "returned more than one item");
}
// if we have an EntityBean, we need to proxy it
if (value instanceof EntityBean) {
final EntityBean entityBean = (EntityBean) value;
if (proxyFactory == null) {
final BeanContext result = getBeanContextByClass(entityBean.getClass());
if (result != null) {
proxyFactory = new ProxyFactory(result);
}
}
if (proxyFactory != null) {
if (beanContext.isRemoteQueryResults(methodSignature)) {
value = proxyFactory.createRemoteProxy(entityBean, this);
} else {
value = proxyFactory.createLocalProxy(entityBean, this);
}
}
}
proxies.add(value);
}
// if not single valued, return the set
if (!isSingleValued) {
return proxies;
}
// single valued query that returned no rows, is an exception
if (proxies.isEmpty()) {
throw new ObjectNotFoundException();
}
// return the single item.... multiple return values was handled in for loop above
return proxies.iterator().next();
} catch (final RuntimeException e) {
throw new EJBException(e);
}
}
use of javax.ejb.EntityBean in project tomee by apache.
the class CmpContainer method ejbLoad.
private void ejbLoad(final EntityBean entityBean) {
if (entityBean == null) {
throw new NullPointerException("entityBean is null");
}
final ThreadContext callContext = createThreadContext(entityBean);
callContext.setCurrentOperation(Operation.LOAD);
final ThreadContext oldCallContext = ThreadContext.enter(callContext);
try {
entityBean.ejbLoad();
} catch (final RemoteException e) {
throw new EJBException(e);
} finally {
ThreadContext.exit(oldCallContext);
}
// if we call load we must call store
try {
// noinspection unchecked
Set<EntityBean> registeredEntities = (LinkedHashSet<EntityBean>) synchronizationRegistry.getResource(ENTITIES_TO_STORE);
if (registeredEntities == null) {
registeredEntities = new LinkedHashSet<EntityBean>();
synchronizationRegistry.putResource(ENTITIES_TO_STORE, registeredEntities);
synchronizationRegistry.registerInterposedSynchronization(new Synchronization() {
@Override
public void beforeCompletion() {
// noinspection unchecked
final Set<EntityBean> registeredEntities = (LinkedHashSet<EntityBean>) synchronizationRegistry.getResource(ENTITIES_TO_STORE);
if (registeredEntities == null) {
return;
}
for (final EntityBean entityBean : registeredEntities) {
ejbStore(entityBean);
}
}
@Override
public void afterCompletion(final int i) {
}
});
}
registeredEntities.add(entityBean);
} catch (final Exception e) {
// no-op
}
}
Aggregations