Search in sources :

Example 6 with RemoveException

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

the class BasicBmpBean method ejbRemove.

/**
 * A container invokes this method before it removes the EJB object
 * that is currently associated with the instance. This method
 * is invoked when a client invokes a remove operation on the
 * enterprise Bean's home interface or the EJB object's remote interface.
 * This method transitions the instance from the ready state to the pool
 * of available instances.
 */
public void ejbRemove() throws RemoveException, EJBException, RemoteException {
    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("delete from entity where id = ?");
            try {
                stmt.setInt(1, primaryKey);
                stmt.executeUpdate();
            } finally {
                stmt.close();
            }
        } finally {
            con.close();
        }
    } catch (final Exception e) {
        e.printStackTrace();
        throw new jakarta.ejb.EJBException(e);
    }
}
Also used : Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) EJBException(jakarta.ejb.EJBException) 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

RemoveException (jakarta.ejb.RemoveException)6 EJBException (jakarta.ejb.EJBException)3 FinderException (jakarta.ejb.FinderException)3 RemoteException (java.rmi.RemoteException)3 ApplicationException (org.apache.openejb.ApplicationException)3 ThreadContext (org.apache.openejb.core.ThreadContext)3 EJBHome (jakarta.ejb.EJBHome)2 EJBLocalHome (jakarta.ejb.EJBLocalHome)2 SessionBean (jakarta.ejb.SessionBean)2 Method (java.lang.reflect.Method)2 NoSuchObjectException (java.rmi.NoSuchObjectException)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 InitialContext (javax.naming.InitialContext)2 DataSource (javax.sql.DataSource)2 BeanContext (org.apache.openejb.BeanContext)2 InvalidateReferenceException (org.apache.openejb.InvalidateReferenceException)2 InterceptorData (org.apache.openejb.core.interceptor.InterceptorData)2 InterceptorStack (org.apache.openejb.core.interceptor.InterceptorStack)2 BeanTransactionPolicy (org.apache.openejb.core.transaction.BeanTransactionPolicy)2