RegisterHierarchyChange(oldObjKey: Integer;
oldHieKey: Integer;
oldHieId: String;
newHieKey: Integer;
newHieId: String;
newObject: IMetabaseObject);
RegisterHierarchyChange(oldObjKey: uinteger;
oldHieKey: uinteger;
oldHieId: string;
newHieKey: uinteger;
newHieId: string;
newObject: Prognoz.Platform.Interop.Metabase.IMetabaseObject);
oldObjKey. Source dictionary key.
oldHieKey. Alternative hierarchy key in source dictionary.
oldHieId. Alternative hierarchy identifier in source dictionary.
newHieKey. Alternative hierarchy key in the consumer dictionary.
newHieId. Alternative hierarchy identifier in the consumer dictionary.
newObject. Consumer dictionary.
The RegisterHierarchyChange method redetermines alternative hierarchy, to which refers updated object.
To redetermine alternative hierarchy taking into account updated object owner, use the IMetabaseUpdateContext.RegisterHierarchyChangeO method.
Executing the example requires that the repository contains table MDM dictionaries with the DM_INDICATOR_S and MDM_INDICATOR_D identifiers. These dictionaries must contain identical alternative hierarchies. The file system assumes the C:\RegHieChng.pefx update file used to update the MDM_INDICATOR_S dictionary.
Add links to the Dimensions, Metabase system assemblies.
Sub UserProc;
Var
MB: IMetabase;
Update: IMetabaseUpdate;
Context: IMetabaseUpdateContext;
sourceDim, targetDim: IMetabaseObject;
sourceHieSrc, targetHieSrc: IMetabaseObject;
sourceHierarchies, targetHierarchies: IDimHierarchies;
sourceHierarchy, targetHierarchy: IDimHierarchy;
i: Integer;
KeyMap: IMetabaseUpdateKeyMap;
UpdObjRemap: IMetabaseUpdateObjectRemapping;
Begin
// Get current repository
MB := MetabaseClass.Active;
// Create an update
Update := Mb.CreateUpdate;
// Load update parameters from file
Update.LoadFromFileNF("C:\RegHieChng.pefx", UpdateLoadMode.Replace);
// Create additional update settings
Context := Update.CreateUpdateContext;
// Get dictionaries
sourceDim := MB.ItemById("MDM_INDICATOR_S").Bind;
targetDim := MB.ItemById("MDM_INDICATOR_D").Bind;
// Get dictionary hierarchies
sourceHierarchies := (sourceDim As IDimensionModel).Hierarchies;
targetHierarchies := (targetDim As IDimensionModel).Hierarchies;
// Go through source dictionary hierarchies
For i := 0 To sourceHierarchies.Count - 1 Do
// Get the current source dictionary hierarchy
sourceHierarchy := sourceHierarchies.Item(i);
// Search identical consumer dictionary hierarchy
targetHierarchy := targetHierarchies.FindById(sourceHierarchy.Id);
// If such hierarchy is found
If (targetHierarchy <> Null) Then
// Redetermine alternative hierarchy, to which source dictionary refers.
// It will refer to consumer dictionary alternative hierarchy
context.RegisterHierarchyChange(sourceDim.Key, sourceHierarchy.Key, sourceHierarchy.Id,
targetHierarchy.Key, targetHierarchy.Id, targetDim);
// Get a dictionary used for alternative hierarchy in source dictionary
sourceHieSrc := sourceHierarchy.Source As IMetabaseObject;
// Get a dictionary used for alternative hierarchy in consumer dictionary
targetHieSrc := targetHierarchy.Source As IMetabaseObject;
// Redetermine a dictionary used for building alternative hierarchy in source dictionary.
// The dictionary will be used to build alternative hierarchy in consumer dictionary
context.RegisterKeyChange(sourceHieSrc.ClassId, sourceHieSrc.Key, targetHieSrc.Key,
sourceHieSrc.Id, targetHieSrc.Id, targetHieSrc);
End If;
End For;
// Get map of keys used for repeated mapping of update objects
KeyMap := Context.KeyMap;
// Check if map is empty
If Not KeyMap.IsEmpty Then
// If map contains data, go through its elements
For i := 0 To KeyMap.Count - 1 Do
// Get parameters of repeated mapping of update object
UpdObjRemap := KeyMap.Item(i);
// Output information about parameters of repeated object mapping
Debug.WriteLine("Repository object type: " + UpdObjRemap.ClassID.ToString);
Debug.WriteLine("Whether several repeated mappings are allowed for objects: " + UpdObjRemap.HasMultiValues.ToString);
Debug.WriteLine("New object identifier: " + UpdObjRemap.NewId);
Debug.WriteLine("Old object identifier: " + UpdObjRemap.OldId);
Debug.WriteLine("New object key: " + UpdObjRemap.NewKey.ToString);
Debug.WriteLine("Old object key: " + UpdObjRemap.OldKey.ToString);
Debug.WriteLine("Zero mapping is used: " + UpdObjRemap.NullRemapping.ToString);
If UpdObjRemap.Object <> Null Then
Debug.WriteLine("Consumer object used for repeated mapping: " + UpdObjRemap.Object.Name);
End If;
Debug.Write("Repeated mapping type: ");
Select Case UpdObjRemap.Type
Case MetabaseUpdateRemappingType.Unknown: Debug.WriteLine("unknown type");
Case MetabaseUpdateRemappingType.Object: Debug.WriteLine("repository object");
Case MetabaseUpdateRemappingType.Hierarchy: Debug.WriteLine("alternative hierarchy");
Case MetabaseUpdateRemappingType.MetafactsAttribute: Debug.WriteLine("time series attributes");
Case MetabaseUpdateRemappingType.MetavalsAttribute: Debug.WriteLine("observation attributes");
Case MetabaseUpdateRemappingType.None: Debug.WriteLine("type is not set");
End Select;
Debug.WriteLine("");
End For;
End If;
// Apply update
Update.ApplyEx(Null, Context);
End Sub UserProc;
After executing the example the MDM_INDICATOR_S dictionary is updated. It will be set up to use alternative hierarchies of the MDM_INDICATOR_D dictionary.
Imports Prognoz.Platform.Interop.Dimensions;
…
Public Shared Sub Main(Params: StartParams);
Var
MB: IMetabase;
Update: IMetabaseUpdate;
Context: IMetabaseUpdateContext;
sourceDim, targetDim: IMetabaseObject;
sourceHieSrc, targetHieSrc: IMetabaseObject;
sourceHierarchies, targetHierarchies: IDimHierarchies;
sourceHierarchy, targetHierarchy: IDimHierarchy;
i: Integer;
KeyMap: IMetabaseUpdateKeyMap;
UpdObjRemap: IMetabaseUpdateObjectRemapping;
Begin
// Get current repository
MB := Params.Metabase;
// Create an update
Update := Mb.CreateUpdate();
// Load update parameters from file
Update.LoadFromFileNF("C:\RegHieChng.pefx", UpdateLoadMode.ulmReplace);
// Create additional update settings
Context := Update.CreateUpdateContext();
// Get dictionaries
sourceDim := MB.ItemById["MDM_INDICATOR_S"].Bind();
targetDim := MB.ItemById["MDM_INDICATOR_D"].Bind();
// Get dictionary hierarchies
sourceHierarchies := (sourceDim As IDimensionModel).Hierarchies;
targetHierarchies := (targetDim As IDimensionModel).Hierarchies;
// Go through source dictionary hierarchies
For i := 0 To sourceHierarchies.Count - 1 Do
// Get the current source dictionary hierarchy
sourceHierarchy := sourceHierarchies.Item[i];
// Search identical consumer dictionary hierarchy
targetHierarchy := targetHierarchies.FindById(sourceHierarchy.Id);
// If such hierarchy is found
If (targetHierarchy <> Null) Then
// Redetermine alternative hierarchy, to which source dictionary refers.
// It will refer to consumer dictionary alternative hierarchy
context.RegisterHierarchyChange(sourceDim.Key, sourceHierarchy.Key, sourceHierarchy.Id,
targetHierarchy.Key, targetHierarchy.Id, targetDim);
// Get dictionary used for alternative hierarchy in source dictionary
sourceHieSrc := sourceHierarchy.Source As IMetabaseObject;
// Get a dictionary used for alternative hierarchy in consumer dictionary
targetHieSrc := targetHierarchy.Source As IMetabaseObject;
// Redetermine a dictionary used for building alternative hierarchy in source dictionary.
// The dictionary will be used to build alternative hierarchy in consumer dictionary
context.RegisterKeyChange(sourceHieSrc.ClassId, sourceHieSrc.Key, targetHieSrc.Key,
sourceHieSrc.Id, targetHieSrc.Id, targetHieSrc);
End If;
End For;
// Get map of keys used for repeated mapping of update objects
KeyMap := Context.KeyMap;
// Check if map is empty
If Not KeyMap.IsEmpty Then
// If map contains data, go through its elements
For i := 0 To KeyMap.Count - 1 Do
// Get parameters of repeated mapping of update object
UpdObjRemap := KeyMap.Item[i];
// Output information about parameters of repeated object mapping
System.Diagnostics.Debug.WriteLine("Repository object type: " + UpdObjRemap.ClassID.ToString());
System.Diagnostics.Debug.WriteLine("Whether several mappings are allowed for object: " + UpdObjRemap.HasMultiValues.ToString());
System.Diagnostics.Debug.WriteLine("New object identifier: " + UpdObjRemap.NewId);
System.Diagnostics.Debug.WriteLine("Old object identifier: " + UpdObjRemap.OldId);
System.Diagnostics.Debug.WriteLine("New object identifier: " + UpdObjRemap.NewKey.ToString());
System.Diagnostics.Debug.WriteLine("Old object identifier: " + UpdObjRemap.OldKey.ToString());
System.Diagnostics.Debug.WriteLine("Zero mapping is used: " + UpdObjRemap.NullRemapping.ToString());
If UpdObjRemap.Object <> Null Then
System.Diagnostics.Debug.WriteLine("Consumer object used for repeated mapping: " + UpdObjRemap.Object.Name);
End If;
System.Diagnostics.Debug.Write("Repeated mapping type: ");
Select Case UpdObjRemap.Type
Case MetabaseUpdateRemappingType.murtUnknown: System.Diagnostics.Debug.WriteLine("unknown type");
Case MetabaseUpdateRemappingType.murtObject: System.Diagnostics.Debug.WriteLine("repository object");
Case MetabaseUpdateRemappingType.murtHierarchy: System.Diagnostics.Debug.WriteLine("alternative hierarchy");
Case MetabaseUpdateRemappingType.murtMetafactsAttribute: System.Diagnostics.Debug.WriteLine("time series attributes");
Case MetabaseUpdateRemappingType.murtMetavalsAttribute: System.Diagnostics.Debug.WriteLine("observation attributes");
Case MetabaseUpdateRemappingType.murtNone: System.Diagnostics.Debug.WriteLine("type is not set");
End Select;
System.Diagnostics.Debug.WriteLine("");
End For;
End If;
// Apply update
Update.ApplyEx(Null, Context);
End Sub;Public Shared Sub Main(Params: StartParams);
Var
MB: IMetabase;
Update: IMetabaseUpdate;
Context: IMetabaseUpdateContext;
sourceDim, targetDim: IMetabaseObject;
sourceHieSrc, targetHieSrc: IMetabaseObject;
sourceHierarchies, targetHierarchies: IDimHierarchies;
sourceHierarchy, targetHierarchy: IDimHierarchy;
i: Integer;
KeyMap: IMetabaseUpdateKeyMap;
UpdObjRemap: IMetabaseUpdateObjectRemapping;
Begin
// Get current repository
MB := Params.Metabase;
// Create an update
Update := Mb.CreateUpdate();
// Load update parameters from file
Update.LoadFromFileNF("C:\RegHieChng.pefx", UpdateLoadMode.ulmReplace);
// Create additional update settings
Context := Update.CreateUpdateContext();
// Get dictionaries
sourceDim := MB.ItemById["MDM_INDICATOR_S"].Bind();
targetDim := MB.ItemById["MDM_INDICATOR_D"].Bind();
// Get dictionary hierarchies
sourceHierarchies := (sourceDim As IDimensionModel).Hierarchies;
targetHierarchies := (targetDim As IDimensionModel).Hierarchies;
// Go through source dictionary hierarchies
For i := 0 To sourceHierarchies.Count - 1 Do
// Get the current source dictionary hierarchy
sourceHierarchy := sourceHierarchies.Item[i];
// Search identical consumer dictionary hierarchy
targetHierarchy := targetHierarchies.FindById(sourceHierarchy.Id);
// If such hierarchy is found
If (targetHierarchy <> Null) Then
// Redetermine alternative hierarchy, to which source dictionary refers.
// It will refer to consumer dictionary alternative hierarchy
context.RegisterHierarchyChange(sourceDim.Key, sourceHierarchy.Key, sourceHierarchy.Id,
targetHierarchy.Key, targetHierarchy.Id, targetDim);
// Get dictionary used for alternative hierarchy in source dictionary
sourceHieSrc := sourceHierarchy.Source As IMetabaseObject;
// Get a dictionary used for alternative hierarchy in consumer dictionary
targetHieSrc := targetHierarchy.Source As IMetabaseObject;
<font color="#008000">// Redetermine dictionary used for building alternative hierarchy in source dictionary.<br/> </font> <font color="#008000">// Whether dictionary is used for building alternative hierarchy in consumer dictionary<br/> </font> context.RegisterKeyChange(sourceHieSrc.ClassId, sourceHieSrc.Key, targetHieSrc.Key,<br/> sourceHieSrc.Id, targetHieSrc.Id, targetHieSrc);<br/> <font color="#008080">End</font> <font color="#008080">If</font>;<br/> <font color="#008080">End</font> <font color="#008080">For</font>;<br/> <font color="#008000">// Get map of keys used for repeated mapping of update objects<br/> </font> KeyMap := Context.KeyMap;<br/> <font color="#008000">// Check if map is empty<br/> </font> <font color="#008080">If</font> <font color="#008080">Not</font> KeyMap.IsEmpty <font color="#008080">Then</font><br/> <font color="#008000">// If map contains data, go through its elements<br/> </font> <font color="#008080">For</font> i := <font color="#008000">0</font> <font color="#008080">To</font> KeyMap.Count - <font color="#008000">1</font> <font color="#008080">Do</font><br/> <font color="#008000">// Get parameters of repeated mapping of update object<br/> </font> UpdObjRemap := KeyMap.Item[i];<br/> <font color="#008000">// Output information about parameters of repeated object mapping<br/> </font> System.Diagnostics.Debug.WriteLine(<font color="#800000">"Repository object type: "</font> + UpdObjRemap.ClassID.ToString());<br/> System.Diagnostics.Debug.WriteLine(<font color="#800000">"Whether several repeated mappings are allowed for object: "</font> + UpdObjRemap.HasMultiValues.ToString());<br/> System.Diagnostics.Debug.WriteLine(<font color="#800000">"New object identifier: "</font> + UpdObjRemap.NewId);<br/> System.Diagnostics.Debug.WriteLine(<font color="#800000">"Old object identifier: "</font> + UpdObjRemap.OldId);<br/> System.Diagnostics.Debug.WriteLine(<font color="#800000">"New object key: "</font> + UpdObjRemap.NewKey.ToString());<br/> System.Diagnostics.Debug.WriteLine(<font color="#800000">"Old object key: "</font> + UpdObjRemap.OldKey.ToString());<br/> System.Diagnostics.Debug.WriteLine(<font color="#800000">"Zero mapping is used: "</font> + UpdObjRemap.NullRemapping.ToString());<br/> <font color="#008080">If</font> UpdObjRemap.Object <> <font color="#008080">Null</font> <font color="#008080">Then</font><br/> System.Diagnostics.Debug.WriteLine(<font color="#800000">"Consumer object used for repeated mapping: "</font> + UpdObjRemap.Object.Name);<br/> <font color="#008080">End</font> <font color="#008080">If</font>;<br/> System.Diagnostics.Debug.Write(<font color="#800000">"Repeated mapping type: "</font>);<br/> <font color="#008080">Select</font> <font color="#008080">Case</font> UpdObjRemap.Type<br/> <font color="#008080">Case</font> MetabaseUpdateRemappingType.murtNone: System.Diagnostics.Debug.WriteLine(<font color="#800000">"type is not set"</font>);<br/> <font color="#008080">Case</font> MetabaseUpdateRemappingType.murtObject: System.Diagnostics.Debug.WriteLine(<font color="#800000">"repository object"</font>);<br/> <font color="#008080">Case</font> MetabaseUpdateRemappingType.murtHierarchy: System.Diagnostics.Debug.WriteLine(<font color="#800000">"alternative hierarchy"</font>);<br/> <font color="#008080">Case</font> MetabaseUpdateRemappingType.murtMetafactsAttribute: System.Diagnostics.Debug.WriteLine(<font color="#800000">"time series attributes"</font>);<br/> <font color="#008080">Case</font> MetabaseUpdateRemappingType.murtMetavalsAttribute: System.Diagnostics.Debug.WriteLine(<font color="#800000">"observation attributes"</font>);<br/> <font color="#008080">End</font> <font color="#008080">Select</font>;<br/> System.Diagnostics.Debug.WriteLine(<font color="#800000">""</font>);<br/> <font color="#008080">End</font> <font color="#008080">For</font>;<br/> <font color="#008080">End</font> <font color="#008080">If</font>;<br/> <font color="#008000">// Apply update<br/> </font> Update.ApplyEx(<font color="#008080">Null</font>, Context);<br/> <font color="#008080">End</font> <font color="#008080">Sub</font>;
See also: