Accessing Repository and Objects

Most times, the work of user application is based on communication with repository and its objects. The IMetabase interface describes connection with repository and has a set of various properties and methods to access to objects, security manager and other platform blocks.

To access the current repository, to which connection is established and in which application code is created, in the Fore language use the MetabaseClass.Active static property:

Public Sub WorkInRepository;
Var
    Mb: IMetabase;
Begin
    Mb := MetabaseClass.Active;
    //...
    // Further work in the current repository
    //...
End Sub WorkInRepository;

If it is required to create a new repository connection on executing the code, then repository descriptions from the IMetabaseManager.Definitions collection of repository manager are used. Repository manager described by the IMetabaseManager interface can be obtained using the IMetabaseManagerFactory.Active property:

Function ConnectToRepository: IMetabase;
Var
    MbManager: IMetabaseManager;
    MbDef: IMetabaseDefinition;
    Package: ISecurityPackage;
    Creds: IPasswordCredentials;
    Mb: IMetabase;
Begin
    // Repository manager
    MbManager := MetabaseManagerFactory.Active;
    // Description of the repository, to which connection is established
    MbDef := MbManager.Definitions.FindById("Repository");
    If MbDef <> Null Then
        Package := MbManager.Packs.FindById(MbDef.SecurityPackage).Package;
        // Credentials for connection
        Creds := Package.CreateCredentials(AuthenticationMode.Password) As IPasswordCredentials;
        Creds.UserName := "User";
        Creds.Password := "Password";
        // Connection
        Mb := MbDef.Open(Creds);
        If Mb <> Null Then
            Return Mb;
        Else
            Return Null;
        End If;
    Else
        Return Null;
    End If;
End Function ConnectToRepository;

Access to Objects

Each repository object has a description containing basic information about object: name, identifier, object class, lists of child and dependent objects and other information. To work with object description, there is an interface IMetabaseObjectDescriptor static property. To get description of one or several objects, use various properties and methods of the IMetabase, IMetabaseObjectDescriptor interface and others:

Public Sub WorkInRepository;
Var
    Mb: IMetabase;
    MDesc: IMetabaseObjectDescriptor;
    MDescs: IMetabaseObjectDescriptors;
    FindInfo: IMetabaseObjectFindInfo;
Begin
    Mb := MetabaseClass.Active;
    // Get object description by identifier
    MDesc := Mb.ItemById("Folder");
    // Default repository database
    MDesc := Mb.SpecialObject(MetabaseSpecialObject.DefaultDatabase);
    // Description of child objects for the specified object
    MDescs := Mb.ItemById("Folder").Children;
    // Search for objects by the specified parameters
    FindInfo := Mb.CreateFindInfo;
    FindInfo.Text := "Module";
    FindInfo.Attribute := FindAttribute.NameOrIdent;
    FindInfo.WholeWordsOnly := False;
    MDescs := MB.Find(FindInfo);
End Sub WorkInRepository;

After obtaining object description, go to set up its properties, work with data, set up access permission and execute any other specific operations.

See also:

Developing User Application