Class SybaseDataStoreHelper
- java.lang.Object
-
- com.ibm.websphere.rsadapter.GenericDataStoreHelper
-
- com.ibm.websphere.rsadapter.SybaseDataStoreHelper
-
- All Implemented Interfaces:
DataStoreHelper
- Direct Known Subclasses:
Sybase11DataStoreHelper
public class SybaseDataStoreHelper extends GenericDataStoreHelper
SybaseDataStoreHelperis aDataStoreHelperimplementation customized for the Sybase database. When mapping aSQLException, theSQLExceptionmappings from theSybaseDataStoreHelperare searched first, and subsequently, if no match is found, theSQLExceptionmappings from theGenericDataStoreHelperare 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.SQLExceptionmappings specific to theSybaseDataStoreHelperare the following:Error Code SQL State PortableSQLExceptionsubclass2601 DuplicateKeyException.classJZ0C0 StaleConnectionException.classJZ0C1 StaleConnectionException.class
-
-
Field Summary
-
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 Description SybaseDataStoreHelper(java.util.Properties props)ThisSybaseDataStoreHelperconstructor creates a newGenericDataStoreHelperbased on theDataStoreHelperproperties provided.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleandoConnectionCleanup(java.sql.Connection conn)This method is used to clean up a connection before it is returned to the connection pool for later reuse.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 theSybaseDataStoreHelper,GenericDataStoreHelper, and user-definedSQLExceptionmaps.intgetIsolationLevel(AccessIntent aIntent)This method determines the transaction isolation level to use as default for the database backend.java.io.PrintWritergetPrintWriter()This method is used to obtain a log writer to set on theDataSourcewhen database logging is enabled (for example:WAS.database=all=enabled).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 lock information for Sybase.-
Methods inherited from class com.ibm.websphere.rsadapter.GenericDataStoreHelper
calcPartitionNumber, doConnectionCleanupPerCloseConnection, doConnectionCleanupWithValidCheck, doConnectionSetupPerGetConnection, doConnectionSetupPerTransaction, getLockType, getMetaData, getPasswordForUseWithTrustedContextWithAuthentication, getResultSetConcurrency, getResultSetType, getXAExceptionContents, hasLostUpdateOrDeadLockOccurred, isBatchUpdateSupportedWithAccessIntent, isConnectionError, isDuplicateKey, isTransientConnectionError, isUnsupported, mapException, modifyXAFlag, setConfig
-
-
-
-
Constructor Detail
-
SybaseDataStoreHelper
public SybaseDataStoreHelper(java.util.Properties props)
ThisSybaseDataStoreHelperconstructor creates a newGenericDataStoreHelperbased 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
-
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 that will be cached. It is called only if at least one of the following statement properties has changed,
- cursorName
- fetchDirection
- maxFieldSize
- maxRows
- queryTimeout
SybaseDataStoreHelperresets all of the 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 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:
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 theSybaseDataStoreHelper,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.
-
getIsolationLevel
public int getIsolationLevel(AccessIntent aIntent) throws javax.resource.ResourceException
This method determines the transaction isolation level to use as default for the database backend. The default transaction isolation level forSybaseDataStoreHelperisConnection.TRANSACTION_REPEATABLE_READ.- Specified by:
getIsolationLevelin interfaceDataStoreHelper- Overrides:
getIsolationLevelin classGenericDataStoreHelper- Parameters:
aIntent- always null in Liberty.- Returns:
- A transaction isolation level.
- Throws:
javax.resource.ResourceException- If a transaction isolation level cannot be determined.
-
showLockInfo
public final java.lang.String showLockInfo(java.util.Properties props) throws java.lang.ExceptionThis method returns lock information for Sybase. The
propsparameter 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.
- 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 Liberty 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.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.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, theDataStoreHelperimplementations map the exception toUserDefinedException.Additionally, mapping done by the built-in
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.Void.classmay also be used for 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 a log writer to set on theDataSourcewhen database logging is enabled (for example:WAS.database=all=enabled). By default, null is returned and ajava.io.PrintWriterinstance created by Liberty 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.
-
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.
SybaseDataStoreHelperchecks theSQLWarningson 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 aSQLWarning. This method scans for thisSQLWarningand if found, throws aSQLExceptionbased on the contents of theSQLWarningindicating that a connection to the requested database could not be established.- 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.
-
doConnectionCleanup
public boolean doConnectionCleanup(java.sql.Connection conn) throws java.sql.SQLExceptionThis method is used to clean up a connection before it is returned to the connection pool for later reuse. Liberty 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, thenSybaseDataStoreHelpercallssetAutoCommit(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 Liberty that at least one standard connection property was modified. A value of false is returned only if no standard connection properties were modified.
If
SybaseDataStoreHelpercallssetAutoCommit(true), this method will return a value of true.- Specified by:
doConnectionCleanupin interfaceDataStoreHelper- Overrides:
doConnectionCleanupin classGenericDataStoreHelper- 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.
-
-