精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-03-04
Spring, Springmodules, JBPM持久化集成理解系列二 【本系列如需转载,请注明作者及出处】
本系列文章假设阅者具备以下知识:
第二部分,Session的关闭: 到了这里,我们就到了验证的最后一部分了,JbpmContext的关闭了。 public void close() { log.debug("closing JbpmContext"); try { if (services!=null) { try { autoSave(); } finally { services.close(); } } } finally { if (jbpmConfiguration!=null) { jbpmConfiguration.jbpmContextClosed(this); } } } 也就是说,JbpmContext关闭的时候会产生自动保存,最后关闭services,现在摘取DbPersistenceService的close里面我们关心的逻辑: 【位置DbPersistenceService】 if (mustSessionBeClosed) { try { if(session.isOpen()) { log.debug("closing hibernate session"); session.close(); } else { log.warn("hibernate session was already closed"); } } catch (Exception e) { throw new JbpmPersistenceException("couldn't close hibernate session", e); } } if (mustConnectionBeClosed) { try { if ( (connection!=null) && (! connection.isClosed()) ) { log.debug("closing jdbc connection"); connection.close(); } else { log.warn("jdbc connection was already closed"); } } catch (Exception e) { throw new JbpmPersistenceException("couldn't close jdbc connection", e); } }
package com.cabernet; import java.util.List; import junit.framework.Assert; import org.jbpm.taskmgmt.exe.TaskInstance; import org.springmodules.workflow.jbpm31.JbpmTemplate; public class TestSetUp extends BaseTestCase { protected JbpmTemplate jbpmTemplate; public void test() { Assert.assertNotNull(this.jbpmTemplate); boolean isDebugEnabled = log.isDebugEnabled(); if (isDebugEnabled) { log.debug("findTaskInstances"); } List<TaskInstance> tasks = this.jbpmTemplate.findTaskInstances("bert"); if (tasks != null) { if (isDebugEnabled) { log.debug("Tasks found, Swimlane: [" + tasks.get(0).getTask() .getSwimlane().getName() + "]."); } return; } if (isDebugEnabled) { log.debug("No tasks found."); } } public JbpmTemplate getJbpmTemplate() { return jbpmTemplate; } public void setJbpmTemplate(JbpmTemplate jbpmTemplate) { this.jbpmTemplate = jbpmTemplate; } }
上述Junit 类继承的父类BaseTestCase是AbstractDependencyInjectionSpringContextTests的子类, 启用了与OpenSessionInView一样的数据LazyLoading和JDBC Connection延迟关闭策略。
附件是测试这个这个流程所发生的Log,首先是SessionFactoryUtils打开了Hibernate Session,最后是SessionFactoryUtils关闭了Hibernate Session,符合Jbpm声称的Context哲学。 2008-03-04 00:14:12 DEBUG (SessionFactoryUtils.java:690) - Initializing deferred close of Hibernate Sessions 2008-03-04 00:14:12 DEBUG (SessionFactoryUtils.java:316) - Opening Hibernate Session 2008-03-04 00:14:12 DEBUG (TestSetUp.java:22) - findTaskInstances 2008-03-04 00:14:12 DEBUG (JbpmContextInfo.java:142) - creating jbpm context with service factories '[message, scheduler, logging, persistence, authentication]' 2008-03-04 00:14:12 DEBUG (JbpmContext.java:124) - creating JbpmContext 2008-03-04 00:14:12 DEBUG (HibernateTemplate.java:364) - Found thread-bound Session for HibernateTemplate 2008-03-04 00:14:12 DEBUG (DbPersistenceServiceFactory.java:55) - creating persistence service 2008-03-04 00:14:12 DEBUG (DbPersistenceService.java:303) - injecting a session disables transaction Hibernate: select taskinstan0_.ID_ as ID1_27_, taskinstan0_.NAME_ as NAME3_27_, taskinstan0_.DESCRIPTION_ as DESCRIPT4_27_, taskinstan0_.ACTORID_ as ACTORID5_27_, taskinstan0_.CREATE_ as CREATE6_27_, taskinstan0_.START_ as START7_27_, taskinstan0_.END_ as END8_27_, taskinstan0_.DUEDATE_ as DUEDATE9_27_, taskinstan0_.PRIORITY_ as PRIORITY10_27_, taskinstan0_.ISCANCELLED_ as ISCANCE11_27_, taskinstan0_.ISSUSPENDED_ as ISSUSPE12_27_, taskinstan0_.ISOPEN_ as ISOPEN13_27_, taskinstan0_.ISSIGNALLING_ as ISSIGNA14_27_, taskinstan0_.ISBLOCKING_ as ISBLOCKING15_27_, taskinstan0_.TASK_ as TASK16_27_, taskinstan0_.TOKEN_ as TOKEN17_27_, taskinstan0_.SWIMLANINSTANCE_ as SWIMLAN18_27_, taskinstan0_.TASKMGMTINSTANCE_ as TASKMGM19_27_ from JBPM_TASKINSTANCE taskinstan0_ where taskinstan0_.ACTORID_=? and taskinstan0_.ISSUSPENDED_<>1 and taskinstan0_.ISOPEN_=1 2008-03-04 00:14:13 DEBUG (HibernateTemplate.java:388) - Not closing pre-bound Hibernate Session after HibernateTemplate 2008-03-04 00:14:13 DEBUG (JbpmContext.java:133) - closing JbpmContext 2008-03-04 00:14:13 DEBUG (Services.java:210) - closing service 'persistence': org.jbpm.persistence.db.DbPersistenceService@1ce663c Hibernate: select task0_.ID_ as ID1_14_0_, task0_.NAME_ as NAME2_14_0_, task0_.PROCESSDEFINITION_ as PROCESSD3_14_0_, task0_.DESCRIPTION_ as DESCRIPT4_14_0_, task0_.ISBLOCKING_ as ISBLOCKING5_14_0_, task0_.ISSIGNALLING_ as ISSIGNAL6_14_0_, task0_.DUEDATE_ as DUEDATE7_14_0_, task0_.ACTORIDEXPRESSION_ as ACTORIDE8_14_0_, task0_.POOLEDACTORSEXPRESSION_ as POOLEDAC9_14_0_, task0_.TASKMGMTDEFINITION_ as TASKMGM10_14_0_, task0_.TASKNODE_ as TASKNODE11_14_0_, task0_.STARTSTATE_ as STARTSTATE12_14_0_, task0_.ASSIGNMENTDELEGATION_ as ASSIGNM13_14_0_, task0_.SWIMLANE_ as SWIMLANE14_14_0_, task0_.TASKCONTROLLER_ as TASKCON15_14_0_ from JBPM_TASK task0_ where task0_.ID_=? Hibernate: select swimlane0_.ID_ as ID1_13_0_, swimlane0_.NAME_ as NAME2_13_0_, swimlane0_.ACTORIDEXPRESSION_ as ACTORIDE3_13_0_, swimlane0_.POOLEDACTORSEXPRESSION_ as POOLEDAC4_13_0_, swimlane0_.ASSIGNMENTDELEGATION_ as ASSIGNME5_13_0_, swimlane0_.TASKMGMTDEFINITION_ as TASKMGMT6_13_0_ from JBPM_SWIMLANE swimlane0_ where swimlane0_.ID_=? 2008-03-04 00:14:13 DEBUG (TestSetUp.java:31) - Tasks found, Swimlane: [buyer]. 2008-03-04 00:14:13 DEBUG (SessionFactoryUtils.java:714) - Processing deferred close of Hibernate Sessions
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
浏览 3253 次