This content has been marked as final.
Show 4 replies
-
1. Re: FInd task according to its variable
aguizar Aug 13, 2005 5:27 AM (in response to kukeltje)How about this: the jbpm_variableinstance table contains a processinstance field and some other fields with either the literal value for value-typed variables or a reference ID for entity-typed variables.
If the office location is a string, you can issue an HQL query like the following to retrieve the process instances for that location:select processInstance from StringInstance where name='officeLocation' and value='Timbouctu'
-
2. Re: FInd task according to its variable
andrewbruno Aug 26, 2005 2:46 AM (in response to kukeltje)The problem I see here is that if you have two or more "different" process definitions that use the same variableName, then it could cause some confusion.
-
3. Re: FInd task according to its variable
aguizar Aug 27, 2005 8:25 PM (in response to kukeltje)You're right Andrew, but that is easily solved by specifying a process definition:
select processInstance from StringInstance where name = 'officeLocation' and value = :location and processInstance.processDefinition.id = :pid
-
4. Re: FInd task according to its variable
andrewbruno Aug 29, 2005 3:09 AM (in response to kukeltje)Alex, thanks for that.
Anyway, this is the code that I ended up implementingprivate static final String findProcessInstancesByVariableNameValueQuery = "select processInstance " + "from org.jbpm.context.exe.variableinstance.StringInstance " + "where name= :variableName " + "and value= :variableValue "; /** * Gets a list of processInstances by variable name and value * * @param variableName * @param variableValue * @return list of ProcessInstances */ public List findProcessInstancesByVariableNameValue(String variableName, String variableValue) { List stringInstances = null; List processInstances = null; try { Query query = session .createQuery(findProcessInstancesByVariableNameValueQuery); query.setString("variableName", variableName); query.setString("variableValue", variableValue); stringInstances = query.list(); } catch (Exception e) { log.error(e); jbpmSession.handleException(); throw new RuntimeException("couldn't get process instances ", e); } // The result is a StringInstance, hence we need to convert the // StringInstance to ProcessInstance if ((stringInstances != null) && (stringInstances.size() != 0)) { StringInstance stringInstance = null; processInstances = new ArrayList(stringInstances.size()); Iterator i = stringInstances.iterator(); while (i.hasNext()) { stringInstance = (StringInstance) i.next(); processInstances.add(stringInstance.getProcessInstance()); } } return processInstances; }
Is there a better way to implement this, rather then looping through the StringInstances in order to get process instances?
Thanks, Andrew