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.green.common.persistence.BaseDao.java

License:Open Source License

/**
 * ?/*  ww w  .  ja  v a 2 s .  c  o  m*/
 * @param query
 * @param parameter
 */
private void setParameter(Query query, Parameter parameter) {
    if (parameter != null) {
        Set<String> keySet = parameter.keySet();
        for (String string : keySet) {
            Object value = parameter.get(string);
            //?????  
            if (value instanceof Collection<?>) {
                query.setParameterList(string, (Collection<?>) value);
            } else if (value instanceof Object[]) {
                query.setParameterList(string, (Object[]) value);
            } else {
                query.setParameter(string, value);
            }
        }
    }
}

From source file:com.heimaide.server.common.persistence.BaseDao.java

License:Open Source License

/**
 * ?//from www.  j  av a  2  s  .co m
 *
 * @param query
 * @param parameter
 */
private void setParameter(Query query, Parameter parameter) {
    if (parameter != null) {
        Set<String> keySet = parameter.keySet();
        for (String string : keySet) {
            Object value = parameter.get(string);
            // ?????
            if (value instanceof Collection<?>) {
                query.setParameterList(string, (Collection<?>) value);
            } else if (value instanceof Object[]) {
                query.setParameterList(string, (Object[]) value);
            } else {
                query.setParameter(string, value);
            }
        }
    }
}

From source file:com.iana.dver.dao.impl.DverDetailsDaoImpl.java

License:Open Source License

@Override
public List<DverDetail> findSelectedRejectedDversForExcel(final List<Integer> dverSelectedIdList)
        throws DataAccessException {

    logger.info("Find selected Rejected Dvers for Excel report....");
    List rejectedDvers = getHibernateTemplate().executeFind(new HibernateCallback<List<DverDetail>>() {
        @Override//www  .j  av a2 s. c  om
        public List<DverDetail> doInHibernate(Session session) throws HibernateException, SQLException {
            Query q = session.createQuery(FIND_SELECTED_REJECTED_DVERS);
            q.setParameterList("dverDetailIds", dverSelectedIdList);
            return q.list();
        }
    });

    return (!CollectionUtils.isEmpty(rejectedDvers)) ? rejectedDvers : new ArrayList<DverDetail>();
}

From source file:com.iana.dver.dao.impl.DverDetailsDaoImpl.java

License:Open Source License

@Override
public List<byte[]> getDverFilesFromDverDetailIds(final List<Integer> dverDetailsIds)
        throws DataAccessException {
    List files = getHibernateTemplate().executeFind(new HibernateCallback<List<byte[]>>() {
        @Override//from w  w w .  java  2s .  c  o  m
        public List<byte[]> doInHibernate(Session session) throws HibernateException, SQLException {
            logger.info("get DverFiles From DverDetailIds ....");
            Query query = session.createQuery(FIND_DVER_FILE_VO_FROM_DVER_DETAIL_ID);
            query.setParameterList("dverDetailIds", dverDetailsIds);
            return query.list();
        }
    });
    return (!CollectionUtils.isEmpty(files)) ? files : new ArrayList<byte[]>();
}

From source file:com.impetus.client.rdbms.HibernateClient.java

License:Apache License

/**
 * Sets the parameters.//from  www  . jav a  2 s .c  om
 * 
 * @param parameterMap
 *            the parameter map
 * @param q
 *            the q
 */
private void setParameters(Map<Parameter, Object> parameterMap, Query q) {
    if (parameterMap != null && !parameterMap.isEmpty()) {
        for (Parameter parameter : parameterMap.keySet()) {
            Object paramObject = parameterMap.get(parameter);
            if (parameter.getName() != null) {
                if (paramObject instanceof Collection) {
                    q.setParameterList(parameter.getName(), (Collection) paramObject);
                } else {
                    q.setParameter(parameter.getName(), paramObject);
                }
            } else if (parameter.getPosition() != null) {
                if (paramObject instanceof Collection) {
                    q.setParameterList(Integer.toString(parameter.getPosition()), (Collection) paramObject);
                } else {
                    q.setParameter(Integer.toString(parameter.getPosition()), paramObject);
                }
            }
        }
    }
}

From source file:com.inkubator.hrm.dao.impl.EmpCareerHistoryDaoImpl.java

private Query setValueQueryEmpEliminationViewModelByParam(Query hbm, EmpEliminationSearchParameter parameter) {
    for (String param : hbm.getNamedParameters()) {
        if (StringUtils.equals(param, "empName")) {
            hbm.setParameter("empName", "%" + parameter.getEmpName() + "%");
        } else if (StringUtils.equals(param, "nik")) {
            hbm.setParameter("nik", "%" + parameter.getNik() + "%");
        } else if (StringUtils.equals(param, "lastJabatanName")) {
            hbm.setParameter("lastJabatanName", "%" + parameter.getLastJabatanName() + "%");
        }//from  ww  w.j a  v a 2  s  .c o  m
    }

    hbm.setParameterList("listCareerHistoryStatus",
            Arrays.asList(HRMConstant.EMP_TERMINATION, HRMConstant.EMP_STOP_CONTRACT, HRMConstant.EMP_LAID_OFF,
                    HRMConstant.EMP_PENSION, HRMConstant.EMP_DISCHAGED));
    return hbm;
}

