Seeing everything that is persisted
No edit summary |
No edit summary |
||
Line 63: | Line 63: | ||
<li style="background: #f3f3f3;">}</li> | <li style="background: #f3f3f3;">}</li> | ||
</ol> | </ol> | ||
</div> | </div> | ||
</div> | </div> |
Revision as of 16:30, 28 November 2018
There is something called a ChainedPersistenceHandlerBase that 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