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.globalsight.persistence.hibernate.HibernateUtil.java

License:Apache License

/**
 * Execute the hql, return the result./*from w  w  w .  j a  v  a2 s.  c o  m*/
 * 
 * @param hql
 *            The hql to execute.
 * @param map
 *            Includes common parameters.
 * @param map2
 *            includes list parameters.
 * @return The search result.
 */
public static List<?> search(String hql, Map<String, ?> map, Map<String, Collection<?>> map2) {
    List<?> result = new ArrayList<Object>();

    if (hql != null) {
        Session session = getSession();
        Query query = session.createQuery(hql);

        if (map != null) {
            Iterator<String> iterator = map.keySet().iterator();
            while (iterator.hasNext()) {
                String key = iterator.next();
                query.setParameter(key, map.get(key));
            }
        }

        if (map2 != null) {
            Iterator<String> iterator = map2.keySet().iterator();
            while (iterator.hasNext()) {
                String key = iterator.next();
                query.setParameterList(key, map2.get(key));
            }
        }

        result = query.list();
    }

    return result;
}

From source file:com.gonzasilve.puntoventas.pvcore.dao.hibernate.HibernateSearchProcessor.java

License:Apache License

@SuppressWarnings("unchecked")
private void addParams(Query query, List<Object> params) {
    StringBuilder debug = null;//from   ww w.j av a2s . co  m

    int i = 1;
    for (Object o : params) {
        if (logger.isDebugEnabled()) {
            if (debug == null)
                debug = new StringBuilder();
            else
                debug.append("\n\t");
            debug.append("p");
            debug.append(i);
            debug.append(": ");
            debug.append(SearchInternalUtil.paramDisplayString(o));
        }
        if (o instanceof Collection) {
            query.setParameterList("p" + Integer.toString(i++), (Collection) o);
        } else if (o instanceof Object[]) {
            query.setParameterList("p" + Integer.toString(i++), (Object[]) o);
        } else {
            query.setParameter("p" + Integer.toString(i++), o);
        }
    }
    if (debug != null && debug.length() != 0) {
        logger.debug(debug.toString());
    }
}

From source file:com.googlecode.hibernate.audit.HibernateAudit.java

License:Open Source License

public static List<AuditObjectProperty> getModifiedAuditObjectProperties(Session session,
        List<AuditTypeField> auditTypeFieldsToCheck, String targetEntityId, Long afterAuditTransactionId) {
    Query query = session.getNamedQuery(SELECT_MODIFIED_AUDIT_OBJECT_PROPERTIES);
    query.setParameterList("auditTypeFields", auditTypeFieldsToCheck);
    query.setParameter("targetEntityId", targetEntityId);
    query.setParameter("afterAuditTransactionId", afterAuditTransactionId);

    List<AuditObjectProperty> result = (List<AuditObjectProperty>) query.list();
    return result;
}

From source file:com.googlecode.hibernate.audit.HibernateAudit.java

License:Open Source License

public static List<AuditTypeField> getModifiedAuditTypeFields(Session session,
        List<AuditTypeField> auditTypeFieldsToCheck, String targetEntityId, Long afterAuditTransactionId) {
    Query query = session.getNamedQuery(SELECT_MODIFIED_AUDIT_TYPE_FIELDS);
    query.setParameterList("auditTypeFields", auditTypeFieldsToCheck);
    query.setParameter("targetEntityId", targetEntityId);
    query.setParameter("afterAuditTransactionId", afterAuditTransactionId);

    List<AuditTypeField> result = (List<AuditTypeField>) query.list();
    return result;
}

From source file:com.gp.cong.lcl.common.constant.ExportUnitQueryUtils.java

