zoukankan      html  css  js  c++  java
  • jbpm sql使用动态参数方法

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

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

    流程定义文件:

    代码
    <?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调用的示例。

     

    代码
    /*
     * 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变量,进行计算了。

  • 相关阅读:
    Wannafly挑战赛21A
    luoguP4000 斐波那契数列
    关于斐波那契数模意义下的循环节问题
    Codeforces Round #501 (Div. 3) F. Bracket Substring
    1257: [CQOI2007]余数之和
    51nod1380 夹克老爷的逢三抽一
    51nod1423 最大二"货" 单调栈
    51nod1624 取余最长路 前缀和 + set
    51nod1437 迈克步 单调栈
    51nod1515 明辨是非 并查集 + set
  • 原文地址:https://www.cnblogs.com/yg_zhang/p/1934145.html
Copyright © 2011-2022 走看看