IRWMutex.LockWrite

Fore Syntax

LockWrite;

Fore.NET Syntax

LockWrite();

Description

The LockWrite method enables data write locking.

Comments

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

Fore 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.

Fore.NET Example

The requirements and result of the Fore.NET example execution match with those in the Fore example.

Imports Prognoz.Platform.Interop.Cubes;
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.ForeSystem;
Imports Prognoz.Platform.Interop.Matrix;
Imports Prognoz.Platform.Interop.Metabase;

Public Shared Sub Main(Params: StartParams);
Var
    MB: IMetabase;
    CubeInst: ICubeInstance;
    CubeDest: ICubeInstanceDestination;
    Executor: ICubeInstanceDestinationExecutor;
    Sels: IDimSelectionSet;
    Sel: IDimSelection;
    ResultMatrix: IMatrix;
    Iter: IMatrixIterator;
    IterMutex: IRWMutex;
Begin
    MB := Params.Metabase;
    //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.cideoCached As Integer);
    ResultMatrix := Executor.Matrix;
    Iter := ResultMatrix.CreateIterator();
    //If data is obtained from cache, iterator supports IRWMutex
    //and locking is required before executing operations
    If Iter Is IRWMutex Then
        IterMutex := Iter As IRWMutex;
        //Data read locking
        IterMutex.LockWrite();
    End If;
    Iter.Move(IteratorDirection.itdFirst);
    While Iter.Valid Do
        //...
        //Work with iterator to edit data
        //...
        Iter.Move(IteratorDirection.itdNext);
    End While;
    //Disable locking
    If IterMutex <> Null Then
        If IterMutex.HasWriteLock Then
            IterMutex.UnlockWrite();
        End If;
    End If;
End Sub;

See also:

IRWMutex