Here is my model:
[A] <1--n> [B] <1--n> [C] <1--1> [D]
| |
C1 C2I want to query for A objects using a C1 timestamp field as criteria (C1 is a subclass of C and C does not have the timestamp field) and a D string field as criteria.
If the timestamp field belonged to the C class, then there would be no problem directly querying for A's.
Since the criteria is a C1 attribute I don't think that I can directly query for A's, so I can do it in two steps by first querying for C1 objects and then iterating through the returned collection to gather the A objects, as follows
// snippit begin
Criteria criteria1 = new Criteria();
Criteria criteria2 = new Criteria();
criteria1.addEqualTo("d.stringField", new String("foo"));
criteria2.addEqualTo("d.stringField", new String("foofoo"));
criteria1.addOrCriteria(criteria2);
Criteria criteria3 = new Criteria();
criteria3.addBetween("timeStamp", timeStamp1, timeStamp2);
criteria1.addAndCriteria(criteria3);Query query = new QueryByCriteria(C1.class, criteria1); Collection c1Set = broker.getCollectionByQuery(query);
java.util.Iterator itr = c1Set.iterator();
List aList = new ArrayList();
while (itr.hasNext())
{
// gather the A's (more db hits here)
A a = c1.getB().getA();
aList.add(a);
}
// snippit endIt would be nice to reduce the DB hits and query for the A's directly as is possible in with standard OQL:
select c1.b.a from c1 in C1.class
where (c1.d.stringField = \"foo\" or
c1.d.stringField = \"foofoo\") and
e.theTimestamp >= timestamp '" + timeStamp1 + "' " and
e.theTimestamp <= timestamp '" + timeStamp2 + "' "Is there any possibility that this is possible with PB queries?
Thanks for read this far,
Phil
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
