if (batcher!=null) batcher.CloseCommands();
         IDbConnection c = connection;
         connection=null;
         if (autoClose) {
            factory.CloseConnection(c);
            return null;
         }
         else  {
            return c;
         }
      }
   }
   finally {
      if ( callAfterTransactionCompletionFromDisconnect ) {
         AfterTransactionCompletion();
      }
   }
}
从上面的代码中可以看出,如果autoClose为true才会自动关闭连接。

这样就实现了数据库事务的生命周期长于会话生命周期的事务处理方法,至于这种方法有没使用性,那就不好说了,因为要在OpenSession时使用数据库连接,那么如果我们把操作分散于各个对象之中的话,显然必须传递数据库连接或事务,但至少做到了数据库事务与会话无关。

相关文章:

  • 2022-12-23
  • 2021-07-24
  • 2022-12-23
  • 2022-01-12
  • 2021-09-03
  • 2021-09-25
猜你喜欢
  • 2022-03-08
  • 2022-01-03
  • 2021-07-22
  • 2021-11-08
  • 2018-07-26
  • 2021-12-05
相关资源
相似解决方案