本文整理汇总了Java中org.h2.jdbcx.JdbcDataSource.getXAConnection方法的典型用法代码示例。如果您正苦于以下问题:Java JdbcDataSource.getXAConnection方法的具体用法?Java JdbcDataSource.getXAConnection怎么用?Java JdbcDataSource.getXAConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.h2.jdbcx.JdbcDataSource
的用法示例。
在下文中一共展示了JdbcDataSource.getXAConnection方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMixedXaNormal
import org.h2.jdbcx.JdbcDataSource; //导入方法依赖的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();
}
示例2: testXAAutoCommit
import org.h2.jdbcx.JdbcDataSource; //导入方法依赖的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();
}
示例3: testRollbackWithoutPrepare
import org.h2.jdbcx.JdbcDataSource; //导入方法依赖的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");
}
示例4: testTwoPhase
import org.h2.jdbcx.JdbcDataSource; //导入方法依赖的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();
}
示例5: testSimple
import org.h2.jdbcx.JdbcDataSource; //导入方法依赖的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");
}
示例6: simpleResource
import org.h2.jdbcx.JdbcDataSource; //导入方法依赖的package包/类
@Test
public void simpleResource() throws SQLException, XAException {
final JdbcDataSource ds = new JdbcDataSource();
ds.setURL(DatabaseUtil.URL_H2);
ds.setUser(DatabaseUtil.USER);
ds.setPassword(DatabaseUtil.PASSWORD);
final XAConnection xaConnection = ds.getXAConnection();
Connection connection = null;
try {
connection = xaConnection.getConnection();
DatabaseUtil.createDatabase(connection);
final Statement statement = connection.createStatement();
final Xid xid = new SimpleXid(100, new byte[] { 0x01 }, new byte[] { 0x02 });
final XAResource xaResource = xaConnection.getXAResource();
xaResource.start(xid, XAResource.TMNOFLAGS);
statement.execute(
"INSERT INTO PERSONNE (PRENOM, NOM, DATE_NAISSANCE) VALUES ('RollBack1', 'SQL', '1970-01-01');");
statement.execute(
"INSERT INTO PERSONNE (PRENOM, NOM, DATE_NAISSANCE) VALUES ('RollBack2', 'SQL', '1970-01-01');");
statement.execute(
"INSERT INTO PERSONNE (PRENOM, NOM, DATE_NAISSANCE) VALUES ('RollBack3', 'SQL', '1970-01-01');");
statement.execute(
"INSERT INTO PERSONNE (PRENOM, NOM, DATE_NAISSANCE) VALUES ('RollBack4', 'SQL', '1970-01-01');");
xaResource.end(xid, XAResource.TMSUCCESS);
final int prepare = xaResource.prepare(xid);
if (prepare == XAResource.XA_OK) {
xaResource.commit(xid, false);
}
} finally {
if (connection != null) {
connection.close();
}
}
}