انتقل إلى المحتوى
أمين أبوزيد
درس مخطط لهJNR-031-L02

حدود المعاملة

  • الدرس 2 من 8
  • Junior
في هذا الدرس 4 موضوعات

هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

في هذا الدرس

put the transaction around one business operation.

الموضوعات المخطط لها

  • The boundary is the business operation, for example "place order", not a single SQL statement.
  • Put @Transactional on 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.
تفاصيل المخطط المبدئي

عرض عملي

java
@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.

التطبيق

طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.

المختبر والتمارين الاختبار

تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.

اكتب للبحث في المستويات والمراحل والوحدات والدروس.