javax.sql.XAConnection Java Examples

The following examples show how to use javax.sql.XAConnection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: J2EEDataSourceTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Test that connections retrieved from {@code XADataSource} that are part
 * of a global XA transaction, behave as expected when {@code close()} is
 * called and the transaction is active.
 */
public void testCloseActiveConnection_XA_global()
    throws SQLException, XAException
{
    XADataSource ds = J2EEDataSource.getXADataSource();
    XAConnection xa = ds.getXAConnection();
    XAResource xar = xa.getXAResource();
    Xid xid = new cdsXid(1, (byte) 2, (byte) 3);
    xar.start(xid, XAResource.TMNOFLAGS);
    // auto-commit is always off in XA transactions, so we expect
    // getAutoCommit() to return false without having set it explicitly
    testCloseActiveConnection(xa.getConnection(), false, true);
    Connection c = xa.getConnection();
    c.setAutoCommit(false);
    testCloseActiveConnection(c, false, true);
    xar.end(xid, XAResource.TMSUCCESS);
}
 
Example #2
Source File: J2EEDataSourceTest.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * check whether commit without statement will flow by checking its transaction id
 * on client. This test is run only for client where commits without an
 * active transactions will not flow to the server.
 * DERBY-4653
 *
 * @throws SQLException
 **/
public void testConnectionFlowCommit()
        throws SQLException {
    ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();

    PooledConnection pc = ds.getPooledConnection();
    Connection conn = pc.getConnection();

    testConnectionFlowCommitWork(conn);
    conn.close();

    //Test for XADataSource
    XADataSource xs = J2EEDataSource.getXADataSource();
    XAConnection xc = xs.getXAConnection();
    conn = xc.getConnection();
    testConnectionFlowCommitWork(conn);
    conn.close();

    //Test for DataSource
    DataSource jds = JDBCDataSource.getDataSource();
    conn = jds.getConnection();
    testConnectionFlowCommitWork(conn);
    conn.close();
}
 
Example #3
Source File: FHIRProxyXADataSource.java    From FHIR with Apache License 2.0 6 votes vote down vote up
@Override
public XAConnection getXAConnection() throws SQLException {
    log.entering(this.getClass().getName(), "getXAConnection()");
    try {
        XAConnection connection = null;

        // XA recovery will be triggered by a call to this method, while
        // threadlocal contains "default/default" for the tenant-id and datastore-id.
        // If we find something else on thread-local then we'll treat it as an error.
        String tenantId = FHIRRequestContext.get().getTenantId();
        String dsId = FHIRRequestContext.get().getDataStoreId();
        if (FHIRConfiguration.DEFAULT_TENANT_ID.equals(tenantId) && FHIRConfiguration.DEFAULT_DATASTORE_ID.equals(dsId)) {
            log.info("Initiating XA recovery process...");
            connection = new RMXAConnectionResource(this);
        } else {
            throw new SQLException("The getXAConnection() method should be called only during XA recovery.");
        }
        return connection;
    } finally {
        log.exiting(this.getClass().getName(), "getXAConnection()");
    }
}
 
Example #4
Source File: XATransactionTest.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * DERBY-4232: Test that an XA transaction can be suspended and resumed
 * when a timeout is in effect.
 */
public void testTransactionTimeoutAndSuspendResume() throws Exception {
    XADataSource xads = J2EEDataSource.getXADataSource();
    XAConnection xac = xads.getXAConnection();
    XAResource xar = xac.getXAResource();
    Xid xid = XATestUtil.getXid(1, 2, 3);

    // Start work in a new transaction with a timeout
    xar.setTransactionTimeout(500);
    xar.start(xid, XAResource.TMNOFLAGS);

    // Suspend the transaction
    xar.end(xid, XAResource.TMSUSPEND);

    // Resume the transaction (used to fail with a XAER_PROTO on the
    // network client)
    xar.start(xid, XAResource.TMRESUME);

    // End the transaction and free up the resources
    xar.end(xid, XAResource.TMSUCCESS);
    xar.rollback(xid);
    xac.close();
}
 
Example #5
Source File: TestFBXADataSource.java    From jaybird with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Test if calling commit throws an exception when participating in a distributed transaction (JDBC 4.0 section 12.4).
 */
