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.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(//w ww.  j av  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 ");
    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. ja  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();
}

From source file:com.ikon.dao.AutomationDAO.java

License:Open Source License

/**
 * Find by pk/*from   w w w . ja  v  a 2 s  . c  o  m*/
 */
public AutomationRule findByPk(long arId) throws DatabaseException {
    log.debug("findByPk({})", arId);
    String qs = "from AutomationRule ar where ar.id=:id";
    Session session = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Query q = session.createQuery(qs);
        q.setLong("id", arId);
        AutomationRule ret = (AutomationRule) q.setMaxResults(1).uniqueResult();
        initialize(ret);
        log.debug("findByPk: {}", ret);
        return ret;
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

From source file:com.ikon.dao.AutomationDAO.java

License:Open Source License

/**
 * Get metadata by pk/*from w  ww .  ja v a2 s .com*/
 */
public AutomationMetadata findMetadataByPk(long amId) throws DatabaseException {
    log.debug("findMetadataByPk({})", amId);
    String qs = "from AutomationMetadata am where am.id=:id";
    Session session = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Query q = session.createQuery(qs);
        q.setLong("id", amId);
        AutomationMetadata ret = (AutomationMetadata) q.setMaxResults(1).uniqueResult();
        log.debug("findMetadataByPk: {}", ret);
        return ret;
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

From source file:com.ikon.dao.AutomationDAO.java

License:Open Source License

/**
 * Get validation by pk//w  ww  . ja  v a 2s  .  c  o m
 */
public AutomationValidation findValidationByPk(long avId) throws DatabaseException {
    log.debug("findValidationByPk({})", avId);
    String qs = "from AutomationValidation av where av.id=:id";
    Session session = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Query q = session.createQuery(qs);
        q.setLong("id", avId);
        AutomationValidation ret = (AutomationValidation) q.setMaxResults(1).uniqueResult();
        initialize(ret);
        log.debug("findValidationByPk: {}", ret);
        return ret;
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

From source file:com.ikon.dao.AutomationDAO.java

License:Open Source License

/**
 * Get action by pk//  w w w  . j  av  a2  s.  com
 */
public AutomationAction findActionByPk(long aaId) throws DatabaseException {
    log.debug("findActionByPk({})", aaId);
    String qs = "from AutomationAction aa where aa.id=:id";
    Session session = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Query q = session.createQuery(qs);
        q.setLong("id", aaId);
        AutomationAction ret = (AutomationAction) q.setMaxResults(1).uniqueResult();
        initialize(ret);
        log.debug("findActionByPk: {}", ret);
        return ret;
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

From source file:com.ikon.dao.BookmarkDAO.java

License:Open Source License

/**
 * Find by pk/*from   www . j a  v a2s .c o m*/
 */
public static Bookmark findByPk(long bmId) throws DatabaseException, RepositoryException {
    log.debug("findByPk({})", bmId);
    String qs = "from Bookmark bm where bm.id=:id";
    Session session = null;
    Transaction tx = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        tx = session.beginTransaction();
        Query q = session.createQuery(qs);
        q.setLong("id", bmId);
        Bookmark ret = (Bookmark) q.setMaxResults(1).uniqueResult();

        if (ret != null) {
            // If user bookmark is missing, set a default
            NodeBase nBase = (NodeBase) session.get(NodeBase.class, ret.getNode());

            if (nBase == null) {
                String rootPath = "/" + Repository.ROOT;
                String rootUuid = NodeBaseDAO.getInstance().getUuidFromPath(session, rootPath);
                ret.setNode(rootUuid);
                ret.setType(Folder.TYPE);
                session.save(ret);
            }
        }

        HibernateUtil.commit(tx);
        log.debug("findByPk: {}", ret);
        return ret;
    } catch (PathNotFoundException e) {
        HibernateUtil.rollback(tx);
        throw new RepositoryException(e.getMessage(), e);
    } catch (HibernateException e) {
        HibernateUtil.rollback(tx);
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

From source file:com.ikon.dao.CronTabDAO.java

License:Open Source License

/**
 * Find by pk//from w w w  .  j a v a 2s .c om
 */
public static CronTab findByPk(long ctId) throws DatabaseException {
    log.debug("findByPk({})", ctId);
    String qs = "from CronTab ct where ct.id=:id";
    Session session = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Query q = session.createQuery(qs);
        q.setLong("id", ctId);
        CronTab ret = (CronTab) q.setMaxResults(1).uniqueResult();
        log.debug("findByPk: {}", ret);
        return ret;
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

From source file:com.ikon.dao.DatabaseMetadataDAO.java

License:Open Source License

/**
 * Find by pk// w ww  .  j  a  v  a  2s .  c  om
 */
public static DatabaseMetadataValue findValueByPk(String table, long id) throws DatabaseException {
    log.debug("findValueByPk({}, {})", table, id);
    String qs = "from DatabaseMetadataValue dmv where dmv.table=:table and dmv.id=:id";
    Session session = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Query q = session.createQuery(qs);
        q.setString("table", table);
        q.setLong("id", id);
        DatabaseMetadataValue ret = (DatabaseMetadataValue) q.setMaxResults(1).uniqueResult();
        log.debug("findValueByPk: {}", ret);
        return ret;
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

From source file:com.ikon.dao.MailAccountDAO.java

License:Open Source License

/**
 * Update password/*from  w w w  .  j  a  va2 s.  c  o  m*/
 */
public static void updatePassword(long maId, String mailPassword) throws DatabaseException {
    log.debug("updatePassword({}, {})", maId, mailPassword);
    String qs = "update MailAccount ma set ma.mailPassword=:mailPassword where ma.id=:id";
    Session session = null;
    Transaction tx = null;

    try {
        if (mailPassword != null && mailPassword.trim().length() > 0) {
            session = HibernateUtil.getSessionFactory().openSession();
            tx = session.beginTransaction();
            Query q = session.createQuery(qs);
            q.setString("mailPassword", mailPassword);
            q.setLong("id", maId);
            q.executeUpdate();
            HibernateUtil.commit(tx);
        }
    } catch (HibernateException e) {
        HibernateUtil.rollback(tx);
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }

    log.debug("updatePassword: void");
}