Package org.alfresco.ibatis
Class HierarchicalSqlSessionFactoryBean
- java.lang.Object
-
- org.mybatis.spring.SqlSessionFactoryBean
-
- org.alfresco.ibatis.HierarchicalSqlSessionFactoryBean
-
- All Implemented Interfaces:
EventListener
,org.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>
,org.springframework.beans.factory.InitializingBean
,org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
public class HierarchicalSqlSessionFactoryBean extends org.mybatis.spring.SqlSessionFactoryBean
Extends the MyBatis-Spring support by allowing a choice ofResourceLoader
. TheResourceLoader
will be used to load the SqlMapConfig file and use aHierarchicalXMLConfigBuilder
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-SpringSqlSessionFactoryBean
; 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:- Since:
- 4.0
- Author:
- Derek Hulley, janv
-
-
Constructor Summary
Constructors Constructor Description HierarchicalSqlSessionFactoryBean()
Default constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterPropertiesSet()
protected org.apache.ibatis.session.SqlSessionFactory
buildSqlSessionFactory()
Build aSqlSessionFactory
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 MyBatisSqlSessionFactory
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 DatabaseIdProvidervoid
setDataSource(DataSource dataSource)
Set the JDBCDataSource
that this instance should manage transactions for.void
setEnvironment(String environment)
NOTE: This class overrides anyEnvironment
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 theSqlSessionFactory
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 theSqlSessionFactoryBuilder
to use when creating theSqlSessionFactory
.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.
-
-
-
Method Detail
-
setResourceLoader
public void setResourceLoader(HierarchicalResourceLoader resourceLoader)
Set the resource loader to use. To use the #resource.dialect# placeholder, use theHierarchicalResourceLoader
.- Parameters:
resourceLoader
- the resource loader to use
-
setObjectFactory
public void setObjectFactory(org.apache.ibatis.reflection.factory.ObjectFactory objectFactory)
Sets the ObjectFactory.- Overrides:
setObjectFactory
in classorg.mybatis.spring.SqlSessionFactoryBean
- Parameters:
objectFactory
- ObjectFactory- Since:
- 1.1.2
-
setObjectWrapperFactory
public void setObjectWrapperFactory(org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory objectWrapperFactory)
Sets the ObjectWrapperFactory.- Overrides:
setObjectWrapperFactory
in classorg.mybatis.spring.SqlSessionFactoryBean
- Parameters:
objectWrapperFactory
- ObjectWrapperFactory- Since:
- 1.1.2
-
getDatabaseIdProvider
public org.apache.ibatis.mapping.DatabaseIdProvider getDatabaseIdProvider()
Sets the DatabaseIdProvider.- Overrides:
getDatabaseIdProvider
in classorg.mybatis.spring.SqlSessionFactoryBean
- Returns:
- DatabaseIdProvider
- Since:
- 1.1.0
-
setDatabaseIdProvider
public void setDatabaseIdProvider(org.apache.ibatis.mapping.DatabaseIdProvider databaseIdProvider)
Gets the DatabaseIdProvider- Overrides:
setDatabaseIdProvider
in classorg.mybatis.spring.SqlSessionFactoryBean
- Parameters:
databaseIdProvider
- DatabaseIdProvider- Since:
- 1.1.0
-
setPlugins
public void setPlugins(org.apache.ibatis.plugin.Interceptor[] plugins)
Mybatis plugin list.- Overrides:
setPlugins
in classorg.mybatis.spring.SqlSessionFactoryBean
- Parameters:
plugins
- list of plugins- Since:
- 1.0.1
-
setTypeAliasesPackage
public void setTypeAliasesPackage(String typeAliasesPackage)
Packages to search for type aliases.- Overrides:
setTypeAliasesPackage
in classorg.mybatis.spring.SqlSessionFactoryBean
- Parameters:
typeAliasesPackage
- package to scan for domain objects- Since:
- 1.0.1
-
setTypeAliasesSuperType
public void setTypeAliasesSuperType(Class<?> typeAliasesSuperType)
Super class which domain objects have to extend to have a type alias created. No effect if there is no package to scan configured.- Overrides:
setTypeAliasesSuperType
in classorg.mybatis.spring.SqlSessionFactoryBean
- Parameters:
typeAliasesSuperType
- super class for domain objects- Since:
- 1.1.2
-
setTypeHandlersPackage
public void setTypeHandlersPackage(String typeHandlersPackage)
Packages to search for type handlers.- Overrides:
setTypeHandlersPackage
in classorg.mybatis.spring.SqlSessionFactoryBean
- Parameters:
typeHandlersPackage
- package to scan for type handlers- Since:
- 1.0.1
-
setTypeHandlers
public void setTypeHandlers(org.apache.ibatis.type.TypeHandler<?>[] typeHandlers)
Set type handlers. They must be annotated withMappedTypes
and optionally withMappedJdbcTypes
- Overrides:
setTypeHandlers
in classorg.mybatis.spring.SqlSessionFactoryBean
- Parameters:
typeHandlers
- Type handler list- Since:
- 1.0.1
-
setTypeAliases
public void setTypeAliases(Class<?>[] typeAliases)
List of type aliases to register. They can be annotated withAlias
- Overrides:
setTypeAliases
in classorg.mybatis.spring.SqlSessionFactoryBean
- Parameters:
typeAliases
- Type aliases list- Since:
- 1.0.1
-
setFailFast
public 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. Defaults to false.- Overrides:
setFailFast
in classorg.mybatis.spring.SqlSessionFactoryBean
- Parameters:
failFast
- enable failFast- Since:
- 1.0.1
-
setConfigLocation
public void setConfigLocation(org.springframework.core.io.Resource configLocation)
Set the location of the MyBatisSqlSessionFactory
config file. A typical value is "WEB-INF/mybatis-configuration.xml".- Overrides:
setConfigLocation
in classorg.mybatis.spring.SqlSessionFactoryBean
-
setMapperLocations
public void setMapperLocations(org.springframework.core.io.Resource[] mapperLocations)
Set locations of MyBatis mapper files that are going to be merged into theSqlSessionFactory
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".- Overrides:
setMapperLocations
in classorg.mybatis.spring.SqlSessionFactoryBean
-
setConfigurationProperties
public 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. This will be used to resolve placeholders in the config file.- Overrides:
setConfigurationProperties
in classorg.mybatis.spring.SqlSessionFactoryBean
-
setDataSource
public void setDataSource(DataSource dataSource)
Set the JDBCDataSource
that this instance should manage transactions for. TheDataSource
should match the one used by theSqlSessionFactory
: for example, you could specify the same JNDI DataSource for both. A transactional JDBCConnection
for thisDataSource
will be provided to application code accessing thisDataSource
directly viaDataSourceUtils
orDataSourceTransactionManager
. TheDataSource
specified here should be the targetDataSource
to manage transactions for, not aTransactionAwareDataSourceProxy
. Only data access code may work withTransactionAwareDataSourceProxy
, while the transaction manager needs to work on the underlying targetDataSource
. If there's nevertheless aTransactionAwareDataSourceProxy
passed in, it will be unwrapped to extract its targetDataSource
.- Overrides:
setDataSource
in classorg.mybatis.spring.SqlSessionFactoryBean
-
setSqlSessionFactoryBuilder
public void setSqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder sqlSessionFactoryBuilder)
Sets theSqlSessionFactoryBuilder
to use when creating theSqlSessionFactory
. This is mainly meant for testing so that mock SqlSessionFactory classes can be injected. By default,SqlSessionFactoryBuilder
createsDefaultSqlSessionFactory
instances.- Overrides:
setSqlSessionFactoryBuilder
in classorg.mybatis.spring.SqlSessionFactoryBean
-
setTransactionFactory
public void setTransactionFactory(org.apache.ibatis.transaction.TransactionFactory transactionFactory)
Set the MyBatis TransactionFactory to use. Default isSpringManagedTransactionFactory
The defaultSpringManagedTransactionFactory
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 defaultTransactionFactory
. If not used, any attempt at getting an SqlSession through Spring's MyBatis framework will throw an exception if a transaction is active.- Overrides:
setTransactionFactory
in classorg.mybatis.spring.SqlSessionFactoryBean
- Parameters:
transactionFactory
- the MyBatis TransactionFactory- See Also:
SpringManagedTransactionFactory
-
setEnvironment
public void setEnvironment(String environment)
NOTE: This class overrides anyEnvironment
you have set in the MyBatis config file. This is used only as a placeholder name. The default value isSqlSessionFactoryBean.class.getSimpleName()
.- Overrides:
setEnvironment
in classorg.mybatis.spring.SqlSessionFactoryBean
- Parameters:
environment
- the environment name
-
afterPropertiesSet
public void afterPropertiesSet() throws Exception
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Overrides:
afterPropertiesSet
in classorg.mybatis.spring.SqlSessionFactoryBean
- Throws:
Exception
-
buildSqlSessionFactory
protected org.apache.ibatis.session.SqlSessionFactory buildSqlSessionFactory() throws IOException
Build aSqlSessionFactory
instance. The default implementation uses the standard MyBatisXMLConfigBuilder
API to build aSqlSessionFactory
instance based on an Reader.- Overrides:
buildSqlSessionFactory
in classorg.mybatis.spring.SqlSessionFactoryBean
- Returns:
- SqlSessionFactory
- Throws:
IOException
- if loading the config file failed
-
getObject
public org.apache.ibatis.session.SqlSessionFactory getObject() throws Exception
- Specified by:
getObject
in interfaceorg.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>
- Overrides:
getObject
in classorg.mybatis.spring.SqlSessionFactoryBean
- Throws:
Exception
-
getObjectType
public Class<? extends org.apache.ibatis.session.SqlSessionFactory> getObjectType()
- Specified by:
getObjectType
in interfaceorg.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>
- Overrides:
getObjectType
in classorg.mybatis.spring.SqlSessionFactoryBean
-
isSingleton
public boolean isSingleton()
- Specified by:
isSingleton
in interfaceorg.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>
- Overrides:
isSingleton
in classorg.mybatis.spring.SqlSessionFactoryBean
-
onApplicationEvent
public void onApplicationEvent(org.springframework.context.ApplicationEvent event)
- Specified by:
onApplicationEvent
in interfaceorg.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
- Overrides:
onApplicationEvent
in classorg.mybatis.spring.SqlSessionFactoryBean
-
-