RegisterKeyChangeO(OwnObject: Integer;
ClassId: Integer;
oldKey: Integer;
newKey: Integer;
oldId: String;
newId: String;
Object: IMetabaseObject);
RegisterKeyChangeO(OwnObject: uinteger;
ClassId: uinteger;
oldKey: uinteger;
newKey: uinteger;
oldId: string;
newId: string;
Object: Prognoz.Platform.Interop.Metabase.IMetabaseObject);
OwnObject. Owner of the object, which key is redetermined.
ClassId. The identifier of the consumer repository class, to which the update object refers.
oldKey. The key of the provider repository object, to which the object refers before update.
newKey. The key of the consumer repository object, to which the object refers after update.
oldId. The identifier of the provider repository object on which the object refers before updating.
newId. The identifier of the consumer repository object, to which the object refers after update.
Object. The consumer repository object on which the object refers after updating.
The RegisterKeyChangeO method redetermines the key of the repository object, to which the update object refers, taking into account owner.
One of the available values of the MetabaseObjectClass enumeration is specified as the value of the ClassId parameter.
Executing the example requires that the repository contains table MDM dictionaries with the MDM_HIE_INDICATOR_S, MDM_HIE_INDICATOR_D and MDM_INDICATOR_D identifiers. The MDM_INDICATOR_D dictionary must be a parent one for the MDM_HIE_INDICATOR_D dictionary.
The file system must contain the C:\CustomObj.pefx update file used to update the custom class object that depends on the MDM_HIE_INDICATOR_D dictionary and its parent.
Add a link to the Metabase system assembly.
Sub UserUpd;
Var
Mb: IMetabase;
Update: IMetabaseUpdate;
Context: IMetabaseUpdateContext;
NewObj, OldObj: IMetabaseObject;
Progress: MyUpdateProgress;
Begin
// Get current repository
Mb := MetabaseClass.Active;
// Create an update
Update := Mb.CreateUpdate;
// Load update parameters from file
Update.LoadFromFileNF("C:\CustomObj.pefx");
// Get dictionaries
NewObj := Mb.ItemById("MDM_HIE_INDICATOR_S").Bind;
OldObj := Mb.ItemById("MDM_HIE_INDICATOR_D").Bind;
// Create additional update settings
Context := Update.CreateUpdateContext;
// Redetermine the dictionary, on which custom object depends in update
Context.RegisterKeyChangeO(Mb.ItemById("MDM_INDICATOR_D").key, MetabaseObjectClass.KE_CLASS_METADICTIONARYRDS,
OldObj.key, NewObj.key, OldObj.Id, NewObj.Id, NewObj);
// Create an object that implements events that occur during update
Progress := New MyUpdateProgress.Create;
// Perform update
Update.ApplyEx(Progress, Context);
End Sub UserUpd;
// Class that implements events that occur during update
Class MyUpdateProgress: UpdateProgress
// Event that occurs if there are additional update settings
Sub OnContext(Context: IMetabaseUpdateContext);
Var
i, j: Integer;
KeyMap: IMetabaseUpdateKeyMap;
UpdRemaps: IMetabaseUpdateRemappings;
UpdObjRemap: IMetabaseUpdateObjectRemapping;
UpdRemap: IMetabaseUpdateRemapping;
Begin
// 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 j := 0 To KeyMap.Count - 1 Do
UpdObjRemap := KeyMap.Item(j);
// Get collection of parameters of repeated mapping for repository objects
UpdRemaps := UpdObjRemap.Map(MetabaseUpdateRemappingType.Object);
// Check if collection contains elements
If Not UpdRemaps.IsEmpty Then
// If collection contains data, go through its elements
For i := 0 To UpdRemaps.Count - 1 Do
UpdRemap := UpdRemaps.Item(i);
// Output information about parameters of repeated object mapping
Debug.WriteLine("New object identifier: " + UpdRemap.NewId);
Debug.WriteLine("Old object identifier: " + UpdRemap.OldId);
Debug.WriteLine("New object key: " + UpdRemap.NewKey.ToString);
Debug.WriteLine("Old object key: " + UpdRemap.OldKey.ToString);
Debug.WriteLine("");
End For;
End If;
End For;
End If;
End Sub OnContext;
End Class MyUpdateProgress;
After executing the example custom object is updated: now it depends on the MDM_HIE_INDICATOR_S dictionary. During the update the event is processed that occurs whether there are additional update settings. The console displays information about repeated object mapping executed on update.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Public Shared Sub Main(Params: StartParams);
Var
Mb: IMetabase;
Update: IMetabaseUpdate;
Context: IMetabaseUpdateContext;
NewObj, OldObj: IMetabaseObject;
Progress: MyUpdateProgress;
Begin
// Get current repository
Mb := Params.Metabase;
// Create an update
Update := Mb.CreateUpdate();
// Load update parameters from file
Update.LoadFromFileNF("C:\CustomObj.pefx", UpdateLoadMode.ulmReplace);
// Get dictionaries
NewObj := Mb.ItemById["MDM_HIE_INDICATOR_S"].Bind();
OldObj := Mb.ItemById["MDM_HIE_INDICATOR_D"].Bind();
// Create additional update settings
Context := Update.CreateUpdateContext();
// Redetermine the dictionary, on which custom object depends in update
Context.RegisterKeyChangeO(Mb.ItemById["MDM_INDICATOR_D"].key, MetabaseObjectClass.KE_CLASS_METADICTIONARYRDS As integer,
OldObj.key, NewObj.key, OldObj.Id, NewObj.Id, NewObj);
// Create an object that implements events that occur during update
Progress := New MyUpdateProgress.Create();
// Perform update
Update.ApplyEx(Progress, Context);
End Sub;
// Class that implements events that occur during update
Public Class MyUpdateProgress: IMetabaseUpdateProgress
// Event that occurs if there are additional update settings
Public Sub OnContext(Context: IMetabaseUpdateContext);
Var
i, j: Integer;
KeyMap: IMetabaseUpdateKeyMap;
UpdRemaps: IMetabaseUpdateRemappings;
UpdObjRemap: IMetabaseUpdateObjectRemapping;
UpdRemap: IMetabaseUpdateRemapping;
Begin
// 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 j := 0 To KeyMap.Count - 1 Do
UpdObjRemap := KeyMap.Item[j];
// Get collection of parameters of repeated mapping for repository objects
UpdRemaps := UpdObjRemap.Map[MetabaseUpdateRemappingType.murtObject];
// Check if collection contains elements
If Not UpdRemaps.IsEmpty Then
// If collection contains data, go through its elements
For i := 0 To UpdRemaps.Count - 1 Do
UpdRemap := UpdRemaps.Item[i];
// Output information about parameters of repeated object mapping
System.Diagnostics.Debug.WriteLine("New object identifier: " + UpdRemap.NewId);
System.Diagnostics.Debug.WriteLine("Old object identifier: " + UpdRemap.OldId);
System.Diagnostics.Debug.WriteLine("New object key: " + UpdRemap.NewKey.ToString());
System.Diagnostics.Debug.WriteLine("Old object key: " + UpdRemap.OldKey.ToString());
System.Diagnostics.Debug.WriteLine("");
End For;
End If;
End For;
End If;
End Sub;
Public Sub OnProgress(Data: IMetabaseUpdateProgressData);
Begin
End Sub;
Public Sub OnError(Data: IMetabaseUpdateProgressData; Var Ignore: Boolean);
Begin
End Sub;
Public Sub OnAskConstraintsHandling(Node: IMetabaseUpdateNode; Details: String; Var Handling: UpdateDataConstraintsHandlingType);
Begin
End Sub;
Public Sub OnAskReflectRights(Var Cancel: Boolean);
Begin
End Sub;
Public Sub OnResolve(Node: IMetabaseUpdateNode; Resolver: IMetabaseUpdateResolver);
Begin
End Sub;
Public Sub OnSkip(Data: IMetabaseUpdateProgressData);
Begin
End Sub OnSkip;
Public Sub OnNullLinks(Node: IMetabaseUpdateNode; Links: IMetabaseUpdateNullLinks);
Begin
End Sub;
Public Sub OnBeforeCustomObjectSaveToPef(Resolver: ICustomObjectResolver);
Begin
End Sub;
Public Sub OnAfterApplyCustomObject(Resolver: ICustomObjectResolver);
Begin
End Sub;
End Class MyUpdateProgress;
See also: