Activiti环境配置说明
===========================

本部分介绍了使用Activiti时需要的环境配置操作。

本部分包含以下章节：

- 数据库连接配置_
- 建表文件_

数据库连接配置
--------------

Activiti的配置信息可以通过配置文件配置，也可以直接在代码中进行配置，以下是两种方式的举例。

a. Activiti使用配置文件配置连接信息，创建工作流需要的表。

   在activiti.cfg.xml 中增加如下声明：

   （KingbaseES形态）

   .. code:: PROGRAMLISTING

      <bean id="processEngineConfiguration"
              class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
              <property name="jdbcDriver" value="com.kingbase8.Driver"></property>
              <property name="jdbcUrl" value="jdbc:kingbase8://localhost:54321/test"
                  ></property>
              <property name="jdbcUsername" value="test"></property>
              <property name="jdbcPassword" value="test"></property>
              <property name="databaseType" value="postgres"></property>
              <!-- 没有表创建表 -->
              <property name="databaseSchemaUpdate" value="true"></property>
          </bean>

   （Postgre形态）

   .. code:: 

      <bean id="processEngineConfiguration"
              class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
              <property name="jdbcDriver" value="org.postgresql.Driver"></property>
              <property name="jdbcUrl" value="jdbc:postgresql://localhost:54321/test"
                  ></property>
              <property name="jdbcUsername" value="test"></property>
              <property name="jdbcPassword" value="test"></property>
              <property name="databaseType" value="postgres"></property>
              <!-- 没有表创建表 -->
              <property name="databaseSchemaUpdate" value="true"></property>
          </bean>

   配置时根据实际情况修改 "jdbcDriver" 、"jdbcUrl" 、"databaseType"即可。 

b. Activiti使用代码配置连接信息，创建工作流需要的表。

   .. code:: PROGRAMLISTING

          @Test
          public void createTable(){
              ProcessEngineConfiguration processEngineConfiguration = 
                  ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
              processEngineConfiguration.setJdbcDriver("org.postgresql.Driver");
              processEngineConfiguration.setJdbcUrl(
                  "jdbc:postgresql://localhost:54321/test");
              processEngineConfiguration.setJdbcUsername("test");
              processEngineConfiguration.setJdbcPassword("test");
              processEngineConfiguration.setDatabaseType("postgres");
              
              processEngineConfiguration.setDatabaseSchemaUpdate(
                  ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
              ProcessEngine processEngine = 
                  processEngineConfiguration.buildProcessEngine();
          }

   配置时根据实际情况修改以下参数：

   1. processEngineConfiguration.setJdbcDriver
   2. processEngineConfiguration.setJdbcUrl
   3. processEngineConfiguration.setDatabaseType

您还可以前往电科金仓官网 下载 `Activiti测试用例 <https://kingbase.oss-cn-beijing.aliyuncs.com/KES_INTERFACE/testyongli/activiti/ActivitiTest.zip>`_ 。

建表文件
--------

KingbaseES兼容Activiti的核心，使用的是PG的建表语句。详细请参考：`Getting Started with Activiti Core Runtime APIs <https://activiti.gitboot.io/activiti-7-developers-guide/getting-started/getting-started-activiti-core>`_ 。