Search in sources :

Example 6 with FinderException

use of javax.ejb.FinderException in project tomee by apache.

the class EjbSelect method execute_float.

public static float execute_float(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, "float", args);
    return result.floatValue();
}
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 7 with FinderException

use of javax.ejb.FinderException in project tomee by apache.

the class EjbSelect method execute_byte.

public static byte execute_byte(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, "byte", args);
    return result.byteValue();
}
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 8 with FinderException

use of javax.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);
}
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 9 with FinderException

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

Example 10 with FinderException

use of javax.ejb.FinderException in project tomee by apache.

the class EmployeeBean method ejbFindAll.

public java.util.Collection ejbFindAll() throws FinderException {
    try {
        final InitialContext jndiContext = new InitialContext();
        final javax.sql.DataSource ds = (javax.sql.DataSource) jndiContext.lookup("java:comp/env/jdbc/orders");
        final Connection con = ds.getConnection();
        java.util.Vector keys;
        try {
            final Statement stmt = con.createStatement();
            try {
                final ResultSet rs = stmt.executeQuery("select EmployeeID from Employees");
                keys = new java.util.Vector();
                while (rs.next()) {
                    keys.addElement(new Integer(rs.getInt("EmployeeID")));
                }
            } finally {
                stmt.close();
            }
        } finally {
            con.close();
        }
        return keys;
    } catch (final Exception e) {
        e.printStackTrace();
        throw new FinderException("FindAll failed");
    }
}
Also used : Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) Connection(java.sql.Connection) InitialContext(javax.naming.InitialContext) FinderException(javax.ejb.FinderException) FinderException(javax.ejb.FinderException) ResultSet(java.sql.ResultSet)

Aggregations

FinderException (javax.ejb.FinderException)21 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 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 SQLException (java.sql.SQLException)2