Note that there are some explanatory texts on larger screens.

plurals
  1. POSaving complex aggregates using Repository Pattern
    primarykey
    data
    text
    <p>We have a complex aggregate (sensitive names obfuscated for confidentiality reasons).</p> <p>The root, R, is composed of collections of Ms, As, Cs, Ss. Ms have collections of other low-level details. etc etc</p> <p>R really is an aggregate (no fair suggesting we split it!)</p> <p>We use lazy loading to retrieve the details. No problem there.</p> <p>But we are struggling a little with how to save such a complex aggregate. </p> <p>From the caller's point of view:</p> <pre><code>r = repository.find(id); r.Ps.add(factory.createP()); r.Cs[5].updateX(123); r.Ms.removeAt(5); repository.save(r); </code></pre> <p>Our competing solutions are:</p> <ol> <li><p>Dirty flags Each entity in the aggregate in the aggregate has a dirty flag. The save() method in the repository walks the tree looking for dirty objects and saves them. Deletes and adds are a little trickier - especially with lazy-loading - but doable.</p></li> <li><p>Event listener accumulates changes. Repository subscribes a listener to changes and accumulates events. When save is called, the repository grabs all the change events and writes them to the DB.</p></li> <li><p>Give up on repository pattern. Implement overloaded save methods to save the parts of the aggregate separately. The original example would become:</p> <p>r = repository.find(id); r.Ps.add(factory.createP()); r.Cs[5].updateX(123); r.Ms.removeAt(5); repository.save(r.Ps); repository.save(r.Cs); repository.save(r.Ms);</p></li> </ol> <p>(or worse)</p> <p>Advice please! What should we do?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload