|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ibm.websphere.rsadapter.GenericDataStoreHelper
GenericDataStoreHelper
is a general DataStoreHelper
implementation for databases and JDBC drivers fully compliant with SQL-99, X/OPEN, and
JDBC. If you need to plug in additional DataStoreHelper
functionality,
you must either inherit from GenericDataStoreHelper
or a subclass
of GenericDataStoreHelper
.
SQLException
mappings specific to the GenericDataStoreHelper
are the following:
Error Code | SQL State | PortableSQLException subclass |
---|---|---|
23505 | 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 | |
---|---|
protected static java.lang.String |
EOLN
|
protected java.util.HashMap |
genErrorMap
A list of default exception mappings for a GenericDataStoreHelper . |
protected static java.lang.String |
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 | |
---|---|
GenericDataStoreHelper(java.util.Properties props)
This GenericDataStoreHelper constructor creates a new
GenericDataStoreHelper based on the DataStoreHelper
properties provided. |
Method Summary | |
---|---|
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. |
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
GenericDataStoreHelper SQLException map and
user-defined SQLException map. |
int |
getIsolationLevel(com.ibm.websphere.appprofile.accessintent.AccessIntent intent)
This method determines the transaction isolation level based on the specified AccessIntent . |
int |
getLockType(com.ibm.websphere.appprofile.accessintent.AccessIntent intent)
This method returns a lock type constant based on the update hint value of the specified AccessIntent. |
DataStoreHelperMetaData |
getMetaData()
This method returns the DataStoreHelperMetaData object associated
with this DataStoreHelper . |
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(com.ibm.websphere.appprofile.accessintent.AccessIntent intent)
This method determines the result set concurrency based on the specified AccessIntent . |
int |
getResultSetType(com.ibm.websphere.appprofile.accessintent.AccessIntent intent)
This method determines the result set type 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 . |
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(com.ibm.websphere.appprofile.accessintent.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 a SQLException indicates a fatal connection error. |
com.ibm.ws.rsadapter.exceptions.DataStoreAdapterException |
mapException(com.ibm.ws.rsadapter.exceptions.DataStoreAdapterException e)
Deprecated. |
java.sql.SQLException |
mapException(java.sql.SQLException e)
This method maps the specified SQLException to a corresponding com.ibm.websphere.ce.cm.PortableSQLException subclass. |
int |
modifyXAFlag(int xaflag)
This method is used only when the transactionBranchesLooselyCoupled
custom DataSource property is set to true. |
void |
processGenericCredentials(javax.resource.spi.security.GenericCredential credential)
This method processes Generic Credentials authentication for a specific database. |
java.lang.String |
processSQL(java.lang.String sqlString,
int isolevel)
Deprecated. : please don't implement this method. |
java.lang.String |
processSQL(java.lang.String sqlString,
int isolevel,
boolean addForUpdate,
boolean addExtendedforUpdateSyntax)
Deprecated. : please don't implement this method. |
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 database lock information needed for the RAS subsystem. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static final java.lang.String resBundle
protected static final java.lang.String EOLN
protected java.util.HashMap genErrorMap
GenericDataStoreHelper
.
Constructor Detail |
public GenericDataStoreHelper(java.util.Properties props)
GenericDataStoreHelper
constructor creates a new
GenericDataStoreHelper
based on the DataStoreHelper
properties provided. The properties parameter is provided only for future
extensibility and is currently unused.
props
- DataStoreHelper
properties.Method Detail |
public DataStoreHelperMetaData getMetaData()
DataStoreHelperMetaData
object associated
with this DataStoreHelper
.
getMetaData
in interface DataStoreHelper
DataStoreHelperMetaData
public int getIsolationLevel(com.ibm.websphere.appprofile.accessintent.AccessIntent intent) throws javax.resource.ResourceException
AccessIntent
.
If the AccessIntent
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.
getIsolationLevel
in interface DataStoreHelper
intent
- An AccessIntent
AccessIntent
.
javax.resource.ResourceException
- If a transaction isolation level cannot be determined
from the AccessIntent
.AccessIntent
,
Connection
public int getResultSetType(com.ibm.websphere.appprofile.accessintent.AccessIntent intent) throws javax.resource.ResourceException
AccessIntent
.
GenericDataStoreHelper
always returns a value of
java.sql.ResultSet.FETCH_FORWARD
.
getResultSetType
in interface DataStoreHelper
intent
- An AccessIntent
.
java.sql.ResultSet
.
javax.resource.ResourceException
- If a result set type cannot be determined from
the AccessIntent
.AccessIntent
,
ResultSet
public int getResultSetConcurrency(com.ibm.websphere.appprofile.accessintent.AccessIntent intent) throws javax.resource.ResourceException
AccessIntent
.
GenericDataStoreHelper
always returns
java.sql.ResultSet.CONCUR_READ_ONLY
.
getResultSetConcurrency
in interface DataStoreHelper
intent
- An AccessIntent
.
java.sql.ResultSet
.
javax.resource.ResourceException
- If a result set concurrency cannot be determined
from the AccessIntent
.AccessIntent
,
ResultSet
public void processGenericCredentials(javax.resource.spi.security.GenericCredential credential) throws javax.resource.ResourceException
GenericDataStoreHelper
, this method is a no-op.
Subclasses can override this method to perform their own proprietary credential
processing.
processGenericCredentials
in interface DataStoreHelper
credential
- The generic credential that is used to get the user name and password from the
java.sql.Connection.
javax.resource.ResourceException
- Any errors while processing the generic credential authentication
will result in throwing this exception. The original SQLException or native Exception
is chained to this Exception.public boolean isConnectionError(java.sql.SQLException ex)
SQLException
indicates a fatal connection error.
isConnectionError
in interface DataStoreHelper
ex
- the SQLException
to check.
SQLException
public java.lang.String hasLostUpdateOrDeadLockOccurred(int isoLevel, boolean loadedForUpdate)
pre-conditions
hasLostUpdateOrDeadLockOccurred
in interface DataStoreHelper
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.
public 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
GenericDataStoreHelper
SQLException
map and
user-defined SQLException
map. Precedence and related details of
SQLException
mapping are described on the
DataStoreHelper.setUserDefinedMap
method.
Overriding this method is one of three options 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.
e
- 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
,
PortableSQLException
public java.sql.SQLException mapException(java.sql.SQLException e)
com.ibm.websphere.ce.cm.PortableSQLException
subclass.
If no corresponding com.ibm.websphere.ce.cm.PortableSQLException
subclass
is found, the SQLException
is returned unchanged.
mapException
in interface DataStoreHelper
e
- a SQLException
.
com.ibm.websphere.ce.cm.PortableSQLException
subclass
corresponding to the specified SQLException
, or the unchanged
SQLException
if no match is found.SQLException
,
PortableSQLException
public final com.ibm.ws.rsadapter.exceptions.DataStoreAdapterException mapException(com.ibm.ws.rsadapter.exceptions.DataStoreAdapterException e)
This method maps the SQLException
contained in the input
DataStoreAdapterException
to a matching WebSphere
PortableSQLException
subclass.
mapException
in interface DataStoreHelper
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.
doConnectionSetup
in interface DataStoreHelper
conn
- the connection to set up.
java.sql.SQLException
- if connection setup cannot be completed successfully.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 the doConnectionCleanup
method must be explicitly closed
within the doConnectionCleanup
method. The
doConnectionCleanup
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.
doConnectionCleanup
in interface DataStoreHelper
conn
- the connection to attempt to cleanup.
java.sql.SQLException
- If an error occurs while cleaning up the connection.Connection
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:
GenericDataStoreHelper
resets all six 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.
doStatementCleanup
in interface DataStoreHelper
stmt
- the PreparedStatement.
java.sql.SQLException
- if an error occurs cleaning up the statement.public java.lang.String showLockInfo(java.util.Properties props) throws java.lang.Exception
props
- properties containing information needed to connect to the database.
java.lang.Exception
- if an error occurs while collecting the lock information.public 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 DataStoreHelper
s does not
include mapping by chained exceptions when no match is found for the original exception.
setUserDefinedMap
in interface DataStoreHelper
newmap
- 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.
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.SQLException
,
PortableSQLException
public int getLockType(com.ibm.websphere.appprofile.accessintent.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
returns
WSInteractionSpec.LOCKTYPE_SELECT
in all cases, except for when all of
the following are true:
AccessIntent.ACCESS_TYPE_UPDATE
.AccessIntent.CONCURRENCY_CONTROL_PESSIMISTIC
.AccessIntent.PESSIMISTIC_UPDATE_LOCK_HINT_NONE
or
AccessIntent.PESSIMISTIC_UPDATE_LOCK_HINT_EXCLUSIVE
.
In the above case, GenericDataStoreHelper
returns
WSInteractionSpec.LOCKTYPE_SELECT_FOR_UPDATE
.
getLockType
in interface DataStoreHelper
intent
- An AccessIntent
com.ibm.websphere.rsadapter.WSInteractionSpec
:
LOCKTYPE_SELECT
LOCKTYPE_SELECT_FOR_UPDATE
LOCKTYPE_SELECT_FOR_UPDATE_WITH_RS
LOCKTYPE_SELECT_FOR_UPDATE_WITH_RR
AccessIntent
,
WSInteractionSpec
public short calcPartitionNumber(java.lang.String fullTableName, java.util.Properties propPartKeys) throws javax.resource.ResourceException
calcPartitionNumber
in interface DataStoreHelper
fullTableName
- - the fully qualified table name.propPartKeys
- - the partition key properties
javax.resource.ResourceException
- any exception which occurs during the calculation of a partition key will result in a
ResourceExceptionpublic 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 DataStoreHelper
java.io.PrintWriter
.public 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
XAException
s to include in WebSphere trace.
getXAExceptionContents
in interface DataStoreHelper
x
- the XAException
.
XAException
, for inclusion in
a WebSphere trace.XAException
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 as
OracleXAResource.ORATRANSLOOSE
.
GenericDataStoreHelper
makes no modifications to the XA start flag.
modifyXAFlag
in interface DataStoreHelper
xaflag
- The XA start flag to modify.
XAResource
public boolean isBatchUpdateSupportedWithAccessIntent(com.ibm.websphere.appprofile.accessintent.AccessIntent accessIntent)
GenericDataStoreHelper
returns a value of true, indicating batch
updates are always supported. If necessary, you can change this value by
overriding this method.
isBatchUpdateSupportedWithAccessIntent
in interface DataStoreHelper
accessIntent
- AccessIntent
AccessIntent
public java.lang.String processSQL(java.lang.String sqlString, int isolevel)
processSQL
in interface DataStoreHelper
sqlString
- the sql string to be modifiedisolevel
- The isolation level of the connection
public java.lang.String processSQL(java.lang.String sqlString, int isolevel, boolean addForUpdate, boolean addExtendedforUpdateSyntax)
processSQL
in interface DataStoreHelper
sqlString
- String: SQLString to be modifiedisolevel
- int: Isolation level, which is used in the case of the db2/390 to determine what the added syntax should beaddForUpdate
- boolean: if true means the equivalent syntax of "FOR UPDATE" to the sqlString will be added
if forUpdate is true, i am guaranteed that the there is no "for update" in the string alreadyaddExtendedforUpdateSyntax
- boolean: if true means the extended-for-update syntax (if applicable) will be added.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |