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: flexible queries?
Date Wed, 28 Jun 2006 20:33:00 GMT
There's nothing in iBATIS that will do this.  I've done something similar in
the past by adding a getter to the parameter object and coding the logic in
the getter method.  Like this:

public boolean isComplexCondition {
  ...some complex decision
}

Then coding an <isEqual property="complexCondition" value="true"> in the SQL
Map.

I ended up liking this better anyway - I think the logic is easier to
understand when written in Java.

Jeff Butler



On 6/28/06, Vadim Grinshpun <vadim@ll.mit.edu> wrote:
>
> Er... Thanks, but either you misread my example, or I completely do not
> understand what you mean.
> The example I gave uses a large chunk of  iBATIS-like *pseudocode*
> (there is no 'if' tag and no 'or' tag!), and thus cannot work as is.
> I've looked through the Dev Guide ( version that was in SVN as of 6/20),
> but so far was unable to find anything that would allow for this kind of
> functionality. (effectively, what I want is to have a *SINGLE* iBATIS
> conditional that would test multiple properties and OR the results).
> Could you take another look at it, please, or explain in more detail?
> Thanks!
> -Vadim
> Niels Beekman wrote:
> > Yes, that should work out just fine. See the Developer Guide for some
> > examples...
> >
> > -----Original Message-----
> > From: Vadim Grinshpun [mailto:vadim@ll.mit.edu]
> > Sent: woensdag 28 juni 2006 20:58
> > To: user-java@ibatis.apache.org
> > Subject: flexible queries?
> >
> > Hi everyone,
> >
> > Suppose I have a query where I want a join to be performed only if *one
> > or more* of a set of parameters are present.
> > Is there a way in SqlMaps to do something like this? (below is an
> > example snippet of  what I'd like to do, using some pseudocode in the
> > first <dynamic> section):
> >
> > SELECT * FROM
> >     table_foo f, table_bar b
> >    <dynamic> <!-- if any of the params in the conditional are defined,
> > add one more table to join -->
> >       <if>
> >         <or>
> >           <isEqual property="X.defined" compareValue="true" />
> >           <isEqual property="X.defined" compareValue="true" />
> >         </or>
> >        <then>, table_baz z</then>
> >       </if>
> >    </dynamic>
> >    WHERE f.field = b.field
> >    <dynamic>
> >      <isEqual property="X.defined" compareValue="true" prepend="AND"
> >  >z.x_field > #X.value#</isEqual>
> >      <isEqual property="Y.defined" compareValue="true" prepend="AND"
> >  >z.y_field = #Y.value#</isEqual>
> >   </dynamic>
> >
> >
> > Thanks,
> > --Vadim
> >
> >
>
>

Mime
View raw message