db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r521854 [1/2] - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/master/ functionTests/master/DerbyNetClient/jdk14/ functionTests/suites/ functionTests/tests/jdbcapi/ functionTests/util/ junit/
Date Fri, 23 Mar 2007 18:38:29 GMT
Author: kmarsden
Date: Fri Mar 23 11:38:28 2007
New Revision: 521854

URL: http://svn.apache.org/viewvc?view=rev&rev=521854
Log:
DERBY-2474: Convert jdbcapi/XATest.java to junit


Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XATestUtil.java
      - copied, changed from r520630, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/XATestUtil.java
Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/XATest.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/XATest.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/XATestUtil.java
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientUseprocess.exclude
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetclientmats.runall
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/xa.runall
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/J2EEDataSource.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientUseprocess.exclude
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientUseprocess.exclude?view=diff&rev=521854&r1=521853&r2=521854
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientUseprocess.exclude (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientUseprocess.exclude Fri Mar 23 11:38:28 2007
@@ -1,4 +1,3 @@
-# DerbyNetClientUseprocess.exclude
 # identifies tests that fail when run in a suite with useprocess=false with DerbyNetClient 
 #
 # jdbcapi/HoldabilityTest.junit - test causes subsequent tests to fail because of missing

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetclientmats.runall
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetclientmats.runall?view=diff&rev=521854&r1=521853&r2=521854
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetclientmats.runall (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetclientmats.runall Fri Mar 23 11:38:28 2007
@@ -1,5 +1,4 @@
 junitTests/derbyNet/CompatibilityTest.java
 jdbcapi/xaSimplePositive.sql
 jdbcapi/xaStateTran.sql
-jdbcapi/XATest.java
 jdbcapi/checkDataSource.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/xa.runall
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/xa.runall?view=diff&rev=521854&r1=521853&r2=521854
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/xa.runall (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/xa.runall Fri Mar 23 11:38:28 2007
@@ -4,7 +4,6 @@
 jdbcapi/xaSimplePositive.sql
 jdbcapi/xaSimpleNegative.sql
 jdbcapi/xaStateTran.sql
-jdbcapi/XATest.java
 jdbcapi/xaMorph.sql
 store/xaOffline1.sql
 store/xab2354.sql

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATest.java?view=diff&rev=521854&r1=521853&r2=521854
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATest.java Fri Mar 23 11:38:28 2007
@@ -1,22 +1,22 @@
-/*
-
- Derby - Class org.apache.derby.impl.services.bytecode.CodeChunk
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements.  See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License.  You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
+/**
+ *  Derby - Class org.apache.derbyTesting.functionTests.tests.jdbapi.XATest
+ *  
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
  */
 
 package org.apache.derbyTesting.functionTests.tests.jdbcapi;
@@ -25,11 +25,9 @@
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.sql.SQLWarning;
 import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.Iterator;
-import java.util.Properties;
 
 import javax.sql.XAConnection;
 import javax.sql.XADataSource;
@@ -37,98 +35,28 @@
 import javax.transaction.xa.XAResource;
 import javax.transaction.xa.Xid;
 
-import org.apache.derby.tools.JDBCDisplayUtil;
-import org.apache.derby.tools.ij;
-import org.apache.derbyTesting.functionTests.util.TestUtil;
-import org.apache.derbyTesting.functionTests.util.XATestUtil;
+import junit.framework.Test;
+import junit.framework.TestSuite;
 
-/**
- * XATests harvested from SQL XA tests.
- * Modified so that they can be run with NetworkServer.
- */
-public class XATest {
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.J2EEDataSource;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.TestConfiguration;
+import org.apache.derbyTesting.junit.XATestUtil;
 
-    /**
-     * Run all the tests.
-     */
-    public static void main(String[] args) throws Exception {
-        ij.getPropertyArg(args);
-        Connection dmc = ij.startJBMS();
-        
-        showHoldStatus("initial ", dmc);
-        
-        XATestUtil.createXATransactionView(dmc);
-        dmc.close();
-
-        XADataSource dsx = TestUtil.getXADataSource(cleanProperties());
-
-        // tests originally from xaSimplePositive.sql
-        singleConnectionOnePhaseCommit(dsx);
-        xaShutdown();
-        interleavingTransactions(dsx);
-
-        xaShutdown();
-
-        // tests originally from xaStateTran.sql
-        noTransaction(dsx);
-
-        // test originally from xaMorph.sql
-        morph(dsx);
-        
-        // DERBY-966 holdability testing
-        derby966(dsx);
-
-        // for cleaning up, make a clean new connection
-        Connection dmc2 = ij.startJBMS();
-        cleanUp(dmc2);
+public class XATest extends BaseJDBCTestCase {
 
-        System.out.println("XATest complete");
-    }
+    public XATest(String name) {
+        super(name);
 
-    /**
-     * Get the basic set of properties for an XADataSource.
-     * Only sets databaseName to wombat.
-     */
-    private static Properties cleanProperties() {
-        Properties dsAttrs = new Properties();
-        dsAttrs.setProperty("databaseName", "wombat");
-        return dsAttrs;
     }
 
     /**
-     * Shutdown the database through an XADataSource.
-     */
-    private static void xaShutdown() {
-
-        Properties dsAttrs = cleanProperties();
-
-        if (TestUtil.isEmbeddedFramework())
-            dsAttrs.put("shutdownDatabase", "shutdown");
-        else
-            dsAttrs.put("connectionAttributes", "shutdown=true");
-
-        XADataSource dsx = TestUtil.getXADataSource(dsAttrs);
-
-        try {
-            dsx.getXAConnection().getConnection();
-        } catch (SQLException sqle) {
-            if ("08006".equals(sqle.getSQLState()))
-                return;
-            TestUtil.dumpSQLExceptions(sqle);
-        }
-        System.out.println("FAIL: no exception on shutdown");
-    }
-
-    /*
-     ** Test cases
-     */
-
-    /**
      * A single connection and 1 phase commit.
      * 
-     
-     Original "SQL" from xaSimplePositive.sql
-     <code>
+     * 
+     * Original "SQL" from xaSimplePositive.sql <code>
      xa_connect ;
      xa_start xa_noflags 0;
      xa_getconnection;
@@ -143,235 +71,217 @@
      
      xa_datasource 'wombat' shutdown;
      </code>
-     * @throws SQLException 
-     * @throws XAException 
+     * 
+     * @throws SQLException
+     * @throws XAException
+     * @throws XAException
      */
-    private static void singleConnectionOnePhaseCommit(XADataSource xads) {
-        System.out.println("singleConnectionOnePhaseCommit");
-        try {
-            XAConnection xac = xads.getXAConnection();
+    public void testSingleConnectionOnePhaseCommit() throws SQLException,
+            XAException {
 
-            XAResource xar = xac.getXAResource();
+        XADataSource xads = J2EEDataSource.getXADataSource();
+        J2EEDataSource.setBeanProperty(xads, "databaseName", "wombat");
 
-            Xid xid = XATestUtil.getXid(0, 32, 46);
+        XAConnection xac = xads.getXAConnection();
 
-            xar.start(xid, XAResource.TMNOFLAGS);
+        XAResource xar = xac.getXAResource();
 
-            Connection conn = xac.getConnection();
-            
-            showHoldStatus("XA ", conn);
+        Xid xid = XATestUtil.getXid(0, 32, 46);
 
-            Statement s = conn.createStatement();
-            showHoldStatus("XA ", s);
+        xar.start(xid, XAResource.TMNOFLAGS);
 
-            s.execute("create table foo (a int)");
-            s.executeUpdate("insert into foo values (0)");
+        Connection conn = xac.getConnection();
+        assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, conn.getHoldability());
 
-            ResultSet rs = s.executeQuery("select * from foo");
-            JDBCDisplayUtil.DisplayResults(System.out, rs, conn);
-            rs.close();
+        Statement s = conn.createStatement();
+        assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, s
+                .getResultSetHoldability());
 
-            XATestUtil.showXATransactionView(conn);
+        s.execute("create table foo (a int)");
+        s.executeUpdate("insert into foo values (0)");
 
-            s.close();
-            xar.end(xid, XAResource.TMSUCCESS);
+        ResultSet rs = s.executeQuery("select * from foo");
+        JDBC.assertDrainResults(rs, 1);
 
-            // 1 phase commit
-            xar.commit(xid, true);
+        String[][] expectedRows = { { "(0", "ACTIVE", "false", "APP",
+                "UserTransaction" } };
 
-            conn.close();
-            xac.close();
+        XATestUtil.checkXATransactionView(conn, expectedRows);
+
+        s.close();
+        xar.end(xid, XAResource.TMSUCCESS);
+
+        // 1 phase commit
+        xar.commit(xid, true);
+
+        conn.close();
+        xac.close();
 
-        } catch (SQLException sqle) {
-            TestUtil.dumpSQLExceptions(sqle);
-            sqle.printStackTrace(System.out);
-        } catch (XAException e) {
-            XATestUtil.dumpXAException("singleConnectionOnePhaseCommit", e);
-        }
     }
 
     /*
      * Two interleaving transaction and prepare/commit prepare/rollback.
      * 
      * (original test said two connections but only one connection was opened)
-
-     <code>
-     xa_datasource 'wombat';
-     xa_connect user 'sku' password 'testxa' ;
-
-     xa_start xa_noflags 1;
-     xa_getconnection;
-     insert into APP.foo values (1);
-     xa_end xa_suspend 1;
-
-     xa_start xa_noflags 2;
-     insert into APP.foo values (2);
-     xa_end xa_suspend 2;
-
-     xa_start xa_resume 1;
-     insert into APP.foo values (3);
-     xa_end xa_suspend 1;
-
-     xa_start xa_resume 2;
-     insert into APP.foo values (4);
-     select * from APP.global_xactTable where gxid is not null order by gxid;
-     -- this prepare won't work since transaction 1 has been suspended - XA_PROTO
-     xa_prepare 1;
-
-     select * from APP.global_xactTable where gxid is not null order by gxid;
-     xa_end xa_success 2;
-
-     -- this assumes a resume
-     xa_end xa_success 1;
-     xa_prepare 1;
-     xa_prepare 2;
-
-     -- both transactions should be prepared
-     select * from APP.global_xactTable where gxid is not null order by gxid;
-
-     -- NOTE: The following call to "xa_recover xa_startrscan" is apt to
-     -- return the result set rows in reverse order when changes to
-     -- the Derby engine affect the number of transactions that it takes
-     -- to create a database.  The transactions are stored in a hash table
-     -- based on a global and local id, and when the number of transactions
-     -- changes, the (internal) local id can change, which may lead to a
-     -- change in the result set order.  This order is determined by the
-     -- JVM's hashing algorithm. Examples of changes to the engine that
-     -- can affect this include ones that cause more commits or that
-     -- change the amount of data being stored, such as changes to the
-     -- metadata statements (which is what prompted this explanation in
-     -- the first place).  Ultimately, the problem is that there is no
-     -- way to order the return values from "xa_recover" since it is an
-     -- ij internal statement, not SQL...
-     xa_recover xa_startrscan;
-     xa_recover xa_noflags;
-
-     xa_commit xa_2Phase 1;
-     xa_rollback 2;
-
-     -- check results
-     xa_start xa_noflags 3;
-     select * from APP.global_xactTable where gxid is not null order by gxid;
-     select * from APP.foo;
-     xa_end xa_success 3;
-
-     xa_prepare 3;
-
-     -- should fail with XA_NOTA because we prepared a read only transaction 
-     xa_commit xa_1Phase 3;
-     disconnect;
-     </code>
+     * 
+     * <code> xa_datasource 'wombat'; xa_connect user 'sku' password 'testxa' ;
+     * 
+     * xa_start xa_noflags 1; xa_getconnection; insert into APP.foo values (1);
+     * xa_end xa_suspend 1;
+     * 
+     * xa_start xa_noflags 2; insert into APP.foo values (2); xa_end xa_suspend
+     * 2;
+     * 
+     * xa_start xa_resume 1; insert into APP.foo values (3); xa_end xa_suspend
+     * 1;
+     * 
+     * xa_start xa_resume 2; insert into APP.foo values (4); select * from
+     * APP.global_xactTable where gxid is not null order by gxid; -- this
+     * prepare won't work since transaction 1 has been suspended - XA_PROTO
+     * xa_prepare 1;
+     * 
+     * select * from APP.global_xactTable where gxid is not null order by gxid;
+     * xa_end xa_success 2; -- this assumes a resume xa_end xa_success 1;
+     * xa_prepare 1; xa_prepare 2; -- both transactions should be prepared
+     * select * from APP.global_xactTable where gxid is not null order by gxid; --
+     * NOTE: The following call to "xa_recover xa_startrscan" is apt to --
+     * return the result set rows in reverse order when changes to -- the Derby
+     * engine affect the number of transactions that it takes -- to create a
+     * database. The transactions are stored in a hash table -- based on a
+     * global and local id, and when the number of transactions -- changes, the
+     * (internal) local id can change, which may lead to a -- change in the
+     * result set order. This order is determined by the -- JVM's hashing
+     * algorithm. Examples of changes to the engine that -- can affect this
+     * include ones that cause more commits or that -- change the amount of data
+     * being stored, such as changes to the -- metadata statements (which is
+     * what prompted this explanation in -- the first place). Ultimately, the
+     * problem is that there is no -- way to order the return values from
+     * "xa_recover" since it is an -- ij internal statement, not SQL...
+     * xa_recover xa_startrscan; xa_recover xa_noflags;
+     * 
+     * xa_commit xa_2Phase 1; xa_rollback 2; -- check results xa_start
+     * xa_noflags 3; select * from APP.global_xactTable where gxid is not null
+     * order by gxid; select * from APP.foo; xa_end xa_success 3;
+     * 
+     * xa_prepare 3; -- should fail with XA_NOTA because we prepared a read only
+     * transaction xa_commit xa_1Phase 3; disconnect; </code>
      */
-    private static void interleavingTransactions(XADataSource xads) {
-        System.out.println("interleavingTransactions");
-        try {
-            XAConnection xac = xads.getXAConnection("sku", "testxa");
-            XAResource xar = xac.getXAResource();
+    public void testInterleavingTransactions() throws SQLException, XAException {
+        XADataSource xads = J2EEDataSource.getXADataSource();
 
-            Xid xid1 = XATestUtil.getXid(1, 93, 18);
-            Xid xid2 = XATestUtil.getXid(2, 45, 77);
+        XAConnection xac = xads.getXAConnection("sku", "testxa");
+        XAResource xar = xac.getXAResource();
 
-            xar.start(xid1, XAResource.TMNOFLAGS);
+        Xid xid1 = XATestUtil.getXid(1, 93, 18);
+        Xid xid2 = XATestUtil.getXid(2, 45, 77);
 
-            Connection conn = xac.getConnection();
+        xar.start(xid1, XAResource.TMNOFLAGS);
 
-            Statement s = conn.createStatement();
-            s.executeUpdate("insert into APP.foo values (1)");
-            xar.end(xid1, XAResource.TMSUSPEND);
+        Connection conn = xac.getConnection();
 
-            xar.start(xid2, XAResource.TMNOFLAGS);
-            s.executeUpdate("insert into APP.foo values (2)");
-            xar.end(xid2, XAResource.TMSUSPEND);
+        Statement s = conn.createStatement();
+        s.executeUpdate("insert into APP.foo values (1)");
+        xar.end(xid1, XAResource.TMSUSPEND);
 
-            xar.start(xid1, XAResource.TMRESUME);
-            s.executeUpdate("insert into APP.foo values (3)");
-            xar.end(xid1, XAResource.TMSUSPEND);
+        xar.start(xid2, XAResource.TMNOFLAGS);
+        s.executeUpdate("insert into APP.foo values (2)");
+        xar.end(xid2, XAResource.TMSUSPEND);
 
-            xar.start(xid2, XAResource.TMRESUME);
-            s.executeUpdate("insert into APP.foo values (4)");
+        xar.start(xid1, XAResource.TMRESUME);
+        s.executeUpdate("insert into APP.foo values (3)");
+        xar.end(xid1, XAResource.TMSUSPEND);
 
-            XATestUtil.showXATransactionView(conn);
+        xar.start(xid2, XAResource.TMRESUME);
+        s.executeUpdate("insert into APP.foo values (4)");
 
-            // this prepare won't work since
-            // transaction 1 has been suspended - XA_PROTO
-            try {
-                xar.prepare(xid1);
-                System.out.println("FAIL - prepare on suspended transaction");
-            } catch (XAException e) {
-                if (e.errorCode != XAException.XAER_PROTO)
-                    XATestUtil.dumpXAException(
-                            "FAIL - prepare on suspended transaction", e);
+        String[][] expectedRows = {
+                { "(1", "ACTIVE", "false", "SKU", "UserTransaction" },
+                { "(2", "ACTIVE", "false", "SKU", "UserTransaction" } };
 
-            }
+        XATestUtil.checkXATransactionView(conn, expectedRows);
+
+        // this prepare won't work since
+        // transaction 1 has been suspended - XA_PROTO
+        try {
+            xar.prepare(xid1);
+            fail("FAIL - prepare on suspended transaction");
+        } catch (XAException e) {
+            if (e.errorCode != XAException.XAER_PROTO)
+                XATestUtil.dumpXAException(
+                        "FAIL - prepare on suspended transaction", e);
 
-            // check it was not prepared
-            XATestUtil.showXATransactionView(conn);
+        }
 
-            xar.end(xid2, XAResource.TMSUCCESS);
+        // check it was not prepared
 
-            xar.end(xid1, XAResource.TMSUCCESS);
+        XATestUtil.checkXATransactionView(conn, expectedRows);
 
-            xar.prepare(xid1);
-            xar.prepare(xid2);
+        xar.end(xid2, XAResource.TMSUCCESS);
 
-            // both should be prepared.
-            XATestUtil.showXATransactionView(conn);
+        xar.end(xid1, XAResource.TMSUCCESS);
 
-            Xid[] recoveredStart = xar.recover(XAResource.TMSTARTRSCAN);
-            System.out.println("recovered start " + recoveredStart.length);
-            Xid[] recovered = xar.recover(XAResource.TMNOFLAGS);
-            System.out.println("recovered " + recovered.length);
-            Xid[] recoveredEnd = xar.recover(XAResource.TMENDRSCAN);
-            System.out.println("recovered end " + recoveredEnd.length);
-
-            for (int i = 0; i < recoveredStart.length; i++) {
-                Xid xid = recoveredStart[i];
-                if (xid.getFormatId() == 1) {
-                    // commit 1 with 2pc
-                    xar.commit(xid, false);
-                } else if (xid.getFormatId() == 2) {
-                    xar.rollback(xid);
-                } else {
-                    System.out.println("FAIL: unknown xact");
-                }
+        xar.prepare(xid1);
+        xar.prepare(xid2);
+
+        // both should be prepared.
+        expectedRows = new String[][] {
+                { "(1", "PREPARED", "false", "SKU", "UserTransaction" },
+                { "(2", "PREPARED", "false", "SKU", "UserTransaction" } };
+
+        XATestUtil.checkXATransactionView(conn, expectedRows);
+
+        Xid[] recoveredStart = xar.recover(XAResource.TMSTARTRSCAN);
+        assertEquals(2, recoveredStart.length);
+        Xid[] recovered = xar.recover(XAResource.TMNOFLAGS);
+        assertEquals(0, recovered.length);
+        Xid[] recoveredEnd = xar.recover(XAResource.TMENDRSCAN);
+        assertEquals(0, recoveredEnd.length);
+
+        for (int i = 0; i < recoveredStart.length; i++) {
+            Xid xid = recoveredStart[i];
+            if (xid.getFormatId() == 1) {
+                // commit 1 with 2pc
+                xar.commit(xid, false);
+            } else if (xid.getFormatId() == 2) {
+                xar.rollback(xid);
+            } else {
+                fail("FAIL: unknown xact");
             }
+        }
 
-            // check the results
-            Xid xid3 = XATestUtil.getXid(3, 2, 101);
-            xar.start(xid3, XAResource.TMNOFLAGS);
-            XATestUtil.showXATransactionView(conn);
-            ResultSet rs = s.executeQuery("select * from APP.foo");
-            JDBCDisplayUtil.DisplayResults(System.out, rs, conn);
-            rs.close();
-            xar.end(xid3, XAResource.TMSUCCESS);
-
-            int pr = xar.prepare(xid3);
-            if (pr != XAResource.XA_RDONLY)
-                System.out.println("FAIL - prepare on read only xact returned "
-                        + pr);
+        // check the results
+        Xid xid3 = XATestUtil.getXid(3, 2, 101);
+        xar.start(xid3, XAResource.TMNOFLAGS);
+        expectedRows = new String[][] { { "(3", "IDLE", "NULL", "SKU",
+                "UserTransaction" } };
+        XATestUtil.checkXATransactionView(conn, expectedRows);
+        ResultSet rs = s.executeQuery("select * from APP.foo");
+        expectedRows = new String[][] { { "0" }, { "1" }, { "3" } };
+        JDBC.assertFullResultSet(rs, expectedRows);
 
-            try {
-                xar.commit(xid3, true);
-                System.out.println("FAIL - 2pc commit on read-only xact");
-            } catch (XAException e) {
-                if (e.errorCode != XAException.XAER_NOTA)
-                    throw e;
-            }
+        rs.close();
+        xar.end(xid3, XAResource.TMSUCCESS);
 
-            s.close();
-            conn.close();
-            xac.close();
-        } catch (SQLException sqle) {
-            TestUtil.dumpSQLExceptions(sqle);
+        int pr = xar.prepare(xid3);
+        if (pr != XAResource.XA_RDONLY)
+            fail("FAIL - prepare on read only xact returned " + pr);
+
+        try {
+            xar.commit(xid3, true);
+            fail("FAIL - 2pc commit on read-only xact");
         } catch (XAException e) {
-            XATestUtil.dumpXAException("interleavingTransactions", e);
+            if (e.errorCode != XAException.XAER_NOTA)
+                throw e;
         }
+
+        s.close();
+        conn.close();
+        xac.close();
+
     }
 
-    /**  
-     Tests on INIT STATE (no tr
-     Original SQL from xaStateTran.sql. 
-     <code>
+    /**
+     * Tests on INIT STATE (no tr Original SQL from xaStateTran.sql. <code>
 
      -- the following should error XAER_NOTA
      xa_start xa_join 11;
@@ -395,875 +305,725 @@
      xa_forget 11;
      </code>
      */
-    private static void noTransaction(XADataSource xads) {
-        System.out.println("noTransaction");
-        try {
-            XAConnection xac = xads.getXAConnection();
-            XAResource xar = xac.getXAResource();
+    public void testNoTransaction() throws SQLException, XAException {
+        XADataSource xads = J2EEDataSource.getXADataSource();
+        XAConnection xac = xads.getXAConnection();
+        XAResource xar = xac.getXAResource();
 
-            Xid xid11 = XATestUtil.getXid(11, 3, 128);
+        Xid xid11 = XATestUtil.getXid(11, 3, 128);
 
-            try {
-                xar.start(xid11, XAResource.TMJOIN);
-            } catch (XAException e) {
-                if (e.errorCode != XAException.XAER_NOTA)
-                    throw e;
-            }
+        try {
+            xar.start(xid11, XAResource.TMJOIN);
+        } catch (XAException e) {
+            if (e.errorCode != XAException.XAER_NOTA)
+                throw e;
+        }
 
-            try {
-                xar.start(xid11, XAResource.TMRESUME);
-            } catch (XAException e) {
-                if (e.errorCode != XAException.XAER_NOTA)
-                    throw e;
-            }
+        try {
+            xar.start(xid11, XAResource.TMRESUME);
+        } catch (XAException e) {
+            if (e.errorCode != XAException.XAER_NOTA)
+                throw e;
+        }
 
-            try {
-                xar.end(xid11, XAResource.TMSUCCESS);
-            } catch (XAException e) {
-                if (e.errorCode != XAException.XAER_NOTA)
-                    throw e;
-            }
-            try {
-                xar.end(xid11, XAResource.TMFAIL);
-            } catch (XAException e) {
-                if (e.errorCode != XAException.XAER_NOTA)
-                    throw e;
-            }
+        try {
+            xar.end(xid11, XAResource.TMSUCCESS);
+        } catch (XAException e) {
+            if (e.errorCode != XAException.XAER_NOTA)
+                throw e;
+        }
+        try {
+            xar.end(xid11, XAResource.TMFAIL);
+        } catch (XAException e) {
+            if (e.errorCode != XAException.XAER_NOTA)
+                throw e;
+        }
 
-            try {
-                xar.end(xid11, XAResource.TMSUSPEND);
-            } catch (XAException e) {
-                if (e.errorCode != XAException.XAER_NOTA)
-                    throw e;
-            }
+        try {
+            xar.end(xid11, XAResource.TMSUSPEND);
+        } catch (XAException e) {
+            if (e.errorCode != XAException.XAER_NOTA)
+                throw e;
+        }
 
-            try {
-                xar.prepare(xid11);
-            } catch (XAException e) {
-                if (e.errorCode != XAException.XAER_NOTA)
-                    throw e;
-            }
-            try {
-                xar.commit(xid11, false);
-            } catch (XAException e) {
-                if (e.errorCode != XAException.XAER_NOTA)
-                    throw e;
-            }
-            try {
-                xar.commit(xid11, true);
-            } catch (XAException e) {
-                if (e.errorCode != XAException.XAER_NOTA)
-                    throw e;
-            }
-            try {
-                xar.rollback(xid11);
-            } catch (XAException e) {
-                if (e.errorCode != XAException.XAER_NOTA)
-                    throw e;
-            }
-            try {
-                xar.forget(xid11);
-            } catch (XAException e) {
-                if (e.errorCode != XAException.XAER_NOTA)
-                    throw e;
-            }
-        } catch (SQLException e) {
-            TestUtil.dumpSQLExceptions(e);
+        try {
+            xar.prepare(xid11);
         } catch (XAException e) {
-            XATestUtil.dumpXAException("noTransaction", e);
+            if (e.errorCode != XAException.XAER_NOTA)
+                throw e;
+        }
+        try {
+            xar.commit(xid11, false);
+        } catch (XAException e) {
+            if (e.errorCode != XAException.XAER_NOTA)
+                throw e;
+        }
+        try {
+            xar.commit(xid11, true);
+        } catch (XAException e) {
+            if (e.errorCode != XAException.XAER_NOTA)
+                throw e;
+        }
+        try {
+            xar.rollback(xid11);
+        } catch (XAException e) {
+            if (e.errorCode != XAException.XAER_NOTA)
+                throw e;
+        }
+        try {
+            xar.forget(xid11);
+        } catch (XAException e) {
+            if (e.errorCode != XAException.XAER_NOTA)
+                throw e;
         }
     }
 
     /**
      * Morph a connection between local anf global transactions.
      */
-    private static void morph(XADataSource xads) {
-        System.out.println("morph");
+    public void testMorph() throws SQLException, XAException {
 
-        try {
-            XAConnection xac = xads.getXAConnection();
+        XADataSource xads = J2EEDataSource.getXADataSource();
+        XAConnection xac = xads.getXAConnection();
 
-            XAResource xar = xac.getXAResource();
+        XAResource xar = xac.getXAResource();
 
-            Connection conn = xac.getConnection();
+        Connection conn = xac.getConnection();
 
-            /*
-             autocommit off;
-             insert into foo values (1);
-             select * from global_xactTable where gxid is not null order by gxid,username;
-             commit;
-             */
-            conn.setAutoCommit(false);
-            Statement s = conn.createStatement();
-            s.executeUpdate("insert into APP.foo values (2001)");
-            XATestUtil.showXATransactionView(conn);
-            conn.commit();
+        /*
+         * autocommit off; insert into foo values (1); select * from
+         * global_xactTable where gxid is not null order by gxid,username;
+         * commit;
+         */
+        conn.setAutoCommit(false);
+        Statement s = conn.createStatement();
+        s.executeUpdate("insert into APP.foo values (2001)");
+        // no rows expected
+        XATestUtil.checkXATransactionView(conn, null);
+        conn.commit();
 
-            /*
-             autocommit on;
-             insert into foo values (2);
-             select * from global_xactTable where gxid is not null order by gxid,username;
-             
-             */
+        /*
+         * autocommit on; insert into foo values (2); select * from
+         * global_xactTable where gxid is not null order by gxid,username;
+         * 
+         */
+
+        conn.setAutoCommit(true);
+        s.executeUpdate("insert into APP.foo values (2002)");
+        XATestUtil.checkXATransactionView(conn, null);
+
+        /*
+         * -- morph the connection to a global transaction xa_start xa_noflags
+         * 1; select * from global_xactTable where gxid is not null order by
+         * gxid,username; insert into foo values (3);
+         */
+
+        Xid xid = XATestUtil.getXid(1001, 66, 13);
+        xar.start(xid, XAResource.TMNOFLAGS);
+        String[][] expectedRows = { { "(1", "IDLE", "NULL", "APP",
+                "UserTransaction" } };
+        XATestUtil.checkXATransactionView(conn, expectedRows);
+        s.executeUpdate("insert into APP.foo values (2003)");
+
+        /*
+         * -- disallowed commit; -- disallowed rollback; -- disallowed
+         * autocommit on; -- OK autocommit off;
+         */
+        try {
+            conn.commit();
+            fail("FAIL: commit allowed in global xact");
+        } catch (SQLException e) {
+        }
 
+        try {
+            conn.rollback();
+            fail("FAIL: roll back allowed in global xact");
+        } catch (SQLException e) {
+        }
+        try {
             conn.setAutoCommit(true);
-            s.executeUpdate("insert into APP.foo values (2002)");
-            XATestUtil.showXATransactionView(conn);
+            fail("FAIL: setAutoCommit(true) allowed " + "in global xact");
+        } catch (SQLException e) {
+        }
+        try {
+            conn.setSavepoint();
+            fail("FAIL: setSavepoint() allowed in global xact");
+        } catch (SQLException e) {
+        }
+        try {
+            conn.setSavepoint("badsavepoint");
+            fail("FAIL: setSavepoint(String) allowed in " + "global xact");
+        } catch (SQLException e) {
+        }
 
-            /*
-             -- morph the connection to a global transaction
-             xa_start xa_noflags 1;
-             select * from global_xactTable where gxid is not null order by gxid,username;
-             insert into foo values (3);
-             */
+        conn.setAutoCommit(false);
 
-            Xid xid = XATestUtil.getXid(1001, 66, 13);
-            xar.start(xid, XAResource.TMNOFLAGS);
-            XATestUtil.showXATransactionView(conn);
-            s.executeUpdate("insert into APP.foo values (2003)");
+        // s was created in local mode so it has holdibilty
+        // set, will execute but ResultSet will have close on commit
 
-            /*
-             -- disallowed
-             commit;
-             -- disallowed
-             rollback;
-             -- disallowed
-             autocommit on;
-             -- OK
-             autocommit off;
-             */
-            try {
-                conn.commit();
-                System.out.println("FAIL: commit allowed in global xact");
-            } catch (SQLException e) {
-            }
+        // DERBY-1158 query with holdable statement
+        s.executeQuery("select * from APP.foo where A >= 2000").close();
+        s.close();
+
+        // statement created in global xact is CLOSE_CURSORS_AT_COMMIT
+        s = conn.createStatement();
+        assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, s
+                .getResultSetHoldability());
+
+        /*
+         * select * from foo; xa_end xa_success 1; xa_prepare 1;
+         */
+        ResultSet rs = s.executeQuery("select * from APP.foo where A >= 2000");
+        expectedRows = new String[][] { { "2001" }, { "2002" }, { "2003" } };
 
-            try {
-                conn.rollback();
-                System.out.println("FAIL: roll back allowed in global xact");
-            } catch (SQLException e) {
-            }
-            try {
-                conn.setAutoCommit(true);
-                System.out
-                        .println("FAIL: setAutoCommit(true) allowed "+
-				 "in global xact");
-            } catch (SQLException e) {
-            }
-            try {
-                conn.setSavepoint();
-                System.out
-                    .println("FAIL: setSavepoint() allowed in global xact");
-            } catch (SQLException e) {}
-            try {
-                conn.setSavepoint("badsavepoint");
-                System.out
-                    .println("FAIL: setAutoCommit(String) allowed in "+
-                             "global xact");
-            } catch (SQLException e) {}
-
-            conn.setAutoCommit(false);
-
-            // s was created in local mode so it has holdibilty
-            // set, will execute but ResultSet will have close on commit
-
-            if (TestUtil.isDerbyNetClientFramework()) { // DERBY-1158
-            s.executeQuery("select * from APP.foo where A >= 2000").close();
-            System.out.println("OK: query with holdable statement");
-            }
-            s.close();
-            
-            
-            s = conn.createStatement();
-            boolean holdable = s.getResultSetHoldability() == ResultSet.HOLD_CURSORS_OVER_COMMIT;
-            System.out.println("Statement created in global has holdabilty: "
-                    + holdable);
-
-            /*
-             select * from foo;
-             xa_end xa_success 1;
-             xa_prepare 1;
-             */
-            ResultSet rs = s
-                    .executeQuery("select * from APP.foo where A >= 2000");
-            JDBCDisplayUtil.DisplayResults(System.out, rs, conn);
-            rs.close();
-
-            xar.end(xid, XAResource.TMSUCCESS);
-            xar.prepare(xid);
-
-            /*
-             -- dup id
-             xa_start xa_noflags 1;
-             */
-            try {
-                xar.start(xid, XAResource.TMNOFLAGS);
-                System.out.println("FAIL - start with duplicate XID");
-            } catch (XAException e) {
-                if (e.errorCode != XAException.XAER_DUPID)
-                    throw e;
-            }
+        rs.close();
 
-            /*
-             xa_start xa_noflags 2;
-             -- still should disallow autommit;
-             autocommit on;
-             -- still should disallow commit and rollback 
-             commit;
-             rollback;
-             select * from global_xactTable where gxid is not null order by gxid,username;
-             xa_end xa_suspend 2;
-             */
+        xar.end(xid, XAResource.TMSUCCESS);
+        xar.prepare(xid);
 
-            Xid xid2 = XATestUtil.getXid(1002, 23, 3);
-            xar.start(xid2, XAResource.TMNOFLAGS);
-            try {
-                conn.commit();
-                System.out.println("FAIL: commit allowed in global xact");
-            } catch (SQLException e) {
-            }
-            try {
-                conn.rollback();
-                System.out.println("FAIL: roll back allowed in global xact");
-            } catch (SQLException e) {
-            }
-            try {
-                conn.setAutoCommit(true);
-                System.out
-                        .println("FAIL: setAutoCommit(true) allowed in global xact");
-            } catch (SQLException e) {
-            }
-            conn.setAutoCommit(false);
+        /*
+         * -- dup id xa_start xa_noflags 1;
+         */
+        try {
+            xar.start(xid, XAResource.TMNOFLAGS);
+            fail("FAIL - start with duplicate XID");
+        } catch (XAException e) {
+            if (e.errorCode != XAException.XAER_DUPID)
+                throw e;
+        }
 
-            xar.end(xid2, XAResource.TMSUSPEND);
+        /*
+         * xa_start xa_noflags 2; -- still should disallow autommit; autocommit
+         * on; -- still should disallow commit and rollback commit; rollback;
+         * select * from global_xactTable where gxid is not null order by
+         * gxid,username; xa_end xa_suspend 2;
+         */
 
-            /*
-             -- get local connection again
-             xa_getconnection;
+        Xid xid2 = XATestUtil.getXid(1002, 23, 3);
+        xar.start(xid2, XAResource.TMNOFLAGS);
+        try {
+            conn.commit();
+            fail("FAIL: commit allowed in global xact");
+        } catch (SQLException e) {
+        }
+        try {
+            conn.rollback();
+            fail("FAIL: roll back allowed in global xact");
+        } catch (SQLException e) {
+        }
+        try {
+            conn.setAutoCommit(true);
+            fail("FAIL: setAutoCommit(true) allowed in global xact");
+        } catch (SQLException e) {
+        }
+        conn.setAutoCommit(false);
 
-             insert into foo values (5);
+        xar.end(xid2, XAResource.TMSUSPEND);
 
-             -- autocommit should be on by default;
-             commit;
+        /*
+         * -- get local connection again xa_getconnection;
+         * 
+         * insert into foo values (5); -- autocommit should be on by default;
+         * commit;
+         * 
+         * autocommit off; insert into foo values (6); -- commit and rollback is
+         * allowed on local connection rollback;
+         * 
+         * insert into foo values (6); commit;
+         */
+        conn = xac.getConnection();
+        s = conn.createStatement();
+        s.executeUpdate("insert into APP.foo values (2005)");
+        conn.commit();
+        conn.setAutoCommit(false);
+        s.executeUpdate("insert into APP.foo values (2006)");
+        conn.rollback();
+        s.executeUpdate("insert into APP.foo values (2007)");
+        conn.commit();
 
-             autocommit off;
-             insert into foo values (6);
+        expectedRows = new String[][] {
+                { "(1", "PREPARED", "false", "APP", "UserTransaction" },
+                { "(1", "IDLE", "NULL", "APP", "UserTransaction" } };
+        XATestUtil.checkXATransactionView(conn, expectedRows);
+        /*
+         * -- I am still able to commit other global transactions while I am
+         * attached to a -- local transaction. xa_commit xa_2phase 1; xa_end
+         * xa_success 2; xa_rollback 2;
+         */
+        xar.commit(xid, false);
+        xar.end(xid2, XAResource.TMSUCCESS);
+        xar.rollback(xid2);
+
+        XATestUtil.checkXATransactionView(conn, null);
+        rs = s.executeQuery("select * from APP.foo where A >= 2000");
+        expectedRows = new String[][] { { "2001" }, { "2002" }, { "2003" },
+                { "2005" }, { "2007" } };
+        JDBC.assertFullResultSet(rs, expectedRows);
+        rs.close();
 
-             -- commit and rollback is allowed on local connection
-             rollback;
+        conn.close();
 
-             insert into foo values (6);
-             commit;
-             */
-            conn = xac.getConnection();
-            s = conn.createStatement();
-            s.executeUpdate("insert into APP.foo values (2005)");
-            conn.commit();
-            conn.setAutoCommit(false);
-            s.executeUpdate("insert into APP.foo values (2006)");
-            conn.rollback();
-            s.executeUpdate("insert into APP.foo values (2007)");
-            conn.commit();
+        /*
+         * xa_getconnection; select * from global_xactTable where gxid is not
+         * null order by gxid,username; select * from foo; autocommit off;
+         * delete from foo;
+         */
+        conn = xac.getConnection();
+        conn.setAutoCommit(false);
+        s = conn.createStatement();
+        s.executeUpdate("delete from app.foo");
+        rs = s.executeQuery("select * from APP.foo");
+        JDBC.assertEmpty(rs);
+        rs.close();
 
-            XATestUtil.showXATransactionView(conn);
-            /*
-             -- I am still able to commit other global transactions while I am attached to a
-             -- local transaction.
-             xa_commit xa_2phase 1;
-             xa_end xa_success 2;
-             xa_rollback 2;
-             */
-            xar.commit(xid, false);
-            xar.end(xid2, XAResource.TMSUCCESS);
-            xar.rollback(xid2);
-
-            XATestUtil.showXATransactionView(conn);
-            rs = s.executeQuery("select * from APP.foo where A >= 2000");
-            JDBCDisplayUtil.DisplayResults(System.out, rs, conn);
-            rs.close();
-
-            conn.close();
-
-            /*
-             xa_getconnection;
-             select * from global_xactTable where gxid is not null order by gxid,username;
-             select * from foo;
-             autocommit off;
-             delete from foo;
-             */
-            conn = xac.getConnection();
-            conn.setAutoCommit(false);
-            s = conn.createStatement();
-            s.executeUpdate("delete from app.foo");
-            rs = s.executeQuery("select * from APP.foo");
-            JDBCDisplayUtil.DisplayResults(System.out, rs, conn);
-            rs.close();
-
-            // DERBY-1004
-            if (TestUtil.isDerbyNetClientFramework()) {
-                System.out.println("DERBY-1004 Call conn.rollback to avoid exception with client");
-                conn.rollback();
-            }
-            /*
-             -- yanking a local connection away should rollback the changes
-             */
-            conn = xac.getConnection();
-            conn.setAutoCommit(false);
-            s = conn.createStatement();
-            rs = s.executeQuery("select * from APP.foo where A >= 2000");
-            JDBCDisplayUtil.DisplayResults(System.out, rs, conn);
-            rs.close();
-
-            /*
-             -- cannot morph it if the local transaction is not idle
-             xa_start xa_noflags 3;
-             commit;
-             -- now morph it to a global transaction
-             xa_start xa_noflags 3;
-             */
-            Xid xid3 = XATestUtil.getXid(1003, 27, 9);
-            try {
-                xar.start(xid3, XAResource.TMNOFLAGS);
-                System.out.println("FAIL XAResource.start on a global transaction with an active local transaction (autocommit false)");
-            } catch (XAException xae) {
-                if (xae.errorCode != XAException.XAER_OUTSIDE)
-                    throw xae;
-                System.out.println("Correct XAException on starting a global transaction with an active local transaction (autocommit false)");
-            }
-            conn.commit();
+        /*
+         * -- yanking a local connection away should rollback the changes
+         */
+        conn = xac.getConnection();
+        conn.setAutoCommit(false);
+        s = conn.createStatement();
+        rs = s.executeQuery("select * from APP.foo where A >= 2000");
+        expectedRows = new String[][] { { "2001" }, { "2002" }, { "2003" },
+                { "2005" }, { "2007" } };
+        JDBC.assertFullResultSet(rs, expectedRows);
+
+        /*
+         * -- cannot morph it if the local transaction is not idle xa_start
+         * xa_noflags 3; commit; -- now morph it to a global transaction
+         * xa_start xa_noflags 3;
+         */
+        Xid xid3 = XATestUtil.getXid(1003, 27, 9);
+        try {
             xar.start(xid3, XAResource.TMNOFLAGS);
+            fail("FAIL XAResource.start on a global transaction with an active local transaction (autocommit false)");
+        } catch (XAException xae) {
+            if (xae.errorCode != XAException.XAER_OUTSIDE)
+                throw xae;
+        }
+        conn.commit();
+        xar.start(xid3, XAResource.TMNOFLAGS);
 
-            /*
-             -- now I shouldn't be able to yank it
-             xa_getconnection;
-             */
-            if (TestUtil.isDerbyNetClientFramework()) {
-                System.out.println("DERBY-341 - Client skipping XAConnection with active local transaction");              
-            } else {
+        /*
+         * -- now I shouldn't be able to yank it xa_getconnection;
+         */
+        // DERBY-341 - client skip XAConnection with active local xact
+        if (usingEmbedded()) {
             try {
                 xac.getConnection();
-                System.out
-                        .println("FAIL: getConnection with active global xact");
+                fail("FAIL: getConnection with active global xact");
             } catch (SQLException sqle) {
-                TestUtil.dumpSQLExceptions(sqle, true);
-            }
+                assertSQLState("XJ059", sqle);
             }
-            /*
-             select * from foo;
-             delete from foo;
-
-             xa_end xa_fail 3;
-             xa_rollback 3;
-
-             -- local connection again
-             xa_getconnection;
-             select * from global_xactTable where gxid is not null order by gxid,username;
-             select * from foo;
-             */
-            s = conn.createStatement();
-            s.executeUpdate("delete from APP.foo");
-            rs = s.executeQuery("select * from APP.foo where A >= 2000");
-            JDBCDisplayUtil.DisplayResults(System.out, rs, conn);
-            rs.close();
-            try {
-                xar.end(xid3, XAResource.TMFAIL);
-            } catch (XAException e) {
-                if (e.errorCode != XAException.XA_RBROLLBACK)
-                    throw e;
-            }
-            xar.rollback(xid3);
-
-            conn = xac.getConnection();
-            s = conn.createStatement();
-            rs = s.executeQuery("select * from APP.foo where A >= 2000");
-            JDBCDisplayUtil.DisplayResults(System.out, rs, conn);
-            rs.close();
-
-            s.close();
-            conn.close();
+        }
+        /*
+         * select * from foo; delete from foo;
+         * 
+         * xa_end xa_fail 3; xa_rollback 3; -- local connection again
+         * xa_getconnection; select * from global_xactTable where gxid is not
+         * null order by gxid,username; select * from foo;
+         */
+        s = conn.createStatement();
+        s.executeUpdate("delete from APP.foo");
+        rs = s.executeQuery("select * from APP.foo where A >= 2000");
+        JDBC.assertEmpty(rs);
 
-        } catch (SQLException e) {
-            TestUtil.dumpSQLExceptions(e);
-            e.printStackTrace(System.out);
+        rs.close();
+        try {
+            xar.end(xid3, XAResource.TMFAIL);
         } catch (XAException e) {
-            XATestUtil.dumpXAException("morph", e);
+            if (e.errorCode != XAException.XA_RBROLLBACK)
+                throw e;
         }
+        xar.rollback(xid3);
+
+        conn = xac.getConnection();
+        s = conn.createStatement();
+        rs = s.executeQuery("select * from APP.foo where A >= 2000");
+        expectedRows = new String[][] { { "2001" }, { "2002" }, { "2003" },
+                { "2005" }, { "2007" } };
+        JDBC.assertFullResultSet(rs, expectedRows);
+        rs.close();
+
+        s.close();
+        conn.close();
 
     }
-    
+
     /**
-     * Derby-966 holdability and global/location transactions.
-     * (work in progress)
+     * Derby-966 holdability and global/location transactions. (work in
+     * progress)
      */
-    private static void derby966(XADataSource xads)
-    {
-        System.out.println("derby966");
-        
-        try {
-            XAConnection xac = xads.getXAConnection();
-            XAResource xar = xac.getXAResource();
-
-            Xid xid = XATestUtil.getXid(996, 9, 48);
-            
-            Connection conn = xac.getConnection();
-            
-            // Obtain Statements and PreparedStatements
-            // with all the holdability options.
-            
-            showHoldStatus("Local ", conn);
-           
-            Statement sdh = conn.createStatement();
-            showHoldStatus("Local(held) default ", sdh);
-            checkHeldRS(conn, sdh, sdh.executeQuery("select * from app.foo"));
-            PreparedStatement psdh = conn.prepareStatement("SELECT * FROM APP.FOO");
-            PreparedStatement psdh_d = conn.prepareStatement("DELETE FROM APP.FOO WHERE A < -99");
-            showHoldStatus("Local(held) default Prepared", psdh);
-            checkHeldRS(conn, psdh, psdh.executeQuery());
-            
-            Statement shh = conn.createStatement(
-                    ResultSet.TYPE_FORWARD_ONLY,
-                    ResultSet.CONCUR_READ_ONLY,
-                    ResultSet.HOLD_CURSORS_OVER_COMMIT);
-            showHoldStatus("Local(held) held ", shh);
-            checkHeldRS(conn, shh, shh.executeQuery("select * from app.foo"));
-            PreparedStatement pshh =
-                conn.prepareStatement("SELECT * FROM APP.FOO",
-                        ResultSet.TYPE_FORWARD_ONLY,
-                        ResultSet.CONCUR_READ_ONLY,
-                        ResultSet.HOLD_CURSORS_OVER_COMMIT);
-            PreparedStatement pshh_d =
-                conn.prepareStatement("DELETE FROM APP.FOO WHERE A < -99",
-                        ResultSet.TYPE_FORWARD_ONLY,
-                        ResultSet.CONCUR_READ_ONLY,
-                        ResultSet.HOLD_CURSORS_OVER_COMMIT);
-            showHoldStatus("Local(held) held Prepared", pshh);
-            checkHeldRS(conn, pshh, pshh.executeQuery());
-                        
-            Statement sch = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
-                    ResultSet.CONCUR_READ_ONLY,
-                    ResultSet.CLOSE_CURSORS_AT_COMMIT);
-            showHoldStatus("Local(held) close ", sch);
-            checkHeldRS(conn, sch, sch.executeQuery("select * from app.foo"));
-            PreparedStatement psch =
-                conn.prepareStatement("SELECT * FROM APP.FOO",
-                        ResultSet.TYPE_FORWARD_ONLY,
-                        ResultSet.CONCUR_READ_ONLY,
-                        ResultSet.CLOSE_CURSORS_AT_COMMIT);
-            PreparedStatement psch_d =
-                conn.prepareStatement("DELETE FROM APP.FOO WHERE A < -99",
-                        ResultSet.TYPE_FORWARD_ONLY,
-                        ResultSet.CONCUR_READ_ONLY,
-                        ResultSet.CLOSE_CURSORS_AT_COMMIT);
-             showHoldStatus("Local(held) close Prepared", psch);
-            checkHeldRS(conn, psch, psch.executeQuery());
-         
-            // set the connection's holdabilty to false
-            conn.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
-            
-            Statement sdc = conn.createStatement();
-            showHoldStatus("Local(close) default ", sdc);
-            checkHeldRS(conn, sdc, sdc.executeQuery("select * from app.foo"));
-            PreparedStatement psdc = conn.prepareStatement("SELECT * FROM APP.FOO");
-            PreparedStatement psdc_d = conn.prepareStatement("DELETE FROM APP.FOO WHERE A < -99");
-            showHoldStatus("Local(close) default Prepared", psdc);
-            checkHeldRS(conn, psdc, psdc.executeQuery());
- 
-            Statement shc = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
-                    ResultSet.CONCUR_READ_ONLY,
-                    ResultSet.HOLD_CURSORS_OVER_COMMIT);
-            showHoldStatus("Local(close) held ", shc);
-            checkHeldRS(conn, shc, shc.executeQuery("select * from app.foo"));
-            PreparedStatement pshc =
-                conn.prepareStatement("SELECT * FROM APP.FOO",
-                        ResultSet.TYPE_FORWARD_ONLY,
-                        ResultSet.CONCUR_READ_ONLY,
-                        ResultSet.HOLD_CURSORS_OVER_COMMIT);
-            PreparedStatement pshc_d =
-                conn.prepareStatement("DELETE FROM APP.FOO WHERE A < -99",
-                        ResultSet.TYPE_FORWARD_ONLY,
-                        ResultSet.CONCUR_READ_ONLY,
-                        ResultSet.HOLD_CURSORS_OVER_COMMIT);
-            showHoldStatus("Local(close) held Prepared", pshc);
-            checkHeldRS(conn, pshc, pshc.executeQuery());
-            
-            Statement scc = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
-                    ResultSet.CONCUR_READ_ONLY,
-                    ResultSet.CLOSE_CURSORS_AT_COMMIT);
-            showHoldStatus("Local(close) close ", scc);
-            checkHeldRS(conn, scc, scc.executeQuery("select * from app.foo"));
-            PreparedStatement pscc =
-                conn.prepareStatement("SELECT * FROM APP.FOO",
-                        ResultSet.TYPE_FORWARD_ONLY,
-                        ResultSet.CONCUR_READ_ONLY,
-                        ResultSet.CLOSE_CURSORS_AT_COMMIT);
-            PreparedStatement pscc_d =
-                conn.prepareStatement("DELETE FROM APP.FOO WHERE A < -99",
-                        ResultSet.TYPE_FORWARD_ONLY,
-                        ResultSet.CONCUR_READ_ONLY,
-                        ResultSet.CLOSE_CURSORS_AT_COMMIT);
-             showHoldStatus("Local(close) close Prepared", pscc);
-            checkHeldRS(conn, pscc, pscc.executeQuery());
-            
-            // Revert back to holdable
+    public void testDerby966() throws SQLException, XAException {
+        XADataSource xads = J2EEDataSource.getXADataSource();
+        XAConnection xac = xads.getXAConnection();
+        XAResource xar = xac.getXAResource();
+
+        Xid xid = XATestUtil.getXid(996, 9, 48);
+
+        Connection conn = xac.getConnection();
+
+        // Obtain Statements and PreparedStatements
+        // with all the holdability options.
+        assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, conn.getHoldability());
+
+        Statement sdh = conn.createStatement();
+        assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, sdh
+                .getResultSetHoldability());
+
+        checkHeldRS(conn, sdh, sdh.executeQuery("select * from app.foo"));
+        PreparedStatement psdh = conn.prepareStatement("SELECT * FROM APP.FOO");
+        PreparedStatement psdh_d = conn
+                .prepareStatement("DELETE FROM APP.FOO WHERE A < -99");
+        assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, psdh
+                .getResultSetHoldability());
+        checkHeldRS(conn, psdh, psdh.executeQuery());
+
+        Statement shh = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+                ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
+        assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, shh
+                .getResultSetHoldability());
+        checkHeldRS(conn, shh, shh.executeQuery("select * from app.foo"));
+        PreparedStatement pshh = conn.prepareStatement("SELECT * FROM APP.FOO",
+                ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
+                ResultSet.HOLD_CURSORS_OVER_COMMIT);
+        PreparedStatement pshh_d = conn.prepareStatement(
+                "DELETE FROM APP.FOO WHERE A < -99",
+                ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
+                ResultSet.HOLD_CURSORS_OVER_COMMIT);
+        assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, shh
+                .getResultSetHoldability());
+        checkHeldRS(conn, pshh, pshh.executeQuery());
+
+        Statement sch = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+                ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT);
+        assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, sch
+                .getResultSetHoldability());
+
+        checkHeldRS(conn, sch, sch.executeQuery("select * from app.foo"));
+        PreparedStatement psch = conn.prepareStatement("SELECT * FROM APP.FOO",
+                ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
+                ResultSet.CLOSE_CURSORS_AT_COMMIT);
+        PreparedStatement psch_d = conn.prepareStatement(
+                "DELETE FROM APP.FOO WHERE A < -99",
+                ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
+                ResultSet.CLOSE_CURSORS_AT_COMMIT);
+        assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, psch_d
+                .getResultSetHoldability());
+        checkHeldRS(conn, psch, psch.executeQuery());
+
+        // set the connection's holdabilty to false
+        conn.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
+
+        Statement sdc = conn.createStatement();
+        assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, sdc
+                .getResultSetHoldability());
+        checkHeldRS(conn, sdc, sdc.executeQuery("select * from app.foo"));
+        PreparedStatement psdc = conn.prepareStatement("SELECT * FROM APP.FOO");
+        PreparedStatement psdc_d = conn
+                .prepareStatement("DELETE FROM APP.FOO WHERE A < -99");
+        assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, psdc
+                .getResultSetHoldability());
+        checkHeldRS(conn, psdc, psdc.executeQuery());
+
+        Statement shc = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+                ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
+        assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, psdc
+                .getResultSetHoldability());
+        checkHeldRS(conn, shc, shc.executeQuery("select * from app.foo"));
+        PreparedStatement pshc = conn.prepareStatement("SELECT * FROM APP.FOO",
+                ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
+                ResultSet.HOLD_CURSORS_OVER_COMMIT);
+        PreparedStatement pshc_d = conn.prepareStatement(
+                "DELETE FROM APP.FOO WHERE A < -99",
+                ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
+                ResultSet.HOLD_CURSORS_OVER_COMMIT);
+        assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, pshc
+                .getResultSetHoldability());
+
+        checkHeldRS(conn, pshc, pshc.executeQuery());
+
+        Statement scc = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+                ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT);
+        assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, scc
+                .getResultSetHoldability());
+        checkHeldRS(conn, scc, scc.executeQuery("select * from app.foo"));
+        PreparedStatement pscc = conn.prepareStatement("SELECT * FROM APP.FOO",
+                ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
+                ResultSet.CLOSE_CURSORS_AT_COMMIT);
+        PreparedStatement pscc_d = conn.prepareStatement(
+                "DELETE FROM APP.FOO WHERE A < -99",
+                ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
+                ResultSet.CLOSE_CURSORS_AT_COMMIT);
+        assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, pscc
+                .getResultSetHoldability());
+
+        checkHeldRS(conn, pscc, pscc.executeQuery());
+
+        // Revert back to holdable
+        conn.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);
+
+        ResultSet rs = sdh.executeQuery("SELECT * FROM APP.FOO");
+        rs.next();
+        // before commit
+        assertEquals(0, +rs.getInt(1));
+        conn.commit();
+        // aftercommit
+        rs.next();
+        assertEquals(1, rs.getInt(1));
+        rs.close();
+
+        // ensure a transaction is active to test DERBY-1025
+        rs = sdh.executeQuery("SELECT * FROM APP.FOO");
+
+        // This switch to global is ok because conn
+        // is in auto-commit mode, thus the start performs
+        // an implicit commit to complete the local transaction.
+
+        // start a global xact and test those statements.
+        xar.start(xid, XAResource.TMNOFLAGS);
+
+        // Statements not returning ResultSet's should be ok
+        sdh.executeUpdate("DELETE FROM APP.FOO where A < -99");
+        shh.executeUpdate("DELETE FROM APP.FOO where A < -99");
+        sch.executeUpdate("DELETE FROM APP.FOO where A < -99");
+
+        ArrayList openRS = new ArrayList();
+
+        // Statements obtained while default was hold.
+        // All should work, holability will be downgraded
+        // to close on commit for those Statements with hold set.
+        openRS.add(sdh.executeQuery("SELECT * FROM APP.FOO"));
+        openRS.add(shh.executeQuery("SELECT * FROM APP.FOO"));
+        openRS.add(sch.executeQuery("SELECT * FROM APP.FOO"));
+
+        // PreparedStatements obtained while default was hold.
+        // Holdability should be downgraded.
+        openRS.add(psdh.executeQuery());
+        openRS.add(pshh.executeQuery());
+        openRS.add(psch.executeQuery());
+
+        // Statements not returning ResultSet's should be ok
+        psdh_d.executeUpdate();
+        pshh_d.executeUpdate();
+        psch_d.executeUpdate();
+
+        // Statements not returning ResultSet's should be ok
+        sdc.executeUpdate("DELETE FROM APP.FOO where A < -99");
+        shc.executeUpdate("DELETE FROM APP.FOO where A < -99");
+        scc.executeUpdate("DELETE FROM APP.FOO where A < -99");
+
+        // Statements obtained while default was close.
+        // all should return close on commit ResultSets
+        openRS.add(sdc.executeQuery("SELECT * FROM APP.FOO"));
+        openRS.add(shc.executeQuery("SELECT * FROM APP.FOO"));
+        openRS.add(scc.executeQuery("SELECT * FROM APP.FOO"));
+
+        // PreparedStatements obtained while default was close.
+        openRS.add(psdc.executeQuery());
+        openRS.add(pshc.executeQuery());
+        openRS.add(pscc.executeQuery());
+
+        // Statements not returning ResultSet's should be ok
+        psdc_d.executeUpdate();
+        pshc_d.executeUpdate();
+        pscc_d.executeUpdate();
+
+        // All the ResultSets should be open. Run a simple
+        // test, clearWarnings throws an error if the ResultSet
+        // is closed. Also would be nice here to use the new
+        // JDBC 4.0 method getHoldabilty to ensure the
+        // holdability is reported correctly.
+        int orsCount = 0;
+        for (Iterator i = openRS.iterator(); i.hasNext();) {
+            ResultSet ors = (ResultSet) i.next();
+            ors.clearWarnings();
+            orsCount++;
+        }
+        assertEquals("Incorrect number of open result sets", 12, orsCount);
+
+        // Test we cannot switch the connection to holdable
+        try {
             conn.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);
