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 Chris O'Connell <oc...@gorillachicago.com> on 2009/02/11 20:33:24 UTC

position while iterating

Is there any way to find my position while iterating through a collection in
the sqlMap file.  For example, I want to do something like this:

<iterate property="attributes" >

                ,(

                    SELECT TEMP_PA.PRODUCT_ID
                    FROM PRODUCT_ATTRIBUTES TEMP_PA,
                        ATTRIBUTES TEMP_A
                    WHERE (
                        TEMP_A.ATTRIBUTE_ID = TEMP_PA.ATTRIBUTE_ID
                        AND TEMP_A.NAME = #attributes[].name#
                        <iterate property="attributes[].values" prepend="
AND ( " close=" ) " conjunction=" OR " >
                            <isNotEmpty
property="attributes[].values[].value">
                                
                                    TEMP_PA.VALUE =
#attributes[].values[].value#
                                
                            </isNotEmpty>
                        </iterate>
                    )
                ) TEMP$attributes[].name$_{POSITION_IN_ITERATION}
                </iterate>

I may have multiple attributes with the same name, so I need something that
will allow me to uniquely name this alias.  Anyone have any ideas?

Thanks,
Chris



Re: position while iterating

Posted by Jeff Butler <je...@gmail.com>.
There is not a way to determine the position in the list.

I would add the alias as an attribute somewhere in the parameter
object and calculate it in Java ($attributes[].alias).

Jeff Butler


On Wed, Feb 11, 2009 at 1:33 PM, Chris O'Connell
<oc...@gorillachicago.com> wrote:
> Is there any way to find my position while iterating through a collection in
> the sqlMap file.  For example, I want to do something like this:
>
> <iterate property="attributes" >
>
>                ,(
>
>                    SELECT TEMP_PA.PRODUCT_ID
>                    FROM PRODUCT_ATTRIBUTES TEMP_PA,
>                        ATTRIBUTES TEMP_A
>                    WHERE (
>                        TEMP_A.ATTRIBUTE_ID = TEMP_PA.ATTRIBUTE_ID
>                        AND TEMP_A.NAME = #attributes[].name#
>                        <iterate property="attributes[].values" prepend="
> AND ( " close=" ) " conjunction=" OR " >
>                            <isNotEmpty
> property="attributes[].values[].value">
>
>                                    TEMP_PA.VALUE =
> #attributes[].values[].value#
>
>                            </isNotEmpty>
>                        </iterate>
>                    )
>                ) TEMP$attributes[].name$_{POSITION_IN_ITERATION}
>                </iterate>
>
> I may have multiple attributes with the same name, so I need something that
> will allow me to uniquely name this alias.  Anyone have any ideas?
>
> Thanks,
> Chris
>
>
>