ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeff Butler" <jeffgbut...@gmail.com>
Subject Re: Abator new Generator Set
Date Wed, 27 Sep 2006 17:26:10 GMT
Yep - that's the only way to do it.  I guess I don't think that's so bad for
the situation you've presented - which is probably somewhat unusual.

Maybe something to do to improve the situation would be to add the ability
to create a single disconnected Criteria class (instead of automatically
adding the first one to the OR list).  Then you could keep the disconnected
Criteria in your super class and add additional ANDs to it in the derived
class before adding it to the OR list.  You could accomplish this now by
doing createCriteria(), then doing example.getOredCriteria().clear().  (BTW
- I've just committed a change to add an example.clear() method to do this
same thing)

The reason the ANDs and ORs are setup the way they are is that I tried to
keed the generated XML for the WHERE clause as concise as possible.  If you
look at what's generated, you'll see that it's pretty complex - there are
several <iterates> nested in <iterates>.  But it is pretty concise too -
only about 20 lines or so.  I think that having a seperate AND and OR list
would about double the generated XML.  And the XML grows larger too if you
use custom type handlers for some fields.

Whew - query by criteria is a very complex thing to do!  There are tradeoffs
between usability and functionality.  I like this new method much more than
what was in previous versions of Abator, but I'm very open to ideas for
improving it too.

Jeff Butler


On 9/27/06, Gwyn Evans <gwyn.evans@gmail.com> wrote:
>
> 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 < jeffgbutler@gmail.com> 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 <earmellin@ateikon.com > 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
> > >
> > >    - W_
> > >    www.ateikon.com
> > >    - @_
> > >    earmellin@ateikon.com
> > >    - T_
> > >    *+39 0422 452101*
> > >
> > > [image: Get Firefox!]
> > > <http://www.spreadfirefox.com/?q=affiliates&id=15653&t=86>
> > > [image: Get Thunderbird]
> > > <http://www.mozilla.org/products/thunderbird/>
> > >
> >
> >
>
>
> --
> Download Wicket 1.2.2 now! - http://wicketframework.org

Mime
View raw message