グローバルトランザクションの中でConnectionに対してcommit()、rollback()、setAutoCommit(true)などをした場合

JDBC2.0 Standard Extension API の7.4の「More on Connection objects」のとこで

XAConnectionから作られたConnectionに対してグローバルトランザクションの中でcommit()、rollback()、setAutoCommit(true)を呼ぶとSQLExceptionが起きるよ。ローカルトランザクションモードでなら通常のJDBCのConnectionのように使えるけどね。

みたいなことが書いてある。(思いっきり超訳
でも、SeasarのConnectionWrapperImplはグローバルトランザクションの中でもcommit()、rollback()、setAutoCommit(true)が可能みたい。

確かめるにはS2TestCaseを使うのが一番簡単そう。S2.2.8で実行。

public class ConnectionTest extends S2TestCase {

    public ConnectionTest(String args) {
        super(args);
    }

    public static void main(String args[]) {
        junit.textui.TestRunner.run(ConnectionTest.class);
    }

    public void setUp() {
        include("j2ee.dicon");
    }

    public void testCommitTx() throws Exception {
        try {
            getDataSource().getConnection().commit();
            fail();
        } catch (SQLException expected) {
        }
    }

    public void testRollbackTx() throws Exception {
        try {
            getDataSource().getConnection().rollback();
            fail();
        } catch (SQLException expected) {
        }
    }

    public void testSetAutoCommitTx() throws Exception {
        try {
            getDataSource().getConnection().setAutoCommit(true);
            fail();
        } catch (SQLException expected) {
        }
    }

}

結果は次の通りでSQLExceptionは発生してないことがわかる。

.F.F.F
Time: 1.493
There were 3 failures:
1) testCommitTx(ConnectionTest)junit.framework.AssertionFailedError
	at ConnectionTest.testCommitTx(ConnectionTest.java:26)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at org.seasar.extension.unit.S2TestCase.runTestTx(S2TestCase.java:1177)
	at org.seasar.extension.unit.S2TestCase.runBare(S2TestCase.java:904)
	at ConnectionTest.main(ConnectionTest.java:16)
2) testRollbackTx(ConnectionTest)junit.framework.AssertionFailedError
	at ConnectionTest.testRollbackTx(ConnectionTest.java:34)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at org.seasar.extension.unit.S2TestCase.runTestTx(S2TestCase.java:1177)
	at org.seasar.extension.unit.S2TestCase.runBare(S2TestCase.java:904)
	at ConnectionTest.main(ConnectionTest.java:16)
3) testSetAutoCommitTx(ConnectionTest)junit.framework.AssertionFailedError
	at ConnectionTest.testSetAutoCommitTx(ConnectionTest.java:42)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at org.seasar.extension.unit.S2TestCase.runTestTx(S2TestCase.java:1177)
	at org.seasar.extension.unit.S2TestCase.runBare(S2TestCase.java:904)
	at ConnectionTest.main(ConnectionTest.java:16)

FAILURES!!!
Tests run: 3,  Failures: 3,  Errors: 0

Exceptionが起きてくれたほうがうれしいな。