osworkflow与spring的集成

丁曦
2023-12-01

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>
这里用了自动注入


 类似资料: