Class InformixDataStoreHelper

  • All Implemented Interfaces:
    DataStoreHelper

    public class InformixDataStoreHelper
    extends GenericDataStoreHelper
    InformixDataStoreHelper is a DataStoreHelper implementation customized for the Informix database. When mapping a SQLException, the SQLException mappings from the InformixDataStoreHelper are searched first, and subsequently, if no match is found, the SQLException mappings from the GenericDataStoreHelper are searched. If you have additional requirements on Informix, 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 InformixDataStoreHelper are the following:

    Error CodeSQL StatePortableSQLException subclass
    -79735StaleConnectionException.class
    -79716StaleConnectionException.class
    -43207StaleConnectionException.class
    -27002StaleConnectionException.class
    -25580StaleConnectionException.class
    -908StaleConnectionException.class
    -710StaleStatementException.class
    -268DuplicateKeyException.class
    43012StaleConnectionException.class
    • Constructor Detail

      • InformixDataStoreHelper

        public InformixDataStoreHelper​(java.util.Properties props)

        This InformixDataStoreHelper constructor creates a new InformixDataStoreHelper based on the DataStoreHelper properties provided.

        The DataStoreHelper properties for InformixDataStoreHelper include an integer property, informixLockModeWait, representing Informix's timeout when waiting for a lock. A value greater than 0 indicates the number of seconds Informix waits for a lock, after which Informix throws an exception. A value of 0 means Informix does not wait for locks at all, immediately throwing an exception. A value less than 0 means Informix waits indefinitely, until the lock it is waiting for is released. Informix's default behavior is to immediately throw an exception. However, Liberty's default setting for informixLockModeWait (which is specified as ifxIFX_LOCK_MODE_WAIT on properties.informix) is 2, meaning Informix waits for a lock for two seconds before throwing an exception.

        Parameters:
        props - DataStoreHelper properties.
    • Method Detail

      • 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 InformixDataStoreHelper, 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 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.

        Overrides:
        findMappingClass in class GenericDataStoreHelper
        Parameters:
        e - The SQLException for which to locate a com.ibm.websphere.ce.cm.PortableSQLException subclass.
        Returns:
        The com.ibm.websphere.ce.cm.PortableSQLException subclass matching the SQLException, or null if no match was found.
      • getIsolationLevel

        public int getIsolationLevel​(AccessIntent intent)
                              throws javax.resource.ResourceException
        This method determines the transaction isolation level to use as default. The default transaction isolation level for InformixDataStoreHelper is Connection.TRANSACTION_REPEATABLE_READ.
        Specified by:
        getIsolationLevel in interface DataStoreHelper
        Overrides:
        getIsolationLevel in class GenericDataStoreHelper
        Parameters:
        intent - always null in Liberty.
        Returns:
        A transaction isolation level.
        Throws:
        javax.resource.ResourceException - If a transaction isolation level cannot be determined.
      • 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.

        The following actions are prohibited in this method:

        1. Changing any standard connection properties found on the java.sql.Connection API. This includes TransactionIsolationLevel, AutoCommit, Catalog, ReadOnly, TypeMap, and Holdability.
        2. Closing the connection.

        The InformixDataStoreHelper configures the Informix IFX_ALLOW_NEWLINE based on the informixAllowNewLine DataStoreHelper property.

        Specified by:
        doConnectionSetup in interface DataStoreHelper
        Overrides:
        doConnectionSetup in class GenericDataStoreHelper
        Parameters:
        conn - the connection to set up.
        Throws:
        java.sql.SQLException - if connection setup cannot be completed successfully.
      • 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 being cached. It is called only if at least one of the following statement properties has changed,

        • cursorName
        • fetchDirection
        • maxFieldSize
        • maxRows
        • queryTimeout

        InformixDataStoreHelper resets all of the statement 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 Liberty when caching statements,

        • setFetchSize(0)
        • clearParameters()
        • clearWarnings()

        A helper class implementing this method can 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 interface DataStoreHelper
        Overrides:
        doStatementCleanup in class GenericDataStoreHelper
        Parameters:
        stmt - the PreparedStatement.
        Throws:
        java.sql.SQLException - if an error occurs cleaning up the statement.
      • 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 Liberty 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.

        Example usage of the setUserDefinedMap method:

            public MyCustomDataStoreHelper()
            {
               ...
               java.util.HashMap MyErrorMap = new java.util.HashMap(2);
               myErrorMap.put(-801, MyDuplicateKeyException.class);
               myErrorMap.put(-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 DataStoreHelper implementations map the exception to UserDefinedException.

        Additionally, mapping done by the DataStoreHelpers does not include mapping by chained exceptions when no match is found for the original exception.

        Specified by:
        setUserDefinedMap in interface DataStoreHelper
        Overrides:
        setUserDefinedMap in class GenericDataStoreHelper
        Parameters:
        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. You can also use Void.class for the value, in which case any existing mapping for the specified SQL State or Error Code is removed.
      • getPrintWriter

        public 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). By default, null is returned and a java.io.PrintWriter instance created by Liberty is used. You can override this method to return a different java.io.PrintWriter instance instead of the default.
        Specified by:
        getPrintWriter in interface DataStoreHelper
        Overrides:
        getPrintWriter in class GenericDataStoreHelper
        Returns:
        java.io.PrintWriter.