What is the goal of managers / deals?

I am creating a spring application for the first time. I have problems with concurrency and I suspect that something is wrong with the way I manage the backend. The only difference I can see between my internal code and the examples I saw are the manager classes.

In my code, I have my model (managed by sleeping) and my DAOs on top of this to do CRUD / search / etc on models. In the sample code I was looking at, they never use the DAO directly. Instead, they use manager classes that are called DAO indirectly. To me, this just seems like pointless code duplication.

What are these manager classes designed for? I read that they wrap my code in a "transaction", but why do I need it?

+6
java spring transactions appfuse
source share
3 answers

Transactions are used to make updates "transactional."

Example) A user clicks on a web page that updates 13 records in the database. The transaction will ensure that 0 or 13 updates are received, the error will force everything to roll back.

Managers are all about making work easier. They will not magically make your code thread safe. Using DAO directly is not a thread safety bug.

However, I suggest you limit the logic in your DAO and put as much logic as you can in the business layers. See Best Practices for the DAO Template?

If you post a small example of your code that does not work with multiple threads, we can offer some ideas ... but neither transactions, nor managers will help solve your problem.

+5
source share

Many applications have non-trivial requirements, and business logic often includes access to several resources (for example, several DAOs), coordinating these accesses and controlling transactions through these calls (if you get access to DAO1 and DAO2 that you want to commit or rollback changes as an indivisible unit of work).

Thus, it is typical to encapsulate and hide this complexity in the components of specialized services that exposed business behavior in a rude manner to customers.

And this is exactly what the managers you refer to do, they make up the Service Level .

The service level defines the boundary of the application [Cockburn PloP] and its set of available operations in terms of the interaction of client layers. It encapsulates the business logic of the application, controls transactions, and coordinates responses when performing its operations.

+2
source share

DAOs do not need to own transactions because they have no way of knowing if they are only part of a larger transaction.

The service level is where the transactions belong. You are mistaken in saying that they are "meaningless code duplication."

0
source share

All Articles