Example usage for org.hibernate SQLQuery setLong

List of usage examples for org.hibernate SQLQuery setLong

Introduction

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

Prototype

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

Source Link

Document

Bind a positional long-valued parameter.

Usage

From source file:com.globalsight.everest.workflow.WorkflowJbpmPersistenceHandler.java

License:Apache License

/**
 * Fix for GBS-1470//w  ww  .  j av a  2 s.co  m
  * Judges whether the user is rejected for (This user Rejected the task first, then reassign to this user) 
  * 
  * @param ctx
  *            {@code JbpmContext}
  * @param userId
  *            the user id.
  * @param taskInstance
  *            {@code TaskInstance}
  * @return <code>true</code> The user reject, and not been reassigned.
  */
public static boolean isUserRejectedForReassign(JbpmContext ctx, String userId, TaskInstance taskInstance) {

    SQLQuery query = null;
    Session session = ctx.getSession();

    query = session.createSQLQuery(SqlHolder.isUserRejectForReassign);

    query.setString(VARIABLE_NAME, WorkflowConstants.VARIABLE_IS_REJECTED);
    query.setString(CATEGORY, VARIABLE_CATEGORY_REJECT);
    query.setString(ACTOR_ID, userId);
    query.setLong(TASK_ID, taskInstance.getId());
    long id = taskInstance.getId();
    Number num = (Number) query.uniqueResult();

    return num == null ? false : num.longValue() > 0;

}

From source file:com.globalsight.everest.workflow.WorkflowJbpmPersistenceHandler.java

License:Apache License

/**
  * Judges whether the task is rejected<br>
  * The rule for judges the task whether is rejected is as below:
  * <ul>//from   ww w.j  ava  2 s  .c  o  m
  * <li>If the lp reject the task, the task showed rejected by the lp</li>
  * <li>If the lp(s) reject the task and there is extra lp availabe for the
  * task, the task showed rejected for pm</li> *
  * <li>If the lp(s) reject the task and there is no extra lp availabe for
  * the task, the task showed availabe for pm</li>
  * </ul>
  * 
  * 
  * @param ctx
  *            {@code JbpmContext}
  * @param taskInstance
  *            {@code TaskInstance}
  * @param p_pm
  *            The name of the pm
  * @return <code>true</code> when the task is rejected
  */
public static boolean isTaskRejected(JbpmContext ctx, TaskInstance taskInstance, String p_pm) {

    SQLQuery query = null;
    Session session = ctx.getSession();

    query = session.createSQLQuery(SqlHolder.isTaskReject);

    query.setString(VARIABLE_NAME, WorkflowConstants.VARIABLE_IS_REJECTED);
    query.setString(CATEGORY, VARIABLE_CATEGORY_REJECT);
    query.setString(PM, p_pm);
    query.setLong(TASK_ID, taskInstance.getId());

    Number num = (Number) query.uniqueResult();

    /* normally, the num should not be null */
    return num == null ? false : num.longValue() > 0;

}

From source file:com.globalsight.everest.workflow.WorkflowJbpmPersistenceHandler.java

License:Apache License

/**
  * Gets the task instances with specified task node id.
  * /* w w w  . j  a v  a2 s .co m*/
  * @param p_taskId -
  *            The task node id.
  * @param p_ctx
  *            the JbpmContext.
  * 
  * @return a list of the task instances.
  */
public static List getTaskInstancesById(long p_taskId, JbpmContext p_ctx) {
    Session session = p_ctx.getSession();
    SQLQuery query = session.createSQLQuery(TASK_INSTANCE_BY_ID);
    query.addEntity(TaskInstance.class);
    query.setLong(TASK_ID, p_taskId);
    List result = query.list();
    return result;
}

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

public void updateUnitSsAssociatedwithMasterBl(Long headerId, String currrentspBookingNo,
        String previousspBookingNo) throws Exception {
    SQLQuery query = getCurrentSession().createSQLQuery(
            "UPDATE  lcl_unit_ss lus SET lus.sp_booking_no =:currrentspBookingNo WHERE lus.ss_header_id =:headerId  AND  "
                    + "lus.`sp_booking_no` =:previousspBookingNo");
    query.setLong("headerId", headerId);
    query.setParameter("currrentspBookingNo", currrentspBookingNo.toUpperCase());
    query.setParameter("previousspBookingNo", previousspBookingNo);
    query.executeUpdate();/*ww  w . j a va  2s .c  o  m*/
}

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