-            
-            ResultSet rs = sdh.executeQuery("SELECT * FROM APP.FOO");
-            rs.next(); System.out.println("BGBC " + rs.getInt(1));
-            conn.commit();
-            rs.next(); System.out.println("BGAC " + rs.getInt(1));
-            rs.close();
-           
-            // ensure a transaction is active to test DERBY-1025
-            rs = sdh.executeQuery("SELECT * FROM APP.FOO");
-           
-            // This switch to global is ok because conn
-            // is in auto-commit mode, thus the start performs
-            // an implicit commit to complete the local transaction.
-            
-            System.out.println("START GLOBAL TRANSACTION");
-            // start a global xact and test those statements.
-            xar.start(xid, XAResource.TMNOFLAGS);
-            
-            // Statements not returning ResultSet's should be ok
-            sdh.executeUpdate("DELETE FROM APP.FOO where A < -99");
-            shh.executeUpdate("DELETE FROM APP.FOO where A < -99");
-            sch.executeUpdate("DELETE FROM APP.FOO where A < -99");
-           
-            ArrayList openRS = new ArrayList();
-            
-            // Statements obtained while default was hold.
-            // All should work, holability will be downgraded
-            // to close on commit for those Statements with hold set.
-            openRS.add(sdh.executeQuery("SELECT * FROM APP.FOO"));
-            openRS.add(shh.executeQuery("SELECT * FROM APP.FOO"));
-            openRS.add(sch.executeQuery("SELECT * FROM APP.FOO"));
-
-            
-            // PreparedStatements obtained while default was hold.
-            // Holdability should be downgraded.
-            openRS.add(psdh.executeQuery());
-            openRS.add(pshh.executeQuery());
-            openRS.add(psch.executeQuery());
-            
-            // Statements not returning ResultSet's should be ok
-            psdh_d.executeUpdate();
-            pshh_d.executeUpdate();
-            psch_d.executeUpdate();
- 
-            // Statements not returning ResultSet's should be ok
-            sdc.executeUpdate("DELETE FROM APP.FOO where A < -99");
-            shc.executeUpdate("DELETE FROM APP.FOO where A < -99");
-            scc.executeUpdate("DELETE FROM APP.FOO where A < -99");
- 
-            // Statements obtained while default was close.
-            // all should return close on commit ResultSets
-            openRS.add(sdc.executeQuery("SELECT * FROM APP.FOO"));
-            openRS.add(shc.executeQuery("SELECT * FROM APP.FOO"));
-            openRS.add(scc.executeQuery("SELECT * FROM APP.FOO"));
-            
-            // PreparedStatements obtained while default was close.
-            openRS.add(psdc.executeQuery());
-            openRS.add(pshc.executeQuery());
-            openRS.add(pscc.executeQuery());
-            
-            // Statements not returning ResultSet's should be ok
-            psdc_d.executeUpdate();
-            pshc_d.executeUpdate();
-            pscc_d.executeUpdate();
-            
-            // All the ResultSets should be open. Run a simple
-            // test, clearWarnings throws an error if the ResultSet
-            // is closed. Also would be nice here to use the new
-            // JDBC 4.0 method getHoldabilty to ensure the
-            // holdability is reported correctly.
-            int orsCount = 0;
-            for (Iterator i = openRS.iterator(); i.hasNext();) {
-                ResultSet ors = (ResultSet) i.next();
-                ors.clearWarnings();
-                orsCount++;
-            }
-            System.out.println("Global transaction open ResultSets " + orsCount);
+            fail("FAIL - set holdability in global xact.");
+        } catch (SQLException sqle) {
+            assertSQLState("XJ05C", sqle);
+        }
 
