org.springmodules.workflow.jbpm30.JbpmTemplate{
/**
* Execute the action specified by the given action object within a JbpmSession.
*
* @param callback
* @return
*/
public Object execute(final JbpmCallback callback) {
final JbpmSession jbpmSession = getSession();
boolean existingTransaction = JbpmSessionFactoryUtils.isTransactional(jbpmSession,
this.jbpmSessionFactory);
if (existingTransaction) {
logger.debug("Found thread-bound Session for JbpmTemplate");
}
try {
return hibernateTemplate.execute(new HibernateCallback() {
/**
* @see org.springframework.orm.hibernate3.HibernateCallback#doInHibernate(org.hibernate.Session)
*/
public Object doInHibernate(Session session) throws HibernateException, SQLException {
return callback.doInJbpm(jbpmSession);
}
}, true);
}
catch (RuntimeException ex) {
throw convertJbpmException(ex);
}
finally {
if (existingTransaction) {
logger.debug("Not closing pre-bound jBPM Session after JbpmTemplate");
}
else {
releaseSession(jbpmSession);
}
}
}
}
org.springmodules.workflow.jbpm31.JbpmTemplate{
/**
* Execute the action specified by the given action object within a
* JbpmSession.
*
* @param callback
* @return
*/
public Object execute(final JbpmCallback callback) {
final JbpmContext context = getContext();
try {
// use the hibernateTemplate is present and if needed
if (hibernateTemplate != null && hasPersistenceService) {
// use hibernate template
return hibernateTemplate.execute(new HibernateCallback() {
/**
* @see org.springframework.orm.hibernate3.HibernateCallback#doInHibernate(org.hibernate.Session)
*/
public Object doInHibernate(Session session) throws HibernateException, SQLException {
// inject the session in the context
context.setSession(session);
return callback.doInJbpm(context);
}
});
}
// plain callback invocation (no template w/ persistence)
return callback.doInJbpm(context);
}
catch (JbpmException ex) {
throw convertJbpmException(ex);
}
finally {
releaseContext(context);
}
}
}
这里可以看到两者之间的区别:
使用的对象是不同的。。
注意在JBPM3.2的版本后。就不再使用jbpmSession对象。。