Activiti Basic Tutorial--01 (Introduction, 25 Tables of code generation Activiti, activiti configuration file Activiti.cfg.xml generate 25 tables, install Activiti plug-ins on eclipse)

Source: Internet
Author: User


First, Introduction





The Activiti project is a new, Apache-based, open-source BPM platform built from the ground up to provide technical implementations that support the new BPMN 2.0 standard, including the Support object Management Group (OMG), and the opportunity to face new technologies such as interoperability and cloud architecture.



Founder Tom Baeyens, a project architect for JBoss JBPM, and another architect Joram Barrez, joined in the development of the BPMN 2.0 engine that created alfresco, the first open-source license for Apache.



Activiti is an open source project brand that operates and operates independently and operates independently of the alfresco open source ECM system. Activiti will be a lightweight, embeddable BPM engine that is also designed for scalable cloud architectures. Activiti will provide a loose Apache License 2.0 so that the project can be widely used while promoting the Activiti BPM engine and the BPMN 2.0 match, which is now being validated by the OMG through the standard. Joining the Alfresco Activiti project is the SpringSource branch of VMware, and alfresco plans to submit the project to the Apache infrastructure in the hope of attracting more BPM experts and promoting BPM innovation.





Activiti Official homepage: http://www.activiti.org/index.html
Activiti Download: http://www.activiti.org/download.html
User Guide English: http://activiti.org/userguide/index.html (we use the User Guide to learn Activiti)
Online API Documentation: http://activiti.org/javadocs/index.html (to be used when we develop it)
Second, the code Activiti 25 Sheets
Activiti operation Support, must have a activiti of 25 tables, mainly in the process of running, records store some of the user body involved in the process,
Groups, as well as the storage of process definitions, some information about the process execution time, and the historical information of the process, etc. (we will describe these tables in detail later)

We first write a small example, to the Activiti of the 25 tables automatically generated;
We'll build a MAVEN project first ActivitiDemo1
Pom.xml plus Activiti support, as well as MySQL driver package.




<dependencies>
     <dependency>
        <groupId>org.activiti</groupId>
        <artifactId>activiti-engine</artifactId>
        <version>5.19.0.2</version>
    </dependency>
     
    <dependency>
        <groupId>org.activiti</groupId>
        <artifactId>activiti-spring</artifactId>
        <version>5.19.0.2</version>
    </dependency>
     
    <dependency>
        <groupId>org.activiti</groupId>
        <artifactId>activiti-bpmn-model</artifactId>
        <version>5.19.0.2</version>
    </dependency>
     
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.38</version>
    </dependency>
     
</dependencies>





Then we create a unit test class ActivitiTest01 (note that sometimes with your own junit jar package, there is a weird problem, so we recommend the JUnit jar package that comes with the eclipse plugin)



The project structure after creation is as follows:






Then we write a test method, testcreatetable, and create the Db_activiti database;
We need to get the process engine configuration, then configure the process engine, to configure the driver package, URL, database user name, password, and also to set the schema, where the schema is set to update. This can be automatically updated and configured to get the process engine through configuration. When we create an instance, we can automatically generate the 25 tables we need.
package com.java1234.activiti.test;
 
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.junit.Test;
 
public class ActivitiTest01 {
 
     / **
      * Generate 25 Activiti tables
      * /
     @Test
     public void testCreateTable () {
         // Engine configuration
         ProcessEngineConfiguration pec = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration ();
         pec.setJdbcDriver ("com.mysql.jdbc.Driver");
         pec.setJdbcUrl ("jdbc: mysql: // localhost: 3306 / db_activiti");
         pec.setJdbcUsername ("root");
         pec.setJdbcPassword ("123456");
         
         / **
          * false cannot automatically create tables
          * create-drop first delete the table and then create the table
          * true automatically create and update tables
          * /
         pec.setDatabaseSchemaUpdate (ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
         
         // Get the process engine object
         ProcessEngine processEngine = pec.buildProcessEngine ();
     }
 
}
We run the test class and after we run our database refresh we can see 25 tables:


act_re_*: ' RE ' represents repository. The table for this prefix contains the process definition and process static resources (pictures, rules, etc.).
act_ru_*: ' RU ' indicates runtime. These run-time tables contain process instances, tasks, variables, asynchronous tasks, and other running data. Activiti only saves this data during the process instance execution and deletes the records at the end of the process. This way the run-time table can always be very small and fast.
act_id_*: ' ID ' denotes identity. These tables contain identity information, such as users, groups, and so on.
act_hi_*: ' HI ' means history. These tables contain historical data, such as historical process instances, variables, tasks, and so on.
act_ge_*: ' GE ' represents general. Common data for different scenarios, such as storing resource files.
These table structures, as well as some auxiliary tables. Our follow-up will explain in detail, here everybody first general understanding can;


iii. activiti configuration file Activiti.cfg.xml generate 25 Tables


Before we implemented the code to generate 25 Activiti tables, today we use the Activiti.cfg.xml configuration file provided by Activiti to simplify the implementation of the previous functionality
Official document reference address: Http://activiti.org/userguide/index.html#configuration

Let's first create an XML file under Src/test/resources The name is: Activiti.cfg.xml, then we'll post the reference XML code from the official document:





<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>
Here, we're going to modify Jdbcurl jdbcdriver Jdbcusername Jdbcpassword according to our project. We can remove some of the things that are later dropped to these configurations, and the following XML is modified:
<?xml version="1.0" encoding="UTF-8"?>
<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:mysql://localhost:3306/db_activiti" />
    <property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
    <property name="jdbcUsername" value="root" />
    <property name="jdbcPassword" value="123456" />
 
    <property name="databaseSchemaUpdate" value="true" />
 
  </bean>
 
</beans>
Next we are going to read the configuration file through the code, and then get the workflow engine instance (the first time the Db_activiti data is removed from the previous table):
/ **
  * Use xml configuration
  * /
@Test
public void testCreateTableWithXml () {
     // Engine configuration
     ProcessEngineConfiguration pec = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource ("activiti.cfg.xml");
     // Get the process engine object
     ProcessEngine processEngine = pec.buildProcessEngine ();
} 
Then run the test class above and we'll find that the table is automatically generated:





The table is still the previous 25 tables; we'll find that using XML configuration simplifies a lot of things.


Iv. Installing the Activiti plugin on Eclipse





Here we are in our eclipse to install this roaring plugin:



First open eclipse (EE version, preferably with a new version, Maven what all support, do not have an antique)



Then click Help, Install new software




Then click Add









We write on the name Activiti BPMN 2.0 Designer



http://activiti.org/designer/update/on location (plugin update address)



Then click the OK button




Tick Next, then next:






Continue Next






Click Accept, then Finish



In the middle may be some safety tips, click OK;









Here we click Yes, restart Eclipse, it will take effect;



To verify that we successfully installed the plugin, we clicked file--New, Others






If we see this, the instructions have been installed successfully. We'll talk about how to use this stuff in the back.


Here we have a place to set down, click the Window-> Preferences








Here I'll explain in general. When you learn later, you create a chart, and you generate a picture. Let's tick here.



When you save the chart, create a picture. We must configure this when we develop it; (you'll see later, set it up first)






OK to here, the plugin has been installed and setup is complete.




Activiti Basic Tutorial--01 (Introduction, 25 Tables of code generation Activiti, activiti configuration file Activiti.cfg.xml generate 25 tables, install Activiti plug-ins on eclipse)


Related Article

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.