现在的位置: 首页 > 综合 > 正文

JbpmTemplate在spring-modules-jbpm30和spring-modules-jbpm31的差别

2013年07月16日 ⁄ 综合 ⁄ 共 1991字 ⁄ 字号 评论关闭

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对象。。

 

【上篇】
【下篇】

抱歉!评论已关闭.