imagine you have this method in Spring Repository class:
Page<SystemEntity> findByNameContainsAndFlagIsFalseOrFamilyContainsAndFlagIsFalseOrEmailContainsAndFlagIsFalse(String name, String family ,String email, Pageable pageable);
one good practice is to break big query into its parts, then use them in this way:
Page<SystemEntity> findByNameContainsAndFlagIsFalse(String name, Pageable pageable);
Page<SystemEntity> findByFamilyContainsAndFlagIsFalse(String family, Pageable pageable);
Page<SystemEntity> findByEmailContainsAndFlagIsFals(String email, Pageable pageable);
// Combine results from above methods
default Page<SystemEntity> findByPrimaryLogicalCondition(String name, String family ,String email, Pageable pageable){
Page<SystemEntity> pageName = findByNameContainsAndFlagIsFalse(name, pageable);
Page<SystemEntity> pageFamily = findByFamilyContainsAndFlagIsFalse(family, pageable);
Page<SystemEntity> pageEmail = findByEmailContainsAndFlagIsFals(email, pageable);
// Combine the results from both queries
List<SystemEntity> combinedResults = new ArrayList<>(pageName.getContent());
combinedResults.addAll(pageFamily.getContent());
combinedResults.addAll(pageEmail.getContent());
return new PageImpl<>(combinedResults, pageable, combinedResults.size());
}
This approach allows you to reuse the smaller methods for other queries if needed and keeps your code more modular and maintainable.