The DataStoreHelper interface supports each data store platform plugging in its own private data store specific functions that are used by the Relational Resource Adapter run time.
package com.ibm.websphere.examples.adapter;
import java.sql.SQLException;
import javax.resource.ResourceException;
import com.ibm.websphere.appprofile.accessintent.AccessIntent;
import com.ibm.websphere.ce.cm.*;
import com.ibm.websphere.rsadapter.WSInteractionSpec;
/**
* Example DataStoreHelper class, demonstrating how to create a user-defined DataStoreHelper.
* Implementation for each method is provided only as an example. More detail would likely be * required for any custom DataStoreHelper created for use by a real application.
*/
public class ExampleDataStoreHelper extends com.ibm.websphere.rsadapter.GenericDataStoreHelper {
static final long serialVersionUID = 8788931090149908285L;
public ExampleDataStoreHelper(java.util.Properties props)
{
super(props);
// Update the DataStoreHelperMetaData values for this helper.
getMetaData().setGetTypeMapSupport(false);
// Update the exception mappings for this helper.
java.util.Map xMap = new java.util.HashMap();
// Add an Error Code mapping to StaleConnectionException.
xMap.put(new Integer(2310), StaleConnectionException.class);
// Add an Error Code mapping to DuplicateKeyException.
xMap.put(new Integer(1062), DuplicateKeyException.class);
// Add a SQL State mapping to the user-defined ColumnNotFoundException xMap.put("S0022", ColumnNotFoundException.class);
// Undo an inherited StaleConnection SQL State mapping.
xMap.put("S1000", Void.class);
setUserDefinedMap(xMap);
// Note: If you are extending a helper class, it is
// normally not necessary to issue 'getMetaData().setHelperType(...)'
// because your custom helper will inherit the helper type from its // parent class. However, certain applications may need to differentiate // between a custom helper and an existing helper of the same type,
// so WebSpehere has provided the value 'DataStoreHelper.CUSTOM_HELPER'
// for this purpose. If this functionality is needed by your application // insert the following line into your code:
// getMetaData().setHelperType(DataStoreHelper.CUSTOM_HELPER);
}
public void doStatementCleanup(java.sql.PreparedStatement stmt) throws SQLException {
// Clean up the statement so it may be cached and reused.
stmt.setCursorName("");
stmt.setEscapeProcessing(true);
stmt.setFetchDirection(java.sql.ResultSet.FETCH_FORWARD);
stmt.setMaxFieldSize(0);
stmt.setMaxRows(0);
stmt.setQueryTimeout(0);
}
public int getIsolationLevel(AccessIntent intent) throws ResourceException {
// Determine an isolation level based on the AccessIntent.
if (intent == null) return java.sql.Connection.TRANSACTION_SERIALIZABLE;
return intent.getConcurrencyControl() == AccessIntent.CONCURRENCY_CONTROL_OPTIMISTIC ?
java.sql.Connection.TRANSACTION_READ_COMMITTED :
java.sql.Connection.TRANSACTION_REPEATABLE_READ;
}
public int getLockType(AccessIntent intent) {
if ( intent.getConcurrencyControl() == AccessIntent.CONCURRENCY_CONTROL_PESSIMISTIC) {
if ( intent.getAccessType() == AccessIntent.ACCESS_TYPE_READ ) {
return WSInteractionSpec.LOCKTYPE_SELECT;
}
else {
return WSInteractionSpec.LOCKTYPE_SELECT_FOR_UPDATE;
}
}
return WSInteractionSpec.LOCKTYPE_SELECT;
}
public int getResultSetConcurrency(AccessIntent intent) throws ResourceException {
// Determine a ResultSet concurrency based on the AccessIntent.
return intent == null || intent.getAccessType() == AccessIntent.ACCESS_TYPE_READ ?
java.sql.ResultSet.CONCUR_READ_ONLY :
java.sql.ResultSet.CONCUR_UPDATABLE;
}
public int getResultSetType(AccessIntent intent) throws ResourceException {
// Determine a ResultSet type based on the AccessIntent.
if (intent == null) return java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE;
return intent.getCollectionAccess() == AccessIntent.COLLECTION_ACCESS_SERIAL ?
java.sql.ResultSet.TYPE_FORWARD_ONLY :
java.sql.ResultSet.TYPE_SCROLL_SENSITIVE;
}
}
ColumnNotFoundException
package com.ibm.websphere.examples.adapter;
import java.sql.SQLException;
import com.ibm.websphere.ce.cm.PortableSQLException;
/**
* Example PortableSQLException subclass, which demonstrates how to create a user-defined * exception for exception mapping.
*/
public class ColumnNotFoundException extends PortableSQLException {
public ColumnNotFoundException(SQLException sqlX)
{
super(sqlX);
}
}
Related concepts
Resource adapter