Search in sources :

Example 16 with FinderException

use of jakarta.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(jakarta.ejb.FinderException) EntityManager(jakarta.persistence.EntityManager) Query(jakarta.persistence.Query) EJBObject(jakarta.ejb.EJBObject) EJBLocalObject(jakarta.ejb.EJBLocalObject) EJBObject(jakarta.ejb.EJBObject) EJBLocalObject(jakarta.ejb.EJBLocalObject)

Example 17 with FinderException

use of jakarta.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;
}
Also used : BeanContext(org.apache.openejb.BeanContext) FinderException(jakarta.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 jakarta.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(jakarta.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 jakarta.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(jakarta.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 jakarta.ejb.FinderException in project tomee by apache.

the class BasicBmp2DataSourcesBean method ejbFindByPrimaryKey.

/**
 * Maps to BasicBmp2DataSourcesHome.findByPrimaryKey
 *
 * @param primaryKey
 * @return Integer
 * @throws jakarta.ejb.FinderException
 */
public Integer ejbFindByPrimaryKey(final Integer primaryKey) throws jakarta.ejb.FinderException {
    boolean found = false;
    try {
        final InitialContext jndiContext = new InitialContext();
        final DataSource ds = (DataSource) jndiContext.lookup("java:comp/env/jdbc/basic/entityDatabase");
        final Connection con = ds.getConnection();
        try {
            final PreparedStatement stmt = con.prepareStatement("select * from entity where id = ?");
            try {
                stmt.setInt(1, primaryKey.intValue());
                found = stmt.executeQuery().next();
            } finally {
                stmt.close();
            }
        } finally {
            con.close();
        }
    } catch (final Exception e) {
        throw new FinderException("FindByPrimaryKey failed");
    }
    if (found)
        return primaryKey;
    else
        throw new jakarta.ejb.ObjectNotFoundException();
}
Also used : FinderException(jakarta.ejb.FinderException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) InitialContext(javax.naming.InitialContext) FinderException(jakarta.ejb.FinderException) RemoteException(java.rmi.RemoteException) RemoveException(jakarta.ejb.RemoveException) EJBException(jakarta.ejb.EJBException) DataSource(javax.sql.DataSource)

Aggregations

FinderException (jakarta.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 (jakarta.ejb.EJBException)4 EJBLocalObject (jakarta.ejb.EJBLocalObject)4 EJBObject (jakarta.ejb.EJBObject)4 EntityBean (jakarta.ejb.EntityBean)3 ObjectNotFoundException (jakarta.ejb.ObjectNotFoundException)3 RemoveException (jakarta.ejb.RemoveException)3 EntityManager (jakarta.persistence.EntityManager)3 Query (jakarta.persistence.Query)3 RemoteException (java.rmi.RemoteException)3 ResultSet (java.sql.ResultSet)3 DataSource (javax.sql.DataSource)3 NoSuchEntityException (jakarta.ejb.NoSuchEntityException)2 NoSuchObjectException (java.rmi.NoSuchObjectException)2