spring2.5整合osworkflow2.8 .

这里是spring2.5 用spring jdbc template的方式整合osworkflow2.8,数据库是mysql的。整合过后,由spring来管理osworkflow的配置类,由于是用spring jdbc才操作osworkflow的数据库,所以datasource可以纳入spring统一控制。

 

 

下面是spring整合osworkflow的配置文件:

 

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!-- 使用aop/tx命名空间 -->  
  3. <beans xmlns="http://www.springframework.org/schema/beans"  
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  5.     xmlns:aop="http://www.springframework.org/schema/aop"  
  6.     xmlns:tx="http://www.springframework.org/schema/tx"  
  7.     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
  8.         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd  
  9.         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">  
  10.       
  11.     <description>spring JDBCTemplate 方式</description>  
  12.     <!-- 专门为mysql数据库定制的一个bean,让工作流程实例(如果需要的话)分享当前事务 -->  
  13.     <bean id="mysqlTemplateWorkflowStore"  
  14.         class="com.opensymphony.workflow.spi.jdbc.MySQLTemplateWorkflowStore"  
  15.         scope="prototype">  
  16.         <property name="dataSource">  
  17.             <ref bean="dataSource" />  
  18.         </property>  
  19.         <property name="propertySetDelegate">  
  20.             <ref bean="propertySetDelegate" />  
  21.         </property>  
  22.         <property name="jdbcTemplateProperties">  
  23.             <props>  
  24.                 <prop key="history.table">OS_HISTORYSTEP</prop>  
  25.                 <prop key="historyPrev.table">OS_HISTORYSTEP_PREV</prop>  
  26.                 <prop key="current.table">OS_CURRENTSTEP</prop>  
  27.                 <prop key="currentPrev.table">OS_CURRENTSTEP_PREV</prop>  
  28.                 <prop key="step.id">ID</prop>  
  29.                 <prop key="step.entryId">ENTRY_ID</prop>  
  30.                 <prop key="step.stepId">STEP_ID</prop>  
  31.                 <prop key="step.actionId">ACTION_ID</prop>  
  32.                 <prop key="step.owner">OWNER</prop>  
  33.                 <prop key="step.caller">CALLER</prop>  
  34.                 <prop key="step.startDate">START_DATE</prop>  
  35.                 <prop key="step.finishDate">FINISH_DATE</prop>  
  36.                 <prop key="step.dueDate">DUE_DATE</prop>  
  37.                 <prop key="step.status">STATUS</prop>  
  38.                 <prop key="step.previousId">PREVIOUS_ID</prop>  
  39.                 <prop key="step.sequence">SELECT max(ID)+1 FROM OS_STEPIDS</prop>  
  40.                 <prop key="entry.sequence">SELECT max(ID)+1 FROM OS_WFENTRY</prop>  
  41.                 <prop key="entry.table">OS_WFENTRY</prop>  
  42.                 <prop key="entry.id">ID</prop>  
  43.                 <prop key="entry.name">NAME</prop>  
  44.                 <prop key="entry.state">STATE</prop>  
  45.                   
  46.                 <!-- mysql 特有的 -->  
  47.                 <prop key="step.sequence.increment">INSERT INTO OS_STEPIDS (ID) values (null)</prop>  
  48.                 <prop key="step.sequence.retrieve">SELECT max(ID) FROM OS_STEPIDS</prop>  
  49.                 <prop key="entry.sequence.increment">INSERT INTO OS_ENTRYIDS (ID) values (null)</prop>  
  50.                 <prop key="entry.sequence.retrieve">SELECT max(ID) FROM OS_ENTRYIDS</prop>  
  51.             </props>  
  52.         </property>  
  53.     </bean>  
  54.     <!-- OSWorkflow的核心功能之一就是动态保存变量,这允许函数从workflow声明周期的一开始就运行还能保存一些数据到OSWorkflow中  
  55.                  因此,后继的action执行的时候,可以取出这些数据,在其他函数中使用。  
  56.                  这是非常强力的功能,使用得当的话可以做出高度定制的,具有长生命周期的工作流行为,就算服务器重启也可以持续  
  57.                        这都归功于PropertySet模块 -->  
  58.     <bean id="propertySetDelegate"  
  59.         class="com.opensymphony.workflow.spi.jdbc.DefaultJDBCTemplatePropertySetDelegate"  
  60.         scope="prototype">  
  61.         <property name="configurationProvider">  
  62.             <ref bean="defaultJDBCTemplateConfigurationProvider"/>  
  63.         </property>  
  64.     </bean>  
  65.       
  66.       
  67.     <bean id="defaultJDBCTemplateConfigurationProvider"  
  68.         class="com.opensymphony.module.propertyset.database.DefaultJDBCTemplateConfigurationProvider"  
  69.         scope="prototype">  
  70.         <property name="propertySetDAO">  
  71.             <ref bean="jdbcTemplatePropertySetDAOImpl"/>  
  72.         </property>  
  73.     </bean>  
  74.     <bean id="jdbcTemplatePropertySetDAOImpl"  
  75.         class="com.opensymphony.module.propertyset.database.JDBCTemplatePropertySetDAOImpl"  
  76.         scope="prototype">  
  77.         <property name="dataSource">  
  78.             <ref bean="dataSource" />  
  79.         </property>  
  80.     </bean>  
  81.     <!-- 
  82.         这是一个XMLWorkflowFactory封装包,它可以允许从容器中注入configuration,从而不再从其它的XML配置文件中读取它们 
  83.     -->  
  84.     <bean id="workflowFactory"  
  85.         class="com.opensymphony.workflow.spi.hibernate.SpringWorkflowFactory"  
  86.         init-method="init">  
  87.         <property name="resource">  
  88.             <value>../osworkflow/workflows.xml</value>  
  89.         </property>  
  90.         <property name="reload">  
  91.             <value>true</value>  
  92.         </property>  
  93.     </bean>  
  94.       
  95.       
  96.     <!-- WorkflowStore 事务处理配置 -->  
  97.     <aop:config>  
  98.         <aop:pointcut id="oswfMethod1"  
  99.             expression="execution(* com.opensymphony.workflow.spi.WorkflowStore.*(..))" />  
  100.         <aop:pointcut id="oswfMethod2"  
  101.             expression="execution(* com.opensymphony.module.propertyset.database.JDBCTemplatePropertySetDAO.*(..))" />             
  102.           
  103.         <aop:advisor pointcut-ref="oswfMethod1" advice-ref="txAdvice_oswf" />  
  104.         <aop:advisor pointcut-ref="oswfMethod2" advice-ref="txAdvice_oswf" />  
  105.     </aop:config>  
  106.     <tx:advice id="txAdvice_oswf" transaction-manager="txManager">  
  107.         <tx:attributes>  
  108.             <tx:method name="*" />  
  109.         </tx:attributes>  
  110.     </tx:advice>  
  111.     <!-- 这是一个Workflow Configuration接口的实现类,它包含指向store和factory的引用,这样可以在spring中注入 -->  
  112.     <bean id="osworkflowConfiguration" class="com.opensymphony.workflow.config.SpringConfiguration"  
  113.           scope="prototype">  
  114.         <property name="store">  
  115.             <ref local="mysqlTemplateWorkflowStore" />  
  116.         </property>  
  117.         <property name="factory">  
  118.             <ref local="workflowFactory" />  
  119.         </property>  
  120.     </bean>  
  121.       
  122.     <!--允许OSWorkflow从Spring ApplicationContext中获得业务逻辑组件(conditions,functions等等) -->  
  123.     <bean id="workflowTypeResolver" class="com.opensymphony.workflow.util.SpringTypeResolver"></bean>  
  124.       
  125. </beans>  

 

