在你有一些成功地调用API的代码之后,你需要把注意力集中在传送正确的XML到应用程序接口中,并且能够分析输出的XML。
大部分的程序将需要使用DESCRIBE操作从DB2 Cube View中读取元数据。这里是一些例子:
例子⒈读取所有的元数据
这里是操作你将使用的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">;
<describe objectType="all" recurse="no">;
</describe>;
</olap:request>;
注意:
· 调用程序和服务器上的DB2存储过程的版本号(比如8.1.2.1.0)必须一致。
· 注意请求标记应该是<olap:request>;。
第二个参数将返回包含元数据的一个CLOB。通常,许多对象被返回。如果DB2只有一个Attribute对象,那么输出元数据XML看起来象如下所示:
<olap:metadata 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">;
<attribute name="FAMILY" schema="MDSAMPLE" businessName="FAMILY"
createTime="2003-04-11T21:28:22" creator="db2admin">;
<datatype schema="SYSIBM" name="VARCHAR" length="15" scale="0"/>;
<sqlExpression template="{$$1}">;
<column name="FAMILY" tableSchema="MDSAMPLE" tableName="FAMILY"/>;
</sqlExpression>;
</attribute>;
</olap:metadata>;
如果成功的话,响应文档就会看起来象这样:
<olap:response 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">;
<describe>;
<status id="0" text="Operation completed successfully. No errors were encountered."
type="informational"/>;
</describe>;
</olap:response>;
例子⒉取得一个指定的Cube模型和关联对象。
下面是你想用来为db2admin.MyCubeModel取得cube模型和它的相关对象的操作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">;
<describe objectType="cubeModel" recurse="yes">;
<restriction>;
<predicate property="name" operator="=" value="MyCubeModel"/>;
<predicate property="schema" operator="=" value="db2admin"/>;
</restriction>;
</describe>;
</olap:request>;
注意:
· Recurse="yes"让应用程序接口返回Cube模型和所有Cube模型递归调用的对象。
· 注意使用一个指定我们感兴趣的Cube模型的谓词。
创建元数据
有两个操作用于新建元数据:CREATE和IMPORT。当你新建元数据的时候使用CREATE。如果你想创建对象有可能和已有的对象冲突(因为名称相同),那么使用IMPORT。
例子:创建DB2 Cube View中的一些元数据对象
这里是你将使用的操作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">;
<create/>;
</olap:request>;
你将通过第二个参数把XML中的一个或多个元数据对象传到储存过程中。
修改元数据
有两个操作,ALTER和RENAME,用于修改元数据对象。
例子⒈修改一个连接对象
ALTER操作与CREATE相似,除了要传入的元数据对象必须已经存在之外。那些对象将要被新的定义替代。这里是你将使用的操作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">;
<alter/>;
</olap:request>;
对于元数据XML,当我们想要它变化的时候,传入Join对象:
<join name="ProductFamily" schema="db2admin" businessName="ProductFamily"
type="inner" cardinality="n:1">;
<attributeJoin operator="=">;
<leftAttributeRef name="FAMILYID" schema="db2admin"/>;
<rightAttributeRef name="FAMILYID (FAMILY)" schema="db2admin"/>;
</attributeJoin>;
</join>;
例子⒉为一个Cube模型对象改名
假设我们想把一个Cube模型对象从db2admin.SalesModel改名为db2admin.SalesModel(2003)。这里是实现这个操作的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">;
<rename objectType="cubeModel">;
<currentRef name="SalesModel" schema="db2admin"/>;
<newRef name="SalesModel (2003)" schema="db2admin"/>;
</rename>;
</olap:request>;
对于改名,你不需要元数据XML.
删除元数据
使用DROP操作来删除元数据对象。
例子1:删除所有的元数据对象
要小心这个操作!下面是我们要使用的操作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">;
<drop objectType="all"/>;
</olap:request>;
例子⒉删除一个cube对象和它的关联对象
这里是删除db2admin.MyCube和它的关联对象的操作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">;
<script>;
<drop objectType="cube">;
<restriction>;
<predicate property="name" operator="=" value="My Cube"/>;
<predicate property="schema" operator="=" value="db2admin"/>;
</restriction>;
</drop>;
<drop objectType="cubeFacts">;
<restriction>;
<predicate property="name" operator="=" value="Cube Facts (My Cube)"/>;
<predicate property="schema" operator="=" value="db2admin"/>;
</restriction>;
</drop>;
<drop objectType="cubeDimension">;<restriction>;
<predicate property="name" operator="=" value="Market (My Cube)"/>;
<predicate property="schema" operator="=" value="db2admin"/>;
</restriction>;</drop>;
<drop objectType="cubeHierarchy">;
<restriction>;<predicate property="name" operator="=" value="Region (My Cube)"/>;
<predicate property="schema" operator="=" value="db2admin"/>;
</restriction>;
</drop>;
</script>;
</olap:request>;
没有元数据XML需要被传入。
排除错误
存储过程中的大部分错误是非常不需加以说明的,虽然你必须习惯用于消息中引用的对象的命名约定。因此,你常常必须非常认真的读这个信息。
下面是一个报告错误的API响应。是当我们试图删除一个不存在的Cube对象(db2admin.My Cube)时返回的信息。(请注意:由于页面的限制,状态消息被分成两行显示。)
<olap:response 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">;
<drop>;
<status id="6006" text="No objects were found matching search criteria:
"objectType=CUBE & name=My Cube & schema=db2admin"." type="warning">;
<tokens>;
<text value="objectType=CUBE & name=My Cube & schema=db2admin"/>;
</tokens>;
</status>;
</drop>;
</olap:response>;