Properties attrs = new Properties();
attrs.setProperty("databaseName", "wombat");
attrs.setProperty("connectionAttributes", "create=true");
XADataSource dscsx = TestUtil.getXADataSource(attrs);
XAConnection xac = dscsx.getXAConnection("fred", "wilma");
XAResource xr = xac.getXAResource();
Xid xid = getXid(25, (byte) 21, (byte) 01);
Connection conn1 = xac.getConnection();
System.out.println("By default, autocommit is " + conn1.getAutoCommit() + " for a connection");
System.out.println("Default holdability for a connection is HOLD_CURSORS_OVER_COMMIT");
System.out.println("CONNECTION(not in xa transaction yet) HOLDABILITY " + (conn1.getHoldability() == ResultSet.HOLD_CURSORS_OVER_COMMIT));
//start a global transaction and default holdability and autocommit will be switched to match Derby XA restrictions
xr.start(xid, XAResource.TMNOFLAGS);
System.out.println("Notice that autocommit now is " + conn1.getAutoCommit() + " for connection because it is part of the global transaction");
System.out.println("Notice that connection's holdability at this point is CLOSE_CURSORS_AT_COMMIT because it is part of the global transaction");
System.out.println("CONNECTION(in xa transaction) HOLDABILITY " + (conn1.getHoldability() == ResultSet.HOLD_CURSORS_OVER_COMMIT));
xr.end(xid, XAResource.TMSUCCESS);
conn1.commit();
conn1.close();
xid = getXid(27, (byte) 21, (byte) 01);
xr.start(xid, XAResource.TMNOFLAGS);
conn1 = xac.getConnection();
System.out.println("CONNECTION(in xa transaction) HOLDABILITY " + (conn1.getHoldability() == ResultSet.HOLD_CURSORS_OVER_COMMIT));
System.out.println("Autocommit on Connection inside global transaction has been set correctly to " + conn1.getAutoCommit());
xr.end(xid, XAResource.TMSUCCESS);
conn1.rollback();
Connection conn = xac.getConnection();
conn.setAutoCommit(false);
conn.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
System.out.println("CONNECTION(non-xa) HOLDABILITY " + (conn.getHoldability() == ResultSet.HOLD_CURSORS_OVER_COMMIT));
Statement s = conn.createStatement();