ICubeSegments.CreateSegment

Syntax

CreateSegment(SelectionSet: IDimSelectionSet): ICubeSegment;

Parameters

SelectionSet. Dimension element selection, according to which data access will be determined.

Description

The CreateSegment method creates a cube segment.

Comments

Before creating a segment all cube dimensions should be added to the collection of dimensions of segment container.

Example

Executing the example requires that the repository contains a standard cube with the STD_CUBE identifier and a segment container with the SEG_CONTAINER identifier. The list of cube dimensions includes a dimension with the COUNTRY identifier. The list of container dimensions should include all cube dimensions.

Add links to the Cubes, Db, Dimensions and Metabase system assemblies.

Sub UserProc;
Var
    Mb: IMetabase;
    SegContainer: ICubeSegmentContainer;
    Cube: IStandardCube;
    CubeDest: ICubeInstanceDestination;
    DimSS: IDimSelectionSet;
    DimS: IDimSelection;
    Segments: ICubeSegments;
    Segment: ICubeSegment;
    MDesc: IMetabaseObjectDescriptor;
    SecDesc: ISecurityDescriptor;
    Subject: ISecuritySubject;
    Acl: IAccessControlList;
Begin
    Mb := MetabaseClass.Active;
    SegContainer := Mb.ItemById("SEG_CONTAINER").Edit As ICubeSegmentContainer;
    // Specify segment container for cube
    Cube := Mb.ItemById("STD_CUBE").Edit As IStandardCube;
    Cube.SegmentContainer := SegContainer;
    (Cube As IMetabaseObject).Save;
    // Open cube
    CubeDest := (Mb.ItemById("STD_CUBE").Open(NullAs ICubeInstance).Destinations.DefaultDestination;
    // Create a selection, according to which a segment will be created
    DimSS := CubeDest.CreateDimSelectionSet;
    DimS := DimSS.FindById("COUNTRY");
    DimS.DeselectAll;
    DimS.SelectElement(0False);
    // Create a segment based on cube selection
    Segments := SegContainer.GetAllSegments;
    Segment := Segments.CreateSegment(DimSS);
    // Save changes
    (SegContainer As IMetabaseObject).Save;
    // Grant access permissions to segment
    MDesc := Segment As IMetabaseObjectDescriptor;
    SecDesc := MDesc.SecurityDescriptor;
    SecDesc.Edit;
    Acl := SecDesc.Acl;
    Subject := Mb.Security.ResolveName("USERS");
    Acl.AddAce(AceType.AccessAllowed, Subject.Sid, MetabaseObjectPredefinedRights.Read);
    Subject := Mb.LogonSession.User;
    Acl.AddAce(AceType.AccessAllowed, Subject.Sid, MetabaseObjectPredefinedRights.Read Or MetabaseObjectPredefinedRights.Write);
    SecDesc.Apply(True);
    Debug.WriteLine("Number of container segments: " + Segments.Count.ToString);
    Debug.WriteLine("Segment created: " + MDesc.Name + '(' + MDesc.Id + ')');
End Sub UserProc;

After executing the example a segment container is set for a standard cube. After this a new segment is created based on the specified cube selection. Access permissions are granted for the segment: for users from the Users group - read-only permissions; for the current user who executed the code - read and write permissions. Information about the number of container segments and a new segment will be displayed in the development environment console.

See also:

ICubeSegments