本文整理汇总了Java中javax.sql.XADataSource.getXAConnection方法的典型用法代码示例。如果您正苦于以下问题:Java XADataSource.getXAConnection方法的具体用法?Java XADataSource.getXAConnection怎么用?Java XADataSource.getXAConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sql.XADataSource
的用法示例。
在下文中一共展示了XADataSource.getXAConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConnectionFlowCommit
import javax.sql.XADataSource; //导入方法依赖的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();
}
示例2: assertConnectionWOUPFail
import javax.sql.XADataSource; //导入方法依赖的package包/类
protected void assertConnectionWOUPFail(
String expectedSqlState, String dbName, String user, String password)
throws SQLException
{
XADataSource xads = J2EEDataSource.getXADataSource();
JDBCDataSource.setBeanProperty(xads, "databaseName", dbName);
JDBCDataSource.setBeanProperty(xads, "user", user);
JDBCDataSource.setBeanProperty(xads, "password", password);
try {
xads.getXAConnection();
fail("Connection should've been refused/failed");
}
catch (SQLException e) {
assertSQLState(expectedSqlState, e);
}
}
示例3: assertShutdownWOUPOK
import javax.sql.XADataSource; //导入方法依赖的package包/类
protected void assertShutdownWOUPOK(
String dbName, String user, String password)
throws SQLException {
XADataSource xads = J2EEDataSource.getXADataSource();
JDBCDataSource.setBeanProperty(xads, "databaseName", dbName);
JDBCDataSource.setBeanProperty(
xads, "shutdownDatabase", "shutdown");
JDBCDataSource.setBeanProperty(xads, "user", user);
JDBCDataSource.setBeanProperty(xads, "password", password);
try {
xads.getXAConnection();
fail ("expected a failed shutdown connection");
} catch (SQLException e) {
// expect 08006 on successful shutdown
assertSQLState("08006", e);
}
}
示例4: assertShutdownWOUPFail
import javax.sql.XADataSource; //导入方法依赖的package包/类
protected void assertShutdownWOUPFail(
String expectedSqlState, String dbName, String user, String password)
throws SQLException
{
XADataSource xads = J2EEDataSource.getXADataSource();
JDBCDataSource.setBeanProperty(xads, "shutdownDatabase", "shutdown");
JDBCDataSource.setBeanProperty(xads, "databaseName", dbName);
JDBCDataSource.setBeanProperty(xads, "user", user);
JDBCDataSource.setBeanProperty(xads, "password", password);
try {
xads.getXAConnection();
fail("expected failed shutdown");
} catch (SQLException e) {
assertSQLState(expectedSqlState, e);
}
}
示例5: testSetSchemaInXAConnection
import javax.sql.XADataSource; //导入方法依赖的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();
}
示例6: assertSystemShutdownFail
import javax.sql.XADataSource; //导入方法依赖的package包/类
protected void assertSystemShutdownFail(
String expectedError, String dbName, String user, String password)
throws SQLException {
XADataSource xads = J2EEDataSource.getXADataSource();
JDBCDataSource.setBeanProperty(
xads, "shutdownDatabase", "shutdown");
JDBCDataSource.setBeanProperty(xads, "databaseName", dbName);
JDBCDataSource.setBeanProperty(xads, "user", user);
JDBCDataSource.setBeanProperty(xads, "password", password);
try {
xads.getXAConnection();
fail("expected shutdown to fail");
} catch (SQLException e) {
assertSQLState(expectedError, e);
}
}
示例7: assertConnectionFail
import javax.sql.XADataSource; //导入方法依赖的package包/类
public void assertConnectionFail(String dbName) throws SQLException {
XADataSource xads = J2EEDataSource.getXADataSource();
// Reset to no user/password though client requires
// a valid name, so reset to the default
if (usingDerbyNetClient())
JDBCDataSource.setBeanProperty(xads, "user", "APP");
else
JDBCDataSource.clearStringBeanProperty(xads, "user");
JDBCDataSource.clearStringBeanProperty(xads, "password");
JDBCDataSource.setBeanProperty(xads, "databaseName", dbName);
try {
xads.getXAConnection();
fail("expected connection to fail");
} catch (SQLException e) {
assertSQLState("08004", e);
}
}
示例8: testSimpleXATransaction
import javax.sql.XADataSource; //导入方法依赖的package包/类
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());
}
示例9: embeddedTestAttributesAsPasswordWithoutPassword_xa
import javax.sql.XADataSource; //导入方法依赖的package包/类
/**
* 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();
}
示例10: embeddedTestAttributesAsPasswordWithPassword_xa
import javax.sql.XADataSource; //导入方法依赖的package包/类
/**
* 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);
}
}
示例11: assertShutdownUsingSetShutdownOK
import javax.sql.XADataSource; //导入方法依赖的package包/类
protected void assertShutdownUsingSetShutdownOK(
String dbName, String user, String password) throws SQLException {
XADataSource xads = J2EEDataSource.getXADataSource();
JDBCDataSource.setBeanProperty(xads, "databaseName", dbName);
JDBCDataSource.setBeanProperty(
xads, "shutdownDatabase", "shutdown");
try {
xads.getXAConnection(user, password);
fail ("expected a failed shutdown connection");
} catch (SQLException e) {
// expect 08006 on successful shutdown
assertSQLState("08006", e);
}
}
示例12: assertShutdownUsingConnAttrsOK
import javax.sql.XADataSource; //导入方法依赖的package包/类
protected void assertShutdownUsingConnAttrsOK(
String dbName, String user, String password) throws SQLException {
XADataSource xads = J2EEDataSource.getXADataSource();
JDBCDataSource.setBeanProperty(
xads, "connectionAttributes", "shutdown=true");
try {
xads.getXAConnection(user, password);
fail("expected shutdown to fail");
} catch (SQLException e) {
// expect 08006 on successful shutdown
assertSQLState("08006", e);
}
}
示例13: assertShutdownFail
import javax.sql.XADataSource; //导入方法依赖的package包/类
protected void assertShutdownFail(
String expectedSqlState, String dbName, String user, String password)
throws SQLException
{
XADataSource xads = J2EEDataSource.getXADataSource();
JDBCDataSource.setBeanProperty(xads, "shutdownDatabase", "shutdown");
JDBCDataSource.setBeanProperty(xads, "databaseName", dbName);
try {
xads.getXAConnection(user, password);
fail("expected failed shutdown");
} catch (SQLException e) {
assertSQLState(expectedSqlState, e);
}
}
示例14: testCloseActiveConnection_XA_local
import javax.sql.XADataSource; //导入方法依赖的package包/类
/**
* 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);
}
示例15: testAutoCommitOnXAResourceStart
import javax.sql.XADataSource; //导入方法依赖的package包/类
public void testAutoCommitOnXAResourceStart() throws SQLException, XAException {
XADataSource dsx = J2EEDataSource.getXADataSource();
XAConnection xac4 = dsx.getXAConnection();
Xid xid4a= null;
// We get an XAID_DUP error from networkserver when attempting
// the XAResource.start below if we use the same xid.
// Possibly because we're in the same jvm.
// When the test is run with clientserverSuite, rather than default,
// this wasn't needed, so just create a different id for client
if (usingEmbedded())
xid4a = new cdsXid(4, (byte) 23, (byte) 76);
else if (usingDerbyNetClient())
xid4a = new cdsXid(5, (byte) 23, (byte) 76);
Connection conn4 = xac4.getConnection();
assertTrue(conn4.getAutoCommit());
Statement s4 = conn4.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT);
ResultSet rs4 = s4.executeQuery("select i from autocommitxastart");
rs4.next();
assertEquals(1, rs4.getInt(1));
rs4.next();
assertEquals(2, rs4.getInt(1));
// XAResource().start should commit the transaction
xac4.getXAResource().start(xid4a, XAResource.TMNOFLAGS);
xac4.getXAResource().end(xid4a, XAResource.TMSUCCESS);
try {
rs4.next();
fail ("expected an exception indicating resultset is closed.");
} catch (SQLException sqle) {
// Embedded gets 08003. No current connection (DERBY-2620)
if (usingDerbyNetClient())
assertSQLState("XCL16",sqle);
}
conn4.setAutoCommit(false);
assertFalse(conn4.getAutoCommit());
rs4 = s4.executeQuery("select i from autocommitxastart");
rs4.next();
assertEquals(1, rs4.getInt(1));
rs4.next();
assertEquals(2, rs4.getInt(1));
// Get a new xid to begin another transaction.
if (usingEmbedded())
xid4a = new cdsXid(4, (byte) 93, (byte) 103);
else if (usingDerbyNetClient())
xid4a = new cdsXid(5, (byte) 93, (byte) 103);
try {
xac4.getXAResource().start(xid4a, XAResource.TMNOFLAGS);
} catch (XAException xae) {
if (usingEmbedded())
assertNull(xae.getMessage());
else if (usingDerbyNetClient())
{
// This should give XAER_OUTSIDE exception because
// the resource manager is busy in the local transaction
assertTrue(xae.getMessage().indexOf("XAER_OUTSIDE") >=0 );
}
assertEquals(-9, xae.errorCode);
}
rs4.next();
assertEquals(3, rs4.getInt(1));
rs4.close();
conn4.rollback();
conn4.close();
xac4.close();
}