Example usage for org.hibernate SQLQuery setInteger

List of usage examples for org.hibernate SQLQuery setInteger

Introduction

In this page you can find the example usage for org.hibernate SQLQuery setInteger.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setInteger(int position, int val) 

Source Link

Document

Bind a positional int-valued parameter.

Usage

From source file:com.bookselling.dao.SellerInvoiceDaoImpl.java

@Override
public double countTotalProfit(User user) {
    SQLQuery sqlQuery = getSession().createSQLQuery(
            "select SUM(totalPrice) profit " + "from sellerinvoicedetail slid, sellerinvoice sli "
                    + "where slid.sellerInvoiceId = sli.id and " + "      sli.seller_id = :id ");
    Double figure = (Double) sqlQuery.setInteger("id", user.getId()).uniqueResult();
    return figure == null ? 0 : figure.doubleValue();
}

From source file:com.bookselling.dao.SellerInvoiceDaoImpl.java

@Override
public int countSoldItem(User user) {
    SQLQuery sqlQuery = getSession()
            .createSQLQuery("select SUM(quatity) " + "from sellerinvoicedetail slid, sellerinvoice sli "
                    + "where slid.sellerInvoiceId = sli.id and " + "      sli.seller_id = :id ");
    BigDecimal figure = (BigDecimal) sqlQuery.setInteger("id", user.getId()).uniqueResult();
    return figure != null ? figure.intValue() : 0;
}

From source file:com.bookselling.dao.SellingPostDaoImpl.java

@Override
public int countStoredItem(User user) {
    SQLQuery sqlQuery = getSession()
            .createSQLQuery("select SUM(quatity) " + "from storeablegood gd, sellingpost slp "
                    + "where gd.id = slp.sellingEntityId and " + "      slp.userId = :id ");
    BigDecimal figure = (BigDecimal) sqlQuery.setInteger("id", user.getId()).uniqueResult();
    return figure != null ? figure.intValue() : 0;
}

From source file:com.bookselling.dao.SellingPostDaoImpl.java

@Override
public Set<SellingPost> bestSellingItem(User user) {
    SQLQuery sqlQuery = getSession().createSQLQuery("select slid.soldEntityId itemId, MAX(quatity) iquatity "
            + "from sellerinvoice sli, sellerinvoicedetail slid " + "where sli.id = slid.sellerInvoiceId and "
            + "      sli.seller_id = :id " + "group by itemId " + "having iquatity > 0 "
            + "order by iquatity asc " + "limit 5 ");
    Set<Object[]> queryResult = new HashSet<>(sqlQuery.setInteger("id", user.getId()).list());
    Set<Integer> ids = new HashSet<>();
    for (Object[] row : queryResult) {
        ids.add((int) row[0]);
        System.out.println((int) row[0]);
    }/*from ww w. j a v a  2  s.c  o m*/

    Criteria criteria = getSession().createCriteria(SellingPost.class);
    if (ids.size() != 0)
        criteria.add(Restrictions.in("id", ids));
    else
        return new HashSet<>();

    Set<SellingPost> data = new HashSet<SellingPost>(criteria.list());
    HibernateInitSupport.setCls(SellingPost.class);
    for (SellingPost post : data)
        HibernateInitSupport.initDomain(post);

    return data;
}

From source file:com.bookselling.dao.UserDaoImpl.java

@Override
public void ratingUser(Serializable id) {
    SQLQuery sqlQuery = getSession().createSQLQuery(
            "update account as acc_1 " + "       inner join ( " + "           select acc.id as accId, "
                    + "           avg(rt.point) as avgpoint, " + "           count(slp.id) as numslp, "
                    + "           case " + "               when avg(rt.point) > 3.0 then 'GOOD' "
                    + "               when avg(rt.point) < 1.5 then 'BAD' " + "               else 'NATURAL' "
                    + "           end as userRating " + "           from account as acc "
                    + "               join `user` as u on u.accountId = acc.id "
                    + "               join sellingpost as slp on slp.userId = u.id "
                    + "               join rating as rt on rt.sellingPostId = slp.id "
                    + "           where acc.id = :id " + "           group by acc.id "
                    + "           having numslp >= :minPost " + "       ) as temp on acc_1.id = temp.accId "
                    + "set acc_1.rating = userRating");
    sqlQuery.setInteger("id", (int) id).setInteger("minPost", minPost).executeUpdate();
}