@Test
public void testInDistributed_commit() throws Exception {
    XAConnection pc = getXAConnection();
    XAResource xa = pc.getXAResource();
    Xid xid = new XidImpl();
    try (Connection con = pc.getConnection()) {
        con.setAutoCommit(false);
        xa.start(xid, XAResource.TMNOFLAGS);

        expectedException.expect(SQLException.class);
        expectedException.expect(sqlStateEquals(SQLStateConstants.SQL_STATE_INVALID_TX_STATE));

        con.commit();
    } finally {
        xa.end(xid, XAResource.TMSUCCESS);
        xa.rollback(xid);
    }
}
 
Example #6
Source File: TestFBXADataSource.java    From jaybird with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void enableWireCompression() throws Exception {
    assumeThat("Test only works with pure java connections", FBTestProperties.GDS_TYPE, isPureJavaType());
    assumeTrue("Test requires wire compression", getDefaultSupportInfo().supportsWireCompression());
    ds.setWireCompression(true);

    XAConnection xaConnection = ds.getXAConnection();
    try (Connection connection = xaConnection.getConnection()){
        assertTrue(connection.isValid(0));
        GDSServerVersion serverVersion =
                connection.unwrap(FirebirdConnection.class).getFbDatabase().getServerVersion();
        assertTrue("expected wire compression in use", serverVersion.isWireCompressionUsed());
    } finally {
        xaConnection.close();
    }
}
 
Example #7
Source File: NarayanaDataSourceTests.java    From narayana-spring-boot with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldGetConnectionAndCommitWithCredentials() throws SQLException {
    String username = "testUsername";
    String password = "testPassword";
    Connection mockConnection = mock(Connection.class);
    XAConnection mockXaConnection = mock(XAConnection.class);
    given(mockXaConnection.getConnection()).willReturn(mockConnection);
    given(this.mockXaDataSource.getXAConnection(username, password)).willReturn(mockXaConnection);

    // TODO properties not used
    Properties properties = new Properties();
    properties.put(TransactionalDriver.XADataSource, this.mockXaDataSource);
    properties.put(TransactionalDriver.userName, username);
    properties.put(TransactionalDriver.password, password);

    Connection connection = this.dataSourceBean.getConnection(username, password);
    assertThat(connection).isInstanceOf(ConnectionImple.class);

    connection.commit();

    verify(this.mockXaDataSource, times(1)).getXAConnection(username, password);
    verify(mockXaConnection, times(1)).getConnection();
    verify(mockConnection, times(1)).commit();
}
 
Example #8
Source File: J2EEDataSourceTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * check whether commit without statement will flow by checking its transaction id
 * on client. This test is run only for client where commits without an
 * active transactions will not flow to the server.
 * DERBY-4653
 * 
 * @throws SQLException
 **/
public void testConnectionFlowCommit()
        throws SQLException {
    ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();

    PooledConnection pc = ds.getPooledConnection();
    Connection conn = pc.getConnection();

    testConnectionFlowCommitWork(conn, 1);
    conn.close();
    
    //Test for XADataSource
    XADataSource xs = J2EEDataSource.getXADataSource();
    XAConnection xc = xs.getXAConnection();
    conn = xc.getConnection();
    testConnectionFlowCommitWork(conn, 1);
    conn.close();
    
    //Test for DataSource
    DataSource jds = JDBCDataSource.getDataSource();
    conn = jds.getConnection();
    testConnectionFlowCommitWork(conn, 1);
    conn.close();       
}
 
Example #9
Source File: TestFBXADataSource.java    From jaybird with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Tests if the connection obtained from the PooledConnection can be used
 * and has expected defaults.
 */
@Test
public void testConnection() throws SQLException {
    XAConnection pc = getXAConnection();

    Connection con = pc.getConnection();

    assertTrue("Autocommit should be true", con.getAutoCommit());
    assertTrue("Read-only should be false", !con.isReadOnly());
    assertEquals("Tx isolation level should be read committed.",
            Connection.TRANSACTION_READ_COMMITTED, con.getTransactionIsolation());

    try (Statement stmt = con.createStatement()) {
        ResultSet rs = stmt.executeQuery("SELECT cast(1 AS INTEGER) FROM rdb$database");

        assertTrue("Should select one row", rs.next());
        assertEquals("Selected value should be 1.", 1, rs.getInt(1));
    }
    con.close();
    assertTrue("Connection should report as being closed.", con.isClosed());
}
 
