Class DB2DataStoreHelper
- java.lang.Object
-
- com.ibm.websphere.rsadapter.GenericDataStoreHelper
-
- com.ibm.websphere.rsadapter.DB2DataStoreHelper
-
- All Implemented Interfaces:
- DataStoreHelper
- Direct Known Subclasses:
- DB2390DataStoreHelper, DB2AS400DataStoreHelper, DB2UniversalDataStoreHelper
public class DB2DataStoreHelper extends GenericDataStoreHelper
DB2DataStoreHelperis aDataStoreHelperimplementation customized for the DB2 legacy CLI-based JDBC driver. When mapping aSQLException, theSQLExceptionmappings from theDB2DataStoreHelperare searched first; subsequently, if no match is found, theSQLExceptionmappings from theGenericDataStoreHelperare searched. If you have additional requirements on DB2, consider subclassing this implementation.
Note: This class and its methods can not be called or referenced directly by user applications.SQLExceptionmappings specific to theDB2DataStoreHelperare the following:Error Code SQL State PortableSQLExceptionsubclass-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.class58004 StaleConnectionException.classS1000 Void.class
-
-
Field Summary
Fields Modifier and Type Field and Description protected static com.ibm.ejs.ras.TraceComponentdb2Tc-
Fields inherited from class com.ibm.websphere.rsadapter.GenericDataStoreHelper
customDefinedWasDefaultIsoLevel, defaultQueryTimeout, EOLN, genErrorMap, resBundle, tranErrorList
-
Fields inherited from interface com.ibm.websphere.rsadapter.DataStoreHelper
CLOUDSCAPE_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 Summary
Constructors Constructor and Description DB2DataStoreHelper(java.util.Properties props)ThisDB2DataStoreHelperconstructor creates a newDB2DataStoreHelperbased on theDataStoreHelperproperties provided.
-
Method Summary
Methods Modifier and Type Method and Description voiddoConnectionSetup(java.sql.Connection conn)This method configures a connection before first use.voiddoStatementCleanup(java.sql.PreparedStatement stmt)This method cleans up a statement before the statement is returned to the statement cache.java.lang.ClassfindMappingClass(java.sql.SQLException e)This method locates thecom.ibm.websphere.ce.cm.PortableSQLExceptionsubclass corresponding to the specifiedSQLException, as defined by theDB2DataStoreHelper,GenericDataStoreHelper, and user-definedSQLExceptionmaps.intgetIsolationLevel(AccessIntent aIntent)This method determines the transaction isolation level based on the specifiedAccessIntent.intgetLockType(AccessIntent intent)This method returns a lock type constant based on the update hint value of the specified AccessIntent.java.io.PrintWritergetPrintWriter()This method is used to obtain thejava.io.PrintWriterto use for logging when database logging is enabled (for example:WAS.database=all=enabled).intgetResultSetConcurrency(AccessIntent intent)This method determines the result set concurrency based on the specifiedAccessIntent.java.lang.StringgetXAExceptionContents(javax.transaction.xa.XAException x)This method provides a plug-in point for providing meaningful logging information for anXAException.booleanisBatchUpdateSupportedWithAccessIntent(AccessIntent accessIntent)This method is used to determine if CMP Entity Beans can support batch updates with the given AccessIntent.voidsetUserDefinedMap(java.util.Map newmap)This method configures a user-definedSQLExceptionmap that supersedes defaultSQLExceptionmappings for theDataStoreHelper.java.lang.StringshowLockInfo(java.util.Properties props)This method returns DB2 lock information needed for the RAS subsystem.-
Methods inherited from class com.ibm.websphere.rsadapter.GenericDataStoreHelper
calcPartitionNumber, doConnectionCleanup, doConnectionCleanupPerCloseConnection, doConnectionCleanupWithValidCheck, doConnectionSetupPerGetConnection, doConnectionSetupPerTransaction, getMetaData, getPasswordForUseWithTrustedContextWithAuthentication, getResultSetType, hasLostUpdateOrDeadLockOccurred, isConnectionError, isDuplicateKey, isTransientConnectionError, mapException, modifyXAFlag, setConfig
-
-
-
-
Constructor Detail
-
DB2DataStoreHelper
public DB2DataStoreHelper(java.util.Properties props)
ThisDB2DataStoreHelperconstructor creates a newDB2DataStoreHelperbased on theDataStoreHelperproperties 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.- Parameters:
props-DataStoreHelperproperties.
-
-
Method Detail
-
doConnectionSetup
public void doConnectionSetup(java.sql.Connection conn) throws java.sql.SQLExceptionThis 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
FALSEas default value. This method sets toTRUEif the backend system is zOS.GenericDataStoreHelperdoes not perform any connection setup.- Specified by:
doConnectionSetupin interfaceDataStoreHelper- Overrides:
doConnectionSetupin classGenericDataStoreHelper- Parameters:
conn- the connection to set up.- Throws:
java.sql.SQLException- if connection setup cannot be completed successfully.
-
doStatementCleanup
public void doStatementCleanup(java.sql.PreparedStatement stmt) throws java.sql.SQLExceptionThis 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,
- cursorName
- fetchDirection
- maxFieldSize
- maxRows
- queryTimeout
DB2DataStoreHelperresets all of the statement properties listed above except for thecursorNameproperty.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.
- Specified by:
doStatementCleanupin interfaceDataStoreHelper- Overrides:
doStatementCleanupin classGenericDataStoreHelper- Parameters:
stmt- the PreparedStatement.- Throws:
java.sql.SQLException- if an error occurs cleaning up the statement.
-
findMappingClass
public final java.lang.Class findMappingClass(java.sql.SQLException e)
This method locates the
com.ibm.websphere.ce.cm.PortableSQLExceptionsubclass corresponding to the specifiedSQLException, as defined by theDB2DataStoreHelper,GenericDataStoreHelper, and user-definedSQLExceptionmaps. Precedence and related details ofSQLExceptionmapping are described on theDataStoreHelper.setUserDefinedMapmethod.Overriding this method is one of three options you have for modifying
SQLExceptionmapping. The other two options are overriding themapExceptionmethod and invoking thesetUserDefinedMapmethod to add a user-definedSQLExceptionmap.- Overrides:
findMappingClassin classGenericDataStoreHelper- Parameters:
e- TheSQLExceptionfor which to locate acom.ibm.websphere.ce.cm.PortableSQLExceptionsubclass.- Returns:
- The
com.ibm.websphere.ce.cm.PortableSQLExceptionsubclass matching theSQLException, or null if no match was found. - See Also:
SQLException,PortableSQLException
-
getIsolationLevel
public int getIsolationLevel(AccessIntent aIntent) throws javax.resource.ResourceException
This method determines the transaction isolation level based on the specifiedAccessIntent. If theAccessIntentparameter is null, a default value is returned that is appropriate for the database backend. The default transaction isolation level forDB2DataStoreHelperisConnection.TRANSACTION_REPEATABLE_READ.In the case where an
AccessIntentis specified,DB2DataStoreHelpercomputes the transaction isolation level as follows:If the concurrency control is
AccessIntent.CONCURRENCY_CONTROL_OPTIMISTIC, a transaction isolation level ofConnection.TRANSACTION_READ_COMMITTEDis returned.If the concurrency control is
AccessIntent.CONCURRENCY_CONTROL_PESSIMISTICand the access type isAccessIntent.ACCESS_TYPE_READ, a transaction isolation level ofConnection.TRANSACTION_REPEATABLE_READis returned.If the concurrency control is
AccessIntent.CONCURRENCY_CONTROL_PESSIMISTICand the access type isAccessIntent.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_NONE
AccessIntent.PESSIMISTIC_UPDATE_LOCK_HINT_WEAKEST_LOCK_AT_LOADConnection.TRANSACTION_REPEATABLE_READAccessIntent.PESSIMISTIC_UPDATE_LOCK_HINT_NOCOLLISIONConnection.TRANSACTION_READ_COMMITTEDAccessIntent.PESSIMISTIC_UPDATE_LOCK_HINT_EXCLUSIVEConnection.TRANSACTION_SERIALIZABLE
- Specified by:
getIsolationLevelin interfaceDataStoreHelper- Overrides:
getIsolationLevelin classGenericDataStoreHelper- Parameters:
intent- AnAccessIntent- Returns:
- A transaction isolation level appropriate for the specified
AccessIntent. - Throws:
javax.resource.ResourceException- If a transaction isolation level cannot be determined from theAccessIntent.- See Also:
AccessIntent,Connection
-
getResultSetConcurrency
public int getResultSetConcurrency(AccessIntent intent) throws javax.resource.ResourceException
This method determines the result set concurrency based on the specifiedAccessIntent.DB2DataStoreHelperalways returnsjava.sql.ResultSet.CONCUR_READ_ONLY.- Specified by:
getResultSetConcurrencyin interfaceDataStoreHelper- Overrides:
getResultSetConcurrencyin classGenericDataStoreHelper- Parameters:
intent- AnAccessIntent.- Returns:
- A result set concurrency constant defined on
java.sql.ResultSet. - Throws:
javax.resource.ResourceException- If a result set concurrency cannot be determined from theAccessIntent.- See Also:
AccessIntent,ResultSet
-
showLockInfo
public final java.lang.String showLockInfo(java.util.Properties props) throws java.lang.ExceptionThis method returns DB2 lock information needed for the RAS subsystem. The
propsparameter can include the following properties:- db2Install - DB2 bin directory
- outputFile - the output file for storing the lock information. If this property is not specifed, no output is generated and null is returned.
- workingDir - a directory with write permission for the method caller where temporary files can be created. If this property is not specified, the current directory is used.
- databaseName - the DB2 database name for which to collect lock information. If this property is not specified, the value defaults to "SAMPLE".
- Overrides:
showLockInfoin classGenericDataStoreHelper- Parameters:
props- properties containing information needed to connect to the database.- Returns:
- the lock information.
- Throws:
java.lang.Exception- if an error occurs while collecting the lock information.
-
setUserDefinedMap
public final void setUserDefinedMap(java.util.Map newmap)
This method configures a user-defined
SQLExceptionmap that supersedes defaultSQLExceptionmappings for theDataStoreHelper. TheDataStoreHelperimplementations provided by WebSphere useSQLExceptionmaps to detect fatal connection errors, as well as other specific types of connection errors. A customDataStoreHelpercan alter the default mappings by invoking this method. Invoke this method only fromDataStoreHelperclasses subclassing this class. Do not invoke this method directly from application code. Internal WebSphere code does not invoke this method.Example usage of the
setUserDefinedMapmethod: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
SQLExceptionis received with SQL State S1000 and Error Code 23505, the WebSphereDataStoreHelperimplementations map the exception toUserDefinedException, whereas the WAS 4.0 DataSource map the exception toDuplicateKeyException.Additionally, mapping done by the WebSphere
DataStoreHelpers does not include mapping by chained exceptions when no match is found for the original exception.- Specified by:
setUserDefinedMapin interfaceDataStoreHelper- Overrides:
setUserDefinedMapin classGenericDataStoreHelper- Parameters:
newmap- a mapping ofSQLExceptionSQL States and Error Codes tocom.ibm.websphere.ce.cm.PortableSQLExceptionsubclasses. The key for the Map must be aString(representing the SQL State) or anInteger(representing the Error Code). The value for the Map must be a subclass ofcom.ibm.websphere.ce.cm.PortableSQLException. User-defined subclasses are permitted, but are required to declare a public constructor accepting aSQLExceptionas the single parameter. You can also useVoid.classfor the value, in which case any existing mapping for the specified SQL State or Error Code is removed.- See Also:
SQLException,PortableSQLException
-
getPrintWriter
public java.io.PrintWriter getPrintWriter()
This method is used to obtain thejava.io.PrintWriterto use for logging when database logging is enabled (for example:WAS.database=all=enabled). By default, null is returned and ajava.io.PrintWriterinstance created by WebSphere is used. You can override this method to return a differentjava.io.PrintWriterinstance instead of the default.- Specified by:
getPrintWriterin interfaceDataStoreHelper- Overrides:
getPrintWriterin classGenericDataStoreHelper- Returns:
java.io.PrintWriter.- Since:
- WAS 5.0.1
-
isBatchUpdateSupportedWithAccessIntent
public boolean isBatchUpdateSupportedWithAccessIntent(AccessIntent accessIntent)
This method is used to determine if CMP Entity Beans can support batch updates with the given AccessIntent. There are some AccessIntents (for example, WebSphere Optimistic Concurrency Control intent) for which some databases are not always capable of determining the number of updated rows. This prevents CMP Entity Beans from supporting batch updates. In such cases, this method must return false.DB2DataStoreHelperreturns false if the concurrency control of theAccessIntentisAccessIntent.CONCURRENCY_CONTROL_OPTIMISTIC, and otherwise returns true.- Specified by:
isBatchUpdateSupportedWithAccessIntentin interfaceDataStoreHelper- Overrides:
isBatchUpdateSupportedWithAccessIntentin classGenericDataStoreHelper- Parameters:
accessIntent- AccessIntent- Returns:
- boolean true if batching is allowed with the given AccessIntent, otherwise false.
- Since:
- WAS 5.0.2
- See Also:
AccessIntent
-
getLockType
public 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
SELECTstatement.- Specified by:
getLockTypein interfaceDataStoreHelper- Overrides:
getLockTypein classGenericDataStoreHelper- Parameters:
intent- AnAccessIntent- Returns:
- the lock type constant. Valid values are defined in
com.ibm.websphere.rsadaper.WSInteractionSpec:LOCKTYPE_SELECTLOCKTYPE_SELECT_FOR_UPDATELOCKTYPE_SELECT_FOR_UPDATE_WITH_RSLOCKTYPE_SELECT_FOR_UPDATE_WITH_RR
- See Also:
AccessIntent,WSInteractionSpec
-
getXAExceptionContents
public java.lang.String getXAExceptionContents(javax.transaction.xa.XAException x)
This method provides a plug-in point for providing meaningful logging information for anXAException. The information can include details of the original exception that caused theXAException, if applicable. WebSphere uses this method to obtain trace information forXAExceptions to include in WebSphere trace.- Specified by:
getXAExceptionContentsin interfaceDataStoreHelper- Overrides:
getXAExceptionContentsin classGenericDataStoreHelper- Parameters:
xae- theXAException.- Returns:
- detailed information about the
XAException, for inclusion in a WebSphere trace. - Since:
- WAS 5.0.2
- See Also:
XAException
-
-