Esempio n. 1
0
 public void add(final User user) {
   this.jdbcTemplate.update(
       "insert into users(id, name, password) values(?,?,?)",
       user.getId(),
       user.getName(),
       user.getPassword());
 }
Esempio n. 2
0
  @Test
  public void andAndGet() {
    dao.deleteAll();
    assertThat(dao.getCount(), is(0));

    dao.add(user1);
    dao.add(user2);
    assertThat(dao.getCount(), is(2));

    User userget1 = dao.get(user1.getId());
    assertThat(userget1.getName(), is(user1.getName()));
    assertThat(userget1.getPassword(), is(user1.getPassword()));

    User userget2 = dao.get(user2.getId());
    assertThat(userget2.getName(), is(user2.getName()));
    assertThat(userget2.getPassword(), is(user2.getPassword()));
  }
Esempio n. 3
0
 public void update(User user) {
   this.jdbcTemplate.update(
       this.sqlService.getSql("userUpdate"),
       user.getName(),
       user.getPassword(),
       user.getLevel().intValue(),
       user.getLogin(),
       user.getRecommend(),
       user.getEmail(),
       user.getId());
 }
Esempio n. 4
0
  public static void main(String[] args) throws ClassNotFoundException, SQLException {
    ApplicationContext context = new GenericXmlApplicationContext("applicationContext.xml");
    //		ApplicationContext context = new AnnotationConfigApplicationContext(DaoFactory.class);

    UserDaoJdbc dao = context.getBean("userDao", UserDaoJdbc.class);
    User user = new User();
    user.setId("whiteship2");
    user.setName("백기선2");
    user.setPassword("married");

    dao.add(user);

    System.out.println(user.getId() + "등록성공");

    User user2 = dao.get(user.getId());

    if (!user.getName().equals(user2.getName())) {
      System.out.println("테스트 실패 (name)");
    } else if (!user.getPassword().equals(user2.getPassword())) {
      System.out.println("테스트 실패 (password)");
    } else {
      System.out.println("조회 테스트 성공");
    }
  }
Esempio n. 5
0
  public void add(final User user) throws DuplicateUserIdException {
    try {
      this.jdbcTemplate.update(
          this.sqlService.getSql("userAdd"),
          user.getId(),
          user.getName(),
          user.getPassword(),
          user.getLevel().intValue(),
          user.getLogin(),
          user.getRecommend(),
          user.getEmail());

    } catch (DuplicateKeyException e) {

      throw new DuplicateUserIdException(e); // Wrapping of Exception	
    }
  }
Esempio n. 6
0
 private void checkSameUser(User user1, User user2) {
   assertThat(user1.getId(), is(user2.getId()));
   assertThat(user1.getName(), is(user2.getName()));
   assertThat(user1.getPassword(), is(user2.getPassword()));
 }