@Test public void save() { User user = User.builder() .email("demo@demo.com") .firstName("Demo") .lastName("Demov") .build(); userRepository.save(user); }
@Override public void save(User model) { try { PreparedStatement statement = connection.prepareStatement(SQL_INSERT_QUERY, PreparedStatement.RETURN_GENERATED_KEYS); statement.setString(1, model.getFirstName()); statement.setString(2, model.getLastName()); statement.setString(3, model.getEmail()); statement.setString(4, model.getHashPassword()); statement.executeUpdate(); ResultSet resultSet = statement.getGeneratedKeys(); while (resultSet.next()) { model.setId(resultSet.getLong("id")); } } catch (SQLException e) { throw new IllegalArgumentException(e); } }
UsersRepositoryConnectionImpl implements UsersRepository { @Override public void save(User model) { try { PreparedStatement statement = connection.prepareStatement(SQL_INSERT_QUERY, PreparedStatement.RETURN_GENERATED_KEYS); statement.setString(1, model.getFirstName()); statement.setString(2, model.getLastName()); statement.setString(3, model.getEmail()); statement.setString(4, model.getHashPassword()); statement.executeUpdate(); ResultSet resultSet = statement.getGeneratedKeys(); while (resultSet.next()) { model.setId(resultSet.getLong("id")); } } catch (SQLException e) { throw new IllegalArgumentException(e); } } }
UsersRepositoryConnectionImpl implements UsersRepository { @Override public void save(User model) { try { PreparedStatement statement = connection.prepareStatement(SQL_INSERT_QUERY, PreparedStatement.RETURN_GENERATED_KEYS); statement.setString(1, model.getFirstName()); statement.setString(2, model.getLastName()); statement.setString(3, model.getEmail()); statement.setString(4, model.getHashPassword()); statement.executeUpdate(); ResultSet resultSet = statement.getGeneratedKeys(); while (resultSet.next()) { model.setId(resultSet.getLong("id")); } } catch (SQLException e) { throw new IllegalArgumentException(e); } } UsersRepositoryConnectionImpl(Connection connection); }
UsersRepositoryConnectionImpl implements UsersRepository { @Override public void save(User model) { try { PreparedStatement statement = connection.prepareStatement(SQL_INSERT_QUERY, PreparedStatement.RETURN_GENERATED_KEYS); statement.setString(1, model.getFirstName()); statement.setString(2, model.getLastName()); statement.setString(3, model.getEmail()); statement.setString(4, model.getHashPassword()); statement.executeUpdate(); ResultSet resultSet = statement.getGeneratedKeys(); while (resultSet.next()) { model.setId(resultSet.getLong("id")); } } catch (SQLException e) { throw new IllegalArgumentException(e); } } UsersRepositoryConnectionImpl(Connection connection); @Override Optional<User> findOne(Long id); @Override void save(User model); @Override void delete(Long id); @Override List<User> findAll(); }
UsersRepositoryConnectionImpl implements UsersRepository { @Override public void save(User model) { try { PreparedStatement statement = connection.prepareStatement(SQL_INSERT_QUERY, PreparedStatement.RETURN_GENERATED_KEYS); statement.setString(1, model.getFirstName()); statement.setString(2, model.getLastName()); statement.setString(3, model.getEmail()); statement.setString(4, model.getHashPassword()); statement.executeUpdate(); ResultSet resultSet = statement.getGeneratedKeys(); while (resultSet.next()) { model.setId(resultSet.getLong("id")); } } catch (SQLException e) { throw new IllegalArgumentException(e); } } UsersRepositoryConnectionImpl(Connection connection); @Override Optional<User> findOne(Long id); @Override void save(User model); @Override void delete(Long id); @Override List<User> findAll();  }