Seeing everything that is persisted
m ((username removed) (log details removed): Moving to Documentation namespace) |
(Updated Edited template to July 12, 2025.) |
||
(3 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
<message>Write the content here to display this box</message> | |||
There is something called a ChainedPersistenceHandlerBase you can inherit from and intercept everything that goes to and from the database. | There is something called a ChainedPersistenceHandlerBase you can inherit from and intercept everything that goes to and from the database. | ||
Line 82: | Line 83: | ||
</div> | </div> | ||
[[Category:Database]] | [[Category:Database]] | ||
{{Edited|July|12|2025}} |
Latest revision as of 06:01, 20 January 2025
This page was created by Alexandra on 2018-11-28. Last edited by Edgar on 2025-01-20.
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;