Implementation of getUsersWithStatuses based on getUsersWithStatus In my code I have method which gets users from database with concrete status. And now I have to add new method which gets users from database with list of statuses. I don't know, is it better to create new repository method or reuse existing code.

I created example method "getUsersWithStatuses" which reuse old method "getUsersWithStatus". But, is it good that this method read data from database in loop?

@Transactional(readOnly = true)
public List&lt;UserDTO&gt; getUsersWithStatus(Long locationId, UserDTO.Status status) {
    List&lt;User&gt; userList = userRepository.findByLocationWithStatus(locationId, orderStatus);
    return userMapper.asDTOs(userList);
}

//new functionality
@Transactional(readOnly = true)
public List&lt;UserDTO&gt; getUsersWithStatuses(Long locationId, EnumSet&lt;UserDTO.Status&gt; statuses) {
    List&lt;UserDTO&gt; result = new LinkedList&lt;&gt;();
    statuses.forEach(status -&gt; result.addAll(getUsersWithStatus(locationId, status)));
    return result;
}
I would say that in your case it is not a good idea because you will execute the same query many times.

However you can change you calls to have the method with a single status calling the one with many satuses.

List&lt;UserDTO&gt; getUsersWithStatus(Long locationId, Status status) {
  return getUserWithStatuses(EnumSet.of(status));
}

List&lt;UserDTO&gt; getUsersWithStatuses(Long locationId, EnumSet&lt;Status&gt; statuses) {
  // SELECT * FROM users WHERE status IN (..)
}