I've been thinking more about all that query model & future peers stuff
lately and got some new ideas (may not actually be that new :-)

It appeared to me that the best way to give criteria for object retrieval is
to use the object itself, as it knows most about it's own structure. I would
imagine API something like that:

//note: we are are working with object SomeObject mapping to SOME_TABLE
//first create the "criteria object":
SomeObject someObjectCr = new SomeObject(); // or, maybe,
SomeObject.newInstance()

//set some criteria:
someObjectCr.setSomeField(value); // SQL: SOME_TABLE.SOME_FIELD=value

//retrieve all records satisfying these criteria:
List results = someObjectCr.find() // or .fetch(), or smth else. returns a
List of SomeObjects

----
// now, if you have a few fields to check this is clear:
someObjectCr.setField1(value1);
someObjectCr.setField2(value2);

---
// now it is getting more complex. What do we do with comparisons other than
"equal"
// one way is to pass in some sort of "comparison type"
someObjectCr.setField1(value1, MORE_THAN);

// or, maybe, create methods for each comparison:
someObjectCr.setField1LessThan(value1);
someObjectCr.setField1Like("abc%");

// or something like this:

someObjectCr.setField1(new LessThan(10));
someObjectCr.setField2(new Like("pattern%"));

-----

the advantages of this approach are:
- stricter typing (so that you do not compare apples to oranges or ints to
dates)
- SQL logic needs not be exposed.
- much of the SQL can be pre-generated rather than built at run-time
- no need for separate Peer classes and Criteria objects since OM objects do
all that work now
- inheritance problems are solved since these objects are instances rather
than classes with static methods.

problems:
- this is quite a change
- it's not entirely clear how to best implement things like joins and
complex conditions (i.e. 'WHERE (A>5 AND B<10) OR (A<10 AND B>15))'). I have
some ideas, but it's an open question...

I believe the abovementioned benefits plus general elegance of the design
outweight the problems...

What do you think?

fedor.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to