public List<ManifestBean> getPickedDrList(Long unitSSId) throws Exception {
    StringBuilder queryStr = new StringBuilder();
    queryStr.append(//from w  w w  .j  a v a  2  s.  c o m
            " SELECT DISTINCT fn.fileId as fileId,fn.fileNo as fileNo,fn.blNumber AS blNo,fn.bkgPieceId AS bkgPieceId  FROM  ");
    queryStr.append(" (SELECT DISTINCT bkp.file_number_id AS fileId,lfn.file_number AS fileNo,  ");
    queryStr.append(" CONCAT_WS('-',(SELECT IF(t.unlocationcode1 <> '',RIGHT(t.unlocationcode1,3),t.trmnum)  ");
    queryStr.append(" AS terminal FROM terminal t WHERE t.trmnum=lb.billing_terminal),  ");
    queryStr.append(
            " IF(dest.bl_numbering = 'Y',RIGHT(dest.un_loc_code, 3),dest.un_loc_code),lfn.file_number) AS blNumber,bkp.id as bkgPieceId   ");
    queryStr.append(
            "  FROM lcl_booking_piece bkp JOIN  lcl_booking_piece_unit bpu ON  bpu.booking_piece_id = bkp.id ");
    queryStr.append(
            " JOIN lcl_file_number lfn ON lfn.id=bkp.file_number_id  JOIN lcl_booking lb ON lb.file_number_id=lfn.id  ");
    queryStr.append(" JOIN un_location dest ON dest.id=lb.fd_id ");
    queryStr.append(
            " JOIN lcl_unit_ss luss ON luss.id = bpu.lcl_unit_ss_id WHERE luss.id =:unitSSId GROUP BY bkp.file_number_id) fn ");
    SQLQuery query = getCurrentSession().createSQLQuery(queryStr.toString());
    query.setLong("unitSSId", unitSSId);
    query.setResultTransformer(Transformers.aliasToBean(ManifestBean.class));
    query.addScalar("fileId", LongType.INSTANCE);
    query.addScalar("fileNo", StringType.INSTANCE);
    query.addScalar("blNo", StringType.INSTANCE);
    query.addScalar("bkgPieceId", LongType.INSTANCE);
    return query.list();
}

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

public boolean validateCollectCharges(String headerId, String unitssId, String fileId) throws Exception {
    SQLQuery query = null;
    if (!fileId.isEmpty()) {
        query = getCurrentSession().createSQLQuery("select if( count(*)>0 ,true ,false) as result from "
                + " lcl_bl_ac ac where ac.file_number_id =:fileId and ac.ar_bill_to_party='A'");
        query.setLong("fileId", Long.parseLong(fileId));
    } else {// w ww . j  a  v  a  2  s  .c  o m
        List<Long> actualDrList = new ExportUnitQueryUtils().getAllPickedCargoBkg(Long.parseLong(headerId),
                Long.parseLong(unitssId));
        query = getCurrentSession().createSQLQuery("select if( count(*)>0 ,true ,false) as result from "
                + " lcl_bl_ac ac where ac.file_number_id in(:fileList) and ac.ar_bill_to_party='A'");
        query.setParameterList("fileList", actualDrList);
    }
    return (boolean) query.addScalar("result", BooleanType.INSTANCE).uniqueResult();
}

From source file:com.ibm.ioes.utilities.AjaxHelper.java

public ArrayList getUsersOfRole(String roleId) throws Exception {
    ArrayList employeeList = new ArrayList();
    Session hibernateSession = null;//from w  w  w .  j  av  a2s .  co  m

    try {
        hibernateSession = com.ibm.ioes.npd.hibernate.dao.CommonBaseDao.beginTrans();
        String sql = "SELECT   TM_EMPLOYEE.NPDEMPID,TM_EMPLOYEE.EMPNAME FROM   NPD.TM_ROLEEMPMAPPING TM_ROLEEMPMAPPING "
                + "INNER JOIN NPD.TM_ROLES TM_ROLES ON TM_ROLEEMPMAPPING.ROLEID = TM_ROLES.ROLEID"
                + "   INNER JOIN NPD.TM_EMPLOYEE TM_EMPLOYEE "
                + "ON TM_ROLEEMPMAPPING.NPDEMPID = TM_EMPLOYEE.NPDEMPID WHERE TM_ROLES.ROLEID=:roleId";
        SQLQuery query = hibernateSession.createSQLQuery(sql);

        query.setLong("roleId", Long.valueOf(roleId));

        query.addScalar("npdempid", Hibernate.LONG).addScalar("empname", Hibernate.STRING)
                .setResultTransformer(Transformers.aliasToBean(TmEmployee.class));

        employeeList = (ArrayList) query.list();

    } catch (Exception ex) {
        ex.printStackTrace();
        String msg = ex.getMessage() + " Exception occured in getUsersOfRole method of "
                + this.getClass().getSimpleName() + AppUtility.getStackTrace(ex);
        AppConstants.NPDLOGGER.error(msg);
        throw new NpdException(msg);
    } finally {
        hibernateSession.close();
    }
    return employeeList;
}

From source file:com.nextep.datadesigner.vcs.services.VersionHelper.java

License:Open Source License

/**
 * Executes the specified revision-check query for the given element id. The return boolean
 * indicates whether the revision number fetched from the database through the given query
 * matches the expected revision number.
 * // www  . j a va  2 s.  co m
 * @param query SQL query which can retrieve the revision number from its ID
 * @param id unique ID of element to check the revision
 * @param expectedRevision expected revision number
 * @return <code>true</code> if the expected revision number matches the repository revision
 *         number, else <code>false</code>
 */
private static boolean queryIsUpToDate(String query, long id, long expectedRevision) {
    final Session session = HibernateUtil.getInstance().getSandBoxSession();
    session.flush();
    session.clear();
    SQLQuery sqlQuery = session.createSQLQuery(query);
    sqlQuery.setLong(0, id);
    Number revision = (Number) sqlQuery.uniqueResult();
    return revision == null || (revision != null && revision.longValue() == expectedRevision);
}

From source file:com.thoughtworks.go.server.persistence.MaterialRepository.java

License:Apache License

private long modificationAfter(final long id, final MaterialInstance materialInstance) {
    BigInteger result = (BigInteger) getHibernateTemplate().execute((HibernateCallback) session -> {
        String sql = "SELECT id " + " FROM modifications " + " WHERE materialId = ? " + "        AND id > ?"
                + " ORDER BY id" + " LIMIT 1";
        SQLQuery query = session.createSQLQuery(sql);
        query.setLong(0, materialInstance.getId());
        query.setLong(1, id);//from   ww w. j av  a 2 s  .  c  o m
        return query.uniqueResult();
    });
    return result == null ? id : result.longValue();
}

From source file:com.thoughtworks.go.server.persistence.MaterialRepository.java

License:Apache License

private Long findLastBuiltModificationId(final Pipeline pipeline, final MaterialInstance materialInstance) {
    BigInteger result = (BigInteger) getHibernateTemplate().execute((HibernateCallback) session -> {
        String sql = "SELECT fromRevisionId " + " FROM pipelineMaterialRevisions pmr "
                + "     INNER JOIN pipelines p on p.id = pmr.pipelineId " + " WHERE materialId = ? "
                + "     AND p.name = ? " + "     AND pipelineId < ? " + " ORDER BY pmr.id DESC" + " LIMIT 1";
        SQLQuery query = session.createSQLQuery(sql);
        query.setLong(0, materialInstance.getId());
        query.setString(1, pipeline.getName());
        query.setLong(2, pipeline.getId());
        return query.uniqueResult();
    });/*from   ww  w  . j a v  a 2s.  co m*/
    return result == null ? null : result.longValue();
}