ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vadim Grinshpun <va...@ll.mit.edu>
Subject Re: Distinguish null and not null parameters
Date Mon, 28 Aug 2006 15:50:12 GMT
Hi,
I don't have a direct answer to your question, but I can suggest a nice 
(IMHO :) workaround.
You can use a macro language, such as GNU m4, to create macros, and then 
use them in your code.
For instance, you could define a macro that takes in as parameters the 
property name and the field name and generates the appropriate 
conditionals, and then in your code you would have something like
<select ...>
SELECT ID FROM TABLE
WHERE
   mymacro(field1,FIELD1)
</select>

I've been using this approach for some time now. The only trade-off is 
that you have to preprocess the file(s) to generate the corresponding 
xml files with the substitutions--that is, you add an extra step to the 
build process.
-Vadim


Chema wrote:
> Hello:
>
> I like to compose the next query
>
> <select id="idQuery" parameterClass="com.project.ParameterClass" 
> resultClass="java.lang.String">
>     SELECT ID FROM  TABLE
>     WHERE
>     <isNotNull property="field1">
>         AND FIELD1 = #field1#
>     </isNotNull>
>     <isNull property="field1">
>         AND FIELD1 IS NULL
>     </isNull>
> </select>
>
> Is there another better way to distinguish null and not null parameters ?
>
> With only one parameter is not problem like in the previous example  , 
> but really I need to make a comparision with many fields of 
> ParameterClass ( All parameters not named like fieldX )
>
> Thanks a lot
>
> Best regards
>
>


Mime
View raw message