// Create and initialize a DAS connection and initialize for externally
// managed transaction boundaries
java.sql.Connection c = getConnection();
DAS das = DAS.FACTORY.createDAS(getConfig("passiveConnection.xml"), c);
// Read customer 1
Command select = das.getCommand("get a customer");
DataObject root = select.executeQuery();
DataObject customer = (DataObject) root.get("CUSTOMER[1]");
String lastName = customer.getString("LASTNAME");
// Modify customer
customer.set("LASTNAME", "Pavick");
try {
das.applyChanges(root);
throw new Exception("Test Exception");
// Since the DAS is not managing tx boundaries, I must
} catch (Exception e) {
// assert here to make sure we didn't run into some hidden error
assertEquals("Test Exception", e.getMessage());
// Roll back the transaction
c.rollback();
}
// Verify that the changes did not go through
root = select.executeQuery();
assertEquals(lastName, root.getString("CUSTOMER[1]/LASTNAME"));
// Try again
customer = (DataObject) root.get("CUSTOMER[1]");
customer.set("LASTNAME", "Pavick");
das.applyChanges(root);
c.commit();
root = select.executeQuery();
assertEquals("Pavick", root.getString("CUSTOMER[1]/LASTNAME"));
}