-                   
-            // Test we cannot switch the connection to holdable
-            try {
-                conn.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);
-                System.out.println("FAIL - set holdability in global xact.");
-            } catch (SQLException sqle)
-            {
-                TestUtil.dumpSQLExceptions(sqle, true);
-            }
-            
-            // JDBC 4.0 (proposed final draft) section allows
-            // drivers to change the holdability when creating
-            // a Statement object and attach a warning to the Connection.
-            Statement sglobalhold = conn.createStatement(
-                    ResultSet.TYPE_FORWARD_ONLY,
+        // JDBC 4.0 (proposed final draft) section allows
+        // drivers to change the holdability when creating
+        // a Statement object and attach a warning to the Connection.
+        Statement sglobalhold = conn.createStatement(
+                ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
+                ResultSet.HOLD_CURSORS_OVER_COMMIT);
+        assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, sglobalhold
+                .getResultSetHoldability());
+
+        sglobalhold.close();
+
+        // DERBY2481 Client does not downgrade PreparedStatement holdability
+        if (!usingDerbyNetClient()) {
+            PreparedStatement psglobalhold = conn.prepareStatement(
+                    "SELECT * FROM APP.FOO", ResultSet.TYPE_FORWARD_ONLY,
                     ResultSet.CONCUR_READ_ONLY,
                     ResultSet.HOLD_CURSORS_OVER_COMMIT);
-            showHoldStatus("Global createStatement(hold)", sglobalhold);
-            sglobalhold.close();
+            assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, psglobalhold
+                    .getResultSetHoldability());
 
