I think my key problem is that I am trying to contain the logic to retry a query or criteria (execute or list) if interrupted due to a broken connection. I would like to contain that logic in one place. Implementing a connection driver will allow me to make several attempts to obtain the connection, but once I obtain it and begin working with it, and it gets broken in between, I may want to create a new session and retry it.
The problem is that in my DAO objects, I obtain the session, create ICriteria or IQuery and setit up. That requires knowledge of the domain so it is better at that level. What I would like to do is then pass that to a common method that would execute it in a try/catch. If an exception is caught that indicates a broken connection, then while in that method, I would like to create a new session, bind that query or criteria to the new session and then re-try. What I am missing really is how to re-bind an already prepared IQuery or ICritera to a different session object. On Wednesday, April 16, 2014 8:39:41 PM UTC-5, Craig wrote: > > Have a look at https://github.com/MRCollective/NHibernate.SqlAzure > > It says it is for Azure but will work the same without. > > > On Thu, Apr 17, 2014 at 8:16 AM, Waqar Sadiq <[email protected]<javascript:> > > wrote: > >> Graham, >> >> We use ICriteria and IQuery quite a lot. I need to centralize the retry >> logic so that if connection is lost, it should be re-established and >> retried. I am looking for a common set of methods that can take a prepared >> ICrietria or a prepared IQuery object and execute it and then retry upto >> maximum number of attempts if needed. Do you have some code that you could >> share. We have a dozens of data access object that execute IQuery and >> ICriteria for various mapped classes that could benefit from retry logic. >> Instead of putting retry logic in all methods of those DAO's, I would >> rather have centralized methods to ExecuteCriteria or ExecuteQuery that >> incorporate the retry logic. >> >> I would appreciate if you or somebody else could share some code that >> does that. >> >> Thanks. >> >> Waqar >> >> >> On Wednesday, October 14, 2009 11:55:20 AM UTC-5, Graham Bunce wrote: >>> >>> All, >>> >>> In my application I have a repository layer which wraps access to >>> database queries. As NH-Linq has come on the scene we've started using >>> his a lot more for new apps. >>> >>> However, as Linq queries are deferred until first use, I'm not sure >>> how to deal with common DB errors that can be retried - i.e. DB >>> deadlock, timeout, connection lost etc. >>> >>> With NH Queries it's quite easy. I have a "QueryProcessor" that has >>> methods such as UniqueResult, List etc. and accepts an NH IQuery or >>> IMultiQuery. The logic then wraps the actual query call with retry >>> logic. >>> >>> This way I have a common QueryProcessor for all my Repository queries. >>> >>> I'm a little stuck as to how to implement this pattern for Linq >>> though... I can wrap the logic around every Linq query but then I have >>> tons of replicated code. Can I use IQueryable in the same way as >>> IQuery ? >>> >>> Do I have to inject an IQueryable<T> into my method and then do a >>> ToList() to force the query to run within my retry logic? >>> >>> Is there another way.. as I may end up using things like >>> SingleOrDefault(), First() etc instead and I'd rather not replicate >>> all these Linq functions as QueryProcessor method calls. >>> >>> Any advice appreciated >> >> -- >> You received this message because you are subscribed to the Google Groups >> "nhusers" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To post to this group, send email to [email protected]<javascript:> >> . >> Visit this group at http://groups.google.com/group/nhusers. >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "nhusers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/nhusers. For more options, visit https://groups.google.com/d/optout.
