jBPM4.4开发(九)-----------HQL,SQL节点

HQL节点

1.定义

hql活动能够支持使用hql直接从数据库中查询数据,并将结果返回到流程变量中。

2.hql活动属性

var   存储hql执行结果的流程变量名称。
unique  此属性为true时,返回结果为一行,结果将作为一个单独的对象存储;此属性为false时,返回结果为多行,结果将作为一个Set存储。

3.hql活动的子元素

query   用来设置hql查询语句。
parameters  用来设置hql的外部参数。

4.Demo

流程定义文件:process.jpdl.xml
<?xml version="1.0" encoding="UTF-8"?>

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

  <start g="17,20,48,48">
    <transition to="get task names" />
  </start>

  <hql name="get task names"
       var="tasknames with i"
       g="96,16,115,52">
    <query>
      select task.name
      from org.jbpm.pvm.internal.task.TaskImpl as task
      where task.name like :taskName
    </query>
    <parameters>
      <string name="taskName" value="%i%" />
    </parameters>
    <transition to="count tasks" />
  </hql>

  <hql name="count tasks"
       var="tasks"
       unique="true"
       g="243,16,95,52">
    <query>
      select count(*)
      from org.jbpm.pvm.internal.task.TaskImpl
    </query>
    <transition to="wait" />
  </hql>

  <state name="wait" g="370,18,96,48"/>

</process>
测试类:HqlTest.java
package com.itstudio.jbpm.hql.demo;

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

import org.jbpm.api.Configuration;
import org.jbpm.api.ExecutionService;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.RepositoryService;
import org.jbpm.api.TaskService;
import org.jbpm.api.task.Task;

public class HqlTest {
	public  final Configuration configuration = new Configuration();
	public  final ProcessEngine processEngine=configuration.buildProcessEngine();
	public  final RepositoryService repositoryService= processEngine.getRepositoryService();
	public  final ExecutionService executionService=processEngine.getExecutionService();
	public  final TaskService taskService=processEngine.getTaskService();
	
	String taskLaundryId;
	String taskDishesId;
	String taskIronId;

	private void deploy() {
		repositoryService.createDeployment().addResourceFromClasspath(
				"com/itstudio/jbpm/hql/demo/process.jpdl.xml").deploy();
		System.out.println("Successful!");
		// 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);
	}
	
	private void test() {
		ProcessInstance processInstance = executionService
				.startProcessInstanceByKey("Hql");
		String processInstanceId = processInstance.getId();

		Set<String> expectedTaskNames = new HashSet<String>();
		expectedTaskNames.add("dishes");
		expectedTaskNames.add("iron");
		Collection<String> taskNames = (Collection<String>) executionService
				.getVariable(processInstanceId, "tasknames with i");
		taskNames = new HashSet<String>(taskNames);
		System.out.println("expectedTaskNames:"+expectedTaskNames);
		System.out.println("taskNames"+taskNames);
		
		Object activities = executionService.getVariable(processInstanceId,
				"tasks");
		System.out.println("activities"+activities.toString());
		
	}
	
	public static void main(String[] args) {
		HqlTest t = new HqlTest();
		t.deploy();
		t.test();
	}
}

5.sql与hql类似

请参照开发文档



By Mr.Z

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值