-->
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.  [ 3 posts ] 
Author Message
 Post subject: Criteria query serialization/deserialization
PostPosted: Tue May 02, 2006 11:20 am 
Newbie

Joined: Tue Mar 21, 2006 4:18 pm
Posts: 11
Hello all, my question is, if there is possibility to serialize criteria query and how to do it. Why i ask for it: in my application, i need to build dynamic where condition using user interface. So my idea was to use NH criteria query, because it is object oriented. I also need to persistent this query (not result) and also fill my UI according saved query. Have anybody some idea, how to do it? Is it NH good tool for this job? Thanks for answer. Jan.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 05, 2006 5:54 pm 
Beginner
Beginner

Joined: Mon Apr 24, 2006 1:43 pm
Posts: 22
Hello
I have a similar problem, and my solution is something like this:

I have a simple class with all the properties for the criteria. It has method, FillCriteria, which fills previously created criteria from the data in the class. For example:
Code:
class UserFilter
{
string Username = null;
int? MinAge = null ;
int? MaxAge = null ;

public void FillCriteria(ICriteria c)
{
   if (string != null)
     c.Add(Expression.Eq("Username",Username));
   if (MinAge != null)
     c.Add(Expression.Ge("Age", MinAge) ;
   if (MaxAge != null)
     c.Add(Expression.Lt("Age", MaxAge);
}
}

And, you can use it like this:
Code:
ICriteria c = CreateCriteria(typeof(User));
UserFilter uf = // load filter from DB, UI, or something
uf.FillCriteria(c) ;
c.List() ;

You can easily databind this UserFilter to the UI, serialize to XML (that's what I'm doing), save to the DB or something else.

HTH, Tom


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 10:43 am 
Newbie

Joined: Tue Mar 21, 2006 4:18 pm
Posts: 11
Yes, It could work, thank you for this idea, i will try it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.