Package com.homannsoftware.transactions
Class CheckoutRepository
java.lang.Object
com.homannsoftware.transactions.CheckoutRepository
Executes parameterized SQL against the lab's single DataSource.
-
Constructor Summary
ConstructorsConstructorDescriptionCheckoutRepository(org.springframework.jdbc.core.JdbcTemplate jdbc) Creates the SQL adapter. -
Method Summary
Modifier and TypeMethodDescriptionvoidrecordOrder(String orderRef, String sku, int quantity) Inserts an order; a duplicate reference is a database constraint error.booleanDecrements stock only when enough stock is still available.
-
Constructor Details
-
CheckoutRepository
public CheckoutRepository(org.springframework.jdbc.core.JdbcTemplate jdbc) Creates the SQL adapter.- Parameters:
jdbc- Spring's transaction-aware JDBC helper
-
-
Method Details
-
reserve
Decrements stock only when enough stock is still available.- Parameters:
sku- product identifierquantity- positive amount, validated by the service- Returns:
- true if one inventory row was updated
-
recordOrder
Inserts an order; a duplicate reference is a database constraint error.- Parameters:
orderRef- unique order referencesku- reserved productquantity- reserved amount
-