• <i id='JhfXN'><tr id='JhfXN'><dt id='JhfXN'><q id='JhfXN'><span id='JhfXN'><b id='JhfXN'><form id='JhfXN'><ins id='JhfXN'></ins><ul id='JhfXN'></ul><sub id='JhfXN'></sub></form><legend id='JhfXN'></legend><bdo id='JhfXN'><pre id='JhfXN'><center id='JhfXN'></center></pre></bdo></b><th id='JhfXN'></th></span></q></dt></tr></i><div id='JhfXN'><tfoot id='JhfXN'></tfoot><dl id='JhfXN'><fieldset id='JhfXN'></fieldset></dl></div>
      <legend id='JhfXN'><style id='JhfXN'><dir id='JhfXN'><q id='JhfXN'></q></dir></style></legend>

      <small id='JhfXN'></small><noframes id='JhfXN'>

        <bdo id='JhfXN'></bdo><ul id='JhfXN'></ul>

        <tfoot id='JhfXN'></tfoot>

      1. 外行术语中的 Spring 传播示例

        时间:2023-09-28

              <bdo id='eByva'></bdo><ul id='eByva'></ul>
            • <small id='eByva'></small><noframes id='eByva'>

                <tfoot id='eByva'></tfoot>
                <i id='eByva'><tr id='eByva'><dt id='eByva'><q id='eByva'><span id='eByva'><b id='eByva'><form id='eByva'><ins id='eByva'></ins><ul id='eByva'></ul><sub id='eByva'></sub></form><legend id='eByva'></legend><bdo id='eByva'><pre id='eByva'><center id='eByva'></center></pre></bdo></b><th id='eByva'></th></span></q></dt></tr></i><div id='eByva'><tfoot id='eByva'></tfoot><dl id='eByva'><fieldset id='eByva'></fieldset></dl></div>
                  <tbody id='eByva'></tbody>

                • <legend id='eByva'><style id='eByva'><dir id='eByva'><q id='eByva'></q></dir></style></legend>
                  本文介绍了外行术语中的 Spring 传播示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  Spring 文档做一个描述事务传播属性的出色工作.

                  The Spring docs do a fantastic job of describing transactional propagation properties.

                  但是,我想知道是否有任何众所周知的真实示例可用外行术语更全面地描述这些属性中的每一个?

                  However, I was wondering if there are any well-known, real-world examples available which describe each of these properties more thoroughly in layman's terms?

                  推荐答案

                  PROPAGATION_REQUIRED

                  class Service {
                      @Transactional(propagation=Propagation.REQUIRED)
                      public void doSomething() {
                          // access a database using a DAO
                      }
                  }
                  

                  当 doSomething() 被调用时,它会开始一个新的事务如果调用者还没有开始一个事务.

                  When doSomething() is called it will start a new transaction if the caller has not already started a transaction.

                  如果该方法的调用者已经启动了一个事务,那么调用者的事务将被使用并且不会创建新的事务(即有一个事务在进行中).

                  If the caller of this method has already started a transaction then the callers' transaction is used and no new transaction is created (i.e. there is one transaction in play).

                  如果在 doSomething() 中抛出异常,那么它将被回滚,这意味着调用者也会看到事务被回滚.

                  If an exception is thrown inside doSomething() then it will be rolled back, meaning that the caller will also see the transaction rolled back.

                  当 doSomething() 返回时,事务还没有提交.提交事务(或可能回滚)的是调用者.

                  When doSomething() returns the transaction will not have been commited yet. It is the caller that will commit the transaction (or possibly rolled-back).

                  PROPAGATION_REQUIRES_NEW

                  class Service {
                      @Transactional(propagation=Propagation.REQUIRES_NEW)
                      public void doSomething() {
                          // access a database using a DAO
                      }
                  }
                  

                  当 doSomething() 被调用时,它会总是开始一个新的事务.

                  When doSomething() is called it will always start a new transaction.

                  如果这个方法的调用者已经开始了一个事务(TxnOuter),那么调用者的事务被挂起并且一个新的事务(TxnInner)被创建(即有两个事务在进行中).

                  If the caller of this method has already started a transaction (TxnOuter) then the callers' transaction is suspended and a new transaction (TxnInner) is created (i.e. there are two transactions in play).

                  如果在 doSomething() 中抛出异常,则 TxnInner 将被回滚,但来自调用者 (TxnOuter) 的暂停"事务不受影响.

                  If an exception is thrown inside doSomething() then TxnInner will be rolled back, but the "suspended" transaction from the caller (TxnOuter) is unaffected.

                  当 doSomething() 返回时没有异常,它将提交事务 (TxnInner).调用者的事务 (TxnOuter) 将被恢复并且不知道另一个事务已提交.然后,调用者可以根据需要提交或回滚 TxnOuter.

                  When doSomething() returns without an Exception it will commit the transaction (TxnInner). The caller's transaction (TxnOuter) will be resumed and be unaware that another transaction was commited. The caller can then commit or roll-back TxnOuter as it sees fit.

                  需要注意的重要一点是,数据库将 TxnOuter 和 TxnInner 视为完全独立的事务,因此是两个独立的提交.

                  The important point to note is that the Database views TxnOuter and TxnInner as completely independant transactions, and therefore two independant commits.

                  PROPAGATION_NESTED

                  class Service {
                      @Transactional(propagation=Propagation.NESTED)
                      public void doSomething() {
                          // access a database using a DAO
                      }
                  }
                  

                  只有当您的 JDBC 驱动程序和/或数据库支持 JDBC 保存点

                  NESTED can only be used if your JDBC driver and/or database supports JDBC savepoints

                  当 doSomething() 被调用时,它会开始一个新的事务如果调用者还没有开始一个事务.

                  When doSomething() is called it will start a new transaction if the caller has not already started a transaction.

                  如果这个方法的调用者已经开始了一个事务,那么调用者的事务被使用并且没有新的事务被创建(即有一个事务在运行).但是,当输入 doSomething() 时,事务上会标记一个保存点".

                  If the caller of this method has already started a transaction then the callers' transaction is used and no new transaction is created (i.e. there is one transaction in play). However a "savepoint" is marked on the transaction when doSomething() is entered.

                  如果在 doSomething() 中抛出异常,则事务可以部分回滚到保存点".调用者将继续进行交易.

                  If an Exception is thrown inside doSomething() then the transaction can be partially rolled back the transaction to the "savepoint". The caller will continue with the transaction.

                  当 doSomething() 返回时没有异常,调用者将提交整个事务(或回滚).

                  When doSomething() returns without an Exception it is the caller who will commit the entire transaction (or roll back).

                  需要注意的重要一点是数据库只查看一个事务并且只有一个提交.

                  The important point to note is that the Database views only one transaction and there is only one commit.

                  这篇关于外行术语中的 Spring 传播示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Struts 2 Convention Plugin 定义多个父包 下一篇:Java注解ElementType常量是什么意思?

                  相关文章

                  最新文章

                    1. <legend id='4Xkyr'><style id='4Xkyr'><dir id='4Xkyr'><q id='4Xkyr'></q></dir></style></legend>
                      <tfoot id='4Xkyr'></tfoot>

                    2. <i id='4Xkyr'><tr id='4Xkyr'><dt id='4Xkyr'><q id='4Xkyr'><span id='4Xkyr'><b id='4Xkyr'><form id='4Xkyr'><ins id='4Xkyr'></ins><ul id='4Xkyr'></ul><sub id='4Xkyr'></sub></form><legend id='4Xkyr'></legend><bdo id='4Xkyr'><pre id='4Xkyr'><center id='4Xkyr'></center></pre></bdo></b><th id='4Xkyr'></th></span></q></dt></tr></i><div id='4Xkyr'><tfoot id='4Xkyr'></tfoot><dl id='4Xkyr'><fieldset id='4Xkyr'></fieldset></dl></div>
                      • <bdo id='4Xkyr'></bdo><ul id='4Xkyr'></ul>
                    3. <small id='4Xkyr'></small><noframes id='4Xkyr'>