|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.mybatis.spring.SqlSessionFactoryBean
org.alfresco.ibatis.HierarchicalSqlSessionFactoryBean
public class HierarchicalSqlSessionFactoryBean
Extends the MyBatis-Spring support by allowing a choice of
ResourceLoader
. The
ResourceLoader
will be used to load the SqlMapConfig
file and use a HierarchicalXMLConfigBuilder
to read the individual MyBatis (3.x) resources.
Pending a better way to extend/override, much of the implementation is a direct copy of the MyBatis-Spring
SqlSessionFactoryBean
; some of the protected methods do not have access to the object's state
and can therefore not be overridden successfully.
This is equivalent to HierarchicalSqlMapClientFactoryBean which extended iBatis (2.x).
See also: IBATIS-589
and:
Constructor Summary | |
---|---|
HierarchicalSqlSessionFactoryBean()
Default constructor |
Method Summary | |
---|---|
void |
afterPropertiesSet()
|
protected org.apache.ibatis.session.SqlSessionFactory |
buildSqlSessionFactory()
Build a SqlSessionFactory instance. |
org.apache.ibatis.session.SqlSessionFactory |
getObject()
|
java.lang.Class |
getObjectType()
|
void |
setConfigLocation(org.springframework.core.io.Resource configLocation)
Set the location of the MyBatis SqlSessionFactory config file. |
void |
setConfigurationProperties(java.util.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(javax.sql.DataSource dataSource)
Set the JDBC DataSource that this instance should manage transactions for. |
void |
setEnvironment(java.lang.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 |
setResourceLoader(HierarchicalResourceLoader resourceLoader)
Set the resource loader to use. |
void |
setSqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder sqlSessionFactoryBuilder)
Sets the SqlSessionFactoryBuilder to use when creating the SqlSessionFactory . |
void |
setTransactionFactory(org.apache.ibatis.transaction.TransactionFactory transactionFactory)
Set the MyBatis TransactionFactory to use. |
Methods inherited from class org.mybatis.spring.SqlSessionFactoryBean |
---|
isSingleton, onApplicationEvent, setFailFast, setPlugins, setTypeAliases, setTypeAliasesPackage, setTypeHandlers, setTypeHandlersPackage |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HierarchicalSqlSessionFactoryBean()
Method Detail |
---|
public void setResourceLoader(HierarchicalResourceLoader resourceLoader)
HierarchicalResourceLoader
.
resourceLoader
- the resource loader to usepublic void afterPropertiesSet() throws java.lang.Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
afterPropertiesSet
in class org.mybatis.spring.SqlSessionFactoryBean
java.lang.Exception
public void setConfigLocation(org.springframework.core.io.Resource configLocation)
SqlSessionFactory
config file. A typical value is
"WEB-INF/mybatis-configuration.xml".
setConfigLocation
in class org.mybatis.spring.SqlSessionFactoryBean
public void setMapperLocations(org.springframework.core.io.Resource[] mapperLocations)
SqlSessionFactory
configuration at runtime.
This is an alternative to specifying "<sqlmapper>" entries in an MyBatis config file.
This property being based on Spring's resource abstraction also allows for specifying
resource patterns here: e.g. "classpath*:sqlmap/*-mapper.xml".
setMapperLocations
in class org.mybatis.spring.SqlSessionFactoryBean
public void setConfigurationProperties(java.util.Properties sqlSessionFactoryProperties)
<properties>
tag in the configuration xml file. This will be used to
resolve placeholders in the config file.
setConfigurationProperties
in class org.mybatis.spring.SqlSessionFactoryBean
public void setDataSource(javax.sql.DataSource dataSource)
DataSource
that this instance should manage transactions for. The DataSource
should match the one used by the SqlSessionFactory
: for example, you could specify the same
JNDI DataSource for both.
A transactional JDBC Connection
for this DataSource
will be provided to application code
accessing this DataSource
directly via DataSourceUtils
or DataSourceTransactionManager
.
The DataSource
specified here should be the target DataSource
to manage transactions for, not
a TransactionAwareDataSourceProxy
. Only data access code may work with
TransactionAwareDataSourceProxy
, while the transaction manager needs to work on the
underlying target DataSource
. If there's nevertheless a TransactionAwareDataSourceProxy
passed in, it will be unwrapped to extract its target DataSource
.
setDataSource
in class org.mybatis.spring.SqlSessionFactoryBean
public void setSqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder sqlSessionFactoryBuilder)
SqlSessionFactoryBuilder
to use when creating the SqlSessionFactory
.
This is mainly meant for testing so that mock SqlSessionFactory classes can be injected. By
default, SqlSessionFactoryBuilder
creates DefaultSqlSessionFactory
instances.
setSqlSessionFactoryBuilder
in class org.mybatis.spring.SqlSessionFactoryBean
public void setTransactionFactory(org.apache.ibatis.transaction.TransactionFactory transactionFactory)
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.
setTransactionFactory
in class org.mybatis.spring.SqlSessionFactoryBean
transactionFactory
- the MyBatis TransactionFactorySpringManagedTransactionFactory
public void setEnvironment(java.lang.String environment)
Environment
you have set in the MyBatis
config file. This is used only as a placeholder name. The default value is
SqlSessionFactoryBean.class.getSimpleName()
.
setEnvironment
in class org.mybatis.spring.SqlSessionFactoryBean
environment
- the environment nameprotected org.apache.ibatis.session.SqlSessionFactory buildSqlSessionFactory() throws java.io.IOException
SqlSessionFactory
instance.
The default implementation uses the standard MyBatis XMLConfigBuilder
API to build a
SqlSessionFactory
instance based on an Reader.
buildSqlSessionFactory
in class org.mybatis.spring.SqlSessionFactoryBean
java.io.IOException
- if loading the config file failedpublic org.apache.ibatis.session.SqlSessionFactory getObject() throws java.lang.Exception
getObject
in interface org.springframework.beans.factory.FactoryBean
getObject
in class org.mybatis.spring.SqlSessionFactoryBean
java.lang.Exception
public java.lang.Class getObjectType()
getObjectType
in interface org.springframework.beans.factory.FactoryBean
getObjectType
in class org.mybatis.spring.SqlSessionFactoryBean
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |