Running ApplicationModule using an external JDBC connection

Use case

This post discusses a bit odd use case. This requirement arose while migrating a huge system built on Java to ADF technology stack. When choosing modules for migration(in a step by step manner), there are chances that a specific service may need to compose business methods from existing legacy system and newly build ADF BC modules. Now the fun starts, functional testing team may not be aware of the underlying migration phases. So there may be cases where existing java code and partially migrated ADF BC modules needs to participate in the same database transaction. This is an easy task if the existing system is based on XADataSource to access database. You may just need to make sure that your ApplicationModule is configured to use the same XADatasource. What if that's not the case? You may need to share same raw JDBC Connection between two implementations. This post discusses a possible solution for this scenario. Please note that, I'm not recommending this approach/solution for a production system. However, this may be useful for certain scenarios as explained above( to carry out an end to end intermediate functionality testing while migrating existing Java applications to use ADF in multiple stages).

Solution

Idea is to store the java.sql.Connection used by the POJO caller in the ThreadLocal instance and customize DBTransactionImpl class from the ApplicationModule to use this Connection. This in turn ensures that ViewObjects/EntityObjects are using the same connection instance supplied by the POJO caller. Please note ADF BC layer let you to override the default DBTransactionImpl using custom DatabaseTransactionFactory class. The customized bc4.xcfg file used for building the attached sample is listed in the following diagram. Please refer the sample project source to learn more.


<AppModuleConfig DeployPlatform="LOCAL" jbo.project="test.Model" JDBCName="DeleteMeLater"
   name="AppModuleLocal" SessionClass="fmwk.extension.CustomSessionImpl"
   TransactionFactory="fmwk.extension.CustomDatabaseTransactionFactory"
   ApplicationName="test.AppModule">
  <AM-Pooling jbo.ampool.connectionstrategyclass="fmwk.extension.CustomDatabaseConnectionStrategy"/>
  <Security AppModuleJndiName="test.AppModule"/>
</AppModuleConfig>

You can download the sample workspace from here.
Run TestAM.java
[Runs with Oracle JDeveloper 11g R1 PS2 + HR Schema]

Comments

Sameh Nassar said…
Good post.

But I want to ask you a question out of your post and out of ADF scope, In your post you type a source code inside square how you do that? Thank You

Sameh Nassar

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of my employer.