| Oracle® OLAP Analytic Workspace Java API Reference 10g Release 2 (10.2.0.3) B14351-03 |
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 the 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. Each line of code is preceded by the number of the line 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.
74 public static AWConnection awConnection;
128 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.
136 String awName = "GLOBALAW";
142 AW globalAW = new AW();
143 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, line 153 specifies that the Dimension is a time dimension.
149 Dimension timeDim = globalAW.createDimension();
150 timeDim.setName("TIME_AW");
153 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 that begins on line 440. The setUseNativeKey(true) method indicates that the primary key of the dimension table contains the lowest-level dimension members.
444 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.
454 Attribute timeTimeSpanAttr = timeDim.createAttribute();
455 timeTimeSpanAttr.setName("Time_Span");
456 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.
461 Level monthLevel = timeDim.createLevel();
462 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.
980 AttributeProjection _ap = monthLevel.createAttributeProjection();
981 _ap.setName("Time Span");
982 _ap.setAttribute(timeTimeSpanAttr);
The next line creates a Hierarchy object and associates it with the Dimension.
526 Hierarchy calendarYearHier = timeDim.createHierarchy();
527 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.
204 Cube unitsCube = globalAW.createCube();
205 unitsCube.setName("UNITS_CUBE_AW");
A CubeDimRef associates a Dimension with a Cube. The program has an associateCubeDimensions method, which begins on line 1083, 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.
1087 CubeDimRef _cdr = unitsCube.createCubeDimRef();
1089 _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.
220 Measure units = unitsCube.createMeasure();
222 units.setName("UNITS_AW");
225 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.
1043 DimensionMapGroup _dmg = monthLevel.createSourceDimensionMapGroup();
1044 DimensionKeySourceExpression _key = _dmg.CreateKeyMap();
1048 SourceColumn _keycol = _key.CreateSourceColumn();
1049 _keycol.setColumn("GLOBAL.TIME_DIM.MONTH_ID");
1058 AttributeSourceExpression _attrMap = _dmg.CreateAttributeMap();
1059 _attrMap.setTargetObject(timeTimeSpanAttr);
1060 SourceColumn _attrCol = monthTS_attrMap.CreateSourceColumn();
1061 _attrCol.setColumn("GLOBAL.TIME_DIM.MONTH_TIMESPAN");
createHierarchyMap method, which begins on line 988, 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.
994 HierarchyLevelAssociation _hla = calendarHier.createHierarchyLevelAssociation();
995 _hla.setLevel(monthLevel);
997 DimensionMapGroup _dmg = _hla.createSourceDimensionMapGroup();
998 DimensionKeySourceExpression _dkse = _dmg.CreateKeyMap();
999 SourceColumn _levColumn = _dkse.CreateSourceColumn();
1000 _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.
1007 HierarchicalParentSourceExpression _hpse = _dmg.CreateParentMap();
1008 SourceColumn _hpsesc = _hpse.CreateSourceColumn();
1009 _hpsesc.setColumn("GLOBAL.TIME_DIM.QUARTER_ID");
createCubeMap method, which begins on line 1097, 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.
1100 CubeMapGroup _cmg = units.createSourceCubeMapGroup();
1105 CubeDimensionSourceExpression _cdse = _cmg.CreateKeyMap();
1106 _cdse.addLevel(monthLevel);
1114 SourceColumn _keycol = _cdse.CreateSourceColumn();
1115 _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.
1122 units.setAutoSolve("NO_AUTO_SOLVE");
1124 MeasureSourceExpression _measMap = _cmg.CreateAttributeMap();
1125 _measMap.setTargetObject(units);
1126 SourceColumn _meascol = _measMap.CreateSourceColumn();
1127 _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.
329 globalAW.Create(awConnection);
330 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, which begins on line 415, accomplishes those tasks. The following lines are from that method. The curInteraction object is a class variable declared on line 75.
418 curInteraction = new Interaction();
421 curInteraction.setConnection(awConnection);
424 BuildDatabase myBuild =
425 (BuildDatabase)curInteraction.createAction("BUILDDATABASE");
428 myBuild.setAWName(awName);
434 myBuild.Execute();
Finally, the program closes the connection to the database.
408 awConnection.close();