com.ibm.websphere.rsadapter
Class SybaseDataStoreHelper
- java.lang.Object
com.ibm.websphere.rsadapter.GenericDataStoreHelper
com.ibm.websphere.rsadapter.SybaseDataStoreHelper
- public class SybaseDataStoreHelper
- extends GenericDataStoreHelper
SybaseDataStoreHelper
is a DataStoreHelper
implementation
customized for the Sybase database.
When mapping a SQLException
, the SQLException
mappings from the
SybaseDataStoreHelper
are searched first, and subsequently, if no match is
found, the SQLException
mappings from the GenericDataStoreHelper
are searched.
If you have additional requirements on Sybase you should consider subclassing this
implementation.
Note: This class and its methods can not be called or referenced directly by user applications.
SQLException
mappings specific to the SybaseDataStoreHelper
are the following:
Error Code | SQL State | PortableSQLException subclass |
---|---|---|
2601 | DuplicateKeyException.class | |
JZ0C0 | StaleConnectionException.class | |
JZ0C1 | StaleConnectionException.class |
Field Summary
Fields inherited from class com.ibm.websphere.rsadapter.GenericDataStoreHelper |
---|
customDefinedWasDefaultIsoLevel, defaultQueryTimeout, EOLN, genErrorMap, resBundle, tranErrorList |
Constructor Summary
Constructor and Description |
---|
SybaseDataStoreHelper(java.util.Properties props)
This
SybaseDataStoreHelper constructor creates a new
GenericDataStoreHelper based on the DataStoreHelper
properties provided.
|
Method Summary
Modifier and Type | Method and Description |
---|---|
|
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.
|
|
doConnectionSetup(java.sql.Connection conn)
This method configures a connection before first use.
|
|
doStatementCleanup(java.sql.PreparedStatement stmt)
This method cleans up a statement before the statement is returned to the statement
cache.
|
|
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
SybaseDataStoreHelper , GenericDataStoreHelper , and
user-defined SQLException maps.
|
|
getIsolationLevel(AccessIntent aIntent)
This method determines the transaction isolation level based on the specified
AccessIntent .
|
|
getPrintWriter()
This method is used to obtain a log writer to set on the
DataSource
when database logging is enabled (for example: WAS.database=all=enabled ).
|
|
setUserDefinedMap(java.util.Map newmap)
This method configures a user-defined
SQLException map that supersedes
default SQLException mappings for the DataStoreHelper .
|
|
showLockInfo(java.util.Properties props)
This method returns lock information for Sybase.
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail
SybaseDataStoreHelper
- public SybaseDataStoreHelper(java.util.Properties props)
props
- DataStoreHelper
properties. Method Detail
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 will be cached. It is called only if at least one of the following statement properties has changed,
- cursorName
- fetchDirection
- maxFieldSize
- maxRows
- queryTimeout
SybaseDataStoreHelper
resets all of the 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 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
doStatementCleanup
in class GenericDataStoreHelper
stmt
- the PreparedStatement. 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.PortableSQLException
subclass corresponding to the specified SQLException
, as defined by the
SybaseDataStoreHelper
, 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 GenericDataStoreHelper
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
getIsolationLevel
- public 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 SybaseDataStoreHelper
is
Connection.TRANSACTION_REPEATABLE_READ.
In the case where an AccessIntent
is specified,
SybaseDataStoreHelper
computes the transaction isolation level as follows:
If the concurrency control is
AccessIntent.CONCURRENCY_CONTROL_OPTIMISTIC
then a transaction isolation level ofConnection.TRANSACTION_READ_COMMITTED
is returned.If the concurrency control is
AccessIntent.CONCURRENCY_CONTROL_PESSIMISTIC
and the access type isAccessIntent.ACCESS_TYPE_READ
then a transaction isolation level ofConnection.TRANSACTION_REPEATABLE_READ
is returned.If the concurrency control is
AccessIntent.CONCURRENCY_CONTROL_PESSIMISTIC
and the access type isAccessIntent.ACCESS_TYPE_UPDATE
then 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_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 DataStoreHelper
getIsolationLevel
in class GenericDataStoreHelper
aIntent
- An AccessIntent
AccessIntent
. javax.resource.ResourceException
- If a transaction isolation level cannot be determined
from the AccessIntent
. AccessIntent
,
Connection
showLockInfo
- public final java.lang.String showLockInfo( java.util.Properties props)
- throws java.lang.Exception
This method returns lock information for Sybase. The
props
parameter may include the following properties:
- user - a user name that has a DBA authority. If not specified, the default value is null.
- password - the password corresponding to the user name. If not specified, the default value is null.
- serverName - the name of the server where the Sybase database resides.
- portNumber - the port where Sybase is listening for connections.
- databaseName - the database name. If not specified, a default value of "" (empty string) is used.
showLockInfo
in class GenericDataStoreHelper
props
- properties containing information needed to connect to the database. 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 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
setUserDefinedMap
in class GenericDataStoreHelper
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
getPrintWriter
- public java.io.PrintWriter getPrintWriter( )
DataSource
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
getPrintWriter
in class GenericDataStoreHelper
java.io.PrintWriter
. 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.
SybaseDataStoreHelper
checks the SQLWarnings
on the
connection to determine if a connection was made to the requested database.
If the requested database does not exist, Sybase's
standard behavior is to connect a "default database" and log a SQLWarning
.
This method scans for this SQLWarning
and if found, throws a
SQLException
based on the contents of the SQLWarning
indicating that a connection to the requested database could not be established.
doConnectionSetup
in interface DataStoreHelper
doConnectionSetup
in class GenericDataStoreHelper
conn
- the connection to set up. 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.
If the connection returned to the pool is from a SybXADataSource
, then
SybaseDataStoreHelper
calls setAutoCommit(true)
on the
connection. This is to handle a case where the jConnect AutoCommit state becomes
incoherent if the AutoCommit state was false when a XA transaction was started.
Forcing AutoCommit true here will resynchronize the jConnect AutoCommit state so
when the connection is next used from the pool, it will behave properly.
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.
If SybaseDataStoreHelper
calls setAutoCommit(true)
,
this method will return a value of true.
conn
- the connection to attempt to cleanup. java.sql.SQLException
- If an error occurs while cleaning up the connection. Connection
SybaseDataStoreHelper
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.