-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Asynchronous fetching ?
PostPosted: Tue Dec 11, 2007 11:19 am 
Newbie

Joined: Tue Jul 17, 2007 9:11 am
Posts: 5
Hi all

Is there a way to to what I would call sort of asynchronous requests with NHibernate ? Let me be more precise.

I have a request which return "lots of" datas. I would like to be able to start to display my datas in the UI as soon as the database begin to return me these datas, as some sql clients do.

I would imagine that the List() method return the result "instantaneously", then start to fill as fast as the database return datas, and that you can access to the first rows even if the request is not complete.
Note that I don't want to use nhibernate lazy loading, because I don't want to issue a new request for each line.

Is it possible ?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 11, 2007 3:33 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
Have you looked at ISession/IQuery/ICriteria.Enumerable()? See, http://www.hibernate.org/hib_docs/nhibe ... a-querying , starting at the paragraph that begins "If you expect your query to return a very large number of objects..."


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 11, 2007 3:46 pm 
Newbie

Joined: Tue May 15, 2007 10:10 am
Posts: 8
Maybe you could use pagination to fetch blocks of data in one thread and load them into the UI in an other thread.

you need a class to synchronise your threads with a queue and maybe a few flags (IsFinished, IsSuccess). Thread A would put load data block per block (with pagination) and put them in the queue and thread B would read the blocks from the queue and load them in the UI.

But do this only if you have a lot of data, and if you have too much data maybe you need to rethink your UI...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 11, 2007 4:44 pm 
Newbie

Joined: Tue Jul 17, 2007 9:11 am
Posts: 5
marcal wrote:
Have you looked at ISession/IQuery/ICriteria.Enumerable()? See, http://www.hibernate.org/hib_docs/nhibe ... a-querying , starting at the paragraph that begins "If you expect your query to return a very large number of objects..."


I don't think it is suited for me. The Enumerable() method first does a "light" request for getting the identifiers only. Then, when doing "foreach", you submit another request for each loop. So, if you fetch the entire collection, which is my case, you do n+1 select. It would slow a lot the UI. I would like to do only one request, as I know I need all the rows.

MisterTom_ wrote:
Maybe you could use pagination to fetch blocks of data in one thread and load them into the UI in an other thread.

you need a class to synchronise your threads with a queue and maybe a few flags (IsFinished, IsSuccess). Thread A would put load data block per block (with pagination) and put them in the queue and thread B would read the blocks from the queue and load them in the UI.

But do this only if you have a lot of data, and if you have too much data maybe you need to rethink your UI..."


Thanks for the tips, but if I understand well, I would need to send one request for each block. It's not possible for my case.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.