TObjectManager Events

Hi there...


I was looking on Aurelius code and could not find what I am going to ask.

I was looking for a way to catch events of Save/Update of the manager.

I can eventually create my own Save, but I was thinking in using the ObjectManager because the TAureliusDataSets also Save;/Update using it.

My intention is catch something like BeforeSave/AfterSave or something similar, in a way that I could ask my entity to be prepared to be saved and check consistency. And also I have to generate a LOG of operations, that could be the correct moment for that.

The problem keeps bugging me is that TAureliusDataset is somehow autonomous of the rest of the structure (in my use case at least) and it does things that the rest of my structure is not aware, since dataset is only a visual way to use livebinding for me.

I need a centralized way, that is not control based (ie, not dropping a control in the form) where I could handle this kind of events when persisting the entities. I believe this could be at TObjectManager level (I have one of this for each model, similar the Music example)

Is there something like that possible?

Unfortunately no, and this is one of the most request features for Aurelius: http://www.tmssoftware.com/site/aurelius.asp?s=fr&id=1206#fr

We have it in our todo list to include it as soon as possible. The workaround, for now, is indeed create your repository class and perform all save/update operations through there.

Exactly that. I have upvoted either.

Well, certainly you are very aware of the need, but just stressing it a little to make that request more complete ( i did not see a way to add to that request description):

  • centralized events on the TObjectManager (or related) for ANY data operation with the manager, including the TAureliusDataSet events (probably when using TAureliusDataSet it will have 2 places generating events, not sure about that, it can be useful eventually)
  • Same events on TObjectManager that there is on TAureliusDataSet, or at least the ones that are not DataSet-only related
  • One that is specially important is when a New Entity is needed to be created, there is a need to have a centralized way to create and initialize the Entity. Even if the Aurelius load the data from the database the Entity can have more information, specially about context that needs to be initialized . My classes are getting complex.
  • Possibility to "cancel/abort" the operation when saving/updating. This is needed when the save/update is requested and I have to ask the Entity if it is ok to be saved. Eventually the object have something missing and it is not able to continue, then the save/update needs to stopped in a way that can be recovered. (to ask user input etc then goes back to saving again)
thank you, right now I will be following the repository class way.

Wagner,


Another question.... When I retrieve a TList<TEntity> many TEntities will be created. That case I have no way to initialize the TEntities first?

I was right now centralizing in the code the object creation, and noted that ObjectManager.FindAll<E> for example, like others, generated a list with the objects. 

In this case I should go to every created list to update the entities created by Aurelius? The major thing is that I need to remember that in the code always as part of any object retrieval.

Yes, for now, Aurelius creates automatically all objects loaded from database. We plan to add an object factory feature. Actually it already uses an object factory, but for now that factory is a singleton and cannot be changed.


Looking further, I see that in ManyValuedAssociation and other associations Aurelius automatically save (I am Using CascadeTypeAll) the associated TList entities.

I am implementing a centralized save, instead of using TObjectManager.Save, then I can intercept the entity before saving.

However in this case the association list could have entities that will be automatically save.

How aurelius knows which ones are going to be saved? Since is the master entity that was called to be saved, how could i cross the associatioin list and find out which ones are going to be saved?

Or any sugestion here?

Thank you!

If you call SaveOrUpdate, it only saves the ones that don't have an id. Later on, when you call Flush, it will update the ones that have any property modified.

thanks,


"If you call SaveOrUpdate, it only saves the ones that don't have an id."
so the ID is only defined at save/update for new ones? that is a way to identify a new created object. I decided to use only TGUID in FID and generated by aurelius to not fight against the elements :)

"when you call Flush, it will update the ones that have any property modified"

How aurelius identify it? Is it somehow exposed? (can I go thru the objects and know which one is candidate for flush?)

This is something that I am also struggling, since i need to implement a way to the Entity knows if it was changed or not. There are some operations to happen when it got changed. 

guid follows the same approach, if the guid is null, object will be saved and a new valid guid will be assigned to the object.

Unfortunately info you requested is not exposed. That's what will be part of the event/callback system of save/update operations.