RegisterHierarchyChangeO(OwnObject: Integer;
oldObjKey: Integer;
oldHieKey: Integer;
oldHieId: String;
newHieKey: Integer;
newHieId: String;
newObject: IMetabaseObject);
RegisterHierarchyChangeO(OwnObject: uinteger;
oldObjKey: uinteger;
oldHieKey: uinteger;
oldHieId: string;
newHieKey: uinteger;
newHieId: string;
newObject: Prognoz.Platform.Interop.Metabase.IMetabaseObject);
OwnObject. Object owner, which alternative hierarchy is redetermined.
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 the alternative hierarchy, to which updated object refers, taking into account object owner.
To redetermine alternative hierarchy without taking into account owner, use the IMetabaseUpdateContext.RegisterHierarchyChange 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 MDM_INDICATOR_S dictionary must be a child one for time series database with the TSDB_PEF identifier.
The file system must contain the C:\RegHieOChng.pefx update file used for updating of custom class object that depends on the MDM_INDICATOR_S dictionary and its parent.
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;
TSDBKey: Integer;
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:\RegHieOChng.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;
// Get time series database key
TSDBKey := MB.GetObjectKeyById("TSDB_PEF");
context.RegisterKeyChangeO(TSDBKey, sourceDim.ClassId, sourceDim.Key, targetDim.Key,
sourceDim.Id, targetDim.Id, targetDim);
// 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.RegisterHierarchyChangeO(TSDBKey, 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.RegisterKeyChangeO(TSDBKey, sourceHieSrc.ClassId, sourceHieSrc.Key, targetHieSrc.Key,
sourceHieSrc.Id, targetHieSrc.Id, targetHieSrc);
End If;
End For;
// Apply update
Update.ApplyEx(Null, Context);
// Get map of keys used for repeated mapping of update objects
KeyMap := Context.KeyMap;
// Search mapping parameters for the dictionary used for building alternative hierarchy
UpdObjRemap := KeyMap.FindByOldId(MetabaseObjectClass.KE_CLASS_METADICTIONARYRDS, targetHieSrc.Id);
// Check if parameters are found
If UpdObjRemap <> Null Then
// Output information about parameters of repeated object mapping
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);
End If;
End Sub UserProc;
After executing the example the dictionary, on which the custom class object depends, and alternative hierarchy of this dictionary are redetermined for the custom class object.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
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;
TSDBKey: uinteger;
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:\RegHieOChng.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;
// Get time series database key
TSDBKey := MB.GetObjectKeyById("TSDB_PEF");
context.RegisterKeyChangeO(TSDBKey, sourceDim.ClassId, sourceDim.Key, targetDim.Key,
sourceDim.Id, targetDim.Id, targetDim);
// 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.RegisterHierarchyChangeO(TSDBKey, 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.RegisterKeyChangeO(TSDBKey, sourceHieSrc.ClassId, sourceHieSrc.Key, targetHieSrc.Key,
sourceHieSrc.Id, targetHieSrc.Id, targetHieSrc);
End If;
End For;
// Apply update
Update.ApplyEx(Null, Context);
// Get map of keys used for repeated mapping of update objects
KeyMap := Context.KeyMap;
// Search mapping parameters for the dictionary used for building alternative hierarchy
UpdObjRemap := KeyMap.FindByOldId(MetabaseObjectClass.KE_CLASS_METADICTIONARYRDS As integer, targetHieSrc.Id);
// Check if parameters are found
If UpdObjRemap <> Null Then
// Output information about parameters of repeated object mapping
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());
End If;
End Sub;
See also: