There is some discussion about improving the dynamic tags on the iBATIS Wiki here:
Feel free to add to the discussion. However, as you noted, this is a far from trivial task and I don't sense any will to make a change anytime soon.
Jeff Butler
On 6/28/06, Vadim Grinshpun <[EMAIL PROTECTED]> wrote:
True, that is a way to get around this issue (and it is what I'm doing
now).
While I agree that logic is more readable when written in Java, I'd also
like to point out that the main advantage of using the data mapper (at
least for me) is to avoid having anything query-related in the code.
This kind of logic has no use outside of a particular database
definition/query, and would be good to keep away from the bean that
otherwise acts only as a container for data...
The bottom line is I'll be a happier man if the iBATIS folks do wind up
adding something that allows this to be done :)
(and I appreciate that this is not a trivial task, just expressing a hope :)
-Vadim
Jeff Butler wrote:
> 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* < [EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>> 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: [EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>]
> > Sent: woensdag 28 juni 2006 20:58
> > To: [email protected] <mailto:[email protected]>
> > 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
> >
> >
>
>
