B
B
Biaci_Anj2022-03-25 22:47:07
Java
Biaci_Anj, 2022-03-25 22:47:07

How to correctly make a transaction with JDBC so as not to violate the DAO pattern?

Here is an example.
I have a method that does two things. I want them to be executed in a transaction.

void setStatusDeclinedAndRefund() {
// sets Order status to DECLINED
// refund money to user's balance
}


But here's the problem, if I just add this code to the DAO impl, will I break the DAO pattern? In the same place, now not only CRUD methods will be, but also this one.

If I want to place this method in a service and just call the UPDATE methods from the DAO twice, then how can I do this in a transaction? Even if I get a connection in the service, what's next? Pass connection to DAO?

I really need your help, no one can answer this. Of course, just sticking the method into the DAO is the easiest solution, but I don’t understand whether it will be normally accepted for review.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question