ILock.Unlock

Fore Syntax

Unlock;

Fore.NET Syntax

Unlock();

Description

The Unlock method disables locking.

Comments

Locking is enabled automatically on getting an object of the ILock type. To disable locking, call the Unlock method and reset the corresponding variable to zero.

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;
    MDesc, CacheDesc: IMetabaseObjectDescriptor;
    Cache: ICubeCacheSaver;
    CubeInst: ICubeInstance;
    Dest: ICubeInstanceDestination;
    Sels: IDimSelectionSet;
    Sel: IDimSelection;
    Matr: IMatrix;
    Lock: ILock;
Begin
    MB := MetabaseClass.Active;
    MDesc := MB.ItemById("STD_CUBE");
    CacheDesc := GetCache(MDesc);
    If CacheDesc <> Null Then
        Cache := CacheDesc.Edit As ICubeCacheSaver;
        CubeInst := MDesc.Open(NullAs ICubeInstance;
        Dest := CubeInst.Destinations.DefaultDestination;
        Sels := Dest.CreateDimSelectionSet;
        For Each Sel In Sels Do
            Sel.SelectAll;
        End For;
        //Get cached matrix with data
        Matr := Cache.GetGlobalCache(Dest.Key, Null, Sels);
        If Matr <> Null Then
            Lock := Cache.GetGlobalWriteLock(Dest.Key, Null, Sels);
            //...
            //Further work with data matrix
            //...
            //Save refreshed matrix to cache
            Cache.SaveCache(Dest.Key, Null, Sels, Matr);
            Lock.Unlock;
            Lock := Null;
        End If;
    End If;
End Sub UserProc;

Function GetCache(MObj: IMetabaseObjectDescriptor): IMetabaseObjectDescriptor;
Var
    Desc: IMetabaseObjectDescriptor;
Begin
    For Each Desc In MObj.Children Do
        If Desc.ClassId = MetabaseObjectClass.KE_CLASS_CUBE_CACHE_SAVER Then
            Return Desc;
        End If;
    End For;
    Return Null;
End Function GetCache;

On executing the example a matrix of cached data is obtained for specified parameters of the cube. Data is locked to be edited. After the cache data is refreshed, locking is disabled.

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;
    MDesc, CacheDesc: IMetabaseObjectDescriptor;
    Cache: ICubeCacheSaver;
    CubeInst: ICubeInstance;
    Dest: ICubeInstanceDestination;
    Sels: IDimSelectionSet;
    Sel: IDimSelection;
    Matr: IMatrix;
    Lock: ILock;
Begin
    MB := Params.Metabase;
    MDesc := MB.ItemById["STD_CUBE"];
    CacheDesc := GetCache(MDesc);
    If CacheDesc <> Null Then
        Cache := CacheDesc.Edit() As ICubeCacheSaver;
        CubeInst := MDesc.Open(NullAs ICubeInstance;
        Dest := CubeInst.Destinations.DefaultDestination;
        Sels := Dest.CreateDimSelectionSet();
        For Each Sel In Sels Do
            Sel.SelectAll();
        End For;
        //Get cached matrix with data
        Matr := Cache.GetGlobalCache(Dest.Key, Null, Sels);
        If Matr <> Null Then
            Lock := Cache.GetGlobalWriteLock(Dest.Key, Null, Sels);
            //...
            //Further work with data matrix
            //...
            //Save refreshed matrix to cache
            Cache.SaveCache(Dest.Key, Null, Sels, Matr);
            Lock.Unlock();
            Lock := Null;
        End If;
    End If;
End Sub;

Public Shared Function GetCache(MObj: IMetabaseObjectDescriptor): IMetabaseObjectDescriptor;
Var
    Desc: IMetabaseObjectDescriptor;
Begin
    For Each Desc In MObj.Children Do
        If Desc.ClassId = MetabaseObjectClass.KE_CLASS_CUBE_CACHE_SAVER As integer Then
            Return Desc;
        End If;
    End For;
    Return Null;
End Function;

See also:

ILock