The c-treeDB .NET API implementation of transaction processing functions follows closely the c-tree ISAM API definition. The basic difference between the c-treeDB .NET and ISAM transaction processing API is the separation of locking mechanisms from transaction processing.
While the ISAM API also allows for locking modes to be specified when beginning a transaction, the c-treeDB .NET API requires that locking functions be implicitly used after a transaction begins. The code fragment below shows an example using a c-tree ISAM call to start a transaction with locking:
/* start transaction enabling write locks */
TRANBEG(TRNLOG | ENABLE | LK_BLOCK);
... perform some data operations ...
/* commit the transaction and release locks */
TRANEND(FREE);
The c-tree code fragment above starts a transaction by invoking function TRANBEG. The mode ENABLE indicates that every c-tree read record operation will lock the record for writing and the mode LK_BLOCK indicates that the thread will block until the lock is acquired.
When using the c-treeDB .NET API, developers must be aware that the transaction processing API will not start the record locking mechanism. The code fragment below shows the equivalent example using the c-treeDB .NET API:
// Recobj is a CTRecord object
// start a transaction
Recobj.Begin();
// enable write locks
Recobj.Lock(LOCK_MODE.WRITE_BLOCK_LOCK);
... perform some data operations ...
// release locks
Recobj.Unlock();
// commit the transaction
Recobj.Commit();
The Begin() method starts a new transaction, while Commit() terminates a transaction by committing any changes. Abort() terminates a transaction and aborts any changes done during the transaction.
SetSavePoint() sets a save point in the current transaction. Once a save point is set within the current transaction, RestoreSavePoint() will reverse only changes done in between the set save point and restore the save point, without terminating the transaction.
Please refer to the chapter entitled "Data Integrity" in the c-tree Plus Programmer's Reference Guide for a detailed description of transaction processing and locking.