Aborting a Transaction

When you abort a transaction, all database modifications performed under the protection of the transaction are discarded, and all locks currently held by the transaction are released. In this event, your data is simply left in the state that it was in before the transaction began performing data modifications.

Once you have aborted a transaction, the transaction handle that you used for the transaction is no longer valid. To perform database activities under the control of a new transaction, you must obtain a fresh transactional handle.

To abort a transaction, call XmlTransaction.abort().

Note that if you are using a retry block, then in your exception handling you should suspect any object used in an update operation. You should not trust the object because the operqtion can be destructive. For example, in the following code fragment you must init a new XmlDocument object in your retry block:

final int maxRetry = 50;

for (int retry = 0; ; retry++) {

    //Create String contents for documents.
    String xmlString = "<aDoc>green</aDoc>";

    // Start a transaction
    XmlTransaction txn = mgr.createTransaction();

    try {
        //Declare an xml document
        XmlDocument xmlDoc = mgr.createDocument();

        //Set the xml document's content
        xmlDoc.setContent(xmlString);

        // Asking DB XML to generate a name
        XmlDocumentConfig docConfig = new XmlDocumentConfig();
        docConfig.setGenerateName(true);

        // Put the document
        container.putDocument(txn, xmlDoc, docConfig);

        txn.commit();
        break;
    } catch (Exception e) {
        if ( txn != null )
            txn.abort();
        if (retry &gt;= maxRetry) {
            System.err.println("Message: " + e.getMessage() );
            throw e;
        }
    }
}