Java Code Examples for com.mysql.jdbc.jdbc2.optional.MysqlXADataSource#setPinGlobalTxToPhysicalConnection()

The following examples show how to use com.mysql.jdbc.jdbc2.optional.MysqlXADataSource#setPinGlobalTxToPhysicalConnection() . 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: ConnectionRegressionTest.java    From r-course with MIT License 6 votes vote down vote up
/**
 * Tests fix for BUG#62452 - NPE thrown in JDBC4MySQLPooledException when statement is closed.
 * 
 * @throws Exception
 */
public void testBug62452() throws Exception {
    PooledConnection con = null;

    MysqlConnectionPoolDataSource pds = new MysqlConnectionPoolDataSource();
    pds.setUrl(dbUrl);
    con = pds.getPooledConnection();
    assertTrue(con instanceof JDBC4MysqlPooledConnection);
    testBug62452WithConnection(con);

    MysqlXADataSource xads = new MysqlXADataSource();
    xads.setUrl(dbUrl);

    xads.setPinGlobalTxToPhysicalConnection(false);
    con = xads.getXAConnection();
    assertTrue(con instanceof JDBC4MysqlXAConnection);
    testBug62452WithConnection(con);

    xads.setPinGlobalTxToPhysicalConnection(true);
    con = xads.getXAConnection();
    assertTrue(con instanceof JDBC4SuspendableXAConnection);
    testBug62452WithConnection(con);

}
 
Example 2
Source File: ConnectionRegressionTest.java    From Komondor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Tests fix for BUG#62452 - NPE thrown in JDBC4MySQLPooledException when statement is closed.
 * 
 * @throws Exception
 */
public void testBug62452() throws Exception {
    PooledConnection con = null;

    MysqlConnectionPoolDataSource pds = new MysqlConnectionPoolDataSource();
    pds.setUrl(dbUrl);
    con = pds.getPooledConnection();
    assertTrue(con instanceof JDBC4MysqlPooledConnection);
    testBug62452WithConnection(con);

    MysqlXADataSource xads = new MysqlXADataSource();
    xads.setUrl(dbUrl);

    xads.setPinGlobalTxToPhysicalConnection(false);
    con = xads.getXAConnection();
    assertTrue(con instanceof JDBC4MysqlXAConnection);
    testBug62452WithConnection(con);

    xads.setPinGlobalTxToPhysicalConnection(true);
    con = xads.getXAConnection();
    assertTrue(con instanceof JDBC4SuspendableXAConnection);
    testBug62452WithConnection(con);

}
 
Example 3
Source File: CustomerConfig.java    From spring-boot-jta-atomikos-sample with Apache License 2.0 6 votes vote down vote up
@Primary
	@Bean(name = "customerDataSource", initMethod = "init", destroyMethod = "close")
//	@Qualifier("customerDataSource")
	public DataSource customerDataSource() {
		MysqlXADataSource mysqlXaDataSource = new MysqlXADataSource();
		mysqlXaDataSource.setUrl(customerDatasourceProperties.getUrl());
		mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);
		mysqlXaDataSource.setPassword(customerDatasourceProperties.getPassword());
		mysqlXaDataSource.setUser(customerDatasourceProperties.getUsername());
		mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);

		AtomikosDataSourceBean xaDataSource = new AtomikosDataSourceBean();
		xaDataSource.setXaDataSource(mysqlXaDataSource);
		xaDataSource.setUniqueResourceName("xads1");
		return xaDataSource;

	}
 
Example 4
Source File: OrderConfig.java    From spring-boot-jta-atomikos-sample with Apache License 2.0 5 votes vote down vote up
@Bean(name = "orderDataSource", initMethod = "init", destroyMethod = "close")
public DataSource orderDataSource() {
	 MysqlXADataSource mysqlXaDataSource = new MysqlXADataSource();
	 mysqlXaDataSource.setUrl(orderDatasourceProperties.getUrl());
	 mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);
	 mysqlXaDataSource.setPassword(orderDatasourceProperties.getPassword());
	 mysqlXaDataSource.setUser(orderDatasourceProperties.getUsername());
	 mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);
	
	 AtomikosDataSourceBean xaDataSource = new AtomikosDataSourceBean();
	 xaDataSource.setXaDataSource(mysqlXaDataSource);
	 xaDataSource.setUniqueResourceName("xads2");
	 return xaDataSource;
}
 
