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

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 String deploymentId;

 

    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 RepositoryService getRepositoryService() {

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

        ProcessEngine processEngine = Configuration.getProcessEngine();

        // 得到一个查询服务

        RepositoryService repositoryService = processEngine.getRepositoryService();

 

        return repositoryService;

    }

 

    public List<ProcessDefinition> getProcessDefinitionList() {

        returnprocessDefinitionList;

    }

 

    publicvoid setDeploymentId(String deploymentId) {

        this.deploymentId = deploymentId;

    }

   

   

}

 struts.xml文件

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC

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

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

<struts>

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

    <constant name="struts.ui.theme" value="simple" />

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

     <constant name="struts.objectFactory" value="spring" />

   

     <package name="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">

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

        </action>

     </package>

 

 

</struts>

 

applicationContext.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: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-scan base-package="com.darren"/>

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

        <property name="locations">

            <list>

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

           </list>

        </property>

    </bean>

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

       <property name="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 -->

       <property name="initialPoolSize" value="1"/>

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

       <property name="minPoolSize" value="1"/> 

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

       <property name="maxPoolSize" value="300"/>

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

       <property name="maxIdleTime" value="60"/>

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

       <property name="acquireIncrement" value="5"/>

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

       <property name="idleConnectionTestPeriod" value="60"/>

    </bean>

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

       <property name="dataSource" ref="dataSource"/>

        <property name="mappingResources">

               <list>

 

               </list>

       </property>

        <property name="hibernateProperties">

            <value>

                 hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

                 hibernate.hbm2ddl.auto=update

                 hibernate.show_sql=true

                 hibernate.format_sql=false

             </value>

        </property>

    </bean>

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

       <property name="sessionFactory" ref="sessionFactory"/>

    </bean>

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

    <tx:annotation-driven transaction-manager="txManager"/>

</beans>

 

hibernate配置部分暂时没有用到

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值