Are methods that update multiple objects that are usually not part of the DAO?

I have seen a million examples of DAOs, and for the most part they all implement your basic CRUD operations for individual objects, perhaps several methods that return lists (like List getCustomers ()).

However, I have never seen an example in which there is a method that updates, deletes or creates several objects, for example: void update (List).

Are there methods that update multiple objects that are usually not part of the DAO, or are they just not used in the examples? I have a requirement in which I need to perform batch insertion, and calling myDAO.create () a hundred times is not very efficient.

I just want to make sure that I don’t miss anything before I go ahead and do what seems obvious.

+3
source share
3 answers

I found that batch updates are usually performed using tools provided by the database provider.

I agree that the DAOs that I have seen usually do not have create / update / delete methods overloaded to get the list, but there is no reason why they cannot.

One thought that fails me is that DAOs do not own transactions when I write them. They can never know where they go in most of the work. What services do.

, DAO . . , "chunking" . .

+2

, . DAO , , .

0

void update(List) , void update(Item), List . , , , . , .

, update(Item) 1000 update(List) 1, , update(Item), 1000 , .

0
source

Source: https://habr.com/ru/post/1709335/


All Articles