Datasets: IStandardCubeDatasets;
The Datasets property returns the collection of data sources for cube display version.
A data source can be tables, external tables, views, queries, ODBC data sources, table MDM dictionaries and table composite MDM dictionaries.
Executing the example requires that the repository contains a table with the T_DATA identifier, the table contains fields with the ID, DATE and VALUE identifiers. The following dictionaries should also be created in the repository:
FACTS. The fact dictionary structure should have an attribute with the KEY identifier.
INDICATORS. Indicators dictionary.
CALENDAR. Calendar dictionary, which structure includes the Years level.
Add links to the Cubes, Db, Dimensions system assemblies. Metabase.
Sub UserProc;
Var
Mb: IMetabase;
CrInfo: IMetabaseObjectCreateInfo;
MObj: IMetabaseObject;
Cube: IStandardCube;
CubeDest: IStandardCubeDestination;
Dims: IStandardCubeDimensions;
Datasets: IStandardCubeDatasets;
Dataset: IStandardCubeDataset;
FactDim, Dim, CalendarDim: IStandardCubeDimension;
FactDimInst: IDimInstance;
KeyAttribute: IDimAttributeInstance;
FactBindings: IStandardCubeFactBindings;
DimBinding: IStandardCubeDimensionBinding;
DimIndex: IDimIndex;
DataSet_ID: String = "T_DATA";
Begin
Mb := MetabaseClass.Active;
//Information for creating a new repository object
CrInfo := MB.CreateCreateInfo;
CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_STDCUBE;
CrInfo.Id := "NEW_STD_CUBE";
CrInfo.Name := "New standard cube";
CrInfo.Parent := Mb.Root;
//Create a cube
MObj := Mb.CreateObject(CrInfo).Edit;
Cube := MObj As IStandardCube;
CubeDest := Cube.Destinations.Item(0);
Dims := CubeDest.Dimensions;
Datasets := CubeDest.Datasets;
//Set existing repository dictionary as fact dimension
FactDim := Dims.Add(MB.ItemById("FACTS").Bind As IDimensionModel);
Cube.ExternalFactDimension := True;
FactDim.FactDimension := True;
//Add data source
Dataset := Datasets.Add(MB.ItemById(DataSet_ID).Bind As IDatasetModel);
//Cube fact binding
FactDimInst := FactDim.OpenDimension;
KeyAttribute := FactDimInst.Attributes.FindById("KEY");
FactBindings := FactDim.FactBindings(Dataset);
FactBindings.Binding(KeyAttribute.Value(0)).Formula.AsString := DataSet_ID + ".VALUE";
//Add dimension
Dim := Dims.Add(MB.ItemById("INDICATORS").Bind As IDimensionModel);
CalendarDim := Dims.Add(MB.ItemById("CALENDAR").Bind As IDimensionModel);
//Dimension binding
//"Dictionary"
DimIndex := Dim.Dimension.Indexes.PrimaryIndex;
DimBinding := Dim.Binding(Dataset);
DimBinding.Index := DimIndex;
DimBinding.Binding(DimIndex.Attributes.Item(0)).AsString := DataSet_ID + ".ID";
//"Calendar"
DimIndex := CalendarDim.Dimension.Blocks.Item("YEARS").Indexes.FindById("INDEX_BLOCK");
DimBinding := CalendarDim.Binding(Dataset);
DimBinding.Index := DimIndex;
DimBinding.Binding(DimIndex.Attributes.Item(0)).AsString := DataSet_ID + ".DATE";
MObj.Save;
End Sub UserProc;
Imports Prognoz.Platform.Interop.Cubes;
Imports Prognoz.Platform.Interop.Db;
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.Metabase;
Public Shared Sub Main(Params: StartParams);
Var
Mb: IMetabase;
CrInfo: IMetabaseObjectCreateInfo;
MObj: IMetabaseObject;
Cube: IStandardCube;
CubeDest: IStandardCubeDestination;
Dims: IStandardCubeDimensions;
Datasets: IStandardCubeDatasets;
Dataset: IStandardCubeDataset;
FactDim, Dim, CalendarDim: IStandardCubeDimension;
FactDimInst: IDimInstance;
KeyAttribute: IDimAttributeInstance;
FactBindings: IStandardCubeFactBindings;
DimBinding: IStandardCubeDimensionBinding;
DimIndex: IDimIndex;
DataSet_ID: String = "T_DATA";
Begin
Mb := Params.Metabase;
//Information for creating a new repository object
CrInfo := Mb.CreateCreateInfo();
CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_STDCUBE As Integer;
CrInfo.Id := "NEW_STD_CUBE";
CrInfo.Name := "New standard cube";
CrInfo.Parent := Mb.Root;
//Create a cube
MObj := Mb.CreateObject(CrInfo).Edit();
Cube := MObj As IStandardCube;
CubeDest := Cube.Destinations.Item[0];
Dims := CubeDest.Dimensions;
Datasets := CubeDest.Datasets;
//Set existing repository dictionary as fact dimension
FactDim := Dims.Add(MB.ItemById["FACTS"].Bind() As IDimensionModel);
Cube.ExternalFactDimension := True;
FactDim.FactDimension := True;
//Add data source
Dataset := Datasets.Add(MB.ItemById[DataSet_ID].Bind() As IDatasetModel);
//Cube fact binding
FactDimInst := FactDim.OpenDimension;
KeyAttribute := FactDimInst.Attributes.FindById("KEY");
FactBindings := FactDim.FactBindings[Dataset];
FactBindings.Binding[KeyAttribute.Value[0]].Formula.AsString := DataSet_ID + ".VALUE";
//Add dimension
Dim := Dims.Add(MB.ItemById["INDICATORS"].Bind() As IDimensionModel);
CalendarDim := Dims.Add(MB.ItemById["CALENDAR"].Bind() As IDimensionModel);
//Dimension binding
//"Dictionary"
DimIndex := Dim.Dimension.Indexes.PrimaryIndex;
DimBinding := Dim.Binding[Dataset];
DimBinding.Index := DimIndex;
DimBinding.Binding[DimIndex.Attributes.Item[0]].AsString := DataSet_ID + ".ID";
//"Calendar"
DimIndex := CalendarDim.Dimension.Blocks.Item["YEARS"].Indexes.FindById("INDEX_BLOCK");
DimBinding := CalendarDim.Binding[Dataset];
DimBinding.Index := DimIndex;
DimBinding.Binding[DimIndex.Attributes.Item[0]].AsString := DataSet_ID + ".DATE";
MObj.Save();
End Sub;
Executing the example creates a new cube in the repository root directory. One data source is added to the cube, fact dimension is set, and two additional dimensions are added. Data source bindings are set up for the first fact in the fact dimension and for additional dimensions.
See also: