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: Detached criteria - refine search - remove restriction
PostPosted: Wed Mar 07, 2007 4:57 am 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
Hi,

I am using DetachedCriteria. After a user builds a DetachedCriteria using query form, and click search, a list of search results show up. Above the search results, user can further refine results by selecting a property value.

For example, color: black, yellow, red.

I need an API to remove a restriction(eg, color) from a detached criteria, then I can set color to different value.

However, DetachedCriteria does not have such a method.
Any idea are appreciated.

Thanks!
Dave


Top
 Profile  
 
 Post subject: Modifying DetachedCriteria
PostPosted: Wed Mar 07, 2007 5:37 pm 
Newbie

Joined: Wed Mar 07, 2007 5:15 pm
Posts: 2
My advise would be to create a wrapper class that collects a list of Criterion and a list of Order elements, and build a DetachedCriteria when you are ready for a search. If your Criterion were in a dictionary, a map, some associative collection, or even an ArrayList, you could replace or remove elements easily.

Code:
class MyCriteriaBuilder
{
  void AddCriterion(Criterion) ...
  void RemoveCriterion(string propertyname) ...
  void AddOrder(Order) ...
  void RemoveOrder(string propertyname) ...
  DetachedCriteria CreateDetachedCriteria() ...
}

_________________
http://roytate.blogspot.com/


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 08, 2007 2:56 am 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
Thanks for idea.
But my case is very complicated, with OR/Add and alias in the criteria.

If I can make a copy of a DetachedCriteria, it can solve the problem.

is DetachedCriteria.clone() a deep clone?
Thanks!


Top
 Profile  
 
 Post subject: MutableDetachedCriteria
PostPosted: Thu Mar 08, 2007 2:54 pm 
Newbie

Joined: Wed Mar 07, 2007 5:15 pm
Posts: 2
Well, the next idea would be to create a MutableDetachedCriteria that is a copy of DetachedCriteria as well as a MutableCriteriaImpl with expression and order removal methods. Once you have a MutableCriteriaImpl, you can implement the methods that I suggested earlier.

Really, I would not recommend this approach. I would recommend a business-case specific class [OrderHistoryFinder] that contains nullable fields, and allows you to get and set them with properties. This class would be responsible for building a DetachedCriteria on request. This would allow you to incorporate the logic for AND, OR, EXISTS, NOT EXISTS, etc. in a correct fashion. Here is a blog link that you should read.

http://www.ayende.com/Blog/archive/2006/12/07/7055.aspx

Good luck!

Roy

_________________
http://roytate.blogspot.com/


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.