| 22352 |
ashik.ali |
1 |
package com.spice.profitmandi.dao.repository.user;
|
|
|
2 |
|
| 36376 |
aman |
3 |
import java.util.List;
|
|
|
4 |
|
| 22352 |
ashik.ali |
5 |
import org.springframework.stereotype.Repository;
|
|
|
6 |
|
|
|
7 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 36376 |
aman |
8 |
import com.spice.profitmandi.dao.cart.v2.CartLifecycleStatus;
|
|
|
9 |
import com.spice.profitmandi.dao.cart.v2.SaleType;
|
| 22352 |
ashik.ali |
10 |
import com.spice.profitmandi.dao.entity.user.Cart;
|
|
|
11 |
|
|
|
12 |
@Repository
|
|
|
13 |
public interface CartRepository {
|
|
|
14 |
public void persist(Cart cart);
|
|
|
15 |
public Cart selectById(int id) throws ProfitMandiBusinessException;
|
| 36376 |
aman |
16 |
|
|
|
17 |
/**
|
| 37706 |
amit |
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 |
/**
|
| 36376 |
aman |
34 |
* Authorization-aware lookup: returns the cart only if it belongs to the
|
|
|
35 |
* given retailer AND matches the expected sale type. Used by
|
|
|
36 |
* V2BillingController so one partner cannot touch another partner's draft.
|
|
|
37 |
*/
|
|
|
38 |
public Cart findByIdAndRetailerAndSaleType(int id, int retailerId, SaleType saleType);
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* All open tertiary drafts for a partner (most recent first). Procurement
|
|
|
42 |
* carts and closed tertiary carts are excluded.
|
|
|
43 |
*/
|
|
|
44 |
public List<Cart> findActiveDraftsByRetailer(int retailerId, SaleType saleType, CartLifecycleStatus status);
|
| 22352 |
ashik.ali |
45 |
}
|