Package org.mybatis.spring.support
Class SqlSessionDaoSupport
java.lang.Object
org.springframework.dao.support.DaoSupport
org.mybatis.spring.support.SqlSessionDaoSupport
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean
- Direct Known Subclasses:
MapperFactoryBean
public abstract class SqlSessionDaoSupport
extends org.springframework.dao.support.DaoSupport
Convenient super class for MyBatis SqlSession data access objects. It gives you access to the template which can then
be used to execute SQL methods.
This class needs a SqlSessionTemplate or a SqlSessionFactory. If both are set the SqlSessionFactory will be ignored.
- Author:
- Putthiphong Boonphong, Eduardo Macarron
- See Also:
setSqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory)
,setSqlSessionTemplate(org.mybatis.spring.SqlSessionTemplate)
,SqlSessionTemplate
-
Field Summary
Fields inherited from class org.springframework.dao.support.DaoSupport
logger
-
Constructor Summary
Constructors Constructor Description SqlSessionDaoSupport()
-
Method Summary
Modifier and Type Method Description protected void
checkDaoConfig()
protected SqlSessionTemplate
createSqlSessionTemplate(org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory)
Create a SqlSessionTemplate for the given SqlSessionFactory.org.apache.ibatis.session.SqlSession
getSqlSession()
Users should use this method to get a SqlSession to call its statement methods This is SqlSession is managed by spring.org.apache.ibatis.session.SqlSessionFactory
getSqlSessionFactory()
Return the MyBatis SqlSessionFactory used by this DAO.SqlSessionTemplate
getSqlSessionTemplate()
Return the SqlSessionTemplate for this DAO, pre-initialized with the SessionFactory or set explicitly.void
setSqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory)
Set MyBatis SqlSessionFactory to be used by this DAO.void
setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate)
Set the SqlSessionTemplate for this DAO explicitly, as an alternative to specifying a SqlSessionFactory.Methods inherited from class org.springframework.dao.support.DaoSupport
afterPropertiesSet, initDao
-
Constructor Details
-
SqlSessionDaoSupport
public SqlSessionDaoSupport()
-
-
Method Details
-
setSqlSessionFactory
public void setSqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory)Set MyBatis SqlSessionFactory to be used by this DAO. Will automatically create SqlSessionTemplate for the given SqlSessionFactory.- Parameters:
sqlSessionFactory
- a factory of SqlSession
-
createSqlSessionTemplate
protected SqlSessionTemplate createSqlSessionTemplate(org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory)Create a SqlSessionTemplate for the given SqlSessionFactory. Only invoked if populating the DAO with a SqlSessionFactory reference!Can be overridden in subclasses to provide a SqlSessionTemplate instance with different configuration, or a custom SqlSessionTemplate subclass.
- Parameters:
sqlSessionFactory
- the MyBatis SqlSessionFactory to create a SqlSessionTemplate for- Returns:
- the new SqlSessionTemplate instance
- See Also:
setSqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory)
-
getSqlSessionFactory
public final org.apache.ibatis.session.SqlSessionFactory getSqlSessionFactory()Return the MyBatis SqlSessionFactory used by this DAO.- Returns:
- a factory of SqlSession
-
setSqlSessionTemplate
Set the SqlSessionTemplate for this DAO explicitly, as an alternative to specifying a SqlSessionFactory.- Parameters:
sqlSessionTemplate
- a template of SqlSession- See Also:
setSqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory)
-
getSqlSession
public org.apache.ibatis.session.SqlSession getSqlSession()Users should use this method to get a SqlSession to call its statement methods This is SqlSession is managed by spring. Users should not commit/rollback/close it because it will be automatically done.- Returns:
- Spring managed thread safe SqlSession
-
getSqlSessionTemplate
Return the SqlSessionTemplate for this DAO, pre-initialized with the SessionFactory or set explicitly.Note: The returned SqlSessionTemplate is a shared instance. You may introspect its configuration, but not modify the configuration (other than from within an
DaoSupport.initDao()
implementation). Consider creating a custom SqlSessionTemplate instance vianew SqlSessionTemplate(getSqlSessionFactory())
, in which case you're allowed to customize the settings on the resulting instance.- Returns:
- a template of SqlSession
-
checkDaoConfig
protected void checkDaoConfig()- Specified by:
checkDaoConfig
in classorg.springframework.dao.support.DaoSupport
-