Q: My database does not support transactions. What commit mode do I use in DOMToDBMS?
Applies to: 1.x
Databases that do not support transactions (such as MySQL) commit statements as they are executed. In XML-DBMS terms, this is COMMIT_AFTERINSERT -- that is, commit each insert immediately after it is executed. Thus, you should use the commit mode COMMIT_AFTERINSERT. This is the default commit mode, so you do not need to set it explicitly. However, you can call DOMToDBMS.setCommitMode(COMMIT_AFTERINSERT) if you want.
Note that using this commit mode results in two transaction-related calls:
In storeDocument(), DOMToDBMS calls map.setAutoCommit(commitMode == COMMIT_AFTERINSERT), which calls Connection.setAutoCommit(true).
In insertRow(), DOMToDBMS calls map.commit(), which calls Connection.commit(). (This call is actually unnecessary: since auto-commit is true, the statement is committed when it is executed. I will remove it in a future release.)
A database that does not support transactions should support both of these calls, since they are the same as its current behavior. (The JDBC spec does not say what should be done here -- it requires databases to support transactions. However, I believe that ODBC, which is based on the same international standard, requires drivers to support both calls.)
If your database throws an exception:
Please post a message to the mailing list.
As a workaround, comment out the above two calls in DOMToDBMS.
Note that version 2.0 solves this problem by adding a COMMIT_NOTRANSACTIONS commit mode.
Back to the XML-DBMS FAQs