public class DB2DataStoreHelper extends GenericDataStoreHelper
DB2DataStoreHelper is a DataStoreHelper implementation
customized for the DB2 legacy CLI-based JDBC driver.
When mapping a SQLException, the SQLException mappings from the
DB2DataStoreHelper are searched first; subsequently, if no match is
found, the SQLException mappings from the GenericDataStoreHelper
are searched.
If you have additional requirements on DB2, consider subclassing this
implementation.
SQLException mappings specific to the DB2DataStoreHelper
are the following:
| Error Code | SQL State | PortableSQLException subclass |
|---|---|---|
| -30108 | StaleConnectionException.class | |
| -30081 | StaleConnectionException.class | |
| -30080 | StaleConnectionException.class | |
| -6036 | StaleConnectionException.class | |
| -1229 | StaleConnectionException.class | |
| -1224 | StaleConnectionException.class | |
| -1035 | StaleConnectionException.class | |
| -1034 | StaleConnectionException.class | |
| -1015 | StaleConnectionException.class | |
| -924 | StaleConnectionException.class | |
| -923 | StaleConnectionException.class | |
| -906 | StaleConnectionException.class | |
| -803 | DuplicateKeyException.class | |
| -518 | StaleConnectionException.class | |
| -514 | StaleConnectionException.class | |
| 58004 | StaleConnectionException.class | |
| S1000 | Void.class |
| Modifier and Type | Field and Description |
|---|---|
protected static com.ibm.ejs.ras.TraceComponent |
db2Tc |
customDefinedWasDefaultIsoLevel, defaultQueryTimeout, EOLN, genErrorMap, resBundle, tranErrorListCLOUDSCAPE_HELPER, CLOUDSCAPE_NETWORK_SERVER_HELPER, CONNECTJDBC_HELPER, CUSTOM_HELPER, DATADIRECT_HELPER, DB2_390_HELPER, DB2_390_LOCAL_HELPER, DB2_400_HELPER, DB2_HELPER, DB2_UNIVERSAL_HELPER, DERBY_HELPER, DERBY_NETWORK_SERVER_HELPER, FIRST_TIME_CALLED, GENERIC_HELPER, INFORMIX_HELPER, INFORMIX_JCC_HELPER, MSSQL_HELPER, ORACLE_10G_HELPER, ORACLE_11G_HELPER, ORACLE_HELPER, POTENTIAL_DEADLOCK, POTENTIAL_LOST_UPDATE, PROXY_DS_HELPER, SEQUELINK_HELPER, SUBJECT, SYBASE_HELPER, SYBASE11_HELPER, TX_REPEATABLE_READ_FORUPDATE, TX_SERIALIZABLE_FORUPDATE, UNDEFINED_HELPER, UNDEFINED_ISOLATOIN_LEVEL, UPDATE_ON_READONLY| Constructor and Description |
|---|
DB2DataStoreHelper(java.util.Properties props)
This
DB2DataStoreHelper constructor creates a new
DB2DataStoreHelper based on the DataStoreHelper
properties provided. |
| Modifier and Type | Method and Description |
|---|---|
void |
doConnectionSetup(java.sql.Connection conn)
This method configures a connection before first use.
|
void |
doStatementCleanup(java.sql.PreparedStatement stmt)
This method cleans up a statement before the statement is returned to the statement
cache.
|
java.lang.Class |
findMappingClass(java.sql.SQLException e)
This method locates the
com.ibm.websphere.ce.cm.PortableSQLException
subclass corresponding to the specified SQLException, as defined by the
DB2DataStoreHelper, GenericDataStoreHelper, and
user-defined SQLException maps. |
int |
getIsolationLevel(AccessIntent aIntent)
This method determines the transaction isolation level based on the specified
AccessIntent. |
int |
getLockType(AccessIntent intent)
This method returns a lock type constant based on the update hint value of the
specified AccessIntent.
|
java.io.PrintWriter |
getPrintWriter()
This method is used to obtain the
java.io.PrintWriter to use for logging
when database logging is enabled (for example: WAS.database=all=enabled). |
int |
getResultSetConcurrency(AccessIntent intent)
This method determines the result set concurrency based on the specified
AccessIntent. |
java.lang.String |
getXAExceptionContents(javax.transaction.xa.XAException x)
This method provides a plug-in point for providing meaningful logging information for an
XAException. |
boolean |
isBatchUpdateSupportedWithAccessIntent(AccessIntent accessIntent)
This method is used to determine if CMP Entity Beans can support batch updates with the
given AccessIntent.
|
void |
setUserDefinedMap(java.util.Map newmap)
This method configures a user-defined
SQLException map that supersedes
default SQLException mappings for the DataStoreHelper. |
java.lang.String |
showLockInfo(java.util.Properties props)
This method returns DB2 lock information needed for the RAS subsystem.
|
calcPartitionNumber, doConnectionCleanup, doConnectionCleanupPerCloseConnection, doConnectionCleanupWithValidCheck, doConnectionSetupPerGetConnection, doConnectionSetupPerTransaction, getMetaData, getPasswordForUseWithTrustedContextWithAuthentication, getResultSetType, hasLostUpdateOrDeadLockOccurred, isConnectionError, isDuplicateKey, isTransientConnectionError, mapException, modifyXAFlag, setConfigpublic DB2DataStoreHelper(java.util.Properties props)
DB2DataStoreHelper constructor creates a new
DB2DataStoreHelper based on the DataStoreHelper
properties provided. All implementations inheriting from a data store helper
must supply this same list of properties to their super class by invoking the
constructor of their super class with the list of properties.props - DataStoreHelper properties.public void doConnectionSetup(java.sql.Connection conn)
throws java.sql.SQLException
This method configures a connection before first use. This method is invoked only when a new connection to the database is created. It is not invoked when connections are reused from the connection pool.
This class will set a variable db2ZOS to FALSE as default value. This method
sets to TRUE if the backend system is zOS.
GenericDataStoreHelper does not perform any connection setup.
doConnectionSetup in interface DataStoreHelperdoConnectionSetup in class GenericDataStoreHelperconn - the connection to set up.java.sql.SQLException - if connection setup cannot be completed successfully.public void doStatementCleanup(java.sql.PreparedStatement stmt)
throws java.sql.SQLException
This method cleans up a statement before the statement is returned to the statement cache. This method is called only for statements being cached. It is called when at least one of the following statement properties has changed,
DB2DataStoreHelper resets all of the statement properties listed above
except for the cursorName property.
The following operations do not need to be included in the statement cleanup since they are automatically performed by WebSphere when caching statements:
setFetchSize(0)clearParameters()clearWarnings()A helper class implementing this method can choose to do additional cleanup for the statement. However, this must never include closing the statement, since the statement is intended to be cached.
doStatementCleanup in interface DataStoreHelperdoStatementCleanup in class GenericDataStoreHelperstmt - the PreparedStatement.java.sql.SQLException - if an error occurs cleaning up the statement.public final java.lang.Class findMappingClass(java.sql.SQLException e)
This method locates the com.ibm.websphere.ce.cm.PortableSQLException
subclass corresponding to the specified SQLException, as defined by the
DB2DataStoreHelper, GenericDataStoreHelper, and
user-defined SQLException maps. Precedence and related details of
SQLException mapping are described on the
DataStoreHelper.setUserDefinedMap method.
Overriding this method is one of three options you have for modifying
SQLException mapping. The other two options are overriding the
mapException method and invoking the setUserDefinedMap
method to add a user-defined SQLException map.
findMappingClass in class GenericDataStoreHelpere - The SQLException for which to locate a
com.ibm.websphere.ce.cm.PortableSQLException subclass.com.ibm.websphere.ce.cm.PortableSQLException subclass matching
the SQLException, or null if no match was found.SQLException,
PortableSQLExceptionpublic int getIsolationLevel(AccessIntent aIntent) throws javax.resource.ResourceException
AccessIntent.
If the AccessIntent parameter is null, a default value is returned
that is appropriate for the database backend. The default transaction isolation level
for DB2DataStoreHelper is
Connection.TRANSACTION_REPEATABLE_READ.
In the case where an AccessIntent is specified,
DB2DataStoreHelper computes the transaction isolation level as follows:
If the concurrency control is
AccessIntent.CONCURRENCY_CONTROL_OPTIMISTIC, a transaction isolation
level of Connection.TRANSACTION_READ_COMMITTED is returned.
If the concurrency control is
AccessIntent.CONCURRENCY_CONTROL_PESSIMISTIC and the access type is
AccessIntent.ACCESS_TYPE_READ, a transaction isolation level of
Connection.TRANSACTION_REPEATABLE_READ is returned.
If the concurrency control is
AccessIntent.CONCURRENCY_CONTROL_PESSIMISTIC and the access type is
AccessIntent.ACCESS_TYPE_UPDATE, the transation isolation level is
determined from the following table based on the pessimistic update lock hint.
| pessimistic update lock hint | transaction isolation level |
|---|---|
AccessIntent.PESSIMISTIC_UPDATE_LOCK_HINT_NONEAccessIntent.PESSIMISTIC_UPDATE_LOCK_HINT_WEAKEST_LOCK_AT_LOAD |
Connection.TRANSACTION_REPEATABLE_READ |
AccessIntent.PESSIMISTIC_UPDATE_LOCK_HINT_NOCOLLISION |
Connection.TRANSACTION_READ_COMMITTED |
AccessIntent.PESSIMISTIC_UPDATE_LOCK_HINT_EXCLUSIVE |
Connection.TRANSACTION_SERIALIZABLE |
getIsolationLevel in interface DataStoreHelpergetIsolationLevel in class GenericDataStoreHelperintent - An AccessIntentAccessIntent.javax.resource.ResourceException - If a transaction isolation level cannot be determined
from the AccessIntent.AccessIntent,
Connectionpublic int getResultSetConcurrency(AccessIntent intent) throws javax.resource.ResourceException
AccessIntent.
DB2DataStoreHelper always returns
java.sql.ResultSet.CONCUR_READ_ONLY.getResultSetConcurrency in interface DataStoreHelpergetResultSetConcurrency in class GenericDataStoreHelperintent - An AccessIntent.java.sql.ResultSet.javax.resource.ResourceException - If a result set concurrency cannot be determined
from the AccessIntent.AccessIntent,
ResultSetpublic final java.lang.String showLockInfo(java.util.Properties props)
throws java.lang.Exception
This method returns DB2 lock information needed for the RAS subsystem. The
props parameter can include the following properties:
showLockInfo in class GenericDataStoreHelperprops - properties containing information needed to connect to the database.java.lang.Exception - if an error occurs while collecting the lock information.public final void setUserDefinedMap(java.util.Map newmap)
This method configures a user-defined SQLException map that supersedes
default SQLException mappings for the DataStoreHelper. The
DataStoreHelper implementations provided by WebSphere use
SQLException maps to detect fatal connection errors, as well as other
specific types of connection errors. A custom DataStoreHelper can alter
the default mappings by invoking this method. Invoke this method only from
DataStoreHelper classes subclassing this class. Do not invoke
this method directly from application code. Internal WebSphere code does
not invoke this method.
Example usage of the setUserDefinedMap method:
public MyCustomDataStoreHelper()
{
...
java.util.HashMap MyErrorMap = new java.util.HashMap(2);
myErrorMap.put(new Integer(-801), MyDuplicateKeyException.class);
myErrorMap.put(new Integer(-1015), MyStaleConnectionException.class);
setUserDefinedMap(myErrorMap);
...
}
User-defined exception mapping takes priority over all other exception mapping done
by a DataStoreHelper. This differs from the WAS 4.0 DataSource model where mapping by
Error Code always takes precedence over mapping by SQL State.
For example, assume the following exception mappings are defined:
User-defined mappings: SQL State S1000 --> UserDefinedException Default mappings: Error Code 23505 --> DuplicateKeyException SQL State S1000 --> StaleConnectionException
Given the above mappings, if a SQLException is received with SQL State
S1000 and Error Code 23505, the WebSphere DataStoreHelper implementations
map the exception to UserDefinedException,
whereas the WAS 4.0 DataSource map the exception to DuplicateKeyException.
Additionally, mapping done by the WebSphere DataStoreHelpers does not
include mapping by chained exceptions when no match is found for the original exception.
setUserDefinedMap in interface DataStoreHelpersetUserDefinedMap in class GenericDataStoreHelpernewmap - a mapping of SQLException SQL States and Error Codes to
com.ibm.websphere.ce.cm.PortableSQLException subclasses.
The key for the Map must be a String (representing the SQL State) or
an Integer (representing the Error Code). The value for the Map must
be a subclass of com.ibm.websphere.ce.cm.PortableSQLException.
User-defined subclasses are permitted, but are required to declare a public
constructor accepting a SQLException as the single parameter.
You can also use Void.class for the value, in which case any
existing mapping for the specified SQL State or Error Code is removed.SQLException,
PortableSQLExceptionpublic java.io.PrintWriter getPrintWriter()
java.io.PrintWriter to use for logging
when database logging is enabled (for example: WAS.database=all=enabled).
By default, null is returned and a java.io.PrintWriter instance created
by WebSphere is used. You can override this method to return a different
java.io.PrintWriter instance instead of the default.getPrintWriter in interface DataStoreHelpergetPrintWriter in class GenericDataStoreHelperjava.io.PrintWriter.public boolean isBatchUpdateSupportedWithAccessIntent(AccessIntent accessIntent)
DB2DataStoreHelper returns false if the concurrency control of the
AccessIntent is AccessIntent.CONCURRENCY_CONTROL_OPTIMISTIC,
and otherwise returns true.isBatchUpdateSupportedWithAccessIntent in interface DataStoreHelperisBatchUpdateSupportedWithAccessIntent in class GenericDataStoreHelperaccessIntent - AccessIntentAccessIntentpublic int getLockType(AccessIntent intent)
This method returns a lock type constant based on the update hint value of the
specified AccessIntent.
The lock type is used by the persistence manager to determine which locking hints
should be used on a SELECT statement.
getLockType in interface DataStoreHelpergetLockType in class GenericDataStoreHelperintent - An AccessIntentcom.ibm.websphere.rsadaper.WSInteractionSpec:
LOCKTYPE_SELECT
LOCKTYPE_SELECT_FOR_UPDATE
LOCKTYPE_SELECT_FOR_UPDATE_WITH_RS
LOCKTYPE_SELECT_FOR_UPDATE_WITH_RR
AccessIntent,
WSInteractionSpecpublic java.lang.String getXAExceptionContents(javax.transaction.xa.XAException x)
XAException. The information can include details of the original
exception that caused the XAException, if applicable.
WebSphere uses this method to obtain trace information for
XAExceptions to include in WebSphere trace.getXAExceptionContents in interface DataStoreHelpergetXAExceptionContents in class GenericDataStoreHelperxae - the XAException.XAException, for inclusion in
a WebSphere trace.XAException