680 DB2 Cube Views: A Primer
db2mdapiclient utility
This utility is a thin wrapper to the DB2 Cube Views stored procedure interface.
The utility is provided as sample source code to show how to code an application
against the API.
Location
The source code, db2mdapiclient.cpp is located in \SQLLIB\samples\olap\client\
directory on Windows (/home/db2inst1/sqllib/samples/olap/client on AIX).
Tasks
You can use the db2mdapiclient utility to perform any of the operations that are
supported by the DB2 Cube Views stored procedure, md_message() as
described in Table D-1
Table D-1 db2mdapiclient utility tasks
Usage
The db2mdapiclient utility uses files to hold the XML that is passed to and
received from the md_message() stored procedure (see Figure D-4).
Figure D-4 How the db2mdapiclient utility works
Task Operation
Export metadata (to an XML file) describe
Import metadata (from an XML file) create, import
Change metadata alter, rename
Delete metadata drop
Verify validity of existing metadata validate
md_message()
Stored procedure
API
Metadata
in
DB2 Sytem
catalog
db2mdapiclient
Appendix D. DB2 Cube Views stored procedure API 681
For example, while importing metadata in to the DB2 Cube Views metadata
catalog, the db2mdapiclient utility typically uses an XML file that was produced
by a DB2 Cube Views bridge or an XML file that was exported from the OLAP
Center. For exporting, the db2mdapiclient utility produces an XML file that a DB2
Cube Views bridge utility can use to add metadata to a database or OLAP tool.
To see a list of parameters for the db2mdapiclient command, you can enter
‘db2mdapiclient’ at a command line (on both Windows and AIX) as shown in
Figure D-5.
Figure D-5 Usage of the db2mdapiclient utility
The typical syntax for the db2mdapiclient command is:
db2mdapiclient -d dbname -u user -p password -i request.xml -o response.xml
-m inputmetadata.xml -n outputmetadata.xml
USAGE:
db2mdapiclient [OPTIONS]
Options can be specified in any order
REQUIRED OPTIONS:
-d or --database database name
-i or --inputoperation input operation file name
-o or --outputoperation output operation file name
OTHER OPTIONS:
-u or --userid userid for database
-p or --password password for database
-m or --inputmetadata input metadata file name. Required for
operations such as "create" & "import"
-n or --outputmetadata output metadata file name. If output
metadata file is not specified & there
is metadata returned by stored procedure
then output metadata will be written to
outputmetadata.xml
-a or --parameterbuffersize parameter buffer size, defaults to
1000000 bytes
-b or --metadatabuffersize metadata buffer size, defaults to
1000000 bytes
-v or --verbose print extra information while
processing
-h or --help this usage text
682 DB2 Cube Views: A Primer
Examples
To further illustrate the usage, we will look an import /export and validate
scenarios, using the db2mdapiclient utility.
1. Import
To import DB2 Cube Views metadata for a database (say SAMPLE), change to
the ..\SQLLIB\samples\olap\xml\input directory (on Windows) and enter the
command shown in Example D-3
Example: D-3 Using db2mdapiclient utility to import metadata
db2mdapiclient -d SAMPLE -u db2admin -p mypasswrd -i create.xml -o
myresponse.xml -m MDSampleMetadata.xml
Here, create.xml, MDSampleMetadata.xml and myresponse.xml are the values
of the arguments of the md_message(request, metadata, response) stored
procedure. That is, create.xml provides the request, MDSampleMetadata.xml is
the metadata(input) and myresponse.xml is the response(status).
2. Export
To export DB2 Cube Views metadata for a database (say SAMPLE), change to
the ..\SQLLIB\samples\olap\xml\input directory (on Windows) and enter the
command shown in Example D-4
Example: D-4 Using db2mdapiclient utility to export metadata
db2mdapiclient -d SAMPLE -u db2admin -p mypasswrd -i describe.xml -o
MyOutput.xml -n SampleOut.xml
Here, describe.xml is the request, SampleOut.xml is the exported metadata
(output) and MyOutput.xml contains the response (status).
3. Validate
To validate DB2 Cube Views metadata for a database (say SAMPLE), change to
the ..\SQLLIB\samples\olap\xml\input directory (on Windows) and enter the
command shown in Example D-5
Example: D-5 Using db2mdapiclient utility to validate metadata
db2mdapiclient -d SAMPLE -u db2admin -p mypasswrd -i validate.xml -o
validateout.xml -v
The default structure of the validate.xml allows validation all metadata objects in
the DB2 catalog for optimization (which is, checking for conformance to base
rules, cube completeness rules and optimization rules).
Appendix D. DB2 Cube Views stored procedure API 683
If you wish to check validity of a particular cube model for completeness, then the
structure of the validate.xml will have to be changed (shown in Example D-6) to
accommodate the restrictions.
Example: D-6 Validate.xml
<olap:request xmlns:olap="http://www.ibm.com/olap"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="8.1.2.1.0">
<validate objectType="cubeModel" mode="cubeModel completeness">
<restriction>
<predicate property="name" operator="=" value="Sales Cube Model"/>
</restriction>
</validate>
</olap:request>
684 DB2 Cube Views: A Primer

Get DB2 Cube Views: A Primer now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.