Good day,
I try to create DAO layer, following mostly this guide.
Take a note, that I don't use any frameworks, just plain JDBC.
Take a look on creating a Connection instance:
Inside each CRUD method we obtain a connection the following way:
Connection connection = daoFactory.getConnection();
So we obtain a new connection each time we call method.
The only question I have is how to implement transactions here?
I see two solutions:
- Instead of DaoFactory field, I use Connection field, which I share among the methods. So as to have one Connection per DAO. But then, what layer should be responsible for transaction? Should I create something in between Service - DAO?
- I create fields for other DAO instances needed to create transaction. So as if, for example, I would have TransactionDao to implement banktransfer (take money from one user and add to another) and this TransactionDao will have also UserDao, because I should make one create and two update actions.
I want to know the right solution, maybe it's none of above mentioned.
Tell me please also are there any concurrency issues I should be worry about?
Thank you