SaveMatrixT(Matrix: IMatrix; Manager: ICubeTransactionManager; ValueFlag: Integer);
SaveMatrixT(Matrix: Prognoz.Platform.Interop.Matrix.IMatrix; Manager: Prognoz.Platform.Interop.Cubes.ICubeTransactionManager; ValueFlag: Integer);
Matrix. Matrix containing values that must be saved back to cube.
Manager. Transaction manager instance that will trace cube operations.
ValueFlag. Flag of elements containing changed data. Only the matrix elements are saved to cube, which flag corresponds to this value.
The SaveMatrixT method saves data matrix to cube using the transaction manager.
Executing the example requires that the repository contains a cube with the STD_CUBE identifier.
Add links to the Cubes, Dimensions, Matrix, Metabase system assemblies.
Sub UserProc;
Var
Mb: IMetabase;
CubInst: ICubeInstance;
Des: ICubeInstanceDestination;
Sels: IDimSelectionSet;
Sel: IDimSelection;
Matr: IMatrix;
Coord: IMatrixCoord;
Sto: ICubeInstanceStorage;
TransMan: ICubeTransactionManager;
i: Integer;
Begin
Mb := MetabaseClass.Active;
//Cube, in which data is changed
CubInst := MB.ItemById("STD_CUBE").Open(Null) As ICubeInstance;
Des := CubInst.Destinations.DefaultDestination;
Sels := Des.CreateDimSelectionSet;
For Each Sel In Sels Do
Sel.SelectElement(0, False);
End For;
//Get values matrix by specified selection
Matr := Des.Execute(Sels);
Matr.ValueFlag := Matr.ValueFlag + 1;
//Create a coordinate in matrix
Coord := Matr.CreateCoord;
For i := 0 To Matr.DimensionCount - 1 Do
Coord.Item(i) := 0;
End For;
//Change value by coordinate
Matr.Item(Coord) := (Matr.Item(Coord) As Double) + 1;
Sto := Des.CreateStorage(CubeInstanceStorageOptions.None);
//Save value using transaction manager
TransMan := New CubeTransactionManager.Create;
Try
Sto.SaveMatrixT(Matr, TransMan, Matr.ValueFlag);
TransMan.Commit;
Except
//Roll back transaction (undo changes)
TransMan.Rollback;
End Try;
End Sub UserProc;
Imports Prognoz.Platform.Interop.Cubes;
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.Matrix;
Imports Prognoz.Platform.Interop.Metabase;
Public Shared Sub Main(Params: StartParams);
Var
Mb: IMetabase;
CubInst: ICubeInstance;
Des: ICubeInstanceDestination;
Sels: IDimSelectionSet;
Sel: IDimSelection;
Matr: IMatrix;
Coord: IMatrixCoord;
Sto: ICubeInstanceStorage;
TransMan: CubeTransactionManager;
i: Integer;
Begin
Mb := Params.Metabase;
//Cube, in which data is changed
CubInst := MB.ItemById["STD_CUBE"].Open(Null) As ICubeInstance;
Des := CubInst.Destinations.DefaultDestination;
Sels := Des.CreateDimSelectionSet();
For Each Sel In Sels Do
Sel.SelectElement(0, False);
End For;
//Get values matrix by specified selection
Matr := Des.Execute(Sels, UInteger.MaxValue);
Matr.ValueFlag := Matr.ValueFlag + 1;
//Create a coordinate in matrix
Coord := Matr.CreateCoord();
For i := 0 To Matr.DimensionCount - 1 Do
Coord.Item[i] := 0;
End For;
//Change value by coordinate
Matr.Item[Coord] := (Matr.Item[Coord] As Double) + 1;
Sto := Des.CreateStorage(CubeInstanceStorageOptions.cisoNone);
//Save value using transaction manager
TransMan := New CubeTransactionManager();
Try
Sto.SaveMatrixT(Matr, TransMan, Matr.ValueFlag);
TransMan.Commit();
Except
//Roll back transaction (undo changes)
TransMan.Rollback();
End Try;
End Sub;
After executing the example a matrix with cube data is obtained. The value is changed by some coordinate, following which the updated matrix is saved back to the cube. Saving is executed using the transaction manager that saves all changes and finishes transaction if data is saved successfully. If some errors occur, the transaction manager cancels all changes.
See also: