Example: Using IBM extended APIs for database connections
Use the WSDataSource extended API, we can code the JDBC application to define connection properties through an object before obtaining a connection. This behavior increases the chances that the application can share a connection with another component, such as a CMP.
If the application runs with a shareable connection that might be shared with other container-managed persistence (CMP) beans within a transaction, IBM recommends that you use the WAS extended APIs to get the connection. When you use these APIs, we cannot port the application to other appservers.
We can code with the extended API directly in the JDBC application; instead of using the DataSource interface to get a connection, use the WSDataSource interface.
The following code segment illustrates WSDataSource:
import com.ibm.websphere.rsadapter.*; ... // Create a JDBCConnectionSpec and set connection properties. If this connection is shared with the CMP bean, make sure that the isolation level is the same as the isolation level that is mapped by the Access Intent defined on the CMP bean.JDBCConnectionSpec connSpec = WSRRAFactory.createJDBCConnectionSpec(); connSpec.setTransactionIsolation(CONNECTION.TRANSACTION_REPEATABLE_READ); connSpec.setCatalog("DEPT407"); //Use WSDataSource to get the connection
Connection conn = ((WSDataSource)datasource).getConnection(connSpec);
Related concepts
Relational resource adapters and JCA
Unshareable and shareable connections
Related
Extensions to data access APIs