company logo

Property :: lockCollection - Lock collection

In order to prevent other applications accessing a collection managed by the property handle, this function allows locking the collection. As long as the collection is locked no other process or thread is able to lock the collection. Locking a collection does not protect the collection from being read or updated. In order to prevent the collection from being updated, one may call lockCollectionForUpdate().

Locking a collection twice in the same or another application will fail (returns false).

Locked collections can be unlocked by calling unlockCollection().

The function returns true, when locking succeeded and false, when the collection is already locked. The function must not be called from within context class event handlers, which will cause an exception. The function also throws an exception, when the property does not handle a collection or when no instance is selected in the parent property handle or property handle is invalid.

When closing the property handle completely, i.e. when closing the last property handle referring to the same cursor object (e.g. created by calling use()), the collection will be unlocked if not yet done by the application. Because cursor copies (created by calling cursorCopy()) will automatically be destroyed when destroying the owning cursor object by closing the last referring property handle, locks initiated by copy cursors are also released.

In order to avoid dead locks, locks performed within a transaction are also released automatically, when terminating the transaction. This is also true for locks made in context functions when updating/creating/deleting data.

Notes:

This feature is dangerous, since remaining locks (e.g. because improper exception handling may cause system dead locks. Hence, we suggest using locker classes (like CollectionLock) instaed, which are automatically destructed when leaving the function, which will unlock the locked resource.

Nevertheless, lock functions might be used, when lock and unlock are called in different functions, which cannot be avoided, sometimes.

Return value:  Success ( bool  )

The value is true when the function was executed successfully. Otherwise the value is set to false.

Implementation overview

Implementation details

  1. Lock collection immediately
    bool Property  :: lockCollection (  )

    The function locks the collection and returns the result immediately, i.e. false, when the collection has already been locked by another application and true when being locked successfully.

  2. to list
  3. Lock and wait
    bool Property  :: lockCollection ( int32 iTimeout )

    The function locks the collection and waits the number of seconds passed in iTimeout, when the collection is not available. The function returns true, as soon as the collection could be locked. When the waiting interval has passed without being able to lock the collection, the function returns false.

    • iTimeout - Timeout in seconds
  4. to list