IMetabaseUpdateContext.RegisterHierarchyChange

Syntax

RegisterHierarchyChange(oldObjKey: Integer; oldHieKey: Integer; oldHieId: String; newHieKey: Integer; newHieId: String; newObject: IMetabaseObject);

Parameters

oldObjKey. Source dictionary key.

oldHieKey. Alternative hierarchy key in source dictionary.

oldHieId. Alternative hierarchy identifier in source dictionary.

newHieKey. Alternative hierarchy key in destination dictionary.

newHieId. Alternative hierarchy identifier in destination dictionary.

newObject. Destination dictionary.

Description

The RegisterHierarchyChange method redetermines the alternative hierarchy, to which the updated object refers.

Comments

To redetermine alternative hierarchy taking into account updated object owner, use the IMetabaseUpdateContext.RegisterHierarchyChangeO method.

Example

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 is assumed to have the C:\RegHieChng.pefx update file that is 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 the 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 destination dictionary hierarchy
        targetHierarchy := targetHierarchies.FindById(sourceHierarchy.Id);
        // If such hierarchy is found
        If (targetHierarchy <> NullThen
            // Redetermine alternative hierarchy, to which source dictionary refers.
            // It will refer to destination 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 destination 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 destination 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 update object repeated mapping parameters
            UpdObjRemap := KeyMap.Item(i);
            // Display information about repeated object mapping parameters
            Debug.WriteLine("Repository object type: " + UpdObjRemap.ClassID.ToString);
            Debug.WriteLine("Indicates 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.

See also:

IMetabaseUpdateContext