Class GenericDataStoreHelper
- java.lang.Object
-
- com.ibm.websphere.rsadapter.GenericDataStoreHelper
-
- All Implemented Interfaces:
- DataStoreHelper
- Direct Known Subclasses:
- CloudscapeDataStoreHelper, com.ibm.websphere.rsadapter.DataDirectDataStoreHelper, DB2DataStoreHelper, DerbyDataStoreHelper, InformixDataStoreHelper, MicrosoftSQLServerDataStoreHelper, OracleDataStoreHelper, ProxyDSDataStoreHelper, SybaseDataStoreHelper
public class GenericDataStoreHelper extends java.lang.Object implements DataStoreHelper
GenericDataStoreHelper
is a generalDataStoreHelper
implementation for databases and JDBC drivers fully compliant with SQL-99, X/OPEN, and JDBC. If you need to plug in additionalDataStoreHelper
functionality, you must either inherit fromGenericDataStoreHelper
or a subclass ofGenericDataStoreHelper
.
Note: This class and its methods can not be called or referenced directly by user applications.SQLException
mappings specific to theGenericDataStoreHelper
are the following:Error Code SQL State PortableSQLException
subclass23505 DuplicateKeyException.class
55032 StaleConnectionException.class
08001 StaleConnectionException.class
08003 StaleConnectionException.class
40003 StaleConnectionException.class
S1000 StaleConnectionException.class
08006 StaleConnectionException.class
08S01 StaleConnectionException.class
-
-
Field Summary
Fields Modifier and Type Field and Description protected int
customDefinedWasDefaultIsoLevel
protected int
defaultQueryTimeout
Default query timeout configured on the data source.protected static java.lang.String
EOLN
protected java.util.HashMap
genErrorMap
A list of default exception mappings for aGenericDataStoreHelper
.protected static java.lang.String
resBundle
protected java.util.List
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 GenericDataStoreHelper(java.util.Properties props)
ThisGenericDataStoreHelper
constructor creates a newGenericDataStoreHelper
based on theDataStoreHelper
properties provided.
-
Method Summary
Methods Modifier and Type Method and Description short
calcPartitionNumber(java.lang.String fullTableName, java.util.Properties propPartKeys)
This method allows you to calculate the partition number based on the input table name and partition key properties.boolean
doConnectionCleanup(java.sql.Connection conn)
This method is used to clean up a connection before it is returned to the connection pool for later reuse.boolean
doConnectionCleanupPerCloseConnection(java.sql.Connection conn, boolean isCMP, java.lang.Object props)
This method is invoked by WebSphere Application Server runtime immediately after a connection handle is closed by the application or implicitly by WebSphere Application Server runtime.boolean
doConnectionCleanupWithValidCheck(java.sql.Connection conn)
void
doConnectionSetup(java.sql.Connection conn)
This method configures a connection before first use.boolean
doConnectionSetupPerGetConnection(java.sql.Connection conn, boolean isCMP, java.lang.Object props)
This method is invoked by WebSphere Application Server runtime before a connection handle is provided to the application.void
doConnectionSetupPerTransaction(javax.security.auth.Subject sub, java.lang.String user, java.sql.Connection conn, boolean reauthRequired, java.lang.Object properties)
This method is invoked by WebSphere runtime each time a connection comes out of the connection pool and only before transactions begin on that connection.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 thecom.ibm.websphere.ce.cm.PortableSQLException
subclass corresponding to the specifiedSQLException
, as defined by theGenericDataStoreHelper
SQLException
map and user-definedSQLException
map.int
getIsolationLevel(AccessIntent intent)
This method determines the transaction isolation level based on the specifiedAccessIntent
.int
getLockType(AccessIntent intent)
This method returns a lock type constant based on the update hint value of the specified AccessIntent.DataStoreHelperMetaData
getMetaData()
This method returns theDataStoreHelperMetaData
object associated with thisDataStoreHelper
.java.lang.String
getPasswordForUseWithTrustedContextWithAuthentication(java.lang.String identityname, java.lang.String realm)
The application server invokes this method at run time to get the password that the application server will use to establish a trusted connection using the DB2 TrustedContext "with authentication" option or when the application server switches a trusted connection to another identity, and the "with authentication" option is enabled.java.io.PrintWriter
getPrintWriter()
This method is used to obtain thejava.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 specifiedAccessIntent
.int
getResultSetType(AccessIntent intent)
This method determines the result set type based on the specifiedAccessIntent
.java.lang.String
getXAExceptionContents(javax.transaction.xa.XAException x)
This method provides a plug-in point for providing meaningful logging information for anXAException
.java.lang.String
hasLostUpdateOrDeadLockOccurred(int isoLevel, boolean loadedForUpdate)
This method is invoked when storing a CMP EntityBean if pessimistic concurrency control is activated.boolean
isBatchUpdateSupportedWithAccessIntent(AccessIntent accessIntent)
This method is used to determine if CMP Entity Beans can support batch updates with the given AccessIntent.boolean
isConnectionError(java.sql.SQLException ex)
This method determines whether aSQLException
indicates a fatal connection error based on the exception map for this data store helper.boolean
isDuplicateKey(java.sql.SQLException sqlX)
The application server invokes this method to determine whether or not the specified error indicates a duplicate key violation.boolean
isTransientConnectionError(java.sql.SQLException ex)
This method determines whether aSQLException
indicates a transient connection error.java.sql.SQLException
mapException(java.sql.SQLException e)
The application server uses this API to replace java.sql.SQLExceptions with the exceptions defined in the map if the data source's error detection model is configured to exception mapping.int
modifyXAFlag(int xaflag)
This method is used only when thetransactionBranchesLooselyCoupled
custom DataSource property is set to true.void
setConfig(java.lang.Object config)
For internal use only.void
setUserDefinedMap(java.util.Map newmap)
This method configures a user-definedSQLException
map that supersedes the defaultSQLException
mappings for theDataStoreHelper
.java.lang.String
showLockInfo(java.util.Properties props)
This method returns database lock information needed for the RAS subsystem.
-
-
-
Field Detail
-
resBundle
protected static final java.lang.String resBundle
- See Also:
- Constant Field Values
-
customDefinedWasDefaultIsoLevel
protected int customDefinedWasDefaultIsoLevel
-
EOLN
protected static final java.lang.String EOLN
-
genErrorMap
protected java.util.HashMap genErrorMap
A list of default exception mappings for aGenericDataStoreHelper
.
-
tranErrorList
protected java.util.List tranErrorList
-
defaultQueryTimeout
protected int defaultQueryTimeout
Default query timeout configured on the data source.- Since:
- F010627, 500009
-
-
Constructor Detail
-
GenericDataStoreHelper
public GenericDataStoreHelper(java.util.Properties props)
ThisGenericDataStoreHelper
constructor creates a newGenericDataStoreHelper
based on theDataStoreHelper
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.- Parameters:
props
-DataStoreHelper
properties.
-
-
Method Detail
-
getMetaData
public DataStoreHelperMetaData getMetaData()
This method returns theDataStoreHelperMetaData
object associated with thisDataStoreHelper
.- Specified by:
getMetaData
in interfaceDataStoreHelper
- Returns:
DataStoreHelperMetaData
-
isDuplicateKey
public boolean isDuplicateKey(java.sql.SQLException sqlX)
The application server invokes this method to determine whether or not the specified error indicates a duplicate key violation. The method is invoked regardless of the data source's error detection model.
- Specified by:
isDuplicateKey
in interfaceDataStoreHelper
- Parameters:
sqlX
- the error.- Returns:
- true if the error indicates a duplicate key violation, otherwise false.
-
getIsolationLevel
public int getIsolationLevel(AccessIntent intent) throws javax.resource.ResourceException
This method determines the transaction isolation level based on the specifiedAccessIntent
. If theAccessIntent
parameter is null, a default value is returned that is appropriate for the database backend.For generic databases and JDBC drivers,
java.sql.Connection.TRANSACTION_READ_COMMITTED
is returned under all circumstances.- Specified by:
getIsolationLevel
in interfaceDataStoreHelper
- 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
.
-
getResultSetType
public int getResultSetType(AccessIntent intent) throws javax.resource.ResourceException
This method determines the result set type based on the specifiedAccessIntent
.GenericDataStoreHelper
always returns a value ofjava.sql.ResultSet.FETCH_FORWARD
.- Specified by:
getResultSetType
in interfaceDataStoreHelper
- Parameters:
intent
- AnAccessIntent
.- Returns:
- A result set type constant defined on
java.sql.ResultSet
. - Throws:
javax.resource.ResourceException
- If a result set type cannot be determined from theAccessIntent
.
-
getResultSetConcurrency
public int getResultSetConcurrency(AccessIntent intent) throws javax.resource.ResourceException
This method determines the result set concurrency based on the specifiedAccessIntent
.GenericDataStoreHelper
always returnsjava.sql.ResultSet.CONCUR_READ_ONLY
.- Specified by:
getResultSetConcurrency
in interfaceDataStoreHelper
- 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
.
-
isConnectionError
public boolean isConnectionError(java.sql.SQLException ex)
This method determines whether aSQLException
indicates a fatal connection error based on the exception map for this data store helper. You need to override this method if you provide custom exceptions that inherit from StaleConnectionException or StaleStatementException.- Specified by:
isConnectionError
in interfaceDataStoreHelper
- Parameters:
ex
- theSQLException
to check.- Returns:
- true if the exception indicates a fatal connection error, otherwise false.
-
hasLostUpdateOrDeadLockOccurred
public java.lang.String hasLostUpdateOrDeadLockOccurred(int isoLevel, boolean loadedForUpdate)
This method is invoked when storing a CMP EntityBean if pessimistic concurrency control is activated. This method determines whether a potential lost update or deadlock scenario has occurred. If so, this method returns an appropriate message ID. This information is passed to the bean provider to provide notification that code changes are needed to avoid potential problems.pre-conditions
- pessimistic concurrency control is being used
- getAutoCommit() on the connection returns false
- Specified by:
hasLostUpdateOrDeadLockOccurred
in interfaceDataStoreHelper
- Parameters:
isoLevel
- the transaction isolation level used.loadedForUpdate
-true
if the CMP EntityBean was loaded for update (eg. FOR UPDATE keywords used on SELECT), otherwise false.- Returns:
- One of the following
-
findMappingClass
public java.lang.Class findMappingClass(java.sql.SQLException e)
This method locates the
com.ibm.websphere.ce.cm.PortableSQLException
subclass corresponding to the specifiedSQLException
, as defined by theGenericDataStoreHelper
SQLException
map and user-definedSQLException
map. Precedence and related details ofSQLException
mapping are described on theDataStoreHelper.setUserDefinedMap
method.Overriding this method is one of three options for modifying
SQLException
mapping. The other two options are overriding themapException
method and invoking thesetUserDefinedMap
method to add a user-definedSQLException
map.- Parameters:
e
- TheSQLException
for which to locate acom.ibm.websphere.ce.cm.PortableSQLException
subclass.- Returns:
- The
com.ibm.websphere.ce.cm.PortableSQLException
subclass matching theSQLException
, or null if no match was found.
-
mapException
public java.sql.SQLException mapException(java.sql.SQLException e)
The application server uses this API to replace java.sql.SQLExceptions with the exceptions defined in the map if the data source's error detection model is configured to exception mapping. If configured to exception checking, then the application server consults the map to help determine the cause of the error, but does not replace the exception.
This method maps the specified SQLException to a correspondingcom.ibm.websphere.ce.cm.PortableSQLException
subclass. If no correspondingcom.ibm.websphere.ce.cm.PortableSQLException
subclass is found, theSQLException
is returned unchanged.- Specified by:
mapException
in interfaceDataStoreHelper
- Parameters:
e
- aSQLException
.- Returns:
- a
com.ibm.websphere.ce.cm.PortableSQLException
subclass corresponding to the specifiedSQLException
, or the unchangedSQLException
if no match is found.
-
doConnectionSetup
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.
GenericDataStoreHelper
does not perform any connection setup.- Specified by:
doConnectionSetup
in interfaceDataStoreHelper
- Parameters:
conn
- the connection to set up.- Throws:
java.sql.SQLException
- if connection setup cannot be completed successfully.
-
doConnectionCleanup
public boolean doConnectionCleanup(java.sql.Connection conn) throws java.sql.SQLException
This method is used to clean up a connection before it is returned to the connection pool for later reuse. WebSphere automatically resets all standard connection properties (fields for which getters and setters are defined on
java.sql.Connection
). This method may be used to reset other properties proprietary to a specific JDBC driver/database and do whatever else is necessary to prepare the connection for reuse.A
DataStoreHelper
is permitted to use the provided connection to create and execute statements for the purpose of cleaning up the connection. Any statements created within thedoConnectionCleanup
method must be explicitly closed within thedoConnectionCleanup
method. ThedoConnectionCleanup
method must never close the connection being cleaned up.If any standard connection properties are modified in this method, a value of true must be returned, indicating to WebSphere that at least one standard connection property was modified. A value of false is returned only if no standard connection properties were modified.
GenericDataStoreHelper
does not perform any connection cleanup.- Specified by:
doConnectionCleanup
in interfaceDataStoreHelper
- Parameters:
conn
- the connection to attempt to cleanup.- Returns:
- true if any standard connection property was modified, otherwise false.
- Throws:
java.sql.SQLException
- If an error occurs while cleaning up the connection.
-
doConnectionCleanupWithValidCheck
public boolean doConnectionCleanupWithValidCheck(java.sql.Connection conn) throws java.sql.SQLException
- Specified by:
doConnectionCleanupWithValidCheck
in interfaceDataStoreHelper
- Throws:
java.sql.SQLException
-
doStatementCleanup
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 that are cached. It is called only if at least one of the following statement properties has changed:
- cursorName
- fetchDirection
- maxFieldSize
- maxRows
- queryTimeout
GenericDataStoreHelper
resets all of the properties listed above.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 may choose to do additional cleanup for the statement. However, this should never include closing the statement, since the statement is intended to be cached.
- Specified by:
doStatementCleanup
in interfaceDataStoreHelper
- Parameters:
stmt
- the PreparedStatement.- Throws:
java.sql.SQLException
- if an error occurs cleaning up the statement.
-
showLockInfo
public java.lang.String showLockInfo(java.util.Properties props) throws java.lang.Exception
This method returns database lock information needed for the RAS subsystem.- 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 void setUserDefinedMap(java.util.Map newmap)
This method configures a user-defined
SQLException
map that supersedes the defaultSQLException
mappings for theDataStoreHelper
. TheDataStoreHelper
implementations that are provided by the application server useSQLException
maps to detect connection errors that can end connections, as well as other specific types of errors. A customDataStoreHelper
can alter the default mappings by invoking this method. Do not invoke this method from a customDataStoreHelper
if you also configure theuserDefinedErrorMap
data source custom property. When you configure theuserDefinedErrorMap
custom data source property, the application server invokes this method to overlay the default error mappings with the error mappings that are specified in the custom property. Do not invoke this method directly from application code.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 WebSphereDataStoreHelper
implementations map the exception toUserDefinedException
, whereas the WAS 4.0 DataSource map the exception toDuplicateKeyException
.Additionally, mapping done by the WebSphere
DataStoreHelper
s does not include mapping by chained exceptions when no match is found for the original exception.- Specified by:
setUserDefinedMap
in interfaceDataStoreHelper
- Parameters:
newmap
- a mapping ofSQLException
SQL States and Error Codes tocom.ibm.websphere.ce.cm.PortableSQLException
subclasses. 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 aSQLException
as the single parameter.Void.class
may also be used for the value, in which case any existing mapping for the specified SQL State or Error Code is removed.
-
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 are used on a
SELECT
statement.GenericDataStoreHelper
returnsWSInteractionSpec.LOCKTYPE_SELECT
in all cases, except for when all of the following are true:- The access type of the AccessIntent is
AccessIntent.ACCESS_TYPE_UPDATE
. - The concurrency control of the AccessIntent is
AccessIntent.CONCURRENCY_CONTROL_PESSIMISTIC
. - The pessimistic update lock hint of the AccessIntent is either
AccessIntent.PESSIMISTIC_UPDATE_LOCK_HINT_NONE
orAccessIntent.PESSIMISTIC_UPDATE_LOCK_HINT_EXCLUSIVE
.
In the above case,
GenericDataStoreHelper
returnsWSInteractionSpec.LOCKTYPE_SELECT_FOR_UPDATE
.- Specified by:
getLockType
in interfaceDataStoreHelper
- Parameters:
intent
- AnAccessIntent
- Returns:
- the lock type constant. Valid values are defined in
com.ibm.websphere.rsadapter.WSInteractionSpec
:LOCKTYPE_SELECT
LOCKTYPE_SELECT_FOR_UPDATE
LOCKTYPE_SELECT_FOR_UPDATE_WITH_RS
LOCKTYPE_SELECT_FOR_UPDATE_WITH_RR
- The access type of the AccessIntent is
-
calcPartitionNumber
public short calcPartitionNumber(java.lang.String fullTableName, java.util.Properties propPartKeys) throws javax.resource.ResourceException
This method allows you to calculate the partition number based on the input table name and partition key properties. This method is reserved for future use and is not currently called by WebSphere.- Specified by:
calcPartitionNumber
in interfaceDataStoreHelper
- Parameters:
fullTableName
- - the fully qualified table name.propPartKeys
- - the partition key properties- Returns:
- a partition number.
- Throws:
javax.resource.ResourceException
- any exception which occurs during the calculation of a partition key will result in a ResourceException
-
getPrintWriter
public java.io.PrintWriter getPrintWriter()
This method is used to obtain thejava.io.PrintWriter
to use for logging when database logging is enabled (for example:WAS.database=all=enabled
). By default, null is returned and ajava.io.PrintWriter
instance created by WebSphere is used. You can override this method to return a differentjava.io.PrintWriter
instance instead of the default.- Specified by:
getPrintWriter
in interfaceDataStoreHelper
- Returns:
java.io.PrintWriter
.- Since:
- WAS 5.0.1
-
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 forXAException
s to include in WebSphere trace.- Specified by:
getXAExceptionContents
in interfaceDataStoreHelper
- Parameters:
xae
- theXAException
.- Returns:
- detailed information about the
XAException
, for inclusion in a WebSphere trace. - Since:
- WAS 5.0.2
-
modifyXAFlag
public int modifyXAFlag(int xaflag)
This method is used only when the
transactionBranchesLooselyCoupled
custom DataSource property is set to true. This method modifies the given XA start flag. Some databases, such as Oracle, require a proprietary flag, such asOracleXAResource.ORATRANSLOOSE
.GenericDataStoreHelper
makes no modifications to the XA start flag.- Specified by:
modifyXAFlag
in interfaceDataStoreHelper
- Parameters:
xaflag
- The XA start flag to modify.- Returns:
- The modified XA start flag.
- 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 being able to support batch updates. In such cases, this method must return false.GenericDataStoreHelper
returns a value of true, indicating batch updates are always supported. If necessary, you can change this value by overriding this method.- Specified by:
isBatchUpdateSupportedWithAccessIntent
in interfaceDataStoreHelper
- Parameters:
accessIntent
- AccessIntent- Returns:
- boolean true if batching is allowed with the given AccessIntent, otherwise false.
- Since:
- WAS 5.0.2
-
doConnectionSetupPerTransaction
public void doConnectionSetupPerTransaction(javax.security.auth.Subject sub, java.lang.String user, java.sql.Connection conn, boolean reauthRequired, java.lang.Object properties) throws java.sql.SQLException
Description copied from interface:DataStoreHelper
This method is invoked by WebSphere runtime each time a connection comes out of the connection pool and only before transactions begin on that connection. This method is different from thedoConnectionSetup()
method which is only called when a physical connection is first created.
Implementation of this method is required if the "reauthentication" datasource custom property is set to true or if "enable reauthentication checkbox" is checked. Failure to do so might result in unpredictable behavior.
This method is not only limited to user reauthentication; users can also take advantage of this method in other situations. For example:
- altering the identity for audit purposes
- altering the target schema
java.sql.Connection
properties.
Note also that users might need to implement the doConnectionCleanup() method to reset thejava.sql.Connection
to the original state prior to callingdoConnectionSetupPerTransaction
Note also that WebSphere runtime will passjava.util.Properties
object which contains a propertyDataStoreHelper.FIRST_TIME_CALLED
. TheDataStoreHelper.FIRST_TIME_CALLED
is set to true when thedoConnectionSetupPerTransaction
is called by WebSphere runtime for the first time for any WebSphere connection. TheDataStoreHelper.FIRST_TIME_CALLED
is set to false thereafter.- Specified by:
doConnectionSetupPerTransaction
in interfaceDataStoreHelper
- Parameters:
sub
- javax.security.auth.Subject for the newly requested connection. This value is null unlessres-auth
is set to container.user
- java.lang.String user name of the newly requested connection. This value is specified only if the subject is null.conn
- java.sql.ConnectionreauthRequired
- boolean that indicates whether reauthentication is required on the passed connection to get the connection in sync with the subject or user name:- FALSE: connection is in sync with the passed subject or user name.
- TRUE: conneciton is not in sync with the passed subject or user name. In this case, users are required to provide reauthentication implementation for the connection.
properties
- java.lang.Object WebSphere runtime passesjava.util.Properties
when calling this method- Throws:
java.sql.SQLException
- if connection throws an exception.
-
doConnectionSetupPerGetConnection
public boolean doConnectionSetupPerGetConnection(java.sql.Connection conn, boolean isCMP, java.lang.Object props) throws java.sql.SQLException
Description copied from interface:DataStoreHelper
This method is invoked by WebSphere Application Server runtime before a connection handle is provided to the application. This method is called by WebSphere Application Server runtime when the connection handle provided is the only handle for the associated ManagedConnection. Thus, if connection sharing occurs, this method will not be called when additional connection handles are provided to the application for the same ManagedConnection. If connection handle usage follows a get/use/close pattern, such that the ManagedConnection has only 1 active connection handle outstanding at a time, then this method will be invoked for each getConnection call made by the application.
This method may be overridden to provide code to set up a connection before its use by the application. This is particularly useful when dealing with CMP, where applications don't have direct access to connections.
Note that The get/use/close pattern must be used by the application if this method is overridden.- Specified by:
doConnectionSetupPerGetConnection
in interfaceDataStoreHelper
- Parameters:
conn
- java.sql.Connection the underlying database physical connectionisCMP
- boolean: specifies if the connection is used for a CMP request or another type of request.props
- Map<String,Object> containing additional properties. The keyDataStoreHelper.SUBJECT
maps to thejavax.security.auth.Subject
if a Subject is available.- Returns:
- boolean false indicates no connection setup is performed by this method, true otherwise. Default is false as its a no-op.
- Throws:
java.sql.SQLException
-
doConnectionCleanupPerCloseConnection
public boolean doConnectionCleanupPerCloseConnection(java.sql.Connection conn, boolean isCMP, java.lang.Object props) throws java.sql.SQLException
Description copied from interface:DataStoreHelper
This method is invoked by WebSphere Application Server runtime immediately after a connection handle is closed by the application or implicitly by WebSphere Application Server runtime. If you override thedoConnectionSetupPerGetConnection
method to perform connection setup, then you must override this method to undo all connection setup done in thedoConnectionSetupPerGetConnection
method.
This method is called by WebSphere Application Server runtime when the connection handle closed is the last active handle for the associated ManagedConnection. Thus, if connection sharing occurs, this method will not be called when additional connection handles are active for the same ManagedConnection. If connection handle usage follows a get/use/close pattern, such that the ManagedConnection has only 1 connection handle outstanding at a time, then this method will be invoked for each Connection.close call made by the application. If the end of a transaction (commit or rollback) occurs before Connection.close is called, then the connection handle is dissociated from the ManagedConnection and this method is not invoked.
Note that the get/use/close pattern must be used by the application when this method is overridden.- Specified by:
doConnectionCleanupPerCloseConnection
in interfaceDataStoreHelper
- Parameters:
conn
- java.sql.Connection the underlying database physical connectionisCMP
- boolean: specifies if the connection is used for a CMP request or another type of request.props
- java.lang.Object this is not used and is a place holder for future changes.- Returns:
- boolean false indicates no connection cleanup is performed by this method, true otherwise. Default is false as its a no-op.
- Throws:
java.sql.SQLException
-
getPasswordForUseWithTrustedContextWithAuthentication
public java.lang.String getPasswordForUseWithTrustedContextWithAuthentication(java.lang.String identityname, java.lang.String realm) throws java.sql.SQLException
Description copied from interface:DataStoreHelper
The application server invokes this method at run time to get the password that the application server will use to establish a trusted connection using the DB2 TrustedContext "with authentication" option or when the application server switches a trusted connection to another identity, and the "with authentication" option is enabled. The password that is returned by this method will not be stored locally in the application server.
Be aware that the application server will call this method to get the password for trusted context usage if the following is true:
- You set the useTrustedContextWithAuthentication data source custom property to true.
- You use the TrustedConnectionMapping login configuration.
- Specified by:
getPasswordForUseWithTrustedContextWithAuthentication
in interfaceDataStoreHelper
- Parameters:
identityname
- String: the identity of the connection to which the application server is switching and for which password is needed.realm
- String: the realm name that is being used that can determine the identity of the user.- Returns:
- String password that will be used when switching trusted context identity to the specified user.
- Throws:
java.sql.SQLException
-
isTransientConnectionError
public boolean isTransientConnectionError(java.sql.SQLException ex)
Description copied from interface:DataStoreHelper
This method determines whether aSQLException
indicates a transient connection error. That means the current SQL operation can be retried on the existing connection, if the method returns true. Currently, implementation of this method is limited to JDBC 4.0 compliant drivers.- Specified by:
isTransientConnectionError
in interfaceDataStoreHelper
- Parameters:
ex
- theSQLException
to check.- Returns:
- true if the exception indicates a transient connection error, otherwise false.
- See Also:
SQLException
-
setConfig
public final void setConfig(java.lang.Object config)
For internal use only.- Parameters:
config
-
-
-