Integrate Quartz .NET with NHibernate -
i have installed quartz .net , have created quartz database. need extend quartz job store own custom data. example, when add job through quartz api, need add additional information own custom tables within same database transaction. know there class called jobstorecmt in quartz, have not been able find concise examples showing how provide quartz transaction nhibernate creates.
my understanding of jobstorecmt declare of transactions using classes in system.transactions namespace introduced in .net 2.0. fortunately nhibernate operates these transactions well, put quartz operations , nhibernate operations in single transactionscope, following:
using (var ts = new transactionscope()) { // scheduler here, eg _scheduler.schedulejob(somejobdetail, sometrigger); // create nhibernate session part of same transaction using (var session = _sessionfactory.opensession()) { // perform actions on session here, *not* make use of // nhibernate transaction methods, such isession.begintransaction(), // because transaction controlled via transactionscope instance. } ts.complete(); }
the code above assumes elsewhere following vars declared , initialized:
quartz.ischeduler _scheduler; nhibernate.isessionfactory _sessionfactory;
the above code sample not packed detail, general idea.
one problem may run above code require distributed transaction because quartz jobstorecmt class creates 1 database connection, , nhibernate session creates database connection. although possible (with sql server, @ least) have 2 different database connections share same transaction, understanding current implementation of system.transactions upgraded transaction distributed transaction opening of second connection. have significant effect on performance distributed transaction slower simple transaction.
Comments
Post a Comment