Example usage for org.hibernate Query setParameterList

List of usage examples for org.hibernate Query setParameterList

Introduction

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

Prototype

Query<R> setParameterList(int position, Object[] values);

Source Link

Usage

From source file:com.viettel.vsaadmin.database.DAOHibernate.UsersDAOHE.java

License:Open Source License

/**
 * tim kiem chuyen vien phoi hop tham dinh
 *
 * @param staffs/*from  w ww. j  a va2  s.co m*/
 * @param start
 * @param count
 * @return
 */
public GridResult getCoordinateStaffs(String staffs, int start, int count) {
    List lstResult = new ArrayList<Users>();
    int total = 0;
    GridResult gridResult = new GridResult();
    try {
        if (staffs != null && !"".equals(staffs)) {
            String[] depts = staffs.split(";");
            Long[] deptId = new Long[depts.length];
            for (int i = 0; i < depts.length; i++) {
                deptId[i] = Long.parseLong(depts[i]);
            }
            String countSql = "SELECT count(u) FROM Users u WHERE u.status = :status and u.userId IN (:userIds) "; // and u.userId <> ?
            Query query = getSession().createQuery(countSql);
            query.setParameter("status", Constants.Status.ACTIVE);
            query.setParameterList("userIds", Arrays.asList(deptId));
            // query.setParameter(2, userId);
            total = Integer.parseInt(query.list().get(0).toString());
            String sql = "SELECT u FROM Users u WHERE u.status = :status and u.userId IN (:userIds) "
                    + " order by nlssort(lower(u.fullName),'nls_sort = Vietnamese') "; // and u.userId <> ?
            query = getSession().createQuery(sql);
            query.setParameter("status", Constants.Status.ACTIVE);
            query.setParameterList("userIds", Arrays.asList(deptId));
            query.setFirstResult(start);
            query.setMaxResults(count);
            lstResult = query.list();
        }
        gridResult.setLstResult(lstResult);
        gridResult.setnCount(Long.valueOf(total));

        return gridResult;
    } catch (Exception ex) {
        LogUtil.addLog(ex);//binhnt sonar a160901
        //            log.error(ex.getMessage());
        return null;
    }
}

From source file:com.viettel.vsaadmin.database.DAOHibernate.UsersDAOHE.java

License:Open Source License

public List<Users> getLeaderByUser(Long deptLoginUser) {
    try {//from w  w w. j  a va 2 s.  c  o m
        // 11/11/2014 viethd
        //Query queryDepts = getSession().createSQLQuery("select PARENT_ID from DEPARTMENT where status = 1 start with DEPT_ID = " + deptLoginUser + " connect by prior DEPT_ID =  PARENT_ID");
        Query queryDepts = getSession().createSQLQuery("select PARENT_ID from DEPARTMENT "
                + "where status = 1 start with DEPT_ID = ? connect by prior DEPT_ID =  PARENT_ID");
        queryDepts.setParameter(0, deptLoginUser);
        List<BigDecimal> depts = queryDepts.list();

        List<Long> longList = new ArrayList<Long>();
        for (BigDecimal i : depts) {
            longList.add(i.longValue());
        }
        if (depts != null && depts.size() > 0) {

            //11/11/2014 viethd
            //                Query query = getSession().createQuery("SELECT u FROM Users u "
            //                        + "WHERE u.status = 1 "
            //                        + "AND u.posId IN (SELECT p.posId FROM Position p WHERE p.status = 1 AND p.posCode LIKE ? escape '!' or p.posCode LIKE ? escape '!') "
            //                        + "AND (u.deptId IN (" + lstDept + ")"
            //                        + "OR u.deptRepresentId IN (" + lstDept + ")) "
            //                        + "order by u.posId asc, nlssort(lower(u.fullName),'nls_sort = Vietnamese') "
            //                );
            Query query = getSession().createQuery("SELECT u FROM Users u " + "WHERE u.status = 1 "
                    + "AND u.posId IN (SELECT p.posId FROM Position p WHERE p.status = 1 AND p.posCode LIKE ? escape '!' or p.posCode LIKE ? escape '!') "
                    + "AND (u.deptId IN (:depts1)" + "OR u.deptRepresentId IN (:depts2)) "
                    + "order by u.posId asc, nlssort(lower(u.fullName),'nls_sort = Vietnamese') ");

            query.setParameter(0, "%" + Constants.POSITION.LEADER_CT + "%");
            query.setParameter(1, "%" + Constants.POSITION.LEADER_PCT + "%");
            query.setParameterList("depts1", longList);
            query.setParameterList("depts2", longList);
            List<Users> user = query.list();
            return user;
        }
        return null;
    } catch (Exception ex) {
        LogUtil.addLog(ex);//binhnt sonar a160901
        //            log.error(e.getMessage());
        return null;
    }
}

From source file:com.viettel.vsaadmin.database.DAOHibernate.UsersDAOHE.java

License:Open Source License

/**
 * tim kiem user theo danh sach chuc vu binhnt 08102015
 *
 * @param deptId/*from ww w. j a va2s.  c om*/
 * @param lstPosCode
 * @return
 */
public List<Users> findLstUserByLstPosition(Long deptId, List<String> lstPosCode) {
    List<Users> user = new ArrayList<Users>();
    try {
        Query query = getSession().createQuery("select u from Users u"
                + " where u.status=? and u.deptId = ? and " + " u.posId in (select p.posId" + " from Position p"
                + " where p.posCode in (:lstPosCode)" + " and p.status = 1" + " and p.posType = 1)");
        query.setParameter(0, Constants.Status.ACTIVE);
        query.setParameter(1, deptId);
        query.setParameterList("lstPosCode", lstPosCode);
        user = (List<Users>) query.list();
        if (user.size() > 0) {
            return user;
        }
    } catch (Exception ex) {
        LogUtil.addLog(ex);//binhnt sonar a160901
        //            log.error(ex.getMessage());
    }
    return null;
}

From source file:com.viettel.vsaadmin.database.DAOHibernate.UsersDAOHE.java

License:Open Source License

public boolean checkUserByLstPosition(Long deptId, Long userId, List<String> lstPosCode) {
    boolean result = false;
    List<Users> user = new ArrayList<>();
    try {//  w ww. ja  v a 2 s  . c o m
        Query query = getSession()
                .createQuery("select u from Users u" + " where u.status= ?" + " and u.deptId = ?"
                        + " and u.userId = ?" + " and u.posId in (select p.posId" + " from Position p"
                        + " where p.posCode in (:lstPosCode)" + " and p.status = 1" + " and p.posType = 1)");
        query.setParameter(0, Constants.Status.ACTIVE);
        query.setParameter(1, deptId);
        query.setParameter(2, userId);
        query.setParameterList("lstPosCode", lstPosCode);
        user = (List<Users>) query.list();
        if (user.size() > 0) {
            result = true;
        }
    } catch (Exception ex) {
        LogUtil.addLog(ex);//binhnt sonar a160901
        //            log.error(ex.getMessage());
    }
    return result;
}

From source file:com.viettel.vsaadmin.database.DAOHibernate.UsersDAOHE.java

License:Open Source License

/**
 *
 * @param deptId/*from   w w  w .  j  av a 2s.  co m*/
 * @param userId
 * @param lstPosCode
 * @return
 */
public boolean checkRoleUserOfLst(Long deptId, Long userId, List<String> lstPosCode) {
    boolean result = false;
    List<Users> user = new ArrayList<Users>();
    try {
        Query query = getSession()
                .createQuery("select u from Users u" + " where u.status= ?" + " and u.deptId = ?"
                        + " and u.userId = ?" + " and u.posId in (select p.posId" + " from Position p"
                        + " where p.posCode in (:lstPosCode)" + " and p.status = 1" + " and p.posType = 1)");
        query.setParameter(0, Constants.Status.ACTIVE);
        query.setParameter(1, deptId);
        query.setParameter(2, userId);
        query.setParameterList("lstPosCode", lstPosCode);
        user = (List<Users>) query.list();
        if (user.size() > 0) {
            result = true;
        }
    } catch (Exception ex) {
        LogUtil.addLog(ex);//binhnt sonar a160901
        //            log.error(ex.getMessage());
    }
    return result;
}

From source file:com.wavemaker.runtime.data.task.NamedQueryTask.java

License:Open Source License

