From: Gavin K. <ga...@ap...> - 2002-09-13 18:28:31
|
Yeah, pretty much. The point is really that Hibernate doesn't need to be involved in that kind of filtering, because it occurs entirely in memory. ----- Original Message ----- From: "Anton van Straaten" <an...@ap...> To: "hibernate list" <hib...@li...> Sent: Saturday, September 14, 2002 12:21 AM Subject: [Hibernate] RE: session.filter(Collection, Predicate)? > I realized in the cold light of day that what I was asking about below can't > possibly work unless the object being filtered has already been fully > loaded, which I presume would defeat the purpose of the filter. Is that > correct? > > > > -----Original Message----- > > From: Anton van Straaten [mailto:an...@ap...] > > Sent: Friday, September 13, 2002 1:45 AM > > To: hibernate list > > Subject: session.filter(Collection, Predicate)? > > > > > > > Accordingly Ive added filtering > > > methods to the Session interface like: > > > > > > filteredCollection = session.filter(collection, query) > > > > > > A filter is just a query where you can refer to "this", the collection > > > element. So, for example: > > > > > > blackCats = session.filter( cat.getKittens(), "where > > this.color='black' > > > order by this.name" ); > > > > Slightly tangential question about this: how straightforward (or > > not) would it be to support an object as the filter parameter? I > > use a Predicate interface in my own code: > > > > public interface Predicate { > > // Apply predicate to a specified object and return boolean result > > boolean apply(Object o); > > } > > > > This can be used to create arbitrary objects to filter on any > > condition - I use it for filtering Java collections and arrays. > > You can also use it inline, e.g.: > > > > blackCats = session.filter( cat.getKittens(), new Predicate() { > > public boolean apply(Object o) { > > return o.color.equals("black"); > > } > > }); > > > > I don't know anything about what Hibernate is doing when it's > > retrieving & filtering a query - if something like this wouldn't > > require too much internal rearranging, I might take a stab at it, > > since it would fit in with some of the other code I'm using. In > > fact it came up in some code which I've just installed for > > testing, and I ended up building a query string to do it instead. > > In some cases, I prefer the approach I've described since it's > > subject to static checking, supports refactoring, etc. > > > > Anton > > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > hibernate-devel mailing list > hib...@li... > https://lists.sourceforge.net/lists/listinfo/hibernate-devel |