用到了一些自己扩展的类(是网上一个牛人的写的,我只抽取了mysql jdbc那部分)见下图的结构:

 

 

代码依次如下:

 

DefaultJDBCTemplateConfigurationProvider.java

 

 

  1. package com.opensymphony.module.propertyset.database;  
  2. /** 
  3.  * @author  
  4.  */  
  5. public class DefaultJDBCTemplateConfigurationProvider implements JDBCTemplateConfigurationProvider {  
  6.     private JDBCTemplatePropertySetDAO propertySetDAO;  
  7.     public JDBCTemplatePropertySetDAO getPropertySetDAO() {  
  8.         return this.propertySetDAO;  
  9.     }  
  10.     public void setPropertySetDAO(JDBCTemplatePropertySetDAO propertySetDAO) {  
  11.         this.propertySetDAO = propertySetDAO;  
  12.     }  
  13. }  

 

JDBCTemplateConfigurationProvider.java

  1. package com.opensymphony.module.propertyset.database;  
  2. /** 
  3.  * @author 
  4.  */  
  5. public interface JDBCTemplateConfigurationProvider {  
  6.     JDBCTemplatePropertySetDAO getPropertySetDAO();  
  7. }  

 

JDBCTemplatePropertySet.java

  1. package com.opensymphony.module.propertyset.database;  
  2. import com.opensymphony.module.propertyset.AbstractPropertySet;  
  3. import com.opensymphony.module.propertyset.PropertyException;  
  4. import com.opensymphony.util.ClassLoaderUtil;  
  5. import org.apache.commons.logging.Log;  
  6. import org.apache.commons.logging.LogFactory;  
  7. import java.util.Collection;  
  8. import java.util.Map;  
  9. /** 
  10.  * @author 
  11.  */  
  12. public class JDBCTemplatePropertySet extends AbstractPropertySet {  
  13.     protected static Log log = LogFactory.getLog(JDBCTemplatePropertySet.class);  
  14.     private JDBCTemplateConfigurationProvider configProvider;  
  15.     private JDBCTemplatePropertySetDAO dao;  
  16.     @SuppressWarnings("unchecked")  
  17.     public void init(Map config, Map args) {  
  18.         log.debug("(JDBCTemplatePropertySet) top of init.");  
  19.         super.init(config, args);  
  20.         // first let's see if we got given a configuration provider to use   
  21.         // already   
  22.         this.configProvider = (JDBCTemplateConfigurationProvider) args.get("configurationProvider"); //$NON-NLS-1$   
  23.         /* if we did not get given one in the args, we need to set a config provider up */  
  24.         if (this.configProvider == null) {  
  25.             // lets see if we need to use a configurationProvider from a class   
  26.             String configProviderClass = (String) config.get("configuration.provider.class");//$NON-NLS-1$   
  27.             if (configProviderClass != null) {  
  28.                 if (log.isDebugEnabled()) {  
  29.                     log.debug("Setting up property set provider of class: " + configProviderClass);//$NON-NLS-1$   
  30.                 }  
  31.                 try {  
  32.                     this.configProvider = (JDBCTemplateConfigurationProvider) ClassLoaderUtil  
  33.                             .loadClass(configProviderClass, this.getClass()).newInstance();  
  34.                 }  
  35.                 catch (Exception e) {  
  36.                     log.error("Unable to load configuration provider class: " + configProviderClass, e);//$NON-NLS-1$   
  37.                     return;  
  38.                 }  
  39.             } else {  
  40.                 if (log.isDebugEnabled()) {  
  41.                     log.debug("Setting up property set with DefaultJDBCTemplateConfigurationProvider");//$NON-NLS-1$   
  42.                 }  
  43.                 this.configProvider = new DefaultJDBCTemplateConfigurationProvider();  
  44.             }  
  45.         } else {  
  46.             if (log.isDebugEnabled()) {  
  47.                 log.debug("Setting up property set with jdbcTemplate provider passed in args."); //$NON-NLS-1$   
  48.             }  
  49.         }  
  50.         dao = configProvider.getPropertySetDAO();  
  51.         dao.setGlobalKey((String) args.get("globalKey"));  
  52.         dao.setTableName((String) config.get("table.name"));  
  53.         dao.setColGlobalKey((String) config.get("col.globalKey"));  
  54.         dao.setColItemKey((String) config.get("col.itemKey"));  
  55.         dao.setColItemType((String) config.get("col.itemType"));  
  56.         dao.setColString((String) config.get("col.string"));  
  57.         dao.setColDate((String) config.get("col.date"));  
  58.         dao.setColData((String) config.get("col.data"));  
  59.         dao.setColFloat((String) config.get("col.float"));  
  60.         dao.setColNumber((String) config.get("col.number"));  
  61.     }  
  62.     @SuppressWarnings("unchecked")  
  63.     public Collection getKeys(String prefix, int type) throws PropertyException {  
  64.         return dao.getKeys(prefix, type);  
  65.     }  
  66.     public int getType(String key) throws PropertyException {  
  67.         return dao.getType(key);  
  68.     }  
  69.     public boolean exists(String key) throws PropertyException {  
  70.         return dao.exists(key);  
  71.     }  
  72.     public void remove(String key) throws PropertyException {  
  73.         dao.remove(key);  
  74.     }  
  75.     protected void setImpl(int type, String key, Object value) throws PropertyException {  
  76.         dao.setImpl(type, key, value);  
  77.     }  
  78.     protected Object get(int type, String key) throws PropertyException {  
  79.         return dao.get(type, key);  
  80.     }  
  81.     public void remove() throws PropertyException {  
  82.     }  
  83. }  

 

