Product Documentation

c-treeDB API for C# - Developers Guide

Previous Topic

Next Topic

Session-Wide Locking

Session-wide locking is based on the principle that the Lock method sets the current lock mode. When locks are activated, every record read from all active tables of all active databases associated with the session are automatically locked with the current lock mode.

// start locking

// ASession is a CTSession object

try

{

ASession.Lock(LOCK_MODE.WRITE_BLOCK_LOCK);

}

catch (CTException err)

{

Console.Write("Session lock failed with error {0}\n", err.GetErrorCode());

}

Unlock() releases all locks acquired since the last Lock() call and clears the current lock mode. IsLockActive() indicates if a session-wide lock mode is set. GetLockMode() retrieves the current session-wide lock mode. If no session-wide locks are active, GetLockMode() returns CTLOCK_FREE.

// unlock if locks are active

// ARecord is a CTRecord object

try

{

if (ARecord.GetLockMode() != LOCK_MODE.FREE_LOCK)

{

ARecord.Unlock();

}

}

catch (CTException err)

{

Console.Write ("Unlock failed with code {0}\n", err.GetErrorCode());

}

Refer to the chapter titled "Data Integrity" in the c-tree Plus Programmer's Reference Guide for a detailed description of transaction processing and locking.

TOCIndex