Seeing everything that is persisted
No edit summary |
No edit summary |
||
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: | ||
Line 35: | Line 35: | ||
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 | 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="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;"> | ||
Line 67: | Line 67: | ||
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 id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9259e046-ad23-4f69-b77e-ec15cd0d3597" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;"> |
Revision as of 06:44, 14 March 2023
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