Example: Using IBM extended APIs for database connections
Use the WSDataSource extended API, you can code your 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 your application runs with a shareable connection that might be shared with other container-managed persistence (CMP) beans within a transaction, it is recommended that you use the WAS extended APIs to get the connection. When you use these APIs, you cannot port your application to other appservers.
You can code with the extended API directly in your 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
Resource adapters
Unshareable and shareable connections
Related Reference
Extensions to data access APIs
Reference topic