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 Peter Martin <pm...@adobe.com> on 2007/09/18 14:53:12 UTC

Using java.util.List as the parameterClass

I want to pass in a List as a parameter class and select the first  
item from the list. I know it is possible to use the <iterate> tag,  
but is it possible to pull out a single item for a given index? For  
example, in the following select I to get the item at position 0:

    <select id="countPeopleWithSurname"  
parameterClass="java.util.List" resultClass="int">
       SELECT count(*) FROM person WHERE per_last_name = <item 0>
    </select>

Likewise in an insert I may want to pull out the different items:

	<insert id="insertPerson" parameterClass="person">
		INSERT INTO PERSON (PER_ID, PER_FIRST_NAME, PER_LAST_NAME,
		PER_BIRTH_DATE, PER_WEIGHT_KG, PER_HEIGHT_M) VALUES (<item 0>,
		<item 1>, <item 2>, <item 3>, <item 4>, <item 5>)
	</insert>

Thanks
Peter




Re: Using java.util.List as the parameterClass

Posted by Jeff Butler <je...@gmail.com>.
You can't do it directly.  However, I think that if you put the list in a
map (or some other object), then you can do it:

Map parms = new HashMap();
parms.put ("items", someList);

Then in your SqlMap:

   <select id="countPeopleWithSurname" parameterClass="java.util.Map"
resultClass="int">
      SELECT count(*) FROM person WHERE per_last_name = #items[0]#
   </select>

Jeff Butler



On 9/18/07, Peter Martin <pm...@adobe.com> wrote:
>
> I want to pass in a List as a parameter class and select the first item
> from the list. I know it is possible to use the <iterate> tag, but is it
> possible to pull out a single item for a given index? For example, in the
> following select I to get the item at position 0:
>
>    <select id="countPeopleWithSurname" parameterClass="java.util.List"
> resultClass="int">
>       SELECT count(*) FROM person WHERE per_last_name = <item 0>
>    </select>
>
>
> Likewise in an insert I may want to pull out the different items:
>
>
> <insert id="insertPerson" parameterClass="person">
> INSERT INTO PERSON (PER_ID, PER_FIRST_NAME, PER_LAST_NAME,
> PER_BIRTH_DATE, PER_WEIGHT_KG, PER_HEIGHT_M) VALUES (<item 0>,
> <item 1>, <item 2>, <item 3>, <item 4>, <item 5>)
> </insert>
>
>
> Thanks
> Peter
>
>
>
>
>
>

Re: Using java.util.List as the parameterClass

Posted by Peter Martin <pm...@adobe.com>.
Thanks for your reply.

I am actually trying to write an assembler for LiveCycle Data  
Services, which provides data management services.  These data  
management services can be consumed by a Flex client. The Assembler  
interface (http://livedocs.adobe.com/livecycle/es/sdkHelp/programmer/ 
lcdsjavadoc/) receives its parameters as a List, ideally I wanted to  
pass this straight through to my sqlmap.

I have it working at the moment, but my assembler is turning the the  
list in to a map (the key is the index of the item in the list),  
which allows me to do something like this:

	<select id="countPeopleWithSurname" parameterClass="java.util.Map"
		resultClass="int">
		SELECT count(*) FROM person WHERE per_last_name = #0#
	</select>



On 18 Sep 2007, at 15:32, Brandon Goodin wrote:

> No, that is currently not possible. If you only ever want the first  
> index then just pass in the first index from your DAO. Not sure  
> what you are trying to accomplish but it looks like it would be  
> better handled in java and not the sqlmap. If you want to provide  
> more information about the context of your decision we might be  
> able to help in determining a good alternative. It may be possible  
> to do this in the future with iB3. But, i don't see it happening in  
> iB2.
>
> Brandon
>
> On 9/18/07, Peter Martin <pm...@adobe.com> wrote:
> I want to pass in a List as a parameter class and select the first  
> item from the list. I know it is possible to use the <iterate> tag,  
> but is it possible to pull out a single item for a given index? For  
> example, in the following select I to get the item at position 0:
>
>    <select id= "countPeopleWithSurname" parameterClass  
> ="java.util.List" resultClass ="int" >
>       SELECT count(*) FROM person WHERE per_last_name = <item 0>
>    </select >
>
> Likewise in an insert I may want to pull out the different items:
>
>  	<insert id="insertPerson" parameterClass="person" >
> 		 INSERT INTO PERSON (PER_ID, PER_FIRST_NAME, PER_LAST_NAME,
> 		 PER_BIRTH_DATE, PER_WEIGHT_KG, PER_HEIGHT_M) VALUES (<item 0>,
> 		 <item 1>, <item 2>, <item 3>, <item 4>, <item 5>)
> 	</ insert>
>
> Thanks
> Peter
>
>
>
>



Cheers
Peter.

-- 
Peter Martin
Technical Architect
Adobe Consulting
Westpoint, 4 Redheughs Rigg, South Gyle, Edinburgh, EH12 9DQ, UK
p: +44 (0) 131 338 6108 m: +44 (0) 7825 032160

Adobe Systems Europe Limited | Registered office: 151 St. Vincent  
Street, Glasgow G2 5NJ | Company No. SC101089






Re: Using java.util.List as the parameterClass

Posted by Brandon Goodin <br...@gmail.com>.
No, that is currently not possible. If you only ever want the first index
then just pass in the first index from your DAO. Not sure what you are
trying to accomplish but it looks like it would be better handled in java
and not the sqlmap. If you want to provide more information about the
context of your decision we might be able to help in determining a good
alternative. It may be possible to do this in the future with iB3. But, i
don't see it happening in iB2.

Brandon

On 9/18/07, Peter Martin <pm...@adobe.com> wrote:
>
> I want to pass in a List as a parameter class and select the first item
> from the list. I know it is possible to use the <iterate> tag, but is it
> possible to pull out a single item for a given index? For example, in the
> following select I to get the item at position 0:
>    <select id="countPeopleWithSurname" parameterClass="java.util.List"
> resultClass="int">
>       SELECT count(*) FROM person WHERE per_last_name = <item 0>
>    </select>
>
> Likewise in an insert I may want to pull out the different items:
>
> <insert id="insertPerson" parameterClass="person">
>  INSERT INTO PERSON (PER_ID, PER_FIRST_NAME, PER_LAST_NAME,
>  PER_BIRTH_DATE, PER_WEIGHT_KG, PER_HEIGHT_M) VALUES (<item 0>,
>  <item 1>, <item 2>, <item 3>, <item 4>, <item 5>)
> </insert>
>
> Thanks
> Peter
>
>
>
>