You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by yu...@sungard.com on 2008/12/02 17:00:58 UTC

Blocking one -help needed on dynamic changing of conjuction property

 HI all,

   I am using criteria querry  and following is the where clause for the
same.

  <sql id="Criteria_Where_Clause" >

 

    <iterate property="oredCriteria" conjunction="or" prepend="where"
removeFirstPrepend="iterate" >

      (

      <iterate prepend="and"
property="oredCriteria[].criteriaWithoutValue" conjunction="and" >

        $oredCriteria[].criteriaWithoutValue[]$

      </iterate>

      <iterate prepend="and"
property="oredCriteria[].criteriaWithSingleValue" conjunction="and" >

        $oredCriteria[].criteriaWithSingleValue[].condition$

          #oredCriteria[].criteriaWithSingleValue[].value#

      </iterate>

      <iterate prepend="and"
property="oredCriteria[].criteriaWithListValue" conjunction="and" >

        $oredCriteria[].criteriaWithListValue[].condition$

        <iterate
property="oredCriteria[].criteriaWithListValue[].values" open="("
close=")" conjunction="," >

          #oredCriteria[].criteriaWithListValue[].values[]#

        </iterate>

      </iterate>

      <iterate prepend="and"
property="oredCriteria[].criteriaWithBetweenValue" conjunction="and" >

        $oredCriteria[].criteriaWithBetweenValue[].condition$

        #oredCriteria[].criteriaWithBetweenValue[].values[0]# and

        #oredCriteria[].criteriaWithBetweenValue[].values[1]#

      </iterate>

      )

    </iterate>  

  I want to dynamically change the value of conjunction with "OR" and
"AND" .

  I am constructing and passing the criteria object here to this where
clause. I have tried with $ $ and # # but it is not working .

 can any body please help me.

Regards

Yuvraj 

 


Re: Blocking one -help needed on dynamic changing of conjuction property

Posted by Jeff Butler <je...@gmail.com>.
Boolean algebra:

(A | B) & (C | D) = (A & C) | (A & D) | (B & C) | (B & D)

The second form can be accomplished with the abator where clause.  I
realise that this becomes more complex as more columns are involved,
but it is likely the best you can do with a generalized query by
criteria given iBATIS' current capabilities in dynamic SQL.

Note that abator's selection of AND and OR is arbitrary - it seemed to
me that I chose the most common case.  You could easily add another
SQL clause and switch the AND/OR if you are more likely to AND clauses
to gether rather than OR them.

Jeff Butler


On Tue, Dec 2, 2008 at 10:17 AM,  <yu...@sungard.com> wrote:
> Thanks a lot...
>
>  But if I want to construct the query such as
>
>   ( Table.columname1="ABC" or Table.columnam1="EFG" )
>
>     and
>
>   (Table.columname2="123" or Table.columname2="456" )
>
> How I should construct this querry.
>
> And also queries become more complex as no of columns goes on
> increasing.
>
>
>
>
>
> -----Original Message-----
> From: Jeff Butler [mailto:jeffgbutler@gmail.com]
> Sent: Tuesday, December 02, 2008 9:41 PM
> To: user-java@ibatis.apache.org
> Subject: Re: Blocking one -help needed on dynamic changing of conjuction
> property
>
> iBATIS does not support changing the XML attributes at runtime.
>
> It looks like you've started with the abator generated where clause.
> You can probably accomplish what you want to do with a little boolean
> algebra and changing the values of the parameter object.
>
> Jeff Butler
>
>
>
>
> On Tue, Dec 2, 2008 at 10:00 AM,  <yu...@sungard.com> wrote:
>>  HI all,
>>
>>    I am using criteria querry  and following is the where clause for
> the
>> same.
>>
>>   <sql id="Criteria_Where_Clause" >
>>
>>
>>
>>     <iterate property="oredCriteria" conjunction="or" prepend="where"
>> removeFirstPrepend="iterate" >
>>
>>       (
>>
>>       <iterate prepend="and"
> property="oredCriteria[].criteriaWithoutValue"
>> conjunction="and" >
>>
>>         $oredCriteria[].criteriaWithoutValue[]$
>>
>>       </iterate>
>>
>>       <iterate prepend="and"
>> property="oredCriteria[].criteriaWithSingleValue" conjunction="and" >
>>
>>         $oredCriteria[].criteriaWithSingleValue[].condition$
>>
>>           #oredCriteria[].criteriaWithSingleValue[].value#
>>
>>       </iterate>
>>
>>       <iterate prepend="and"
> property="oredCriteria[].criteriaWithListValue"
>> conjunction="and" >
>>
>>         $oredCriteria[].criteriaWithListValue[].condition$
>>
>>         <iterate
> property="oredCriteria[].criteriaWithListValue[].values"
>> open="(" close=")" conjunction="," >
>>
>>           #oredCriteria[].criteriaWithListValue[].values[]#
>>
>>         </iterate>
>>
>>       </iterate>
>>
>>       <iterate prepend="and"
>> property="oredCriteria[].criteriaWithBetweenValue" conjunction="and" >
>>
>>         $oredCriteria[].criteriaWithBetweenValue[].condition$
>>
>>         #oredCriteria[].criteriaWithBetweenValue[].values[0]# and
>>
>>         #oredCriteria[].criteriaWithBetweenValue[].values[1]#
>>
>>       </iterate>
>>
>>       )
>>
>>     </iterate>
>>
>>   I want to dynamically change the value of conjunction with "OR" and
> "AND"
>> .
>>
>>   I am constructing and passing the criteria object here to this where
>> clause. I have tried with $ $ and # # but it is not working .
>>
>>  can any body please help me.
>>
>> Regards
>>
>> Yuvraj
>>
>>
>
>
>

