-
1. Re: Persistance
maxip Aug 1, 2006 5:47 AM (in response to maxip)Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at de.fhkl.bda.TestClass.main(TestClass.java:32) -
2. Re: Persistance
olivier_debels Aug 1, 2006 6:56 AM (in response to maxip)You should use JbpmContext.loadProcessInstance() to load a process instance.
What you're trying to do here doesn't make any sense.
Take a look at chapter 3 in the document. -
3. Re: Persistance
maxip Aug 1, 2006 7:30 AM (in response to maxip)Thank you
But how do i fetch a list with all started / active process instances ? -
4. Re: Persistance
olivier_debels Aug 1, 2006 7:44 AM (in response to maxip)Well,
You could try something like:
GraphSession.findAllProcessDefinitions() and loop through these ones and get all processInstances for each processDefinition (GraphSession.findProcessInstances(long)) or you could create a custom query to retrieve them in one shot. -
5. Re: Persistance
maxip Aug 1, 2006 8:00 AM (in response to maxip)OK
but i think i have a probleme with the persistance.
i deployd withd graphsession.deploy(processDefinition);
but the definition cant be found
thats my code :package de.fhkl.bda; import java.util.List; import java.util.Map; import java.util.Set; import org.jbpm.JbpmConfiguration; import org.jbpm.JbpmContext; import org.jbpm.db.GraphSession; import org.jbpm.graph.def.ProcessDefinition; import org.jbpm.graph.exe.ProcessInstance; import org.jbpm.graph.exe.Token; import org.jbpm.identity.Entity; import org.jbpm.identity.xml.IdentityXmlParser; public class TestClass { private static String actorID = "1"; /** * @param args */ public static void main(String[] args) { JbpmConfiguration.getInstance().createSchema(); JbpmContext jbpmContext = JbpmConfiguration.getInstance().createJbpmContext(); try { GraphSession graphSession = jbpmContext.getGraphSession(); ProcessDefinition processDefinition = findProcessDefinitionsFromServer("SimpleDefinition1", graphSession); System.out.println(processDefinition.getId()); } finally { jbpmContext.close(); } } public static void deployProcessDefinition(GraphSession graphSession) { ProcessDefinition processDefinition = ProcessDefinition .parseXmlString( "<process-definition name='SimpleDefinition1'>" + " <start-state name='start'>" + " <transition to='s' />" + " </start-state>" + " <state name='s'>" + " <transition to='t' />" + " </state>" + " <state name='t'>" + " <transition to='end' />" + " </state>" + " <end-state name='end' />" + "</process-definition>" ); graphSession.deployProcessDefinition(processDefinition); } public static ProcessDefinition findProcessDefinitionsFromServer(String name, GraphSession graphSession) { ProcessDefinition processDefinition = graphSession.findLatestProcessDefinition(name); if(processDefinition == null) System.out.println("No process definitions found for '" + name + "' !!!"); return processDefinition; } }
-
6. Re: Persistance
maxip Aug 1, 2006 8:06 AM (in response to maxip)it only works if i deploy the processdefinition at the same time:
JbpmConfiguration.getInstance().createSchema(); JbpmContext jbpmContext = JbpmConfiguration.getInstance().createJbpmContext(); try { GraphSession graphSession = jbpmContext.getGraphSession(); deployProcessDefinition(graphSession); // ************ findAllProcessDefinitions(graphSession); ProcessDefinition processDefinition = findProcessDefinitionsFromServer("SimpleDefinition1", graphSession); System.out.println(processDefinition.getId()); } finally { jbpmContext.close(); } }
-
7. Re: Persistance
olivier_debels Aug 1, 2006 8:15 AM (in response to maxip)The process definition is not persisted probably because you forget to close the JbpmContext when deploying. Closing the context will perform a commit on the database.
So in a realistic example you need to open a JbpmContext, deploy and close. Afterwards you create another JbpmContext to retrieve the process instances (and close this one). -
8. Re: Persistance
maxip Aug 1, 2006 8:17 AM (in response to maxip)I always create and close
so do i always create an new one ?
how can i reopen an existing jbpm context ?
btw. : thank you :) -
9. Re: Persistance
olivier_debels Aug 1, 2006 8:25 AM (in response to maxip)You can reuse JbpmContext by using JbpmContext.getCurrentJbpmContext(). This is stored in a thread local variable.
So if you open a context, only perform a deploy and then close the context the process definition is not saved? -
10. Re: Persistance
maxip Aug 1, 2006 8:33 AM (in response to maxip)hm
but how do i reuse a jbpm context with different classes ?
i want to write some classes as an example how to use jbpm for our univeristy.
so i want to deploy a process definition. close the program
then i want to start a programm which uses this context, too and starts a process instance
and there should be one more program that shows all open tasks
so actually i have to keep the programm running all the time ? it should be more like a server / client
i have the jbpm server running (starters kit) but it seems that eclipse only starts a "local" jbpm contaxt which is lost after my programm has terminated
thats the programm that works:package de.fhkl.bda; import java.util.List; import java.util.Map; import java.util.Set; import org.jbpm.JbpmConfiguration; import org.jbpm.JbpmContext; import org.jbpm.db.GraphSession; import org.jbpm.graph.def.ProcessDefinition; import org.jbpm.graph.exe.ProcessInstance; import org.jbpm.graph.exe.Token; import org.jbpm.identity.Entity; import org.jbpm.identity.xml.IdentityXmlParser; public class TestClass { private static String actorID = "1"; /** * @param args */ public static void main(String[] args) { JbpmConfiguration.getInstance().createSchema(); JbpmContext jbpmContext = JbpmConfiguration.getInstance().createJbpmContext(); try { GraphSession graphSession = jbpmContext.getGraphSession(); deployProcessDefinition(graphSession); findAllProcessDefinitions(graphSession); ProcessDefinition processDefinition = findProcessDefinitionsFromServer("SimpleDefinition1", graphSession); System.out.println(processDefinition.getId()); } finally { jbpmContext.close(); } } public static void deployProcessDefinition(GraphSession graphSession) { ProcessDefinition processDefinition = ProcessDefinition .parseXmlString( "<process-definition name='SimpleDefinition1'>" + " <start-state name='start'>" + " <transition to='s' />" + " </start-state>" + " <state name='s'>" + " <transition to='t' />" + " </state>" + " <state name='t'>" + " <transition to='end' />" + " </state>" + " <end-state name='end' />" + "</process-definition>" ); graphSession.deployProcessDefinition(processDefinition); graphSession.saveProcessDefinition(processDefinition); } public static ProcessDefinition findProcessDefinitionsFromServer(String name, GraphSession graphSession) { ProcessDefinition processDefinition = graphSession.findLatestProcessDefinition(name); if(processDefinition == null) System.out.println("No process definitions found for '" + name + "' !!!"); return processDefinition; } public static void findAllProcessDefinitions(GraphSession graphSession) { System.out.println(graphSession.findAllProcessDefinitions()); } }
But as i told above i want to re-use the same context in several different programs.
so how can i use the server to store it forever ?
now i guess why i cant find anything i deployed / started in earlier times -
11. Re: Persistance
olivier_debels Aug 1, 2006 8:40 AM (in response to maxip)In your case it should work if:
* you create and close a context when deploying
* you create and close a context when retrieving process instances
* you create and close a context when showing all open tasks
No need to reuse a context here. -
12. Re: Persistance
maxip Aug 1, 2006 8:43 AM (in response to maxip)Thank you for your help but it does not work :(
i createt a context deployed the process definition.
then i started another main class which created e new context and tried to get all process definitions.
but none were found.
How can i ensure that the server us used which is running ? i have the feeling its every time just a temporaily created jbpm server which stops when my main class ends. -
13. Re: Persistance
olivier_debels Aug 1, 2006 8:52 AM (in response to maxip)Strange,
If you are using hsqldb, see 8.3 in documentation to check if process definitions are actually stored in the database. You can also try to deploy the definitions using the gpd designer tool. -
14. Re: Persistance
maxip Aug 1, 2006 8:59 AM (in response to maxip)OK
so i deployed a process definition by the designer (deployment was successfull)
but i cant find any process definitionpublic static void main(String[] args) {
JbpmConfiguration.getInstance().createSchema();
JbpmContext jbpmContext = JbpmConfiguration.getInstance().createJbpmContext();
try {
GraphSession graphSession = jbpmContext.getGraphSession();
// deployProcessDefinition(graphSession);
findAllProcessDefinitions(graphSession);
//ProcessDefinition processDefinition = findProcessDefinitionsFromServer("SimpleDefinition1", graphSession);
//System.out.println(processDefinition.getId());
}
finally {
jbpmContext.close();
}
}
public static void findAllProcessDefinitions(GraphSession graphSession) {
System.out.println(graphSession.findAllProcessDefinitions());
}