public String getINTRCargo(int pol, int pod, Long unitSsId, List fileList) throws Exception {
    StringBuilder sb = new StringBuilder();
    sb.append(/*from  w w  w  .jav a  2 s .  c o  m*/
            " SELECT GROUP_CONCAT(distinct fn.fileId) FROM (SELECT distinct bkp.file_number_id AS fileId FROM lcl_booking_piece bkp ");
    if (null != unitSsId) {
        sb.append(" Left JOIN  lcl_booking_piece_unit bpu ON  bpu.`booking_piece_id` = bkp.`id`   ");
        sb.append(" JOIN lcl_unit_ss luss ON luss.id = bpu.`lcl_unit_ss_id` WHERE luss.id =:unitSsId ) fn");
    } else {
        sb.append(" where bkp.file_number_id in(:fileList) )fn");
    }
    sb.append(" JOIN  lcl_booking b ON b.`file_number_id` = fn.fileId ");
    sb.append(" JOIN lcl_file_number f  ON f.`id` = b.`file_number_id` ");
    sb.append(" JOIN lcl_booking_piece bp     ON bp.`file_number_id` = f.`id`   JOIN lcl_booking_dispo dispo ");
    sb.append(
            " ON b.`file_number_id` = dispo.`file_number_id`   JOIN disposition d     ON dispo.`disposition_id` = d.id ");
    sb.append(
            " AND d.`elite_code` =  (SELECT   d.`elite_code` FROM   lcl_booking_dispo dispo   JOIN disposition d  ");
    sb.append(
            " ON d.`id` = dispo.`disposition_id` WHERE dispo.`file_number_id` = b.`file_number_id` ORDER BY dispo.id DESC LIMIT 1)  ");
    sb.append(" WHERE  b.`pol_id` =:pol  AND  b.`pod_id` =:pod  AND d.`elite_code` = 'INTR' ");
    Query queryObject = getCurrentSession().createSQLQuery(sb.toString());
    if (null != unitSsId) {
        queryObject.setLong("unitSsId", unitSsId);
    } else {
        queryObject.setParameterList("fileList", fileList);
    }
    queryObject.setInteger("pol", pol);
    queryObject.setInteger("pod", pod);
    return (String) queryObject.uniqueResult();
}

From source file:com.gp.cong.lcl.common.constant.ExportUnitQueryUtils.java

public String toArriveBookingList(Long unitssId, int poo, int pol, List fileList) throws Exception {
    StringBuilder sb = new StringBuilder();
    sb.append(//from  ww  w.  j  a va 2  s.  co  m
            " SELECT GROUP_CONCAT(distinct fn.fileId) FROM (SELECT distinct bkp.file_number_id AS fileId FROM lcl_booking_piece bkp ");
    sb.append(" join lcl_booking b on b.file_number_id = bkp.file_number_id  ");
    if (null != unitssId) {
        sb.append(
                "  Left JOIN  lcl_booking_piece_unit bpu ON  bpu.`booking_piece_id` = bkp.`id`  JOIN lcl_unit_ss luss ON luss.id = bpu.`lcl_unit_ss_id` ");
    }
    sb.append(getBookingDispo());
    sb.append(" WHERE b.poo_id =:poo AND b.`pol_id` =:pol   ");
    if (null != unitssId) {
        sb.append(" and luss.id =:unitSsId ");
    } else {
        sb.append(" and bkp.file_number_id in(:fileList) ");
    }
    sb.append(" AND d.`elite_code` = 'OBKG' ) fn  ");
    Query queryObject = getCurrentSession().createSQLQuery(sb.toString());
    queryObject.setInteger("poo", poo);
    queryObject.setInteger("pol", pol);
    if (null != unitssId) {
        queryObject.setLong("unitSsId", unitssId);
    } else {
        queryObject.setParameterList("fileList", fileList);
    }
    return (String) queryObject.uniqueResult();
}

From source file:com.gp.cong.lcl.common.constant.ExportUnitQueryUtils.java

