use of javax.ejb.EJBException 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.EJBException in project Payara by payara.
the class JDOEJB11HelperImpl method convertPCToEJBObject.
/**
* Converts persistence-capable instance to EJBObject.
* @param pc the persistence-capable instance to be converted as an Object.
* @param pm the associated instance of PersistenceManager.
* @return instance of EJBObject.
*/
public EJBObject convertPCToEJBObject(Object pc, PersistenceManager pm) {
if (pc == null)
return null;
Object jdoObjectId = pm.getObjectId(pc);
Object key = convertObjectIdToPrimaryKey(jdoObjectId);
try {
return CMPHelper.getEJBObject(key, getContainer());
} catch (Exception ex) {
EJBException e = new EJBException(I18NHelper.getMessage(messages, "EXC_ConvertPCToEJBObject", key.toString()), // NOI18N
ex);
// NOI18N
logger.throwing("JDOEJB11HelperImpl", "convertPCToEJBObject", e);
throw e;
}
}
use of javax.ejb.EJBException in project Payara by payara.
the class JDOEJB20HelperImpl method convertPCToEJBLocalObject.
/**
* Converts persistence-capable instance to EJBLocalObject. Returns null if
* the instance is already removed via cascade-delete operation.
* @param pc the persistence-capable instance to be converted as an Object.
* @param pm the associated instance of PersistenceManager.
* @param context the EJBContext of the calling bean.
* @return instance of EJBLocalObject.
*/
public EJBLocalObject convertPCToEJBLocalObject(Object pc, PersistenceManager pm, EJBContext context) {
if (pc == null)
return null;
Object jdoObjectId = pm.getObjectId(pc);
Object key = convertObjectIdToPrimaryKey(jdoObjectId);
try {
return CMPHelper.getEJBLocalObject(key, getContainer(), context);
} catch (Exception ex) {
EJBException e = new EJBException(I18NHelper.getMessage(messages, "EXC_ConvertPCToEJBLocalObjectCtx", key.toString()), // NOI18N
ex);
// NOI18N
logger.throwing("JDOEJB20HelperImpl", "convertPCToEJBLocalObjectCtx", e);
throw e;
}
}
use of javax.ejb.EJBException in project Payara by payara.
the class ActiveTxCache method getEJBWithIncompleteTx.
// getReadyEJB(inv)
// called from releaseContext, afterCompletion
/**
* Get an EJB instance for this EJBObject and current client Tx
* Called only from getContext.
* Return null if there no INCOMPLETE_TX bean for the pkey & tx.
*/
private EntityContextImpl getEJBWithIncompleteTx(EjbInvocation inv) {
// We need to make sure that two concurrent client
// invocations with same primary key and same client tx
// get the SAME EJB instance.
// So we need to maintain exactly one copy of an EJB's state
// per transaction.
JavaEETransaction current = null;
try {
current = (JavaEETransaction) transactionManager.getTransaction();
} catch (SystemException ex) {
throw new EJBException(ex);
}
EntityContextImpl ctx = null;
if (current != null) {
ActiveTxCache activeTxCache = (ActiveTxCache) ejbContainerUtilImpl.getActiveTxCache(current);
ctx = (activeTxCache == null) ? null : activeTxCache.get(this, getInvocationKey(inv));
inv.foundInTxCache = (ctx != null);
}
return ctx;
}
use of javax.ejb.EJBException in project Payara by payara.
the class MessageBean method onMessage.
public void onMessage(Message message) {
System.out.println("Got message!!!");
QueueConnection connection = null;
try {
System.out.println("Calling hello1 stateless bean");
hello1.hello("local ejb3.0 stateless");
System.out.println("Calling hello2 stateful bean");
hello2.hello("local ejb3.0 stateful");
hello2.removeMethod();
try {
hello2.hello("this call should not go through");
throw new Exception("bean should have been removed " + "after removeMethod()");
} catch (NoSuchEJBException e) {
System.out.println("Successfully caught EJBException after " + " accessing removed SFSB");
}
connection = qcFactory.createQueueConnection();
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender sender = session.createSender(clientQueue);
TextMessage tmessage = session.createTextMessage();
tmessage.setText("mdb() invoked");
System.out.println("Sending message");
sender.send(tmessage);
System.out.println("message sent");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Aggregations