JDBCTemplatePropertySetDAO.java

 

  1. package com.opensymphony.module.propertyset.database;  
  2. import com.opensymphony.module.propertyset.PropertyException;  
  3. import java.util.Collection;  
  4. /** 
  5.  * @author 
  6.  */  
  7. public interface JDBCTemplatePropertySetDAO {  
  8.     @SuppressWarnings("unchecked")  
  9.     public Collection getKeys(String prefix, int type) throws PropertyException;  
  10.     public int getType(String key) throws PropertyException;  
  11.     public boolean exists(String key) throws PropertyException;  
  12.     public void remove(String key) throws PropertyException;  
  13.     public void setImpl(int type, String key, Object value) throws PropertyException;  
  14.     public Object get(int type, String key) throws PropertyException;  
  15.     public void setColData(String colData);  
  16.     public void setColDate(String colDate);  
  17.     public void setColFloat(String colFloat);  
  18.     public void setColGlobalKey(String colGlobalKey);  
  19.     public void setColItemKey(String colItemKey);  
  20.     public void setColItemType(String colItemType);  
  21.     public void setColNumber(String colNumber);  
  22.     public void setColString(String colString);  
  23.     public void setGlobalKey(String globalKey);  
  24.     public void setTableName(String tableName);  
  25. }  

 

