I think I have managed to re-write the Criteria.Criterion inner class to 
support the kind of nested or/and clause behaviour described in the 
Peers-howto document.

I think the key is declaring "and" or "or" precedence in the Criterion 
object and then using it to determine the appropriate order for the clauses.

If I can work out how to check this in to torque I'll make it available 
for others.

CHEERS> SAM

Sam Joseph wrote:

> Hi There,
>
> So I have been using nested criterion as described below in the 
> Peers-howto document:
>
> select * from abc where (a < 1 and b > 2) or (  a > 5  and b < 3)
>
> Criteria crit = new Criteria();
> Criteria.Criterion a1 = crit.getNewCriterion(ABC.A, 1,
> Criteria.LESS_THAN);
> Criteria.Criterion b2 = crit.getNewCriterion(ABC.B, 2,
> Criteria.GREATER_THAN);
> Criteria.Criterion a5 = crit.getNewCriterion(ABC.A, 5,
> Criteria.GREATER_THAN);
> Criteria.Criterion b3 = crit.getNewCriterion(ABC.B, 3,
> Criteria.LESS_THAN);
>
> crit.add( a1.and(b2).or(a5.and(b3)) );
>
> However the current Criteria and Criterion code do not seem to support 
> this.  In fact the result of the above operation is:
>
> (a<1 or (a<5 and (b< 3 and b< 2)))
>
> I find someone else with a similar problem in the turbine mailing list:
>
> 
>http://nagoya.apache.org:8080/eyebrowse/ReadMsg?[EMAIL PROTECTED]&msgId=75229
> 
>
>
> which I am dismayed to see has no responses to it.
>
> It may be that this problem has been fixed in a more recent version of 
> the code - I am using torque-3.0-b2-dev
> but it seems that the way that "and" and "or" are handled in Criterion 
> will just not allow statements like
>
> (a < 1 and b > 2) or (  a > 5  and b < 3)
>
> My apologies if I'm overlooking something straightforward, but it 
> seems like Criterion should change to have either an "or" attachment 
> or an "and" attachment.  With each criterion potentially having both 
> "or" and "and" attachments it seems there is outstanding vagueness 
> about precedence.  I'm very keen to use this functionality so I may 
> well try and implement this change, but I would like some input on 
> whether I am overlooking something.
>
> Partly to this end I have created IRC groups entitle #torque and 
> #torque-user on share.whichever.com 6667 which appears to be the irc 
> server used by turbine people.  I'll be monitoring those chat rooms 
> whenever I can so if you would like to discuss these and other issues 
> in real time, please join me there.
>
> CHEERS> SAM
>
>
>
>
>
>
> -- 
> To unsubscribe, e-mail:   
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: 
> <mailto:[EMAIL PROTECTED]>
>
>
>




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

Reply via email to