In jbpm4, how do I configure dynamic parameters for SQL activities?
Let's use the jbpm4 example to check the modification method:
Process definition file:
Code
<? XML version = "1.0" encoding = "UTF-8" ?>
<ProcessName= "SQL"Xmlns= "Http://jbpm.org/4.4/jpdl">
<StartG= "16, 20, 48">
<TransitionTo= "Get task names" />
</Start>
< SQL Name = "Get task names"
VaR = "Tasknames with I"
G = "96,16, 126,52" >
< Query >
Select name _
From jbpm4_task
Where name _ like: Name
</ Query >
< Parameters >
< Object Name = "Name" Expr = "# {Name }" />
<! --
<String name = "name" value = "% I %"/>
-->
</ Parameters >
< Transition To = "Count tasks" />
</ SQL >
< SQL Name = "Count tasks"
VaR = "Tasks"
Unique = "True"
G = "254,16, 92,52" >
< Query >
Select count (*)
From jbpm4_task
</ Query >
< Transition To = "Wait" />
</ SQL >
<StateName= "Wait"G="/>
</Process>
Set <string name = "name" value = "% I %"/>
Change<ObjectName= "Name"Expr= "# {Name }" />
In this way, you can input parameters from the outside.
The following is an example of a Java call.
Code
/*
* JBoss, home of professional Open Source
* Copyright 2005, JBoss inc., and individual contributors as indicated
* By the @ authors tag. See the copyright.txt IN THE DISTRIBUTION FOR
* Full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* Under the terms of the GNU lesser General Public License
* Published by the Free Software Foundation; either version 2.1
* The license, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* But without any warranty; without even the implied warranty
* Merchantability or fitness for a special purpose. See the GNU
* Lesser General Public License for more details.
*
* You shoshould have written ed a copy of the GNU lesser general public
* License along with this software; if not, write to the free
* Software Foundation, inc., 51 Franklin St, fifth floor, Boston, MA
* 02110-1301 USA, or see the FSF site: Http://www.fsf.org .
*/
Package Org. jbpm. Examples. SQL;
ImportJava. util. collection;
ImportJava. util. hashmap;
ImportJava. util. hashset;
ImportJava. util. Map;
ImportJava. util. Set;
Import Org. jbpm. API. execution;
Import Org. jbpm. API. task. task;
Import Org. jbpm. examples. java. hand;
Import Org. jbpm. test. jbpmtestcase;
/**
*@ AuthorTom Baeyens
*/
Public ClassSqltestExtendsJbpmtestcase {
String deploymentid;
String tasklaundryid;
String taskdishesid;
String taskironid;
Protected Void Setup () Throws Exception {
Super . Setup ();
Deploymentid = Repositoryservice. createdeployment ()
. Addresourcefromclasspath ( " Org/jbpm/examples/SQL/process. jpdl. xml " )
. Deploy ();
// Add task laundry
Task = Taskservice. newtask ();
Task. setname ( " Laundry " );
Tasklaundryid = Taskservice. savetask (task );
// Add task dishes
Task = Taskservice. newtask ();
Task. setname ( " Dishes " );
Taskdishesid = Taskservice. savetask (task );
// Add task Iron
Task = Taskservice. newtask ();
Task. setname ( " Iron " );
Taskironid = Taskservice. savetask (task );
}
Protected VoidTeardown ()ThrowsException {
Repositoryservice. deletedeploymentcascade (deploymentid );
Taskservice. deletetaskcascade (tasklaundryid );
Taskservice. deletetaskcascade (taskdishesid );
Taskservice. deletetaskcascade (taskironid );
Super. Teardown ();
}
Public Void Testsql (){
Map < String, Object > Variables = New Hashmap < String, Object > ();
Variables. Put ( " Name " , " % I % " );
Execution = Executionservice. startprocessinstancebykey ( " SQL " , Variables );
String executionid = Execution. GETID ();
Set < String > Expectedtasknames = New Hashset < String > ();
Expectedtasknames. Add ( " Dishes " );
Expectedtasknames. Add ( " Iron " );
Collection < String > Tasknames = (Collection < String > ) Executionservice. getvariable (executionid, " Tasknames with I " );
Tasknames = New Hashset < String > (Tasknames );
Assertequals (expectedtasknames, tasknames );
Object activities = Executionservice. getvariable (executionid, " Tasks " );
Assertequals ( " 3 " , Activities. tostring ());
}
}
Here is the modifiedCode:
Map < String, Object > Variables = New Hashmap < String, Object > ();
Variables. Put ( " Name " , " % I % " );
Execution = Executionservice. startprocessinstancebykey ( " SQL " , Variables );
We passed in the name variable for calculation.