Adding user code after commit

Posts   
 
    
Posts: 2
Joined: 22-Jul-2011
# Posted on: 22-Jul-2011 17:50:26   

We have a rather large application built off of LLBL, and have discovered that somehow users are able to throw off some of our denormalized data through some unknown action. When the data is off, it is not apparent until months later, in which we need to go in a correct a few tables.

We would like to run a series of audit / checks against the data everytime a save happens that touches one or more of 4 specific tables. Basically, if data is added to one table, it needs to be delete from another. If we check at the time of SaveEntity, it is possible that we run an audit before the second command runs. We would like to run our audit after the entire commit / transaction has been completed, and then if the audit fails, we are planning on kicking out an email with the full stack trace, without alerting the user.

Where in the LLBL Adapter code would we place code to execute after a transaction / commit has completed?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-Jul-2011 22:55:00   

At your DBSpecific project you can create a partial class file and override this method:

using SD.LLBLGen.Pro.ORMSupportClasses;

namespace NW.LLBL.MSSQL.Adapter.v31.DatabaseSpecific
{
    public partial class DataAccessAdapter
    {       
        protected override void OnAfterTransactionCommit()
        {
            // .., you code
            base.OnAfterTransactionCommit();
        }
    }
}

Now how would you put those validations in there? Maybe the best way would be to call some ActionProcedure that return true/false and maybe an error message. That's up to you.

David Elizondo | LLBLGen Support Team
Posts: 2
Joined: 22-Jul-2011
# Posted on: 22-Jul-2011 22:58:01   

That is exactly where I ended up. Except that I am first checking the entity type within OnSaveEntityCollectionComplete to see if one of the specific entities is being touched. If it is being touched, then I am adding its ID to a list so that I can loop through the list within OnAfterTransactionCommit since OnAfterTransactionCommit doesn't have any parameters, I'm capturing the entities earlier in the cycle.