Search in sources :

Example 1 with UserMapper

use of vo.mapper.UserMapper in project JessMA by ldcsaa.

the class UserDao method createUser.

@Transaction(level = TransIsoLevel.REPEATABLE_READ)
public boolean createUser(User user) {
    UserMapper mapper = getMapper(UserMapper.class);
    int effect = mapper.createUser(user);
    if (effect > 0) {
        /*
			 * changeSessionExecutorTypeToXxx() 方法:
			 * 能在事务中动态修改 Session 的 Executor Type。
			 * 在执行批量更新等场合非常有用,使用得当能大大提升性能
			 * 
			 * 本例展示了一种典型的使用场合:Session 通过默认(SIMPLE)
			 * Executor Type 向主表插入一条记录并获得自增主键,然后把 
			 * Executor Type 动态修改为 BATCH,对从表执行批量更新操作
			 */
        changeSessionExecutorTypeToBatch();
        int userId = user.getId();
        List<Integer> interests = user.getInterests();
        if (interests != null)
            for (Integer interestId : interests) mapper.createUserInterest(userId, interestId);
    }
    return (effect > 0);
}
Also used : UserMapper(vo.mapper.UserMapper) Transaction(org.jessma.dao.Transaction)

Example 2 with UserMapper

use of vo.mapper.UserMapper in project JessMA by ldcsaa.

the class UserDao method queryInterest.

@Transaction(false)
public List<User> queryInterest(int gender, int experience) {
    Cache cache = Cache.getInstance();
    UserMapper mapper = getMapper(UserMapper.class);
    List<User> users = mapper.queryInterest(gender, experience);
    for (User user : users) {
        user.setGenderObj(cache.getGenderById(user.getGender()));
        user.setExperienceObj(cache.getExperenceById(user.getExperience()));
        List<Integer> ints = user.getInterests();
        if (ints != null) {
            List<Interest> intsObjs = new ArrayList<Interest>();
            for (Integer i : ints) intsObjs.add(cache.getInterestById(i));
            user.setInterestObjs(intsObjs);
        }
    }
    return users;
}
Also used : Interest(vo.Interest) UserMapper(vo.mapper.UserMapper) User(vo.User) ArrayList(java.util.ArrayList) Cache(global.Cache) Transaction(org.jessma.dao.Transaction)

Example 3 with UserMapper

use of vo.mapper.UserMapper in project JessMA by ldcsaa.

the class UserDao method findUsers.

@Transaction(false)
public List<User> findUsers(String name, int experience) {
    Cache cache = Cache.getInstance();
    UserMapper mapper = getMapper(UserMapper.class);
    List<User> users = mapper.findUsers(name, experience);
    for (User user : users) {
        user.setGenderObj(cache.getGenderById(user.getGender()));
        user.setExperienceObj(cache.getExperenceById(user.getExperience()));
        List<Integer> ints = user.getInterests();
        if (ints != null) {
            List<Interest> intsObjs = new ArrayList<Interest>();
            for (Integer i : ints) intsObjs.add(cache.getInterestById(i));
            user.setInterestObjs(intsObjs);
        }
    }
    return users;
}
Also used : Interest(vo.Interest) UserMapper(vo.mapper.UserMapper) User(vo.User) ArrayList(java.util.ArrayList) Cache(global.Cache) Transaction(org.jessma.dao.Transaction)

Example 4 with UserMapper

use of vo.mapper.UserMapper in project JessMA by ldcsaa.

the class UserDao method deleteUser.

public boolean deleteUser(int id) {
    UserMapper mapper = getMapper(UserMapper.class);
    mapper.deleteUserInterest(id);
    int effect = mapper.deleteUser(id);
    return (effect > 0);
}
Also used : UserMapper(vo.mapper.UserMapper)

Aggregations

UserMapper (vo.mapper.UserMapper)4 Transaction (org.jessma.dao.Transaction)3 Cache (global.Cache)2 ArrayList (java.util.ArrayList)2 Interest (vo.Interest)2 User (vo.User)2