JDBCTemplatePropertySetDAOImpl.java

  1. package com.opensymphony.module.propertyset.database;  
  2. import com.opensymphony.module.propertyset.InvalidPropertyTypeException;  
  3. import com.opensymphony.module.propertyset.PropertyException;  
  4. import com.opensymphony.module.propertyset.PropertySet;  
  5. import com.opensymphony.util.Data;  
  6. import org.springframework.dao.DataAccessException;  
  7. import org.springframework.jdbc.core.RowCallbackHandler;  
  8. import org.springframework.jdbc.core.support.JdbcDaoSupport;  
  9. import java.sql.ResultSet;  
  10. import java.sql.SQLException;  
  11. import java.sql.Timestamp;  
  12. import java.util.ArrayList;  
  13. import java.util.Collection;  
  14. import java.util.List;  
  15. /** 
  16.  * @author  
  17.  */  
  18. public class JDBCTemplatePropertySetDAOImpl extends JdbcDaoSupport implements JDBCTemplatePropertySetDAO {  
  19.     private String colData;  
  20.     private String colDate;  
  21.     private String colFloat;  
  22.     private String colGlobalKey;  
  23.     private String colItemKey;  
  24.     private String colItemType;  
  25.     private String colNumber;  
  26.     private String colString;  
  27.     // args   
  28.     private String globalKey;  
  29.     private String tableName;  
  30.     public void setColData(String colData) {  
  31.         this.colData = colData;  
  32.     }  
  33.     public void setColDate(String colDate) {  
  34.         this.colDate = colDate;  
  35.     }  
  36.     public void setColFloat(String colFloat) {  
  37.         this.colFloat = colFloat;  
  38.     }  
  39.     public void setColGlobalKey(String colGlobalKey) {  
  40.         this.colGlobalKey = colGlobalKey;  
  41.     }  
  42.     public void setColItemKey(String colItemKey) {  
  43.         this.colItemKey = colItemKey;  
  44.     }  
  45.     public void setColItemType(String colItemType) {  
  46.         this.colItemType = colItemType;  
  47.     }  
  48.     public void setColNumber(String colNumber) {  
  49.         this.colNumber = colNumber;  
  50.     }  
  51.     public void setColString(String colString) {  
  52.         this.colString = colString;  
  53.     }  
  54.     public void setGlobalKey(String globalKey) {  
  55.         this.globalKey = globalKey;  
  56.     }  
  57.     public void setTableName(String tableName) {  
  58.         this.tableName = tableName;  
  59.     }  
  60.     @SuppressWarnings("unchecked")  
  61.     public Collection getKeys(String prefix, int type) throws PropertyException {  
  62.         if (prefix == null) {  
  63.             prefix = "";  
  64.         }  
  65.         try {  
  66.             String sql = "SELECT " + colItemKey + " FROM " + tableName + " WHERE " + colItemKey + " LIKE ? AND " + colGlobalKey + " = ?";  
  67.             final ArrayList list = new ArrayList();  
  68.             if (type == 0) {  
  69.                 this.getJdbcTemplate().query(sql, new Object[]{prefix + "%", globalKey}, new RowCallbackHandler() {  
  70.                     public void processRow(ResultSet rs) throws SQLException {  
  71.                         list.add(rs.getString(colItemKey));  
  72.                     }  
  73.                 });  
  74.             } else {  
  75.                 sql = sql + " AND " + colItemType + " = ?";  
  76.                 this.getJdbcTemplate().query(sql, new Object[]{prefix + "%", globalKey, new Integer(type)}, new RowCallbackHandler() {  
  77.                     public void processRow(ResultSet rs) throws SQLException {  
  78.                         list.add(rs.getString(colItemKey));  
  79.                     }  
  80.                 });  
  81.             }  
  82.             return list;  
  83.         } catch (DataAccessException  
  84.                 e) {  
  85.             throw new PropertyException(e.getMessage());  
  86.         }  
  87.     }  
  88.     public int getType(String key) throws PropertyException {  
  89.         try {  
  90.             String sql = "SELECT " + colItemType + " FROM " + tableName + " WHERE " + colGlobalKey + " = ? AND " + colItemKey + " = ?";  
  91.             return this.getJdbcTemplate().queryForInt(sql, new Object[]{globalKey, key});  
  92.         } catch (DataAccessException e) {  
  93.             throw new PropertyException(e.getMessage());  
  94.         }  
  95.     }  
  96.     public boolean exists(String key) throws PropertyException {  
  97.         return getType(key) != 0;  
  98.     }  
  99.     public void remove(String key) throws PropertyException {  
  100.         try {  
  101.             String sql = "DELETE FROM " + tableName + " WHERE " + colGlobalKey + " = ? AND " + colItemKey + " = ?";  
  102.             this.getJdbcTemplate().update(sql, new Object[]{globalKey, key});  
  103.         } catch (DataAccessException e) {  
  104.             throw new PropertyException(e.getMessage());  
  105.         }  
  106.     }  
  107.     public void setImpl(int type, String key, Object value) throws PropertyException {  
  108.         if (value == null) {  
  109.             throw new PropertyException("JDBCTemplatePropertySet does not allow for null values to be stored");  
  110.         }  
  111.         try {  
  112.             int rows = updateValues(type, key, value);  
  113.             if (rows != 1) {  
  114.                 insertValues(type, key, value);  
  115.             }  
  116.         } catch (Exception e) {  
  117.             throw new PropertyException(e.getMessage());  
  118.         }  
  119.     }  
  120.     @SuppressWarnings("unchecked")  
  121.     public Object get(final int type, String key) throws PropertyException {  
  122.         String sql = "SELECT " + colItemType + ", " + colString + ", " + colDate + ", " + colData + ", " + colFloat + ", " + colNumber + " FROM " + tableName + " WHERE " + colItemKey + " = ? AND " + colGlobalKey + " = ?";  
  123.         final List list = new ArrayList();  
  124.         try {  
  125.             this.getJdbcTemplate().query(sql, new Object[]{key, globalKey}, new RowCallbackHandler() {  
  126.                 public void processRow(ResultSet rs) throws SQLException {  
  127.                     int propertyType = rs.getInt(colItemType);  
  128.                     if (propertyType != type) {  
  129.                         throw new InvalidPropertyTypeException();  
  130.                     }  
  131.                     Object o;  
  132.                     switch (type) {  
  133.                         case PropertySet.BOOLEAN:  
  134.                             int boolVal = rs.getInt(colNumber);  
  135.                             o = new Boolean(boolVal == 1);  
  136.                             break;  
  137.                         case PropertySet.DATA:  
  138.                             o = rs.getBytes(colData);  
  139.                             break;  
  140.                         case PropertySet.DATE:  
  141.                             o = rs.getTimestamp(colDate);  
  142.                             break;  
  143.                         case PropertySet.DOUBLE:  
  144.                             o = new Double(rs.getDouble(colFloat));  
  145.                             break;  
  146.                         case PropertySet.INT:  
  147.                             o = new Integer(rs.getInt(colNumber));  
  148.                             break;  
  149.                         case PropertySet.LONG:  
  150.                             o = new Long(rs.getLong(colNumber));  
  151.                             break;  
  152.                         case PropertySet.STRING:  
  153.                             o = rs.getString(colString);  
  154.                             break;  
  155.                         default:  
  156.                             throw new InvalidPropertyTypeException("JDBCPropertySet doesn't support this type yet.");  
  157.                     }  
  158.                     list.add(o);  
  159.                 }  
  160.             });  
  161.         } catch (NumberFormatException e) {  
  162.             throw new PropertyException(e.getMessage());  
  163.         }  
  164.         return list.get(0);  
  165.     }  
  166.     private int updateValues(int type, String key, Object value) throws DataAccessException, PropertyException {  
  167.         //String sql = "UPDATE " + tableName + " SET " + colString + " = ?, " + colDate + " = ?, " + colData + " = ?, " + colFloat + " = ?, " + colNumber + " = ?, " + colItemType + " = ? " + " WHERE " + colGlobalKey + " = ? AND " + colItemKey + " = ?";   
  168.         String sql = "";  
  169.         switch (type) {  
  170.             case PropertySet.BOOLEAN:  
  171.                 Boolean boolVal = (Boolean) value;  
  172.                 sql = "UPDATE " + tableName + " SET " + colNumber + " = ?, " + colItemType + " = ? " + " WHERE " + colGlobalKey + " = ? AND " + colItemKey + " = ?";  
  173.                 return this.getJdbcTemplate().update(sql, new Object[]{(boolVal.booleanValue() ? 1 : 0), type, globalKey, key});  
  174.             case PropertySet.DATA:  
  175.                 Data data = (Data) value;  
  176.                 sql = "UPDATE " + tableName + " SET " + colData + " = ?, " + colItemType + " = ? " + " WHERE " + colGlobalKey + " = ? AND " + colItemKey + " = ?";  
  177.                 return this.getJdbcTemplate().update(sql, new Object[]{data.getBytes(), type, globalKey, key});  
  178.             case PropertySet.DATE:  
  179.                 java.util.Date date = (java.util.Date) value;  
  180.                 sql = "UPDATE " + tableName + " SET " + colDate + " = ?, " + colItemType + " = ? " + " WHERE " + colGlobalKey + " = ? AND " + colItemKey + " = ?";  
  181.                 return this.getJdbcTemplate().update(sql, new Object[]{new Timestamp(date.getTime()), type, globalKey, key});  
  182.             case PropertySet.DOUBLE:  
  183.                 Double d = (Double) value;  
  184.                 sql = "UPDATE " + tableName + " SET " + colFloat + " = ?, " + colItemType + " = ? " + " WHERE " + colGlobalKey + " = ? AND " + colItemKey + " = ?";  
  185.                 return this.getJdbcTemplate().update(sql, new Object[]{d, type, globalKey, key});  
  186.             case PropertySet.INT:  
  187.                 Integer i = (Integer) value;  
  188.                 sql = "UPDATE " + tableName + " SET " + colNumber + " = ?, " + colItemType + " = ? " + " WHERE " + colGlobalKey + " = ? AND " + colItemKey + " = ?";  
  189.                 return this.getJdbcTemplate().update(sql, new Object[]{i, type, globalKey, key});  
  190.             case PropertySet.LONG:  
  191.                 Long l = (Long) value;  
  192.                 sql = "UPDATE " + tableName + " SET " + colNumber + " = ?, " + colItemType + " = ? " + " WHERE " + colGlobalKey + " = ? AND " + colItemKey + " = ?";  
  193.                 return this.getJdbcTemplate().update(sql, new Object[]{l, type, globalKey, key});  
  194.             case PropertySet.STRING:  
  195.                 sql = "UPDATE " + tableName + " SET " + colString + " = ?, " + colItemType + " = ? " + " WHERE " + colGlobalKey + " = ? AND " + colItemKey + " = ?";  
  196.                 return this.getJdbcTemplate().update(sql, new Object[]{(String) value, type, globalKey, key});  
  197.             default:  
  198.                 throw new PropertyException("This type isn't supported!");  
  199.         }  
  200.     }  
  201.     private void insertValues(int type, String key, Object value) throws DataAccessException, PropertyException {  
  202.         //String sql = "INSERT INTO " + tableName + " (" + colString + ", " + colDate + ", " + colData + ", " + colFloat + ", " + colNumber + ", " + colItemType + ", " + colGlobalKey + ", " + colItemKey + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?)";   
  203.         String sql = "";  
  204.         switch (type) {  
  205.             case PropertySet.BOOLEAN:  
  206.                 Boolean boolVal = (Boolean) value;  
  207.                 sql = "INSERT INTO " + tableName + " (" + colNumber + ", " + colItemType + ", " + colGlobalKey + ", " + colItemKey + ") VALUES (?, ?, ?, ?)";  
  208.                 this.getJdbcTemplate().update(sql, new Object[]{(boolVal.booleanValue() ? 1 : 0), type, globalKey, key});  
  209.                 break;  
  210.             case PropertySet.DATA:  
  211.                 Data data = (Data) value;  
  212.                 sql = "INSERT INTO " + tableName + " (" + colData + ", " + colItemType + ", " + colGlobalKey + ", " + colItemKey + ") VALUES (?, ?, ?, ?)";  
  213.                 this.getJdbcTemplate().update(sql, new Object[]{data.getBytes(), type, globalKey, key});  
  214.                 break;  
  215.             case PropertySet.DATE:  
  216.                 java.util.Date date = (java.util.Date) value;  
  217.                 sql = "INSERT INTO " + tableName + " (" + colDate + ", " + colItemType + ", " + colGlobalKey + ", " + colItemKey + ") VALUES (?, ?, ?, ?)";  
  218.                 this.getJdbcTemplate().update(sql, new Object[]{new Timestamp(date.getTime()), type, globalKey, key});  
  219.                 break;  
  220.             case PropertySet.DOUBLE:  
  221.                 Double d = (Double) value;  
  222.                 sql = "INSERT INTO " + tableName + " (" + colFloat + ", " + colItemType + ", " + colGlobalKey + ", " + colItemKey + ") VALUES (?, ?, ?, ?)";  
  223.                 this.getJdbcTemplate().update(sql, new Object[]{d, type, globalKey, key});  
  224.                 break;  
  225.             case PropertySet.INT:  
  226.                 Integer i = (Integer) value;  
  227.                 sql = "INSERT INTO " + tableName + " (" + colNumber + ", " + colItemType + ", " + colGlobalKey + ", " + colItemKey + ") VALUES (?, ?, ?, ?)";  
  228.                 this.getJdbcTemplate().update(sql, new Object[]{i, type, globalKey, key});  
  229.                 break;  
  230.             case PropertySet.LONG:  
  231.                 Long l = (Long) value;  
  232.                 sql = "INSERT INTO " + tableName + " (" + colNumber + ", " + colItemType + ", " + colGlobalKey + ", " + colItemKey + ") VALUES (?, ?, ?, ?)";  
  233.                 this.getJdbcTemplate().update(sql, new Object[]{l, type, globalKey, key});  
  234.                 break;  
  235.             case PropertySet.STRING:  
  236.                 sql = "INSERT INTO " + tableName + " (" + colString + ", " + colItemType + ", " + colGlobalKey + ", " + colItemKey + ") VALUES (?, ?, ?, ?)";  
  237.                 this.getJdbcTemplate().update(sql, new Object[]{(String) value, type, globalKey, key});  
  238.                 break;  
  239.             default:  
  240.                 throw new PropertyException("This type isn't supported!");  
  241.         }  
  242.     }  
  243. }  

 

