iBATIS 3 @InsertProvider (and other @*Provider) annotation question

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

iBATIS 3 @InsertProvider (and other @*Provider) annotation question

Alex Sherwin
I just want to make sure, but there is there simply no way to pass
arguments to the sql provider method defined in the annotations such as
@InsertProvider?

It would be very beneficial to be able to do so in terms of building
dynamic sql, such as an insert statements for a dynamic number of rows

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iBATIS 3 @InsertProvider (and other @*Provider) annotation question

Jeff Butler-2
Not right - the parameter object on the interface method is passed to
the *Provider method:

// interface...
@InsertProvider(type=MyProvider.class, method="myInsert")
int insertFoo(Foo foo);


// provider method...
public String myInsert(Foo foo) {
 ....
}

Works like a charm.

BTW - join us at the new project - www.mybatis.org
New mailing list: http://groups.google.com/group/mybatis-user


Jeff Butler




On Fri, May 21, 2010 at 9:23 AM, Alex Sherwin
<[hidden email]> wrote:

> I just want to make sure, but there is there simply no way to pass arguments
> to the sql provider method defined in the annotations such as
> @InsertProvider?
>
> It would be very beneficial to be able to do so in terms of building dynamic
> sql, such as an insert statements for a dynamic number of rows
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iBATIS 3 @InsertProvider (and other @*Provider) annotation question

Alex Sherwin
In reply to this post by Alex Sherwin
On 5/21/2010 10:23 AM, Alex Sherwin wrote:

> I just want to make sure, but there is there simply no way to pass
> arguments to the sql provider method defined in the annotations such
> as @InsertProvider?
>
> It would be very beneficial to be able to do so in terms of building
> dynamic sql, such as an insert statements for a dynamic number of rows
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
>
After stepping through the code I've answered my own question, I don't
know how I missed that before; and I also see it underlined specifically
in the documentation.. missed that as well somehow.

My next question is, which the documentation doesn't touch upon, is
there a notation for directly accessing members of an array or list?  
Ultimately, my question is, in a java sql provider, can I pass in a
List/Array of objects and generate (pseudo) sql such as this:

