当前位置: 首页>>代码示例>>Java>>正文


Java XAConnection.close方法代码示例

本文整理汇总了Java中javax.sql.XAConnection.close方法的典型用法代码示例。如果您正苦于以下问题:Java XAConnection.close方法的具体用法?Java XAConnection.close怎么用?Java XAConnection.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.sql.XAConnection的用法示例。


在下文中一共展示了XAConnection.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testMixedXaNormal

import javax.sql.XAConnection; //导入方法依赖的package包/类
private void testMixedXaNormal() throws Exception {
    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL("jdbc:h2:mem:test");
    ds.setUser("sa");
    ds.setPassword("");
    XAConnection xa = ds.getXAConnection();
    Connection c = xa.getConnection();
    assertTrue(c.getAutoCommit());
    MyXid xid = new MyXid();
    XAResource res = xa.getXAResource();

    res.start(xid, XAResource.TMNOFLAGS);
    assertTrue(!c.getAutoCommit());
    res.end(xid, XAResource.TMSUCCESS);
    res.commit(xid, true);
    assertTrue(c.getAutoCommit());

    res.start(xid, XAResource.TMNOFLAGS);
    assertTrue(!c.getAutoCommit());
    res.end(xid, XAResource.TMFAIL);
    res.rollback(xid);
    assertTrue(c.getAutoCommit());

    c.close();
    xa.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:27,代码来源:TestXA.java

示例2: testSetSchemaInXAConnection

import javax.sql.XAConnection; //导入方法依赖的package包/类
public void testSetSchemaInXAConnection() throws SQLException {
    // tests that set schema works correctly in an XA connection.

    XADataSource dsx = J2EEDataSource.getXADataSource();
    XAConnection xac3 = dsx.getXAConnection();
    Connection conn3 = xac3.getConnection();
    Statement st3 = conn3.createStatement();
    st3.execute("SET SCHEMA SCHEMA_Patricio");
    st3.close();

    PreparedStatement ps3 = 
        conn3.prepareStatement("INSERT INTO Patricio VALUES (?, ?)");
    ps3.setString(1, "Patricio");
    ps3.setInt(2, 3);
    ps3.executeUpdate();

    assertEquals(1, ps3.getUpdateCount());
    ps3.close();
    conn3.close();
    xac3.close();
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:22,代码来源:J2EEDataSourceTest.java

示例3: testBug62577TestUrl

import javax.sql.XAConnection; //导入方法依赖的package包/类
private void testBug62577TestUrl(String url) throws Exception {
    MysqlXADataSource dataSource = new MysqlXADataSource();
    dataSource.setUrl(url);
    XAConnection xaConn = dataSource.getXAConnection();
    Statement st = xaConn.getConnection().createStatement();
    this.rs = st.executeQuery("SELECT 1;");
    xaConn.close();
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:9,代码来源:ConnectionRegressionTest.java

示例4: testXAAutoCommit

import javax.sql.XAConnection; //导入方法依赖的package包/类
private void testXAAutoCommit() throws Exception {
    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL("jdbc:h2:mem:test");
    ds.setUser("sa");
    ds.setPassword("");
    XAConnection xa = ds.getXAConnection();
    MyXid xid = new MyXid();
    xa.getXAResource().start(xid,
            XAResource.TMNOFLAGS);
    Connection c = xa.getConnection();
    assertTrue(!c.getAutoCommit());
    c.close();
    xa.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:15,代码来源:TestXA.java

示例5: testClosedXADSConnection

import javax.sql.XAConnection; //导入方法依赖的package包/类
public void testClosedXADSConnection() throws SQLException, Exception {
    // verify that outstanding updates from a closed connection, obtained
    // from an XADataSource, are not committed, but rolled back.
    XADataSource dsx = J2EEDataSource.getXADataSource();
    XAConnection xac = dsx.getXAConnection();
    Connection c1 = xac.getConnection();
    Statement s = c1.createStatement();

    c1.setAutoCommit(false);

    // this update should be rolled back
    s.executeUpdate("insert into intTable values(2)");
    
    c1 = xac.getConnection();

    ResultSet rs = c1.createStatement().executeQuery(
       "select count(*) from intTable");
    rs.next();

    assertEquals(0, rs.getInt(1));

    rs.close();
    c1.close();
    xac.close();
    xac = null;

    PoolReset("XADataSource", dsx.getXAConnection());
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:29,代码来源:J2EEDataSourceTest.java

示例6: timeoutTestDerby1144XADS

import javax.sql.XAConnection; //导入方法依赖的package包/类
public void timeoutTestDerby1144XADS() throws SQLException {
   
    XADataSource xds = J2EEDataSource.getXADataSource();
    // Test xa connection isolation
    XAConnection xpc1 = xds.getXAConnection();        
    assertPooledConnIso("XAConnection", xpc1);                 
    xpc1.close();
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:9,代码来源:J2EEDataSourceTest.java

示例7: testBug62577TestUrl

import javax.sql.XAConnection; //导入方法依赖的package包/类
private void testBug62577TestUrl(String url) throws Exception {
    MysqlXADataSource dataSource = new MysqlXADataSource();
    dataSource.setUrl(url);
    XAConnection xaConn = dataSource.getXAConnection();
    Statement st = xaConn.getConnection().createStatement();
    st.executeQuery("SELECT 1;");
    xaConn.close();
}
 
开发者ID:mniepert,项目名称:TPKB,代码行数:9,代码来源:ConnectionRegressionTest.java

示例8: testBug72890

import javax.sql.XAConnection; //导入方法依赖的package包/类
/**
 * Tests fix for BUG#72890 - Java jdbc driver returns incorrect return code when it's part of XA transaction
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug72890() throws Exception {
    MysqlXADataSource myDs = new MysqlXADataSource();
    myDs.setUrl(BaseTestCase.dbUrl);

    final Xid xid = new MysqlXid("72890".getBytes(), "72890".getBytes(), 1);

    final XAConnection xaConn = myDs.getXAConnection();
    final XAResource xaRes = xaConn.getXAResource();
    final Connection dbConn = xaConn.getConnection();
    final long connId = ((MySQLConnection) ((com.mysql.jdbc.Connection) dbConn).getConnectionMutex()).getId();

    xaRes.start(xid, XAResource.TMNOFLAGS);
    xaRes.end(xid, XAResource.TMSUCCESS);
    assertEquals(XAResource.XA_OK, xaRes.prepare(xid));

    // Simulate a connection hang
    this.stmt.execute("KILL CONNECTION " + connId);

    XAException xaEx = assertThrows(XAException.class, "Undetermined error occurred in the underlying Connection - check your data for consistency",
            new Callable<Void>() {
                public Void call() throws Exception {
                    xaRes.commit(xid, false);
                    return null;
                }
            });
    assertEquals("XAException error code", XAException.XAER_RMFAIL, xaEx.errorCode);

    dbConn.close();
    xaConn.close();
}
 
开发者ID:mniepert,项目名称:TPKB,代码行数:37,代码来源:DataSourceRegressionTest.java

示例9: testRecover

import javax.sql.XAConnection; //导入方法依赖的package包/类
@Test
public void testRecover() throws Exception {
    XAConnection xaConnection = dataSource.getXAConnection();
    try {
        Connection connection = xaConnection.getConnection();
        Xid xid = newXid();
        XAResource xaResource = xaConnection.getXAResource();
        xaResource.start(xid, XAResource.TMNOFLAGS);
        connection.createStatement().executeQuery("SELECT 1");
        xaResource.end(xid, XAResource.TMSUCCESS);
        xaResource.prepare(xid);
        Xid[] recoveredXids = xaResource.recover(XAResource.TMSTARTRSCAN | XAResource.TMENDRSCAN);
        assertTrue(recoveredXids != null);
        assertTrue(recoveredXids.length > 0);
        boolean found = false;

        for (Xid x : recoveredXids) {
            if (x != null && x.equals(xid)) {
                found = true;
                break;
            }
        }
        assertTrue(found);
    } finally {
        xaConnection.close();
    }
}
 
开发者ID:MariaDB,项目名称:mariadb-connector-j,代码行数:28,代码来源:DistributedTransactionTest.java

示例10: testSuspendableTx

import javax.sql.XAConnection; //导入方法依赖的package包/类
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();
        }
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:70,代码来源:XATest.java

示例11: testBug72890

import javax.sql.XAConnection; //导入方法依赖的package包/类
/**
 * Tests fix for BUG#72890 - Java jdbc driver returns incorrect return code when it's part of XA transaction
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug72890() throws Exception {
    MysqlXADataSource myDs = new MysqlXADataSource();
    myDs.setUrl(BaseTestCase.dbUrl);

    try {
        final Xid xid = new MysqlXid("72890".getBytes(), "72890".getBytes(), 1);

        final XAConnection xaConn = myDs.getXAConnection();
        final XAResource xaRes = xaConn.getXAResource();
        final Connection dbConn = xaConn.getConnection();
        final long connId = ((MySQLConnection) ((com.mysql.jdbc.Connection) dbConn).getConnectionMutex()).getId();

        xaRes.start(xid, XAResource.TMNOFLAGS);
        xaRes.end(xid, XAResource.TMSUCCESS);
        assertEquals(XAResource.XA_OK, xaRes.prepare(xid));

        // Simulate a connection hang and make sure the connection really dies.
        this.stmt.execute("KILL CONNECTION " + connId);
        int connAliveChecks = 4;
        while (connAliveChecks > 0) {
            this.rs = this.stmt.executeQuery("SHOW PROCESSLIST");
            boolean connIsAlive = false;
            while (!connIsAlive && this.rs.next()) {
                connIsAlive = this.rs.getInt(1) == connId;
            }
            this.rs.close();
            if (connIsAlive) {
                connAliveChecks--;
                System.out.println("Connection id " + connId + " is still alive. Checking " + connAliveChecks + " more times.");
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                }
            } else {
                connAliveChecks = -1;
            }
        }
        if (connAliveChecks == 0) {
            fail("Failed to kill the Connection id " + connId + " in a timely manner.");
        }

        XAException xaEx = assertThrows(XAException.class, "Undetermined error occurred in the underlying Connection - check your data for consistency",
                new Callable<Void>() {
                    public Void call() throws Exception {
                        xaRes.commit(xid, false);
                        return null;
                    }
                });
        assertEquals("XAException error code", XAException.XAER_RMFAIL, xaEx.errorCode);

        dbConn.close();
        xaConn.close();

    } finally {
        /*
         * After MySQL 5.7.7 a prepared XA transaction is no longer rolled back at disconnect. It needs to be rolled back manually to prevent test failures
         * in subsequent runs.
         * Other MySQL versions won't have any transactions to recover.
         */
        final XAConnection xaConnRecovery = myDs.getXAConnection();
        final XAResource xaResRecovery = xaConnRecovery.getXAResource();

        final Xid[] xidsToRecover = xaResRecovery.recover(XAResource.TMSTARTRSCAN);
        for (Xid xidToRecover : xidsToRecover) {
            xaResRecovery.rollback(xidToRecover);
        }

        xaConnRecovery.close();
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:77,代码来源:DataSourceRegressionTest.java

示例12: testRollbackWithoutPrepare

import javax.sql.XAConnection; //导入方法依赖的package包/类
private void testRollbackWithoutPrepare() throws Exception {
    if (config.memory) {
        return;
    }
    Xid xid = new Xid() {
        @Override
        public int getFormatId() {
            return 3145;
        }
        @Override
        public byte[] getGlobalTransactionId() {
            return new byte[] { 1, 2, 3, 4, 5, 6, 6, 7, 8 };
        }
        @Override
        public byte[] getBranchQualifier() {
            return new byte[] { 34, 43, 33, 3, 3, 3, 33, 33, 3 };
        }
    };
    deleteDb("xa");
    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL(getURL("xa", true));
    ds.setPassword(getPassword());
    Connection dm = ds.getConnection();
    Statement stat = dm.createStatement();
    stat.execute("CREATE TABLE IF NOT EXISTS TEST(ID INT PRIMARY KEY, VAL INT)");
    stat.execute("INSERT INTO TEST(ID,VAL) VALUES (1,1)");
    dm.close();
    XAConnection c = ds.getXAConnection();
    XAResource xa = c.getXAResource();
    Connection connection = c.getConnection();
    xa.start(xid, XAResource.TMJOIN);
    PreparedStatement ps = connection.prepareStatement(
            "UPDATE TEST SET VAL=? WHERE ID=?");
    ps.setInt(1, new Random().nextInt());
    ps.setInt(2, 1);
    ps.close();
    xa.rollback(xid);
    connection.close();
    c.close();
    deleteDb("xa");
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:42,代码来源:TestXA.java

示例13: testTwoPhase

import javax.sql.XAConnection; //导入方法依赖的package包/类
private void testTwoPhase(String db, boolean shutdown, boolean commit)
        throws Exception {
    deleteDb(db);
    JdbcDataSource ds = new JdbcDataSource();
    ds.setPassword(getPassword());
    ds.setUser("sa");
    // ds.setURL(getURL("xaSimple", true) + ";trace_level_system_out=3");
    ds.setURL(getURL(db, true));

    XAConnection xa;
    xa = ds.getXAConnection();
    Connection conn;

    conn = xa.getConnection();
    Statement stat = conn.createStatement();
    stat.execute("create table test(id int primary key, name varchar(255))");
    Xid xid = SimpleXid.createRandom();
    xa.getXAResource().start(xid, XAResource.TMNOFLAGS);
    conn.setAutoCommit(false);
    stat.execute("insert into test values(1, 'Hello')");
    xa.getXAResource().end(xid, XAResource.TMSUCCESS);
    xa.getXAResource().prepare(xid);
    if (shutdown) {
        shutdown(ds);
    }

    xa = ds.getXAConnection();
    Xid[] list = xa.getXAResource().recover(XAResource.TMSTARTRSCAN);
    assertEquals(1, list.length);
    assertTrue(xid.equals(list[0]));
    if (commit) {
        xa.getXAResource().commit(list[0], false);
    } else {
        xa.getXAResource().rollback(list[0]);
    }
    conn = xa.getConnection();
    conn.createStatement().executeQuery("select * from test");
    if (shutdown) {
        shutdown(ds);
    }

    xa = ds.getXAConnection();
    list = xa.getXAResource().recover(XAResource.TMSTARTRSCAN);
    assertEquals(0, list.length);
    conn = xa.getConnection();
    ResultSet rs;
    rs = conn.createStatement().executeQuery("select * from test");
    if (commit) {
        assertTrue(rs.next());
    } else {
        assertFalse(rs.next());
    }
    xa.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:55,代码来源:TestXASimple.java

示例14: testSimple

import javax.sql.XAConnection; //导入方法依赖的package包/类
private void testSimple() throws SQLException {

        deleteDb("xaSimple1");
        deleteDb("xaSimple2");
        org.h2.Driver.load();

        // InitialContext context = new InitialContext();
        // context.rebind(USER_TRANSACTION_JNDI_NAME, j.getUserTransaction());

        JdbcDataSource ds1 = new JdbcDataSource();
        ds1.setPassword(getPassword());
        ds1.setUser("sa");
        ds1.setURL(getURL("xaSimple1", true));

        JdbcDataSource ds2 = new JdbcDataSource();
        ds2.setPassword(getPassword());
        ds2.setUser("sa");
        ds2.setURL(getURL("xaSimple2", true));

        // UserTransaction ut = (UserTransaction)
        // context.lookup("UserTransaction");
        // ut.begin();

        XAConnection xa1 = ds1.getXAConnection();
        Connection c1 = xa1.getConnection();
        c1.setAutoCommit(false);
        XAConnection xa2 = ds2.getXAConnection();
        Connection c2 = xa2.getConnection();
        c2.setAutoCommit(false);

        c1.createStatement().executeUpdate(
                "create table test(id int, test varchar(255))");
        c2.createStatement().executeUpdate(
                "create table test(id int, test varchar(255))");

        // ut.rollback();
        c1.close();
        c2.close();

        xa1.close();
        xa2.close();

        // j.stop();
        // System.exit(0);
        deleteDb("xaSimple1");
        deleteDb("xaSimple2");

    }
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:49,代码来源:TestXASimple.java

示例15: XADataSourceStatement

import javax.sql.XAConnection; //导入方法依赖的package包/类
public void XADataSourceStatement(ij parser, Token dbname, Token shutdown,
								String create)
	 throws SQLException
{
	try
	{
		  currentXADataSource = (XADataSource) getXADataSource();

		  databaseName = parser.stringValue(dbname.image);
		  
		  if (isJCC || isNetClient)
		  {
		  	String hostName = System.getProperty("hostName");
		  	if ((hostName != null ) && (!hostName.equals("localhost")))
			{			
		  		xaHelper.setDataSourceProperty(currentXADataSource,
										 "ServerName", hostName);
			}
		  	else
			{			
		  		xaHelper.setDataSourceProperty(currentXADataSource,
						 "ServerName", "localhost");
			}
		  xaHelper.setDataSourceProperty(currentXADataSource,
										 "portNumber", 1527);
		  
		  String user;
		  String password;
		  user = "APP";
		  password = "APP";
		  xaHelper.setDataSourceProperty(currentXADataSource,
										 "user", user);
		  xaHelper.setDataSourceProperty(currentXADataSource,
										 "password", password);
		  //xaHelper.setDataSourceProperty(currentXADataSource,
		  //"traceFile", "trace.out." + framework);
		  }
		  if (isJCC)
		  {
			  xaHelper.setDataSourceProperty(currentXADataSource,
											 "driverType", 4);

			  xaHelper.setDataSourceProperty(currentXADataSource, 
											 "retrieveMessagesFromServerOnGetMessage", true);
		  }
		  xaHelper.setDataSourceProperty(currentXADataSource, "databaseName", databaseName);

		if (shutdown != null && shutdown.toString().toLowerCase(Locale.ENGLISH).equals("shutdown"))
		{	
			if (isJCC || isNetClient)
				xaHelper.setDataSourceProperty(currentXADataSource,"databaseName", databaseName + ";shutdown=true");
			else
				xaHelper.setDataSourceProperty(currentXADataSource, "shutdownDatabase", "shutdown");

			// do a getXAConnection to shut it down */
			currentXADataSource.getXAConnection().getConnection();
			currentXADataSource = null;
			currentXAConnection = null;
		}
		else if (create != null && create.toLowerCase(java.util.Locale.ENGLISH).equals("create"))
		{
			if (isJCC || isNetClient)
				xaHelper.setDataSourceProperty(currentXADataSource,"databaseName", databaseName + ";create=true");
			else
				xaHelper.setDataSourceProperty(currentXADataSource,
											   "createDatabase", "create");

			/* do a getXAConnection to create it */
			XAConnection conn = currentXADataSource.getXAConnection();
			conn.close();
			
			xaHelper.setDataSourceProperty(currentXADataSource, "createDatabase", null);
		}
	}
	catch (Throwable t)
	{
		handleException(t);
	}	
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:80,代码来源:xaHelper.java


注:本文中的javax.sql.XAConnection.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。