Tuesday, May 17, 2016

ADF Taskflow Transactions Management and Datacontrol scope - Part 3

In our previous post we had discussions about how DataControl Scopes and multiple Application Module Transactions interact with each other.

Lets use the same application used in previous post and discuss more about Taskflow Transactions Management

What is Transaction management in taskflow?
Transactions are managed by the Application Modules, As an application grows we might want to use multiple data controls from different application modules in a single view.

Eg : If we use datacontrol from 3 different application modules (Assuming they are not nested in Data Model) in one taskflow view, then we end up with 3 Root App Modules = 3 Database connections and the important part is we need 3 separate commits to post all changes to DB.

ADF taskflows offer an elegant solution to such problems,  that is to manage Transactions at taskflow level.

Lets see how it works -

Case 3 :
Parent Taskflow
Transaction - Always Begin New Transaction
Data Control Scope - ISOLATED

Child Taskflow
Transaction - Use Existing Transaction if possible
Data Control Scope - SHARED

As we saw in Case 1 and 2, each Application module is created as Root with separate Transactions.
In Case 3 lets make the Parent Taskflow to begin new Transaction and Child to Use the Existing Transaction.

This is how it works internally -






























Key Observations -

1) Parent Taskflow begins a new Transaction at Taskflow level and Child taskflow uses the same.

2) Only  Root Application Module(App module 1) is created and App module 2 is nested inside App Module 1. Hence overall only 1 Transaction and 1 DB Connection is used across different application modules and taskflows.

3) Only one DCFrame is used.

4) A commit/rollback in any iterator will commit the changes to DB since they use one Transaction.
There is also a better way to do it using taskflow return, which we can discuss later in different post.


Check out the flow in a real example, 
Notice that only one Transaction is used in all 4 iterators.







































Similarly we can create multiple cases based on different Transaction management and Datacontrol scope options, But with the above examples you will be able to figure out those combinations pretty easily.

Eg : 
Case 4 :
Parent Taskflow
Transaction - No Controller Transaction
Data Control Scope - ISOLATED

Child Taskflow
Transaction - Always Begin New Transaction
Data Control Scope - ISOLATED

Parent taskflow will use 2 Transactions and Child will use 1.

Case 5 :
Parent Taskflow
Transaction - No Controller Transaction
Data Control Scope - ISOLATED

Child Taskflow
Transaction - Use Existing Transaction if possible
Data Control Scope - ISOLATED

Parent taskflow will use 2 Transactions and Child creates a new Transaction since no new transaction already exists in taskflow layer.

we can go on and on.. 


In my opinion, Don't use Transaction management options unless you absolutely sure of its use.. 
In most cases you needn't use it.

In simple terms - 
Data Control Scope - To manage DC Frames.
Transaction management options - To manage DB Transactions in taskflow layer instead of in the model layer using Application Modules.

You can checkout the application used in these blog posts from
https://github.com/bsatishinbox/FusionSamples/tree/master/TransactionFlows


Hope this helps.. :-) 







2 comments:

  1. When i run the application its asking the username and password.
    What is the username and password?

    ReplyDelete
    Replies
    1. Hi,

      Its any username and password in your realm.

      Delete