OSWorkFlow工作流引擎的使用

java开源的工作流目前风头正劲的当属OSWorkFlow和jbpm,而OSWorkFlow由于其灵活性越来越受到开发者的追捧。使用工作流能很大的简化具有流程化处理的程序逻辑,使得用户集中精力关注于业务的实现。
      OSWorkFlow的重点就在于工作流文件的建立,所以工作流文件的定义和语法就是掌握的重点,推荐满江红站点
http://wiki.redsaga.com 翻译的中文参考文档,基于最新版本,特别详细和到位。
      由于文档中的示例配置较老,这里主要说一下osworkflow在tomcat5.5版本下的配置,基于mysql数据库。其他的知识点就需要自己来学习了。
运行环境:
Tomcat 5.5
MySQL 5.0
OSWorkFlow 2.8
步骤如下:
1、下载并部署osworkflow-2.8.0-example.war
2、下载MySQL的JDBC驱动,拷贝至$TOMCAT_HOME/common/lib/目录下
3、配置Tomcat数据源(注意:tomcat5和tomcat5.5数据源配置是有差异的,此处为5.5的)
     修改$TOMCAT_HOME/conf/server.xml,在</Host>前加上
<Context path="/osworkflow_example" docBase="osworkflow-2.8.0-example"
         debug= "99" reloadable="true" crossContext="true" verbosity="DEBUG">
<Logger className="org.apache.catalina.logger.FileLogger"
        prefix="OSWorkflow." suffix=".log" timestamp="true"/>
<!--jdbc/DefaultDS为数据源的名称,后面许多地方要用到,不要更改-->
<Resource name="jdbc/DefaultDS" auth="Container"
type="javax.sql.DataSource" password="admin"
    driverClassName="com.mysql.jdbc.Driver"
    maxIdle="2"
    maxWait="5000"
    username="root"
    url="jdbc:mysql://localhost:3306/workflow?autoReconnect=true"<!--将此处设置为你的数据库连接-->
    maxActive="4"/>
</Context>
4、修改web应用的/WEB-INF/classes下的osworkflow.xml为
<osworkflow>
<persistence class="com.opensymphony.workflow.spi.jdbc.MySQLWorkflowStore">
<!--此处指定的class似乎只有MySQL需要这样指定,其它数据库均使用JDBCWorkflowStore-->
        <!-- For jdbc persistence, all are required. -->
        <property key="datasource" value="jdbc/DefaultDS"/>
        <property key="entry.sequence"
                      value="SELECT nextVal('seq_os_wfentry')"/>
        <property key="entry.table" value="OS_WFENTRY"/>
        <property key="entry.id" value="ID"/>
        <property key="entry.name" value="NAME"/>
        <property key="entry.state" value="STATE"/>
        <!--
        <property key="step.sequence"
                       value="SELECT nextVal('seq_os_currentsteps')"/>
                       -->
<property key="step.sequence" value="select sum(c1) + 1 from (select 1 as tb, count(*) as c1 from os_currentstep union select 2 as tb, count(*) as c1 from os_historystep) as TabelaFinal" />
        <property key="history.table" value="OS_HISTORYSTEP"/>
        <property key="current.table" value="OS_CURRENTSTEP"/>
        <property key="historyPrev.table" value="OS_HISTORYSTEP_PREV"/>
        <property key="currentPrev.table" value="OS_CURRENTSTEP_PREV"/>
        <property key="step.id" value="ID"/>
        <property key="step.entryId" value="ENTRY_ID"/>
        <property key="step.stepId" value="STEP_ID"/>
        <property key="step.actionId" value="ACTION_ID"/>
        <property key="step.owner" value="OWNER"/>
        <property key="step.caller" value="CALLER"/>
        <property key="step.startDate" value="START_DATE"/>
        <property key="step.finishDate" value="FINISH_DATE"/>
        <property key="step.dueDate" value="DUE_DATE"/>
        <property key="step.status" value="STATUS"/>
        <property key="step.previousId" value="PREVIOUS_ID"/>
        <property key="step.sequence.increment"
    value="INSERT INTO OS_STEPIDS (ID) values (null)"/>
<property key="step.sequence.retrieve"
    value="SELECT max(ID) FROM OS_STEPIDS"/>
<property key="entry.sequence.increment"
    value="INSERT INTO OS_ENTRYIDS (ID) values (null)"/>
<property key="entry.sequence.retrieve"
    value="SELECT max(ID) FROM OS_ENTRYIDS"/>
</persistence>

    <factory class="com.opensymphony.workflow.loader.XMLWorkflowFactory">
        <property key="resource" value="workflows.xml" />
    </factory>
</osworkflow>

5、修改web应用的/WEB-INF/classes下的osuser.xml为
<opensymphony-user>
         <provider class="com.opensymphony.user.provider.jdbc.JDBCAccessProvider">
         <property name="user.table">os_user</property>
         <property name="group.table">os_group</property>
         <property name="membership.table">os_membership</property>
         <property name="user.name" >username</property>
         <property name="user.password">passwordhash</property>
         <property name="group.name">groupname</property>
         <property name="membership.userName" >username</property>
         <property name="membership.groupName">groupname</property>
         <property name="datasource">jdbc/DefaultDS</property>
       </provider>
       <provider class="com.opensymphony.user.provider.jdbc.JDBCCredentialsProvider">
         <property name="user.table">os_user</property>
         <property name="group.table">os_group</property>
         <property name="membership.table">os_membership</property>
         <property name="user.name" >username</property>
         <property name="user.password">passwordhash</property>
         <property name="group.name">groupname</property>
         <property name="membership.userName" >username</property>
         <property name="membership.groupName">groupname</property>
         <property name="datasource">jdbc/DefaultDS</property>
       </provider>
       <provider class="com.opensymphony.user.provider.jdbc.JDBCProfileProvider">
         <property name="user.table">os_user</property>
         <property name="group.table">os_group</property>
         <property name="membership.table">os_membership</property>
         <property name="user.name" >username</property>
         <property name="user.password">passwordhash</property>
         <property name="group.name">groupname</property>
         <property name="membership.userName" >username</property>
         <property name="membership.groupName">groupname</property>
         <property name="datasource">jdbc/DefaultDS</property>
       </provider>
       <authenticator class="com.opensymphony.user.authenticator.SmartAuthenticator" />
     </opensymphony-user>
6、在classes目录下新建propertyset.xml,内容如下
<propertysets>
    <propertyset name="jdbc"
      class="com.opensymphony.module.propertyset.database.JDBCPropertySet">
        <arg name="datasource" value="jdbc/DefaultDS"/>
        <arg name="table.name" value="OS_PROPERTYENTRY"/>
        <arg name="col.globalKey" value="GLOBAL_KEY"/>
        <arg name="col.itemKey" value="ITEM_KEY"/>
        <arg name="col.itemType" value="ITEM_TYPE"/>
        <arg name="col.string" value="STRING_VALUE"/>
        <arg name="col.date" value="DATE_VALUE"/>
        <arg name="col.data" value="DATA_VALUE"/>
        <arg name="col.float" value="FLOAT_VALUE"/>
        <arg name="col.number" value="NUMBER_VALUE"/>
    </propertyset>
</propertysets>
7、在mysql数据库中建立workflow数据库,从下载的包中找到osworkflow2.8\src\etc\deployment\jdbc\mysql.sql,执行该SQL语句

      配置工作完成,启动进行测试吧。这时候tomcat可能会出错,去掉以上各个xml中的中文注释,重新启动应该就没有问题了。

你可能感兴趣的:(工作,mysql,jdbc,workflow,OS)