public String getGeneralCargoBkgList(Long unitssId, String serviceType, List fileList) throws Exception {
    StringBuilder sb = new StringBuilder();

    String secure_cargo = getSecureCargoBkgList(unitssId, serviceType, fileList);
    String ups_cargo = getUPSCargoBkgList(unitssId, serviceType, fileList);
    String hazmat_cargo = getHazmatCargoBkgList(unitssId, serviceType, fileList);

    secure_cargo = null != secure_cargo ? secure_cargo + "," : "";
    ups_cargo = null != ups_cargo ? ups_cargo + "," : "";
    hazmat_cargo = null != hazmat_cargo ? hazmat_cargo : "";

    String booking_ids = secure_cargo + "" + ups_cargo + "" + hazmat_cargo;

    List secure_ups_bkg = !"".equalsIgnoreCase(booking_ids) ? Arrays.asList(booking_ids.split(","))
            : new ArrayList();

    sb.append(//from   w  w w  .j av  a2 s .  c  om
            " SELECT GROUP_CONCAT(distinct fn.fileId) FROM (SELECT distinct bkp.file_number_id AS fileId FROM lcl_booking_piece bkp ");
    if (null != unitssId) {
        sb.append(" Left JOIN  lcl_booking_piece_unit bpu ON  bpu.`booking_piece_id` = bkp.`id`   ");
        sb.append(" JOIN lcl_unit_ss luss ON luss.id = bpu.`lcl_unit_ss_id` ");
    }
    sb.append(getBookingDispo());
    if (null != unitssId) {
        sb.append(" WHERE luss.id =:unitSsId ");
    } else {
        sb.append(" WHERE bkp.file_number_id in(:fileList) ");
    }
    if ("E".equalsIgnoreCase(serviceType) || "C".equalsIgnoreCase(serviceType)) {
        sb.append(" AND d.`elite_code` != 'INTR' ");
    } else if ("N".equalsIgnoreCase(serviceType)) {
        sb.append(" and d.`elite_code` != 'OBKG'");
    }
    sb.append(!secure_ups_bkg.isEmpty() ? " AND bkp.file_number_id NOT IN (:BkgId)" : "").append(") fn");
    Query queryObject = getCurrentSession().createSQLQuery(sb.toString());
    if (null != unitssId) {
        queryObject.setLong("unitSsId", unitssId);
    } else {
        queryObject.setParameterList("fileList", fileList);
    }
    if (!secure_ups_bkg.isEmpty()) {
        queryObject.setParameterList("BkgId", secure_ups_bkg);
    }
    return (String) queryObject.uniqueResult();
}

From source file:com.gp.cong.lcl.common.constant.ExportUnitQueryUtils.java

public String getHazmatCargoBkgList(Long unitssId, String serviceType, List fileList) throws Exception {
    StringBuilder sb = new StringBuilder();
    sb.append(//from  w  ww  .j  av a  2 s.  com
            " SELECT GROUP_CONCAT(distinct fn.fileId) FROM (SELECT distinct bkp.file_number_id AS fileId FROM lcl_booking_piece bkp ");
    if (unitssId != null) {
        sb.append(" Left JOIN  lcl_booking_piece_unit bpu ON  bpu.`booking_piece_id` = bkp.`id`   ");
        sb.append(" JOIN lcl_unit_ss luss ON luss.id = bpu.`lcl_unit_ss_id` ");
    }
    sb.append(getBookingDispo());
    sb.append(" WHERE  bkp.hazmat = 1  ");
    if (null != unitssId) {
        sb.append(" and luss.id =:unitSsId ");
    } else {
        sb.append(" and bkp.file_number_id IN(:fileList) ");
    }
    if ("E".equalsIgnoreCase(serviceType)) {
        sb.append(" AND d.`elite_code` != 'INTR' ");
    } else if ("N".equalsIgnoreCase(serviceType)) {
        sb.append(" and d.`elite_code` != 'OBKG' ");
    }
    sb.append(" ) fn");
    Query queryObject = getCurrentSession().createSQLQuery(sb.toString());
    if (null != unitssId) {
        queryObject.setLong("unitSsId", unitssId);
    } else {
        queryObject.setParameterList("fileList", fileList);
    }
    return (String) queryObject.uniqueResult();
}

From source file:com.gp.cong.lcl.common.constant.ExportUnitQueryUtils.java

