com.ibm.websphere.rsadapter
Class DB2DataStoreHelper

java.lang.Object
  |
  +--com.ibm.websphere.rsadapter.GenericDataStoreHelper
        |
        +--com.ibm.websphere.rsadapter.DB2DataStoreHelper
All Implemented Interfaces:
DataStoreHelper, java.io.Serializable
Direct Known Subclasses:
DB2390DataStoreHelper, DB2AS400DataStoreHelper, DB2UniversalDataStoreHelper

public class DB2DataStoreHelper
extends GenericDataStoreHelper
implements java.io.Serializable

This is a helper class customized for the DB2 database. It allows us to plug in data store specific functions. When trying to map an exception, the db2 errormap will be searched first then the generic one will be searched.

If you have any special DB2 requirements, you might want to look into extending this class and overwriting the methods you wish to change.

See Also:
Serialized Form

Field Summary
protected static com.ibm.ejs.ras.TraceComponent db2Tc
           
 
Fields inherited from class com.ibm.websphere.rsadapter.GenericDataStoreHelper
EOLN, genErrorMap, resBundle
 
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, GENERIC_HELPER, INFORMIX_HELPER, MSSQL_HELPER, ORACLE_HELPER, POTENTIAL_DEADLOCK, POTENTIAL_LOST_UPDATE, SEQUELINK_HELPER, SYBASE_HELPER, SYBASE11_HELPER, TX_REPEATABLE_READ_FORUPDATE, TX_SERIALIZABLE_FORUPDATE, UPDATE_ON_READONLY, WSCONNECTJDBC_HELPER
 
Constructor Summary
DB2DataStoreHelper(java.util.Properties props)
          Ctor does not do anything with the props argument.
 
Method Summary
 void doStatementCleanup(java.sql.PreparedStatement stmt)
          Clean up a statement before it is placed in the cache.
 java.lang.Class findMappingClass(java.sql.SQLException e)
          This method returns mapping for a given exception if one is found.
 int getIsolationLevel(com.ibm.websphere.appprofile.accessintent.AccessIntent aIntent)
          This method returns the isolation level given the Intent object.
 java.io.PrintWriter getPrintWriter()
          This method is used to get the printWriter to be used to output jdbc logging when database logging is enabled (e.g.
 int getResultSetConcurrency(com.ibm.websphere.appprofile.accessintent.AccessIntent intent)
          This method returns the resultSet concurrency given the Intent Object.
 boolean isBatchUpdateSupportedWithAccessIntent(com.ibm.websphere.appprofile.accessintent.AccessIntent accessIntent)
          This method is used to determine if Batch is supported with the given accessIntent object.
 void setUserDefinedMap(java.util.Map newmap)
          This method is used to add user defined error maps.
 java.lang.String showLockInfo(java.util.Properties props)
          This method creates lock information for DB2.
 
Methods inherited from class com.ibm.websphere.rsadapter.GenericDataStoreHelper
calcPartitionNumber, doConnectionCleanup, doConnectionSetup, getLockType, getMetaData, getResultSetType, getXAExceptionContents, hasLostUpdateOrDeadLockOccurred, isConnectionError, mapException, mapException, modifyXAFlag, processGenericCredentials
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

db2Tc

protected static final com.ibm.ejs.ras.TraceComponent db2Tc
Constructor Detail

DB2DataStoreHelper

public DB2DataStoreHelper(java.util.Properties props)
Ctor does not do anything with the props argument.
Parameters:
props - is ignored
Method Detail

doStatementCleanup

public void doStatementCleanup(java.sql.PreparedStatement stmt)
                        throws java.sql.SQLException
Clean up a statement before it is placed in the cache. This method is called only for statements which are being cached. It is called only if certain statement properties have changed. See DataStoreHelper.
Overrides:
doStatementCleanup in class GenericDataStoreHelper
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 returns mapping for a given exception if one is found. First the user defined map is searched followed by the predefined DB2 map. If nothing is found, the search continues in the parent class - GenericHelper. The search is done in the following order:
  1. first the errorCode is searched
  2. then the SQLState.

If a user wants to override the mapping of a specific Exception, they can override this method and either return the same exception class or return null. In the mapexception() which calls this method if the map found is null then the original exception is returned. A user can also cancel the mapping by returning null for that exception map.

Overrides:
findMappingClass in class GenericDataStoreHelper
Parameters:
e - The SQLException we need to find a mapping class for
Returns:
java.lang.Class - The mapped class

getIsolationLevel

public final int getIsolationLevel(com.ibm.websphere.appprofile.accessintent.AccessIntent aIntent)
                            throws javax.resource.ResourceException
This method returns the isolation level given the Intent object. If the intent Object passed is null, the websphere default is returned. The websphere default is dependent on the backend database. In this case it will be TRANSACTION_READ_COMMITTED If this value is not desired one could override it in a subclass.

AccessType: Optimistic --> map to RC; PessimisticRead --> map to RR

PessimisticUpdate : Update Hint Value order is:
greedy nocollision Exclusive
0/1 0/1 0/1

when adding up the combo as an integer, for example:

BTW 7 is an invalid option since you can't have nocollision and exclusive together.

Note:
we don't allow pessimistic_update_random, therefore, this assumption is made when calculation is done

Overrides:
getIsolationLevel in class GenericDataStoreHelper
Parameters:
aIntent - AccessIntent
Returns:
int - An isolation level. The value is based on the isolation level that is defined in the java.sql.Connection.
Throws:
javax.resource.ResourceException -  
See Also:
Intent

getResultSetConcurrency

public int getResultSetConcurrency(com.ibm.websphere.appprofile.accessintent.AccessIntent intent)
                            throws javax.resource.ResourceException
This method returns the resultSet concurrency given the Intent Object. For DB2 CONCUR_READ_ONLY is the only supported value. CONCUR_READ_ONLY is also the default JDBC value. So the Intent Object is always ignored. If this value is not desired one could override it in a subclass. This method has the same implementation as the Generic but we duplicate code here for the Trace to print correctly.
Overrides:
getResultSetConcurrency in class GenericDataStoreHelper
Parameters:
intent - AccessIntent
Returns:
CONCUR_READ_ONLY in all cases
Throws:
javax.resource.ResourceException -  
See Also:
AccessIntent

showLockInfo

public final java.lang.String showLockInfo(java.util.Properties props)
                                    throws java.lang.Exception
This method creates lock information for DB2. We depend on DB2's mechanism to generate the lock information. DB2 puts this information into a file. We consider our job done when the lock information file has been created.
Overrides:
showLockInfo in class GenericDataStoreHelper
Parameters:
props - Props should have the following data to establish a connection with DB2:
  1. db2Install - DB2 bin directory
  2. outputFile - output file to put locking information in, if not specifed, no output will be generated and null is returned.
  3. workingDir - directory to create some needed file, this directory should have write permission to the caller of this method, if not specified, current directory is used.
  4. databaseName - database name, if not specified defaults to "SAMPLE"
    Returns:
    null, since the output will be generated in the specifed output file
    Throws:
    java.lang.Exception - Could range from java.io exceptions to javax.sql exceptions since we are running operations against the OS

setUserDefinedMap

public final void setUserDefinedMap(java.util.Map newmap)
This method is used to add user defined error maps. It is useful when the user wants a slght tweaking of the map. For a comprehensive change it might be advisable to extend this object.
Overrides:
setUserDefinedMap in class GenericDataStoreHelper
Parameters:
newmap - Map - a list of SQL error codes / states and the Exception class

getPrintWriter

public java.io.PrintWriter getPrintWriter()
This method is used to get the printWriter to be used to output jdbc logging when database logging is enabled (e.g. WAS.database=all=enabled). by default, a null is returned and a WAS printWriter is used. Users could overwrite this method to return a different PrintWriter, and it will be used instead of the default.
Overrides:
getPrintWriter in class GenericDataStoreHelper
Returns:
java.io.PrintWriter.

isBatchUpdateSupportedWithAccessIntent

public boolean isBatchUpdateSupportedWithAccessIntent(com.ibm.websphere.appprofile.accessintent.AccessIntent accessIntent)
This method is used to determine if Batch is supported with the given accessIntent object. there are some cases e.g. occ where some database e.g DB2 legacy don't support occ since they don't return the actual number of records updated, rather they return -2 all the time. This method will be called indirectly by PM's code before they do the batching
Overrides:
isBatchUpdateSupportedWithAccessIntent in class GenericDataStoreHelper
Parameters:
accessIntent - AccessIntent
Returns:
boolean true if batching is allowd, false otherwise