private void handleBindParams(Query query, String queryName, Object[] paramValues, DataServiceMetaData meta) {

    NamedQueryDefinition def = meta.getQueryDefinition(queryName);

    Map<String, String> m = CastUtils.cast(def.getParameterTypes());

    String paramNames[] = new String[m.size()];
    String paramTypes[] = new String[m.size()];

    int i = 0;/*  w ww.jav a2s  . c  o m*/
    for (Map.Entry<String, String> e : m.entrySet()) {
        paramNames[i] = e.getKey();
        paramTypes[i] = e.getValue();
        i++;
    }

    if (paramTypes.length == 0) {
        if (paramValues.length > 0) {
            logExtraParam(queryName, paramValues);
        }
    } else {
        if (paramValues.length == 0) {
            throw new DataServiceRuntimeException(MessageResource.QUERY_REQUIRES_PARAMS, queryName,
                    ObjectUtils.toString(paramTypes));
        }

        // REVIEW 09-Sep-07 stoens@activegrid.com --
        // verify handling of datetime types here
        for (int j = 0; j < paramValues.length; j++) {
            String name = paramNames[j];
            Object value = paramValues[j];
            if (value != null && Collection.class.isAssignableFrom(value.getClass())) {
                query.setParameterList(name, (Collection) value);
            } else {
                query.setParameter(name, value);
            }
        }
    }
}

From source file:com.wavemaker.runtime.data.task.QueryTask.java

License:Open Source License

@SuppressWarnings("unchecked")
protected void prepareQuery(Query query, Map<String, BindParameter> bindParams, PagingOptions pagingOptions) {

    for (Map.Entry<String, BindParameter> e : bindParams.entrySet()) {

        String name = e.getKey();
        Object value = e.getValue().value;

        if (value != null && Collection.class.isAssignableFrom(value.getClass())) {
            query.setParameterList(name, (Collection<Object>) value);
        } else {//from   w  ww  .j  av  a  2 s.c  o m
            query.setParameter(name, value);
        }
    }

    applyPaging(pagingOptions, query);

}

From source file:com.wideplay.warp.persist.hibernate.HibernateFinderInterceptor.java

License:Apache License

private void bindQueryNamedParameters(Query hibernateQuery, FinderDescriptor descriptor, Object[] arguments) {
    for (int i = 0; i < arguments.length; i++) {
        Object argument = arguments[i];
        Object annotation = descriptor.parameterAnnotations[i];

        if (null == annotation)
            continue; //skip param as it's not bindable
        else if (annotation instanceof Named) {
            Named named = (Named) annotation;
            if (Collection.class.isAssignableFrom(argument.getClass())) {
                hibernateQuery.setParameterList(named.value(), (Collection) argument);
            } else if (argument.getClass().isArray()) {
                hibernateQuery.setParameterList(named.value(), (Object[]) argument);
            } else {
                hibernateQuery.setParameter(named.value(), argument);
            }// w w w.ja  va 2  s .  c  o m
        } else if (annotation instanceof FirstResult)
            hibernateQuery.setFirstResult((Integer) argument);
        else if (annotation instanceof MaxResults)
            hibernateQuery.setMaxResults((Integer) argument);
    }
}

From source file:com.wm.framework.sh.dao.impl.BaseDaoImpl.java

License:Open Source License

@SuppressWarnings("rawtypes")
protected void prepareQueryParams(Query query, List<SearchCondition> searchConditions) {
    if (searchConditions == null) {
        return;// ww w .  ja v a2  s  . co  m
    }
    int index = 0;
    for (SearchCondition searchCondition : searchConditions) {
        if (null == searchCondition) {
            continue;
        }
        if (searchCondition.getOperator() == CompareOperator.Like) {
            query.setParameter("param" + index++, "%" + searchCondition.getValue() + "%");
        } else if (searchCondition.getOperator() == CompareOperator.In) {
            query.setParameterList("param" + index++, (Collection) searchCondition.getValue());
        } else if (searchCondition.getOperator() == CompareOperator.IsNull) {

        } else {
            query.setParameter("param" + index++, searchCondition.getValue());
        }
    }
}

From source file:com.xplatform.base.system.attachment.service.impl.AttachServiceImpl.java

@Override
public List<AttachEntity> queryAttachsByIds(String aIds) throws BusinessException {
    List<AttachEntity> attachList = new ArrayList<AttachEntity>();
    if (StringUtil.isNotEmpty(aIds)) {
        String hql = "FROM AttachEntity WHERE id in (:ids)";
        Query q = this.commonDao.getSession().createQuery(hql);
        q.setParameterList("ids", aIds.split(","));
        attachList = q.list();//from  ww w.  j  a va 2s  .c  om
    }
    return attachList;
}