jbpm sql使用动态参数方法

在jbpm4中如何配置sql活动使用动态参数呢?

我们使用JBPM4的例子为例,查看修改的方法:

流程定义文件:

 

ExpandedBlockStart.gif 代码
<? xml version="1.0" encoding="UTF-8" ?>

< process  name ="Sql"  xmlns ="http://jbpm.org/4.4/jpdl" >

  
< start  g ="16,20,48,48" >
    
< transition  to ="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 >

  
< state  name ="wait"  g ="378,18,94,48" />

</ process >

 

<string name="name" value="%i%" /> 
修改为  <object name="name" expr="#{name}" />

这样我们就可以从外部传入参数。

下面为JAVA调用的示例。

 

ExpandedBlockStart.gif 代码
/*
 * 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 a
 * 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 as
 * published by the Free Software Foundation; either version 2.1 of
 * 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 of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received 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;

import  java.util.Collection;
import  java.util.HashMap;
import  java.util.HashSet;
import  java.util.Map;
import  java.util.Set;

import  org.jbpm.api.Execution;
import  org.jbpm.api.task.Task;
import  org.jbpm.examples.java.Hand;
import  org.jbpm.test.JbpmTestCase;


/**
 * 
@author  Tom Baeyens
 
*/
public   class  SqlTest  extends  JbpmTestCase {

  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 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   void  tearDown()  throws  Exception {
    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 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());
  }
}

 

这里是修改过后的代码:

Map<String, Object> variables = new HashMap<String, Object>();
        variables.put(
"name""%i%");
    Execution execution 
= executionService.startProcessInstanceByKey("Sql",variables);
我们传入name变量,进行计算了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值