public class HierarchicalSqlSessionFactoryBean
extends org.mybatis.spring.SqlSessionFactoryBean
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 and Description |
|---|
HierarchicalSqlSessionFactoryBean()
Default constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
protected org.apache.ibatis.session.SqlSessionFactory |
buildSqlSessionFactory()
Build a
SqlSessionFactory instance. |
org.apache.ibatis.mapping.DatabaseIdProvider |
getDatabaseIdProvider()
Sets the DatabaseIdProvider.
|
org.apache.ibatis.session.SqlSessionFactory |
getObject() |
Class<? extends org.apache.ibatis.session.SqlSessionFactory> |
getObjectType() |
boolean |
isSingleton() |
void |
onApplicationEvent(org.springframework.context.ApplicationEvent event) |
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 |
setDatabaseIdProvider(org.apache.ibatis.mapping.DatabaseIdProvider databaseIdProvider)
Gets the DatabaseIdProvider
|
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 |
setFailFast(boolean failFast)
If true, a final check is done on Configuration to assure that all mapped
statements are fully loaded and there is no one still pending to resolve
includes.
|
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 |
setObjectFactory(org.apache.ibatis.reflection.factory.ObjectFactory objectFactory)
Sets the ObjectFactory.
|
void |
setObjectWrapperFactory(org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory objectWrapperFactory)
Sets the ObjectWrapperFactory.
|
void |
setPlugins(org.apache.ibatis.plugin.Interceptor[] plugins)
Mybatis plugin list.
|
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.
|
void |
setTypeAliases(Class<?>[] typeAliases)
List of type aliases to register.
|
void |
setTypeAliasesPackage(String typeAliasesPackage)
Packages to search for type aliases.
|
void |
setTypeAliasesSuperType(Class<?> typeAliasesSuperType)
Super class which domain objects have to extend to have a type alias created.
|
void |
setTypeHandlers(org.apache.ibatis.type.TypeHandler<?>[] typeHandlers)
Set type handlers.
|
void |
setTypeHandlersPackage(String typeHandlersPackage)
Packages to search for type handlers.
|
public HierarchicalSqlSessionFactoryBean()
public void setResourceLoader(HierarchicalResourceLoader resourceLoader)
HierarchicalResourceLoader.resourceLoader - the resource loader to usepublic void setObjectFactory(org.apache.ibatis.reflection.factory.ObjectFactory objectFactory)
setObjectFactory in class org.mybatis.spring.SqlSessionFactoryBeanobjectFactory - ObjectFactorypublic void setObjectWrapperFactory(org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory objectWrapperFactory)
setObjectWrapperFactory in class org.mybatis.spring.SqlSessionFactoryBeanobjectWrapperFactory - ObjectWrapperFactorypublic org.apache.ibatis.mapping.DatabaseIdProvider getDatabaseIdProvider()
getDatabaseIdProvider in class org.mybatis.spring.SqlSessionFactoryBeanpublic void setDatabaseIdProvider(org.apache.ibatis.mapping.DatabaseIdProvider databaseIdProvider)
setDatabaseIdProvider in class org.mybatis.spring.SqlSessionFactoryBeandatabaseIdProvider - DatabaseIdProviderpublic void setPlugins(org.apache.ibatis.plugin.Interceptor[] plugins)
setPlugins in class org.mybatis.spring.SqlSessionFactoryBeanplugins - list of pluginspublic void setTypeAliasesPackage(String typeAliasesPackage)
setTypeAliasesPackage in class org.mybatis.spring.SqlSessionFactoryBeantypeAliasesPackage - package to scan for domain objectspublic void setTypeAliasesSuperType(Class<?> typeAliasesSuperType)
setTypeAliasesSuperType in class org.mybatis.spring.SqlSessionFactoryBeantypeAliasesSuperType - super class for domain objectspublic void setTypeHandlersPackage(String typeHandlersPackage)
setTypeHandlersPackage in class org.mybatis.spring.SqlSessionFactoryBeantypeHandlersPackage - package to scan for type handlerspublic void setTypeHandlers(org.apache.ibatis.type.TypeHandler<?>[] typeHandlers)
MappedTypes and optionally with MappedJdbcTypessetTypeHandlers in class org.mybatis.spring.SqlSessionFactoryBeantypeHandlers - Type handler listpublic void setTypeAliases(Class<?>[] typeAliases)
AliassetTypeAliases in class org.mybatis.spring.SqlSessionFactoryBeantypeAliases - Type aliases listpublic void setFailFast(boolean failFast)
setFailFast in class org.mybatis.spring.SqlSessionFactoryBeanfailFast - enable failFastpublic 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.SqlSessionFactoryBeanpublic 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.SqlSessionFactoryBeanpublic void setConfigurationProperties(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.SqlSessionFactoryBeanpublic void setDataSource(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.SqlSessionFactoryBeanpublic 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.SqlSessionFactoryBeanpublic 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.SqlSessionFactoryBeantransactionFactory - the MyBatis TransactionFactorySpringManagedTransactionFactorypublic void setEnvironment(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.SqlSessionFactoryBeanenvironment - the environment namepublic void afterPropertiesSet()
throws Exception
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanafterPropertiesSet in class org.mybatis.spring.SqlSessionFactoryBeanExceptionprotected org.apache.ibatis.session.SqlSessionFactory buildSqlSessionFactory()
throws 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.SqlSessionFactoryBeanIOException - if loading the config file failedpublic org.apache.ibatis.session.SqlSessionFactory getObject()
throws Exception
getObject in interface org.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>getObject in class org.mybatis.spring.SqlSessionFactoryBeanExceptionpublic Class<? extends org.apache.ibatis.session.SqlSessionFactory> getObjectType()
getObjectType in interface org.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>getObjectType in class org.mybatis.spring.SqlSessionFactoryBeanpublic boolean isSingleton()
isSingleton in interface org.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>isSingleton in class org.mybatis.spring.SqlSessionFactoryBeanpublic void onApplicationEvent(org.springframework.context.ApplicationEvent event)
onApplicationEvent in interface org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>onApplicationEvent in class org.mybatis.spring.SqlSessionFactoryBeanCopyright © 2005–2018 Alfresco Software. All rights reserved.