Example #10
Source File: J2EEDataSourceTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Test that connections retrieved from {@code XADataSource} that are not
 * part of a global XA transaction, behave as expected when {@code close()}
 * is called and the transaction is active.
 */
public void testCloseActiveConnection_XA_local() throws SQLException {
    XADataSource ds = J2EEDataSource.getXADataSource();
    XAConnection xa = ds.getXAConnection();
    testCloseActiveConnection(xa.getConnection(), true, false);
    Connection c = xa.getConnection();
    c.setAutoCommit(false);
    testCloseActiveConnection(c, false, false);
}
 
Example #11
Source File: MysqlXADataSource.java    From Komondor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Wraps a connection as a 'fake' XAConnection
 */

private XAConnection wrapConnection(Connection conn) throws SQLException {
    if (getPinGlobalTxToPhysicalConnection() || ((com.mysql.jdbc.Connection) conn).getPinGlobalTxToPhysicalConnection()) {
        return SuspendableXAConnection.getInstance((com.mysql.jdbc.Connection) conn);
    }

    return MysqlXAConnection.getInstance((com.mysql.jdbc.Connection) conn, getLogXaCommands());
}
 
Example #12
Source File: DataSourceProxy.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * {@link javax.sql.XADataSource#getXAConnection()}
 */
public XAConnection getXAConnection() throws SQLException {
    Connection con = getConnection();
    if (con instanceof XAConnection) {
        return (XAConnection)con;
    } else {
        try {con.close();} catch (Exception ignore){}
        throw new SQLException("Connection from pool does not implement javax.sql.XAConnection");
    }
}
 
Example #13
Source File: DataSourcePropertiesTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that the default password is not sent as an attribute string when
 * <code>attributesAsPassword</code> is <code>true</code>. The test is run
 * with an <code>XADataSource</code>.
 */
public void embeddedTestAttributesAsPasswordWithoutPassword_xa()
    throws Exception
{
    XADataSource ds = J2EEDataSource.getXADataSource();
    JDBCDataSource.setBeanProperty(ds, "password",  "mypassword");
    JDBCDataSource.setBeanProperty(ds, "attributesAsPassword", Boolean.TRUE);
    XAConnection xa = ds.getXAConnection();
    Connection c = xa.getConnection();
    c.close();
}
 
Example #14
Source File: XATransactionTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testSimpleXATransaction() throws Exception {
  Statement stm = getConnection().createStatement();
  stm.execute("create table XATT2 (i int, text char(10))");

  XADataSource xaDataSource = (XADataSource)TestUtil.getXADataSource(TestUtil.EmbeddedeXADsClassName);
  // create large enough xid
  byte[] gid = new byte[64];
  byte[] bid = new byte[64];
  for (int i = 0; i < 64; i++) {
    gid[i] = (byte)i;
    bid[i] = (byte)(64 - i);
  }
  Xid xid = new ClientXid(0x1234, gid, bid);

  // get the stuff required to execute the global transaction
  XAConnection xaConn = xaDataSource.getXAConnection();
  XAResource xaRes = xaConn.getXAResource();
  Connection conn = xaConn.getConnection();
  conn.setTransactionIsolation(getIsolationLevel());
  // start the transaction with that xid
  xaRes.start(xid, XAResource.TMNOFLAGS);

  // do some work
  stm = conn.createStatement();
  stm.execute("insert into XATT2 values (1234, 'Test_Entry')");
  stm.close();

  stm = getConnection().createStatement();
  stm.execute("select * from XATT2");
  ResultSet rs = stm.getResultSet();
  assertFalse(rs.next());
  // end the work on the transaction branch
  xaRes.end(xid, XAResource.TMSUCCESS);
  xaRes.prepare(xid);
  xaRes.commit(xid, false);
  stm.execute("select * from XATT2");
  rs = stm.getResultSet();
  assertTrue(rs.next());
}
 
Example #15
Source File: MysqlUtils.java    From clearpool with GNU General Public License v3.0 5 votes vote down vote up
public static XAConnection mysqlXAConnection(Connection con) throws SQLException {
  ConnectionImpl mysqlConn = (ConnectionImpl) con;
  if (mysqlConn.getPinGlobalTxToPhysicalConnection()) {
    if (!Util.isJdbc4()) {
      return new SuspendableXAConnection(mysqlConn);
    }
    return new JDBC4SuspendableXAConnection(mysqlConn);
  }
  return new MysqlXAConnection(mysqlConn, false);
}
 
Example #16
Source File: NetXAResource.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
public NetXAResource(XAConnection xaconn, int rmId,
                     String userId, String password,
                     com.splicemachine.db.client.net.NetXAConnection conn) {
    xaconn_ = xaconn;
    rmId_ = rmId;
    conn_ = conn.getNetConnection();
    netXAConn_ = conn;
    rmIdx_ = userId;
    rmIdy_ = password;
    port_ = conn_.netAgent_.getPort();
    ipaddr_ = conn_.netAgent_.socket_.getLocalAddress().getHostAddress();
    conn.setNetXAResource(this);

    // link the primary connection to the first XACallInfo element
    conn_.currXACallInfoOffset_ = 0;

    // construct the NetXACallInfo object for the array.
    for (int i = 0; i < INITIAL_CALLINFO_ELEMENTS; ++i) {
        callInfoArray_[i] = new NetXACallInfo(null, XAResource.TMNOFLAGS, this,
                null);
    }

    // initialize the first XACallInfo element with the information from the
    //  primary connection
    callInfoArray_[0].actualConn_ = conn;
    callInfoArray_[0].currConnection_ = true;
    callInfoArray_[0].freeEntry_ = false;
    // ~~~ save conn_ connection variables in callInfoArray_[0]
    callInfoArray_[0].saveConnectionVariables();
}
 
Example #17
Source File: RMXAConnectionResource.java    From FHIR with Apache License 2.0 5 votes vote down vote up
@Override
public void addConnectionEventListener(ConnectionEventListener listener) {
    log.entering(this.getClass().getName(), "addConnectionEventListener");
    try {
        // Drive the method calls to each of the proxied XAConnections.
        List<XAConnection> connections = getProxiedXAConnections();
        for (XAConnection connection : connections) {
            connection.addConnectionEventListener(listener);
        }
    } finally {
        log.exiting(this.getClass().getName(), "addConnectionEventListener");
    }
}
 
Example #18
Source File: ProxyConnection.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public Object unwrap(Class<?> iface) throws SQLException {
    if (iface == PooledConnection.class) {
        return connection;
    }else if (iface == XAConnection.class) {
        return connection.getXAConnection();
    } else if (isWrapperFor(iface)) {
        return connection.getConnection();
    } else {
        throw new SQLException("Not a wrapper of "+iface.getName());
    }
}
 
Example #19
Source File: Main.java    From genericconnector with Apache License 2.0 5 votes vote down vote up
private static void runSql(XAConnection xamysql, String username) throws SQLException {
    try(Connection conn = xamysql.getConnection()){
    	try(PreparedStatement stmt = conn.prepareStatement("insert into person(id, name) select max(id)+1, ? from person")){
    		stmt.setString(1, username);
    		stmt.executeUpdate();
    	}
    }
}
 
Example #20
Source File: EmbeddedXADataSource.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Intantiate and return an EmbedXAConnection from this instance
 * of EmbeddedXADataSource.
 *
 * @param user 
 * @param password 
 * @return XAConnection
 */
protected XAConnection createXAConnection (ResourceAdapter ra, 
    String user, String password, boolean requestPassword)
    throws SQLException
{
    /* This object (EmbeddedXADataSource) is a JDBC 2 and JDBC 3
     * implementation of XADatSource.  However, it's possible that we
     * are running with a newer driver (esp. JDBC 4) in which case we
     * should return a PooledConnection that implements the newer JDBC
     * interfaces--even if "this" object does not itself satisfy those
     * interfaces.  As an example, if we have a JDK 6 application then
     * even though this specific object doesn't implement JDBC 4 (it
     * only implements JDBC 2 and 3), we should still return an
     * XAConnection object that *does* implement JDBC 4 because that's
     * what a JDK 6 app expects.
     *
     * By calling "findDriver()" here we will get the appropriate
     * driver for the JDK in use (ex. if using JDK 6 then findDriver()
     * will return the JDBC 4 driver).  If we then ask the driver to
     * give us an XA connection, we will get a connection that
     * corresponds to whatever driver/JDBC implementation is being
     * used--which is what we want.  So for a JDK 6 application we
     * will correctly return a JDBC 4 XAConnection. DERBY-2488.
     *
     * This type of scenario can occur if an application that was
     * previously running with an older JVM (ex. JDK 1.4/1.5) starts
     * running with a newer JVM (ex. JDK 6), in which case the app
     * is probably still using the "old" data source (ex. is still
     * instantiating EmbeddedXADataSource) instead of the newer one
     * (EmbeddedXADataSource40).
     */
    return ((Driver30) findDriver()).getNewXAConnection(
        this, ra, user, password, requestPassword);
}
 
Example #21
Source File: FBXADataSource.java    From jaybird with GNU Lesser General Public License v2.1 5 votes vote down vote up
public XAConnection getXAConnection(String user, String password) throws SQLException {
    if (internalDs == null) {
        initialize();
    }
    FBConnection connection = (FBConnection) internalDs.getConnection(user, password);
    return new FBXAConnection(connection);
}
 
Example #22
Source File: JDBCXADataSource.java    From evosql with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a new XAConnection after validating the given username
 * and password.
 *
 * @param user String which must match the 'user' configured for this
 *             JDBCXADataSource.
 * @param password  String which must match the 'password' configured
 *                  for this JDBCXADataSource.
 *
 * @see #getXAConnection()
 */
public XAConnection getXAConnection(String user,
                                    String password) throws SQLException {

    if (user == null || password == null) {
        throw JDBCUtil.nullArgument();
    }

    if (user.equals(this.user) && password.equals(this.password)) {
        return getXAConnection();
    }

    throw JDBCUtil.sqlException(Error.error(ErrorCode.X_28000));
}
 
Example #23
Source File: TransactionUtil.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
/** Enlists the given XAConnection and if a transaction is active in the current thread, returns a plain JDBC Connection */
public static Connection enlistConnection(XAConnection xacon) throws GenericTransactionException {
    if (xacon == null) {
        return null;
    }
    try {
        XAResource resource = xacon.getXAResource();
        TransactionUtil.enlistResource(resource);
        return xacon.getConnection();
    } catch (SQLException e) {
        throw new GenericTransactionException("SQL error, could not enlist connection in transaction even though transactions are available", e);
    }
}
 
Example #24
Source File: EmbeddedXADataSource.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Intantiate and return an EmbedXAConnection from this instance
 * of EmbeddedXADataSource.
 *
 * @param user 
 * @param password 
 * @return XAConnection
 */
protected XAConnection createXAConnection (ResourceAdapter ra, 
    String user, String password, boolean requestPassword)
    throws SQLException
{
    /* This object (EmbeddedXADataSource) is a JDBC 2 and JDBC 3
     * implementation of XADatSource.  However, it's possible that we
     * are running with a newer driver (esp. JDBC 4) in which case we
     * should return a PooledConnection that implements the newer JDBC
     * interfaces--even if "this" object does not itself satisfy those
     * interfaces.  As an example, if we have a JDK 6 application then
     * even though this specific object doesn't implement JDBC 4 (it
     * only implements JDBC 2 and 3), we should still return an
     * XAConnection object that *does* implement JDBC 4 because that's
     * what a JDK 6 app expects.
     *
     * By calling "findDriver()" here we will get the appropriate
     * driver for the JDK in use (ex. if using JDK 6 then findDriver()
     * will return the JDBC 4 driver).  If we then ask the driver to
     * give us an XA connection, we will get a connection that
     * corresponds to whatever driver/JDBC implementation is being
     * used--which is what we want.  So for a JDK 6 application we
     * will correctly return a JDBC 4 XAConnection. DERBY-2488.
     *
     * This type of scenario can occur if an application that was
     * previously running with an older JVM (ex. JDK 1.4/1.5) starts
     * running with a newer JVM (ex. JDK 6), in which case the app
     * is probably still using the "old" data source (ex. is still
     * instantiating EmbeddedXADataSource) instead of the newer one
     * (EmbeddedXADataSource40).
     */
    return ((Driver30) findDriver()).getNewXAConnection(
        this, ra, user, password, requestPassword);
}
 
Example #25
Source File: DataSourcePropertiesTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Tests that the default password is not sent as an attribute string when
 * <code>attributesAsPassword</code> is <code>true</code>. The test is run
 * with an <code>XADataSource</code>.
 */
public void embeddedTestAttributesAsPasswordWithoutPassword_xa()
    throws Exception
{
    XADataSource ds = J2EEDataSource.getXADataSource();
    JDBCDataSource.setBeanProperty(ds, "password",  "mypassword");
    JDBCDataSource.setBeanProperty(ds, "attributesAsPassword", Boolean.TRUE);
    XAConnection xa = ds.getXAConnection();
    Connection c = xa.getConnection();
    c.close();
}
 
Example #26
Source File: DataSourcePropertiesTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that the <code>attributesAsPassword</code> property of an
 * <code>XADataSource</code> causes an explicitly specified password to be
 * sent as a property string.
 */
public void embeddedTestAttributesAsPasswordWithPassword_xa()
    throws Exception
{
    XADataSource ds = J2EEDataSource.getXADataSource();
    JDBCDataSource.setBeanProperty(ds, "attributesAsPassword", Boolean.TRUE);
    try {
        XAConnection xa = ds.getXAConnection("username", "mypassword");
        fail("Expected getXAConnection to fail.");
    } catch (SQLException e) {
        // expect error because of malformed url
        assertSQLState("XJ028", e);
    }
}
 
Example #27
Source File: ClientXADataSource.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Method that establishes the initial physical connection
 * using DS properties instead of CPDS properties.
 */
private XAConnection getXAConnectionX(LogWriter dncLogWriter,
    ClientBaseDataSource ds, String user, String password)
    throws SQLException
{
    return ClientDRDADriver.getFactory().newClientXAConnection(ds,
            dncLogWriter, user, password);
}
 
Example #28
Source File: ClientXADataSource.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public XAConnection getXAConnection(String user, String password) throws SQLException {
    try
    {
        NetLogWriter dncLogWriter = (NetLogWriter) super.computeDncLogWriterForNewConnection("_xads");
        return getXAConnectionX(dncLogWriter, this, user, password);
    }
    catch ( SqlException se )
    {
        throw se.getSQLException(null /* GemStoneAddition */);
    }
}
 
Example #29
Source File: AbortTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
private void    xa()        throws Exception
{
    XADataSource xads = J2EEDataSource.getXADataSource();
    
    XAConnection conn0 = getXAConnection( xads, "user6");
    XAConnection conn1 = getXAConnection( xads, "user7");
    XAConnection conn2 = getXAConnection( xads, "user8");

    vet( conn0.getConnection(), conn1.getConnection(), conn2.getConnection() );
}
 
Example #30
Source File: XATransactionTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testSimpleXATransaction() throws Exception {
  Statement stm = getConnection().createStatement();
  stm.execute("create table XATT2 (i int, text char(10))");

  XADataSource xaDataSource = (XADataSource)TestUtil.getXADataSource(TestUtil.EmbeddedeXADsClassName);
  // create large enough xid
  byte[] gid = new byte[64];
  byte[] bid = new byte[64];
  for (int i = 0; i < 64; i++) {
    gid[i] = (byte)i;
    bid[i] = (byte)(64 - i);
  }
  Xid xid = new ClientXid(0x1234, gid, bid);

  // get the stuff required to execute the global transaction
  XAConnection xaConn = xaDataSource.getXAConnection();
  XAResource xaRes = xaConn.getXAResource();
  Connection conn = xaConn.getConnection();
  conn.setTransactionIsolation(getIsolationLevel());
  // start the transaction with that xid
  xaRes.start(xid, XAResource.TMNOFLAGS);

  // do some work
  stm = conn.createStatement();
  stm.execute("insert into XATT2 values (1234, 'Test_Entry')");
  stm.close();

  stm = getConnection().createStatement();
  stm.execute("select * from XATT2");
  ResultSet rs = stm.getResultSet();
  assertFalse(rs.next());
  // end the work on the transaction branch
  xaRes.end(xid, XAResource.TMSUCCESS);
  xaRes.prepare(xid);
  xaRes.commit(xid, false);
  stm.execute("select * from XATT2");
  rs = stm.getResultSet();
  assertTrue(rs.next());
}