I have installed Quartz .NET and have created the Quartz database. I need to extend the Quartz job store with my own custom data. For example, when I add a job through the Quartz API, I need to add additional information to my own custom tables within the same database transaction. I know there is a class called JobStoreCMT in Quartz, but I have not been able to find any concise examples showing how to provide Quartz with the transaction that NHibernate creates.
Share
My understanding of the JobStoreCMT is that you declare all of your transactions using the classes in System.Transactions namespace that was introduced in .NET 2.0. Fortunately NHibernate operates well with these transactions as well, so you would put your Quartz operations and NHibernate operations in a single TransactionScope, like the following:
The code above assumes that elsewhere the following vars are declared and initialized:
The above code sample is not packed with detail, but this is the general idea.
One problem you may run into is that the above code will require a distributed transaction because the Quartz JobStoreCMT class creates one database connection, and the NHibernate session creates another database connection. Although it is possible (with SQL Server, at least) to have two different database connections share the same transaction, my understanding is that the current implementation of System.Transactions will upgraded the transaction to a distributed transaction with the opening of the second connection. This will have a significant effect on performance as a distributed transaction is significantly slower than a simple transaction.