From source file:com.inkubator.hrm.dao.impl.EmpDataDaoImpl.java

@Override
public List<EmpData> getAllDataByCompanyIdAndEmpTypeAndGolJabAndUnitKerja(Long companyId, List<Long> empTypes,
        List<Long> golJabs, List<Long> unitKerjas) {
    StringBuffer selectQuery = new StringBuffer("SELECT empData " + "FROM EmpData as empData "
            + "INNER JOIN empData.jabatanByJabatanId as jabatan " + "INNER JOIN jabatan.unitKerja as unitKerja "
            + "INNER JOIN jabatan.department as department " + "INNER JOIN department.company as company "
            + "INNER JOIN empData.employeeType as employeeType "
            + "INNER JOIN empData.golonganJabatan as golonganJabatan " + "WHERE company.id = :companyId "
            + "AND status != :status ");

    if (!empTypes.isEmpty()) {
        selectQuery.append("AND employeeType.id IN (:employeeTypes) ");
    }// w  w w. ja v a2s  .c  om
    if (!golJabs.isEmpty()) {
        selectQuery.append("AND golonganJabatan.id IN (:golonganJabatans) ");
    }
    if (!unitKerjas.isEmpty()) {
        selectQuery.append("AND unitKerja.id IN (:unitKerjas) ");
    }

    Query hbm = getCurrentSession().createQuery(selectQuery.toString()).setParameter("companyId", companyId)
            .setParameter("status", HRMConstant.EMP_TERMINATION);
    if (!empTypes.isEmpty()) {
        hbm.setParameterList("employeeTypes", empTypes);
    }
    if (!golJabs.isEmpty()) {
        hbm.setParameterList("golonganJabatans", golJabs);
    }
    if (!unitKerjas.isEmpty()) {
        hbm.setParameterList("unitKerjas", unitKerjas);
    }

    return hbm.list();
}

From source file:com.inkubator.hrm.dao.impl.RecruitSelectionApplicantInitialDaoImpl.java

private Query setValueQueryRecruitmentScheduleSettingByParam(Query hbm,
        RecruitmentScheduleSettingSearchParameter parameter) {
    for (String param : hbm.getNamedParameters()) {
        if (StringUtils.equals(param, "careerCandidate")) {
            hbm.setParameter("careerCandidate", parameter.getCandidateStatusId());
        } else if (StringUtils.equals(param, "listJabatanOnSelectedMppApply")) {
            hbm.setParameterList("listJabatanOnSelectedMppApply", parameter.getListJabatanOnSelectedMppApply());
        }/*from   w  w  w.  j a v  a 2 s. c o  m*/
    }
    return hbm;
}

From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.hibernate.HQLFieldsReader.java

License:Open Source License

/**
 * Binds a paramter value to a query paramter.
 * //from   w  w w .j  ava2s .  c o m
 * @param parameter the report parameter
 */
protected void setParameter(Session session, Query query, String hqlParamName, Object parameterValue)
        throws Exception {
    //ClassLoader cl = MainFrame.getMainInstance().getReportClassLoader();

    if (parameterValue == null) {
        query.setParameter(hqlParamName, parameterValue);
        return;
    }

    Class clazz = parameterValue.getClass();
    Type type = (Type) hibernateTypeMap.get(clazz);

    if (type != null) {
        query.setParameter(hqlParamName, parameterValue, type);
    } else if (Collection.class.isAssignableFrom(clazz)) {
        query.setParameterList(hqlParamName, (Collection) parameterValue);
    } else {
        if (session.getSessionFactory().getClassMetadata(clazz) != null) //param type is a hibernate mapped entity
        {
            query.setEntity(hqlParamName, parameterValue);
        } else //let hibernate try to guess the type
        {
            query.setParameter(hqlParamName, parameterValue);
        }
    }
}

From source file:com.jdon.persistence.hibernate.HibernateTemplate.java

License:Apache License

/**
 * Apply the given name parameter to the given Query object.
 * //from   w  w w . j a va 2  s  . co m
 * @param queryObject
 *            the Query object
 * @param paramName
 *            the name of the parameter
 * @param value
 *            the value of the parameter
 * @throws HibernateException
 *             if thrown by the Query object
 */
protected void applyNamedParameterToQuery(Query queryObject, String paramName, Object value)
        throws HibernateException {

    if (value instanceof Collection) {
        queryObject.setParameterList(paramName, (Collection) value);
    } else if (value instanceof Object[]) {
        queryObject.setParameterList(paramName, (Object[]) value);
    } else {
        queryObject.setParameter(paramName, value);
    }
}