|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.mybatis.spring.SqlSessionFactoryBean
public class SqlSessionFactoryBean
FactoryBean
that creates an MyBatis
SqlSessionFactory
. This is the usual way to set up a shared
MyBatis SqlSessionFactory in a Spring application context; the SqlSessionFactory can then be
passed to MyBatis-based DAOs via dependency injection.
Either DataSourceTransactionManager
or
JtaTransactionManager
can be used for transaction
demarcation in combination with a SqlSessionFactory. JTA should be used for transactions
which span multiple databases or when container managed transactions (CMT) are being used.
Allows for specifying a DataSource at the SqlSessionFactory level. This is preferable to per-DAO
DataSource references, as it allows for lazy loading and avoids repeated DataSource references in
every DAO.
setConfigLocation(org.springframework.core.io.Resource)
,
setDataSource(javax.sql.DataSource)
Constructor Summary | |
---|---|
SqlSessionFactoryBean()
|
Method Summary | ||
---|---|---|
void |
afterPropertiesSet()
|
|
protected org.apache.ibatis.session.SqlSessionFactory |
buildSqlSessionFactory()
Build a SqlSessionFactory instance. |
|
org.apache.ibatis.session.SqlSessionFactory |
getObject()
|
|
Class<? extends org.apache.ibatis.session.SqlSessionFactory> |
getObjectType()
|
|
boolean |
isSingleton()
|
|
void |
setConfigLocation(org.springframework.core.io.Resource configLocation)
Set the location of the MyBatis SqlSessionFactory config file. |
|
void |
setConfigurationProperties(Properties sqlSessionFactoryProperties)
Set optional properties to be passed into the SqlSession configuration, as alternative to a <properties> tag in the configuration xml file. |
|
void |
setDataSource(DataSource dataSource)
Set the JDBC DataSource that this instance should manage transactions for. |
|
void |
setEnvironment(String environment)
NOTE: This class overrides any Environment you have set in the MyBatis config file. |
|
void |
setMapperLocations(org.springframework.core.io.Resource[] mapperLocations)
Set locations of MyBatis mapper files that are going to be merged into the SqlSessionFactory configuration at runtime. |
|
void |
setSqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder sqlSessionFactoryBuilder)
Sets the SqlSessionFactoryBuilder to use when creating the SqlSessionFactory. |
|
|
setTransactionFactoryClass(Class<TF> transactionFactoryClass)
Set the MyBatis TransactionFactory class to use. |
|
void |
setTransactionFactoryProperties(Properties transactionFactoryProperties)
Set properties to be passed to the TransactionFactory instance used by this SqlSessionFactory. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SqlSessionFactoryBean()
Method Detail |
---|
public void setConfigLocation(org.springframework.core.io.Resource configLocation)
public void setMapperLocations(org.springframework.core.io.Resource[] mapperLocations)
public void setConfigurationProperties(Properties sqlSessionFactoryProperties)
<properties>
tag in the configuration xml file. This will be used to
resolve placeholders in the config file.
Configuration.getVariables()
public void setDataSource(DataSource dataSource)
TransactionAwareDataSourceProxy
,
DataSourceUtils
,
DataSourceTransactionManager
public void setSqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder sqlSessionFactoryBuilder)
DefaultSqlSessionFactory instances.
- See Also:
SqlSessionFactoryBuilder
public <TF extends org.apache.ibatis.transaction.TransactionFactory> void setTransactionFactoryClass(Class<TF> transactionFactoryClass)
SpringManagedTransactionFactory
.
The default SpringManagedTransactionFactory should be appropriate for all cases: be it Spring
transaction management, EJB CMT or plain JTA. If there is no active transaction, SqlSession
operations will execute SQL statements non-transactionally.
It is strongly recommended to use the default TransactionFactory. If not used, any
attempt at getting an SqlSession through Spring's MyBatis framework will throw an exception if
a transaction is active.
TF
- the MyBatis TransactionFactory typetransactionFactoryClass
- the MyBatis TransactionFactory class to usesetDataSource(javax.sql.DataSource)
,
setTransactionFactoryProperties(java.util.Properties)
,
TransactionFactory
,
SpringManagedTransactionFactory
,
Transaction
public void setTransactionFactoryProperties(Properties transactionFactoryProperties)
TransactionFactory.setProperties(java.util.Properties)
,
JdbcTransactionFactory
,
ManagedTransactionFactory
public void setEnvironment(String environment)
SqlSessionFactoryBean.class.getSimpleName()
.
environment
- the environment namepublic void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
Exception
protected org.apache.ibatis.session.SqlSessionFactory buildSqlSessionFactory() throws IOException, IllegalAccessException, InstantiationException
XMLConfigBuilder
API to build a
SqlSessionFactory instance based on an Reader.
IOException
- if loading the config file failed
IllegalAccessException
InstantiationException
XMLConfigBuilder.parse()
public org.apache.ibatis.session.SqlSessionFactory getObject() throws Exception
getObject
in interface org.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>
Exception
public Class<? extends org.apache.ibatis.session.SqlSessionFactory> getObjectType()
getObjectType
in interface org.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>
public boolean isSingleton()
isSingleton
in interface org.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |