use of javax.ejb.FinderException 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.FinderException in project tomee by apache.
the class EjbSelect method execute_int.
public static int execute_int(final Object obj, final String methodSignature, final Object... args) throws FinderException {
final BeanContext beanContext = (BeanContext) obj;
final Container container = beanContext.getContainer();
if (!(container instanceof CmpContainer)) {
throw new FinderException("Deployment is not connected to a CmpContainer " + beanContext.getDeploymentID());
}
final CmpContainer cmpContainer = (CmpContainer) container;
final Number result = (Number) cmpContainer.select(beanContext, methodSignature, "int", args);
return result.intValue();
}
use of javax.ejb.FinderException in project tomee by apache.
the class EjbSelect method execute_double.
public static double execute_double(final Object obj, final String methodSignature, final Object... args) throws FinderException {
final BeanContext beanContext = (BeanContext) obj;
final Container container = beanContext.getContainer();
if (!(container instanceof CmpContainer)) {
throw new FinderException("Deployment is not connected to a CmpContainer " + beanContext.getDeploymentID());
}
final CmpContainer cmpContainer = (CmpContainer) container;
final Number result = (Number) cmpContainer.select(beanContext, methodSignature, "double", args);
return result.doubleValue();
}
use of javax.ejb.FinderException in project tomee by apache.
the class EjbSelect method execute_boolean.
public static boolean execute_boolean(final Object obj, final String methodSignature, final Object... args) throws FinderException {
final BeanContext beanContext = (BeanContext) obj;
final Container container = beanContext.getContainer();
if (!(container instanceof CmpContainer)) {
throw new FinderException("Deployment is not connected to a CmpContainer " + beanContext.getDeploymentID());
}
final CmpContainer cmpContainer = (CmpContainer) container;
final Boolean result = (Boolean) cmpContainer.select(beanContext, methodSignature, "byte", args);
return result.booleanValue();
}
use of javax.ejb.FinderException in project tomee by apache.
the class JpaCmpEngine method executeUpdateQuery.
public int executeUpdateQuery(final BeanContext beanContext, final String signature, Object[] args) throws FinderException {
final EntityManager entityManager = getEntityManager(beanContext);
Query query = createNamedQuery(entityManager, signature);
if (query == null) {
final int parenIndex = signature.indexOf('(');
if (parenIndex > 0) {
final String shortName = signature.substring(0, parenIndex);
query = createNamedQuery(entityManager, shortName);
}
if (query == null) {
throw new FinderException("No query defined for method " + signature);
}
}
// process args
if (args == null) {
args = NO_ARGS;
}
for (int i = 0; i < args.length; i++) {
Object arg = args[i];
// ejb proxies need to be swapped out for real instance classes
if (arg instanceof EJBObject) {
arg = Cmp2Util.getEntityBean((EJBObject) arg);
}
if (arg instanceof EJBLocalObject) {
arg = Cmp2Util.getEntityBean((EJBLocalObject) arg);
}
query.setParameter(i + 1, arg);
}
final int result = query.executeUpdate();
return result;
}
Aggregations