Seeing everything that is persisted
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:
- namespace Eco.Persistence
- {
- // Summary:
- // Base class for persistence handler.
- //
- // Remarks:
- // Use this class to implement your own IPersistenceHandler override any of
- // the virtual methods to inject your own behaviour and copy the Install-procedure
- // (from the source of this class) for a convenient way to install the new class
- // in the EcoSpace.
- public class ChainedPersistenceHandlerBase : IPersistenceHandler
- {
- public ChainedPersistenceHandlerBase(IEcoTypeSystem typeSystem);
- public bool IsPersistent { get; }
- public virtual int MaxSavedVersion { get; }
- public IPersistenceHandler NextPersistenceHandler { get; set; }
- public bool SupportsSync { get; }
- protected IEcoTypeSystem TypeSystem { get; }
- public virtual event LocatorArrayEventHandler ObjectsUpdated;
- public virtual void Fetch(ICollection<Locator> locators, int[] members, FetchStrategy FetchStrategy);
- public virtual ICollection<Locator> FetchLinksWithObjects(ICollection<Locator> objects, IAssociationEnd assocEnd);
- public virtual ICollection<Locator> GetAllWithCondition(AbstractCondition condition, int maxAnswers, int offset);
- public virtual Datablock GetValueWithCondition(AbstractCondition condition, int maxAnswers, int offset);
- public virtual void RetrieveChanges(out DBChangeCollection ignoredChanges);
- public virtual DateTime TimeForVersion(int version);
- public virtual void UpdateDatabaseWithList(ICollection<Locator> locators);
- public virtual int VersionAtTime(DateTime time);
- }
- }
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