insert into tbl (id, field) values (#{ilst[0].id}, #{list[0].field},
#{list[1].id}, #{list[2].id}, .. )

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iBATIS 3 @InsertProvider (and other @*Provider) annotation question

Jeff Butler-2
Yes - that works.  iBATIS is using OGNL to interpret the parameters,
so any valid OGNL expression works.

Jeff Butler


On Fri, May 21, 2010 at 10:04 AM, Alex Sherwin
<[hidden email]> wrote:

> On 5/21/2010 10:23 AM, Alex Sherwin wrote:
>>
>> I just want to make sure, but there is there simply no way to pass
>> arguments to the sql provider method defined in the annotations such as
>> @InsertProvider?
>>
>> It would be very beneficial to be able to do so in terms of building
>> dynamic sql, such as an insert statements for a dynamic number of rows
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>>
> After stepping through the code I've answered my own question, I don't know
> how I missed that before; and I also see it underlined specifically in the
> documentation.. missed that as well somehow.
>
> My next question is, which the documentation doesn't touch upon, is there a
> notation for directly accessing members of an array or list?  Ultimately, my
> question is, in a java sql provider, can I pass in a List/Array of objects
> and generate (pseudo) sql such as this:
>
> insert into tbl (id, field) values (#{ilst[0].id}, #{list[0].field},
> #{list[1].id}, #{list[2].id}, .. )
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iBATIS 3 @InsertProvider (and other @*Provider) annotation question

Alex Sherwin
Method is annotated with @InsertProvider, my implementation method takes
a Map<String, Object> and can see the array passed in keyed with "array"
(I also explicitly set its name with @Param to be sure it was consitent
in my sql provider and where it creates the prepared statement values)

Generated sql in java:
INSERT INTO test (id, field) VALUES (#{array[0].id}, #{array[0].field}),
(#{array[1].id}, #{array[1].field}), (#{array[2].id}, #{array[2].field})

However, when the sql is run with a array of 3 objects, which in order
have id's 1,2,3 and field values "field1", "field2", "field3", in this
case it only populated the values for the last item in the array, and
into the second position of the parameter values..

==>  Executing: INSERT INTO test (id, field) VALUES (?, ?), (?, ?), (?, ?)
==> Parameters: null, null, 3, field3(String), null, null

This isn't the behavior one would expect, no?

On 5/21/2010 11:10 AM, Jeff Butler wrote:

> Yes - that works.  iBATIS is using OGNL to interpret the parameters,
> so any valid OGNL expression works.
>
> Jeff Butler
>
>
> On Fri, May 21, 2010 at 10:04 AM, Alex Sherwin
> <[hidden email]>  wrote:
>    
>> On 5/21/2010 10:23 AM, Alex Sherwin wrote:
>>      
>>> I just want to make sure, but there is there simply no way to pass
>>> arguments to the sql provider method defined in the annotations such as
>>> @InsertProvider?
>>>
>>> It would be very beneficial to be able to do so in terms of building
>>> dynamic sql, such as an insert statements for a dynamic number of rows
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>>
>>>
>>>        
>> After stepping through the code I've answered my own question, I don't know
>> how I missed that before; and I also see it underlined specifically in the
>> documentation.. missed that as well somehow.
>>
>> My next question is, which the documentation doesn't touch upon, is there a
>> notation for directly accessing members of an array or list?  Ultimately, my
>> question is, in a java sql provider, can I pass in a List/Array of objects
>> and generate (pseudo) sql such as this:
>>
>> insert into tbl (id, field) values (#{ilst[0].id}, #{list[0].field},
>> #{list[1].id}, #{list[2].id}, .. )
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>>      
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
>
>    


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iBATIS 3 @InsertProvider (and other @*Provider) annotation question

Alex Sherwin
Alright.. don't waste your time, it works fine as one would expect when
given proper input.  Sorry about that, I'm usually more thorough before
resorting to mailing lists

On 5/21/2010 11:33 AM, Alex Sherwin wrote:

> Method is annotated with @InsertProvider, my implementation method
> takes a Map<String, Object> and can see the array passed in keyed with
> "array" (I also explicitly set its name with @Param to be sure it was
> consitent in my sql provider and where it creates the prepared
> statement values)
>
> Generated sql in java:
> INSERT INTO test (id, field) VALUES (#{array[0].id},
> #{array[0].field}), (#{array[1].id}, #{array[1].field}),
> (#{array[2].id}, #{array[2].field})
>
> However, when the sql is run with a array of 3 objects, which in order
> have id's 1,2,3 and field values "field1", "field2", "field3", in this
> case it only populated the values for the last item in the array, and
> into the second position of the parameter values..
>
> ==>  Executing: INSERT INTO test (id, field) VALUES (?, ?), (?, ?),
> (?, ?)
> ==> Parameters: null, null, 3, field3(String), null, null
>
> This isn't the behavior one would expect, no?
>
> On 5/21/2010 11:10 AM, Jeff Butler wrote:
>> Yes - that works.  iBATIS is using OGNL to interpret the parameters,
>> so any valid OGNL expression works.
>>
>> Jeff Butler
>>
>>
>> On Fri, May 21, 2010 at 10:04 AM, Alex Sherwin
>> <[hidden email]>  wrote:
>>> On 5/21/2010 10:23 AM, Alex Sherwin wrote:
>>>> I just want to make sure, but there is there simply no way to pass
>>>> arguments to the sql provider method defined in the annotations
>>>> such as
>>>> @InsertProvider?
>>>>
>>>> It would be very beneficial to be able to do so in terms of building
>>>> dynamic sql, such as an insert statements for a dynamic number of rows
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [hidden email]
>>>> For additional commands, e-mail: [hidden email]
>>>>
>>>>
>>>>
>>> After stepping through the code I've answered my own question, I
>>> don't know
>>> how I missed that before; and I also see it underlined specifically
>>> in the
>>> documentation.. missed that as well somehow.
>>>
>>> My next question is, which the documentation doesn't touch upon, is
>>> there a
>>> notation for directly accessing members of an array or list?  
>>> Ultimately, my
>>> question is, in a java sql provider, can I pass in a List/Array of
>>> objects
>>> and generate (pseudo) sql such as this:
>>>
>>> insert into tbl (id, field) values (#{ilst[0].id}, #{list[0].field},
>>> #{list[1].id}, #{list[2].id}, .. )
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...