> > > How do I do something like this with a Criteria...
> > >
> > > select * from table where columnA='foo' OR columnA='bar'
> >
> > for this particular case:
> >
> > String[] values = new String[2];
> > values[0]="foo";
> > values[1]="bar";
> > ...
> > Criteria crit = new Criteria();
> > crit.addIn(...Peer.columnA, values);
>
> Of course, this won't cut it for such cases as:
>
> where (c1 < 'A' or c2 > 'B') and
> (c3 < 'C' or c4 > 'D') and
> (c5 < 'E' or c6 > 'F');
Right. As I said it was the solution for that particular case and not a
general one.
> > AFAIK there is no general-purpose way to create OR
> > in Criteria other than running two separate queries.
>
> What would it take to add OR support for Criteria? Is
> this an inherent limitation in the Criteria class design?
> If anybody can give me pointers, I could try a stab at this.
First of all you can fall back to CUSTOM (Not sure how that works).
But good support for ORs etc. can be easily added.
It can be added in the following way:
1. add a property to Criteria (not sure about the name, I'll call it
Operator in the example) which would regulate whether all the conditions in
the object are ORed or ANDed (AND should be default and it will be identical
to the current behavior).
2. add method
public Criteria add(Criteria subCriteria);
to Criteria object which adds a Criteria object as a sub-criteria.
So for your case you'll construct Criteria as follows:
Criteria crit = new Criteria()
.add(new Criteria()
.add(xPeer.c1,"A",Criteria.LESS_THAN)
.add(xPeer.c2,"B",Criteria.MORE_THAN)
.setOperator(Criteria.OR))
.add(new Criteria()
.add(xPeer.c3,"C",Criteria.LESS_THAN)
.add(xPeer.c4,"D",Criteria.MORE_THAN)
.setOperator(Criteria.OR))
.add(new Criteria()
.add(xPeer.c5,"E",Criteria.LESS_THAN)
.add(xPeer.c6,"F",Criteria.MORE_THAN)
.setOperator(Criteria.OR))
fedor.
_______________________________________________________
Say Bye to Slow Internet!
http://www.home.com/xinbox/signup.html
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?: [EMAIL PROTECTED]