Search in sources :

Example 1 with Account

use of org.apache.openejb.test.object.Account in project tomee by apache.

the class SingletonBeanTxTests method BUG_test06_singleTransactionRollback.

/**
     * This test does work for the IntraVM Server, but it fails on
     * the Remote Server.  For some reason, when the RollbackException is
     * sent to the client, the server blocks.
     */
public void BUG_test06_singleTransactionRollback() {
    final Account expected = new Account("234-56-7890", "Charlie", "Brown", 20000);
    final Account actual = new Account();
    // throw a RollbackException
    try {
        ejbObject.openAccount(expected, Boolean.TRUE);
        fail("A javax.transaction.RollbackException should have been thrown.");
    } catch (final RollbackException re) {
    // Good.
    } catch (final Exception e) {
        fail("Received Exception " + e.getClass() + " : " + e.getMessage());
    }
//// Now check that the account really wasn't added.
//try{
//    actual = ejbObject.retreiveAccount( expected.getSsn() );
//    //assertTrue( "The transaction was commited when it should have been rolledback.", !expected.equals(actual) );
//} catch (Exception e){
//    fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
//}
}
Also used : Account(org.apache.openejb.test.object.Account) RollbackException(javax.transaction.RollbackException) RollbackException(javax.transaction.RollbackException)

Example 2 with Account

use of org.apache.openejb.test.object.Account in project tomee by apache.

the class ContainerTxStatelessBean method retreiveAccount.

public Account retreiveAccount(final String ssn) {
    final Account acct = new Account();
    try {
        final DataSource ds = (DataSource) jndiContext.lookup("java:comp/env/database");
        final Connection con = ds.getConnection();
        try {
            final PreparedStatement stmt = con.prepareStatement("select * from Account where SSN = ?");
            try {
                stmt.setString(1, ssn);
                final ResultSet rs = stmt.executeQuery();
                if (!rs.next())
                    return null;
                acct.setSsn(rs.getString(1));
                acct.setFirstName(rs.getString(2));
                acct.setLastName(rs.getString(3));
                acct.setBalance(rs.getInt(4));
            } finally {
                stmt.close();
            }
        } finally {
            con.close();
        }
    } catch (final Exception e) {
    //throw new RemoteException("[Bean] "+e.getClass().getName()+" : "+e.getMessage());
    }
    return acct;
}
Also used : Account(org.apache.openejb.test.object.Account) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) EJBException(javax.ejb.EJBException) RollbackException(javax.transaction.RollbackException) CreateException(javax.ejb.CreateException) RemoteException(java.rmi.RemoteException) DataSource(javax.sql.DataSource)

Example 3 with Account

use of org.apache.openejb.test.object.Account in project tomee by apache.

the class BeanTxStatefulBean method retreiveAccount.

public Account retreiveAccount(final String ssn) throws RemoteException {
    final Account acct = new Account();
    try {
        final DataSource ds = (DataSource) jndiContext.lookup("java:comp/env/datasource");
        final Connection con = ds.getConnection();
        try {
            final PreparedStatement stmt = con.prepareStatement("select * from Account where SSN = ?");
            try {
                stmt.setString(1, ssn);
                final ResultSet rs = stmt.executeQuery();
                if (!rs.next())
                    return null;
                acct.setSsn(rs.getString(1));
                acct.setFirstName(rs.getString(2));
                acct.setLastName(rs.getString(3));
                acct.setBalance(rs.getInt(4));
            } finally {
                stmt.close();
            }
        } finally {
            con.close();
        }
    } catch (final Exception e) {
        e.printStackTrace();
        throw new RemoteException("[Bean] " + e.getClass().getName() + " : " + e.getMessage());
    }
    return acct;
}
Also used : Account(org.apache.openejb.test.object.Account) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) RemoteException(java.rmi.RemoteException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) RollbackException(javax.transaction.RollbackException) CreateException(javax.ejb.CreateException) DataSource(javax.sql.DataSource)

Example 4 with Account

use of org.apache.openejb.test.object.Account in project tomee by apache.

the class StatefulBeanTxTests method test05_singleTransactionCommit.

/**
     *
     */
public void test05_singleTransactionCommit() {
    try {
        final Account expected = new Account("123-45-6789", "Joe", "Cool", 40000);
        Account actual = new Account();
        ejbObject.openAccount(expected, Boolean.FALSE);
        actual = ejbObject.retreiveAccount(expected.getSsn());
        assertNotNull("The transaction was not commited.  The record is null", actual);
        assertEquals("The transaction was not commited cleanly.", expected, actual);
    } catch (final RollbackException re) {
        fail("Transaction was rolledback.  Received Exception " + re.getClass() + " : " + re.getMessage());
    } catch (final Exception e) {
        fail("Received Exception " + e.getClass() + " : " + e.getMessage());
    }
}
Also used : Account(org.apache.openejb.test.object.Account) RollbackException(javax.transaction.RollbackException) RollbackException(javax.transaction.RollbackException)

Example 5 with Account

use of org.apache.openejb.test.object.Account in project tomee by apache.

the class BeanTxSingletonBean method retreiveAccount.

public Account retreiveAccount(final String ssn) throws RemoteException {
    final Account acct = new Account();
    try {
        final DataSource ds = (DataSource) jndiContext.lookup("java:comp/env/database");
        final Connection con = ds.getConnection();
        try {
            final PreparedStatement stmt = con.prepareStatement("select * from Account where SSN = ?");
            try {
                stmt.setString(1, ssn);
                final ResultSet rs = stmt.executeQuery();
                if (!rs.next())
                    return null;
                acct.setSsn(rs.getString(1));
                acct.setFirstName(rs.getString(2));
                acct.setLastName(rs.getString(3));
                acct.setBalance(rs.getInt(4));
            } finally {
                stmt.close();
            }
        } finally {
            con.close();
        }
    } catch (final Exception e) {
        e.printStackTrace();
        throw new RemoteException("[Bean] " + e.getClass().getName() + " : " + e.getMessage());
    }
    return acct;
}
Also used : Account(org.apache.openejb.test.object.Account) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) RemoteException(java.rmi.RemoteException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) RollbackException(javax.transaction.RollbackException) CreateException(javax.ejb.CreateException) DataSource(javax.sql.DataSource)

Aggregations

RollbackException (javax.transaction.RollbackException)11 Account (org.apache.openejb.test.object.Account)11 RemoteException (java.rmi.RemoteException)5 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 ResultSet (java.sql.ResultSet)5 CreateException (javax.ejb.CreateException)5 EJBException (javax.ejb.EJBException)5 DataSource (javax.sql.DataSource)5