-->
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.  [ 2 posts ] 
Author Message
 Post subject: Design pattern question
PostPosted: Sun Oct 22, 2006 12:16 pm 
Beginner
Beginner

Joined: Thu Oct 19, 2006 1:03 pm
Posts: 29
Hibernate version:
Production

Question
I have a WebForm page that makes it possible to list entries and sort them by different criteria. For this I use a class I call EntriesBLL and EntryCollection : List<Entry>, IComparer<Entry>.

The entry page binds to a GridView when it first is called - all entries in the database for this specific user.

Then I can sort by different criteria, but what about the overall design to minimize database queries. First I created an instance of EntryCollection in the page, but I couldn't reuse it because it was recreated for every page load. Would it be a good idea to store the EntryCollection instance in the session? Or in the viewstate?

Right now I'm storing it in the viewstate. But then; what about when I sort it? Should I use NHibernate to do the sorting, by creating a new ICriteria, adding ICriteria and ICriterion-s onto this, (and hence by fetching it all again from the database) or has NHibernate some way of caching a collection and then sorting it when needed?

This is a method I use to sort the data:
Code:
public EntryCollection GetEntriesByStatusAndType(int StatusId, int TypeId)
{
   IList results = null;
   try
   {
      session = factory.OpenSession();
      ICriteria baseCrit = session.CreateCriteria(typeof(Entry));
      if (StatusId != 0)
      {
         ICriteria statusCrit = baseCrit.CreateCriteria("Status")
               .Add(Expression.Eq("Id", StatusId));
      }
      if (TypeId != 0)
      {
         ICriteria typeCrit = baseCrit.CreateCriteria("Type")
               .Add(Expression.Eq("Id", TypeId));
      }
      results = baseCrit.List();
   }
   catch { throw; }
   finally
   {
      session.Disconnect();
   }
   EntryCollection entries = new EntryCollection(results);
   return entries;
}
and as you can see, it takes the route I just talked about...

What would be a good design pattern to use here?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 24, 2006 9:16 am 
Beginner
Beginner

Joined: Thu Oct 19, 2006 1:03 pm
Posts: 29
Somebody?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.