Example 5
Source File: XATest.java    From r-course with MIT License 4 votes vote down vote up
public void testSuspendableTx() throws Exception {
    if (!versionMeetsMinimum(5, 0)) {
        return;
    }

    Connection conn1 = null;

    MysqlXADataSource suspXaDs = new MysqlXADataSource();
    suspXaDs.setUrl(BaseTestCase.dbUrl);
    suspXaDs.setPinGlobalTxToPhysicalConnection(true);
    suspXaDs.setRollbackOnPooledClose(true);

    XAConnection xaConn1 = null;

    Xid xid = createXid();

    try {
        /*
         * -- works using RESUME
         * xa start 0x123,0x456;
         * select * from foo;
         * xa end 0x123,0x456;
         * xa start 0x123,0x456 resume;
         * select * from foo;
         * xa end 0x123,0x456;
         * xa commit 0x123,0x456 one phase;
         */

        xaConn1 = suspXaDs.getXAConnection();
        XAResource xaRes1 = xaConn1.getXAResource();
        conn1 = xaConn1.getConnection();
        xaRes1.start(xid, XAResource.TMNOFLAGS);
        conn1.createStatement().execute("SELECT 1");
        xaRes1.end(xid, XAResource.TMSUCCESS);
        xaRes1.start(xid, XAResource.TMRESUME);
        conn1.createStatement().execute("SELECT 1");
        xaRes1.end(xid, XAResource.TMSUCCESS);
        xaRes1.commit(xid, true);

        xaConn1.close();

        /*
         * 
         * -- fails using JOIN
         * xa start 0x123,0x456;
         * select * from foo;
         * xa end 0x123,0x456;
         * xa start 0x123,0x456 join;
         * select * from foo;
         * xa end 0x123,0x456;
         * xa commit 0x123,0x456 one phase;
         */

        xaConn1 = suspXaDs.getXAConnection();
        xaRes1 = xaConn1.getXAResource();
        conn1 = xaConn1.getConnection();
        xaRes1.start(xid, XAResource.TMNOFLAGS);
        conn1.createStatement().execute("SELECT 1");
        xaRes1.end(xid, XAResource.TMSUCCESS);
        xaRes1.start(xid, XAResource.TMJOIN);
        conn1.createStatement().execute("SELECT 1");
        xaRes1.end(xid, XAResource.TMSUCCESS);
        xaRes1.commit(xid, true);
    } finally {
        if (xaConn1 != null) {
            xaConn1.close();
        }
    }
}
 
Example 6
Source File: XATest.java    From Komondor with GNU General Public License v3.0 4 votes vote down vote up
public void testSuspendableTx() throws Exception {
    if (!versionMeetsMinimum(5, 0)) {
        return;
    }

    Connection conn1 = null;

    MysqlXADataSource suspXaDs = new MysqlXADataSource();
    suspXaDs.setUrl(BaseTestCase.dbUrl);
    suspXaDs.setPinGlobalTxToPhysicalConnection(true);
    suspXaDs.setRollbackOnPooledClose(true);

    XAConnection xaConn1 = null;

    Xid xid = createXid();

    try {
        /*
         * -- works using RESUME
         * xa start 0x123,0x456;
         * select * from foo;
         * xa end 0x123,0x456;
         * xa start 0x123,0x456 resume;
         * select * from foo;
         * xa end 0x123,0x456;
         * xa commit 0x123,0x456 one phase;
         */

        xaConn1 = suspXaDs.getXAConnection();
        XAResource xaRes1 = xaConn1.getXAResource();
        conn1 = xaConn1.getConnection();
        xaRes1.start(xid, XAResource.TMNOFLAGS);
        conn1.createStatement().execute("SELECT 1");
        xaRes1.end(xid, XAResource.TMSUCCESS);
        xaRes1.start(xid, XAResource.TMRESUME);
        conn1.createStatement().execute("SELECT 1");
        xaRes1.end(xid, XAResource.TMSUCCESS);
        xaRes1.commit(xid, true);

        xaConn1.close();

        /*
         * 
         * -- fails using JOIN
         * xa start 0x123,0x456;
         * select * from foo;
         * xa end 0x123,0x456;
         * xa start 0x123,0x456 join;
         * select * from foo;
         * xa end 0x123,0x456;
         * xa commit 0x123,0x456 one phase;
         */

        xaConn1 = suspXaDs.getXAConnection();
        xaRes1 = xaConn1.getXAResource();
        conn1 = xaConn1.getConnection();
        xaRes1.start(xid, XAResource.TMNOFLAGS);
        conn1.createStatement().execute("SELECT 1");
        xaRes1.end(xid, XAResource.TMSUCCESS);
        xaRes1.start(xid, XAResource.TMJOIN);
        conn1.createStatement().execute("SELECT 1");
        xaRes1.end(xid, XAResource.TMSUCCESS);
        xaRes1.commit(xid, true);
    } finally {
        if (xaConn1 != null) {
            xaConn1.close();
        }
    }
}