XA function supported by Db2

Db2 supports the XA91 specification defined in X/Open CAE Specification Distributed Transaction Processing: The XA Specification, with the following exceptions:

  • Asynchronous services

    The XA specification allows the interface to use asynchronous services, so that the result of a request can be checked at a later time. The database manager requires that the requests be invoked in synchronous mode.

  • Registration
    The XA interface allows two ways to register an RM: static registration and dynamic registration. Db2 supports both dynamic and static registration. Db2 provides two switches to control the type of registration used.
    • db2xa_switch_std for dynamic registration
    • db2xa_switch_static_std for static registration
  • Association migration

    The Db2 product does not support transaction migration between threads of control.

XA switch usage and location

As required by the XA interface, the database manager provides a db2xa_switch_std and a db2xa_switch_static_std external C variable of type xa_switch_t to return the XA switch structure to the TM. Other than the addresses of various XA functions, the following fields are returned:

Field
Value
name
The product name of the database manager. For example, IBM® Db2 Version 9.7 for AIX®.
flags
For db2xa_switch_std TMREGISTER | TMNOMIGRATE is set

Explicitly states that the Db2 product uses dynamic registration, and that the TM should not use association migration. Implicitly states that asynchronous operation is not supported.

For db2xa_switch_static_std TMNOMIGRATE is set

Explicitly states that the Db2 product uses static registration, and that the TM should not use association migration. Implicitly states that asynchronous operation is not supported.

version
Must be zero.

Using the Db2 XA switch

The XA architecture requires that a Resource Manager (RM) provide a switch that gives the XA Transaction Manager (TM) access to the RM's xa_ routines. An RM switch uses a structure called xa_switch_t. The switch contains the RM's name, non-NULL pointers to the RM's XA entry points, a flag, and a version number.

Linux® and UNIX

The switch for Db2 can be obtained through either of the following two ways:

  • Through one additional level of indirection. In a C program, this can be accomplished by defining the macro:
       #define db2xa_switch_std (*db2xa_switch_std)
       #define db2xa_switch_static_std (*db2xa_switch_std)
    prior to using db2xa_switch_std or db2xa_switch_static_std.
  • By calling db2xacic_std or db2xacicst_std
    Db2 provides these APIs, which return the address of the db2xa_switch_std or db2xa_switch_static_std structure. This function is prototyped as:
       struct xa_switch_t * SQL_API_FN  db2xacic_std( )
       struct xa_switch_t * SQL_API_FN  db2xacicst_std( )

With either method, you must link your application with libdb2.

Windows

The pointer to the xa_switch structure, db2xa_switch_std, or db2xa_switch_static_std is exported as DLL data. This implies that a Windows application using this structure must reference it in one of three ways:

  • Through one additional level of indirection. In a C program, this can be accomplished by defining the macro:
       #define db2xa_switch_std (*db2xa_switch_std)
       #define db2xa_switch_static_std (*db2xa_switch_std)
    prior to using db2xa_switch_std or db2xa_switch_static_std.
  • If using the Microsoft Visual C++ compiler, db2xa_switch_std or db2xa_switch_static_std can be defined as:
       extern __declspec(dllimport) struct xa_switch_t db2xa_switch_std
       extern __declspec(dllimport) struct xa_switch_t db2xa_switch_static_std
  • By calling db2xacic_std or db2xacicst_std
    Db2 provides this API, which returns the address of the db2xa_switch_std or db2xa_switch_static_std structure. This function is prototyped as:
       struct xa_switch_t * SQL_API_FN  db2xacic_std( )
       struct xa_switch_t * SQL_API_FN  db2xacicst_std( )

With any of these methods, you must link your application with db2api.lib.

Example C Code

The following code illustrates the different ways in which the db2xa_switch_std or db2xa_switch_static_std can be accessed via a C program. Be sure to link your application with the appropriate library.

   #include <stdio.h>
   #include <xa.h>

   struct xa_switch_t * SQL_API_FN  db2xacic_std( );

   #ifdef DECLSPEC_DEFN
   extern __declspec(dllimport) struct xa_switch_t db2xa_switch_std;
   #else
   #define db2xa_switch_std (*db2xa_switch_std)
   extern struct xa_switch_t db2xa_switch_std;
   #endif
main( )
   {
      struct xa_switch_t *foo;
      printf ( "switch_std.name );
      foo = db2xacic_std();
      printf ( "name );
      return ;
   }