RE: Blocking one -help needed on dynamic changing of conjuction property

Posted by yu...@sungard.com.
Thanks a lot...

 But if I want to construct the query such as

   ( Table.columname1="ABC" or Table.columnam1="EFG" )

     and  

   (Table.columname2="123" or Table.columname2="456" )

How I should construct this querry.

And also queries become more complex as no of columns goes on
increasing.
     




-----Original Message-----
From: Jeff Butler [mailto:jeffgbutler@gmail.com] 
Sent: Tuesday, December 02, 2008 9:41 PM
To: user-java@ibatis.apache.org
Subject: Re: Blocking one -help needed on dynamic changing of conjuction
property

iBATIS does not support changing the XML attributes at runtime.

It looks like you've started with the abator generated where clause.
You can probably accomplish what you want to do with a little boolean
algebra and changing the values of the parameter object.

Jeff Butler




On Tue, Dec 2, 2008 at 10:00 AM,  <yu...@sungard.com> wrote:
>  HI all,
>
>    I am using criteria querry  and following is the where clause for
the
> same.
>
>   <sql id="Criteria_Where_Clause" >
>
>
>
>     <iterate property="oredCriteria" conjunction="or" prepend="where"
> removeFirstPrepend="iterate" >
>
>       (
>
>       <iterate prepend="and"
property="oredCriteria[].criteriaWithoutValue"
> conjunction="and" >
>
>         $oredCriteria[].criteriaWithoutValue[]$
>
>       </iterate>
>
>       <iterate prepend="and"
> property="oredCriteria[].criteriaWithSingleValue" conjunction="and" >
>
>         $oredCriteria[].criteriaWithSingleValue[].condition$
>
>           #oredCriteria[].criteriaWithSingleValue[].value#
>
>       </iterate>
>
>       <iterate prepend="and"
property="oredCriteria[].criteriaWithListValue"
> conjunction="and" >
>
>         $oredCriteria[].criteriaWithListValue[].condition$
>
>         <iterate
property="oredCriteria[].criteriaWithListValue[].values"
> open="(" close=")" conjunction="," >
>
>           #oredCriteria[].criteriaWithListValue[].values[]#
>
>         </iterate>
>
>       </iterate>
>
>       <iterate prepend="and"
> property="oredCriteria[].criteriaWithBetweenValue" conjunction="and" >
>
>         $oredCriteria[].criteriaWithBetweenValue[].condition$
>
>         #oredCriteria[].criteriaWithBetweenValue[].values[0]# and
>
>         #oredCriteria[].criteriaWithBetweenValue[].values[1]#
>
>       </iterate>
>
>       )
>
>     </iterate>
>
>   I want to dynamically change the value of conjunction with "OR" and
"AND"
> .
>
>   I am constructing and passing the criteria object here to this where
> clause. I have tried with $ $ and # # but it is not working .
>
>  can any body please help me.
>
> Regards
>
> Yuvraj
>
>



Re: Blocking one -help needed on dynamic changing of conjuction property

Posted by Jeff Butler <je...@gmail.com>.
iBATIS does not support changing the XML attributes at runtime.

It looks like you've started with the abator generated where clause.
You can probably accomplish what you want to do with a little boolean
algebra and changing the values of the parameter object.

Jeff Butler




On Tue, Dec 2, 2008 at 10:00 AM,  <yu...@sungard.com> wrote:
>  HI all,
>
>    I am using criteria querry  and following is the where clause for the
> same.
>
>   <sql id="Criteria_Where_Clause" >
>
>
>
>     <iterate property="oredCriteria" conjunction="or" prepend="where"
> removeFirstPrepend="iterate" >
>
>       (
>
>       <iterate prepend="and" property="oredCriteria[].criteriaWithoutValue"
> conjunction="and" >
>
>         $oredCriteria[].criteriaWithoutValue[]$
>
>       </iterate>
>
>       <iterate prepend="and"
> property="oredCriteria[].criteriaWithSingleValue" conjunction="and" >
>
>         $oredCriteria[].criteriaWithSingleValue[].condition$
>
>           #oredCriteria[].criteriaWithSingleValue[].value#
>
>       </iterate>
>
>       <iterate prepend="and" property="oredCriteria[].criteriaWithListValue"
> conjunction="and" >
>
>         $oredCriteria[].criteriaWithListValue[].condition$
>
>         <iterate property="oredCriteria[].criteriaWithListValue[].values"
> open="(" close=")" conjunction="," >
>
>           #oredCriteria[].criteriaWithListValue[].values[]#
>
>         </iterate>
>
>       </iterate>
>
>       <iterate prepend="and"
> property="oredCriteria[].criteriaWithBetweenValue" conjunction="and" >
>
>         $oredCriteria[].criteriaWithBetweenValue[].condition$
>
>         #oredCriteria[].criteriaWithBetweenValue[].values[0]# and
>
>         #oredCriteria[].criteriaWithBetweenValue[].values[1]#
>
>       </iterate>
>
>       )
>
>     </iterate>
>
>   I want to dynamically change the value of conjunction with "OR" and  "AND"
> .
>
>   I am constructing and passing the criteria object here to this where
> clause. I have tried with $ $ and # # but it is not working .
>
>  can any body please help me.
>
> Regards
>
> Yuvraj
>
>