Search in sources :

Example 21 with FinderException

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

the class JpaCmpEngine method queryBeans.

public List<Object> queryBeans(final ThreadContext callContext, final Method queryMethod, final Object[] args) throws FinderException {
    final BeanContext deploymentInfo = callContext.getBeanContext();
    final EntityManager entityManager = getEntityManager(deploymentInfo);
    final StringBuilder queryName = new StringBuilder();
    queryName.append(deploymentInfo.getAbstractSchemaName()).append(".").append(queryMethod.getName());
    final String shortName = queryName.toString();
    if (queryMethod.getParameterTypes().length > 0) {
        queryName.append('(');
        boolean first = true;
        for (final Class<?> parameterType : queryMethod.getParameterTypes()) {
            if (!first) {
                queryName.append(',');
            }
            queryName.append(parameterType.getCanonicalName());
            first = false;
        }
        queryName.append(')');
    }
    final String fullName = queryName.toString();
    Query query = createNamedQuery(entityManager, fullName);
    if (query == null) {
        query = createNamedQuery(entityManager, shortName);
        if (query == null) {
            throw new FinderException("No query defined for method " + fullName);
        }
    }
    return executeSelectQuery(query, args);
}
Also used : BeanContext(org.apache.openejb.BeanContext) FinderException(javax.ejb.FinderException) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query)

Example 22 with FinderException

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

the class BasicBmp2DataSourcesBean method ejbFindByPrimaryKey.

/**
 * Maps to BasicBmp2DataSourcesHome.findByPrimaryKey
 *
 * @param primaryKey
 * @return Integer
 * @throws javax.ejb.FinderException
 */
public Integer ejbFindByPrimaryKey(final Integer primaryKey) throws javax.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 javax.ejb.ObjectNotFoundException();
}
Also used : FinderException(javax.ejb.FinderException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) InitialContext(javax.naming.InitialContext) RemoveException(javax.ejb.RemoveException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) FinderException(javax.ejb.FinderException) DataSource(javax.sql.DataSource)

Example 23 with FinderException

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

the class BasicBmpBean method ejbFindByPrimaryKey.

/**
 * Maps to BasicBmpHome.findByPrimaryKey
 *
 * @param primaryKey
 * @return
 * @throws javax.ejb.FinderException
 * @see BasicBmpHome#sum
 */
public Integer ejbFindByPrimaryKey(final Integer primaryKey) throws javax.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 javax.ejb.ObjectNotFoundException();
}
Also used : FinderException(javax.ejb.FinderException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) InitialContext(javax.naming.InitialContext) RemoveException(javax.ejb.RemoveException) NoSuchObjectException(java.rmi.NoSuchObjectException) NamingException(javax.naming.NamingException) RemoteException(java.rmi.RemoteException) ApplicationException(org.apache.openejb.test.ApplicationException) EJBException(javax.ejb.EJBException) SQLException(java.sql.SQLException) FinderException(javax.ejb.FinderException) NoSuchEntityException(javax.ejb.NoSuchEntityException) DataSource(javax.sql.DataSource)

Example 24 with FinderException

use of javax.ejb.FinderException in project Payara by payara.

the class TimerWrapper method getSchedule.

public ScheduleExpression getSchedule() throws java.lang.IllegalStateException, javax.ejb.NoSuchObjectLocalException, javax.ejb.EJBException {
    checkCallPermission();
    ScheduleExpression schedule;
    if (!isCalendarTimer()) {
        throw new IllegalStateException("Only allowed for calendar-based timers");
    }
    try {
        schedule = timerService_.getScheduleExpression(timerId_);
    } catch (FinderException fe) {
        throw new NoSuchObjectLocalException("timer no longer exists", fe);
    }
    return schedule;
}
Also used : NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException) ScheduleExpression(javax.ejb.ScheduleExpression) FinderException(javax.ejb.FinderException)

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