nl.topicus.jdbc.xa

## Class CloudSpannerXAConnection

- java.lang.Object
- - nl.topicus.jdbc.CloudSpannerPooledConnection
  - - nl.topicus.jdbc.xa.CloudSpannerXAConnection

All Implemented Interfaces:
  AutoCloseable, PooledConnection, XAConnection, XAResource

    public class CloudSpannerXAConnection
    extends CloudSpannerPooledConnection
    implements XAConnection, XAResource

The PostgreSQL implementation of `XAResource`. This implementation doesn't support transaction interleaving (see JTA specification, section 3.4.4) and suspend/resume. Two-phase commit requires PostgreSQL server version 8.1 or higher.

Author:
  Heikki Linnakangas (heikki.linnakangas@iki.fi)

### Field Summary

Fields
`static String` `XA_MUTATION_COLUMN`
`static String` `XA_NUMBER_COLUMN`
`static String` `XA_PREPARED_MUTATIONS_TABLE`
`static String` `XA_XID_COLUMN`

### Fields inherited from interface javax.transaction.xa.XAResource

`TMENDRSCAN, TMFAIL, TMJOIN, TMNOFLAGS, TMONEPHASE, TMRESUME, TMSTARTRSCAN, TMSUCCESS, TMSUSPEND, XA_OK, XA_RDONLY`

### Constructor Summary

Constructors
Constructor and Description
`CloudSpannerXAConnection(CloudSpannerConnection conn)`
`CloudSpannerXAConnection(CloudSpannerConnection conn, boolean createXATable)`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `commit(Xid xid, boolean onePhase)`
`void` `end(Xid xid, int flags)` Preconditions: 1.
`void` `forget(Xid xid)`
`ICloudSpannerConnection` `getConnection()` XAConnection interface
`int` `getTransactionTimeout()` We don't do transaction timeouts.
`XAResource` `getXAResource()`
`boolean` `isSameRM(XAResource xares)`
`int` `prepare(Xid xid)` Preconditions: 1.
`Xid[]` `recover(int flag)` Preconditions: 1.
`void` `rollback(Xid xid)` Preconditions: 1.
`boolean` `setTransactionTimeout(int seconds)` We don't do transaction timeouts.
`void` `start(Xid xid, int flags)` Preconditions: 1.

### Methods inherited from class nl.topicus.jdbc.CloudSpannerPooledConnection

`addConnectionEventListener, addStatementEventListener, close, createConnectionEvent, getParentLogger, removeConnectionEventListener, removeStatementEventListener`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface javax.sql.PooledConnection

`addConnectionEventListener, addStatementEventListener, close, removeConnectionEventListener, removeStatementEventListener`

### Field Detail

#### XA_PREPARED_MUTATIONS_TABLE

    public static final String XA_PREPARED_MUTATIONS_TABLE

See Also:
  Constant Field Values

#### XA_XID_COLUMN

    public static final String XA_XID_COLUMN

See Also:
  Constant Field Values

#### XA_NUMBER_COLUMN

    public static final String XA_NUMBER_COLUMN

See Also:
  Constant Field Values

#### XA_MUTATION_COLUMN

    public static final String XA_MUTATION_COLUMN

See Also:
  Constant Field Values

### Constructor Detail

#### CloudSpannerXAConnection

    public CloudSpannerXAConnection(CloudSpannerConnection conn)
                             throws SQLException

Throws:
  `SQLException`

#### CloudSpannerXAConnection

    public CloudSpannerXAConnection(CloudSpannerConnection conn,
                                    boolean createXATable)
                             throws SQLException

Throws:
  `SQLException`

### Method Detail

#### getConnection

    public ICloudSpannerConnection getConnection()
                                          throws SQLException

XAConnection interface

Specified by:
  `getConnection` in interface `PooledConnection`
Overrides:
  `getConnection` in class `CloudSpannerPooledConnection`
Throws:
  `SQLException`

#### getXAResource

    public XAResource getXAResource()

Specified by:
  `getXAResource` in interface `XAConnection`

#### start

    public void start(Xid xid,
                      int flags)
               throws XAException

Preconditions: 1. flags must be one of TMNOFLAGS, TMRESUME or TMJOIN 2. xid != null 3. connection must not be associated with a transaction 4. the TM hasn't seen the xid before Implementation deficiency preconditions: 1. TMRESUME not supported. 2. if flags is TMJOIN, we must be in ended state, and xid must be the current transaction 3. unless flags is TMJOIN, previous transaction using the connection must be committed or prepared or rolled back Postconditions: 1. Connection is associated with the transaction

Specified by:
  `start` in interface `XAResource`
Throws:
  `XAException`
See Also:
  `XAResource.start(Xid, int)`

#### end

    public void end(Xid xid,
                    int flags)
             throws XAException

Preconditions: 1. Flags is one of TMSUCCESS, TMFAIL, TMSUSPEND 2. xid != null 3. Connection is associated with transaction xid Implementation deficiency preconditions: 1. Flags is not TMSUSPEND Postconditions: 1. connection is disassociated from the transaction.

Specified by:
  `end` in interface `XAResource`
Throws:
  `XAException`
See Also:
  `XAResource.end(Xid, int)`

#### prepare

    public int prepare(Xid xid)
                throws XAException

Preconditions: 1. xid != null 2. xid is in ended state Implementation deficiency preconditions: 1. xid was associated with this connection Postconditions: 1. Transaction is prepared

Specified by:
  `prepare` in interface `XAResource`
Throws:
  `XAException`
See Also:
  `XAResource.prepare(Xid)`

#### recover

    public Xid[] recover(int flag)
                  throws XAException

Preconditions: 1. flag must be one of TMSTARTRSCAN, TMENDRSCAN, TMNOFLAGS or TMSTARTTRSCAN | TMENDRSCAN 2. if flag isn't TMSTARTRSCAN or TMSTARTRSCAN | TMENDRSCAN, a recovery scan must be in progress Postconditions: 1. list of prepared xids is returned

Specified by:
  `recover` in interface `XAResource`
Throws:
  `XAException`
See Also:
  `XAResource.recover(int)`

#### rollback

    public void rollback(Xid xid)
                  throws XAException

Preconditions: 1. xid is known to the RM or it's in prepared state Implementation deficiency preconditions: 1. xid must be associated with this connection if it's not in prepared state. Postconditions: 1. Transaction is rolled back and disassociated from connection

Specified by:
  `rollback` in interface `XAResource`
Throws:
  `XAException`

#### commit

    public void commit(Xid xid,
                       boolean onePhase)
                throws XAException

Specified by:
  `commit` in interface `XAResource`
Throws:
  `XAException`

#### isSameRM

    public boolean isSameRM(XAResource xares)
                     throws XAException

Specified by:
  `isSameRM` in interface `XAResource`
Throws:
  `XAException`

#### forget

    public void forget(Xid xid)
                throws XAException

Specified by:
  `forget` in interface `XAResource`
Throws:
  `XAException`

#### getTransactionTimeout

    public int getTransactionTimeout()

We don't do transaction timeouts. Just returns 0.

Specified by:
  `getTransactionTimeout` in interface `XAResource`

#### setTransactionTimeout

    public boolean setTransactionTimeout(int seconds)

We don't do transaction timeouts. Returns false.

Specified by:
  `setTransactionTimeout` in interface `XAResource`