public String getSecureCargoBkgList(Long unitssId, String serviceType, List<String> fileList) throws Exception {
    StringBuilder sb = new StringBuilder();
    sb.append(//from ww w  .j a va 2 s. c om
            " SELECT GROUP_CONCAT(distinct fn.fileId) FROM (SELECT distinct bkp.file_number_id AS fileId FROM lcl_booking_piece bkp ");
    sb.append(getBookingDispo());
    if (null != unitssId) {
        sb.append(" Left JOIN  lcl_booking_piece_unit bpu ON  bpu.`booking_piece_id` = bkp.`id`   ");
        sb.append(" JOIN lcl_unit_ss luss ON luss.id = bpu.`lcl_unit_ss_id` ");
    }
    sb.append(" JOIN  lcl_booking_piece_whse  bkw ON bkw.id = (SELECT bw.id FROM lcl_booking_piece_whse bw ");
    sb.append(" WHERE bw.`booking_piece_id` = bkp.`id`AND bw.location <> ''  order by bw.id desc LIMIT 1) ");
    sb.append(" AND ( bkw.`location`  LIKE 's%' AND  bkw.`location` NOT LIKE 'r%')  WHERE  bkp.hazmat = 0  ");
    if (null != unitssId) {
        sb.append(" and luss.id =:unitSsId ");
    } else {
        sb.append(" and bkp.file_number_id IN(:fileList) ");
    }
    if ("E".equalsIgnoreCase(serviceType)) {
        sb.append(" AND d.`elite_code` != 'INTR' ");
    } else if ("N".equalsIgnoreCase(serviceType)) {
        sb.append(" and d.`elite_code` != 'OBKG' ");
    }
    sb.append(" ) fn");
    Query queryObject = getCurrentSession().createSQLQuery(sb.toString());
    if (null != unitssId) {
        queryObject.setLong("unitSsId", unitssId);
    } else {
        queryObject.setParameterList("fileList", fileList);
    }
    return (String) queryObject.uniqueResult();
}

From source file:com.gp.cong.lcl.common.constant.ExportUnitQueryUtils.java

public String getUPSCargoBkgList(Long unitssId, String serviceType, List<String> fileList) throws Exception {
    StringBuilder sb = new StringBuilder();
    sb.append(//  w w  w . j a v  a 2s .  c o m
            " SELECT GROUP_CONCAT(distinct fn.fileId) FROM (SELECT distinct bkp.file_number_id AS fileId FROM lcl_booking_piece bkp ");
    if (null != unitssId) {
        sb.append(" Left JOIN  lcl_booking_piece_unit bpu ON  bpu.`booking_piece_id` = bkp.`id`   ");
        sb.append(" JOIN lcl_unit_ss luss ON luss.id = bpu.`lcl_unit_ss_id` ");
    }
    sb.append(
            " JOIN lcl_booking_dispo dispo ON bkp.`file_number_id` = dispo.`file_number_id`   JOIN disposition d ON dispo.`disposition_id` = d.id ");
    sb.append(
            " AND d.`elite_code` = (SELECT   d.`elite_code` FROM   lcl_booking_dispo dispo   JOIN disposition d  ");
    sb.append(
            " ON d.`id` = dispo.`disposition_id` WHERE dispo.`file_number_id` = bkp.`file_number_id` ORDER BY dispo.id DESC LIMIT 1)  ");
    sb.append(" JOIN  lcl_booking_piece_whse  bkw ON bkw.id = (SELECT bw.id FROM lcl_booking_piece_whse bw  ");
    sb.append(" WHERE bw.`booking_piece_id` = bkp.`id`AND bw.location <> '' order by bw.id desc LIMIT 1) ");
    sb.append(" AND ( bkw.`location` NOT LIKE 's%' AND  bkw.`location`  LIKE 'r%')  WHERE  bkp.hazmat = 0  ");
    if (null != unitssId) {
        sb.append(" and luss.id =:unitSsId ");
    } else {
        sb.append(" and bkp.file_number_id IN(:fileList) ");
    }
    if ("E".equalsIgnoreCase(serviceType)) {
        sb.append(" AND d.`elite_code` != 'INTR' ");
    } else if ("N".equalsIgnoreCase(serviceType)) {
        sb.append(" and d.`elite_code` != 'OBKG' ");
    }
    sb.append(" ) fn");
    Query queryObject = getCurrentSession().createSQLQuery(sb.toString());
    if (null != unitssId) {
        queryObject.setLong("unitSsId", unitssId);
    } else {
        queryObject.setParameterList("fileList", fileList);
    }
    return (String) queryObject.uniqueResult();
}