osworkflow+spring+jdbc实现
最近研究osworkflow, 觉得这个工作流框架很轻便灵活,但是只有osworkflow+spring+hibernate的实现,我在想,如果一个大型的工作流系统,数据非常多,岂不是不能用hibernate了?,于是我就照着Hibernate的实现做了一个 Jdbc的的spring实现,反正jdbc可以解决任何数据优化问题,
package com.opensymphony.workflow.spi.jdbc; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import javax.sql.DataSource; import org.springframework.beans.factory.InitializingBean; import org.springframework.jdbc.datasource.DataSourceUtils; import org.springframework.jdbc.support.JdbcUtils; public class SpringJDBCWorkflowStore extends JDBCWorkflowStore implements InitializingBean { @Override public void afterPropertiesSet() throws Exception { entryTable = "OS_WFENTRY"; entryId = "ID"; entryName = "NAME"; entryState = "STATE"; historyTable = "OS_HISTORYSTEP"; currentTable = "OS_CURRENTSTEP"; currentPrevTable = "OS_CURRENTSTEP_PREV"; historyPrevTable = "OS_HISTORYSTEP_PREV"; stepId = "ID"; stepEntryId = "ENTRY_ID"; stepStepId = "STEP_ID"; stepActionId = "ACTION_ID"; stepOwner = "OWNER"; stepCaller = "CALLER"; stepStartDate = "START_DATE"; stepFinishDate = "FINISH_DATE"; stepDueDate = "DUE_DATE"; stepStatus = "STATUS"; stepPreviousId = "PREVIOUS_ID"; } public void setDataSource(DataSource dataSource){ this.ds = dataSource; } public DataSource getDataSource(){ return this.ds; } @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); } public void setEntrySequence(String entrySequence){ this.entrySequence = entrySequence; } public void setStepSequence(String stepSequence){ this.stepSequence = stepSequence; } }
数据库的连接是基于JdbcTemplate的,好处就是可以很方便的和spring的事务框架整合(备注:如果想要用spring的事务管理,必须使用JdbcTemplate,原因是Spring的事务管理的数据库连接是从ConnHolder中取的,JdbcTemplate的数据库连接也是从ConnHolder中取的),这样使得osworkflow带入事务管理特性
Spring配置文件
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <description>数据源spring配置</description> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" singleton="true" lazy-init="default" autowire="default" dependency-check="default"> <property name="driverClassName"> <value>com.mysql.jdbc.Driver</value> </property> <property name="url"> <value>jdbc:mysql://localhost:3306/test?autoReconnect=true</value> </property> <property name="username"> <value>root</value> </property> <property name="password"> <value>123</value> </property> </bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <bean id="workflowStore" class="com.opensymphony.workflow.spi.jdbc.SpringJDBCWorkflowStore"> <property name="dataSource" ref="dataSource"></property> <property name="entrySequence"> <value>select count(*) + 1 from os_wfentry</value> </property> <property name="stepSequence"> <value>select sum(c1) + 1 from (select 1 as tb, count(id) as c1 from os_currentstep union select 2 as tb, count(id) as c1 from os_historystep) as TabelaFinal</value> </property> </bean> <bean id="workflowTypeResolver" class="com.opensymphony.workflow.util.SpringTypeResolver"/> <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>false</value></property> </bean> <bean id="osworkflowConfiguration" class="com.opensymphony.workflow.config.SpringConfiguration"> <property name="store"><ref local="workflowStore"/></property> <property name="factory"><ref local="workflowFactory"/></property> </bean> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager"><ref local="transactionManager"/></property> <property name="transactionAttributes"> <props> <prop key="*">PROPAGATION_REQUIRED,-Exception</prop> </props> </property> </bean> <bean id="workflow" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="singleton"> <value>false</value> </property> <property name="proxyInterfaces"> <value>com.opensymphony.workflow.Workflow</value> </property> <property name="interceptorNames"> <list> <value>transactionInterceptor</value> </list> </property> <property name="target" ref="workflowTarget"></property> </bean> <bean id="workflowTarget" class="com.opensymphony.workflow.basic.BasicWorkflow" singleton="false"> <property name="configuration"><ref local="osworkflowConfiguration"/></property> <constructor-arg> <value>test2</value> </constructor-arg> </bean> </beans>
相关推荐
白净垃圾桶 2020-07-04
HappyHeng 2020-06-25
ASoc 2020-11-14
Andrea0 2020-09-18
Cherishyuu 2020-08-19
dongtiandeyu 2020-08-18
CoderYYN 2020-08-16
大黑牛 2020-08-15
Dullonjiang 2020-08-11
gaozhennan 2020-08-03
mcvsyy 2020-08-02
zbcaicai 2020-07-29
AscaryBird 2020-07-27
liulin0 2020-07-26
ldcwang 2020-07-26
helloxusir 2020-07-25
娜娜 2020-07-20
pengpengflyjhp 2020-07-19
点滴技术生活 2020-07-19