DBINFO.MD_MESSAGE(Operation IN, metadata IN/OUT, response OUT)
所有參數都屬于 CLOB 類型?! ≡摯鎯^程有兩個輸入參數。第一參數是必需的,它指定調用程序希望執行什么操作。這些操作有:DESCRIBE
CREATE
ALTER
RENAME
DROP
IMPORT
VALIDATE
某些操作(象 CREATE 和 IMPORT)需要通過第二個參數將元數據傳入這個存儲過程。操作 DESCRIBE 通過第二個參數返回元數據?! ≥敵鰠怠 ≡摯鎯^程的第三個參數是輸出參數。對于對該存儲過程的每個調用,都會通過第三個參數返回響應文檔。然而,假如發生某些嚴重錯誤,則不會創建任何輸出響應文檔?! 〗馕?XML 要使用 API,程序必須構造要傳入該存儲過程的 XML 文檔。還需要解析該存儲過程所返回的 XML?! B2 Cube Views API 使用的 XML 的語法由隨該產品一起提供的 XSD 模式文件(位于 sqllib/cfg 目錄中)指定。您將使用的 XSD 模式文件如 表 1所示?! ”?1. 與輸入和輸出參數相關聯的 XSD 文件API 參數 | 模式文件 |
操作和響應 ?。ǖ谝粋€和第三個參數) | db2md_parameter.xsd |
元數據(第二個參數) | db2md_metadata.xsd 和 db2md_types.xsd |
/* Calls the DB2 stored procedure passing in the request string
* as the first parameter and the metadata string as the second
* parameter. If xmlRequestString contains a script or no output
* metadata is required the xmlMetadata parameter may be null.
* The outputMetadata boolean controls what is returned by the
* method. If it is true any output metadata is returned. If
* false the response output is returned. */
private String callDB2StoredProc(String xmlRequestString,
String xmlMetadataString,
boolean outputMetadata)
throws OCException,
OCApiException
{
/* Create an SQL command to call the Stored procedure in DB2
* to get the XML */
String sql = "CALL db2info.MD_MESSAGE (?, ?, ?)";
String response = null;
String xmlMetadataResponse = null;
CallableStatement callStmt = null;
try
{
callStmt = auroraCatalogConnection.prepareCall(sql);
/* Set input parameter to request and metadata strings. */
callStmt.setString (1, xmlRequestString);
callStmt.setString (2, xmlMetadataString);
/* Register the output parameters. */
callStmt.registerOutParameter (2, Types.VARCHAR);
callStmt.registerOutParameter (3, Types.VARCHAR);
/* Call the stored procedure */
callStmt.execute();
/* Retrieve output parameters. If the procedure was called with
* a request that returns metadata in the middle parameter then
* xmlMetadataResponse will store the output XML. */
if (outputMetadata == true)
xmlMetadataResponse = callStmt.getString(2);
response = callStmt.getString(3);
/* See if there are any warnings. */
SQLWarning warning = callStmt.getWarnings();
/* If execute returns a warning with a non-zero SQL state
* then the API has had an error and returned some response
* info in the output XML document. */
if (warning != null)
{
OCLog.trace("Stored procedure execute returned a warning.");
OCLog.trace("SQL state: " + warning.getSQLState());
OCLog.trace("SQL state: " + warning.getErrorCode());
/* readResponseFromXML will throw an OCApiException containing
* the error info (which will then be thrown to our caller) or
* it will throw an OCException if a parsing error occurred. If
* for some strange reason the file does not contain error
* info it will just return and then we'll throw an OCException
* to notify the user. */
try { readResponseFromXML(response); }
/* If an API exception was thrown add the SQL state etc to
* it and then throw it again. */
catch (OCApiException apie)
{
apie.setSqlException(warning);
throw apie;
}
/* If we have had a warning we always want to rollback any changes.
* If we have a problem rolling back the exception will be caught
* below. */
finally
{
auroraCatalogConnection.rollback();
}
/* If we got here there must have been a warning with nothing
* in the output XML so throw an exception explaining this. */
throw new OCException("OC_ERR_API_DB2_STORED_PROC_FAIL_NO_INFO");
}
}
/* If we had an error executing the SQL, log the information and
* throw an exception. We also rollback any changes and catch
* the exception if the rollback has a problem. */
catch (SQLException e)
{
OCApiException newe = new OCApiException(e);
OCLog.trace( newe.getMessage() );
logExceptionInfo(e);
try { auroraCatalogConnection.rollback(); }
catch (SQLException e2)
{
OCLog.trace("An exception also occurred rolling back.");
logExceptionInfo(e2);
}
throw newe;
}
讀取元數據 在獲得成功調用該 API 的一些代碼之后,將需要把注重力放在將正確的 XML 傳遞給該 API,以及能夠解析輸出 XML?! 〈蠖鄶党绦驅⑿枰ㄟ^使用 DESCRIBE 操作來從 DB2 Cube Views 讀取元數據。下面是一些示例: 示例 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">
<describe objectType="all" recurse="no">
</describe>
</olap:request>
注: 調用程序和服務器上的 DB2 存儲過程之間的版本號(如 8.1.2.1.0)必須一致?! ≌堊⒅兀瑧搶⒄埱髽擞浵薅?<olap:request> ?! ≥敵鰰r,第二個參數將返回包含元數據的 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>
示例 2. 獲取特定的多維數據模型及相關對象 下面是您將用來獲取 db2admin.MyCubeModel 的多維數據模型及其相關對象的操作 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" 告訴 API 返回多維數據模型以及該多維數據模型遞歸引用的所有對象?! ≌堊⒅?,謂詞的運用,謂詞指定我們感愛好的多維數據模型。 創建元數據 有兩個用于創建新元數據的操作:CREATE 和 IMPORT。在創建新的元數據時,使用 CREATE。假如您想要創建的對象碰巧與現有對象沖突(因為名稱相同),則使用 IMPORT。 示例. 在 DB2 Cube Views 中創建一些元數據對象 下面是您要使用的操作 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。 示例 1. 改變連接對象 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>
示例 2. 重命名多維數據模型對象 假設我們想要將多維數據模型對象 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>
示例 2. 刪除多維數據對象及其相關對象 下面是刪除 db2admin.MyCube 及其相關對象的操作 XML。請注重,非凡的 <script> 標記,它可以在一次 API 調用中執行多次刪除:<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>
跟蹤 當發生錯誤而您又無法斷定 API 失敗的原因時,通常有必要打開 API 跟蹤。從高級別跟蹤(信息量最少)開始,僅當絕對需要時才打開中級或低級跟蹤(這些級別的信息要具體得多)?! ∫蜷_跟蹤,請修改配置文件 db2md_config.xml ,如下所示。每個 DB2 實例都有一個這樣的文件,可以在實例目錄中找到它。在 Windows 上,缺省的 DB2 實例名為“DB2”,可以在 sqllib/DB2/db2md_config.xml 中找到這個配置文件。在下面的 XML 中,已經將跟蹤級別設置為 high。<?xml version="1.0" encoding="UTF-8" ?>
<!-- <copyright> -->
<!-- Licensed Materials - Property of IBM -->
<!-- 5724-E15 -->
<!-- (c) Copyright IBM Corp. 2002, 2003 All Rights Reserved. -->
<!-- US Government Users Restricted Rights - Use, duplication or disclosure -->
<!-- restricted by GSA ADP Schedule Contract with IBM Corp. -->
<!-- </copyright> -->
<olap:config xmlns:olap="http://www.ibm.com/olap">
<log>
<trace level="
high" logFile="db2mdtrace.log" bufferSize="0"/>
<error level="medium" logFile="db2mderror.log" bufferSize="0"/>
</log>
</olap:config>
請注重:不要嘗試重命名跟蹤文件。其名稱必須是 db2mdtrace.log ??梢栽趯嵗夸浿姓业礁櫸募?db2mdtrace.log 。 創建元數據橋 元數據橋是將元數據從一種格式映射成另一種格式的軟件組件或實用程序。開發橋是為了在第三方商業智能或 OLAP 工具與 DB2 Cube Views 之間交換元數據。 圖 3. 元數據橋 特性 | 說明 |
模式 | 當映射到 DB2 Cube Views 時,所有新對象通常都被放入單個模式中。但答應多維數據視圖對象引用其它不同模式中的多維數據視圖對象。DB2 Cube Views 中每個對象的完整名稱由它的模式和名稱構成,如 MYSCHEMA.MYATTRIBUTE 。 模式的長度不超過 30 個字節。 |
名稱 | 每個 DB2 Cube Views 對象類型都有自己的名稱空間,除了 Attribute 和 Measure 共享同一個名稱空間。因此,例如,Attribute 和 Join 可以具有同一個完整名稱?! ≈?DB2 Cube Views 的橋通常必須生成一些目標對象的名稱?! ∶Q的長度不超過 128 個字節。 |
商業名稱 | 最多 128 個字節。 |
注釋 | 最多 254 個字節。 |
創建者 | 當映射到 DB2 Cube Views 時不需要。 |
創建時間 | 當映射到 DB2 Cube Views 時不需要。 |
修改者 | 當映射到 DB2 Cube Views 時不需要。 |
修改時間 | 當映射到 DB2 Cube Views 時不需要。 |
對象類型 | 映射說明 |
Attribute | SQL 表達式模板是映射過程中最難的特性,因為它通常需要對表達式進行解析。另外,始于 DB2 Cube Views 的橋需要處理引用其它 Attribute 的 Attribute,并以遞歸方式遍歷所有 Attribute 來確定給定 Attribute 的最終 SQL 表達式?! ‘斢成錇? Attribute 時,不需要數據類型特性;當創建該 Attribute 時,由 DB2 多維數據視圖確定它。 |
Join | 當映射到 DB2 Cube Views 時創建 Join 很重要,因為它們捕捉構建 Dimension 和 Cube Model 所需的結構信息。 |
Attribute Relationship | 屬于 Hierarchy 的一部分??稍谳^復雜的 Cube Model 中找到它。 |
Measure | 與 Attribute 的問題一樣(即 SQL 表達式模板的映射很難)。通常,橋對支持十分復雜的量方面有一些限制。 |
Facts | 一組具有相同維數的 Measure。請注重,需要映射可選的 Attribute 和 Join。 |
Dimension | 當創建 Dimension 時,請確保包括了所有的 Attribute。請注重,Hierarchy 和 Join 是可選的。 |
層次結構 | 請注重,Attribute 列表是經過排序的。還要注重,并不答應所有的類型和部署的組合。有時候,橋在可以映射的層次結構類型方面有一些限制。 |
Cube Model | 它是橋在通常的映射過程中的最高一層對象。假如完全可能的話,至 DB2 Cube Views 的橋應該創建 Cube Model 對象。 |
Cube(和 Cube Facts、Cube Dimension、Cube Hierarchy) | 被映射為 Cube Model 的一部分(假如它有意義的話)。 |
新聞熱點
疑難解答