Skip to main content

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).


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"
  <AM-Pooling jbo.ampool.connectionstrategyclass="fmwk.extension.CustomDatabaseConnectionStrategy"/>
  <Security AppModuleJndiName="test.AppModule"/>

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


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

Popular posts from this blog

How to set Bind Variable Values at runtime ?

In this post I'm sharing a couple of approaches for programmatically setting bind variables values at run time. This post is an attempt to explain 'When to use what ?'[ In case if you are familiar with 'Bind Variables' in ADF BC, please refer Section 5.10, Working with Bind Variables in Fusion Developer's Guide ]

1. Set the Bind Variable value using RowSet::setNamedWhereClauseParam(...)

You can use use the setNamedWhereClauseParam(...) method on the ViewObject interface (which extends oracle.jbo.RowSet) to set the value for bind variables. Please note this sets the value on default RowSet. In other words, this doesn't have any effect on the secondary RowSets that you/system generates.
ViewObject vo = am.findViewObject("EmployeesView1"); vo.setNamedWhereClauseParam("bindVarDeptId", new Number(10)); vo.executeQuery();
2. Set the Bind Variable value using ViewObject's VariableValueManager::setVariableValue(...)

VariableValueManager Ma…

Happy New Year 2018 !

We can't go back and change the beginning, but we always can start where we are and change the ending. Believe in yourself and you will be unstoppable!

Wishing you and your family a very happy new year 2018 !!!