ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simone Tripodi <simone.trip...@gmail.com>
Subject Re: XML vs Annotations
Date Sat, 06 Feb 2010 23:25:32 GMT
Hi all,
I'm *very* interested too on this last topic, I'd really would like to
know more about it :P
Have a good weekend,
Simo

http://people.apache.org/~simonetripodi/



On Sat, Feb 6, 2010 at 11:21 PM, Daryl Stultz <daryl@6degrees.com> wrote:
>
>
> On Sat, Feb 6, 2010 at 3:29 PM, Daryl Stultz <daryl@6degrees.com> wrote:
>>
>>
>> Hmm, I may be stuck then on finding my own "style" of using iBATIS.
>>
> I'm wondering if I can do away with XML and annotations and build the
> mappings programmatically. So far I've done this:
> SqlSession session = factory.openSession();
> final Configuration configuration = session.getConfiguration();
> SqlSource sqlSource = new SqlSource() {
> public BoundSql getBoundSql(Object parameterObject) {
> List<ParameterMapping> paramMap = new ArrayList<ParameterMapping>();
> paramMap.add(new ParameterMapping.Builder(configuration, "id",
> configuration.getTypeHandlerRegistry().getTypeHandler(Integer.class)).build());
> return new BoundSql(configuration, "select userId as user_id, name as
> user_name, userTypeId as user_userTypeId\n" +
> " from Users \n" +
> " where userId = ?", paramMap, parameterObject);
> }
> };
> MappedStatement.Builder builder = new MappedStatement.Builder(configuration,
> "model.UserMapper.findById", sqlSource, SqlCommandType.SELECT);
> final MappedStatement ms = builder.build();
> configuration.addMappedStatement(ms);
> To replace this:
> <select id="findById" parameterType="Integer" resultMap="userResult">
> select userId as user_id, name as user_name, userTypeId as user_userTypeId
> from Users
> where userId = #{id}
> </select>
> It doesn't work, since I haven't figured out how to specify the resultMap.
> Can anyone tell me if this is a futile effort, or is it reasonable to think
> I can build up my configuration entirely with Java objects (no annotations)?
> Thanks.
> --
> Daryl Stultz
> _____________________________________
> 6 Degrees Software and Consulting, Inc.
> http://www.6degrees.com
> mailto:daryl@6degrees.com
>

---------------------------------------------------------------------
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