IMetabaseUpdateObjectNode.ApplyState

Syntax

ApplyState: IMetabaseUpdateObjectApplyState;

Description

The ApplyState property returns parameters of object readiness to updating.

Comments

A property value is filled after calling the IMetabaseUpdate.Prepare method of the whole update, or the IMetabaseUpdateNode.Prepare method of the particular object in the update.

Example

Public Class CUpdateEvents: UpdateEvents

Public Sub OnBeginUpdate(Update: IMetabaseUpdate);

Begin

Debug.WriteLine("Beginning of update of repository objects");

End Sub OnBeginUpdate;

 

Public Sub OnBeforeApplyUpdate(Update: IMetabaseUpdate);

Var

Root: IMetabaseUpdateFolderNode;

Node: IMetabaseUpdateNode;

ObjectNode: IMetabaseUpdateObjectNode;

State: IMetabaseUpdateObjectApplyState;

MB: IMetabase;

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 Or 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("Update of objects is completed");

End Sub OnEndUpdate;

End Class CUpdateEvents;

This example is a template for update module. On applying the update that contains this module readiness of objects that correspond with repository objects is checked. Particularly, a conflict will be solved if in repository there is not an object for that the type - Only Update was assigned in update.

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

NOTE. It is necessary to 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:

IMetabaseUpdateObjectNode