osworkflow与spring的集成

osworkflow与spring的集成方法,在《OSWorkflow开发指南.pdf》中有描述,但那篇文章中没有代码,这里贴出我自己集成的代码和配置:

1.新的WorkflowStore

package com.opensymphony.workflow.spi.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Properties;

import javax.sql.DataSource;

import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.jdbc.support.JdbcUtils;

import com.opensymphony.module.propertyset.PropertySet;
import com.opensymphony.module.propertyset.PropertySetManager;
import com.opensymphony.workflow.StoreException;

public class SpringJDBCWorkflowStore extends JDBCWorkflowStore {
	
    public void setDataSource(DataSource dataSource){  
        this.ds = dataSource;  
    }  
      
    public void setJdbcProperties(Properties ps) throws StoreException {
    	init(ps);
    }
    
    @Override  
    protected Connection getConnection() throws SQLException {  
        return DataSourceUtils.getConnection(this.ds);  
    }  
      
    @Override  
    protected void cleanup(Connection connection, Statement statement, ResultSet result) {  
        JdbcUtils.closeStatement(statement);  
        JdbcUtils.closeResultSet(result);  
        DataSourceUtils.releaseConnection(connection, this.ds);  
          
    }

	@Override
	public PropertySet getPropertySet(long entryId) {
		HashMap args = new HashMap();
        args.put("globalKey", "osff_" + entryId);
        args.put("dataSource", ds);

        return PropertySetManager.getInstance("spring", args);
	}  
      
	
	
}


2.新的PropertySet

package com.opensymphony.module.propertyset.database;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Map;

import javax.sql.DataSource;

import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.jdbc.support.JdbcUtils;

public class SpringJDBCPropertySet extends JDBCPropertySet {

	@Override
	public void init(Map config, Map args) {
		super.init(config, args);
		this.ds = (DataSource) args.get("dataSource");
	}

    @Override  
    protected Connection getConnection() throws SQLException {  
        return DataSourceUtils.getConnection(this.ds);  
    }  
      
    @Override  
    protected void cleanup(Connection connection, Statement statement, ResultSet result) {  
        JdbcUtils.closeStatement(statement);  
        JdbcUtils.closeResultSet(result);  
        DataSourceUtils.releaseConnection(connection, this.ds);  
          
    }

}

3.增加spring配置:

	<bean id="jdbcTemplateWorkflowStore"
		class="com.opensymphony.workflow.spi.jdbc.SpringJDBCWorkflowStore">
		<property name="jdbcProperties">
			<props>
				<prop key="entry.sequence">select IFNULL(max(id)+1,1) from os_wfentry</prop>
				<prop key="step.sequence">select IFNULL(GREATEST((select max(id) from os_currentstep),(select max(id) from os_historystep))+1,1)</prop>
			</props>
		</property>
	</bean>

	<bean id="workflowFactory"
		class="com.opensymphony.workflow.spi.hibernate.SpringWorkflowFactory"
		init-method="init">
		<property name="resource">
			<value>workflows.xml</value>
		</property>
		<property name="reload">
			<value>true</value>
		</property>
	</bean>
	
	<bean id="osworkflowConfiguration" class="com.opensymphony.workflow.config.SpringConfiguration">
		<property name="store">
			<ref local="jdbcTemplateWorkflowStore" />
		</property>
		<property name="factory">
			<ref local="workflowFactory" />
		</property>
	</bean>
这里用了自动注入


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值