From source file:com.duroty.application.files.manager.FilesManager.java

License:Open Source License

/**
 * DOCUMENT ME!/*from w  w w .j a v  a  2s. c  o m*/
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 * @param folderName DOCUMENT ME!
 * @param page DOCUMENT ME!
 * @param messagesByPage DOCUMENT ME!
 * @param order DOCUMENT ME!
 * @param orderType DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws FilesException DOCUMENT ME!
 */
public Vector getFiles(Session hsession, String repositoryName, String folderName, int label, int page,
        int messagesByPage, int order, String orderType) throws FilesException {
    Vector files = new Vector();

    try {
        Users user = getUser(hsession, repositoryName);
        Locale locale = new Locale(user.getUseLanguage());
        TimeZone timeZone = TimeZone.getDefault();

        Date now = new Date();
        Calendar calendar = Calendar.getInstance(timeZone, locale);
        calendar.setTime(now);

        SimpleDateFormat formatter1 = new SimpleDateFormat("MMM dd", locale);
        SimpleDateFormat formatter2 = new SimpleDateFormat("HH:mm:ss", locale);
        SimpleDateFormat formatter3 = new SimpleDateFormat("MM/yy", locale);

        Query hquery = null;

        String[] folderNameList = new String[0];

        try {
            folderName = parseFolder(folderName);

            folderNameList = new String[] { folderName };

            if (folderName.equals(this.folderAll) || folderName.equals(this.folderHidden)) {
                folderNameList = new String[] { this.folderAll, this.folderDraft, this.folderHidden,
                        this.folderImportant, this.folderInbox, this.folderSent };
            }
        } catch (Exception ex) {
        }

        if ((folderNameList.length == 0) && (label <= 0)) {
            hquery = hsession.getNamedQuery("attachments");
        } else if ((folderNameList.length > 0) && (label <= 0)) {
            hquery = hsession.getNamedQuery("attachments-by-folder");
        } else if ((folderNameList.length == 0) && (label > 0)) {
            hquery = hsession.getNamedQuery("attachments-by-label");
        } else if ((folderNameList.length > 0) && (label > 0)) {
            hquery = hsession.getNamedQuery("attachments-by-folder-label");
        }

        String aux = hquery.getQueryString();

        switch (order) {
        case ORDER_BY_SIZE:

            if (orderType.equals("ASC")) {
                aux += " order by att_size asc";
            } else {
                aux += " order by att_size desc";
            }

            break;

        case ORDER_BY_DATE:

            if (orderType.equals("ASC")) {
                aux += " order by mes_date asc";
            } else {
                aux += " order by mes_date desc";
            }

            break;

        case ORDER_BY_TYPE:

            if (orderType.equals("ASC")) {
                aux += " order by att_content_type asc";
            } else {
                aux += " order by att_content_type desc";
            }

            break;

        default:

            if (!orderType.equals("ASC")) {
                aux += " order by att_name desc";
            } else {
                aux += " order by att_name asc";
            }

            break;
        }

        SQLQuery h2query = hsession.createSQLQuery(aux);

        if ((folderNameList.length == 0) && (label <= 0)) {
            h2query.setParameterList("no_boxes",
                    new String[] { this.folderTrash, this.folderChat, this.folderSpam, FOLDER_DELETE });
            h2query.setInteger("user", getUser(hsession, repositoryName).getUseIdint());
        } else if ((folderNameList.length > 0) && (label <= 0)) {
            h2query.setParameterList("boxes", folderNameList);
            h2query.setInteger("user", getUser(hsession, repositoryName).getUseIdint());
        } else if ((folderNameList.length == 0) && (label > 0)) {
            h2query.setInteger("label", label);
            h2query.setParameterList("no_boxes",
                    new String[] { this.folderTrash, this.folderChat, this.folderSpam, FOLDER_DELETE });
            h2query.setInteger("user", getUser(hsession, repositoryName).getUseIdint());
        } else if ((folderNameList.length > 0) && (label > 0)) {
            h2query.setInteger("label", label);
            h2query.setParameterList("boxes", folderNameList);
            h2query.setInteger("user", getUser(hsession, repositoryName).getUseIdint());
        }

        h2query.setFirstResult(page * messagesByPage);
        h2query.setMaxResults(messagesByPage);

        h2query.addEntity("testo", AttachmentWithDate.class);

        ScrollableResults scroll = h2query.scroll();

        while (scroll.next()) {
            AttachmentWithDate attachment = (AttachmentWithDate) scroll.get(0);

            AttachmentObj obj = new AttachmentObj();
            obj.setContentType(attachment.getAttContentType());

            Date date = attachment.getAttDate();

            if (date != null) {
                Calendar calendar2 = Calendar.getInstance(timeZone, locale);
                calendar2.setTime(date);

                if ((calendar.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR))
                        && (calendar.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH))
                        && (calendar.get(Calendar.DATE) == calendar2.get(Calendar.DATE))) {
                    obj.setDateStr(formatter2.format(calendar2.getTime()));
                } else if (calendar.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR)) {
                    obj.setDateStr(formatter1.format(calendar2.getTime()));
                } else {
                    obj.setDateStr(formatter3.format(calendar2.getTime()));
                }
            }

            obj.setDate(date);

            obj.setDate(date);
            obj.setIdint(attachment.getAttIdint());
            obj.setName(attachment.getAttName());
            obj.setPart(attachment.getAttPart());

            int size = attachment.getAttSize();
            size /= 1024;

            if (size > 1024) {
                size /= 1024;
                obj.setSize(size + " MB");
            } else {
                obj.setSize(((size > 0) ? (size + "") : "<1") + " kB");
            }

            String extension = (String) this.extensions.get(attachment.getAttContentType());

            if (StringUtils.isBlank(extension)) {
                extension = "generic";
            }

            obj.setExtension(extension);

            Message message = attachment.getMessage();

            if (message.isMesFlagged()) {
                obj.setFlagged(true);
            } else {
                obj.setFlagged(false);
            }

            if (message.getLabMeses() != null) {
                Iterator it = message.getLabMeses().iterator();
                StringBuffer lab = new StringBuffer();

                while (it.hasNext()) {
                    if (lab.length() > 0) {
                        lab.append(", ");
                    }

                    LabMes labMes = (LabMes) it.next();
                    lab.append(labMes.getId().getLabel().getLabName());
                }

                if (lab.length() > 0) {
                    obj.setLabel(lab.toString());
                } else {
                }
            }

            obj.setBox(message.getMesBox());

            obj.setMid(message.getMesName());

            files.addElement(obj);
        }

        return files;
    } catch (Exception e) {
        throw new FilesException(e);
    } finally {
        GeneralOperations.closeHibernateSession(hsession);
    }
}

