On Sat, Feb 6, 2010 at 3:29 PM, Daryl Stultz <da...@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:da...@6degrees.com

Reply via email to