Add: IMetaIndex;
The Add method adds an index in the collection.
Executing the example requires an MDM repository with the RDS_REPO identifier. The MDM repository must contain dictionaries with the DICT_CTR and DICT_IND identifiers.
Sub Main;
Var
Mb: IMetabase;
Inf: IMetabaseObjectCreateInfo;
Obj: IMetabaseObjectDescriptor;
Cat: IRubricator;
RdsDescr: IMetabaseObjectDescriptor;
Rds: IRdsDatabase;
Facts: IMetaDictionary;
Attributes: IMetaAttributes;
Attribute: IMetaAttribute;
Indexes: IMetaIndexes;
Index: IMetaIndex;
AttrColl: IMetaAttributesCollection;
Begin
Mb := MetabaseClass.Active;
RdsDescr := Mb.ItemById("RDS_REPO");
// Define parameters for time series database
Inf := Mb.CreateCreateInfo;
Inf.Id := Mb.GenerateId("OBJ_FC");
Inf.Name := Inf.Id;
Inf.ClassId := MetabaseObjectClass.KE_CLASS_RUBRICATOR;
Inf.Parent := Mb.Root;
Inf.KeepEdit := True;
Obj := Mb.CreateObject(Inf);
Cat := (Obj As IRubricator);
Rds := RdsDescr.Bind As IRdsDatabase;
Cat.Database := Rds;
Cat.GetDictionary(RubricatorDictionary.AllDictionaries,
RubricatorDictionaryOperation.Create Or RubricatorDictionaryOperation.ForEachBasis);
// Create compulsory custom attribute COUNTRY
Facts := Cat.Facts;
Attributes := Facts.Attributes;
Attribute := Attributes.Add;
Attribute.Id := "COUNTRY";
Attribute.Name := "Country";
Attribute.Nullable := False;
Attribute.HasMultipleValues := False;
Attribute.DataType := DbDataType.Integer;
Attribute.ValuesObject := Mb.ItemByIdNamespace("DICT_CTR", RdsDescr.Key).Bind;
// Create compulsory custom attribute INDICATOR
Attribute := Attributes.Add;
Attribute.Id := "INDICATOR";
Attribute.Name := "Indicator";
Attribute.Nullable := False;
Attribute.HasMultipleValues := False;
Attribute.DataType := DbDataType.Integer;
Attribute.ValuesObject := Mb.ItemByIdNamespace("DICT_IND", RdsDescr.Key).Bind;
// Create index
Indexes := Facts.Indexes;
Index := Indexes.Add;
Index.Name := New index;
Index.Unique := True;
Attributes := Facts.Attributes;
AttrColl := Index.Attributes;
Attribute := Attributes.FindById("COUNTRY");
AttrColl.Add(Attribute);
Attribute := Attributes.FindById("INDICATOR");
AttrColl.Add(Attribute);
Attributes.CreateTable;
(Obj As IMetabaseObject).Save;
End Sub Main;
After executing the example, the OBJ_FC time series database is created in the repository. A unique index that consists of the mandatory custom attributes COUNTRY and INDICATOR is created to measure factors.
See also: