Perhaps moving that logic out of your xml file into Java land.

Assuming you have a Map as the parameter. 

boolean useSupplierForParts =
Boolean.valueOf(parameters.containsKey("supplierCompanyId") ||
parameters.containsKey("supplierRef));

Parameters.put("supplierTable", useSupplierForParts ? ",
suppliers_for_parts sp" : "");


Or, if you have a parameter class:

class MyParameter {
    // all sorts of goodies in here...

    public String supplierTable() {
       return (supplierCompanyId != null || supplierRef != null) ? ",
suppliers_for_parts sp" : "";
    }
}

In your map file:

SELECT whatever FROM whatever w, other_table ot, $supplierTable$




-----Original Message-----
From: Tim Azzopardi [mailto:[EMAIL PROTECTED] 
Sent: Thursday, February 22, 2007 5:58 AM
To: user-java@ibatis.apache.org
Subject: conditionally add a table to the from clause just once if
either or both of two parameters is not empty


ibatis2.2 java5 and 6 on winXpSp2

I'm using the code below to conditionally add a table to the from clause
of my sql if one or other or both of two parameters is not empty. (The
tricky bit is not to include add the table twice).

The following works, but I wondered if there was a simpler way that
avoids my ugly /*dummy*/ cludge.
(Without the /*dummy*/ nothing is ever generated.) 

<dynamic prepend=", suppliers_for_parts sp">
  <isNotEmpty property="supplierCompanyId"  >
    /*dummy*/
  </isNotEmpty>
  <isNotEmpty property="supplierRef">
    /*dummy*/
  </isNotEmpty>
</dynamic>
--
View this message in context:
http://www.nabble.com/conditionally-add-a-table-to-the-from-clause-just-
once-if-either-or-both-of-two-parameters-is-not-empty-tf3272865.html#a91
00250
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.

Reply via email to