DefaultJDBCTemplatePropertySetDelegate.java

  1. package com.opensymphony.workflow.spi.jdbc;  
  2. import com.opensymphony.module.propertyset.PropertySet;  
  3. import com.opensymphony.module.propertyset.PropertySetManager;  
  4. import com.opensymphony.module.propertyset.database.DefaultJDBCTemplateConfigurationProvider;  
  5. import com.opensymphony.workflow.util.PropertySetDelegate;  
  6. import java.util.HashMap;  
  7. import java.util.Map;  
  8. /** 
  9.  * @author  
  10.  */  
  11. public class DefaultJDBCTemplatePropertySetDelegate implements PropertySetDelegate {  
  12.     private DefaultJDBCTemplateConfigurationProvider configurationProvider;  
  13.       
  14.     public void setConfigurationProvider(  
  15.             DefaultJDBCTemplateConfigurationProvider configurationProvider) {  
  16.         this.configurationProvider = configurationProvider;  
  17.     }  
  18.       
  19.     public DefaultJDBCTemplatePropertySetDelegate() {  
  20.         super();  
  21.     }  
  22.     @SuppressWarnings("unchecked")  
  23.     public PropertySet getPropertySet(long entryId) {  
  24.         Map args = new HashMap(1);  
  25.         args.put("globalKey""osff_temp_" + entryId);  
  26.         args.put("configurationProvider", configurationProvider);  
  27.         return PropertySetManager.getInstance("jdbcTemplate", args);  
  28.     }  
  29. }  

 

JDBCTemplateWorkflowStore.java

 

 

MySQLTemplateWorkflowStore.java

 

 

要注意配置文件里,spring关于osworkflow事务的aop配置,一定对应扩展的类,否则流程过程中的sql语句不能即使的执行,配了就完全ok了。

 

下面是数据库的sql,我把原数据库里的用户权限的3个表去了,这个可以用自己的,用它的好不爽。

 

 

对了还有个propertyset.xml文件:

 

 

至于自定义的流程的xml就参看osworkflow官方的例子吧,这样配置好以后osworkflowConfiguration就成为了spring的bean了可以注入了,当然也可以把baseWorkflow也配置成bean,进行注入。

 

 

最后提供一个svn:http://xeducation.googlecode.com/svn/trunk,这里是一个spring2.5+hibernate3.x+struts2.1.x+osworkflow2.8的一个空架子,可以运行的。注释也写的比较明白。(myeclipse的工程)

有兴趣的可以当下来看看。

 

 

 

 

 

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值