| Line 13... |
Line 13... |
| 13 |
public interface CartRepository {
|
13 |
public interface CartRepository {
|
| 14 |
public void persist(Cart cart);
|
14 |
public void persist(Cart cart);
|
| 15 |
public Cart selectById(int id) throws ProfitMandiBusinessException;
|
15 |
public Cart selectById(int id) throws ProfitMandiBusinessException;
|
| 16 |
|
16 |
|
| 17 |
/**
|
17 |
/**
|
| - |
|
18 |
* The cart row, locked FOR UPDATE, as the first statement of anything that mutates this cart.
|
| - |
|
19 |
*
|
| - |
|
20 |
* This exists to fix a lock-ordering deadlock, not to guard a read. Two request paths used to
|
| - |
|
21 |
* take the same two rows in opposite orders: adding a line INSERTs into user.line, whose
|
| - |
|
22 |
* line_cart_id_fk shared-locks the parent cart FIRST and the line second, while validation
|
| - |
|
23 |
* mutated the line rows FIRST and wrote cart.total_price second. Run concurrently on one cart
|
| - |
|
24 |
* that is a cycle, and InnoDB rolls one side back ("Deadlock found when trying to get lock").
|
| - |
|
25 |
* Taking the cart row here, before any line is touched, gives every path the same cart -> line
|
| - |
|
26 |
* order and makes the cycle impossible. It also serialises concurrent edits to the SAME cart,
|
| - |
|
27 |
* which is what the @Version column on Cart was already trying and failing to express.
|
| - |
|
28 |
*
|
| - |
|
29 |
* Different carts are different rows, so this costs nothing across partners.
|
| - |
|
30 |
*/
|
| - |
|
31 |
public Cart selectByIdForUpdate(int id);
|
| - |
|
32 |
|
| - |
|
33 |
/**
|
| 18 |
* Authorization-aware lookup: returns the cart only if it belongs to the
|
34 |
* Authorization-aware lookup: returns the cart only if it belongs to the
|
| 19 |
* given retailer AND matches the expected sale type. Used by
|
35 |
* given retailer AND matches the expected sale type. Used by
|
| 20 |
* V2BillingController so one partner cannot touch another partner's draft.
|
36 |
* V2BillingController so one partner cannot touch another partner's draft.
|
| 21 |
*/
|
37 |
*/
|
| 22 |
public Cart findByIdAndRetailerAndSaleType(int id, int retailerId, SaleType saleType);
|
38 |
public Cart findByIdAndRetailerAndSaleType(int id, int retailerId, SaleType saleType);
|