Quantcast

Advance Warning: API Change in iBATIS 3 Beta 4

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

Advance Warning: API Change in iBATIS 3 Beta 4

Clinton Begin
Hi all,

As with any major release, once it's in the wild, we find things that we'd like to change.  Rather than live with something we're not happy with for the next few years, we've decided to make a couple of simple API changes to clean a few things up.

First:  

  List selectList(String statement, Object parameter, RowBounds rowBounds)
  void select(String statement, Object parameter, RowBounds rowBounds, ResultHandler handler)

These methods used to take two int params to define the OFFSET and LIMIT for limiting the rows that were returned (for paging etc).  We've introduced the RowBounds class to clean that up, but also to allow for multi-parameter bindings.  So that this is now possible in Mapper classes:

  List<Post> findAllPostsLike(@Param("subject") String subject, @Param("body") String body, RowBounds rowBounds);

RowBounds can be any parameter, not necessarily the last one.  You don't have to specify @Param, as it will default to using the ordinal position e.g. #{1} #{2}, but with the @Param annotations, you can use #{subject} and #{body}.  If you only specify a single parameter, then it's passed as always, as the top level parameter (with all properties accessible by name without qualification).

Also, I've moved ALL classes that SqlSession and SqlSessionFactory depend upon, into the .session package.  Therefore you don't have to import so many packages, and the classes will be easier to find if you're looking for them (balancing practicality with practice).  The affected classes include: Configuration, ResultHandler, RowBounds, ExecutorType, and ResultContext.

I think these changes were worth it, despite the slight annoyance.  Any modern IDE will have this fixed up for you in minutes.

Clinton 

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

Re: Advance Warning: API Change in iBATIS 3 Beta 4

Guy Rouillier-2
Clinton Begin wrote:

>   List selectList(String statement, Object parameter, RowBounds rowBounds)
>   void select(String statement, Object parameter, RowBounds rowBounds,
> ResultHandler handler)
>
> These methods used to take two int params to define the OFFSET and LIMIT
> for limiting the rows that were returned (for paging etc)  We've
> introduced the RowBounds class to clean that up, but also to allow for
> multi-parameter bindings.  So that this is now possible in Mapper classes:
>
>   List<Post> findAllPostsLike(@Param("subject") String
> subject, @Param("body") String body, RowBounds rowBounds);
>
> RowBounds can be any parameter, not necessarily the last one.  You don't
> have to specify @Param, as it will default to using the ordinal position
> e.g. #{1} #{2}, but with the @Param annotations, you can use #{subject}
> and #{body}.  If you only specify a single parameter, then it's passed
> as always, as the top level parameter (with all properties accessible by
> name without qualification).

Clinton, thank you very much for the tremendous amount of effort you put
into iBatis.

I'm unclear about the XML implementation of multiple parameter bindings.
  I couldn't find any full examples in the PDF, so I looked in
XMLStatementBuilder.java.  Looks like parameterType is still a
single-valued entry.  So, with the example you provide above, what would
we enter for parameterType in the XML file?  Seems like parameterType
will have to become a multi-valued list (comma-separated or some
alternative.)

--
Guy Rouillier

---------------------------------------------------------------------
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: Advance Warning: API Change in iBATIS 3 Beta 4

Clinton Begin
Multiple parameter support like this:

insertSomething(@Param("param1") int param1, @Param("param2") int param2) 

is basically shorthand for:

Map params = new HashMap();
params.put("param1", someObject);
params.put("param2", otherObject);


So, the parameter type for multiple parameters is always Map.

<insert ... parameterType="map">

Parameter type binding in iBATIS 3 is a lot looser than it was in iBATIS 2, and is more like iBATIS 1.  There's not a lot of benefit to locking down the parameter type, so I went with the simpler syntax to avoid something like the Generics over-typing nightmare.

iBATIS knows the type of the parameter when you pass it.

Clinton

On Sun, Oct 11, 2009 at 11:50 PM, Guy Rouillier <[hidden email]> wrote:
Clinton Begin wrote:
 List selectList(String statement, Object parameter, RowBounds rowBounds)
 void select(String statement, Object parameter, RowBounds rowBounds, ResultHandler handler)

These methods used to take two int params to define the OFFSET and LIMIT for limiting the rows that were returned (for paging etc)  We've introduced the RowBounds class to clean that up, but also to allow for multi-parameter bindings.  So that this is now possible in Mapper classes:

 List<Post> findAllPostsLike(@Param("subject") String subject, @Param("body") String body, RowBounds rowBounds);

RowBounds can be any parameter, not necessarily the last one.  You don't have to specify @Param, as it will default to using the ordinal position e.g. #{1} #{2}, but with the @Param annotations, you can use #{subject} and #{body}.  If you only specify a single parameter, then it's passed as always, as the top level parameter (with all properties accessible by name without qualification).

Clinton, thank you very much for the tremendous amount of effort you put into iBatis.

I'm unclear about the XML implementation of multiple parameter bindings.  I couldn't find any full examples in the PDF, so I looked in XMLStatementBuilder.java.  Looks like parameterType is still a single-valued entry.  So, with the example you provide above, what would we enter for parameterType in the XML file?  Seems like parameterType will have to become a multi-valued list (comma-separated or some alternative.)

--
Guy Rouillier

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


Loading...