package net.tooan.ynpay.core.ejb.dao.user; import net.tooan.ynpay.third.mongodb.BuguDao; import net.tooan.ynpay.user.agent.bean.User; import net.tooan.ynpay.user.agent.model.Session; /** * Created with IntelliJ IDEA. * User: Jing * Date: 13-10-24 * Time: 下午1:39 */ public class SessionDao extends BuguDao<Session> { public static SessionDao dao = new SessionDao(); public SessionDao() { super(Session.class); } public void cleanExpire() { remove(query().notEquals("expire", -1).where("function() { return (+this._id.getTimestamp() + this.expire * 1000) < +new Date(); }")); } public Session get(String token) { return query().is("token", token).is("expire", -1).where("function() { return (+this._id.getTimestamp() + this.expire * 1000) > +new Date(); }").result(); } public Session add(User user, String token, Integer expire) { Session session = new Session(); session.setExpire(expire); session.setToken(token); session.setUser(user); save(session); return session; } }