Java Reference
In-Depth Information
Table 4-7. Sample Data in the BOOK Table for Testing Propagation Behaviors
ISBN
BOOK_NAME
PRICE
0001
The First Book
30
0002
The Second Book
50
Table 4-8. Sample Data in the BOOK_STOCK Table for Testing Propagation Behaviors
ISBN
STOCK
0001
10
0002
10
Table 4-9. Sample Data in the ACCOUNT Table for Testing Propagation Behaviors
USERNAME
BALANCE
user1
40
The REQUIRED Propagation Behavior
When the user user1 checks out the two books from the cashier, the balance is sufficient to purchase the
first book, but not the second.
package com.apress.springenterpriserecipes.bookshop.spring;
...
public class Main {
public static void main(String[] args) {
...
Cashier cashier = (Cashier) context.getBean( " cashier " );
List<String> isbnList =
Arrays.asList(new String[] { " 0001 " , " 0002 " });
cashier.checkout(isbnList, " user1 " );
}
}
When the book shop's purchase() method is called by another transactional method, such as
checkout() , it will run within the existing transaction by default. This default propagation behavior is
called REQUIRED . That means there will be only one transaction whose boundary is the beginning and
ending of the checkout() method. This transaction will be committed only at the end of the checkout()
method. As a result, the user can purchase none of the books. Figure 4-3 illustrates the REQUIRED
propagation behavior.
Search WWH ::




Custom Search