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 <da...@6degrees.com
<mailto: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 <mailto:da...@6degrees.com>


--
Guy Rouillier

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
For additional commands, e-mail: user-java-h...@ibatis.apache.org

Reply via email to