Hi,

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.





View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3920465#3920465

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3920465


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to