Search in sources :

Example 1 with ICloudSpannerConnection

use of nl.topicus.jdbc.ICloudSpannerConnection in project spanner-jdbc by olavloite.

the class CloudSpannerXAConnectionTest method testStart.

@Test
public void testStart() throws SQLException, XAException {
    CloudSpannerXAConnection subject = createSubject();
    ICloudSpannerConnection connection = subject.getConnection();
    assertTrue(connection.getAutoCommit());
    Xid xid = createXid();
    subject.start(xid, XAResource.TMNOFLAGS);
    assertNotNull(connection);
    assertFalse(connection.getAutoCommit());
    thrown.expect(CloudSpannerSQLException.class);
    connection.commit();
}
Also used : Xid(javax.transaction.xa.Xid) ICloudSpannerConnection(nl.topicus.jdbc.ICloudSpannerConnection) Test(org.junit.Test) UnitTest(nl.topicus.jdbc.test.category.UnitTest)

Example 2 with ICloudSpannerConnection

use of nl.topicus.jdbc.ICloudSpannerConnection in project spanner-jdbc by olavloite.

the class CloudSpannerXAConnectionTest method testGetConnection.

@Test
public void testGetConnection() throws SQLException {
    CloudSpannerXAConnection subject = createSubject();
    ICloudSpannerConnection connection = subject.getConnection();
    assertNotNull(connection);
    assertTrue(connection.getAutoCommit());
    assertEquals(subject.getXAResource(), subject);
    connection.setAutoCommit(false);
    assertFalse(connection.getAutoCommit());
}
Also used : ICloudSpannerConnection(nl.topicus.jdbc.ICloudSpannerConnection) Test(org.junit.Test) UnitTest(nl.topicus.jdbc.test.category.UnitTest)

Example 3 with ICloudSpannerConnection

use of nl.topicus.jdbc.ICloudSpannerConnection in project spanner-jdbc by olavloite.

the class CloudSpannerXAConnection method getConnection.

/**
 **
 * XAConnection interface
 ***
 */
@Override
public ICloudSpannerConnection getConnection() throws SQLException {
    if (logger.logDebug()) {
        debug("CloudSpannerXAConnection.getConnection called");
    }
    Connection connection = super.getConnection();
    // false.
    if (state == STATE_IDLE) {
        connection.setAutoCommit(true);
    }
    /*
		 * Wrap the connection in a proxy to forbid application from fiddling
		 * with transaction state directly during an XA transaction
		 */
    ConnectionHandler handler = new ConnectionHandler(connection);
    return (ICloudSpannerConnection) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { Connection.class, ICloudSpannerConnection.class }, handler);
}
Also used : CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) CloudSpannerPooledConnection(nl.topicus.jdbc.CloudSpannerPooledConnection) ICloudSpannerConnection(nl.topicus.jdbc.ICloudSpannerConnection) ICloudSpannerConnection(nl.topicus.jdbc.ICloudSpannerConnection)

Aggregations

ICloudSpannerConnection (nl.topicus.jdbc.ICloudSpannerConnection)3 UnitTest (nl.topicus.jdbc.test.category.UnitTest)2 Test (org.junit.Test)2 Connection (java.sql.Connection)1 XAConnection (javax.sql.XAConnection)1 Xid (javax.transaction.xa.Xid)1 CloudSpannerConnection (nl.topicus.jdbc.CloudSpannerConnection)1 CloudSpannerPooledConnection (nl.topicus.jdbc.CloudSpannerPooledConnection)1