Executing the example requires an MDM repository with the REP_NSI identifier. This repository already contains the MDM dictionary with the DICT_RDS identifier.
There are the RDS_IMP and RDS_EXP tables in the database set for the MDM repository. These tables contain the following set of fields:
Field identifier | Field data type | Field name |
EL_KEY | Integer | Element key. |
EL_NAME | String | Element name. |
EL_ORD | Integer | Element order. |
EL_PARENT_KEY | Integer | Parent element key. |
USER_DATA | Date | Value of a custom attribute. |
LINK | Integer | Value of linked attribute that corresponds to the key of element in linked dictionary. |
PARAM | Date | Value of a parameter that ensures availability of this element. |
Table data should be connected to the import and export schemes, respectively.
Sub UserProc;
Var
MB: IMetabase;
NSI: IMetabaseObjectDescriptor;
CrInfo: IMetabaseObjectCreateInfo;
Dict, Dict1: IRdsDictionary;
Attrs: IRdsAttributes;
Attr, ParamAttr, LinkAttr, LookupAttr: IRdsAttribute;
Param: IRdsParam;
Link: IRdsLink;
UniqKey: IRdsUniqueKey;
Level: IRdsLevel;
Import: IRdsImportSchemas;
SchemaImport: IRdsImportSchema;
Export: IRdsExportSchemas;
SchemaExport: IRdsExportSchema;
Begin
MB := MetabaseClass.Active;
NSI := MB.ItemById("REP_NSI");
CrInfo := MB.CreateCreateInfo;
CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_RDS_DICTIONARY;
CrInfo.Id := "NewDictionary";
CrInfo.Name := "New dictionary";
CrInfo.Parent := NSI;
Dict := MB.CreateObject(CrInfo).Edit As IRdsDictionary;
Dict1 := MB.ItemByIdNamespace("DICT_RDS", NSI.Key).Bind As IRdsDictionary;
Attrs := Dict.Attributes;
//Creating additional attributes
//Custom attribute
Attr := Attrs.Add;
Attr.DataType := DbDataType.DateTime;
Attr.Id := "USERATTRIBUT";
Attr.Name := "Custom attribute";
//Attribute for link
LinkAttr := Attrs.Add;
LinkAttr.DataType := DbDataType.Integer;
LinkAttr.Id := "LINKATTR";
LinkAttr.Name := Attribute to link;
//Attribute for parameter
ParamAttr := Attrs.Add;
ParamAttr.DataType := DbDataType.DateTime;
ParamAttr.Id := "PARAMATTR";
ParamAttr.Name := "Parameter attribute";
//Creating parameter
Param := Dict.Params.Add;
Param.Attribute := ParamAttr;
Param.Id := "Param1";
Param.Name := "Value";
//Link with the dictionary
Link := Dict.Links.Add;
Link.Attribute := LinkAttr;
Link.Reference := Dict1.Attributes.Key;
Link.Id := "Link";
Link.Name := "Link with the Dict_1 dictionary";
//Imported attribute "Name" from the Dict_1 dictionary
LookupAttr := Attrs.Add;
LookupAttr.Id := "Dict1_Name";
LookupAttr.Name := "Name from Dict_1";
LookupAttr.Link := Link;
LookupAttr.Lookup := Dict1.Attributes.Name;
//Unique key
UniqKey := Dict.UniqueKeys.Add;
UniqKey.Id := "UniqKey_1";
UniqKey.Name := Unique key;
UniqKey.Contains(Attr) := True;
UniqKey.Contains(ParamAttr) := True;
//Dictionary levels
Level := Dict.Levels.Add;
Level.Id := "Newlevel1";
Level.Name := "The first level";
Level := Dict.Levels.Add;
Level.Id := "Newleve2";
Level.Name := "The second level";
//Creating import scheme
Import := Dict.ImportSchemas;
SchemaImport := Import.Add;
SchemaImport.Id := "NewSchemaImport";
SchemaImport.Name := Import scheme #1;
//Binding basic attributes to table fields
SchemaImport.Mappings(Attrs.Key).FieldName := "EL_KEY";
SchemaImport.Mappings(Attrs.Name).FieldName := "EL_NAME";
SchemaImport.Mappings(Attrs.Order).FieldName := "EL_ORD";
SchemaImport.Mappings(Attrs.ParentKey).FieldName := "EL_PARENT_KEY";
//Binding custom attributes to table fields
SchemaImport.Mappings(Attrs.FindById("USERATTRIBUT")).FieldName := "USER_DATA";
SchemaImport.Mappings(Attrs.FindById("LINKATTR")).FieldName := "LINK";
SchemaImport.Mappings(Attrs.FindById("PARAMATTR")).FieldName := "PARAM";
SchemaImport.TableName := "RDS_IMP";
SchemaImport.Incremental := True;
//Creating export scheme
Export := Dict.ExportSchemas;
SchemaExport := Export.Add;
SchemaExport.Id := "NewSchemaExport";
SchemaExport.Name := Export scheme #1;
//Binding basic attributes to table fields
SchemaExport.Mappings(Attrs.Key).FieldName := "EL_KEY";
SchemaExport.Mappings(Attrs.Name).FieldName := "EL_NAME";
SchemaExport.Mappings(Attrs.Order).FieldName := "EL_ORD";
SchemaExport.Mappings(Attrs.ParentKey).FieldName := "EL_PARENT_KEY";
//Binding custom attributes to table fields
SchemaExport.Mappings(Attrs.FindById("USERATTRIBUT")).FieldName := "USER_DATA";
SchemaExport.Mappings(Attrs.FindById("LINKATTR")).FieldName := "LINK";
SchemaExport.Mappings(Attrs.FindById("PARAMATTR")).FieldName := "PARAM";
SchemaExport.TableName := "RDS_EXP";
(Dict As IMetabaseObject).Save;
End Sub UserProc;
After executing the example a new MDM dictionary with the NewDictionary identifier is created in the MDM repository root. The following settings are determined in this dictionary:
Three custom attributes are created:
The USERATTRIBUT attribute. It is used to set date.
The LINKATTR attribute. It is used to create a link with the Dict_1 dictionary.
The PARAMATTR attribute. It is used to store parameter values.
The parameter of the Param1 dictionary is created. Date should be set as values of this parameter. Values of the parameter are stored by the PARAMATTR attribute.
The link with the Dict_1 dictionary is created. The LINKATTR attribute is used for link.
The imported attribute that refers to the Name attribute of the Dict_1 dictionary is created.
Unique key that includes the USERATTRIBUT custom attribute and attribute used to store values of the PARAMATTR parameter is created.
Two dictionary levels are created. They can be used further to set up aggregation.
An import scheme is created. Import is executed from the RDS_IMP table. Data is complemented during the import.
An export scheme is created. Export is executed to the RDS_EXP table.
The requirements and result of the Fore.NET Example execution match with those in the Fore Example.
Imports Prognoz.Platform.Interop.Dal;
Imports Prognoz.Platform.Interop.Rds;
…
Public Shared Sub Main(Params: StartParams);
Var
MB: IMetabase;
NSI: IMetabaseObjectDescriptor;
CrInfo: IMetabaseObjectCreateInfo;
Dict, Dict1: IRdsDictionary;
Attrs: IRdsAttributes;
Attr, ParamAttr, LinkAttr, LookupAttr: IRdsAttribute;
Param: IRdsParam;
Link: IRdsLink;
UniqKey: IRdsUniqueKey;
Level: IRdsLevel;
Import: IRdsImportSchemas;
SchemaImport: IRdsImportSchema;
Export: IRdsExportSchemas;
SchemaExport: IRdsExportSchema;
Begin
MB := Params.Metabase;
NSI := MB.ItemById["REP_NSI"];
CrInfo := MB.CreateCreateInfo();
CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_RDS_DICTIONARY As integer;
CrInfo.Id := "NewDictionary";
CrInfo.Name := "New dictionary";
CrInfo.Parent := NSI;
Dict := MB.CreateObject(CrInfo).Edit() As IRdsDictionary;
Dict1 := MB.ItemByIdNamespace["DICT_RDS", NSI.Key].Bind() As IRdsDictionary;
Attrs := Dict.Attributes;
//Creating additional attributes
//Custom attribute
Attr := Attrs.Add();
Attr.DataType := DbDataType.ddtDateTime;
Attr.Id := "USERATTRIBUT";
Attr.Name := "Custom attribute";
//Attribute for link
LinkAttr := Attrs.Add();
LinkAttr.DataType := DbDataType.ddtInteger;
LinkAttr.Id := "LINKATTR";
LinkAttr.Name := Attribute to link;
//Attribute for parameter
ParamAttr := Attrs.Add();
ParamAttr.DataType := DbDataType.ddtDateTime;
ParamAttr.Id := "PARAMATTR";
ParamAttr.Name := "Parameter attribute";
//Creating parameter
Param := Dict.Params.Add();
Param.Attribute := ParamAttr;
Param.Id := "Param1";
Param.Name := "Value";
//Link with the dictionary
Link := Dict.Links.Add();
Link.Attribute := LinkAttr;
Link.Reference := Dict1.Attributes.Key;
Link.Id := "Link";
Link.Name := "Link with the Dict_1 dictionary";
//Imported attribute "Name" from the Dict_1 dictionary
LookupAttr := Attrs.Add();
LookupAttr.Id := "Dict1_Name";
LookupAttr.Name := "Name from Dict_1";
LookupAttr.Link := Link;
LookupAttr.Lookup := Dict1.Attributes.Name;
//Unique key
UniqKey := Dict.UniqueKeys.Add();
UniqKey.Id := "UniqKey_1";
UniqKey.Name := Unique key;
UniqKey.Contains[Attr] := True;
UniqKey.Contains[ParamAttr] := True;
//Dictionary levels
Level := Dict.Levels.Add();
Level.Id := "Newlevel1";
Level.Name := "The first level";
Level := Dict.Levels.Add();
Level.Id := "Newleve2";
Level.Name := "The second level";
//Creating import scheme
Import := Dict.ImportSchemas;
SchemaImport := Import.Add();
SchemaImport.Id := "NewSchemaImport";
SchemaImport.Name := Import scheme #1;
//Binding basic attributes to table fields
SchemaImport.Mappings[Attrs.Key].FieldName := "EL_KEY";
SchemaImport.Mappings[Attrs.Name].FieldName := "EL_NAME";
SchemaImport.Mappings[Attrs.Order].FieldName := "EL_ORD";
SchemaImport.Mappings[Attrs.ParentKey].FieldName := "EL_PARENT_KEY";
//Binding custom attributes to table fields
SchemaImport.Mappings[Attrs.FindById("USERATTRIBUT")].FieldName := "USER_DATA";
SchemaImport.Mappings[Attrs.FindById("LINKATTR")].FieldName := "LINK";
SchemaImport.Mappings[Attrs.FindById("PARAMATTR")].FieldName := "PARAM";
SchemaImport.TableName := "RDS_IMP";
SchemaImport.Incremental := True;
//Creating export scheme
Export := Dict.ExportSchemas;
SchemaExport := Export.Add();
SchemaExport.Id := "NewSchemaExport";
SchemaExport.Name := Export scheme #1;
//Binding basic attributes to table fields
SchemaExport.Mappings[Attrs.Key].FieldName := "EL_KEY";
SchemaExport.Mappings[Attrs.Name].FieldName := "EL_NAME";
SchemaExport.Mappings[Attrs.Order].FieldName := "EL_ORD";
SchemaExport.Mappings[Attrs.ParentKey].FieldName := "EL_PARENT_KEY";
//Binding custom attributes to table fields
SchemaExport.Mappings[Attrs.FindById("USERATTRIBUT")].FieldName := "USER_DATA";
SchemaExport.Mappings[Attrs.FindById("LINKATTR")].FieldName := "LINK";
SchemaExport.Mappings[Attrs.FindById("PARAMATTR")].FieldName := "PARAM";
SchemaExport.TableName := "RDS_EXP";
(Dict As IMetabaseObject).Save();
End Sub;
See also: