List of usage examples for org.hibernate Query setInteger
@Deprecated @SuppressWarnings("unchecked") default Query<R> setInteger(String name, int val)
From source file:com.consult.app.dao.impl.CargoMessageDaoImpl.java
@Override public CargoMessage getFirstLineMessage(int start, int end, Long userId, Long updateTime) { String hql = "from CargoMessage message where message.updateTime>=? and message.userId=? and message.start=? and message.end=?"; Session session = null;/*from ww w. j a v a 2s .co m*/ try { CargoMessageInterceptor inter = new CargoMessageInterceptor(updateTime); session = sessionFactory.openSession(inter); Query query = session.createQuery(hql); query.setLong(0, TimeUtils.getStartOfDay(updateTime)); query.setLong(1, userId); query.setInteger(2, start); query.setInteger(3, end); query.setFirstResult(0); query.setMaxResults(1); CargoMessage message = (CargoMessage) query.uniqueResult(); return message; } catch (Exception e) { e.printStackTrace(); return null; } finally { if (session != null) { session.close(); session = null; } } }
From source file:com.consult.app.dao.impl.CargoMessageDaoImpl.java
@Override public List<Object> getCargosByTel(GetCargosRequest req) { Session session = null;//from w w w. j a va2s. co m long now = System.currentTimeMillis(); String hql = "select new com.consult.app.response.admin.GetCargosItem(message.messageId,message.userId,message.start,message.end,message.telephone," + "message.contact,message.weight,message.capacity,message.truckLength,message.truckType,message.type,message.description,message.modifyTime," + "message.updateTime,message.companyName,message.companyAddress,message.landlines,message.charges,message.cargoType,message.truckLengthSet) from CargoMessage message " + "where message.telephone=? and message.modifyTime > ? and message.modifyTime < ? and (message.type=1 or message.type=-1 or message.type=4)"; if (req.getCity() > 0) { hql += " and message.start = ?"; } hql += " order by message.modifyTime desc"; try { CargoMessageInterceptor inter = new CargoMessageInterceptor(System.currentTimeMillis()); session = sessionReadFactory.openSession(inter); Query query = session.createQuery(hql); query.setLong(0, req.getTelephone()); query.setLong(1, TimeUtils.getStartOfDay(req.getUpdateTime())); query.setLong(2, TimeUtils.getEndOfDay(req.getUpdateTime())); if (req.getCity() > 0) { query.setInteger(3, req.getCity()); } List<Object> list = query.list(); return list; } catch (Exception e) { e.printStackTrace(); } finally { if (session != null) { session.close(); session = null; } } return null; }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
@Override public void updatePosition(PostPositionRequest req, long userId, Position user) { try {/*from w w w .j a v a 2 s .c o m*/ if (PositionHelper.distFrom(req.getLat(), req.getLon(), user.getLat(), user.getLon()) > 5000) { String hql = "update Position user set user.lon=?, user.lat=?, user.positionTime=?, user.city=?, " + "user.lastEffectLon=?, user.lastEffectLat=?, user.lastPositionTime=?, user.lastEffectCity=?, " + "user.updateTime=? "; hql += " where user.userId=?"; Query query = sessionFactory.getCurrentSession().createQuery(hql); int i = 0; query.setDouble(i, req.getLon()); query.setDouble(++i, req.getLat()); query.setLong(++i, System.currentTimeMillis()); query.setInteger(++i, req.getCityId()); query.setDouble(++i, req.getLon()); query.setDouble(++i, req.getLat()); query.setLong(++i, System.currentTimeMillis()); query.setInteger(++i, req.getCityId()); query.setLong(++i, System.currentTimeMillis()); query.setLong(++i, userId); query.executeUpdate(); } else { String hql = "update Position user set user.lon=?, user.lat=?, user.positionTime=?, user.city=?, user.updateTime=? "; hql += " where user.userId=?"; Query query = sessionFactory.getCurrentSession().createQuery(hql); int i = 0; query.setDouble(i, req.getLon()); query.setDouble(++i, req.getLat()); query.setLong(++i, System.currentTimeMillis()); query.setInteger(++i, req.getCityId()); query.setLong(++i, System.currentTimeMillis()); query.setLong(++i, userId); query.executeUpdate(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
@Override public int getOnlineUser(int cityId) { try {//from w w w . java 2s. c o m long onlineTriggerTime = TimeUtils.getStartOfDay(System.currentTimeMillis());// - Constant.HOUR_IN_MILLI;//PushExecutor.HEARTBEAT_INTERVAL * 2500;//1000*2.5 // String hql = "select new com.consult.app.response.user.LoginInfoItem(user.city, count(user.city)) " + // "from User user, Profile profile " + // "where user.userId=profile.userId and profile.userType=? and user.positionTime>? and user.city>0 " + // "group by user.city"; String hql = "select count(user.userId) " + "from User user, Profile profile " + "where user.userId=profile.userId and profile.userType=? and user.updateTime>? and user.city=?"; Query query = sessionFactory.getCurrentSession().createQuery(hql); query.setInteger(0, Constant.USER_TYPE_TRUCKER); query.setLong(1, onlineTriggerTime); query.setInteger(2, cityId); return ((Long) query.uniqueResult()).intValue(); } catch (Exception e) { e.printStackTrace(); return 0; } }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
@Override public List<Object> getLongUnloginUserToken(int appType, Long startId, int count, Long threshTime) { try {/* w w w . jav a 2 s .co m*/ // String content, Integer pushType, String token, // Integer notificationType, int badgeCount String hql = "select new com.consult.app.push.modal.PushQueueItem('" + Constant.LONG_UNLOGIN_MSG_CONTENT + "', user.loginFrom, user.token, " + PushUtil.NOTIFICATION_TYPE_BROADCAST + ", 0) " + "from User user, Profile profile, Token token " + "where user.userId=token.userId and user.token=token.token and user.userId=profile.userId and user.userId>? "; if (appType != Cookie.APP_TYPE_ALL) { hql = hql + " and user.loginFrom=? "; } hql = hql + " and profile.userType=? and user.lastLogin<? order by user.userId asc"; Query query = sessionFactory.getCurrentSession().createQuery(hql); int i = 0; query.setLong(i, startId); if (appType != Cookie.APP_TYPE_ALL) { query.setInteger(++i, appType); } query.setInteger(++i, Constant.USER_TYPE_TRUCKER); query.setLong(++i, threshTime); query.setFirstResult(0); query.setMaxResults(count + 1); return query.list(); } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
@Override public List<Object> getTodayLoginUsers(IdTypeBeforeAfterRequest req) { String hql = ""; try {/*w w w . java 2s . co m*/ if (req.getId().intValue() <= Constant.CITY_ALL) { hql = "select new com.consult.app.response.admin.LastLoginItem(profile.userName, user.telephone, user.lastLogin) " + "from User user, Profile profile " + "where user.userId=profile.userId and user.lastLogin>? and user.lastLogin<? "; if (req.getType() == Constant.USER_TYPE_TRUCKER) { hql = hql + " and profile.userType=?"; } else { hql = hql + " and profile.userType<>?"; } hql = hql + " order by user.lastLogin desc"; Query query = sessionFactory.getCurrentSession().createQuery(hql); // query.setLong(0, TimeUtils.getStartOfDay(System.currentTimeMillis())); query.setLong(0, req.getBefore()); query.setLong(1, req.getAfter()); query.setInteger(2, Constant.USER_TYPE_TRUCKER); query.setFirstResult(0); query.setMaxResults(req.getCount()); return query.list(); } else { hql = "select new com.consult.app.response.admin.LastLoginItem(profile.userName, user.telephone, user.lastLogin) " + "from User user, Profile profile " + "where user.userId=profile.userId and user.lastLogin>? and user.lastLogin<? "; if (req.getType() == Constant.USER_TYPE_TRUCKER) { hql = hql + " and profile.userType=?"; } else { hql = hql + " and profile.userType<>?"; } hql = hql + " and user.city=? order by user.lastLogin desc"; Query query = sessionFactory.getCurrentSession().createQuery(hql); query.setLong(0, req.getBefore()); query.setLong(1, req.getAfter()); query.setInteger(2, Constant.USER_TYPE_TRUCKER); query.setInteger(3, req.getId().intValue()); query.setFirstResult(0); query.setMaxResults(req.getCount()); return query.list(); } } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
@Override public int updatePushConfig(TypeRequest req, long userId) { try {// w w w . j av a2 s . com String hql = "update User user set user.pushSubscribe=? where user.userId=?"; Query query = sessionFactory.getCurrentSession().createQuery(hql); query.setInteger(0, req.getType()); query.setLong(1, userId); if (query.executeUpdate() > 0) { JUserCache.getInstance().removeUser(userId); } return Cookie.RESPONSE_SUCCESS; } catch (Exception e) { e.printStackTrace(); return Cookie.RESPONSE_SERVER_QUERY_ERROR; } }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
@Override public Integer getLoginCount(int userType, long from, long to) { try {//from ww w. ja va 2 s. c om String hql = ""; if (userType == Constant.USER_TYPE_TRUCKER) { hql = "select count(*) from User user, Profile profile where user.userId=profile.userId and user.lastLogin>? and user.lastLogin<? and profile.userType=?"; } else { hql = "select count(*) from User user, Profile profile where user.userId=profile.userId and user.lastLogin>? and user.lastLogin<? and profile.userType>=?"; } Query query = sessionFactory.getCurrentSession().createQuery(hql); query.setLong(0, from); query.setLong(1, to); query.setInteger(2, userType); return ((Long) query.uniqueResult()).intValue(); } catch (Exception e) { e.printStackTrace(); return 0; } }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
@Override public List<Object> getLongUnloginUserTelephone(int appType, Long startId, int count, Long threshTime) { try {//w w w .j av a 2 s.c o m // String content, Integer pushType, String token, // Integer notificationType, int badgeCount String hql = "select new com.consult.app.response.user.TelephoneItem(user.telephone) " + "from User user, Token token " + "where user.userId=token.userId and user.token=token.token and user.userId>? "; if (appType != Cookie.APP_TYPE_ALL) { hql = hql + " and user.loginFrom=? "; } hql = hql + " and profile.userType=? and user.lastLogin<? order by user.userId asc"; Query query = sessionFactory.getCurrentSession().createQuery(hql); int i = 0; query.setLong(i, startId); if (appType != Cookie.APP_TYPE_ALL) { query.setInteger(++i, appType); } query.setInteger(++i, Constant.USER_TYPE_TRUCKER); query.setLong(++i, threshTime); query.setFirstResult(0); query.setMaxResults(count + 1); return query.list(); } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
@Override public int getRegisterCount(int userType, long from, long to, int city) { try {//from ww w . j av a2s . c om String hql = ""; if (userType == Constant.USER_TYPE_TRUCKER) { hql = "select count(*) from User user, Profile profile where user.userId=profile.userId and user.createTime>? and user.createTime<? and profile.userType=?"; } else { hql = "select count(*) from User user, Profile profile where user.userId=profile.userId and user.createTime>? and user.createTime<? and profile.userType>=?"; } if (city > 0) { hql = hql + " and user.installPlace=?"; } Query query = sessionFactory.getCurrentSession().createQuery(hql); query.setLong(0, from); query.setLong(1, to); query.setInteger(2, userType); if (city > 0) { query.setInteger(3, city); } return ((Long) query.uniqueResult()).intValue(); } catch (Exception e) { e.printStackTrace(); return 0; } }