| Oracle® OLAP Analytic Workspace Java API Reference 10g Release 2 (10.2.0.4) B14351-04 |
BuildAWExample.java example program creates a similar analytic workspace by using the Oracle OLAP Analytic Workspace Java API.
The BuildAWExample program creates objects that implement the following tasks described in Oracle OLAP Application Developer's Guide.
The data sources are columns in the relational tables of the Global sample schema. This document outlines the sequence in which the program creates the Analytic Workspace Java API objects. The code examples are from the program. The lines as they appear in this document are not necessarily consecutive in the program.
The program accomplishes other tasks that are not included in this outline, such as creating a measure folder, writing an XML representation of the objects to a file, and creating a log file that records the creation of the objects.
AWConnection as a class variable and instantiates it using values passed in as command-line arguments.
public static AWConnection awConnection;
awConnection = new AWConnection(user, password, connection);
BuildAWExample program implements a multidimensional model that associates dimensions, levels, hierarchies, attributes, cubes, and measures with an analytic workspace. The program first creates an AW object to represent the analytic workspace. It then creates Dimension objects and the Attribute, Level, and Hierarchy objects associated with each Dimension. Next, it creates Cube and Measure objects.
AW object and specify a name for it.
String awName = "GLOBALAW";
AW globalAW = new AW();
globalAW.setName(awName);
The program creates a Dimension object for each of the logical dimensions of the analytic workspace. This outline includes only the creation of a Dimension for a dimension that has time values as its members. Because a time dimension has attributes that other dimensions do not have, the setIsTime(true) method specifies that the Dimension is a time dimension.
Dimension timeDim = globalAW.createDimension();
timeDim.setName("TIME_AW");
timeDim.setIsTime(true);
The members of the dimensions of the analytic workspace are organized into level-based hierarchies.
For each Dimension, the program creates Attribute, Level, and
Hierarchy objects.
The program has separate methods that creates those objects for each Dimension. The following code is in the createTimeDim method. The setUseNativeKey(true) method indicates that the primary key of the dimension table contains the lowest-level dimension members.
timeDim.setUseNativeKey(true);
The following lines create one of the Attribute objects associated with the Dimension. Creation of Attribute objects for the other attributes of the dimension is not shown.
Attribute timeTimeSpanAttr = timeDim.createAttribute();
timeTimeSpanAttr.setName("Time_Span");
timeTimeSpanAttr.setClassification("TIME_SPAN");
The members of the dimension are organized into a hierarchical relationship that is defined by levels. The levels are represented by Level objects and the hierarchy is represented by a Hiearchy object.
The following lines create a Level for the lowest-level members of dimension, which are month values.
Level monthLevel = timeDim.createLevel();
monthLevel.setName("MONTH_AW");
An AttributeProjection associates an Attribute with a Level. In the BuildAWExample program, the setupAttributeProjection method creates the AttributeProjection objects. The following lines are from that method, but have the values passed to the method for creating an AttributeProjection for the time span attribute for the month level.
AttributeProjection _ap = monthLevel.createAttributeProjection();
_ap.setName("Time Span");
_ap.setAttribute(timeTimeSpanAttr);
The next line creates a Hierarchy object and associates it with the Dimension.
Hierarchy calendarYearHier = timeDim.createHierarchy();
calendarYearHier.setName("CALENDAR_YEAR_AW");
Cube object for each set of Measure objects that is dimensioned by the same set of Dimension objects. The following lines illustrate the creation of a Cube that associates a measure with its dimensions. The data in the measure is the quantity of product units sold. The measure is dimensioned by dimensions for time, customers, products, and sales channels.
The following lines create a Cube and specify a name for it.
Cube unitsCube = globalAW.createCube();
unitsCube.setName("UNITS_CUBE_AW");
A CubeDimRef associates a Dimension with a Cube. The program has an associateCubeDimensions method that creates a CubeDimRef for each dimension that dimensions the measures associated with the Cube. The following lines from that method have values that create a CubeDimRef for the time dimension.
CubeDimRef _cdr = unitsCube.createCubeDimRef();
_cdr.setDimension(timeDim);
The program creates Measure objects and associate them with a Cube. The following lines create a Measure for the units Cube, and specify a name and a data type for the Measure.
Measure units = unitsCube.createMeasure();
units.setName("UNITS_AW");
units.setDataType("NUMBER");
MappingGroup classes to map relational data sources to their target AWObject objects. For a diagram of the class hierarchy and associations of MappingGroup, see MappingGroup Class Associations.
BuildAWExample program has a createLevelMap method that maps the Level and AttributeProjection objects to columns in the relational tables of the Global schema. The following lines are from that method, but have the values passed to the method for creating the objects that map the month level and time span attribute to relational source columns.
The DimensionMapGroup owns the DimensionKeySourceExpression and AttributeSourceExpression objects. Each of those ExternalSourceExpression objects has a SourceColumn that specifies the column to which the Level or AttributeProjection is mapped.
DimensionMapGroup _dmg = monthLevel.createSourceDimensionMapGroup();
DimensionKeySourceExpression _key = _dmg.CreateKeyMap();
SourceColumn _keycol = _key.CreateSourceColumn();
_keycol.setColumn("GLOBAL.TIME_DIM.MONTH_ID");
AttributeSourceExpression _attrMap = _dmg.CreateAttributeMap();
_attrMap.setTargetObject(timeTimeSpanAttr);
SourceColumn _attrCol = monthTS_attrMap.CreateSourceColumn();
_attrCol.setColumn("GLOBAL.TIME_DIM.MONTH_TIMESPAN");
createHierarchyMap method associates Level objects with a Hierarchy, specifies a source column for each Level, and specifies the parent Level for each Level except the highest one. The following lines are from that method, but have the values passed to the method for creating the objects that associate the time dimension levels with the calendarHier Hierarchy.
The method creates a HierarchyLevelAssociation for each Level and then creates a set of mapping objects for each HierarchyLevelAssociation.
The following lines use values that create the objects for the month Level.
HierarchyLevelAssociation _hla = calendarHier.createHierarchyLevelAssociation();
_hla.setLevel(monthLevel);
DimensionMapGroup _dmg = _hla.createSourceDimensionMapGroup();
DimensionKeySourceExpression _dkse = _dmg.CreateKeyMap();
SourceColumn _levColumn = _dkse.CreateSourceColumn();
_levColumn.setColumn("GLOBAL.TIME_DIM.MONTH_ID");
For each Level except the highest one, the createHierarchyMap method creates a HierarchicalParentSourceExpression that associates the Level with its parent and that has a SourceColumn that maps a relational column to the parent. The following lines create a parent map for the month Level.
HierarchicalParentSourceExpression _hpse = _dmg.CreateParentMap();
SourceColumn _hpsesc = _hpse.CreateSourceColumn();
_hpsesc.setColumn("GLOBAL.TIME_DIM.QUARTER_ID");
createCubeMap method creates a CubeMapGroup for the Cube. The method creates objects that map the lowest levels of the dimensions to their source columns and that map the measures to their source columns. It associates those objects with the CubeMapGroup.
The following lines are from the createCubeMap method but have the values passed to the method for creating the objects for the units Cube. The lines create a CubeMapGroup, and then create a CubeDimensionSourceExpression for the lowest level of the time dimension and associate a source column with it.
CubeMapGroup _cmg = units.createSourceCubeMapGroup();
CubeDimensionSourceExpression _cdse = _cmg.CreateKeyMap();
_cdse.addLevel(monthLevel);
SourceColumn _keycol = _cdse.CreateSourceColumn();
_keycol.setColumn("GLOBAL.UNITS_HISTORY_FACT.MONTH_ID");
The next lines specify that Oracle OLAP does not automatically calculate the aggregated values for the measure. They map the measure to a source column for the Cube by creating MeasureSourceExpression and SourceColumn objects and specifying the column.
units.setAutoSolve("NO_AUTO_SOLVE");
MeasureSourceExpression _measMap = _cmg.CreateAttributeMap();
_measMap.setTargetObject(units);
SourceColumn _meascol = _measMap.CreateSourceColumn();
_meascol.setColumn("GLOBAL.UNITS_HISTORY_FACT.UNITS");
AW object to create the structures in the analytic workspace and to commit them to the relational database. The next two lines call those methods.
globalAW.Create(awConnection);
globalAW.Commit(awConnection);
The program then uses classes from the AWAction package to build the analytic workspace and populate it with data. In the program, the method xml_build_global_aw accomplishes those tasks. The following lines are from that method. The curInteraction object is a class variable.
curInteraction = new Interaction();
curInteraction.setConnection(awConnection);
BuildDatabase myBuild =
(BuildDatabase)curInteraction.createAction("BUILDDATABASE");
myBuild.setAWName(awName);
myBuild.Execute();
Finally, the program closes the connection to the database.
awConnection.close();