activiti 自定义流程6 配置processEngineConfiguration时为什么不能使用databaseSchema为oracle多用户创建表

不了了之之了之
activiti配置
activiti Configuration(配置)
Table of Contents
Creating a ProcessEngine(建立一个流程引擎)
The Activiti process engine is configured through a xml file called activiti.cfg.xml. Note that this is not applicable if you're using .
Activiti流程引擎通过一个叫做的xml文件来配置。注意你采用构建流程引擎的Spring风格的方式,这种方式并不适合
The easiest way to obtain a ProcessEngine, is to use the org.activiti.engine.ProcessEngines class:
获取ProcessEngine最容易的方式是使用org.activiti.engine.ProcessEngines类:
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine()
This will look for an activiti.cfg.xml file on the classpath and construct an engine based on the configuration in that file. The following snippet shows an example configuration. The following sections will give a detailed overview of the configuration
properties.
这将在classpath上寻找 activiti.cfg.xml文件,并在那个文件的配置之上构建一个引擎。下列片段显示了一个示例配置。下面部分将给出详细的配置特性的总体概观。
&beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd"&
&bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"&
&property name="databaseType" value="h2" /&
&property name="jdbcUrl" value="jdbc:h2:mem:DB_CLOSE_DELAY=1000" /&
&property name="jdbcDriver" value="org.h2.Driver" /&
&property name="jdbcUsername" value="sa" /&
&property name="jdbcPassword" value="" /&
&property name="databaseSchemaUpdate" value="true" /&
&property name="jobExecutorActivate" value="false" /&
&property name="mailServerHost" value="mail.my-corp.com" /&
&property name="mailServerPort" value="5025" /&
Note that the configuration xml is in fact a Spring configuration. This does not mean that Activiti can only be used in a Spring environment! We are simply leveraging the parsing and dependency injection capabilitities of Spring internally
for building up the engine.
注意配置文件事实上是一个Spring配置。这并不意味着Activiti只能在Spring环境下使用! 为了构建引擎,我们在内部简单地平衡了解析和Spring的依赖注入的能力。
The ProcessEngineConfiguration object can also be created programmatically using the configuration file. It is also possible to use a different bean id (eg. see line 3).
通过使用配置文件,也能通过编程方式建立ProcessEngineConfiguration对象。使用一个不同的bean id也是可能的。(例如,见第3行)。
ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault();
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(String resource);
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(String resource, String beanName);
ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(InputStream inputStream);
ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(InputStream inputStream, String beanName);
It is also possible not to use a configuration file, and create a configuration based on defaults (see
for more information).
不使用配置文件也是可能的,基于缺省建立一个配置(详情参见不同支持的类())
ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration();
All these ProcessEngineConfiguration.createXXX() methods return a ProcessEngineConfiguration that can further be tweaked if needed. After calling thebuildProcessEngine() operation, aProcessEngine is created:
如果需要所有 ProcessEngineConfiguration.createXXX()的方法返回一个能进一步配置的ProcessEngineConfiguration 。在调用操作之后,建立一个ProcessEngine 。
ProcessEngine processEngine = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration()
.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
.setJdbcUrl("jdbc:h2:mem:my-own-DB_CLOSE_DELAY=1000")
.setJobExecutorActivate(true)
.buildProcessEngine();
ProcessEngineConfiguration bean
The activiti.cfg.xml must contain a bean that has the id 'processEngineConfiguration'.
dd activiti.cfg.xml 必须包括具有id 'processEngineConfiguration'的bean。
&bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"&
This bean is then used to construct the ProcessEngine. There are multiple classes available that can be used to define the processEngineConfiguration. These classes represent different environments, and set defaults accordingly. It's
a best practice to select the class the matches (the most) your environment, to minimalise the number of properties needed to configure the engine. Following classes are currently available (more will follow in future releases):
得到这个bean然后用来构建e ProcessEngine。可以定义processEngineConfiguration的类有多个。这些类表示不同的环境,响应地设置为缺省。为了减少需要配置引擎的属性数量,选择的类以匹配环境是最佳实践。当前可获得的类如下(将来的版本将推出新的类)
org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration: the process engine is used in a standalone way. Activiti will take care of the transactions. By default, the database will only
be checked when the engine boots (and an exception is thrown if there is no Activiti schema or the schema version is incorrect).
org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration:以独立方式运行的流程引擎。Activiti将考虑事务。缺省地,只有在引擎引导时检查数据库(如果没有Activiti schema或者schema版本不正确,将抛出异常)。
org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration: this is a convience class for unit testing purposes. Activiti will take care of the transactions. An H2 in-memory database
is used by default. The database will be created and dropped when the engine boots and shuts down. When using this, probably no additional configuration is needed (except when using for example the job executor or mail capabilities).
org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration: 这是一个针对单元测试目的的便捷类。Activiti将考虑事务。缺省使用H2内存数据库。当引擎引导并关闭时,数据库将被建立和删除。当使用时,可能需要额外的配置(当使用作业执行器或者邮件能力的示例除外)
org.activiti.spring.SpringProcessEngineConfiguration: To be used when the process engine is used in a Spring environment. See
for more information.
org.activiti.spring.SpringProcessEngineConfiguration: 当在Spring环境下使用流程引擎时使用。详情参见Spring集成部分。
org.activiti.engine.impl.cfg.JtaProcessEngineConfiguration: ()
to be used when the engine runs in standalone mode, with JTA transactions.
org.activiti.engine.impl.cfg.JtaProcessEngineConfiguration: ()当引擎以带有JTA事务的单独模式运行时使用。
Database configuration(数据库配置)
There are two ways to configure the database that the Activiti engine will use. The first option is to define the jdbc properties of the database:
有两种方式类配置引擎将使用的数据库。第一个选项是定义数据库的jdbc属性:
jdbcUrl: jdbc url of the database.
jdbcUrl: 数据库的jdbc url。
jdbcDriver: implementation of the driver for the specific database type.
jdbcDriver: 特定数据库驱动的实现。
jdbcUsername: username to connect to the database.
jdbcUsername: 连接到数据的用户名。
jdbcPassword: password to connect to the database.
jdbcPassword: 连接到数据库的密码。
The datasource that is constructed based on the provided jdbc properties will have the default
connection pool settings. Following attributes can optionally be
set to tweak that connection pool (taken from the MyBatis documentation):
基于所提供的jdbc属性所构建的数据源将有的连接池设置。
jdbcMaxActiveConnections: The number of active connections that the connection pool at maximum at any time can contain. Default is 10.
jdbcMaxActiveConnections: 在任何时刻连接池最大能够包含的可以激活的连接数。缺省为10.
jdbcMaxIdleConnections: The number of idle connections that the connection pool at maximum at any time can contain.
jdbcMaxIdleConnections:在任何时刻连接池最大能够包含的空闲的连接数
jdbcMaxCheckoutTime: The amount of time in milliseconds a connection can be 'checked out' from the connection pool before it is forcefully returned. Default is 20000 (20 seconds).
jdbcMaxCheckoutTime: 在连接强制返回之前,能够从连接池检出一个连接所需的以毫秒计算的时间值。
jdbcMaxWaitTime: This is a low level setting that gives the pool a chance to print a log status and re-attempt the acquisition of a connection in the case that it’s taking unusually long (to avoid
failing silently forever if the pool is misconfigured) Default is 20000 (20 seconds).
jdbcMaxWaitTime: 这是一个底层的设置,给连接池一个打印日志状态并重试连接获取的机会。在这种情况下通常占用很长时间(以避免如果连接池位置不好导致导致悄无声息地失败),缺省时20000(20秒)。
Example database configuration:
示例数据库配置:
&property name="databaseType" value="h2" /&
&property name="jdbcUrl" value="jdbc:h2:mem:DB_CLOSE_DELAY=1000" /&
&property name="jdbcDriver" value="org.h2.Driver" /&
&property name="jdbcUsername" value="sa" /&
&property name="jdbcPassword" value="" /&
Alternatively, a javax.sql.DataSource implementation can be used (eg. DBCP from ):
可选,可以使用 javax.sql.DataSource的实现(例如的DBCP):
&bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" &
&property name="driverClassName" value="com.mysql.jdbc.Driver" /&
&property name="url" value="jdbc:mysql://localhost:3306/activiti" /&
&property name="username" value="activiti" /&
&property name="password" value="activiti" /&
&property name="defaultAutoCommit" value="false" /&
&bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"&
&property name="dataSource" ref="dataSource" /&
Note that Activiti does not ship with a library that allows to define such datasource. So you have to make sure that the libraries (eg. from DBCP) are on your classpath.
注意Activiti并不包含允许定义如此数据源的Java库。所以,确保这些(例如,从DBCP而来)在你的classpath里面。
Following properties can be set, regardless of using the jdbc or datasource approach:
不管采用jdbc还是数据源方法,可以设置下列属性:
databaseType: indicates the type of database. This property is required when not using the default H2 database This setting will determine which create/drop scripts and queries
will be used. See
for an overview of which types are supported.
databaseType: 指示数据库类型。当不是采用缺省的H2数据库时xuyao 需要。这个设置将决定将要使用哪个建立/删除脚本。要了解支持哪些类型的概要,请参见 。
databaseSchemaUpdate: allows to set the strategy to handle the database schema on process engine boot and shutdown.
databaseSchemaUpdate:允许当流程引擎引导和关闭时,设置处理数据库结构采取的策略。
false (default): Checks the version of the DB schema against the library when the process engine is being created and throws an exception if the versions don't match.
false (缺省):当流程引擎建立时,检查DB和库的版本。如果版本不匹配,将抛出异常。
true: Upon building of the process engine, a check is performed and an update of the schema is performed if it is necessary. If the schema doesn't exist, it is created.
true:一旦流程引擎构建完成,执行一个检查。如果有必要,更新数据库的结构。如果结构不存在,就创建它。
create-drop: Creates the schema when the process engine is being created and drops the schema when the process engine is being closed.
create-drop:在流程引擎创建时创建结构;当流程引擎时到达删除结构。
Job executor activation(作业执行器激活)
The JobExecutor is a component that manages a couple of threads to fire timers (and later also asynchronous messages). For unit testing scenarios, it is cumbersome to work with multiple threads. Therefor the API allows to query for (ManagementService.createJobQuery)
and execute jobs (ManagementService.executeJob) through the API so that job execution can be controlled from within a unit test. To avoid that the job executor interferes, it can be turned off.
作业执行器是一个管理点火定时器一对线程的组件(之后也叫异步消息)。对于单元测试场景,和多个线程一道工作是麻烦的。所以API允许通过API查询 (ManagementService.createJobQuery) 并执行作业 (ManagementService.executeJob) 以便从一个单元测试里控制作业执行。为了避免作业干扰,可以关掉它。
By default, the JobExecutor is activated when the process engine boots. Specify
缺省地,当流程引擎引导时激活JobExecutor。指定
&property name="jobExecutorActivate" value="false" /&
when you don't want the JobExecutor to be activated upon process engine boot.
当流程引擎引导时,并不想激活 JobExecutor。
Mail server configuration(邮件服务器配置)
Optional. Activiti supports sending e-mails in business processes. To actually send an e-mail, a valid SMTP mail server configuration is required. See the
for the configuration options.
可选。. Activiti 支持在业务流程里发送电子邮件。事实上,为了发送邮件,需要配置一个有效的SMTP邮件服务器配置。这个配置可选项参见 。
History configuration(历史配置)
Optional. Allows to tweak settings that influence the
of the engine. See
for more details.
可选项。允许影响引擎的历史能力的设置。详情参见 。
&property name="history" value="audit" /&
Supported databases(支持的数据库)
Following are the types (case sensitive!) that Activiti uses to refer to databases.
下表是Activiti所使用的数据库表类型(大小写敏感的)。
Table 1.1. Supported databases
Activiti database type
Versions tested
Default configured database
not yet supported (coming soon, see )
not yet supported (coming soon)
Changing the database(改变数据库)
One of the things you probably want to do at some point, is configuring Activiti to use a different database. To configure the demo setup or to generate a configuration file for a different database, follow these steps:
在某些点你可能想做的其中一件事是配置来使用不同的数据库。为了配置演示安装或者为不同数据库产生一个配置文件,遵从这些步骤:
Edit setup/build.properties and change the db parameter to your type of database {oracle | mysql | postgresql | h2}.
编辑 setup/build.properties 并将db参数变为你的数据库的类型 {oracle | mysql | postgresql | h2}。
Edit setup/build.${db}.properties and change the JDBC connection parameters to those of your database installation.
编辑setup/build.${db}.properties并将JDBC连接参数变为你所安装数据库的那些参数。
To create a configuration file for your database based on the properties you've specified in the build.*.properties files run
为了建立一个基于你所指定build.*.properties 文件的属性的配置文件。请运行
ant cfg.create
from within the setup folder. The generate configuration file can now be found in setup/build/activiti-cfg. Also, for convenience, a jar called containing the configuration file can be found in setup/build
在setup 文件夹。产生的配置文件在setup/build/activiti-cfg里能够找到。 为了方便起见,一个叫activiti-cfg.jar的jar包包含了能够在setup/build 里找到的配置文件。
If you want to run the demo setup on another database, first stop the demo setup with
如果你想在另一个数据库上运行演示安装,首先用下面的命令停止示例安装
ant demo.stop demo.clean demo.start
Then clean and re-start the demo setup with
然后清除并重新启动演示安装:
ant demo.clean demo.start
Downloading the Oracle driver(下载Oracle)
When you want to run the demo setup using oracle as datasource, an extra step is required BEFORE you call the ant target demo.start.
当你想使用oracle作为数据源来运行演示安装,在调用ant目标 demo.start之前,必须要有额外的步骤:
Since we cannot redistribute the Oracle JDBC driver due to its licence, you should download it manually:.
Make sure you download ojdbc5.jar (our tests run against 10g ojdbc using version 11.2.0.1).
因为由于Oracle JDBC Driver的授权原因,我们不能重新分发它,所以你应当手动下载:。确保下载的是ojdbc5.jar()
Copy the downloaded ojdbc5.jar to setup/files/dependencies/libs/ This filename is
拷贝下载的ojdbc5.jar至setup/files/dependencies/libs/。
activiti学习笔记3---Job Executor and Async Executor
Activiti(一)--安装配置详解
activiti流程引擎配置
【Activiti工作流】4.准备开发环境(配置文件)和核心api的介绍
Activiti的引擎与引擎配置对象
activiti入门三(引擎配置)
Activiti基础教程--01(简介、代码生成Activiti的25张表、Activiti配置文件activiti.cfg.xml生成25张表、在Eclipse上安装Activiti插件)
Activiti进阶(一)——HelloWorld
Activiti入门教程三(详解流程引擎配置)
activiti自定义流程之Spring整合activiti-modeler5.16实例(四):部署流程定义
没有更多推荐了,Activiti快速入门 - myJavaEE - 博客园
1.什么是Activiti
在解释activiti之前我们看一下什么是工作流。工作流(Workflow),就是“业务过程的部分或整体在计算机应用环境下的自动化”,它主要解决的是“使在多个参与者之间按照某种预定义的规则传递文档、信息或任务的过程自动进行,从而实现某个预期的业务目标,或者促使此目标的实现”。我的理解是,工作流将一套大的业务逻辑分解成业务逻辑段, 并统一控制这些业务逻辑段的执行条件,执行顺序以及相互通信。 实现业务逻辑的分解和解耦。Activiti是一个开源的工作流引擎,它实现了BPMN 2.0规范,可以发布设计好的流程定义,并通过api进行流程调度。BPMN即业务流程建模与标注(Business Process Model and Notation,BPMN) ,描述流程的基本符号,包括这些图元如何组合成一个业务流程图(Business Process Diagram)。
BPMN的流程图长这样子
activiti5.13使用了23张表支持整个工作流框架,底层使用mybatis操作数据库。这些数据库表为
1)ACT_RE_*: 'RE'表示repository。 这个前缀的表包含了流程定义相关的静态资源(图片,规则等)。2)ACT_RU_*: 'RU'表示runtime。 运行时表,包含流程实例,任务,变量,异步任务等运行中的数据。流程结束时这些记录会被删除。3)ACT_ID_*: 'ID'表示identity。 这些表包含用户和组的信息。4)ACT_HI_*: 'HI'表示history。 这些表包含历史数据,比如历史流程实例,变量,任务等。5)ACT_GE_*: 通用数据,bytearray表保存文件等字节流对象。
工作流进行的基本过程如下:定义流程(框架外) -& 部署流程定义 -& 启动流程实例, 框架移动到任务1 -& 拾取组任务 -& 办理个人任务, 框架移动到任务2 -& 拾取组任务 -& 办理个人任务...
组任务是多个用户都可以完成的任务。没有组任务直接办理个人任务; 有组任务需先通过拾取将组任务变成个人任务, 然后再办理。
个人任务/组任务在表中的区别
个人任务: 表act_ru_task的ASSIGNEE段即指定的办理人
组任务: 表act_ru_task的ASSIGNEE段为null, 相关信息在表act_ru_identitylink中, 组任务1见userid段;& 组任务2见groupid段, 当然还需查询act_id_xxx表才能精确到人.
2.Activiti的使用
2.1 创建processEngine
processEngine控制着工作流整个流程
public class processEngine {
public void createProcessEngine1() {
String resource = "activiti-context.xml";
// 配置文件
String beanName = "processEngineConfiguration";
// 配置文件中bean name
// 从配置文件创建配置对象
ProcessEngineConfiguration config = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(resource, beanName);
// 根据配置创建引擎对象
ProcessEngine processEngine = config.buildProcessEngine();
一条语句创建processEngine, 要求:
* 1、配置文件必须在classpath根目录下
* 2、配置文件名必须为activiti-context.xml或activiti.cfg.xml
* 3、工厂对象的id必须为processEngine
public void createProcessEngine2() {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
&beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"&
&!-- 配置 --&
&bean id="processEngineConfiguration"
class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"&
&property name="jdbcDriver"
value="com.mysql.jdbc.Driver"/&
&property name="jdbcUrl"
value="jdbc:mysql:///test_activiti"/&
&property name="jdbcUsername"
value="root"/&
&property name="jdbcPassword"
value="root"/&
&!-- 创建processEngine时, activiti自动创建23张表 --&
&property name="databaseSchemaUpdate" value="true"/&
&!-- 使用配置创建引擎对象 --&
&bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean"&
&property name="processEngineConfiguration" ref="processEngineConfiguration"/&
当然, 可以与spring进一步整合, 使用spring方式获取processEngine.& applicationContext.xml如下
&beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"&
&bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"&
&property name="driverClassName" value="com.mysql.jdbc.Driver" /&
&property name="url" value="jdbc:mysql:///activiti_day2" /&
&property name="username" value="root" /&
&property name="password" value="root" /&
&bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&
&property name="dataSource" ref="dataSource"/&
&!-- 流程引擎配置对象 --&
&bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration"&
&!-- 注入数据源 --&
&property name="dataSource" ref="dataSource"/&
&!-- 注入事务管理器对象 --&
&property name="transactionManager" ref="transactionManager"/&
&property name="databaseSchemaUpdate" value="true" /&
&bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean"&
&property name="processEngineConfiguration" ref="processEngineConfiguration" /&
2.2 部署流程定义
流程是由用户通过bpmn等文件(底层xml)定义的, 即上面列举的的bpmn流程图
定义好的流程需要部署给activiti才能被其使用
* 部署流程定义
* 一套定义文件只有一个流程定义Key, 但可以被部署多次形成多个版本(部署表里多个id和流程定义表里多个id)
* 涉及的表:act_re_deployment(部署表)、act_re_procdef(流程定义表)、act_ge_bytearray(二进制表)
public void test() throws FileNotFoundException {
DeploymentBuilder deploymentBuilder = processEngine.getRepositoryService().createDeployment();
// 逐个文件部署
// deploymentBuilder.addClasspathResource("qjlc.bpmn");
// deploymentBuilder.addClasspathResource("qjlc.png");
// 压缩文件打包部署, 推荐
ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(new File("d:\\processDef.zip")));
deploymentBuilder.addZipInputStream(zipInputStream );
Deployment deployment = deploymentBuilder.deploy();
2.3 启动流程实例
* 启动一个流程实例
* 涉及的表:
* act_ru_execution(流程实例表), 管理流程进度
* act_ru_task(任务表), 进行到哪一个流程的哪一个任务, 该由谁完成
public void test() throws Exception{
String processDefinitionKey = "qjlc";
//方式一:根据流程定义id启动流程实例
//String processDefinitionId = "qjlc:6:904";
//ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitionId);
//方式二:根据流程定义Key启动流程实例
推荐!流程定义有多个版本时会选择最新版本
ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceByKey(processDefinitionKey);
2.4 办理任务
* 办理任务, 办理后框架自动移动到下一任务
* 涉及的表: act_ru_execution(流程实例表)、act_ru_task(任务表)
public void test() throws Exception{
String taskId = "1304";
processEngine.getTaskService().complete(taskId);
2.5 其他操作
* 查询流程定义
* 涉及的表:act_re_procdef
public void test(){
ProcessDefinitionQuery query = processEngine.getRepositoryService().createProcessDefinitionQuery();
// 查询条件过滤
query.processDefinitionKey("qjlc");
query.orderByProcessDefinitionVersion().asc();
List&ProcessDefinition& list = query.listPage(0, 10);
for (ProcessDefinition processDefinition : list) {
System.out.println(processDefinition.getId());
activiti中查询的套路:& processEngine.getXXXService().createXXXQuery().list()/singleResult()processEngine.getRepositoryService().createDeploymentQuery().list(); // 查询部署processEngine.getRuntimeService().createProcessInstanceQuery().list(); // 查询流程实例processEngine.getTaskService().createTaskQuery().list(); // 查询个人任务 processEngine.getIdentityService().createUserQuery().list(); // 查询用户processEngine.getHistoryService().createHistoricActivityInstanceQuery().list(); //查询历史过滤条件查询个人任务 query.taskAssignee()查询组任务&&& query.taskCandidate()
几个javabean(和表对应):Deployment------act_re_deploymentProcessDefinition-----act_re_procdefProcessInstance------act_ru_executionTask-----act_ru_task几个Query对象:DeploymentQuery------act_re_deploymentProcessDefinitionQuery-----act_re_procdefProcessInstanceQuery------act_ru_executionTaskQuery-----act_ru_task几个Service:RepositoryService----操作部署表、流程定义表等静态资源信息表RuntimeService----操作流程实例表、任务表等动态信息表TaskService-----操作任务表HistoryService----操作历史表IdentityService----操作用户表、组表、关系表
  // 删除流程定义
public void test1(){
String deploymentId = "101";
boolean cascade = false;
// 级联删除, 设置为true的话, 有正在跑的流程实例及任务也会被删除
processEngine.getRepositoryService().deleteDeployment(deploymentId, cascade);
// 删除流程实例
public void test2() throws Exception{
String processInstanceId = "1201";
String deleteReason = "不请假了";
// 可以添加删除原因
processEngine.getRuntimeService().deleteProcessInstance(processInstanceId, deleteReason);
}  // 根据部署id, 获取定义文件
public void test3() throws Exception{
String deploymentId = "201"; //部署id
// 先获得定义文件的名字
List&String& names = processEngine.getRepositoryService().getDeploymentResourceNames(deploymentId);
for (String name : names) {
InputStream in = processEngine.getRepositoryService().getResourceAsStream(deploymentId, name);
FileUtils.copyInputStreamToFile(in, new File("d:\\"+name));
in.close();
// 根据流程定义id, 获取定义文件
public void test4() throws Exception{
String processDefinitionId = "qjlc:6:904"; //流程定义id
InputStream pngStream = processEngine.getRepositoryService().getProcessDiagram(processDefinitionId);
FileUtils.copyInputStreamToFile(pngStream, new File("d:\\abc.png"));
通过javabean能访问到某些需要的字段, 例如
processInstance.getActivityId() -& 当前执行的任务名
processDefinition.getDiagramResourceName() -& 定义文件中图片的名字
2.6& 流程变量
多个任务间可以通过流程变量通信.
流程变量以key-value形式存放, 存于表 act_ru_variable. 在同一流程实例里, 不同方式设置变量, key相同时会覆盖
// 启动流程实例时 设置流程变量
public void test1() {
String processDefinitionKey = "bxlc";
Map&String, Object& variables = new HashMap&String, Object&();
variables.put("key", "value");
ProcessInstance pi = processEngine.getRuntimeService().startProcessInstanceByKey(processDefinitionKey, variables);
// 办理任务时 设置流程变量, 更实用!
public void test2() {
String taskId = "206";
Map&String, Object& variables = new HashMap&&();
variables.put("key", "value");
processEngine.getTaskService().complete(taskId, variables);
// 通过RuntimeService 设置流程变量
public void test3() {
String executionId = "201"; // 流程实例id
Map&String, Object& variables = new HashMap&&();
variables.put("key", "value");
//processEngine.getRuntimeService().setVariable(executionId, variableName, value);
processEngine.getRuntimeService().setVariables(executionId, variables);
// 通过TaskService 设置流程变量
public void test4() {
String taskId = "304";
String key = "key";
Object value = "value";
processEngine.getTaskService().setVariable(taskId , key, value);
// 通过RuntimeService 获取流程变量
public void test5() {
String executionId = "201";
Object value = processEngine.getTaskService().getVariable(executionId, "user");
System.out.println(value);
// 通过TaskService 获取流程变量
public void test6() {
String taskId = "304";
Object value = processEngine.getTaskService().getVariable(taskId, "user");
System.out.println(value);
流程变量还可以通过在定义流程用表达式${}.& 框架在该段任务执行前从act_ru_variable表里动态获取
另外, 启动流程实例还有一个重载函数, 除了流程变量variables还能指定业务主键businessKey
processEngine.getRuntimeService().startProcessInstanceByKey(processDefinitionKey, businessKey, variables);
businessKey一般设置为业务表的主键值, 在使用activiti的时候,&通过查询业务表主键, 能方便地查询出业务的最新状态
2.7& 组任务
  // 查询组任务
public void test1() {
TaskQuery query = processEngine.getTaskService().createTaskQuery();
// 使用候选人查询组任务
String candidateUser = "财务二";
query.taskCandidateUser(candidateUser);
List&Task& list = query.list();
for (Task task : list) {
System.out.println(task.getId());
// 拾取组任务
public void test2() {
String taskId = "1102";
processEngine.getTaskService().claim(taskId , "财务二");
// 办理组任务, 无需指定办理人
public void test3() throws Exception{
String taskId = "1102";
processEngine.getTaskService().complete(taskId);
  // activiti使用自己的用户与组的权限表, 因此需要设置. 但需注意要与框架外用户/组同步设置
public void test2() {
Group group = new GroupEntity();
group.setId("财务组");
processEngine.getIdentityService().saveGroup(group);
// 创建用户
User user = new UserEntity();
user.setId("2");
processEngine.getIdentityService().saveUser(user);
// 维护用户与组的关系
processEngine.getIdentityService().createMembership("2", "财务组");
// 查询组任务
public void test2() {
TaskQuery query = processEngine.getTaskService().createTaskQuery();
String candidateUser = "2";
// 使用候选人过滤
query.taskCandidateUser(candidateUser);
// 使用组过滤
//query.taskCandidateGroup("财务组");
List&Task& list = query.list();
for (Task task : list) {
System.out.println(task.getId());
// 拾取组任务
public void test3() {
String taskId = "1902";
processEngine.getTaskService().claim(taskId , "2");
// 办理组任务略
2.8 排他网关
设置分支条件
3. 一些使用经验
考虑到工作流中的一个任务, 对应一个业务段, 可以将taskDefinitionKey设置成strus action类的method, 使之具有一定的通用性
两种对流程定义的查询, 后者能获得更多定义的细节信息& processDefinitionEntity.findActivity(taskId) 工作流中某任务的信息
repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult()
(ProcessDefinitionEntity) repositoryService.getProcessDefinition(processDefinitionId)

我要回帖

更多关于 activiti 表单 的文章

 

随机推荐