-            PreparedStatement psglobalhold = conn.prepareStatement(
-                "SELECT * FROM APP.FOO",
-                ResultSet.TYPE_FORWARD_ONLY,
-                ResultSet.CONCUR_READ_ONLY,
-                ResultSet.HOLD_CURSORS_OVER_COMMIT);
-            showHoldStatus("Global prepareStatement(hold)", psglobalhold);
             psglobalhold.close();
-            
-            if (!TestUtil.isDerbyNetClientFramework()) { //DERBY-1158 in progress
-            // Show the holdability for all the Statements while
-            // in the global transaction, all should be close on commit.
-            showHoldStatus("Global xact Statement sdh ", sdh);
-            showHoldStatus("Global xact Statement shh ", shh);
-            showHoldStatus("Global xact Statement sch ", sch);
-            
-            showHoldStatus("Global xact Statement psdh ", psdh);
-            showHoldStatus("Global xact Statement pshh ", pshh);
-            showHoldStatus("Global xact Statement psch ", psch);
-            
-            showHoldStatus("Global xact Statement sdc ", sdc);
-            showHoldStatus("Global xact Statement shc ", shc);
-            showHoldStatus("Global xact Statement scc ", scc);
- 
-            showHoldStatus("Global xact Statement psdh_d ", psdh_d);
-            showHoldStatus("Global xact Statement pshh_d ", pshh_d);
-            showHoldStatus("Global xact Statement psch_d ", psch_d);
-            }
- 
-        
-            xar.end(xid, XAResource.TMSUCCESS);
-            if (xar.prepare(xid) != XAResource.XA_RDONLY)
-                System.out.println("FAIL prepare didn't indicate r/o");
-            
-            // All the ResultSets should be closed. Run a simple
-            // test, clearWarnings throws an error if the ResultSet
-            // is closed.
-            int crsCount = 0;
-            for (Iterator i = openRS.iterator(); i.hasNext();) {
-                ResultSet crs = (ResultSet) i.next();
-                try {
-                    crs.clearWarnings();
-                } catch (SQLException sqle) {
-                }
-                crsCount++;
-            }
-            System.out.println("After global transaction closed ResultSets " + crsCount);
 
