Hi Jeff,
  One minor issue I had (till I refactored) in this area was that at one point I set some criteria in a base class, but sometimes wanted to set some additional "AND" clauses in a derived class.  As such, I there needed to re-obtain the (single) Criteria instance, (which I did via example.getOredCriteria().get(0)), but wondered if there was/should be a better way that that?

/Gwyn

On 26/09/06, Jeff Butler < [EMAIL PROTECTED]> wrote:
Hi Emiliano,
 
You are correct - you are using the Criteria class in just the way I had envisioned.  But I (obviously) didn't account for the case where there are no criteria set :(  I'll fix it for the next release.  The workaround for now would be to not create the criteria class if there will be no criteria set.  I know this is an imperfect solution, but it will work for now.
 
There is no "example.and(Criteria)" method because the current setup already allows any WHERE clause to be generated - there's no need for it.  You can do as many ANDs as you want - in exactly the way you are doing it, and you can add as many ORs as you want too.
 
Jeff Butler
 

 
On 9/26/06, Emiliano Armellin <[EMAIL PROTECTED] > wrote:
Hello,

I have to add different and clauses in different place of my code, 0 or more and clauses...

Which is the correct way to do it?

My solution is this:

            TableExample.Criteria criteria = example.createCriteria();

            if(StringUtils.isNotBlank(field1)){
                criteria.andField2EqualTo(field1);
            }
           
            if(StringUtils.isNotBlank(field2)){
                criteria.andField2EqualTo(field2);
            }


this solution does not work if field1 & field2 are empty, it creates an empty clause  (   )

Why does not exist an example.and(criteria) method?


--
Emiliano Armellin




--
Download Wicket 1.2.2 now! - http://wicketframework.org

Reply via email to