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 or the ConnectionPoolDataSource, 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 or other WebSphere provided helpers to support any new data source.
For more information, see the Javadoc DataStoreHelper in the Javadoc index.
The following code segment shows how a new data store helper is created to add two new error mappings for an unsupported data source.
public class NewDSHelper extends GenericDataStoreHelper { public NewDSHelper() { super(null); java.util.Hashtable myErrorMap = null; myErrorMap = new java.util.Hashtable(2); myErrorMap.put(new Integer(-803), myDuplicateKeyException.class); myErrorMap.put(new Integer(-1015), myStaleConnectionException.class); myErrorMap.put("S1000", MyTableNotFoundException.class); setUserDefinedMap(myErrorMap); ... } }
All methods are static: see Javadoc WSCallHelper in the Javadoc index.
The following code segment illustrates using this helper class (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);