Database Connection Management

Use

Basics

The management of the database connections follows the basic rules, which the Connector Container Service applies to the connections to other types of EIS. The specific feature about working with the database connections is the option to cache SQL statements.

From the transaction management perspective, there are four possible states of each connection:

  • Closed

  • Active and enlisted in a JTA transaction

  • Active and enlisted in a local transaction

  • Active and not enlisted in a transaction

To reduce costs and time consumption, the AS Java provides connection pooling which comprises a single-time creation of connections and their reusability. Different applications share the connection pools.

More information:

Sharing Connections

Connection Pooling

Automatic Connection Cleanup

Sometimes an application does not close a connection, that is, it does not return it to the pool, or the application uses the connection for a long time. This prevents other applications from using the connection and increases their waiting time, making their performance unacceptably slower.

The automatic connection dissociation mechanism is implemented as a solution to this problem.

After each call to a Web component (servlet, JSP, portal, iView) or to a stateless EJB method, the mechanism checks for active connections and closes them, if possible. The same check is also performed after a commit/rollback of a JTA transaction or a local transaction.

Different resource adapters provide different connections and from the database connection management perspective, resource adapters are divided into three groups depending on their properties:

  • Resource adapters which support dissociation

    When the resource system determines a connection handle as not in a transaction, the resource adapter can dissociate the physical connection from this connection handle, thus releasing the physical connection for further use. In this case, the application can still use the connection handle associated with a new physical connection.

    JDBC Connector (DB) connections support dissociation.

  • Resource adapters which support reassociation but do not support dissociation

    The connection handle can be associated with another physical connection but cannot be dissociated.

  • Resource adapters which do not support dissociation or reassociation

Stateless Components

After the stateless component's method ends, the system performs the following operations depending on the connection state and the relevant resource adapter properties:

Connection State

Resource Adapter Supports Dissociation

Resource Adapter Supports Reassociation

Resource Adapter Does Not Support Dissociation or Reassociation

Closed

No action

No action

No action

Active and enlisted in a JTA transaction

The connection handle is dissociated but remains usable.

The physical connection is returned to the connection pool when the transaction is completed.

The connection handle is reassociated with a new physical connection which is not in a JTA transaction.

The physical connection is returned to the connection pool when the transaction is completed.

The application server attempts to reassociate the connection handle with a new physical connection that is not in a JTA transaction.

Active and enlisted in a local transaction

The physical connection is returned to the connection pool.

The connection handle remains unusable.

The physical connection is returned to the connection pool.

The connection handle remains unusable.

The physical connection is returned to the connection pool.

The connection handle remains unusable.

Active and not enlisted in a transaction

The connection handle is dissociated but remains usable.

The physical connection is returned to the connection pool.

No action

No action

Stateful Components

JTA Transactions

After a commit/rollback of a JTA transaction, the system performs the following operations depending on the connection state and the relevant resource adapter properties:

Connection State

Resource Adapter Supports Dissociation

Resource Adapter Supports Reassociation

Resource Adapter Does Not Support Dissociation or Reassociation

Closed

No action

No action

No action

Active

The connection handle is dissociated but remains usable.

The physical connection is returned to the connection pool.

The connection handle is reassociated with a new physical connection which is not in a JTA transaction.

The application server attempts to reassociate the connection handle with a new physical connection that is not in a JTA transaction.

Local Transactions

After a commit/rollback of a local transaction, the system performs the following operations depending on the relevant resource adapter properties:

Connection State

Resource Adapter Supports Dissociation

Resource Adapter Supports Reassociation

Resource Adapter Does Not Support Dissociation or Reassociation

Active

The physical connection is returned to the pool.

The connection handle remains unusable.

No action

No action