Activiti Study Notes
Activiti isOpen-sourceWorkflow engine. The homepage is at http://www.activiti.org/. to download downloading, you can click it directly. The downloaded files include document, tutorial, all required jar packages, and some demos. The latest version is activit-5.9
The project leader of this project is the famous Tom Baeyens. It is said that he used to do jbpm. When jbpm4 was achieved, he left JBoss and went to alfresco, the activiti R & D team was set up. To some extent, it can be said that activiti is the real jbpm5, and now the so-called jbpm5 almost gave up all jbpm4 code and started from the beginning, is the previous drool flow.
After the downloaded ZIP file is decompressed, the first thing is to check the documentfile. There is a readme.html file.
Let's see, he will tell you how to run its demo, that is, to run ant demo. Start in the setup directory. Some problems occurred while I was running. Run demo. Start to do the following:
1. will be automatically createdH2 Database, Create a table, and import data
2. automatically downloadSuitable version of Tomcat, The specific configuration information is in the setup directoryBuild. PropertiesAnd build. DB. properties to view
3. automatically release the project activiti-explorer and activiti-rest to the Tomcat
4. Open your browser and access activiti-explorer.
Too stupid and too automated.
If you already have a good Tomcat and do not want to download it, it is also simple, as long as you press
In the configuration in build. properties, add your tomcat to the command above to generate the downloads directory, and modify the appropriate tomcat version number.
If there is no accident, you can finish the step by step. You have already seen the logon interface of activiti-Explorer. This demo shows the default logon user document, for example, the Administrator Kermit/Kermit, log on and play. After logging on, you can see tasks, processes, databases, and databases as administrators. You can view the data in the database. The data is stored in H2. If you are interested, you can study this H2 database. You only need a jar package and an embedded package.
Click "process" to view some released Process demos. A startprocess button is displayed in the upper-right corner to start a process. After the process is started, you need to complete it. If the current logon user can perform this task after the process is started, the current user will receive an inbox task and open the task, inbox is available. If a task is assigned to a group during the process definition, it means that all the members of the group can complete the task. If the current user wants to do this, claim it.
There is a lot of nonsense. Take a good look at document, tutorial!
In actual project application, we will not store the data above H2, such as Oracle and MySQL. Now let's talk about MySQL. It is also very easy. First, create a database in your MySQL, for example, activiti. You do not need to create a table, as long as the database is empty.
Create a Java project in eclipse and import the jar package listed in {activiti} \ Setup \ files \ dependencies \ libs.engine.runtime.txt. In addition, add a MySQL driver package. cfg. for xml configuration, the commons-DBCP and commons-pool packages need to be used here.
Create an activiti. cfg. xml file in the source file directory of the project. The content is as follows:
<?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="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="root" /> <property name="password" value="leonsu" /> <property name="defaultAutoCommit" value="false" /></bean><bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"><property name="databaseSchemaUpdate" value="true"/><!--<property name="jdbcUrl" value="jdbc:h2:tcp://localhost/activiti" /><property name="jdbcDriver" value="org.h2.Driver" /><property name="jdbcUsername" value="sa" /><property name="jdbcPassword" value="" />--><property name="dataSource" ref="dataSource" /><property name="jobExecutorActivate" value="true" /></bean></beans>
Now run the activiti-engine-5.x.jar package org. activiti. Engine. impl. DB. dbschemacreate this class, the source code, the activiti-engine-5.x-sources.jar package is the corresponding source code, dbschemacreate source code:
/* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.activiti.engine.impl.db;import org.activiti.engine.ProcessEngineConfiguration;import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;import org.activiti.engine.impl.util.LogUtil;/** * @author Tom Baeyens */public class DbSchemaCreate { static { LogUtil.readJavaUtilLoggingConfigFromClasspath(); } public static void main(String[] args) { ProcessEngineConfiguration .createProcessEngineConfigurationFromResourceDefault() .setDatabaseSchemaUpdate(ProcessEngineConfigurationImpl.DB_SCHEMA_UPDATE_CREATE) .buildProcessEngine(); }}
The code here is written by Tom.
Run its main method to automatically create a database, which is very simple.
As for how it interacts with the database in the background, go to the source code for detailed code. Here mybatis is used as the ORM layer framework.
In addition, there are SQL files under org. activiti. DB. Create. You may feel this troublesome and want to run these SQL statements on your own. However, creating the above Java project is very useful, and the following learning is useful.
These SQL files run only the table structure and are empty tables.
If you want to import data, such as connecting to MySQL and running activiti-Explorer without connecting H2, you can go to {activiti} \ Setup \ build \ demo \ h2.data. run the SQL file.
Then, you need to modify the connection between activiti-explorer and activiti-rest databases under tomcat/webapp/, change it to MySQL, and import necessary jar packages, such as the MySQL driver package.
Restart tomcat to switch the database to MySQL to run the demo.
The following is the core: learning the activiti workflow engine API.
About the configuration file configuration, about the processengine class, about the process definition syntax rules, about how to release a process to the engine, how to start a process, how to obtain a work list, and so on...
In fact, the core is processengine, which generates various services to complete the above work.