activiti的建表方式和創建引擎對象


    /*
     * 這裏有三種方式創建表:
     *   第一種:
     *      1.創建一個引擎配置對象。通過對象去讀取 鏈接數據庫的四要素。
     *      2.設置建表的策略  通常使用false
     *      3.通過引擎配置對象類的靜態方法創建引擎對象。
     *      4.系統自動創建表
     *  第二種:
     *      1.第一種方式需要把數據庫四要素都寫在程序中,所以第二種方法就是將他配置到一個配置文件中。
     *        以爲 acitviti 就是以spring 和mybatis等框架開發出的一個成型的完整的系統。所以配置
     *       文件和spring的applictionConfiguration.xml一樣。
     *      2.有了配置文件 我們在構建引擎配置對象的同時就讀取這個配置文件即可。
     *  第三種:
     *      1.不需要創建一個引擎配置對象  直接通過ProcessEngines類直接得到默認的引擎對象。
     *      ps:  通過查看源碼,在引擎初始化的時候會默認去讀取activiti.cfg.xml文件。
     */
    @Test
    public void TestActivitiEngine() {
        //創建一個引擎  配置  對象。
        ProcessEngineConfiguration configuration =
                ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
        //的到數據庫四要素
        configuration.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/oa_database?useUnicode=true&characterEncoding=utf-8");
        configuration.setJdbcDriver("com.mysql.jdbc.Driver");
        configuration.setJdbcUsername("root");
        configuration.setJdbcPassword("*******");
        //設置建表策略
        /*
         * 這個方法提供了三個參數(後兩種都不常用,程序員只需要使用第一種  false 就可以了)
         * ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE:數據庫中沒有表就報錯
         * ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE :數據庫中沒有表就創建,有表就拉到
         * ProcessEngineConfiguration.DB_SCHEMA_UPDATE_CREATE :每次都刪除表創建新表
         * */
        configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE);

        //創建工作流引擎對象。
        /*
         * 這個對象被創建的同時,系統就會創建所有必要的表。
         * */
        ProcessEngine processEngine = configuration.buildProcessEngine();
        System.out.println(processEngine);
    }

    @Test
    public void TestSecondActivitiEngine(){
        ProcessEngineConfiguration configuration = 
                ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
        ProcessEngine processEngine = configuration.buildProcessEngine();
        System.out.println(processEngine);
    }

    @Test
    public void TestThirdActivitiEngine(){
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        System.out.println(processEngine);
    }

activiti.cfg.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
        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-4.2.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd">

    <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
        <property name="jdbcDriver" value="com.mysql.jdbc.Driver"></property>
        <property name="jdbcUrl" value="jdbc:mysql://127.0.0.1:3306/oa_database?useUnicode=true&amp;characterEncoding=utf-8"></property>
        <property name="jdbcUsername" value="root"></property>
        <property name="jdbcPassword" value="*****"></property>
        <property name="databaseSchemaUpdate" value="false"></property>
    </bean>

</beans>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章