Re: Criteria objects
From: John C. Bollinger (jobollin_at_indiana.edu)
Date: 08/24/04
- Next message: Matt Hughes: "EJBs & CMP with real database users"
- Previous message: Alan: "Re: Hibernate noob problem - Named query not known"
- In reply to: VisionSet: "Criteria objects"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 24 Aug 2004 08:50:46 -0500
VisionSet wrote:
> I think there is a valid approach to retrieving records based on a criteria
> object that is of the same class as the object you are retrieving.
>
> A Record object may be used as the criteria to find other Record objects.
>
> If we have a method such as
>
> Record[] find(Record record);
>
> then the argument can have any of its fields as null
> this would signify no filtering on that field.
>
> A criteria object could be set up as so:
>
> public Record(Integer key, String[] data);
>
> new Record(null, new String {"Foo", "Bar", null, null, null, null, null})
>
> I think Hibernate uses this approach.
>
> But I'm a little unhappy about this, a null primary key?
>
> Is this abuse of the object? should I have a separate criteria class?
I think it's a bit iffy from an OO purism point of view, but that
doesn't mean it couldn't be made to work fine. If you need to be able
to match against every field and combination of fields then you do need
a criterion object containing at least as much information as a Record,
so there is surely some advantage to using the Record class also for
criteria.
> I'm after the simplest design that I do feel happy about.
If you're unsatisfied with using the same class, then you could consider
using inheritance. The fields and accessor methods could be on a
superclass that does not restrict its field values, and Record could be
a subclass (that need not redefine any accessor methods). You can
stipulate that Record instances may not have null fields (whether or not
you enforce it in code), but that that doesn't necessarily apply to the
superclass. If you like symmetry then you can make the criterion class
be a sibling of Record; otherwise you can just use the superclass.
John Bollinger
jobollin@indiana.edu
- Next message: Matt Hughes: "EJBs & CMP with real database users"
- Previous message: Alan: "Re: Hibernate noob problem - Named query not known"
- In reply to: VisionSet: "Criteria objects"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|