Seeing everything that is persisted
No edit summary |
(Automatically adding template at the end of the page.) |
||
(7 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
There is something called a ChainedPersistenceHandlerBase | There is something called a ChainedPersistenceHandlerBase you can inherit from and intercept everything that goes to and from the database. | ||
You can use override as you see fit: | You can use override as you see fit: | ||
<div | <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4ec7f1f8-600a-44ef-972a-92308fe10bc8" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;"> | ||
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"> | |||
<div style="background: #fff; overflow: auto;"> | |||
<ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> | |||
<li><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> <span style="color: #2b91af;">UpdateHandler</span> : <span style="color: #2b91af;">ChainedPersistenceHandlerBase</span></li> | |||
<li style="background: #f3f3f3;">{</li> | |||
<li> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">readonly</span> <span style="color: #2b91af;">IObjectRepresentationProvider</span> orp;</li> | |||
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">public</span> UpdateHandler(<span style="color: #2b91af;">IObjectRepresentationProvider</span> orp, <span style="color: #2b91af;">IEcoTypeSystem</span> typeSystem)</li> | |||
<li> : <span style="color: #0000ff;">base</span>(typeSystem)</li> | |||
<li style="background: #f3f3f3;"> {</li> | |||
<li> <span style="color: #0000ff;">this</span>.orp = orp;</li> | |||
<li style="background: #f3f3f3;"> }</li> | |||
<li> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> UpdateDatabaseWithList(<span style="color: #2b91af;">ICollection</span><<span style="color: #2b91af;">Locator</span>> locators)</li> | |||
<li style="background: #f3f3f3;"> {</li> | |||
<li> <span style="color: #2b91af;">DateTime</span> timestamp = <span style="color: #2b91af;">DateTime</span>.Now;</li> | |||
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">foreach</span> (<span style="color: #2b91af;">Locator</span> loc <span style="color: #0000ff;">in</span> locators)</li> | |||
<li> {</li> | |||
<li style="background: #f3f3f3;"> <span style="color: #2b91af;">IObject</span> obj = orp.IObjectForLocator(loc);</li> | |||
<li> <span style="color: #0000ff;">if</span> (obj.AsObject <span style="color: #0000ff;">is</span> <span style="color: #2b91af;">ITrackUpdate</span>)</li> | |||
<li style="background: #f3f3f3;"> {</li> | |||
<li> (obj.AsObject <span style="color: #0000ff;">as</span> <span style="color: #2b91af;">ITrackUpdate</span>).PreUpdate(timestamp);</li> | |||
<li style="background: #f3f3f3;"> }</li> | |||
<li> }</li> | |||
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">base</span>.UpdateDatabaseWithList(locators);</li> | |||
<li> }</li> | |||
<li style="background: #f3f3f3;">}</li> | |||
</ol> | |||
</div> | |||
</div> | |||
</div> | |||
Maybe you have a common base class for all classes in your model, and maybe this class implements an Interface ITrackUpdate, then it would be a good thing to catch all updates and set the DateTime… | |||
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"> | |||
<div style="background: #fff; overflow: auto;"> | |||
<ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> | |||
<li><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> <span style="color: #2b91af;">UpdateHandler</span> : <span style="color: #2b91af;">ChainedPersistenceHandlerBase</span></li> | |||
<li style="background: #f3f3f3;">{</li> | |||
<li> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">readonly</span> <span style="color: #2b91af;">IObjectRepresentationProvider</span> orp;</li> | |||
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">public</span> UpdateHandler(<span style="color: #2b91af;">IObjectRepresentationProvider</span> orp, <span style="color: #2b91af;">IEcoTypeSystem</span> typeSystem)</li> | |||
<li> : <span style="color: #0000ff;">base</span>(typeSystem)</li> | |||
<li style="background: #f3f3f3;"> {</li> | |||
<li> <span style="color: #0000ff;">this</span>.orp = orp;</li> | |||
<li style="background: #f3f3f3;"> }</li> | |||
<li> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> UpdateDatabaseWithList(<span style="color: #2b91af;">ICollection</span><<span style="color: #2b91af;">Locator</span>> locators)</li> | |||
<li style="background: #f3f3f3;"> {</li> | |||
<li> <span style="color: #2b91af;">DateTime</span> timestamp = <span style="color: #2b91af;">DateTime</span>.Now;</li> | |||
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">foreach</span> (<span style="color: #2b91af;">Locator</span> loc <span style="color: #0000ff;">in</span> locators)</li> | |||
<li> {</li> | |||
<li style="background: #f3f3f3;"> <span style="color: #2b91af;">IObject</span> obj = orp.IObjectForLocator(loc);</li> | |||
<li> <span style="color: #0000ff;">if</span> (obj.AsObject <span style="color: #0000ff;">is</span> <span style="color: #2b91af;">ITrackUpdate</span>)</li> | |||
<li style="background: #f3f3f3;"> {</li> | |||
<li> (obj.AsObject <span style="color: #0000ff;">as</span> <span style="color: #2b91af;">ITrackUpdate</span>).PreUpdate(timestamp);</li> | |||
<li style="background: #f3f3f3;"> }</li> | |||
<li> }</li> | |||
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">base</span>.UpdateDatabaseWithList(locators);</li> | |||
<li> }</li> | |||
<li style="background: #f3f3f3;">}</li> | |||
</ol> | |||
</div> | |||
</div> | |||
We need to install our ChainedPersistenceHandlerBase baseclass. We do this by mixing it in before the current | We need to install our ChainedPersistenceHandlerBase baseclass. We do this by mixing it in before the current PersistenceHandler. We do this in the ecospace – before we go active: | ||
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9259e046-ad23-4f69-b77e-ec15cd0d3597" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;"> | |||
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"> | |||
<div style="background: #fff; overflow: auto;"> | |||
<ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> | |||
<li><span style="color: #008000;">// Install the update handler which intercepts all updates and updated the "Modified" attribute</span></li> | |||
<li style="background: #f3f3f3;"><span style="color: #2b91af;">UpdateHandler</span> uh = <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">UpdateHandler</span>(FrontsidePolicy.ObjectRepresentationProvider, TypeSystem);</li> | |||
<li><span style="color: #2b91af;">PersistenceServiceImpl</span> ps = Persistence <span style="color: #0000ff;">as</span> <span style="color: #2b91af;">PersistenceServiceImpl</span>;</li> | |||
<li style="background: #f3f3f3;">uh.NextPersistenceHandler = ps.PersistenceHandler;</li> | |||
<li>ps.PersistenceHandler = uh;</li> | |||
<li style="background: #f3f3f3;">FrontsidePolicy.PersistenceHandler = uh;</li> | |||
</ol> | |||
</div> | |||
</div> | |||
</div> | |||
[[Category:Database]] | |||
{{Edited|July|12|2024}} |
Latest revision as of 15:46, 10 February 2024
There is something called a ChainedPersistenceHandlerBase you can inherit from and intercept everything that goes to and from the database.
You can use override as you see fit:
- public class UpdateHandler : ChainedPersistenceHandlerBase
- {
- private readonly IObjectRepresentationProvider orp;
- public UpdateHandler(IObjectRepresentationProvider orp, IEcoTypeSystem typeSystem)
- : base(typeSystem)
- {
- this.orp = orp;
- }
- public override void UpdateDatabaseWithList(ICollection<Locator> locators)
- {
- DateTime timestamp = DateTime.Now;
- foreach (Locator loc in locators)
- {
- IObject obj = orp.IObjectForLocator(loc);
- if (obj.AsObject is ITrackUpdate)
- {
- (obj.AsObject as ITrackUpdate).PreUpdate(timestamp);
- }
- }
- base.UpdateDatabaseWithList(locators);
- }
- }
Maybe you have a common base class for all classes in your model, and maybe this class implements an Interface ITrackUpdate, then it would be a good thing to catch all updates and set the DateTime…
- public class UpdateHandler : ChainedPersistenceHandlerBase
- {
- private readonly IObjectRepresentationProvider orp;
- public UpdateHandler(IObjectRepresentationProvider orp, IEcoTypeSystem typeSystem)
- : base(typeSystem)
- {
- this.orp = orp;
- }
- public override void UpdateDatabaseWithList(ICollection<Locator> locators)
- {
- DateTime timestamp = DateTime.Now;
- foreach (Locator loc in locators)
- {
- IObject obj = orp.IObjectForLocator(loc);
- if (obj.AsObject is ITrackUpdate)
- {
- (obj.AsObject as ITrackUpdate).PreUpdate(timestamp);
- }
- }
- base.UpdateDatabaseWithList(locators);
- }
- }
We need to install our ChainedPersistenceHandlerBase baseclass. We do this by mixing it in before the current PersistenceHandler. We do this in the ecospace – before we go active:
- // Install the update handler which intercepts all updates and updated the "Modified" attribute
- UpdateHandler uh = new UpdateHandler(FrontsidePolicy.ObjectRepresentationProvider, TypeSystem);
- PersistenceServiceImpl ps = Persistence as PersistenceServiceImpl;
- uh.NextPersistenceHandler = ps.PersistenceHandler;
- ps.PersistenceHandler = uh;
- FrontsidePolicy.PersistenceHandler = uh;
This page was edited more than 11 months ago on 02/10/2024. What links here