From source file:com.duroty.application.mail.manager.MailManager.java

License:Open Source License

/**
 * DOCUMENT ME!/*from w  w  w  . j  av  a2s  .  com*/
 *
 * @param hsession DOCUMENT ME!
 * @param repositoryName DOCUMENT ME!
 * @param label DOCUMENT ME!
 * @param page DOCUMENT ME!
 * @param messagesByPage DOCUMENT ME!
 * @param order DOCUMENT ME!
 * @param orderType DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws MailException DOCUMENT ME!
 */
public Vector getMessages(Session hsession, String repositoryName, Label label, int page, int messagesByPage,
        int order, String orderType) throws MailException {
    Vector messages = new Vector();

    try {
        Users user = getUser(hsession, repositoryName);
        Locale locale = new Locale(user.getUseLanguage());
        TimeZone timeZone = TimeZone.getDefault();

        Date now = new Date();
        Calendar calendar = Calendar.getInstance(timeZone, locale);
        calendar.setTime(now);

        SimpleDateFormat formatter1 = new SimpleDateFormat("MMM dd", locale);
        SimpleDateFormat formatter2 = new SimpleDateFormat("HH:mm:ss", locale);
        SimpleDateFormat formatter3 = new SimpleDateFormat("MM/yy", locale);

        Query hquery = hsession.getNamedQuery("messages-by-label");
        String aux = hquery.getQueryString();

        switch (order) {
        case ORDER_BY_IMPORTANT:

            if (orderType.equals("ASC")) {
                aux += " order by mes_flagged asc";
            } else {
                aux += " order by mes_flagged desc";
            }

            break;

        case ORDER_BY_ADDRESS:

            if (orderType.equals("ASC")) {
                aux += " order by mes_from asc";
            } else {
                aux += " order by mes_from desc";
            }

            break;

        case ORDER_BY_SIZE:

            if (orderType.equals("ASC")) {
                aux += " order by mes_size asc";
            } else {
                aux += " order by mes_size desc";
            }

            break;

        case ORDER_BY_SUBJECT:

            if (orderType.equals("ASC")) {
                aux += " order by mes_subject asc";
            } else {
                aux += " order by mes_subject desc";
            }

            break;

        case ORDER_BY_DATE:

            if (orderType.equals("ASC")) {
                aux += " order by mes_date asc";
            } else {
                aux += " order by mes_date desc";
            }

            break;

        case ORDER_BY_UNREAD:

            if (orderType.equals("ASC")) {
                aux += " order by mes_recent asc";
            } else {
                aux += " order by mes_recent desc";
            }

            break;

        default:
            aux += " order by mes_date desc";

            break;
        }

        SQLQuery h2query = hsession.createSQLQuery(aux);
        h2query.addEntity("i", Message.class);
        h2query.setInteger("label", label.getLabIdint());
        h2query.setInteger("user", user.getUseIdint());
        h2query.setString("folderTrash", this.folderTrash);
        h2query.setString("folderSpam", this.folderSpam);
        h2query.setString("folderDelete", FOLDER_DELETE);
        h2query.setFirstResult(page * messagesByPage);
        h2query.setMaxResults(messagesByPage);

        ScrollableResults scroll = h2query.scroll();

        while (scroll.next()) {
            Message message = (Message) scroll.get(0);

            MessageObj obj = new MessageObj(message.getMesName());

            obj.setBox(message.getMesBox());

            obj.setFrom(message.getMesFrom());

            if ((message.getAttachments() != null) && (message.getAttachments().size() > 0)) {
                obj.setHasAttachment(true);
            } else {
                obj.setHasAttachment(false);
            }

            int size = message.getMesSize();
            size /= 1024;

            if (size > 1024) {
                size /= 1024;
                obj.setSize(size + " MB");
            } else {
                obj.setSize(((size > 0) ? (size + "") : "<1") + " kB");
            }

            if (message.getMesBox().equals(folderSent)) {
                try {
                    obj.setEmail(message.getMesTo());
                } catch (Exception e) {
                    obj.setEmail("unknown to");
                }
            } else {
                obj.setEmail(message.getMesFrom());
            }

            Date date = message.getMesDate();

            if (date != null) {
                Calendar calendar2 = Calendar.getInstance(timeZone, locale);
                calendar2.setTime(date);

                if ((calendar.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR))
                        && (calendar.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH))
                        && (calendar.get(Calendar.DATE) == calendar2.get(Calendar.DATE))) {
                    obj.setDateStr(formatter2.format(calendar2.getTime()));
                } else if (calendar.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR)) {
                    obj.setDateStr(formatter1.format(calendar2.getTime()));
                } else {
                    obj.setDateStr(formatter3.format(calendar2.getTime()));
                }
            }

            obj.setDate(date);

            if (message.getLabMeses() != null) {
                Iterator it = message.getLabMeses().iterator();
                StringBuffer buff = new StringBuffer();

                while (it.hasNext()) {
                    if (buff.length() > 0) {
                        buff.append(", ");
                    }

                    LabMes labMes = (LabMes) it.next();
                    buff.append(labMes.getId().getLabel().getLabName());
                }

                obj.setLabel(buff.toString());
            }

            try {
                if (StringUtils.isBlank(message.getMesSubject())) {
                    obj.setSubject("(no subject)");
                } else {
                    obj.setSubject(message.getMesSubject());
                }
            } catch (Exception ex) {
                obj.setSubject("(no subject)");
            }

            if (message.isMesFlagged()) {
                obj.setFlagged(true);
            } else {
                obj.setFlagged(false);
            }

            if (message.isMesRecent()) {
                obj.setRecent(true);
            } else {
                obj.setRecent(false);
            }

            String priority = "normal";

            if (MessageUtilities.isHighPriority(message.getMesHeaders())) {
                priority = "high";
            } else if (MessageUtilities.isLowPriority(message.getMesHeaders())) {
                priority = "low";
            }

            obj.setPriority(priority);

            messages.addElement(obj);
        }

        return messages;
    } catch (Exception e) {
        throw new MailException(e);
    } finally {
        GeneralOperations.closeHibernateSession(hsession);
    }
}

