انتقل إلى المحتوى
أمين أبوزيد
MID-022

بدائل التخزين الدائم (Persistence)

  • 5 درس
  • 2.5 ساعة تدريب (تقدير)
في هذه الصفحة 8 موضوعات

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

نظرة عامة

الموضوعات

  • jOOQ
  • مقايضات JDBC مقابل JPA
  • نماذج القراءة في CQRS

تعلّم أولًا

2.5 ساعة تدريب (تقدير)

مخرجات التعلم

  1. Write type-safe SQL with jOOQ, generated from the schema.
  2. Compare JDBC, jOOQ, and JPA for a given use case and justify a choice.
  3. Build a separate read model for queries (CQRS-lite) inside one service.

الدروس

  1. 01متى تكون JPA الأداة الخاطئة
  2. 02jOOQ عمليًا
  3. 03اختيار أسلوب التخزين الدائم
  4. 04نماذج القراءة وCQRS المبسّط
  5. 05عرض عملي: إعادة كتابة تقرير المبيعات باستخدام jOOQ

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

Lab

MID-022-LAB1 · Dashboard read model

Outcomes: 1–3 · Time: ~3 h Build an admin dashboard for Shop (orders and revenue per day, top products): a dashboard_daily read-model table updated when orders are placed, queried with jOOQ, with a rebuild command. Write a decision record comparing JDBC, jOOQ, and JPA for this feature. Acceptance: a written decision record comparing the three approaches; the dashboard served from the read model with a working rebuild.

Exercises (assessment: decision-record review)

IDOutcomeTask
MID-022-EX011Configure jOOQ code generation from the Flyway-migrated schema in the build.
MID-022-EX021Write a jOOQ query with a join, group by, and filter, and map it to a DTO.
MID-022-EX032Choose JDBC, jOOQ, or JPA for: order placement, monthly report, bulk price update, product CRUD. Justify.
MID-022-EX042Explain how JPA and jOOQ can share one transaction in a Spring service.
MID-022-EX053Design a read-model table for the dashboard and decide how it is updated (same transaction or event) and why.
MID-022-EX063Write the rebuild query that recreates the read model from the write tables.
أظهر الحلول
  • EX01 jOOQ code generator plugin pointing to a Testcontainers/PostgreSQL database after Flyway migration; generated sources added to the build.
  • EX02 dsl.select(...).from(...).join(...).on(...).where(...).groupBy(...).fetchInto(Dto.class).
  • EX03 Order placement: JPA. Monthly report: jOOQ. Bulk price update: set-based SQL via jOOQ or JDBC. Product CRUD: JPA. Check the justification.
  • EX04 Both use the same DataSource and Spring transaction manager; DSLContext uses the transaction-bound connection.
  • EX05 For example dashboard_daily(day pk, orders, revenue); update in the same transaction for exact numbers or from an after-commit event for looser coupling; state staleness.
  • EX06 INSERT ... SELECT date_trunc('day', created_at), count(*), sum(total_cents) FROM orders GROUP BY 1 ON CONFLICT (day) DO UPDATE ....
  • Mixing without boundaries and full event-sourced CQRS for simple reads are covered by EX03, EX05, and the decision record.

الاختبار

Outcomes: O1 jOOQ · O2 comparing approaches · O3 read models.

اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.

  1. 1jOOQ generates classes from:O1
  2. 2A main benefit of jOOQ over SQL strings:O1
  3. 3jOOQ queries run in the same Spring transaction when they:O1
  4. 4Best fit for JPA:O2
  5. 5Best fit for jOOQ:O2
  6. 6JDBC (JdbcClient) trades convenience for:O2
  7. 7Mixing persistence approaches in a service is acceptable when:O2
  8. 8CQRS-lite means:O3
  9. 9A read model updated in the same transaction as the order is:O3
  10. 10A needed safety feature for a read model:O3

الجزء العملي

Decision-record review: assess a written record comparing JDBC, jOOQ, and JPA for the dashboard (criteria, trade-offs, decision, consequences). Pass: quiz 8/10, a decision record covering all three options with a justified choice, and the lab dashboard running from its read model.

أخطاء شائعة

Mixing approaches without boundaries; full CQRS with event sourcing for simple reads.

التقييم

Decision-record review.

الصلة بالمسار الوظيفي

CQRS and materialized views (SRB-001).

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