Transaction Management in use cases

706 views
Skip to first unread message

Carlos Hernandez Perez

unread,
Oct 2, 2014, 10:37:26 AM10/2/14
to clean-code...@googlegroups.com, r...@tralix.com
Hello clean coders, we have a discussion  about managing database transactions in the use cases. There are two cases, when a module begins a transaction and depends on other module that begins another transaction and the transaction must be shared/independent each other.

Example:

class ModuleA{

IModuleB b;

public ModuleA(IModuleB b){
this.b=b;
}

void doSomethingInTransaction(){
//begin tranasction
b.doSomethingElseInTransaction();
//ends transaction
}


That is the idea. How can a manage this in a clean architecture???

Jakob Holderbaum

unread,
Oct 3, 2014, 2:01:18 AM10/3/14
to clean-code...@googlegroups.com
Well, I have a similar thing going on in the last application I worked on.

What about a singular transaction provider? You can instantiate it oncde
inside of your
Context/Runtime/ServiceRegistry/ServiceLocator/WhatEverSingletonAbstractionYouLike.

Or you inject it as a dependency. This provider Interface gives you the
possibilities of starting and committing transactions. Whether it is the
same transactions or nested ones remains then a minor implementation
detail provided by your persistence layers.

BTW, in this app all the semantical user transaction (interactions by
utilizing Interactors) where automatically wrapped in a transaction from
this provider. We could push thousands of requests per second with a
single database server without performance implications. That lead me to
the conclusion, that defaulting to transactions per default is probably
(depending on the system and its runtime context and environment) a good
thing which safes you from different kinds of headaches!

WDYT?

Cheers
--
Jakob Holderbaum, M.Sc.
Systems Engineer

0176 637 297 71
http://jakob.io/
http://jakob.io/mentoring/
h...@jakob.io
@hldrbm

Sebastian Gozin

unread,
Oct 3, 2014, 4:57:20 AM10/3/14
to clean-code...@googlegroups.com, mail...@jakob.io
With regards to Jakob's customary WDYT.

I think it's a bit of a shame or an annoyance that these transaction controls only cover the database.
At least when we're talking about declarative transaction management systems based on aspects or annotations.

I don't mind an API which allows me to control the database transaction. As that would allow me to program a custom transaction handler to be used with other systems which do not live inside the database.
Then again most of the time I seem to just have work orders in a queue and keep them there until completed. Which I guess is also a kind of transaction.

In any event.
Stuff to practice more with for me.
Reply all
Reply to author
Forward
0 new messages