01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (license2)
04: * Initial Developer: H2 Group
05: */
06: package org.h2.test.jdbcx;
07:
08: import java.sql.Connection;
09:
10: import javax.sql.XAConnection;
11:
12: import org.h2.jdbcx.JdbcDataSource;
13: import org.h2.test.TestBase;
14:
15: /**
16: * A simple XA test.
17: */
18: public class TestXASimple extends TestBase {
19:
20: public void test() throws Exception {
21:
22: deleteDb("xaSimple1");
23: deleteDb("xaSimple2");
24: Class.forName("org.h2.Driver");
25:
26: // InitialContext context = new InitialContext();
27: // context.rebind(USER_TRANSACTION_JNDI_NAME, j.getUserTransaction());
28:
29: JdbcDataSource ds1 = new JdbcDataSource();
30: ds1.setPassword("");
31: ds1.setUser("sa");
32: ds1.setURL("jdbc:h2:" + baseDir + "/xaSimple1");
33:
34: JdbcDataSource ds2 = new JdbcDataSource();
35: ds2.setPassword("");
36: ds2.setUser("sa");
37: ds2.setURL("jdbc:h2:" + baseDir + "/xaSimple2");
38:
39: // UserTransaction ut = (UserTransaction)
40: // context.lookup("UserTransaction");
41: // ut.begin();
42:
43: XAConnection xa1 = ds1.getXAConnection();
44: Connection c1 = xa1.getConnection();
45: c1.setAutoCommit(false);
46: XAConnection xa2 = ds2.getXAConnection();
47: Connection c2 = xa2.getConnection();
48: c2.setAutoCommit(false);
49:
50: c1.createStatement().executeUpdate(
51: "create table test(id int, test varchar(255))");
52: c2.createStatement().executeUpdate(
53: "create table test(id int, test varchar(255))");
54:
55: // ut.rollback();
56: c1.close();
57: c2.close();
58:
59: xa1.close();
60: xa2.close();
61:
62: // j.stop();
63: // System.exit(0);
64: deleteDb("xaSimple1");
65: deleteDb("xaSimple2");
66:
67: }
68: }
|