-            
-            // Check the statements revert to holdable as required.
-            showHoldStatus("Global xact Statement sdh ", sdh);
-            showHoldStatus("Global xact Statement shh ", shh);
-            showHoldStatus("Global xact Statement sch ", sch);
-            
-            showHoldStatus("Global xact Statement psdh ", psdh);
-            showHoldStatus("Global xact Statement pshh ", pshh);
-            showHoldStatus("Global xact Statement psch ", psch);
- 
-            showHoldStatus("Global xact Statement sdc ", sdc);
-            showHoldStatus("Global xact Statement shc ", shc);
-            showHoldStatus("Global xact Statement scc ", scc);
-            
-            showHoldStatus("Global xact Statement psdh_d ", psdh_d);
-            showHoldStatus("Global xact Statement pshh_d ", pshh_d);
-            showHoldStatus("Global xact Statement psch_d ", psch_d);
-            
-            conn.close();
-            
-            System.out.println("derby966 complete");
-                
-        } catch (SQLException e) {
-            TestUtil.dumpSQLExceptions(e);
-            e.printStackTrace(System.out);
-        } catch (XAException e) {
-            XATestUtil.dumpXAException("derby966", e);
+            assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, sdh
+                    .getResultSetHoldability());
+            assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, sch
+                    .getResultSetHoldability());
+
+            assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, psdh
+                    .getResultSetHoldability());
+            assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, pshh
+                    .getResultSetHoldability());
+            assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, psch
+                    .getResultSetHoldability());
+
+            assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, sdc
+                    .getResultSetHoldability());
+            assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, shc
+                    .getResultSetHoldability());
+            assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, scc
+                    .getResultSetHoldability());
+
+            assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, psdh_d
+                    .getResultSetHoldability());
+            assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, pshh_d
+                    .getResultSetHoldability());
+            assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, psch_d
+                    .getResultSetHoldability());
         }
