Queries to search the database for process instances based
clannoy Jan 30, 2006 1:03 PMHi,
I need to make an API in jBPM 3.0.2 able to make simple queries to search the database for process instances based on process variables.
I try a little test and I develloped that :
on ContextSession :
nomAtt : process variable name
o : value of the process variable to search
public List findProcessInstance(String nomAtt,Object o)
{
JbpmType jbpmType = this.getJbpmType(o.getClass());
Object objetConverti = jbpmType.converter.convert(o);
String req = "select vi.processInstance " +
" from " +
jbpmType.variableInstanceClass.getName() +
" vi" +
" where vi.value = :value and vi.name = :name ";
List result = null;
try {
Query query = session.createQuery(req);
query.setParameter("value", objetConverti);
query.setString("name", nomAtt);
result = query.list();
} catch (Exception e) {
jbpmSession.handleException();
throw new RuntimeException("oulahlah ", e);
}
return result;
}and the code of the method getJbpmType the idea come from VariableInstance.createVariableInstance(Class javaType)
public JbpmType getJbpmType(Class javaType) {
Iterator iter = JbpmType.getJbpmTypes().iterator();
while (iter.hasNext())
{
JbpmType jbpmType = (JbpmType) iter.next();
// isMatch indicates wether the given javaType matches this jbpmType
boolean isMatch = false;
if ( (jbpmType.variableClass!=null)
&& (jbpmType.variableClass.isAssignableFrom(javaType)) ) {
isMatch = true;
} else {
if (javaType.getName().equals(jbpmType.variableClassName)) {
isMatch = true;
} else if ("{serializable-classes}".equals(jbpmType.variableClassName)) {
isMatch = (Serializable.class.isAssignableFrom(javaType));
} else if ("{hibernateable-long-id-classes}".equals(jbpmType.variableClassName)) {
JbpmSession currentJbpmSession = JbpmSession.getCurrentJbpmSession();
isMatch = ( (currentJbpmSession!=null)
&& (currentJbpmSession.getJbpmSessionFactory().isHibernatableWithLongId(javaType)));
} else if ("{hibernateable-string-id-classes}".equals(jbpmType.variableClassName)) {
JbpmSession currentJbpmSession = JbpmSession.getCurrentJbpmSession();
isMatch = ( (currentJbpmSession!=null)
&& (currentJbpmSession.getJbpmSessionFactory().isHibernatableWithStringId(javaType)));
}
}
if (isMatch) {
return jbpmType;
}
}
return null;
}Does someone have an idea/suggestion on this code. Is it a good way to do that ?
Can I use easily this method with the futur versions (3.1, ...) of jBPM
Thanks in advance for your answer.