More lifecycle events required

5 posts, 0 answers
  1. Tomasz M.Lipiński
    Tomasz M.Lipiński avatar
    71 posts
    Member since:
    Nov 2009

    Posted 09 Apr 2010 Link to this post

    Hi,

    There are 3 events available via IInstanceCallbacks interface. It would be very nice to have this interface extended, including "PostStore" method. It should be called immedietely after commiting transaction and saving changes to the database.
    A simple use case: tracking creation and modifications of the object in a self-made event log. This cannot be done by PreStore because:
    • if the object is being created its ID (that is autoincrement type) is not known yet - the log entry cannot refer to this object
    • it is not good to write to the log in the same transaction - failing to write to the log will abandon the object's changes; but if I use another scope and transation to log and the main transaction would fail - there would be incorrect entry in the log

    Regards
    Tomasz

  2. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 12 Apr 2010 Link to this post

    Hello Tomasz M.Lipiński,
    You can just start a transaction on a 2nd scope, write your log entries there and if the first txn succeeds you can commit the second one. A global dictionary<scope, 2ndscope> can help to find the related 2nd scope if you are in a multi scopes scenario.

    Greetings,
    Jan Blessenohl
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft banner
  4. Tomasz M.Lipiński
    Tomasz M.Lipiński avatar
    71 posts
    Member since:
    Nov 2009

    Posted 22 Apr 2010 Link to this post

    Hi,
    As I understand it should be as follows:
    - begin transaction in the main scope (for creating and storing the main object)
    - create the main object
    - begin transaction in the 2nd scope
    - commit transaction in the main scope; this launches the PreStore method which creates a log object in the context of the 2nd scope
    - commit transaction in the 2nd scope; this updates the reference in the log object (writes the actual main object's ID)
    Do I understand it correctly?

    But this means that creating the log object cannot be "black-boxed" in the ORM class of the main object. Everyone who creates a new "main object" must know that something special must be done. This is something that I would like to avoid - the "PostStore" method would be the solution.

    Regards
    Tomasz
  5. Tomasz M.Lipiński
    Tomasz M.Lipiński avatar
    71 posts
    Member since:
    Nov 2009

    Posted 22 Apr 2010 Link to this post

    ... continued
    Another useful method would be "Initialize". This should be called immedietely after a new object has been created. It would be a place for filling fields like "creation date" or "unique identifier (GUID)": again, fields that are context-independent.
    This can be done in PreStore (on condition it is a new object). But in this case these values couldn't be used by anybody before commiting the transaction.

    Regards
    Tomasz
  6. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 23 Apr 2010 Link to this post

    Hi Tomasz M.Lipiński,
    We do not know about your new object before you call scope.Add(). The adding event is fired then. I have no idea where we can hook into the object construction. The default ctor is also called from our lower layer to create the query result. There you do not want to get events.

    One idea is to use a factory mechanism where you do not create your new objects everywhere in the code but by a factory call which can initialize and add the new object to the scope.

    Best wishes,
    Jan Blessenohl
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top
DevCraft banner