use of jakarta.ejb.FinderException in project tomee by apache.
the class JpaCmpEngine method queryBeans.
public List<Object> queryBeans(final BeanContext beanContext, final String signature, final 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);
}
}
return executeSelectQuery(query, args);
}
use of jakarta.ejb.FinderException in project tomee by apache.
the class CmpContainer method findEJBObject.
private Object findEJBObject(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 List<Object> results = cmpEngine.queryBeans(callContext, callMethod, args);
final KeyGenerator kg = beanContext.getKeyGenerator();
// single ProxyInfo object is returned.
if (callMethod.getReturnType() == Collection.class || callMethod.getReturnType() == Enumeration.class) {
final List<ProxyInfo> proxies = new ArrayList<>();
for (final Object value : results) {
final EntityBean bean = (EntityBean) value;
if (value == null) {
proxies.add(null);
} else {
// get the primary key
final Object primaryKey = kg.getPrimaryKey(bean);
// create a new ProxyInfo based on the deployment info and primary key and add it to the vector
proxies.add(new ProxyInfo(beanContext, primaryKey));
}
}
if (callMethod.getReturnType() == Enumeration.class) {
return new Enumerator(proxies);
} else {
return proxies;
}
} else {
if (results.size() != 1) {
throw new ObjectNotFoundException("A Enteprise bean with deployment_id = " + beanContext.getDeploymentID() + (args != null && args.length >= 1 ? " and primarykey = " + args[0] : "") + " Does not exist");
}
// create a new ProxyInfo based on the deployment info and primary key
final EntityBean bean = (EntityBean) results.get(0);
if (bean == null) {
return null;
} else {
final Object primaryKey = kg.getPrimaryKey(bean);
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 jakarta.ejb.FinderException in project tomee by apache.
the class EjbSelect method execute_void.
/**
* Perform a select operation when the return value is
* a void. This one is slightly different from the
* rest, as the container operation performed is an
* update() rather than a select() because there's
* no value to return.
*
* @param obj The ejb object we're executing on behalf of.
* @param methodSignature The signature of the selectxxxx method being invoked.
* @param args The arguments to the select. These need to match
* the method signature.
* @throws FinderException
*/
public static void execute_void(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;
cmpContainer.update(beanContext, methodSignature, args);
}
use of jakarta.ejb.FinderException in project tomee by apache.
the class EjbSelect method execute_Object.
/**
* The single execution stub for all non-primitive
* select operations. This method has an additional
* returnType parameter used to instantiate the return
* value.
*
* @param obj The EJB object we're operating against.
* @param methodSignature The signature of the ejbSelectxxxx method.
* @param returnType The return type signature of the method.
* @param args The select arguments.
* @return An object of the specified type...which might be
* one of the collection types.
* @throws FinderException
*/
public static Object execute_Object(final Object obj, final String methodSignature, final String returnType, 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;
return cmpContainer.select(beanContext, methodSignature, returnType, args);
}
use of jakarta.ejb.FinderException in project tomee by apache.
the class EjbSelect method execute_short.
public static short execute_short(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, "short", args);
return result.shortValue();
}
Aggregations