ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Clinton Begin <clinton.be...@gmail.com>
Subject Re: Unconstrained signature interface mappers for ibatis 3
Date Sun, 30 Aug 2009 18:58:57 GMT
I think your point about the "prioritizing" the rest of the application
code, even at the expense of a bit of duplication in the interface, is a
good one.  And if that's the case, I think my preference would be for this
syntax:

@Select("select * from employee where first_name = #{firstName} and
last_name = #{lastName})
List<Employee> findEmployeesLike(@Param("firstName") String firstName,
@Param("lastName") String lastName);

The reason being, we'd need to mark the "special" parameters for
pagination.  Unless I introduce a class for that..... hmmm... what are your
thoughts on the following two options:

@Select("select * from employee where first_name = #{firstName} and
last_name = #{lastName})
List<Employee> findEmployeesLike(@Param("firstName") String firstName,
@Param("lastName") String lastName, @Offset int offset, @Limit, int limit);

@Select("select * from employee where first_name = #{firstName} and
last_name = #{lastName})
List<Employee> findEmployeesLike(@Param("firstName") String firstName,
@Param("lastName") String lastName, Constraint offsetLimit);

Where the latter would be used like:

findEmployeesLike("C%", "B%", new Constraint(offset,limit));

I could detect the constraint type and treat all other parameters like SQL
parameters.  I could do the same with the ResultHandler...

findEmployeesLike("C%", "B%", new Constraint(offset,limit), new
ResultHandler(){...});

I think I answered my own question, I definitely like that better than the
annotations (other than for the actual parameters themselves.  Hmmm... I
almost like that better than how I have it now.  It does introduce an iBATIS
type into your Mapper signature though... But then again ResultHandler is a
dependency already.  I suppose if I wanted to go crazy I could accept any
class named Constraint that had two integer properties ... LOL :-)

Thoughts?

Cheers,
Clinton

On Sun, Aug 30, 2009 at 12:03 PM, <carlosjosepita@gmail.com> wrote:

> > I really wish Java made this easier.  One thought I had to submit to the
> JCP
> > was to add introspection on parameter names by having the compiler
> > automatically create annotations for the parameter names.
>
> This was scheduled for java 6 but it was postponed, now it seems unlikely
> that java 7 will introduce it either, so we have to wait for java 8 at
> least.
>
> There is the paranamer library that follows an approach similar to the
> one I described in my previous mail: it obtains the info parsing the
> debug enabled bytecode with asm.
>
> Regards
> --
> Carlos
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>

Mime
View raw message