Seeing everything that is persisted
(Adding message template to the top of the page)
(Updated Edited template to July 12, 2025.)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{message|Write the content here to display this box}}
<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 83: Line 83:
</div>
</div>
[[Category:Database]]
[[Category:Database]]
{{Edited|July|12|2024}}
{{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:

  1. public class UpdateHandler : ChainedPersistenceHandlerBase
  2. {
  3.   private readonly IObjectRepresentationProvider orp;
  4.   public UpdateHandler(IObjectRepresentationProvider orp, IEcoTypeSystem typeSystem)
  5.     : base(typeSystem)
  6.   {
  7.     this.orp = orp;
  8.   }
  9.   public override void UpdateDatabaseWithList(ICollection<Locator> locators)
  10.   {
  11.     DateTime timestamp = DateTime.Now;
  12.     foreach (Locator loc in locators)
  13.     {
  14.       IObject obj = orp.IObjectForLocator(loc);
  15.       if (obj.AsObject is ITrackUpdate)
  16.       {
  17.         (obj.AsObject as ITrackUpdate).PreUpdate(timestamp);
  18.       }
  19.     }
  20.     base.UpdateDatabaseWithList(locators);
  21.   }
  22. }

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…

  1. public class UpdateHandler : ChainedPersistenceHandlerBase
  2. {
  3.   private readonly IObjectRepresentationProvider orp;
  4.   public UpdateHandler(IObjectRepresentationProvider orp, IEcoTypeSystem typeSystem)
  5.     : base(typeSystem)
  6.   {
  7.     this.orp = orp;
  8.   }
  9.   public override void UpdateDatabaseWithList(ICollection<Locator> locators)
  10.   {
  11.     DateTime timestamp = DateTime.Now;
  12.     foreach (Locator loc in locators)
  13.     {
  14.       IObject obj = orp.IObjectForLocator(loc);
  15.       if (obj.AsObject is ITrackUpdate)
  16.       {
  17.         (obj.AsObject as ITrackUpdate).PreUpdate(timestamp);
  18.       }
  19.     }
  20.     base.UpdateDatabaseWithList(locators);
  21.   }
  22. }

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:

  1. // Install the update handler which intercepts all updates and updated the "Modified" attribute
  2. UpdateHandler uh = new UpdateHandler(FrontsidePolicy.ObjectRepresentationProvider, TypeSystem);
  3. PersistenceServiceImpl ps = Persistence as PersistenceServiceImpl;
  4. uh.NextPersistenceHandler = ps.PersistenceHandler;
  5. ps.PersistenceHandler = uh;
  6. FrontsidePolicy.PersistenceHandler = uh;