日期:2014-05-16 浏览次数:20402 次
** * @version 2007-5-4 * @author xalinx at gmail dot com * */ public class UserDaoImpl extends DaoSupport<User, Long> implements UserDao { private final ParameterizedRowMapper<UserImpl> rowMapper = new AutoRowMapper<UserImpl>() { }; public void deleteById(Long id) { // create proxy BeanMonitor<User> monitor = new BeanMonitor<User>(); User proxy = monitor.proxy(new UserImpl()); // proxy where proxy.setId(id); monitor.eq(); getSimpleDaoTemplate().proxyDelete(monitor); } public User findById(Long id) { // create proxy BeanMonitor<User> monitor = new BeanMonitor<User>(); User proxy = monitor.proxy(new UserImpl()); // proxy select proxy.getId(); proxy.getUsername(); proxy.getPassword(); proxy.getNickname(); proxy.getCity(); proxy.getProv(); proxy.getUserStatus(); proxy.getCreateTime(); proxy.getModifyTime(); // proxy where proxy.setId(id); monitor.eq(); return getSimpleDaoTemplate().proxyQueryObject(monitor, rowMapper); } public int findCount() { return getSimpleDaoTemplate().findCount(UserImpl.class); } public void store(User u) { // integrity validate if (u == null || u.getId() <= 0 || u.getUserStatus() < 0 || u.getUsername() == null || u.getPassword() == null || u.getNickname() == null || u.getCreateTime() == null || u.getModifyTime() == null) { throw new DataIntegrityViolationException(u.toString()); } BeanMonitor<User> monitor = new BeanMonitor<User>(); User proxy = monitor.proxy(new UserImpl()); // proxy insert proxy.setId(u.getId()); proxy.setUsername(u.getUsername()); proxy.setPassword(u.getPassword()); proxy.setNickname(u.getNickname()); proxy.setCity(u.getCity()); proxy.setProv(u.getProv()); proxy.setUserStatus(u.getUserStatus()); proxy.setCreateTime(u.getCreateTime()); proxy.setModifyTime(u.getModifyTime()); // store getSimpleDaoTemplate().proxyStore(monitor); } public void updateById(BeanMonitor<User> monitor) { User u = monitor.getBean(); // integrity validate if (u == null || u.getId() <= 0) { throw new DataIntegrityViolationException(u.toString()); } // proxy where User proxy = monitor.getProxy(); monitor.where(); proxy.setId(u.getId()); monitor.eq(); // update getSimpleDaoTemplate().proxyUpdate(monitor, u.getId()); } public BasePage<User> findPage(UserPageQuery pageQuery) { // create proxy BeanMonitor<User> monitor = new BeanMonitor<User>(); User proxy = monitor.proxy(new UserImpl()); // proxy select proxy.getId(); proxy.getUsername(); proxy.getCreateTime(); // proxy where if (null != pageQuery.getUser().getCity()) { proxy.setCity(pageQuery.getUser().getCity()); monitor.eq(); } if (null != pageQuery.getEndCreateTime()) { proxy.setCreateTime(pageQuery.getEndCreateTime()); monitor.and().leeq(); } if (null != pageQuery.getStartCreateTime()) { proxy.setCreateTime(pageQuery.getStartCreateTime()); monitor.and().gteq(); } if (null != pageQuery.getUser().getUsername()) { proxy.setUsername(pageQuery.getUser().getUsername()); monitor.and().like(); } // query & orm & page return getSimpleDaoTemplate().proxyQueryPage(monitor, rowMapper, pageQuery); } }