From source file:com.exilant.eGov.src.domain.BankReconciliationSummary.java

License:Open Source License

public String getUnReconciledDrCr(Integer bankAccId, Date fromDate, Date toDate) throws Exception {

    String instrumentsForTotal = "case when iv.voucherHeaderId is null then 0 else ih.instrumentAmount end)";
    String instrumentsForBrsEntryTotal = "(case when br.voucherHeaderId is null then ih.instrumentAmount else 0 end)";

    String totalQuery = "SELECT (sum(case when ih.ispaycheque='1' then ih.instrumentAmount else 0 end))  AS \"brs_creditTotal\", "
            + " (sum( case when ih.ispaycheque= '0' then ih.instrumentAmount else 0 end) ) AS \"brs_debitTotal\" "
            + " FROM egf_instrumentheader ih    WHERE   ih.bankAccountId =:bankAccountId "
            + " AND IH.INSTRUMENTDATE >= :fromDate" + " AND IH.INSTRUMENTDATE <= :toDate"
            + " AND  ( (ih.ispaycheque='0' and  ih.id_status=(select id from egw_status where moduletype='Instrument'  and description='Deposited'))or (ih.ispaycheque='1' and  ih.id_status=(select id from egw_status where moduletype='Instrument'  and description='New'))) "
            + " and ih.instrumentnumber is not null";
    //see u might need to exclude brs entries here 

    String otherTotalQuery = " SELECT (sum(case when ih.ispaycheque='1' then ih.instrumentAmount else 0 end ))  AS \"brs_creditTotalOthers\", "
            + " (sum(case when ih.ispaycheque='0' then ih.instrumentAmount else 0 end ) ) AS \"brs_debitTotalOthers\" "
            + " FROM  egf_instrumentheader ih   WHERE   ih.bankAccountId =:bankAccountId"
            + " AND IH.transactiondate >= :fromDate" + " AND IH.transactiondate <= :toDate  "
            + " AND ( (ih.ispaycheque='0' and ih.id_status=(select id from egw_status where moduletype='Instrument'  and description='Deposited'))or (ih.ispaycheque='1' and  ih.id_status=(select id from egw_status where moduletype='Instrument'  and description='New'))) "
            + " AND ih.transactionnumber is not null";

    String brsEntryQuery = "select (sum(case when be.type='Receipt' then (case when be.voucherheaderid is null then be.txnamount else 0 end) else 0 end))AS \"brs_creditTotalBrsEntry\","
            + "(sum(case when be.type='Payment' then (case when be.voucherheaderid is null then be.txnamount else 0 end) else 0 end))AS \"brs_debitTotalBrsEntry\""
            + "FROM  bankentries be WHERE   be.bankAccountId = :bankAccountId and be.voucherheaderid is null AND be.txndate >=:fromDate   AND be.txndate <= :toDate";

    if (LOGGER.isInfoEnabled())
        LOGGER.info("  query  for  total : " + totalQuery);
    if (LOGGER.isInfoEnabled())
        LOGGER.info("  query  for other than cheque/DD: " + otherTotalQuery);
    if (LOGGER.isInfoEnabled())
        LOGGER.info("  query  for bankEntries: " + brsEntryQuery);

    String unReconciledDrCr = "";

    String creditTotal = null;/*from   w w  w  .jav a2s  .c  o  m*/
    String creditOthertotal = null;
    String debitTotal = null;
    String debitOtherTotal = null;
    String creditTotalBrsEntry = null;
    String debitTotalBrsEntry = null;

    try {
        SQLQuery totalSQLQuery = persistenceService.getSession().createSQLQuery(totalQuery);
        totalSQLQuery.setInteger("bankAccountId", bankAccId);
        totalSQLQuery.setDate("fromDate", fromDate);
        totalSQLQuery.setDate("toDate", toDate);

        List list = totalSQLQuery.list();
        if (list.size() > 0) {
            if (LOGGER.isDebugEnabled())
                LOGGER.debug(list.get(0));
            Object[] my = (Object[]) list.get(0);
            creditTotal = my[0] != null ? my[0].toString() : null;
            debitTotal = my[1] != null ? my[1].toString() : null;
        }

        totalSQLQuery = persistenceService.getSession().createSQLQuery(otherTotalQuery);
        totalSQLQuery.setInteger("bankAccountId", bankAccId);
        totalSQLQuery.setDate("fromDate", fromDate);
        totalSQLQuery.setDate("toDate", toDate);
        list = totalSQLQuery.list();
        if (list.size() > 0) {
            if (LOGGER.isDebugEnabled())
                LOGGER.debug(list.get(0));
            Object[] my = (Object[]) list.get(0);
            creditOthertotal = my[0] != null ? my[0].toString() : null;
            debitOtherTotal = my[1] != null ? my[1].toString() : null;
        }

        totalSQLQuery = persistenceService.getSession().createSQLQuery(brsEntryQuery);
        totalSQLQuery.setInteger("bankAccountId", bankAccId);
        totalSQLQuery.setDate("fromDate", fromDate);
        totalSQLQuery.setDate("toDate", toDate);
        list = totalSQLQuery.list();
        if (list.size() > 0) {
            if (LOGGER.isDebugEnabled())
                LOGGER.debug(list.get(0));
            Object[] my = (Object[]) list.get(0);
            creditTotalBrsEntry = my[0] != null ? my[0].toString() : null;
            debitTotalBrsEntry = my[1] != null ? my[1].toString() : null;
        }

        unReconciledDrCr = (creditTotal != null ? creditTotal : "0") + "/"
                + (creditOthertotal != null ? creditOthertotal : "0") + "/"
                + (debitTotal != null ? debitTotal : "0") + "/"
                + (debitOtherTotal != null ? debitOtherTotal : "0") + "" + "/"
                + (creditTotalBrsEntry != null ? creditTotalBrsEntry : "0") + "/"
                + (debitTotalBrsEntry != null ? debitTotalBrsEntry : "0") + "";
    } catch (Exception e) {
        LOGGER.error("Exp in getUnReconciledDrCr" + e.getMessage());
        throw e;
    }
    return unReconciledDrCr;
}

