Hey everyone, Are you aware of any good way to int...
# arrow
p
Hey everyone, Are you aware of any good way to integrate
@Transactional
and
Either
? Basically I'm using
Either<Throwable, Something>
as return type for many of my services and now I'd like to add transactional control through annotations instead of doing it manually (just recently integrated micronaut into the project) Do you have any tips on how(if possible) to accommodate both ?
a
I've used the TransactionManager itself and a wrapper around the either block to encompass the transaction. You can shove the transactional context within the coroutine scope to access it from lower layers as well. Something similar to:
Copy code
fun save(m: Model): Either<Error, Model> = tx { stuff.. }
p
I see your point Alex, makes sense to me. Did you have cases where a method you are already opening a transaction needs to call another method that is doing the same ? That is my concern and one of the selling points of the
@Transactional
for me as it simply reuses any ongoing transaction (unless specified otherwise)
d
Hi Pedro,
@Transactional
is based on thread locals -> it will not work with
suspend
functions as coroutines. You have to switch to
TransactionalOperator
in such case.
p
Thanks for the info Dariusz, I had no idea about this limitation, I'll investigate further another option, thanks
s
This sounds very interesting, if anyone wants to collaborate on some code I'd be happy to help. @Alex Johnson do you have that
tx
block public somewhere?