The WebSphere Application Server 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.
You can achieve application portability through the following:
In addition, the interface also provides a GenericDataStoreHelper class for unsupported data sources to use. You 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); ... } }
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);
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.
XMLType poXML = XMLType.createXML(conn, poString);
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 WebSphere Application Server 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.
Related concepts
Resource adapter
JDBC providers
Data sources