Data access portability features

The WAS relational resource adapter (RRA) provides a portability feature that enables applications to access data from different databases without changing the application. In addition, WebSphere Application Server enables you to plug in a data source that is not supported by WebSphere persistence. However, the data source must be implemented as either the XADataSource type or the ConnectionPoolDataSource type, and it must be in compliance with the JDBC 2.x specification.

We can achieve application portability through the following:

DataStoreHelper interface

With this interface, each data store platform can plug in its own private data store specific functions that the relational resource adapter run time uses. WAS provides an implementation for each supported JDBC provider.

In addition, the interface also provides a GenericDataStoreHelper class for unsupported data sources to use. We can subclass the GenericDataStoreHelper class or other WebSphere provided helpers to support any new data source.

Note: If you are configuring data access through a user-defined JDBC provider, do not implement the DataStoreHelper interface directly. Either subclass the GenericDataStoreHelper class or subclass one of the DataStoreHelper implementation classes provided by IBM (if your database behavior or SQL syntax is similar to one of these provided classes).

For more information, see the API documentation DataStoreHelper topic (as listed in the API documentation index).

The following code segment shows how a new data store helper is created to add new error mappings for an unsupported data source.

public class NewDSHelper extends GenericDataStoreHelper
{
  public NewDSHelper(java.util.Properties dataStoreHelperProperties)   
  {
    super(dataStoreHelperProperties); 
    java.util.Hashtable myErrorMap = null;
    myErrorMap = new java.util.Hashtable();
    myErrorMap.put(new Integer(-803), myDuplicateKeyException.class);
    myErrorMap.put(new Integer(-1015), myStaleConnectionException.class);
    myErrorMap.put("S1000", MyTableNotFoundException.class);
    setUserDefinedMap(myErrorMap);
    ...
  }
}


WSCallHelper class

This class provides two methods that enable you to use vendor-specific methods and classes that do not conform to the standard JDBC APIs (and are not part of WAS extension packages).

  • jdbcCall() method

    By using the static jdbcCall() method, you can invoke vendor-specific, nonstandard JDBC methods on your JDBC objects. (For more information, see the API documentation WSCallHelper topic.) The following code segment illustrates using this method with a DB2 data source:

     
    Connection conn = ds.getConnection();
    // get connection attribute
    String connectionAttribute =(String) WSCallHelper.jdbcCall(DataSource.class, ds,
     "getConnectionAttribute", null, null);
    // setAutoClose to false
    WSCallHelper.jdbcCall(java.sql.Connection.class,
    conn, "setAutoClose",
    new Object[] { new Boolean(false)},
    new Class[] { boolean.class });
    // get data store helper
    DataStoreHelper dshelper = WSCallHelper.getDataStoreHelper(ds);
    
    
    

  • jdbcPass() method

    Use this method to exploit the nonstandard JDBC classes that some database vendors provide. These classes contain methods that require vendors' proprietary JDBC objects to be passed as parameters.

    In particular, implementations of Oracle can involve use of nonstandard classes furnished by the vendor. Methods contained within these classes include:

    oracle.sql.ArrayDescriptor ArrayDescriptor.createDescriptor(java.lang.String, java.sql.Connection)
    oracle.sql.ARRAY new ARRAY(oracle.sql.ArrayDescriptor, java.sql.Connection, java.lang.Object)
    oracle.xml.sql.query.OracleXMLQuery(java.sql.Connection, java.lang.String)
    oracle.sql.BLOB.createTemporary(java.sql.Connection, boolean, int)
    oracle.sql.CLOB.createTemporary(java.sql.Connection, boolean, int)
    oracle.xdb.XMLType.createXML(java.sql.Connection, java.lang.String)
    

    The following code examples demonstrate the difference between a call to the XMLType.createXML() method over a direct connection to Oracle, and a call to the same method within WebSphere Application Server.

    1. Over a direct connection

      XMLType poXML = XMLType.createXML(conn, poString);
      

    2. Within Application Server, using the jdbcPass() method

      XMLType poXML (XMLType)(WSCallHelper.jdbcPass(XMLType.class, 
      "createXML", new Object[]{conn,poString},
        new Class[]{java.sql.Connection.class, java.lang.String.class},
        new int[]{WSCallHelper.CONNECTION,WSCallHelper.IGNORE}));
      

    There are two different jdbcPass() methods available, one for use in invoking static methods, another for use when invoking non-static methods. See the API documentation WSCallHelper topic.

    Note: Because of the possible problems that can occur by passing an underlying object to a method, WebSphere Application Server strictly controls which methods are allowed to be invoked using the jdbcPass() method support. If you require support for a method that is not listed previously in this document, please contact WAS support with information on the method you require.

    WARNING: Use of the jdbcPass() method causes the JDBC object to be used outside of WebSphere's protective mechanisms. Performing certain operations (such as setting autoCommit, or transaction isolation settings, etc.) outside of these protective mechanisms will cause problems with the future use of these pooled connections. IBM does not guarantee stability of the object after invocation of this method; it is the user's responsibility to ensure that invocation of this method does not perform operations that harm the object. Use at your own risk.

 

See also


Example: Developing your own DataStoreHelper class

 

See Also


Resource adapter
JDBC providers
Data sources