jPBM4.3 -- 第四节 动态发布与删除流程实例

来源:互联网 发布:一句话恐怖故事 知乎 编辑:程序博客网 时间:2024/05/18 00:06

package com.darren.action;

 

import java.util.List;

import org.jbpm.api.Configuration;

import org.jbpm.api.NewDeployment;

import org.jbpm.api.ProcessDefinition;

import org.jbpm.api.ProcessDefinitionQuery;

import org.jbpm.api.ProcessEngine;

import org.jbpm.api.RepositoryService;

import org.springframework.stereotype.Controller;

 

@Controller//控制层

publicclass ProcessAction {

 

    private List<ProcessDefinition>processDefinitionList;

    private StringdeploymentId;

 

    public String deployProcess() {

        //得到一个查询服务

        RepositoryService repositoryService =this.getRepositoryService();

        //获取一个部署对象

        NewDeployment newDeployment = repositoryService.createDeployment();

        //加载流程部署文件并部署发布流程

        newDeployment.addResourceFromClasspath("leave.jpdl.xml").deploy();

 

        return"deploy";

    }

 

    public String deleteProcess() {

        RepositoryService repositoryService =this.getRepositoryService();

        repositoryService.deleteDeploymentCascade(deploymentId);

        return"delete";

    }

 

    public String listDefinitionProcess() {

        RepositoryService repositoryService =this.getRepositoryService();

        ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();

        processDefinitionList = processDefinitionQuery.list();

        return"list";

    }

 

    private RepositoryServicegetRepositoryService() {

        //得到一个流程控制引擎

        ProcessEngine processEngine = Configuration.getProcessEngine();

        //得到一个查询服务

        RepositoryService repositoryService = processEngine.getRepositoryService();

 

        return repositoryService;

    }

 

    public List<ProcessDefinition> getProcessDefinitionList() {

        returnprocessDefinitionList;

    }

 

    publicvoid setDeploymentId(String deploymentId) {

        this.deploymentId = deploymentId;

    }

   

   

}

 struts.xml文件

<?xmlversion="1.0"encoding="UTF-8"?>

<!DOCTYPEstruts PUBLIC

    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

<!-- 默认的视图主题 -->

    <constantname="struts.ui.theme"value="simple"/>

<!-- 使用spring工厂类去替换struts默认的工厂类 Actionspring进行创建和维护,而不再由struts进行管理-->

     <constantname="struts.objectFactory"value="spring"/>

   

     <packagename="process" extends="struts-default">

        <action name="deployProcess"class="processAction"method="deployProcess">

           <result name="deploy"type="redirect">listDefinitionProcess</result>

        </action>

       

        <action name="deleteProcess"class="processAction"method="deleteProcess">

           <result name="delete"type="redirect">listDefinitionProcess</result>

        </action>

       

        <action name="listDefinitionProcess"class="processAction"method="listDefinitionProcess">

            <resultname="list">/WEB-INF/pages/index.jsp</result>

        </action>

     </package>

 

 

</struts>

 

applicationContext.xml文件

 

<?xmlversion="1.0"encoding="UTF-8"?>

<beansxmlns="http://www.springframework.org/schema/beans"

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xmlns:context="http://www.springframework.org/schema/context"

       xmlns:aop="http://www.springframework.org/schema/aop"

       xmlns:tx="http://www.springframework.org/schema/tx"

       xsi:schemaLocation="http://www.springframework.org/schema/beans

           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd

           http://www.springframework.org/schema/context

           http://www.springframework.org/schema/context/spring-context-2.5.xsd

           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd

           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

      

    <!--开启注解方式使用IOC -->   

    <context:annotation-config/>

    <context:component-scanbase-package="com.darren"/>

    <beanid="propertyConfigurer"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"lazy-init="false">

        <propertyname="locations">

            <list>

                <value>classpath:database.properties</value>

           </list>

        </property>

    </bean>

    <beanid="dataSource"class="com.mchange.v2.c3p0.ComboPooledDataSource"destroy-method="close">

       <propertyname="driverClass">

            <value>${jdbc.driverClass}</value>

        </property>

        <property name="jdbcUrl">

           <value>${jdbc.url}</value>

        </property>

        <property name="user">

        <value>${jdbc.uesrName}</value>

        </property>

        <property name="password">

        <value>${jdbc.passWord}</value>

        </property>

       

       <!--初始化时获取的连接数,取值应在minPoolSizemaxPoolSize之间。Default: 3 -->

       <propertyname="initialPoolSize"value="1"/>

       <!--连接池中保留的最小连接数。-->

       <propertyname="minPoolSize"value="1"/> 

       <!--连接池中保留的最大连接数。Default: 15 -->

       <propertyname="maxPoolSize"value="300"/>

       <!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->

       <propertyname="maxIdleTime"value="60"/>

       <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->

       <propertyname="acquireIncrement"value="5"/>

       <!--60秒检查所有连接池中的空闲连接。Default: 0 -->

       <propertyname="idleConnectionTestPeriod"value="60"/>

    </bean>

    <beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

       <propertyname="dataSource"ref="dataSource"/>

        <propertyname="mappingResources">

               <list>

 

               </list>

       </property>

        <propertyname="hibernateProperties">

            <value>

                 hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

                 hibernate.hbm2ddl.auto=update

                 hibernate.show_sql=true

                 hibernate.format_sql=false

             </value>

        </property>

    </bean>

    <beanid="txManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager">

       <propertyname="sessionFactory"ref="sessionFactory"/>

    </bean>

    <!--使用基于注解方式配置事务 -->

    <tx:annotation-driventransaction-manager="txManager"/>

</beans>

 

hibernate配置部分暂时没有用到

原创粉丝点击