LockRead;
LockRead();
The LockRead method enables data read locking.
After the data read is complete, execute the UnlockRead method to disable locking.
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(Null) As 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.LockRead;
End If;
Iter.Move(IteratorDirection.First);
While Iter.Valid Do
//...
//Work with iterator to read data
//...
Iter.Move(IteratorDirection.Next);
End While;
//Disable locking
If IterMutex <> Null Then
If IterMutex.HasReadLock Then
IterMutex.UnlockRead;
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, cache read is locked.
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 Main1(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(Null) As 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.LockRead();
End If;
Iter.Move(IteratorDirection.itdFirst);
While Iter.Valid Do
//...
//Work with iterator to read data
//...
Iter.Move(IteratorDirection.itdNext);
End While;
//Disable locking
If IterMutex <> Null Then
If IterMutex.HasReadLock Then
IterMutex.UnlockRead();
End If;
End If;
End Sub;
See also: