integrating semi-automatic history management

Posts   
 
    
Asimov
User
Posts: 113
Joined: 05-Dec-2003
# Posted on: 06-Dec-2004 18:08:37   

Hi,

In almost every application, we need to create code to keep an history of all the data for our main tables. We used to work with triggers, but I would like to integrate something into the generated LLBL code. I thought about creating a method SaveHistory in each derived entity class, override the Save method and in the new Save method, I would call the SaveHistory method and then the Save method (to be able to save the old entity values). Do you see any problems in doing so? Or is there something similar that already exists in llbl?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 07-Dec-2004 11:32:32   

Your suggestion can work. Just set the proper IsNew/IsDirty flags to true to make the insert work (and alter the SourceObjectName (and set it back afterwards!) to save into the proper table wink ). Be sure to start a transaction.

Though, I think a trigger would be easier in this case I think.

Frans Bouma | Lead developer LLBLGen Pro
Asimov
User
Posts: 113
Joined: 05-Dec-2003
# Posted on: 07-Dec-2004 14:28:18   

The thing is that we need to save the Id of the user currently logged in who made the changes, and currently we have to save this id in a temporary table just before running the save, so we have these calls everywhere. Do you know a better way of passing a variable from the Session to an SQL Server (even tough this has nothing to do with llbl... flushed )

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 07-Dec-2004 14:49:17   

No, that's pretty hard I think. I think the save method override is the proper way to do it.

Frans Bouma | Lead developer LLBLGen Pro
Asimov
User
Posts: 113
Joined: 05-Dec-2003
# Posted on: 07-Dec-2004 20:42:58   

But if I add dstinct code to save stuff in my History table before each genuine Save call to an entity, why would I need to play around with the IsDirty/IsNew flags and what do you mean by the SourceObjectName? simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 08-Dec-2004 09:16:14   

Asimov wrote:

But if I add dstinct code to save stuff in my History table before each genuine Save call to an entity, why would I need to play around with the IsDirty/IsNew flags and what do you mean by the SourceObjectName? simple_smile

heh, I think we have a misunderstanding going on wink . What I thought was: you have this entity, say myCustomer, and you want that to be saved in the CustomerHistory table as well. So instead of creating a new entity, copying all fields, I simply altered the original entity a bit and make it save in the CustomerHistory table.

Which is one way to do it of course, another is to just create a history entity, copy the values over and save that one (which is probably a better way to do it anyway, as you can add more fields to the history entity as well, like date of save, who made the change etc.)

Frans Bouma | Lead developer LLBLGen Pro
Asimov
User
Posts: 113
Joined: 05-Dec-2003
# Posted on: 08-Dec-2004 15:42:40   

hehe simple_smile what I wanted to do is in my new Save method is something like:


HistoryEntity.Create(some parameters);
this.Save();