This is a migrated thread and some comments may be shown as answers.

More lifecycle events required

4 Answers 56 Views
Feature Requests
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tomasz M.Lipiński
Top achievements
Rank 1
Tomasz M.Lipiński asked on 09 Apr 2010, 11:16 PM
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

4 Answers, 1 is accepted

Sort by
0
Jan Blessenohl
Telerik team
answered on 12 Apr 2010, 04:02 PM
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.
0
Tomasz M.Lipiński
Top achievements
Rank 1
answered on 22 Apr 2010, 10:28 AM
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
0
Tomasz M.Lipiński
Top achievements
Rank 1
answered on 22 Apr 2010, 10:52 AM
... 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
0
Jan Blessenohl
Telerik team
answered on 23 Apr 2010, 11:59 AM
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.
Tags
Feature Requests
Asked by
Tomasz M.Lipiński
Top achievements
Rank 1
Answers by
Jan Blessenohl
Telerik team
Tomasz M.Lipiński
Top achievements
Rank 1
Share this question
or