Vadim,
        One other way would be to pass parameters that require logic in using a map.  I know there are pros and cons to using a map, but you can send this from your service layer where you have the rest of your business logic (from which you're probably calling your DAO anyway).  It does lead to DAO's where you have a single parameter of a map and consequently have to look at the sql to determine the parameters, but depending on implementation.  The advantage is that you don't have logic in your bean.  Another advantage is that you're not passing half filled objects around.  Expecting such objects doesn't lead to any tighter coupling than you'd find with a map anyway.

The other thing to keep in mind is that you can nest logical expressions in your map.  For 2 - 3 element "and" or "or" logic, it shouldn't take many evaluations to cover all possible scenarios.  Obivously, this is something you would want to minimize for readability and debugging ease.

Diran

Vadim Grinshpun 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
    >
    >



Reply via email to