本文整理汇总了Java中javax.sql.XAConnection类的典型用法代码示例。如果您正苦于以下问题:Java XAConnection类的具体用法?Java XAConnection怎么用?Java XAConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XAConnection类属于javax.sql包,在下文中一共展示了XAConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getXAConnection
import javax.sql.XAConnection; //导入依赖的package包/类
/**
* Get new XAConnection connection, to be managed by a connection manager.
*/
public XAConnection getXAConnection() throws SQLException {
// Comment out before public release:
/*
System.err.print("Executing " + getClass().getName()
+ ".getXAConnection()...");
*/
// Use JDBCDriver directly so there is no need to register with DriverManager
JDBCConnection connection =
(JDBCConnection) JDBCDriver.getConnection(url, connectionProps);
JDBCXAConnection xaConnection = new JDBCXAConnection(this, connection);
return xaConnection;
}
示例2: testBug46925
import javax.sql.XAConnection; //导入依赖的package包/类
public void testBug46925() throws Exception {
MysqlXADataSource xads1 = new MysqlXADataSource();
MysqlXADataSource xads2 = new MysqlXADataSource();
Xid txid = new MysqlXid(new byte[] { 0x1 }, new byte[] { 0xf }, 3306);
xads1.setPinGlobalTxToPhysicalConnection(true);
xads1.setUrl(dbUrl);
xads2.setPinGlobalTxToPhysicalConnection(true);
xads2.setUrl(dbUrl);
XAConnection c1 = xads1.getXAConnection();
assertTrue(c1 instanceof SuspendableXAConnection);
// start a transaction on one connection
c1.getXAResource().start(txid, XAResource.TMNOFLAGS);
c1.getXAResource().end(txid, XAResource.TMSUCCESS);
XAConnection c2 = xads2.getXAConnection();
assertTrue(c2 instanceof SuspendableXAConnection);
// prepare on another one. Since we are using a "pinned" connection we should have the same "currentXAConnection" for both SuspendableXAConnection
c2.getXAResource().prepare(txid); // this will fail without the fix.
c2.getXAResource().commit(txid, false);
}
示例3: testBug69506
import javax.sql.XAConnection; //导入依赖的package包/类
/**
* Tests fix for BUG#69506 - XAER_DUPID error code is not returned when a duplicate XID is offered in Java.
*
* @throws Exception
* if the test fails.
*/
public void testBug69506() throws Exception {
MysqlXADataSource dataSource = new MysqlXADataSource();
dataSource.setUrl(dbUrl);
XAConnection testXAConn1 = dataSource.getXAConnection();
XAConnection testXAConn2 = dataSource.getXAConnection();
Xid duplicateXID = new MysqlXid("1".getBytes(), "1".getBytes(), 1);
testXAConn1.getXAResource().start(duplicateXID, 0);
try {
testXAConn2.getXAResource().start(duplicateXID, 0);
fail("XAException was expected.");
} catch (XAException e) {
assertEquals("Wrong error code retured for duplicated XID.", XAException.XAER_DUPID, e.errorCode);
}
}
示例4: switchToXid
import javax.sql.XAConnection; //导入依赖的package包/类
private synchronized void switchToXid(Xid xid) throws XAException {
if (xid == null) {
throw new XAException();
}
try {
if (!xid.equals(this.currentXid)) {
XAConnection toSwitchTo = findConnectionForXid(this.underlyingConnection, xid);
this.currentXAConnection = toSwitchTo;
this.currentXid = xid;
this.currentXAResource = toSwitchTo.getXAResource();
}
} catch (SQLException sqlEx) {
throw new XAException();
}
}
示例5: getXAConnection
import javax.sql.XAConnection; //导入依赖的package包/类
/**
* Get new XAConnection connection, to be managed by a connection manager.
*/
public XAConnection getXAConnection() throws SQLException {
// Comment out before public release:
/*
System.err.print("Executing " + getClass().getName()
+ ".getXAConnection()...");
*/
// Use JDBCDriver directly so there is no need to regiser with DriverManager
JDBCConnection connection =
(JDBCConnection) JDBCDriver.getConnection(url, connectionProps);
JDBCXAConnection xaConnection = new JDBCXAConnection(this, connection);
return xaConnection;
}
示例6: connectionClosed
import javax.sql.XAConnection; //导入依赖的package包/类
/**
* Implementation of call back function from ConnectionEventListener interface. This callback will
* be invoked on connection close event.
*
* @param event Connection event object
*/
public void connectionClosed(ConnectionEvent event) {
if (isActive) {
try {
XAConnection conn = (XAConnection) event.getSource();
XAResource xar = (XAResource) xaResourcesMap.get(conn);
xaResourcesMap.remove(conn);
Transaction txn = transManager.getTransaction();
if (txn != null && xar != null)
txn.delistResource(xar, XAResource.TMSUCCESS);
provider.returnConnection(conn);
} catch (Exception e) {
String exception =
"GemFireTransactionDataSource::connectionClosed: Exception occured due to " + e;
if (logger.isDebugEnabled()) {
logger.debug(exception, e);
}
}
}
}
示例7: registerTranxConnection
import javax.sql.XAConnection; //导入依赖的package包/类
/**
*
*/
void registerTranxConnection(XAConnection xaConn) throws Exception {
try {
synchronized (this) {
if (transManager == null) {
transManager = JNDIInvoker.getTransactionManager();
}
}
Transaction txn = transManager.getTransaction();
if (txn != null) {
XAResource xar = xaConn.getXAResource();
txn.enlistResource(xar);
// Add in the Map after successful registration of XAResource
this.xaResourcesMap.put(xaConn, xar);
}
} catch (Exception ex) {
Exception e = new Exception(
LocalizedStrings.GemFireTransactionDataSource_GEMFIRETRANSACTIONDATASOURCEREGISTERTRANXCONNECTION_EXCEPTION_IN_REGISTERING_THE_XARESOURCE_WITH_THE_TRANSACTIONEXCEPTION_OCCURED_0
.toLocalizedString(ex));
e.initCause(ex);
throw e;
}
}
示例8: 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();
}
示例9: testCloseActiveConnection_XA_global
import javax.sql.XAConnection; //导入依赖的package包/类
/**
* 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);
}
示例10: 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();
}
示例11: testConnectionFlowCommit
import javax.sql.XAConnection; //导入依赖的package包/类
/**
* 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();
}
示例12: shouldGetConnectionAndCommit
import javax.sql.XAConnection; //导入依赖的package包/类
@Test
public void shouldGetConnectionAndCommit() throws SQLException {
Connection mockConnection = mock(Connection.class);
XAConnection mockXaConnection = mock(XAConnection.class);
given(mockXaConnection.getConnection()).willReturn(mockConnection);
given(this.dataSource.getXAConnection()).willReturn(mockXaConnection);
Properties properties = new Properties();
properties.put(TransactionalDriver.XADataSource, this.dataSource);
Connection connection = this.dataSourceBean.getConnection();
assertThat(connection).isInstanceOf(ConnectionImple.class);
connection.commit();
verify(this.dataSource, times(1)).getXAConnection();
verify(mockXaConnection, times(1)).getConnection();
verify(mockConnection, times(1)).commit();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:NarayanaDataSourceBeanTests.java
示例13: shouldGetConnectionAndCommitWithCredentials
import javax.sql.XAConnection; //导入依赖的package包/类
@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.dataSource.getXAConnection(username, password))
.willReturn(mockXaConnection);
Properties properties = new Properties();
properties.put(TransactionalDriver.XADataSource, this.dataSource);
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.dataSource, times(1)).getXAConnection(username, password);
verify(mockXaConnection, times(1)).getConnection();
verify(mockConnection, times(1)).commit();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:25,代码来源:NarayanaDataSourceBeanTests.java
示例14: getXAConnection
import javax.sql.XAConnection; //导入依赖的package包/类
public XAConnection getXAConnection(String user, String password) throws SQLException {
final Properties info = new Properties();
info.putAll(properties);
if (!isEmpty(user)) {
info.put("user", user);
}
if (!isEmpty(password)) {
info.put("password", password);
}
int currentLoginTimeout = DriverManager.getLoginTimeout();
try {
DriverManager.setLoginTimeout(loginTimeout);
final Connection con = DriverManager.getConnection(url, info);
return new XAConnectionImpl(con);
} finally {
try {
DriverManager.setLoginTimeout(currentLoginTimeout);
} catch (Exception e) {
logger.info("Failed to set login timeout: currentLoginTimeout=" + currentLoginTimeout, e);
}
}
}
示例15: testBug46925
import javax.sql.XAConnection; //导入依赖的package包/类
public void testBug46925() throws Exception {
MysqlXADataSource xads1 = new MysqlXADataSource();
MysqlXADataSource xads2 = new MysqlXADataSource();
Xid txid = new MysqlXid(new byte[] { 0x1 }, new byte[] { 0xf }, 3306);
xads1.setPinGlobalTxToPhysicalConnection(true);
xads1.setUrl(dbUrl);
xads2.setPinGlobalTxToPhysicalConnection(true);
xads2.setUrl(dbUrl);
XAConnection c1 = xads1.getXAConnection();
assertTrue(c1 instanceof SuspendableXAConnection);
// start a transaction on one connection
c1.getXAResource().start(txid, XAResource.TMNOFLAGS);
c1.getXAResource().end(txid, XAResource.TMSUCCESS);
XAConnection c2 = xads2.getXAConnection();
assertTrue(c2 instanceof SuspendableXAConnection);
// prepare on another one. Since we are using a "pinned" connection
// we should have the same "currentXAConnection" for both
// SuspendableXAConnection
c2.getXAResource().prepare(txid); // this will fail without the fix.
c2.getXAResource().commit(txid, false);
}