读书人

Spring, Springmodules, JBPM持久化集

发布时间: 2012-11-06 14:07:00 作者: rapoo

Spring, Springmodules, JBPM持久化集成--优雅的背后(Part1)

Spring, Springmodules, JBPM持久化集成理解系列二?

?

【本系列如需转载,请注明作者及出处】?

?

本系列文章假设阅者具备以下知识:
1,ThreadLocal相关知识
2,Spring持久化,事务管理相关知识
3,Hibernate 持久化相关知识
4,Jbpm 持久化相关知识
5,Springmodules项目相关知识
6,相关J2EE知识


且具备以下材料:
1,Spring源代码
2,Hibernate源代码
3,Jbpm源代码
4,Springmodules源代码?

?

?

? 本篇尝试探讨SpringModules集成的背后逻辑,这涉及到JbpmContext持久化的哲学。?

public TaskInstance loadTaskInstance(long taskInstanceId) { return getTaskMgmtSession().loadTaskInstance(taskInstanceId);}public TaskMgmtSession getTaskMgmtSession() { PersistenceService persistenceService = getPersistenceService(); if (persistenceService==null) return null; return (persistenceService!=null ? persistenceService.getTaskMgmtSession() : null);

public TaskMgmtSession getTaskMgmtSession() { if (taskMgmtSession==null) { Session session = getSession(); if (session!=null) { taskMgmtSession = new TaskMgmtSession(session); } } return taskMgmtSession; }

?

好了,到此我们就差不多达到Jbpm管理Session的环节了,我们再进入到getSession方法,看看它到底做了什么事情:

?

?

准备工作:1)以下是会涉及的布尔变量,以及其默认值:

?

【位置DbPersistenceService】

?

Connection connection = null;  boolean mustConnectionBeClosed = false;  Transaction transaction = null;  boolean isTransactionEnabled = true;  boolean isCurrentSessionEnabled = false;  boolean isRollbackOnly = false;  Session session;  boolean mustSessionBeFlushed = false;boolean mustSessionBeClosed = false;

?

?

?

准备工作2)由于DbPersistenceService只有一个Constructor,也就是

?

【位置DbPersistenceService】

?

public DbPersistenceService(DbPersistenceServiceFactory persistenceServiceFactory) {    this.persistenceServiceFactory = persistenceServiceFactory;    this.isTransactionEnabled = persistenceServiceFactory.isTransactionEnabled();    this.isCurrentSessionEnabled = persistenceServiceFactory.isCurrentSessionEnabled();  }

?

public Session getSession() { if ( (session==null) && (getSessionFactory()!=null) ) { Connection connection = getConnection(false); if (isCurrentSessionEnabled) { session = getSessionFactory().getCurrentSession(); mustSessionBeClosed = false; mustSessionBeFlushed = false; mustConnectionBeClosed = false; } else if (connection!=null) { log.debug("creating hibernate session with connection "+connection); session = getSessionFactory().openSession(connection); mustSessionBeClosed = true; mustSessionBeFlushed = true; mustConnectionBeClosed = false; } else { log.debug("creating hibernate session"); session = getSessionFactory().openSession(); mustSessionBeClosed = true; mustSessionBeFlushed = true; mustConnectionBeClosed = false; } if (isTransactionEnabled) { log.debug("beginning hibernate transaction"); transaction = session.beginTransaction(); } } return session; }

??

?

?

?

?

?

?

因为注入到JbpmContext的session和sessionFactory Setter方法都是将其注入到persistenceService里面的?在上面这个方法里

读书人网 >软件架构设计

热点推荐