use of javax.transaction.RollbackException in project tomee by apache.
the class ContainerTxSingletonBean method openAccount.
public void openAccount(final Account acct, final Boolean rollback) throws RollbackException {
try {
final DataSource ds = (DataSource) jndiContext.lookup("java:comp/env/database");
final Connection con = ds.getConnection();
try {
/*[2] Update the table */
final PreparedStatement stmt = con.prepareStatement("insert into Account (SSN, First_name, Last_name, Balance) values (?,?,?,?)");
try {
stmt.setString(1, acct.getSsn());
stmt.setString(2, acct.getFirstName());
stmt.setString(3, acct.getLastName());
stmt.setInt(4, acct.getBalance());
stmt.executeUpdate();
} finally {
stmt.close();
}
} finally {
con.close();
}
} catch (final Exception e) {
//throw new RemoteException("[Bean] "+e.getClass().getName()+" : "+e.getMessage());
}
}
use of javax.transaction.RollbackException in project tomee by apache.
the class StatefulBeanTxTests 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());
//}
}
use of javax.transaction.RollbackException in project tomee by apache.
the class TransactionRollbackCauseTest method test.
public void test() throws Exception {
final Map<String, Object> map = new HashMap<String, Object>();
map.put(EJBContainer.MODULES, new SingletonBean(Orange.class));
EJBContainer.createEJBContainer(map).getContext().bind("inject", this);
userTransaction.begin();
orange.exceptionRollback();
try {
userTransaction.commit();
fail("transaction should have been rolled back");
} catch (final RollbackException e) {
final Throwable throwable = e.getCause();
assertTrue(throwable instanceof UserException);
}
}
use of javax.transaction.RollbackException in project tomee by apache.
the class StatelessBeanTxTests 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());
//}
}
use of javax.transaction.RollbackException in project tomee by apache.
the class StatelessBeanTxTests 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());
}
}
Aggregations