Transaction across multiple adapters?

Posts   
 
    
Posts: 33
Joined: 31-May-2005
# Posted on: 14-Jun-2006 21:21:31   

How can I string a transaction across multiple DataAccessAdapters that are all pointing to the same database? I know this has been discussed, but the solution never seemed very clear (or just contained snippets of code rather than a full description or code sample).

Here's our situation ... we have an application that uses multiple modules: - Main app - Generic, DBSpecific, manager, and GUI projects - Logging module - Generic, DBSpecific, manager and GUI projects - Workflow module - Generic, DBSpecific, manager, and GUI projects

The modules actually pull from the same database as the main app, which allows us to easily attach these modules to any of our applications by simply running the SQL.

Our problem is that in many cases, we want the modules to participate in transactions from the main application. For example, if a long running transaction occurs in the main app, we don't want interim logging to show up if the transaction is rolled back. Logically, it seems like we should just be able to copy the transaction and connection from one adapter to another, but I don't see how this is possible.

Any ideas? Thanks, Josh

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 15-Jun-2006 00:20:27   

A user had a similar issue a while back. Does this post help? http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=4670&HighLight=1

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 15-Jun-2006 10:20:45   
Frans Bouma | Lead developer LLBLGen Pro
Posts: 33
Joined: 31-May-2005
# Posted on: 15-Jun-2006 15:05:44   

bclubb wrote:

A user had a similar issue a while back. Does this post help? http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=4670&HighLight=1

I had seen these examples, but does this mean I need to override the adapter in both my main app and each module (we actually have a bunch of modules, I just used 2 as an example)? This seems like a lot of work just to grab the transaction and connection.

Our usage of LLBL seems like something that would be fairly common in larger organizations. I know I could modify the base class to expose the transaction + connection, this way I wouldn't need to change any of my code ... but I was reluctant to change the base code if there was already a viable option. Maybe I'm missing something ...

Thanks, Josh

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 15-Jun-2006 15:22:59   

JoshLindenmuth wrote:

bclubb wrote:

A user had a similar issue a while back. Does this post help? http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=4670&HighLight=1

I had seen these examples, but does this mean I need to override the adapter in both my main app and each module (we actually have a bunch of modules, I just used 2 as an example)? This seems like a lot of work just to grab the transaction and connection.

You need to create a derived class of the DataAccessAdapter class and in there perform the code as suggested there. In general, it's not recommended, because the dataaccessadapter class does housekeeping on which elements participate in a transaction. Sharing a transaction among adapter objects isn't going to work in some occasions.

Much better is to use a unitofwork and store the work to be done in there, then commit the in 1 go using a single adapter instance. Then you don't have to share anything, just collect work and commit it at one place.

Frans Bouma | Lead developer LLBLGen Pro