Search in sources :

Example 21 with FinderException

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

the class BasicBmpBean method ejbFindByPrimaryKey.

/**
 * Maps to BasicBmpHome.findByPrimaryKey
 *
 * @param primaryKey
 * @return
 * @throws jakarta.ejb.FinderException
 * @see BasicBmpHome#sum
 */
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) NoSuchObjectException(java.rmi.NoSuchObjectException) FinderException(jakarta.ejb.FinderException) NamingException(javax.naming.NamingException) RemoteException(java.rmi.RemoteException) ApplicationException(org.apache.openejb.test.ApplicationException) SQLException(java.sql.SQLException) NoSuchEntityException(jakarta.ejb.NoSuchEntityException) 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