Ejemplo n.º 1
0
 public List<Map<String, Object>> queryStatusByUid(long uid, int platform) {
   if (platform == 0) {
     return userMapper.queryStatusByUid(uid);
   } else {
     return userMapper.queryStatusByUidAndPlatform(uid, platform);
   }
 }
Ejemplo n.º 2
0
  @Test
  public void findAll() {
    final UserMapper sut = new UserMapper(dataSource(), new IntegerIdentityMap<User>());

    for (final User user : sut.findAll(10, 0)) {
      final int userId = user.getId();

      switch (userId) {
        case 1:
          assertThat(user.getLoginName(), is("Foo"));
          assertThat(user.getHashedUserData(), is("b9f46238b289f23ba807973840655032"));
          break;
        case 2:
          assertThat(user.getLoginName(), is("Bar"));
          assertThat(user.getHashedUserData(), is("043bd227eaa879d438e7c1dfea568bc9"));
          break;
        case 3:
          assertThat(user.getLoginName(), is("Baz"));
          assertThat(user.getHashedUserData(), is("aa82cc74b4a932c06d4ea5a9ac38cf5e"));
          break;
        default:
          fail("Unexpected user id: " + userId);
      }
    }
  }
Ejemplo n.º 3
0
  @Test
  public void delete() {
    UserMapper sut = new UserMapper(dataSource(), new IntegerIdentityMap<User>());
    final User user = sut.find(2);
    assertThat(user.getId(), is(2));
    assertThat(user.getLoginName(), is("Bar"));
    assertThat(user.getHashedUserData(), is("043bd227eaa879d438e7c1dfea568bc9"));

    sut.delete(user);

    try {
      sut.find(2);
      fail("Expected exception not thrown!");
    } catch (DomainModelException ex) {
      assertThat(ex.getMessage(), is("There is no record set whith primary key '2'!"));
    }

    // avoid cache
    sut = new UserMapper(dataSource(), new IntegerIdentityMap<User>());

    try {
      sut.find(2);
      fail("Expected exception not thrown!");
    } catch (DomainModelException ex) {
      assertThat(ex.getMessage(), is("There is no record set whith primary key '2'!"));
    }
  }
Ejemplo n.º 4
0
 @Test
 public void testUpdateByPrimaryKey() {
   User record = userMapper.selectByPrimaryKey(104L);
   record.setFirstName("firstName-updated");
   record.setLastName("lastName-updated");
   int updateByPrimaryKey = userMapper.updateByPrimaryKey(record);
   assertEquals(1, updateByPrimaryKey);
 }
Ejemplo n.º 5
0
 @Test
 public void findByLoginName() {
   final UserMapper sut = new UserMapper(dataSource(), new IntegerIdentityMap<User>());
   final User user = sut.findByLoginName("Baz");
   assertThat(user.getId(), is(3));
   assertThat(user.getLoginName(), is("Baz"));
   assertThat(user.getHashedUserData(), is("aa82cc74b4a932c06d4ea5a9ac38cf5e"));
 }
Ejemplo n.º 6
0
 public List<UserDto> selectUsers(UserQuery query) {
   SqlSession session = mybatis.openSession(false);
   try {
     UserMapper mapper = session.getMapper(UserMapper.class);
     return mapper.selectUsers(query);
   } finally {
     MyBatis.closeQuietly(session);
   }
 }
Ejemplo n.º 7
0
 @Test
 public void findAll_emptyTable()
     throws SQLException, ClassNotFoundException, IOException, URISyntaxException {
   destroyTestDatabase();
   startTestDatabase(false);
   final UserMapper sut = new UserMapper(dataSource(), new IntegerIdentityMap<User>());
   final Collection<User> users = sut.findAll(10, 0);
   assertThat(users, is(empty()));
 }
 @Test
 public void testAdd() throws Exception {
   int preSize = userMapper.selectAll().size();
   User user = new User();
   user.setName("ysjian003");
   user.setPassword(new BCryptPasswordEncoder().encode("000"));
   user.setSex(User.Sex.MALE);
   userMapper.insert(user);
   assertEquals(preSize + 1, userMapper.selectAll().size());
 }
Ejemplo n.º 9
0
  @Test
  public void findUserById() {
    final UserMapper sut = new UserMapper(dataSource(), new IntegerIdentityMap<User>());
    User user = sut.find(1);
    assertThat(user.getId(), is(1));
    assertThat(user.getLoginName(), is("Foo"));
    assertThat(user.getHashedUserData(), is("b9f46238b289f23ba807973840655032"));

    user = sut.find(2);
    assertThat(user.getId(), is(2));
    assertThat(user.getLoginName(), is("Bar"));
    assertThat(user.getHashedUserData(), is("043bd227eaa879d438e7c1dfea568bc9"));
  }
Ejemplo n.º 10
0
  @Test
  public void insert() {
    final String loginName = "snafu";
    final String hashedUserData = "snafupw";
    User user = new User(loginName, hashedUserData);
    UserMapper sut = new UserMapper(dataSource(), new IntegerIdentityMap<User>());
    final int id = sut.insert(user);

    // avoid cache
    sut = new UserMapper(dataSource(), new IntegerIdentityMap<User>());
    user = sut.find(id);
    assertThat(user.getLoginName(), is(loginName));
    assertThat(user.getHashedUserData(), is(hashedUserData));
  }
Ejemplo n.º 11
0
 public List<User> list(UserQueryCondition condition) {
   List<User> result = userMapper.list(condition);
   for (User user : result) {
     fillUserExtInfo(user);
   }
   return result;
 }
Ejemplo n.º 12
0
  @Test
  public void testSelectByPrimaryKey() {
    User selectByPrimaryKey = userMapper.selectByPrimaryKey(Long.valueOf(102));
    assertNotNull(selectByPrimaryKey);

    assertEquals("first_name_102", selectByPrimaryKey.getFirstName());
    assertEquals("last_name_102", selectByPrimaryKey.getLastName());
  }
Ejemplo n.º 13
0
 public User getUser(long uid, long mid) {
   User user = userMapper.get(uid, mid);
   if (user == null) {
     return null;
   }
   fillUserExtInfo(user);
   return user;
 }
Ejemplo n.º 14
0
 @Test
 public void testInsert() {
   User record = new User();
   record.setFirstName("firstName");
   record.setLastName("lastName");
   int insert = userMapper.insert(record);
   assertEquals(1, insert);
   assertNotNull(record.getId());
 }
Ejemplo n.º 15
0
  @Test
  public void testDynamicCount() {
    UserSearch search = new UserSearch();
    search.setFirstName("first_name_page");
    search.setLastName("last_name_page");
    search.setOrderBy("firstName");
    search.setSequance("desc");

    Long cnt = userMapper.count("dynamicFind", search);
    assertEquals(Long.valueOf(3), cnt);
  }
Ejemplo n.º 16
0
 @Override
 public User map(LoginResult loginResult) {
   User user = null;
   for (UserPo userPo : loginResult.getData()) {
     user = modelMapper.toModel(userPo);
     if (user != null) {
       return user;
     }
   }
   return user;
 }
Ejemplo n.º 17
0
  @Test
  public void testDynamicFind() {
    UserSearch search = new UserSearch();
    search.setFirstName("first_name_page");
    search.setLastName("last_name_page");
    search.setOrderBy("firstName");
    search.setSequance("desc");

    List<User> list = userMapper.find("dynamicFind", search);
    assertEquals(3, list.size());
  }
Ejemplo n.º 18
0
  @Test
  public void testCount() {
    User search = new User();
    search.setFirstName("first_name_page");
    search.setLastName("last_name_page");

    Example example = Example.create(search);
    DetachedCriteria dc = DetachedCriteria.forClass(User.class).add(example);

    Long count = userMapper.count(dc);
    assertEquals(Long.valueOf(3), count);
  }
Ejemplo n.º 19
0
 public void deleteAllByUidAndMid(long uid, long mid) {
   userContactMapper.delete(uid, mid);
   userExtMapper.delete(uid, mid);
   userLastActiveMappper.delete(uid, mid);
   userTagMapper.deleteUserTag(uid, mid);
   platformMapper.delete(uid, mid);
   userMapper.delete(uid, mid);
   memberExpRecordMapper.delete(uid, mid);
   memberPointRecordMapper.delete(uid, mid);
   addressMapper.deleteAll(mid);
   memberMapper.deleteMember(uid, mid);
 }
Ejemplo n.º 20
0
 public Member addOrUpdate(Member member) {
   checkMid(member.getUid(), member.getMid());
   checkMemberLevelId(member.getUid(), member.getMember_level_id());
   Member finded = memberMapper.get(member.getUid(), member.getMid());
   if (finded == null) {
     member.defaultValue();
     memberMapper.add(member);
     userMapper.joinMember(member.getUid(), member.getMid());
   } else {
     memberMapper.update(member);
   }
   return memberMapper.get(member.getUid(), member.getMid());
 }
Ejemplo n.º 21
0
  @Test
  public void update() {
    UserMapper sut = new UserMapper(dataSource(), new IntegerIdentityMap<User>());
    User user = sut.find(2);
    assertThat(user.getId(), is(2));
    assertThat(user.getLoginName(), is("Bar"));
    assertThat(user.getHashedUserData(), is("043bd227eaa879d438e7c1dfea568bc9"));

    user.setLoginName("snafu");
    user.setHashedUserData("snafupw");
    sut.update(user);

    user = sut.find(2); // get from cache
    assertThat(user.getId(), is(2));
    assertThat(user.getLoginName(), is("snafu"));
    assertThat(user.getHashedUserData(), is("snafupw"));

    sut = new UserMapper(dataSource(), new IntegerIdentityMap<User>());
    user = sut.find(2);
    assertThat(user.getId(), is(2));
    assertThat(user.getLoginName(), is("snafu"));
    assertThat(user.getHashedUserData(), is("snafupw"));
  }
Ejemplo n.º 22
0
  @Test
  public void testFind() {
    User search = new User();
    search.setFirstName("first_name_page");
    search.setLastName("last_name_page");

    Example example = Example.create(search);
    DetachedCriteria dc = DetachedCriteria.forClass(User.class).add(example);
    OrderBy orderBy = new OrderBy();
    orderBy.setOrderBy("firstName");
    orderBy.setSequance("asc");

    List<User> find = userMapper.find(dc, orderBy);
    assertEquals(3, find.size());
  }
 public int insert(User user) {
   byte[] bytes = null;
   try {
     System.out.println("privatekey: " + userStatusCache.getPrivateKey());
     System.out.println("password: "******"UTF-8");
     System.out.println("md5pw: " + md5pw);
     user.setPassword(md5pw);
     return userMapper.insert(user);
   } catch (Exception e) {
     e.printStackTrace();
     return -1;
   }
 }
Ejemplo n.º 24
0
 public User add(User user) {
   user.defaultValue();
   userMapper.add(user);
   return getUser(user.getUid(), user.getMid());
 }
 public int getCountByUserName(String name) {
   return userMapper.countByUserName(name);
 }
Ejemplo n.º 26
0
 @Test
 public void findUserById_caches() {
   final UserMapper sut = new UserMapper(dataSource(), new IntegerIdentityMap<User>());
   final User user = sut.find(1);
   assertThat(user, is(sameInstance(sut.find(1))));
 }
 public User getUserById(int id) {
   return userMapper.selectByPrimaryKey(id);
 }
Ejemplo n.º 28
0
 @Test
 public void testDeleteByPrimaryKey() {
   int deleteByPrimaryKey = userMapper.deleteByPrimaryKey(Long.valueOf(101));
   assertEquals(1, deleteByPrimaryKey);
 }
 @Test(expected = NullPointerException.class)
 public void testGet() throws Exception {
   userMapper.selectByName("").getName();
 }
Ejemplo n.º 30
0
 @Test
 public void findByLoginName_caches() {
   final UserMapper sut = new UserMapper(dataSource(), new IntegerIdentityMap<User>());
   final User user = sut.findByLoginName("Baz");
   assertThat(user, is(sameInstance(sut.findByLoginName("Baz"))));
 }