From source file:com.g3.framework.orm.SimpleHibernateDao.java

License:Apache License

public SQLQuery createSQLQuery(String sql, Map<String, Object> parameters) {
    sql = sql.toUpperCase();//w  w  w.  j  a  va2  s.  c  o m
    Assert.hasText(sql, "queryString?");
    SQLQuery query = getSession().createSQLQuery(sql);
    if (parameters != null) {
        for (String key : parameters.keySet()) {
            Object value = parameters.get(key);
            //System.out.println(key + "<::>" + value);
            if (value instanceof Collection) {
                query.setParameterList(key.toUpperCase(), (Collection) value);
            } else if (value instanceof Integer) {
                query.setInteger(key.toUpperCase(), ((Integer) value).intValue());
            } else {
                query.setParameter(key.toUpperCase(), value);
            }
        }
    }
    return query;
}

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

public List<ExportVoyageSearchModel> searchByUnCompleteUnit(Integer pooId, Integer fdId, String serviceType)
        throws Exception {
    StringBuilder queryStr = new StringBuilder();
    queryStr.append(this.selectvoyageSearchQuery());
    queryStr.append("   FROM ");
    queryStr.append(" lcl_ss_header lsh ");
    queryStr.append(" JOIN un_location pod ON lsh.destination_id=pod.id ");
    queryStr.append(" JOIN lcl_ss_detail lsd ");
    queryStr.append(" ON (lsh.id = lsd.ss_header_id ");
    queryStr.append(" AND lsh.status <> 'V' ");
    queryStr.append(" AND lsd.`id` = (SELECT ls.id FROM ");
    queryStr.append(" lcl_ss_detail ls ");
    queryStr.append("  WHERE ls.`ss_header_id` = lsh.id ");
    queryStr.append(" ORDER BY id DESC LIMIT 1)) ");
    queryStr.append("  JOIN lcl_unit_ss lus ");
    queryStr.append(" ON (lus.ss_header_id = lsh.id ) ");
    queryStr.append(/*from   w w  w. j  av a 2s  . c o  m*/
            "  JOIN lcl_unit lu ON (lu.id=lus.unit_id) JOIN unit_type ut ON (ut.id = lu.unit_type_id) ");
    queryStr.append(" WHERE lsh.service_type=:serviceType and  lus.status = 'E'  ");
    if (CommonUtils.isNotEmpty(pooId)) {
        queryStr.append(" AND lsh.origin_id =:pooId ");
    }
    if (CommonUtils.isNotEmpty(fdId)) {
        queryStr.append(" AND lsh.destination_id =:fdId ");
    }
    queryStr.append(" ORDER BY pod.un_loc_code ,lsh.schedule_no ASC ");
    SQLQuery query = getCurrentSession().createSQLQuery(queryStr.toString());
    if (CommonUtils.isNotEmpty(pooId)) {
        query.setInteger("pooId", pooId);
    }
    if (CommonUtils.isNotEmpty(fdId)) {
        query.setInteger("fdId", fdId);
    }
    query.setString("serviceType", serviceType);
    query.setResultTransformer(Transformers.aliasToBean(ExportVoyageSearchModel.class));
    query.addScalar("ssHeaderId", StringType.INSTANCE);
    query.addScalar("scheduleNo", StringType.INSTANCE);
    query.addScalar("serviceType", StringType.INSTANCE);
    query.addScalar("serviceType", StringType.INSTANCE);
    query.addScalar("fdUnLocCode", StringType.INSTANCE);
    query.addScalar("fdName", StringType.INSTANCE);
    query.addScalar("departPierUnloc", StringType.INSTANCE);
    query.addScalar("departPier", StringType.INSTANCE);
    query.addScalar("arrivalPierUnloc", StringType.INSTANCE);
    query.addScalar("arrivalPier", StringType.INSTANCE);
    query.addScalar("loadingDeadLineDate", StringType.INSTANCE);
    query.addScalar("etaSailDate", StringType.INSTANCE);
    query.addScalar("etaPodDate", StringType.INSTANCE);
    query.addScalar("totaltransPod", StringType.INSTANCE);
    query.addScalar("totaltransFd", StringType.INSTANCE);
    query.addScalar("vesselName", StringType.INSTANCE);
    query.addScalar("ssVoyage", StringType.INSTANCE);
    query.addScalar("carrierName", StringType.INSTANCE);
    query.addScalar("carrierAcctNo", StringType.INSTANCE);
    query.addScalar("sealNo", StringType.INSTANCE);
    query.addScalar("unitNo", StringType.INSTANCE);
    query.addScalar("unitSize", StringType.INSTANCE);
    query.addScalar("numberDrs", StringType.INSTANCE);
    query.addScalar("loadedBy", StringType.INSTANCE);
    query.addScalar("doorLocation", StringType.INSTANCE);
    query.addScalar("dispoCode", StringType.INSTANCE);
    query.addScalar("dispoDesc", StringType.INSTANCE);
    query.addScalar("isInbond", StringType.INSTANCE);
    query.addScalar("dispoDesc", StringType.INSTANCE);
    query.addScalar("isHazmat", StringType.INSTANCE);
    return query.list();
}