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: XML vs Annotations
Date Sun, 07 Feb 2010 22:27:30 GMT
The current APIs are optimized for "configurators", such as XML and
Annotations.  If you guys are going to go this route, you'll probably want
to create your own wrapper classes to simplify the configuration.

Clinton

On Sun, Feb 7, 2010 at 2:48 PM, Guy Rouillier <guyr-ml1@burntmail.com>wrote:

> I don't know if what you are trying to do is possible, but it seems to
> defeat the intent of iBATIS (remove all the routine JDBC code and replace it
> with declarations, so your Java code becomes much simpler.)
>
> If you are going to add lots of Java code to build the mappings, you might
> as well just go back to using straight JDBC.
>
>
> On 2/6/2010 5:21 PM, Daryl Stultz wrote:
>
>>
>>
>> On Sat, Feb 6, 2010 at 3:29 PM, Daryl Stultz <daryl@6degrees.com
>> <mailto: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 <mailto:daryl@6degrees.com>
>>
>
>
> --
> Guy Rouillier
>
> ---------------------------------------------------------------------
> 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