حدود المعاملة
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
put the transaction around one business operation.
الموضوعات المخطط لها
- The boundary is the business operation, for example "place order", not a single SQL statement.
- Put
@Transactionalon service methods, not on controllers or repositories. - Repository calls inside join the service's transaction.
- Without a boundary each repository call commits alone, and a failure leaves partial data.
- Keep the business operation as one public service method.
تفاصيل المخطط المبدئي
عرض عملي
@Service
public class OrderService {
@Transactional
public Order placeOrder(PlaceOrderCommand cmd) {
stockService.reserve(cmd.lines()); // same transaction
return orderRepository.save(Order.from(cmd));
}
}اختبر فهمك
Which layer owns the transaction?
أظهر الإجابة
The service layer.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.