科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道教你如何构建DB2 Cube View元数据桥

教你如何构建DB2 Cube View元数据桥

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

对于许多OLAP工具和应用程序,与DB2 Cube View整合需要构建一个元数据桥。 这个桥可以使用DB2 Cube View的基于XML的存储过程接口读取或者创建元数据。

作者:赛迪网 来源:赛迪网 2007年9月3日

关键字: 数据库 DB2 DB2 Cube View 元数据

  • 评论
  • 分享微博
  • 分享邮件
 

分析XML

为了使用应用程序接口,你的程序必须构造传入存储过程的XML文档。你还将需要分析存储过程返回的XML。

DB2 Cube View应用程序接口使用的XML的语法由XSD模式文件指定,XSD模式文件在sqllib/cfg目录。你将使用的XSD模式文件如表1所示。

表⒈与输入和输出参数相联系的XSD文件

应用程序接口参数                模式文件 
Operations and responses        db2md_parameter.xsd 
(first and third arguments) 
Metadata (second argument)      db2md_metadata.xsd anddb2md_types.xsd

使用应用程序接口

用于调用md_message()存储过程的例程C++代码在sqllib/samples/olap/client/DB2mdapiclient.cpp的DB2 Cube View产品中。

如果你是使用Java编写程序,那么这里给出使用JDBC调用存储过程的样例代码段:

/* 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;
}
    • 评论
    • 分享微博
    • 分享邮件
    邮件订阅

    如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

    重磅专题
    往期文章
    最新文章