Activiti workflow learning ----- Based on version 5.19.0 (1) and activiti5.19.0

Source: Internet
Author: User

Activiti workflow learning ----- Based on version 5.19.0 (1) and activiti5.19.0

Note:

1. JDK 6 +, preferably Kepler or later in Eclipse.

2. All test functions are availableEXPERIMENTALAnnotation, the labeled part should not be regarded as stable.

If you are interested, you can go to the Activiti Explorer project, which covers most of the Activiti functions. If you do not have the Activiti concept, take a look.

I. workflow development Configuration

Activiti follows the Spring configuration file style. By default, the workflow is namedActiviti. cfg. xmlConfiguration file:

<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="jdbcUrl" value="jdbc:h2:mem:activiti;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="asyncExecutorEnabled" value="true" />    <property name="asyncExecutorActivate" value="false" />    <property name="mailServerHost" value="mail.my-corp.com" />    <property name="mailServerPort" value="5025" />  </bean></beans>

We can write the configuration file and hand it over to activiti for loading in the following ways:

ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault();ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(String resource);ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(String resource, String beanName);ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(InputStream inputStream);ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(InputStream inputStream, String beanName);

If you like zero configuration, you can:

ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration();

For example, the second method is used for Zero Configuration:

1 ProcessEngine processEngine = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration()2   .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)3   .setJdbcUrl("jdbc:h2:mem:my-own-db;DB_CLOSE_DELAY=1000")4   .setAsyncExecutorEnabled(true)5   .setAsyncExecutorActivate(false)6   .buildProcessEngine();

However, I personally think that if all trivial configurations are handed over to the Code for maintenance, it will be too laborious! Besides, it is not safe to give it to programmers with low levels of code. So let's leave it to xml. It's useless without any configuration.

1.1 activiti. cfg. xml file configuration

activiti.cfg.xmlMust contain id =Bean node of processEngineConfiguration, for example:

<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
ProcessEngineConfiguration is usually used to constructProcessEngine and activiti provide the following four classes to defineprocessEngineConfiguration:
  • Org. activiti. engine. impl. cfg. StandaloneProcessEngineConfiguration: Obtain the process engine object in an independent way. Activiti manages transactions by itself. Generally, the database is only detected when the system is started.

  • Org. activiti. engine. impl. cfg. StandaloneInMemProcessEngineConfiguration: It is mainly used for testing. Activiti manages transactions by itself. The H2 database is used by default, and the database tables are destroyed when they are created and disabled at startup. So there is not much configuration.

  • Org. activiti. spring. SpringProcessEngineConfiguration: It is used for integration with Spring.

  • Org. activiti. engine. impl. cfg. JtaProcessEngineConfiguration: In standalone mode, distributed transactions can be used. (I am not sure)

1.1.1 database connection Configuration

Currently, two types of database connections are available: MyBatis default database connection configuration and mainstream database connection pools. I recommend the latter because the former's official instructions have already stated that we recommend that you do not use the default database connection settings in production.

The configuration of the former is as follows: (simple pass)

<property name="jdbcUrl" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" /><property name="jdbcDriver" value="org.h2.Driver" /><property name="jdbcUsername" value="sa" /><property name="jdbcPassword" value="" />

Solution 2: UseJavax. SQL. DataSource, such as DBCP, C3P0, And Druid

<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><bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">    <property name="dataSource" ref="dataSource" />    ...

The Activiti workflow does not provide a Jar package for the database connection pool. We need to manually download the package to the class path.

Regardless of the database connection scheme, other configurations of some databases need to be noted:

DatabaseType:Generally, no data elements are automatically analyzed in the workflow. The configuration is read only after the automatic analysis fails. Currently, the supported databases include h2, mysql, oracle, S, mssql, and db2.

DatabaseSchemaUpdate:

1.1.2 create a workflow-related table

Add the activiti jar package under the class path, the database connection jar, and addActiviti. cfg. xml,Then runDbSchemaCreateYou can..

In production, developers often do not have database administrator permissions. Therefore, SQL is provided to relevant personnel in activiti jar. These tables are generally divided into three categories:

  • Engine: This is required.
  • Identity: user management table provided by activiti.
  • History: Process history Table

When running SQL statements on MySQL, note that if the version is 5.5 ~ For MySQL 5.6.3, use SQL 5.5 or upgrade database 5.6.4 + because the precision of timestamps or date in MySQL versions earlier than 5.6.4 is not milliseconds, if this type of column is created in the workflow, an exception is thrown.

1.1.3 introduction to workflow-related tables Workflow-related tables all start with "ACT _", followed by a short description of the service provided by activiti, such:
  • ACT_RE _*:RERepresentativerepository. Contains process definitions and process resources.

  • ACT_RU _*:RURepresentativeruntime. These tables contain process running instances, tasks, variables, and assignments. These tables only store running data and are cleared after the execution of the Process instance. In this way, the table contains less data, it makes the program run fast.

  • ACT_ID _*:IDRepresentativeidentity. These tables contain user information data, such as user personal information and group information.

  • ACT_HI _*:HIRepresentativehistory. These tables contain historical data, such as previous process instances, variables, and tasks.

  • ACT_GE _*: A common data table used to store various types of data.

 

 

 

 

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.