GetGlobalWriteLock(
DestKey: Integer;
ParamValues: IMetabaseObjectParamValues;
Selections: IDimSelectionSet): ILock;
DestKey. The key of the required cube display version.
ParamValues. The set of parameter values, for which caching object is saved.
Selections. The collection of selections in the specified cube display version.
The GetGlobalWriteLock method returns the object that manages write and read locking of cached data for the specified cube.
Locking is required to exclude the case when several users need to change the same data and open the report for view at the same time. It is probable if working with cube cache is executed in the code, which is executed via web services of the BI server of Foresight Analytics Platform.
Executing the example requires that the repository contains a cube with the STD_CUBE identifier. Data caching is available for the cube.
Add links to the Cubes, Dimensions, Matrix, Metabase, and System system assemblies.
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(Null) As 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 working with data matrix
//...
//Save updated 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;
After executing the example the cached data matrix is obtained for the specified cube parameters. Data is locked for modification. After data is updated in cache, the data is unlocked.
See also: