List of usage examples for org.hibernate Session createSQLQuery
@Override NativeQuery createSQLQuery(String queryString);
From source file:com.globalsight.everest.workflow.WorkflowJbpmPersistenceHandler.java
License:Apache License
/** * Gets the active(available) task instances. * //from www . j av a 2 s.c o m * @param p_userId * the user id. * @param p_session * the hibernate session. * @param p_pm * is pm or not (true:PM|false:user). * * @return the active(available) task instances. */ @SuppressWarnings("unchecked") private static List<TaskInstance> activeTaskInstances(String p_userId, Session p_session, boolean p_pm) { SQLQuery query = null; if (p_pm) { query = p_session.createSQLQuery(SqlHolder.activeTaskPm); query.setString(PM, p_userId); if (c_logger.isDebugEnabled()) { c_logger.debug("The query sql is " + SqlHolder.activeTaskPm); } } else { query = p_session.createSQLQuery(SqlHolder.activeTask); if (c_logger.isDebugEnabled()) { c_logger.debug("The query sql is " + SqlHolder.activeTask); } query.setString(ACTOR_ID, p_userId); } query.setString(VARIABLE_NAME, WorkflowConstants.VARIABLE_IS_REJECTED); query.setString(CATEGORY, VARIABLE_CATEGORY_REJECT); query.addEntity(TaskInstance.class); return query.list(); }
From source file:com.globalsight.everest.workflow.WorkflowJbpmPersistenceHandler.java
License:Apache License
/** * Gets the rejected task instances./*from w w w. jav a 2s .c o m*/ * * @param p_userId * the user id. * @param p_session * the hibernate session. * @param p_pm * is pm or not (true:PM|false:user). * * @return the rejected task instances. */ @SuppressWarnings("unchecked") private static List<TaskInstance> rejectedTaskInstances(String p_userId, Session p_session, boolean p_pm) { SQLQuery query = null; if (p_pm) { query = p_session.createSQLQuery(SqlHolder.rejectTaskPm); query.setString(PM, p_userId); } else { query = p_session.createSQLQuery(SqlHolder.rejectTask); query.setString(USER_ID, p_userId); } query.setString(VARIABLE_NAME, WorkflowConstants.VARIABLE_IS_REJECTED); query.setString(CATEGORY, VARIABLE_CATEGORY_REJECT); query.addEntity(TaskInstance.class); return query.list(); }
From source file:com.globalsight.everest.workflow.WorkflowJbpmPersistenceHandler.java
License:Apache License
/** * Judges whether the user is rejected for the specified * <code>TaskInstance</code>. <br> * The rejected user will be stored in the table * <code>JBPM_GS_VARIABLE</code>. * /* w ww.jav a2s . c om*/ * @param ctx * {@code JbpmContext} * @param userId * the user id. * @param taskInstance * {@code TaskInstance} * @return <code>true</code> when the user is reject by the specified * taskinstance. */ public static boolean isUserRejected(JbpmContext ctx, String userId, TaskInstance taskInstance) { SQLQuery query = null; Session session = ctx.getSession(); query = session.createSQLQuery(SqlHolder.isUserReject); 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()); Number num = (Number) query.uniqueResult(); return num == null ? false : num.longValue() > 0; }
From source file:com.globalsight.everest.workflow.WorkflowJbpmPersistenceHandler.java
License:Apache License
/** * Fix for GBS-1470//from ww w .ja v 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>//w ww.j a v a 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. * //from w w w .jav a2 s . c om * @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.globalsight.everest.workflow.WorkflowJbpmPersistenceHandler.java
License:Apache License
public static List<String> getSkippedTaskInstance(long workflowId, JbpmContext p_ctx) { Session session = p_ctx.getSession(); SQLQuery query = session.createSQLQuery(SqlHolder.skippedTask); query.setString(WORKFLOW_ID, String.valueOf(workflowId)); return query.list(); }
From source file:com.globalsight.everest.workflow.WorkflowJbpmUtil.java
License:Apache License
public static List<Long> getRejectedTaskIds(List<TaskInstance> tasks, String p_userId) { JbpmContext ctx = WorkflowConfiguration.getInstance().getCurrentContext(); List<Long> allIds = new ArrayList<Long>(); if (tasks == null || tasks.size() == 0) { return allIds; }//from ww w . j a v a 2s . co m for (TaskInstance task : tasks) { allIds.add(task.getId()); } String idsString = allIds.toString(); idsString = idsString.substring(1, idsString.length() - 1); StringBuffer sql = new StringBuffer("select vi.TASKINSTANCE_ID "); sql.append("from JBPM_GS_VARIABLE vi "); sql.append("where vi.NAME = :name and vi.VALUE = :value "); sql.append("and vi.CATEGORY = 'reject' and vi.TASKINSTANCE_ID in (:ids);"); SQLQuery query = null; Session session = ctx.getSession(); query = session.createSQLQuery(sql.toString()); query.setString("name", WorkflowConstants.VARIABLE_IS_REJECTED); query.setString("value", p_userId); query.setParameterList("ids", allIds); List<Long> ids = new ArrayList<Long>(); for (Object id : query.list()) { // id is BigInteger ids.add(Long.parseLong(id.toString())); } return ids; }
From source file:com.globalsight.persistence.hibernate.HibernateUtil.java
License:Apache License
/** * Execute the Sql which starts with "select count" and returns the count * result.//from w w w .j a v a2 s. c o m * * @param hql * @param params * @return the count result. * @throws HibernateException */ public static int countWithSql(String sql, Map<String, ?> params) throws HibernateException { Session session = getSession(); Query query = session.createSQLQuery(sql); if (params != null) { Iterator<String> iterator = params.keySet().iterator(); while (iterator.hasNext()) { String key = iterator.next(); query.setParameter(key, params.get(key)); } } return ((Number) query.uniqueResult()).intValue(); }
From source file:com.globalsight.persistence.hibernate.HibernateUtil.java
License:Apache License
public static Object getFirstWithSql(String sql, Object param1) throws HibernateException { Session session = getSession(); SQLQuery query = session.createSQLQuery(sql); query.setParameter(0, param1);/*from w ww.j ava2 s . co m*/ List<?> result = query.list(); if (result == null || result.size() == 0) { return null; } return result.get(0); }