Friday, February 28, 2014

Application Module Connection Sharing - Code Example Proof

There is a excellent and very informative video on AM Connection Sharing by Chris Muir where he describes how Multiple Root application modules due to sharing of ADF Library jars can be made to use single connection under the covers by using powerful feature of transaction management in task flows. Thanks to Chris for explaining this wonderful concept. Here is the link to the video AM Connection Sharing .

In this post we will see this powerful concept with the help of code example. Below is the concept:

"If there are multiple root AM's may be due to shared libraries, if task flows are used with default No Controller Transaction option, then there will be as many number of connections to DB as number of Root AM's. On the other hand if task flows in the application uses any of the three Transaction Option, then there will be Only Single connection to the DB be there any number of Root AM's , i.e. connection will be shared."



Below is the picture of the workspaces and components we will be using in jdeveloper.

The first workspace is CommonWorkspace. This has simple EO , VO and Application Module. This is shared as ADF Lib jar to the second project. Second project is named as CustomFirstWorkspace (There can be CustomNworkspaces) . This project has its own EO, VO and AM named CustomEO,CustomVO and CustomFirstApplicationModule.

Now Since CommonWorkspace is imported as ADF Library Jar in CustomFirstWorkspace, it has two DataControls because of two ApplicationModules. This in turn means it has TWO DB connections.

The View Project has a Task Flow, which has a jsff which uses VO from both the AM(DC) to create a table and a form using each VO respectively.

Lets get started and do actual coding :)


Create a Fusion Web App in Jdev as below. Its a simple app having EO,VO and Application module in model project. View Project is empty. Used HR schema with HR as user to connect to DB.



Now create a deploy profile of Model project as Create ADF Lib Jar . The jar will be created.

Now create a new application CustomFirstApplication with default EO,VO and AM but with different names.



Create a Resource connection and add ADF Lib jar of CommonWorkspace to ViewController project of CustomFirstApplication.



Now since the CustomFirstApplication project is having adf lib jar of CommonWorkspace project, there will be two DataControls for both AM's as shown.


Now create a Task Flow in view project of CustomFirstApplication. Create a JSFF inside it and use EmployeesVO1 from first DC to create a table and EmployeesCustomVO1 from second DC to create a form.




The page.jsff has tow VO's which correspond to two different AM (means 2 different DB Connections on run time)

Lets run the page and verify. Create a test.jspx and add taskflow as region and run it.

Below is the output of the page.



Now if we check the DB for user sessions, it shows 2 DB session as below.


This is the case when we used default (No Controller Transaction) option with the Task Flow.

Now lets stop the server and change the Task Flow Transaction option. Use one of the three transaction options. Here Use Existing If Possible option is used.




Now save and run the page again. When page runs, check the number of session in the DB.



We can see , by using just Transaction option in Task Flows, the connection is shared under the covers, even though there are different Root AM's due to shared libraries.

If two user sessions are there then application with task flow with No Controller Option will have 4 DB sessions while application with TaskFlow Option set will have only 2 sessions.  No Controller Option can really impact the performance if there are more shared libraries and large users that access the application.



Thanks


4 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. hi Rohan ,but what about if i consume a BTF that use Am with different connection Details such different schema ?

    ReplyDelete
  3. Trying to find the Ultimate Dating Site? Join to find your perfect date.

    ReplyDelete
  4. BlueHost is definitely the best web-hosting provider for any hosting services you require.

    ReplyDelete