JDBC mediator transactions

 

Mediator managed transactions

A JDBC connection is wrapped in a connection wrapper and passed to the Data Mediator Service (DMS) at instance creation. The ConnectionWrapper object contains the connection used by the JDBC DMS and indicates whether the mediator manages the current transaction. When the JDBC DMS is managing the transaction, it performs commit and rollback operations as required. However, it does not perform any transaction management activities if the wrapped connection is currently engaged in another transaction.

The default action is to manage transactions.

 

Non-mediator managed transactions

When a passive connection wrapper is created for use by the mediator, then the mediator assumes that there is an existing transaction and that it is being managed externally. No commit or rollback operations are performed by the connection wrapper in this case.

 

Optimistic concurrency control

Optimistic concurrency control (OCC) assumes that data collisions are rare when multiple clients update the same backend data concurrently. A data collision is when the data that was used to populate the client’s DataGraph is changed in the database before submitting the changes made to the data. When a data collision does occur, the JDBC DMS causes an exception to occur. The client application must determine how to recover from the collision. For example, the client can re-read the data and restart the transaction. Once one exception occurs, there is no way of knowing whether there are more exceptions deeper in the DataGraph than the DataObject that cause the displayed exception. An OCC column is not created by default on a table, create one manually. You do this by adding an OCC Integer column to the table and then specifying that this column is to be used for OCC in the Metadata. The defined OCC collision column is reserved for the exclusive use of the mediator.

Setting the OCC Column

In order to take advantage of OCC, have a column in the table created for this purpose. Here is how you do this

Column collisionColumn = table.addIntegerColumn("OCC_COUNT");
 collisionColumn.setNullable(false);
 table.setCollisionColumn(collisionColumn);
This creates the OCC column and makes sure that it does not allow null values, then designates it as the table collision column. If there is no OCC column defined for a table, then the DMS does not monitor and notify for update collisions.

We can see a code example that forces a collision to demonstrate detection and shows the exception that occurs as a result at Example: OCC data collisions and JDBC mediator.

 

See also


JDBC mediator exceptions
Example: OCC data collisions and JDBC mediator