Here is a distributed commit of 2 phase protocol:

public static void main( String[] args ) throws SQLException, XAException { OracleXADataSource dataSource1 = new OracleXADataSource(); dataSource1.setURL("jdbc:oracle:thin:@//localhost:1521/XE"); dataSource1.setUser("system"); dataSource1.setPassword("111"); OracleXADataSource dataSource2 = new OracleXADataSource(); dataSource2.setURL("jdbc:oracle:thin:@//localhost:1521/XE"); dataSource2.setUser("alex"); dataSource2.setPassword("111"); XAConnection xaConnection = dataSource1.getXAConnection(); XAResource res = xaConnection.getXAResource(); Connection connection = xaConnection.getConnection(); FooXid xid1 = new FooXid(1); res.start(xid1, XAResource.TMNOFLAGS); connection.createStatement().execute("INSERT INTO TABLE1 VALUES (1)"); res.end(xid1, XAResource.TMSUCCESS); XAConnection xaConnection2 = dataSource2.getXAConnection(); XAResource res2 = xaConnection2.getXAResource(); Connection connection2 = xaConnection2.getConnection(); FooXid xid2 = new FooXid(2); res2.start(xid2, XAResource.TMNOFLAGS); connection2.createStatement().execute("INSERT INTO TABLE1 VALUES (2)"); res2.end(xid2, XAResource.TMSUCCESS); int verdict = res.prepare(xid1); int verdict2 = res2.prepare(xid2); if (verdict == XAResource.XA_OK) res.commit(xid1, false);//breakpoint1 if (verdict2 == XAResource.XA_OK) res2.commit(xid2, false);//breakpoint2 xaConnection.close(); xaConnection2.close(); connection.close(); connection2.close(); } 

When I reach the debager at // breakpoint1 or // breakpoint2 and try to select the SELECT values ​​from the table, the query passes. But the table must be locked according to the documentation!

  • I did not work with, but the normal engine never blocks the table. he blocks the records. besides, a lot depends on the isolation level, if it is not serializable. - etki
  • @Etki and how orakl without blocking of the table can be sure that data (dirty) will not be read during the distributed commit? Ie we read the old data in 1 table, when new data is recorded in 2nd - voipp
  • one
    And at you it is forbidden by the current isolation level? - etki
  • And why do you even need to lock the tables. In oracle, usually everything is done without locks. There is of course a separate "lock table" statement ... - Mike
  • @Mike everything, understood. orakl by default blocks the table on its change - voipp

0