What I am trying to do is to prevent lost update from happening.
In first java script I put a xquery update inside a “serializable” transaction, like following:
TConnectionFactory connectionFactory = TConnectionFactory.getInstance();
connection = connectionFactory.newConnection( DATABASE_URI );
TLocalTransaction transaction = connection.useLocalTransactionMode();
accessor = connection.newXMLObjectAccessor(TAccessLocation.newInstance(collection ) ,
String query_string = “update replace input()/note[@id=“20”]/a with eric”;
TXQuery xquery = TXQuery.newInstance(query_string);
TResponse response = accessor.xquery( xquery );
Then in the second java script, I have the exact same code.
When I run the first code, since it has Thread.sleep(10000), it will hang a little time, then I run the second script, to my supprise, both code will finish successfully, which is a lost update.
However, if in the second java code, I don’t put the xquery in a transaction, it actually will fail since it says that it cann’t get a lock on the document.