Search in sources :

Example 16 with FinderException

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");
}
Also used : BeanContext(org.apache.openejb.BeanContext) ProxyInfo(org.apache.openejb.ProxyInfo) FinderException(javax.ejb.FinderException) EntityBean(javax.ejb.EntityBean) ObjectNotFoundException(javax.ejb.ObjectNotFoundException) TransactionPolicy(org.apache.openejb.core.transaction.TransactionPolicy) EjbTransactionUtil.createTransactionPolicy(org.apache.openejb.core.transaction.EjbTransactionUtil.createTransactionPolicy) EJBLocalObject(javax.ejb.EJBLocalObject) EJBObject(javax.ejb.EJBObject)

Example 17 with FinderException

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();
}
Also used : BeanContext(org.apache.openejb.BeanContext) FinderException(javax.ejb.FinderException) CmpContainer(org.apache.openejb.core.cmp.CmpContainer) Container(org.apache.openejb.Container) CmpContainer(org.apache.openejb.core.cmp.CmpContainer)

Example 18 with FinderException

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();
}
Also used : BeanContext(org.apache.openejb.BeanContext) FinderException(javax.ejb.FinderException) CmpContainer(org.apache.openejb.core.cmp.CmpContainer) Container(org.apache.openejb.Container) CmpContainer(org.apache.openejb.core.cmp.CmpContainer)

Example 19 with FinderException

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();
}
Also used : BeanContext(org.apache.openejb.BeanContext) FinderException(javax.ejb.FinderException) CmpContainer(org.apache.openejb.core.cmp.CmpContainer) Container(org.apache.openejb.Container) CmpContainer(org.apache.openejb.core.cmp.CmpContainer)

Example 20 with FinderException

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;
}
Also used : FinderException(javax.ejb.FinderException) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) EJBObject(javax.ejb.EJBObject) EJBObject(javax.ejb.EJBObject) EJBLocalObject(javax.ejb.EJBLocalObject) EJBLocalObject(javax.ejb.EJBLocalObject)

Aggregations

FinderException (javax.ejb.FinderException)24 BeanContext (org.apache.openejb.BeanContext)14 Container (org.apache.openejb.Container)10 CmpContainer (org.apache.openejb.core.cmp.CmpContainer)10 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 InitialContext (javax.naming.InitialContext)5 EJBException (javax.ejb.EJBException)4 EJBLocalObject (javax.ejb.EJBLocalObject)4 EJBObject (javax.ejb.EJBObject)4 RemoteException (java.rmi.RemoteException)3 ResultSet (java.sql.ResultSet)3 EntityBean (javax.ejb.EntityBean)3 NoSuchObjectLocalException (javax.ejb.NoSuchObjectLocalException)3 ObjectNotFoundException (javax.ejb.ObjectNotFoundException)3 RemoveException (javax.ejb.RemoveException)3 EntityManager (javax.persistence.EntityManager)3 Query (javax.persistence.Query)3 DataSource (javax.sql.DataSource)3 NoSuchObjectException (java.rmi.NoSuchObjectException)2