use of javax.ejb.EntityBean in project tomee by apache.
the class CmpContainer method homeMethod.
private Object homeMethod(final Method callMethod, final Object[] args, final ThreadContext callContext, final InterfaceType interfaceType) throws OpenEJBException {
final BeanContext beanContext = callContext.getBeanContext();
final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, interfaceType), callContext);
final EntityBean bean;
Object returnValue = null;
try {
/*
Obtain a bean instance from the method ready pool
*/
bean = createNewInstance(callContext);
// set the entity context
setEntityContext(bean);
try {
callContext.setCurrentOperation(Operation.HOME);
final Method runMethod = beanContext.getMatchingBeanMethod(callMethod);
try {
returnValue = runMethod.invoke(bean, args);
} catch (final IllegalArgumentException e) {
System.out.println("********************************************************");
System.out.println("callMethod = " + callMethod);
System.out.println("runMethod = " + runMethod);
System.out.println("bean = " + bean.getClass().getName());
throw e;
}
} finally {
unsetEntityContext(bean);
}
} catch (Throwable e) {
if (e instanceof InvocationTargetException) {
e = ((InvocationTargetException) e).getTargetException();
}
final ExceptionType type = callContext.getBeanContext().getExceptionType(e);
if (type == ExceptionType.SYSTEM) {
/* System Exception ****************************/
handleSystemException(txPolicy, e, callContext);
} else {
/* Application Exception ***********************/
handleApplicationException(txPolicy, e, type == ExceptionType.APPLICATION_ROLLBACK);
}
} finally {
afterInvoke(txPolicy, callContext);
}
return returnValue;
}
use of javax.ejb.EntityBean in project tomee by apache.
the class CmpContainer method removeEJBObject.
private void removeEJBObject(final Method callMethod, final ThreadContext callContext, final InterfaceType interfaceType) throws OpenEJBException {
final BeanContext beanContext = callContext.getBeanContext();
final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, interfaceType), callContext);
try {
final EntityBean entityBean = (EntityBean) cmpEngine.loadBean(callContext, callContext.getPrimaryKey());
if (entityBean == null) {
throw new NoSuchObjectException(callContext.getBeanContext().getDeploymentID() + " " + callContext.getPrimaryKey());
}
ejbRemove(entityBean);
cmpEngine.removeBean(callContext);
} catch (final NoSuchObjectException e) {
handleApplicationException(txPolicy, e, false);
} catch (final Throwable e) {
// handle reflection exception
handleSystemException(txPolicy, e, callContext);
} finally {
afterInvoke(txPolicy, callContext);
}
}
use of javax.ejb.EntityBean in project tomee by apache.
the class CmpContainer method findByPrimaryKey.
private Object findByPrimaryKey(final Method callMethod, final Object[] args, final ThreadContext callContext, final InterfaceType interfaceType) throws OpenEJBException {
final BeanContext beanContext = callContext.getBeanContext();
final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, interfaceType), callContext);
try {
final EntityBean bean = (EntityBean) cmpEngine.loadBean(callContext, args[0]);
if (bean == null) {
throw new ObjectNotFoundException(beanContext.getDeploymentID() + " : " + args[0]);
}
// rebuild the primary key
final KeyGenerator kg = beanContext.getKeyGenerator();
final Object primaryKey = kg.getPrimaryKey(bean);
// create a new ProxyInfo based on the deployment info and primary key
return new ProxyInfo(beanContext, primaryKey);
} catch (final FinderException fe) {
handleApplicationException(txPolicy, fe, false);
} catch (final Throwable e) {
// handle reflection exception
handleSystemException(txPolicy, e, callContext);
} finally {
afterInvoke(txPolicy, callContext);
}
throw new AssertionError("Should not get here");
}
use of javax.ejb.EntityBean in project tomee by apache.
the class Cmp2Util method getEntityBean.
public static <Bean extends EntityBean> Bean getEntityBean(final EJBLocalObject proxy) {
if (proxy == null) {
return null;
}
final EjbObjectProxyHandler handler = (EjbObjectProxyHandler) ProxyManager.getInvocationHandler(proxy);
if (handler.container == null) {
return null;
}
if (!(handler.container instanceof CmpContainer)) {
throw new IllegalArgumentException("Proxy is not connected to a CMP container but is conect to " + handler.container.getClass().getName());
}
final CmpContainer container = (CmpContainer) handler.container;
final Bean entity = (Bean) container.getEjbInstance(handler.getBeanContext(), handler.primaryKey);
return entity;
}
use of javax.ejb.EntityBean in project tomee by apache.
the class CmrSet method getEntityBeans.
private static <Bean extends EntityBean> Set<Bean> getEntityBeans(final Collection<?> proxies, final Class type) {
if (proxies == null) {
return null;
}
final Set<Bean> entities = new HashSet<Bean>();
for (final Object value : proxies) {
if (type != null && !type.isInstance(value)) {
throw new IllegalArgumentException("Object is not an instance of " + type.getName() + ": " + (value == null ? "null" : value.getClass().getName()));
}
final Bean entity = Cmp2Util.<Bean>getEntityBean((EJBLocalObject) value);
if (entity == null) {
throw new IllegalArgumentException("Entity has been deleted");
}
entities.add(entity);
}
return entities;
}
Aggregations