Example usage for org.hibernate Query setLong

List of usage examples for org.hibernate Query setLong

Introduction

In this page you can find the example usage for org.hibernate Query setLong.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setLong(String name, long val) 

Source Link

Document

Bind a named long-valued parameter.

Usage

From source file:com.consult.app.dao.impl.UserDaoImpl.java

@Override
public int changePassword(long userId, String newPassword) {
    try {/*from w ww  .j  av  a  2  s.c  om*/
        String hql = "update User user set user.password=? where user.userId=?";
        Query query = sessionFactory.getCurrentSession().createQuery(hql);
        query.setString(0, newPassword);
        query.setLong(1, userId);
        query.executeUpdate();
        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 List<Object> getMessages(TypeBeforeAfterRequest req, int mode, long userId) {

    String condition = "", hql = "";
    MessageInterceptor inter = null;/*from   ww  w  .jav  a 2s.co m*/
    condition = " and message.updateTime>? and message.updateTime<=? order by message.updateTime desc";
    if (req.getType() == Constant.MESSAGE_TYPE_CARGO) {
        hql = "select new com.consult.app.response.cargo.MyCargoMessageItem"
                + "(message.messageId, case when message.type>=1 and message.type<4 then 1 else 0 end, message.weight, message.capacity,"
                + "message.truckType, message.contact, message.telephone, message.start, message.end,"
                + "message.description, message.updateTime, message.truckLength, message.companyName, message.companyAddress, message.landlines,"
                + "message.picture, message.avatarAuthenticate, message.userId, message.licenseAuthenticate, message.charges, message.cargoType, message.score, message.orderCount, message.messageCount, message.truckLengthSet) "
                + "from CargoMessage message where message.userId=? and message.type>=1 and message.type<=4 ";
        inter = new CargoMessageInterceptor();
    } else if (req.getType() == Constant.MESSAGE_TYPE_FIXED) {
        // Noneed
        return null;
    } else if (req.getType() == Constant.MESSAGE_TYPE_TRUCK) {
        hql = "select new com.consult.app.response.truck.TruckMessageItem"
                + "(message.messageId, message.userId, message.start, message.end, message.travelType,"
                + "profile.userName, message.telephone, message.transfer, "
                + "message.number, message.truckLength, message.truckLoad, message.truckType,"
                + "case when message.type>=" + Constant.TYPE_NORMAL
                + " then 1 else 0 end, message.description, "
                + "message.updateTime, profile.picture, message.commonLines, user.avatarAuthenticate, user.numberAuthenticate) "
                + "from TruckMessage message, Profile profile, User user where user.userId=profile.userId and message.userId=user.userId and message.userId=? ";
        inter = new TruckMessageInterceptor();
    } else {
        return null;
    }
    List<Object> list = new ArrayList<Object>();
    Long triggerTime = req.getAfter();
    if (triggerTime.equals(Long.MAX_VALUE)) {
        triggerTime = System.currentTimeMillis();
    }
    int count = req.getCount();
    //      for(int i = 0; i < Constant.SEARCH_TABLE_COUNT; i++) {
    Session session = null;
    try {
        inter.setShardCriteria(triggerTime);
        session = sessionFactory.openSession(inter);
        Query query = session.createQuery(hql + condition);
        query.setLong(0, userId);
        query.setLong(1, req.getBefore());
        query.setLong(2, req.getAfter());
        query.setFirstResult(0);
        query.setMaxResults(count);
        @SuppressWarnings("unchecked")
        List<Object> tmpList = query.list();
        if (tmpList != null && tmpList.size() > 0) {
            list.addAll(tmpList);
            if (tmpList.size() >= count) {
                return list;
            }
            count -= tmpList.size();
            //               min = metaList.get(metaList.size() - 1).getUpdateTime();
        }
        if (inter.isFinishSearch(req.getBefore())) {
            return list;
        }
        triggerTime = inter.getTriggerTime();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    } finally {
        if (session != null) {
            session.close();
            session = null;
        }
    }
    //      }
    return list;
}

From source file:com.consult.app.dao.impl.UserDaoImpl.java

@Override
public void updatePosition(PostPositionRequest req, long userId, Position user) {
    try {/*from www . j  a v a  2s .  c  om*/
        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 PasswordResponse findPasswordById(Long id) {
    try {/*from   w  w  w. jav  a  2 s  .  c  om*/
        Query query = sessionFactory.getCurrentSession().createQuery(
                "select new com.consult.app.response.PasswordResponse(user.password, user.sessionId, user.announceTime, user.type) from User user where user.userId=?");
        query.setLong(0, id);
        return (PasswordResponse) query.uniqueResult();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.consult.app.dao.impl.UserDaoImpl.java

@Override
public User findByIdFromDB(Long userId) {
    try {/*from w  w w .  j a va2  s .  c o m*/
        Query query = sessionFactory.getCurrentSession().createQuery("from User user where user.userId=?");
        query.setLong(0, userId);
        return (User) query.uniqueResult();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.consult.app.dao.impl.UserDaoImpl.java

@Override
public void clearToken(long userId, String token) {
    try {/*from  w w w  .j av  a  2  s. com*/
        // Changed 20140429: For Send SMS to 
        //update User user set user.token='', user.sessionId=0 where user.userId=?
        String hql = "update User user set user.sessionId=0 where user.userId=?";
        Query query = sessionFactory.getCurrentSession().createQuery(hql);
        query.setLong(0, userId);
        JUserCache.getInstance().removeUser(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  .  j  a va 2  s  .  co  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 {/*ww  w . j  a va 2s .c  o  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 {//www. j  a va2  s .  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 {/*from  w w w .ja  v a 2  s . c o m*/
        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;
    }

}