IMetabaseUpdateObjectApplyState.UpdateObject

Syntax

UpdateObject: IMetabaseObject;

Description

The UpdateObject property determines a repository object that will be updated.

Comments

This property is set automatically on executing the Prepare method if updated object is found in repository. The user can change value of this property in the OnBeforeApplyUpdate custom event used in update unit. If the update unit is not assumed to be used, use the ForceUpdateObject property to replace the repository object, to which the update is applied.

NOTE. An object that has the same class as an object in update has must be specified as an updated object.

Example

Public Class CUpdateEvents: UpdateEvents
    Public Sub OnBeginUpdate(Update: IMetabaseUpdate);
    Begin
        Debug.WriteLine("Repository objects update start");
    End Sub OnBeginUpdate;

    Public Sub OnBeforeApplyUpdate(Update: IMetabaseUpdate);
    Var
        MB: IMetabase;
        Root: IMetabaseUpdateFolderNode;
        Node: IMetabaseUpdateNode;
        ObjectNode: IMetabaseUpdateObjectNode;
        State: IMetabaseUpdateObjectApplyState;
        CrInfo: IMetabaseObjectCreateInfo;
        MObj: IMetabaseObject;
        i: Integer;
    Begin
        MB := MetabaseClass.Active;
        Root := Update.RootFolder;
        For i := 0 To Root.Count - 1 Do
            Node := Root.Item(i);
            If Node.NodeType = MetabaseUpdateNodeType.Object Then
                ObjectNode := Node As IMetabaseUpdateObjectNode;
                State := ObjectNode.ApplyState;
                Select Case State.State
                Case MetabaseUpdateObjectApplyState.Conflict, MetabaseUpdateObjectApplyState.ConflictObjectNotFound:
                    CrInfo := MB.CreateCreateInfo;
                    CrInfo.ClassID := ObjectNode.Object.ClassId;
                    CrInfo.Id := MB.GenerateId(ObjectNode.Object.Id);
                    CrInfo.Name := ObjectNode.Object.Name;
                    CrInfo.Parent := MB.Root;
                    CrInfo.SkipIdFormatCheck := True;
                    MObj := MB.CreateObject(CrInfo).Edit;
                    MObj.Save;
                    State.UpdateObject := MObj;
                    State.State := MetabaseUpdateObjectApplyState.EditExisting;
                End Select;
            End If;
        End For;
    End Sub OnBeforeApplyUpdate;

    Public Sub OnEndUpdate(Update: IMetabaseUpdate);
    Begin
        Debug.WriteLine("Object update is finished");
    End Sub OnEndUpdate;
End Class CUpdateEvents;

This example is a template for update unit. When the update that contains this unit is applied, readiness of objects that correspond to repository objects is checked. Particularly, a conflict will be solved if the repository does not have an object, for which the Update Only type was assigned in update.

A new empty object of the same class is created in repository to solve a conflict. This object is assigned as an updated object. The state of readiness of the updated object will be changed to Update Existing Object (MetabaseUpdateObjectApplyState.EditExisting).

NOTE. Remember that not all conflicts can be solved. In this example a condition of update of the object by key is ignored. If an object does not exist in repository, it will be created. Keys of the object in repository and in update are different.

See also:

IMetabaseUpdateObjectApplyState