+
+        xar.end(xid, XAResource.TMSUCCESS);
+        if (xar.prepare(xid) != XAResource.XA_RDONLY)
+            fail("FAIL prepare didn't indicate r/o");
+
+        // All the ResultSets should be closed. Run a simple
+        // test, clearWarnings throws an error if the ResultSet
+        // is closed.
+        int crsCount = 0;
+        for (Iterator i = openRS.iterator(); i.hasNext();) {
+            ResultSet crs = (ResultSet) i.next();
+            try {
+                crs.clearWarnings();
+            } catch (SQLException sqle) {
+            }
+            crsCount++;
+        }
+        assertEquals("After global transaction closed ResultSets ", 12,
+                crsCount);
+
+        // Check the statements revert to holdable as required.
+        assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, sdh
+                .getResultSetHoldability());
+        assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, shh
+                .getResultSetHoldability());
+        assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, sch
+                .getResultSetHoldability());
+
+        assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, psdh
+                .getResultSetHoldability());
+        assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, pshh
+                .getResultSetHoldability());
+        assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, psch
+                .getResultSetHoldability());
+
+        assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, sdc
+                .getResultSetHoldability());
+        assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, shc
+                .getResultSetHoldability());
+        assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, scc
+                .getResultSetHoldability());
+
+        assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, psdh_d
+                .getResultSetHoldability());
+        assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, pshh_d
+                .getResultSetHoldability());
+        assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, psch_d
+                .getResultSetHoldability());
+
+        conn.close();
+
     }
-    
+
     /**
-     * Check the held state of a ResultSet by fetching
-     * one row, executing a commit and then fetching the
-     * next. Checks the held state matches the behaviour.
-    */
-    private static void checkHeldRS(Connection conn,
-            Statement s, ResultSet rs) throws SQLException
-    {
-        if (s.getConnection() != conn)
-            System.out.println("FAIL - mismatched statement & Connection");
-        if (rs.getStatement() != s)
-        {
+     * Check the held state of a ResultSet by fetching one row, executing a
+     * commit and then fetching the next. Checks the held state matches the
+     * behaviour.
+     */
+    private static void checkHeldRS(Connection conn, Statement s, ResultSet rs)
+            throws SQLException {
+        // DERBY-1008 - can't run with client
+        if (!usingDerbyNetClient()) {
+            if (s.getConnection() != conn)
+                fail("FAIL - mismatched statement & Connection");
+        }
+        if (rs.getStatement() != s) {
             // DERBY-1009
-            System.out.println("FAIL - mismatched statement & ResultSet");
-            System.out.println("Statement class " + s.getClass());
-            System.out.println("ResultSet' Statements class " + rs.getStatement().getClass());
-         }
-
-        boolean held = s.getResultSetHoldability() ==
-            ResultSet.HOLD_CURSORS_OVER_COMMIT;
-        
-        System.out.println("ResultSet " + holdStatus(s.getResultSetHoldability()));
-        
+            fail("FAIL - mismatched statement & ResultSet "
+                    + " Statement class " + s.getClass()
+                    + " ResultSet' Statements class "
+                    + rs.getStatement().getClass());
+        }
+
+        boolean held = (ResultSet.HOLD_CURSORS_OVER_COMMIT == s
+                .getResultSetHoldability());
         rs.next();
-        System.out.println("  BC A=" + rs.getInt(1));
+        assertEquals(0, rs.getInt(1));
         conn.commit();
-       
+
         try {
-            while (rs.next())
-            {
-                rs.getInt(1);
-                System.out.println("  AC A=" + rs.getInt(1));
-            }
-           if (!held)
-               System.out.println("FAIL: non-held cursor not closed by commit");
-        } catch (SQLException sqle)
-        {
+            rs.next();
+        } catch (SQLException sqle) {
             boolean ok = !held;
-            boolean showError = true;
+
             if (ok) {
-                if (TestUtil.isEmbeddedFramework()) {
-                    if ("XCL16".equals(sqle.getSQLState()))
-                        showError = false;
-                } else if (TestUtil.isDerbyNetClientFramework()) {
-                    // No SQL state yet from client error.
-                    showError = false;
-                }
+                assertSQLState("XCL16", sqle);
+            } else {
+                fail("Held cursor closed on commit");
             }
-            if (showError)
-                TestUtil.dumpSQLExceptions(sqle, ok);
-            else if (ok)
-                System.out.println("Non-held ResultSet correctly closed after commit");
         }
-        
+
         rs.close();
         conn.commit();
     }
-    
-    /**
-     * Show the held status of the Statement.
-    */
-    private static void showHoldStatus(String tag, Statement s) throws SQLException
-    {
-        System.out.println(tag + "Statement holdable " +
-                holdStatus(s.getResultSetHoldability()));
-        SQLWarning w = s.getConnection().getWarnings();
-        while (w != null)
-        {
-            System.out.println(w.getSQLState() + " :" + w.toString());
-            w = w.getNextWarning();
-        }
-        s.getConnection().clearWarnings();
-        
-    }
-    /**
-     * Show the held status of the Connection.
-    */
-    private static void showHoldStatus(String tag, Connection conn) throws SQLException
-    {
-        System.out.println(tag + "Connection holdable " +
-                holdStatus(conn.getHoldability()));
-    }
-    
-    private static String holdStatus(int holdability)
-    {
-        String s;
-        switch (holdability)
-        {
-        case ResultSet.CLOSE_CURSORS_AT_COMMIT:
-            s = "CLOSE_CURSORS_AT_COMMIT ";
-            break;
-        case ResultSet.HOLD_CURSORS_OVER_COMMIT:
-            s = "HOLD_CURSORS_OVER_COMMIT ";
-            break;
-        default:
-            s = "UNKNOWN HOLDABILITY ";
-            break;
-        }
-        
-        return s + Integer.toString(holdability);
+
+    public static Test baseSuite(String name) {
+        TestSuite suite = new TestSuite(name);
+        suite.addTestSuite(XATest.class);
+
+        return new CleanDatabaseTestSetup(suite) {
+            /**
+             * Creates the table used in the test cases.
+             * 
+             */
+            protected void decorateSQL(Statement s) throws SQLException {
+                Connection conn = getConnection();
+                XATestUtil.createXATransactionView(conn);
+            }
+
+        };
     }
-    
-    /*
-     * 5 interleaving transactions.
-     * Taken from the SQL test xaANotherTest.
-     * <code>
-xa_connect user 'mamta' password 'mamta' ;
-
--- global connection 1
-xa_start xa_noflags 1;
-xa_getconnection;
-insert into APP.foo values (1);
-xa_end xa_suspend 1;
-
--- global connection 2
-xa_start xa_noflags 2;
-insert into APP.foo values (2);
-xa_end xa_suspend 2;
-
--- global connection 3
-xa_start xa_noflags 3;
-insert into APP.foo values (3);
-xa_end xa_suspend 3;
-
--- global connection 4
-xa_start xa_noflags 4;
-insert into APP.foo values (4);
-xa_end xa_suspend 4;
-
--- global connection 5
-xa_start xa_noflags 5;
-insert into APP.foo values (5);
-xa_end xa_suspend 5;
-
-xa_start xa_resume 1;
-insert into APP.foo values (11);
-xa_end xa_suspend 1;
-
-xa_start xa_resume 5;
-insert into APP.foo values (55);
-xa_end xa_suspend 5;
-
-xa_start xa_resume 2;
-insert into APP.foo values (22);
-xa_end xa_suspend 2;
-
-xa_start xa_resume 4;
-insert into APP.foo values (44);
-xa_end xa_suspend 4;
-
-xa_start xa_resume 3;
-insert into APP.foo values (33);
-xa_end xa_suspend 3;
-
--- prepare all the global connections except the first one. This way, we will see all
--- the global transactions prepared so far after the database shutdown and restart.
-xa_end xa_success 2;
-xa_prepare 2;
-xa_end xa_success 3;
-xa_prepare 3;
-xa_end xa_success 4;
-xa_prepare 4;
-xa_end xa_success 5;
-xa_prepare 5;
 
-     * </code>
+    /**
+     * Runs the test fixtures in embedded and client.
+     * 
+     * @return test suite
      */
-    private static void interleavingTransactions5(XADataSource xads) throws SQLException
-    {
-        System.out.println("interleavingTransactions5");
-        
-        XAConnection xac = xads.getXAConnection("mamta", "mamtapwd");
-        
+    public static Test suite() {
+        TestSuite suite = new TestSuite("XATest");
+        // no XA for JSR169
+        if (JDBC.vmSupportsJSR169())
+            return suite;
+        suite.addTest(baseSuite("XATest:embedded"));
+
+        suite.addTest(TestConfiguration
+                .clientServerDecorator(baseSuite("XATest:client")));
+        return suite;
     }
 
-    private static void cleanUp(Connection conn) throws SQLException
-    {
-        String testObjects[] = { "view XATESTUTIL.global_xactTable", 
-                                 "schema XATESTUTIL restrict", "table app.foo", "table foo" };
-        Statement stmt = conn.createStatement();
-        TestUtil.cleanUpTest(stmt, testObjects);
-        conn.commit();
-        stmt.close();
-    }
- 
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/J2EEDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/J2EEDataSource.java?view=diff&rev=521854&r1=521853&r2=521854
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/J2EEDataSource.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/J2EEDataSource.java Fri Mar 23 11:38:28 2007
@@ -68,6 +68,20 @@
     {
         return getXADataSource(TestConfiguration.getCurrent(), (HashMap) null);
     }
+    
+    
+    /**
+     * Set a bean property for a data source. This code can be used
+     * on any data source type.
+     * @param ds DataSource to have property set
+     * @param property name of property.
+     * @param value Value, type is derived from value's class.
+     */
+    public static void setBeanProperty(Object ds, String property, Object value) {
+       // reuse code from JDBCDataSource
+        JDBCDataSource.setBeanProperty(ds, property, value);
+    }
+    
     /**
      * Create a new DataSource object setup from the passed in TestConfiguration.
      * The getXAConnection() method is configured



Mime
View raw message