org.mybatis.spring
Interface SqlSessionCallback<T>


public interface SqlSessionCallback<T>

Callback interface for data access code that works with the MyBatis Executor interface. To be used with SqlSessionTemplate's execute method, assumably often as anonymous classes within a method implementation.

Version:
$Id: SqlSessionCallback.java 2662 2010-10-09 22:26:07Z eduardo.macarron $
See Also:
SqlSessionTemplate, DataSourceTransactionManager

Method Summary
 T doInSqlSession(org.apache.ibatis.session.SqlSession sqlSession)
          Gets called by SqlSessionTemplate.execute with an active SqlSession.
 

Method Detail

doInSqlSession

T doInSqlSession(org.apache.ibatis.session.SqlSession sqlSession)
Gets called by SqlSessionTemplate.execute with an active SqlSession. Does not need to care about activating or closing the SqlSession , or handling transactions.

If called without a thread-bound JDBC transaction (initiated by DataSourceTransactionManager), the code will simply get executed on the underlying JDBC connection with its transactional semantics. If using a JTA-aware DataSource, the JDBC connection and thus the callback code will be transactional if a JTA transaction is active.

Allows for returning a result object created within the callback, i.e. a domain object or a collection of domain objects. A thrown custom RuntimeException is treated as an application exception: It gets propagated to the caller of the template.

Parameters:
sqlSession - an active MyBatis SqlSession, passed-in as Executor interface here to avoid manual life-cycle handling
Returns:
a result object, or null if none
See Also:
SqlSessionTemplate.execute(org.mybatis.spring.SqlSessionCallback)


Copyright © 2010 MyBatis.org. All Rights Reserved.