BAEL-2502

This commit is contained in:
Ekaterina Galkina 2019-02-14 15:46:06 +05:00 committed by ashleyfrieze
parent f29191df67
commit dec56b6d0f
2 changed files with 24 additions and 0 deletions

View File

@ -70,4 +70,7 @@ public interface UserRepository extends JpaRepository<User, Integer> , UserRepos
@Modifying
@Query(value = "UPDATE Users u SET status = ? WHERE u.name = ?", nativeQuery = true)
int updateUserSetStatusForNameNativePostgres(Integer status, String name);
@Query(value = "SELECT u FROM User u WHERE u.name IN :names")
List<User> findUserByNameList(@Param("names") Collection<String> names);
}

View File

@ -12,6 +12,7 @@ import org.springframework.data.jpa.domain.JpaSort;
import org.springframework.data.mapping.PropertyReferenceException;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
@ -364,6 +365,26 @@ class UserRepositoryCommon {
assertThat(usersWithEmails.size()).isEqualTo(2);
}
@Test
public void givenUsersInDBWhenFindByNameListReturnCollection() {
User user1 = new User();
user1.setName(USER_NAME_ADAM);
user1.setEmail(USER_EMAIL);
userRepository.save(user1);
User user2 = new User();
user2.setName(USER_NAME_PETER);
user2.setEmail(USER_EMAIL2);
userRepository.save(user2);
List<String> names = Arrays.asList(USER_NAME_ADAM, USER_NAME_PETER);
List<User> usersWithNames = userRepository.findUserByNameList(names);
assertThat(usersWithNames.size()).isEqualTo(2);
}
@After
public void cleanUp() {
userRepository.deleteAll();