将使用 WSCallHelper 接口的应用程序迁移到 Liberty
WebSphere® Application Server 传统版中使用的 WSCallHelper 接口必须迁移到 Java™ 数据库连接 (JDBC) 包装程序模式,这样应用程序才能在 Liberty 中工作。在 WebSphere Application Server Liberty 中,未提供 WebSphere Application Server 7.0 中弃用的 WSCallHelper API。
关于此任务
在 WebSphere Application Server 传统版中,应用程序使用 WSCallHelper 接口来访问特定于供应商的非标准 JDBC API。对于 Liberty,请使用 JDBC 包装程序模式,这是更加标准且基于 JDBC 规范的方法。包装程序模式使 JDBC 程序员能够实现 Wrapper 接口,以便在应用程序服务器受管环境中安全地访问特定于供应商的 JDBC API。要让包装程序模式工作,JDBC 驱动程序必须与 JDBC 4.0 或更新规范级别相符。要确定 JDBC 规范级别,请咨询驱动程序供应商。
过程
实现 Wrapper 接口 isWrapperFor 和 unwrap 方法,以访问特定于供应商的 JDBC API。
下列示例说明如何使用 JDBC 包装程序模式来获取本机 Oracle 连接或本机 Oracle PreparedStatement 对象,以调用特定于供应商的非标准方法。
- 获取 oracle.jdbc.OracleConnection 对象。
Context ic = new InitialContext(); DataSource ds = (DataSource)ic.lookup("jdbc/OracleDS"); Connection conn = ds.getConnection(); if (conn.isWrapperFor(oracle.jdbc.OracleConnection.class)) { oracle.jdbc.OracleConnection oraCon = conn.unwrap(oracle.jdbc.OracleConnection.class); // Do some vendor-specific work here. } conn.close();
- 获取 oracle.jdbc.OraclePreparedStatement 对象。
Context ic = new InitialContext(); DataSource ds = (DataSource)ic.lookup("jdbc/OracleDS"); Connection conn = ds.getConnection(); PreparedStatement pstmt = conn.prepareStatement("SELECT 1 FROM DUAL"); if(pstmt.isWrapperFor(oracle.jdbc.OraclePreparedStatement.class)){ oracle.jdbc.OraclePreparedStatement opstmt = pstmt.unwrap(oracle.jdbc.OraclePreparedStatement.class); // Do some vendor-specific work here. } pstmt.close(); conn.close();