IRWMutex.LockWrite

Syntax

LockWrite;

Description

The LockWrite method enables data write locking.

Comments

After data editing is complete, execute the UnlockWrite method to disable locking.

Example

Executing the example requires that the repository contains a cube with the STD_CUBE identifier. Cube data can be cached.

Sub UserProc;
Var
    MB: IMetabase;
    CubeInst: ICubeInstance;
    CubeDest: ICubeInstanceDestination;
    Executor: ICubeInstanceDestinationExecutor;
    Sels: IDimSelectionSet;
    Sel: IDimSelection;
    ResultMatrix: IMatrix;
    Iter: IMatrixIterator;
    IterMutex: IRWMutex;
Begin
    MB := MetabaseClass.Active;
    //Open cube
    CubeInst := MB.ItemById("STD_CUBE").Open(NullAs ICubeInstance;
    CubeDest := CubeInst.Destinations.DefaultDestination;
    Executor := CubeDest.CreateExecutor;
    //Selection, according to which data matrix is created
    Sels := CubeDest.CreateDimSelectionSet;
    For Each Sel In Sels Do
        Sel.SelectAll;
    End For;
    Executor.PrepareExecute(Sels);
    //Get matrix from cache
    Executor.PerformExecuteO(CubeInstanceDestinationExecutorOptions.Cached);
    ResultMatrix := Executor.Matrix;
    Iter := ResultMatrix.CreateIterator;
    //If data is obtained from cache, iterator supports IRWMutex
    //and locking is required before executing actions
    If Iter Is IRWMutex Then
        IterMutex := Iter As IRWMutex;
        //Data read locking
        IterMutex.LockWrite;
    End If;
    Iter.Move(IteratorDirection.First);
    While Iter.Valid Do
        //...
        //Work with iterator to edit data
        //...
        Iter.Move(IteratorDirection.Next);
    End While;
    //Disable locking
    If IterMutex <> Null Then
        If IterMutex.HasWriteLock Then
            IterMutex.UnlockWrite;
        End If;
    End If;
End Sub UserProc;

After executing the example the data matrix is obtained from the cube cache. To work with the matrix and edit its data, cache write is locked.

See also:

IRWMutex