Merge remote-tracking branch 'baeldung/master' into bael-2538

This commit is contained in:
dupirefr
2019-02-19 07:42:13 +01:00
32 changed files with 643 additions and 93 deletions
@@ -71,6 +71,10 @@ public interface UserRepository extends JpaRepository<User, Integer> , UserRepos
@Query(value = "UPDATE Users u SET u.status = ? WHERE u.name = ?", nativeQuery = true)
int updateUserSetStatusForNameNative(Integer status, String name);
@Query(value = "INSERT INTO Users (name, age, email, status, active) VALUES (:name, :age, :email, :status, :active)", nativeQuery = true)
@Modifying
void insertUser(@Param("name") String name, @Param("age") Integer age, @Param("email") String email, @Param("status") Integer status, @Param("active") boolean active);
@Modifying
@Query(value = "UPDATE Users u SET status = ? WHERE u.name = ?", nativeQuery = true)
int updateUserSetStatusForNameNativePostgres(Integer status, String name);
@@ -30,10 +30,10 @@ class UserRepositoryCommon {
final String USER_EMAIL4 = "email4@example.com";
final Integer INACTIVE_STATUS = 0;
final Integer ACTIVE_STATUS = 1;
private final String USER_EMAIL5 = "email5@example.com";
private final String USER_EMAIL6 = "email6@example.com";
private final String USER_NAME_ADAM = "Adam";
private final String USER_NAME_PETER = "Peter";
final String USER_EMAIL5 = "email5@example.com";
final String USER_EMAIL6 = "email6@example.com";
final String USER_NAME_ADAM = "Adam";
final String USER_NAME_PETER = "Peter";
@Autowired
protected UserRepository userRepository;
@@ -389,6 +389,22 @@ class UserRepositoryCommon {
}
@Test
@Transactional
public void whenInsertedWithQuery_ThenUserIsPersisted() {
userRepository.insertUser(USER_NAME_ADAM, 1, USER_EMAIL, ACTIVE_STATUS, true);
userRepository.insertUser(USER_NAME_PETER, 1, USER_EMAIL2, ACTIVE_STATUS, true);
User userAdam = userRepository.findUserByNameLike(USER_NAME_ADAM);
User userPeter = userRepository.findUserByNameLike(USER_NAME_PETER);
assertThat(userAdam).isNotNull();
assertThat(userAdam.getEmail()).isEqualTo(USER_EMAIL);
assertThat(userPeter).isNotNull();
assertThat(userPeter.getEmail()).isEqualTo(USER_EMAIL2);
}
@Test
@Transactional
public void givenTwoUsers_whenFindByNameUsr01_ThenUserUsr01() {
@@ -520,7 +536,7 @@ class UserRepositoryCommon {
Query nativeQuery = entityManager.createNativeQuery("select deleted from USERS where NAME = 'usr01'");
assertEquals(0, nativeQuery.getResultList().get(0));
}
@After
public void cleanUp() {
userRepository.deleteAll();