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 List<Object> getPreAuthenticateUsers(CountTypeRequest req) {
    String hql = "";
    List<Object> list1 = null, list2 = null;
    String cond = "";
    if (req.getType() == 1) {
        cond = " and profile.userType=1 ";
    } else if (req.getType() > 1) {
        cond = " and profile.userType>1 ";
    }/*www.  j  a v  a2 s .co  m*/
    try {
        //String userId, int type, String field1,
        //         String field2, Long updateTime, int userType
        hql = "select new com.consult.app.response.admin.AuthenticateUserItem("
                + "user.userId, 1, cer.idCard, profile.picture, profile.companyName, profile.companyAddress, user.updateTime, profile.userType, user.telephone, cer.idNumber) "
                + "from User user, Profile profile, Certificate cer "
                + "where user.userId=profile.userId and user.certificateId=cer.userId "
                + "and user.avatarAuthenticate=? and user.isAuthenticate=? " + cond
                + " order by user.updateTime asc";
        Query query = sessionFactory.getCurrentSession().createQuery(hql);
        query.setLong(0, Constant.USER_AUTHENTICATE_WAIT);
        query.setLong(1, Constant.USER_AUTHENTICATE_SUCCESS);
        query.setFirstResult(0);
        query.setMaxResults(req.getCount());
        return query.list();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    //      try {
    //         //String userId, int type, String field1,
    ////         String field2, Long updateTime, int userType
    //         hql = "select new com.consult.app.response.admin.AuthenticateUserItem(" +
    //         "user.userId, 2, profile.drivingLicense, profile.number, profile.companyName, profile.companyAddress, user.updateTime, profile.userType, user.telephone, '') " +
    //         "from User user, Profile profile " +
    //         "where user.userId=profile.userId " +
    //         "and user.numberAuthenticate=? order by user.updateTime asc";
    //         Query query = sessionFactory.getCurrentSession().createQuery(hql);
    //         query.setLong(0, Constant.USER_AUTHENTICATE_WAIT);
    //         query.setFirstResult(0);
    //         query.setMaxResults(req.getCount()); 
    //         list2 = query.list();
    //      } catch (Exception e) {
    //         e.printStackTrace();
    //         return null;
    //      }
    //      return Cookie.mergeSort(new ArrayList(list1), new ArrayList(list2), 20, Cookie.ORDER_ASC);
}

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

@Override
public void updateAuthenticate(long userId, int status, int authType) {

    try {/* ww  w.j  ava2  s . co m*/
        String hql = "";

        if (authType == Constant.AUDIT_TYPE_AVATAR) {
            hql = "update User user set user.avatarAuthenticate=?, user.updateTime=? where user.userId=?";
        } else if (authType == Constant.AUDIT_TYPE_DRIVING_LICENSE) {
            hql = "update User user set user.numberAuthenticate=?, user.updateTime=? where user.userId=?";
        } else if (authType == Constant.AUDIT_TYPE_IDNUMBER) {
            if (authType == Constant.USER_AUTHENTICATE_SUCCESS) {
                hql = "update User user set user.isAuthenticate=?, user.updateTime=? where user.userId=?";
            } else {
                hql = "update User user set user.isAuthenticate=?,user.avatarAuthenticate=0,user.updateTime=? where user.userId=?";
            }
        }
        Query query = sessionFactory.getCurrentSession().createQuery(hql);
        query.setLong(0, status);
        query.setLong(1, System.currentTimeMillis());
        query.setLong(2, userId);
        if (query.executeUpdate() > 0) {
            JUserCache.getInstance().removeUser(userId);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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

@Override
public MessageAuthenticateItem getMessageAuthenticate(Long userId) {

    try {//from w w w . j a va2  s  . com
        //int avatarAuthenticate,
        //         int numberAuthenticate, String picture
        String hql = "select new com.consult.app.response.user.MessageAuthenticateItem("
                + "user.userId, user.avatarAuthenticate, user.numberAuthenticate, profile.picture) "
                + "from User user, Profile profile " + "where user.userId=profile.userId and user.userId=?";
        Query query = sessionFactory.getCurrentSession().createQuery(hql);
        query.setLong(0, userId);
        return (MessageAuthenticateItem) query.uniqueResult();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

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

@Override
public List<Object> getPreIdAuthenticateUsers(CountRequest req) {
    try {//from w ww .  j  a va2 s .co  m
        //String userId, int type, String field1,
        //         String field2, Long updateTime, int userType
        String hql = "select new com.consult.app.response.admin.AuthenticateUserItem("
                + "user.userId, 3, certificate.idNumber, certificate.realName, user.updateTime, profile.userType, user.telephone) "
                + "from User user, Certificate certificate, Profile profile "
                + "where user.userId=profile.userId and user.certificateId=certificate.userId "
                + "and user.isAuthenticate=? order by user.userId asc";
        Query query = sessionFactory.getCurrentSession().createQuery(hql);
        query.setLong(0, Constant.USER_AUTHENTICATE_WAIT);
        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 CargoMessageAuthItem getMessageAuthenticateByTel(Long telephone) {

    try {//from ww w.  j  a  v  a2s. c o m
        //int avatarAuthenticate,
        //         int numberAuthenticate, String picture
        String hql = "select new com.consult.app.response.user.CargoMessageAuthItem("
                + "user.userId, user.avatarAuthenticate, user.numberAuthenticate, profile.picture, profile.companyName,"
                + "profile.companyAddress, profile.userName, profile.landlines, profile.userType, profile.score, profile.orderCount, profile.messageCount, user.installPlace) "
                + "from User user, Profile profile " + "where user.userId=profile.userId and user.telephone=?";
        Query query = sessionFactory.getCurrentSession().createQuery(hql);
        query.setLong(0, telephone);
        return (CargoMessageAuthItem) query.uniqueResult();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

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

@Override
public Integer getLoginCount(int userType, long from, long to) {
    try {//ww w  .  ja  va 2 s  .  com
        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 {//from   w  w  w. j  a v  a  2  s.  com
        //         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 {//  ww  w.  j  av  a 2 s.  co m
        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;
    }
}

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

@Override
public List<Object> getReadyToCheckUser(Long startId, int count) {

    try {/* w  ww. ja  v a  2s .  c  om*/
        //         String content, Integer pushType, String token,
        //         Integer notificationType, int badgeCount
        String hql = "from User user " + "where user.userId>? and user.smsLocate=? order by user.userId asc";
        Query query = sessionFactory.getCurrentSession().createQuery(hql);
        query.setLong(0, startId);
        query.setInteger(1, Constant.SMS_LOCATE_READY_TO_CHECK);
        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 void disableSms(Long userId, int trigger) {
    try {//w ww  .  j a  va2  s  .co m
        Query query = sessionFactory.getCurrentSession()
                .createQuery("update User obj set obj.pushSubscribe=? where obj.userId=?");
        query.setInteger(0, trigger);
        query.setLong(1, userId);
        if (query.executeUpdate() > 0) {
            JUserCache.getInstance().removeUser(userId);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}