All eXtremeDB database access is performed within transactions to assure database integrity by enforcing the
ACID
principles (see the eXtremeDB User Guide for a detailed description of transaction processing). When using the eXtremeSQL API, transaction processing isimplicit
, i.e. transactions are started and committed by the runtime without requiring explicit function calls. Specifically, the SqlLocalConnection or SqlRemoteConnection methodexecuteStatement()
starts and closes aREAD_ONLY
transaction when performing an SQLSELECT
(unless theFOR UPDATE
clause is specified), and aREAD_WRITE
transaction when performingINSERT
,UPDATE
orDELETE
statements. Similarly, theexecuteQuery
() method starts and closes aREAD_ONLY
transaction and returns a result setSqlResultSet
.These
implicit
transactions are managed by an internal SqlLocalConnection or SqlRemoteConnection object and for most database operations the application developer need not be concerned with the transaction interface. However, some applications need to perform updates that require transaction blocking that spans more than one eXtremeSQL function call.To take control of transaction processing with eXtremeSQL the application uses the SqlLocalConnection or SqlRemoteConnection methods
startTransaction()
andcommitTransaction()
orrollbackTransaction()
. (Note also that you can use thecheckpointTransaction()
method to update indexes and make objects visible to queries while the transaction is still open.) This is illustrated in the following code snippet:
SqlLocalConnection con = db.connectSql(); con.startTransaction(Database.TransactionType.ReadWrite); con.executeStatement("insert into MyTable (pk,value) values (?,?)", 2012, "Good bye"); con.executeStatement("insert into MyTable (pk,value) values (?,?)", 2013, "Hello"); con.commitTransaction();
Checkpoint and Autocheckpoint
As explained in the eXtremeSQL Transaction Control page, a checkpoint operation may be necessary in complex transactions to update indexes prior to the transaction commit. The Java API to cause a checkpoint can be called as follows:
SqlLocalConnection con = db.connectSql(); con.startTransaction(Database.TransactionType.ReadWrite); con.executeStatement("insert into MyTable (pk,value) values (?,?)", 2012, "Good bye"); con.checkpointTransaction(); SqlResultSet result = conn.executeQuery("SELECT * FROM MyTable WHERE pk=?", 2012); con.commitTransaction();Or the following SQL statement can be used to cause a checkpoint:
con.executeStatement("CHECKPOINT TRANSACTION");To enable the autocheckpoint feature, set the
DB_SQL_AUTOCHECKPOINT
flag in database parametersMode
. For example:Database.Parameters parameters = new Database.Parameters(); parameters.mode = Database.DB_SQL_AUTOCHECKPOINT; ...