How database transactions are recovered

When the Liberty transaction manager recovers indoubt database transactions, it uses either the unique identifier or the JNDI name to locate the current dataSource element, and then determines the user ID and password to use for recovery.

Configure a data source by specifying the attributes of the dataSource element in the server.xml configuration file. You can assign a unique identifier or a jndiName attribute for the data source as follows:

<dataSource id="ds1" jndiName="jdbc/ds1"... />

You must not change the value of the id or jndiName attribute when a recovery is pending for a transaction in which the data source participated. If you change any other attributes of the dataSource element, those changes are retained for the recovery. Therefore, you can, for example, add a recoveryAuthDataRef attribute that specifies a database user ID and password to use for recovery.

The database user ID and password to use for recovery are determined according to the following order of precedence:
  1. If the dataSource element has the recoveryAuthDataRef attribute defined, then the user ID and password from the authData element are used. For example:
    <authData id="recoveryAuth" user="dbuser1" password="{xor}Oz0vKDtu"/>
    <dataSource id="ds1" jndiName="jdbc/ds1" jdbcDriverRef="DB2" 
                recoveryAuthDataRef="recoveryAuth" .../>
  2. If container-managed authentication is used, then the user ID and password from the container-managed authentication alias are used. For example:
    • In the ibm-web-bnd.xml file, you have the following code:
      <resource-ref name="jdbc/ds1ref" binding-name="jdbc/ds1">
          <authentication-alias name="user1Auth"/>
       </resource-ref>
    • In the server.xml file, you must define the following code:
      <authData id="user1Auth" user="dbuser1" password="{xor}Oz0vKDtu"/>
      <dataSource id="ds1" jndiName="jdbc/ds1" jdbcDriverRef="DB2" .../>
  3. The user ID and password from the dataSource element are used. For example:
    <dataSource id="ds1" jndiName="jdbc/ds1" jdbcDriverRef="DB2" ...>
         <properties.db2.jcc databaseName="testdb" user="dbuser1" password="{xor}Oz0vKDtu"/>
    </dataSource>
  4. If none of the previous conditions are satisfied, and the recovery is attempted without any user ID and password, then the behavior is determined by the JDBC driver and database.
Note: If the transaction recovery is performed by an application-defined data source, such as an @DataSourceDefinition annotation or a <data-source> element in the deployment descriptor, you must ensure that the associated application is running when the recovery is taking place. You cannot use configuration settings in the server.xml file to recover application-defined data sources.