Package org.alfresco.ibatis
Class HierarchicalSqlSessionFactoryBean
- java.lang.Object
-
- org.mybatis.spring.SqlSessionFactoryBean
-
- org.alfresco.ibatis.HierarchicalSqlSessionFactoryBean
-
- All Implemented Interfaces:
java.util.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.SqlSessionFactoryBeanExtends the MyBatis-Spring support by allowing a choice ofResourceLoader. TheResourceLoaderwill be used to load the SqlMapConfig file and use aHierarchicalXMLConfigBuilderto 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 voidafterPropertiesSet()protected org.apache.ibatis.session.SqlSessionFactorybuildSqlSessionFactory()Build aSqlSessionFactoryinstance.org.apache.ibatis.mapping.DatabaseIdProvidergetDatabaseIdProvider()Sets the DatabaseIdProvider.DBMetricsReportergetDbMetricsReporter()org.apache.ibatis.session.SqlSessionFactorygetObject()java.lang.Class<? extends org.apache.ibatis.session.SqlSessionFactory>getObjectType()booleanisSingleton()voidonApplicationEvent(org.springframework.context.ApplicationEvent event)voidsetConfigLocation(org.springframework.core.io.Resource configLocation)Set the location of the MyBatisSqlSessionFactoryconfig file.voidsetConfigurationProperties(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.voidsetDatabaseIdProvider(org.apache.ibatis.mapping.DatabaseIdProvider databaseIdProvider)Gets the DatabaseIdProvidervoidsetDataSource(javax.sql.DataSource dataSource)Set the JDBCDataSourcethat this instance should manage transactions for.voidsetDbMetricsReporter(DBMetricsReporter dbMetricsReporter)voidsetEnvironment(java.lang.String environment)NOTE: This class overrides anyEnvironmentyou have set in the MyBatis config file.voidsetFailFast(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.voidsetMapperLocations(org.springframework.core.io.Resource[] mapperLocations)Set locations of MyBatis mapper files that are going to be merged into theSqlSessionFactoryconfiguration at runtime.voidsetObjectFactory(org.apache.ibatis.reflection.factory.ObjectFactory objectFactory)Sets the ObjectFactory.voidsetObjectWrapperFactory(org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory objectWrapperFactory)Sets the ObjectWrapperFactory.voidsetPlugins(org.apache.ibatis.plugin.Interceptor[] plugins)Mybatis plugin list.voidsetResourceLoader(HierarchicalResourceLoader resourceLoader)Set the resource loader to use.voidsetSqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder sqlSessionFactoryBuilder)Sets theSqlSessionFactoryBuilderto use when creating theSqlSessionFactory.voidsetTransactionFactory(org.apache.ibatis.transaction.TransactionFactory transactionFactory)Set the MyBatis TransactionFactory to use.voidsetTypeAliases(java.lang.Class<?>[] typeAliases)List of type aliases to register.voidsetTypeAliasesPackage(java.lang.String typeAliasesPackage)Packages to search for type aliases.voidsetTypeAliasesSuperType(java.lang.Class<?> typeAliasesSuperType)Super class which domain objects have to extend to have a type alias created.voidsetTypeHandlers(org.apache.ibatis.type.TypeHandler<?>[] typeHandlers)Set type handlers.voidsetTypeHandlersPackage(java.lang.String typeHandlersPackage)Packages to search for type handlers.
-
-
-
Method Detail
-
getDbMetricsReporter
public DBMetricsReporter getDbMetricsReporter()
-
setDbMetricsReporter
public void setDbMetricsReporter(DBMetricsReporter dbMetricsReporter)
-
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:
setObjectFactoryin 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:
setObjectWrapperFactoryin classorg.mybatis.spring.SqlSessionFactoryBean- Parameters:
objectWrapperFactory- ObjectWrapperFactory- Since:
- 1.1.2
-
getDatabaseIdProvider
public org.apache.ibatis.mapping.DatabaseIdProvider getDatabaseIdProvider()
Sets the DatabaseIdProvider.- Overrides:
getDatabaseIdProviderin classorg.mybatis.spring.SqlSessionFactoryBean- Returns:
- DatabaseIdProvider
- Since:
- 1.1.0
-
setDatabaseIdProvider
public void setDatabaseIdProvider(org.apache.ibatis.mapping.DatabaseIdProvider databaseIdProvider)
Gets the DatabaseIdProvider- Overrides:
setDatabaseIdProviderin 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:
setPluginsin classorg.mybatis.spring.SqlSessionFactoryBean- Parameters:
plugins- list of plugins- Since:
- 1.0.1
-
setTypeAliasesPackage
public void setTypeAliasesPackage(java.lang.String typeAliasesPackage)
Packages to search for type aliases.- Overrides:
setTypeAliasesPackagein classorg.mybatis.spring.SqlSessionFactoryBean- Parameters:
typeAliasesPackage- package to scan for domain objects- Since:
- 1.0.1
-
setTypeAliasesSuperType
public void setTypeAliasesSuperType(java.lang.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:
setTypeAliasesSuperTypein classorg.mybatis.spring.SqlSessionFactoryBean- Parameters:
typeAliasesSuperType- super class for domain objects- Since:
- 1.1.2
-
setTypeHandlersPackage
public void setTypeHandlersPackage(java.lang.String typeHandlersPackage)
Packages to search for type handlers.- Overrides:
setTypeHandlersPackagein 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 withMappedTypesand optionally withMappedJdbcTypes- Overrides:
setTypeHandlersin classorg.mybatis.spring.SqlSessionFactoryBean- Parameters:
typeHandlers- Type handler list- Since:
- 1.0.1
-
setTypeAliases
public void setTypeAliases(java.lang.Class<?>[] typeAliases)
List of type aliases to register. They can be annotated withAlias- Overrides:
setTypeAliasesin 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:
setFailFastin 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 MyBatisSqlSessionFactoryconfig file. A typical value is "WEB-INF/mybatis-configuration.xml".- Overrides:
setConfigLocationin 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 theSqlSessionFactoryconfiguration 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:
setMapperLocationsin classorg.mybatis.spring.SqlSessionFactoryBean
-
setConfigurationProperties
public 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. This will be used to resolve placeholders in the config file.- Overrides:
setConfigurationPropertiesin classorg.mybatis.spring.SqlSessionFactoryBean
-
setDataSource
public void setDataSource(javax.sql.DataSource dataSource)
Set the JDBCDataSourcethat this instance should manage transactions for. TheDataSourceshould match the one used by theSqlSessionFactory: for example, you could specify the same JNDI DataSource for both. A transactional JDBCConnectionfor thisDataSourcewill be provided to application code accessing thisDataSourcedirectly viaDataSourceUtilsorDataSourceTransactionManager. TheDataSourcespecified here should be the targetDataSourceto 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 aTransactionAwareDataSourceProxypassed in, it will be unwrapped to extract its targetDataSource.- Overrides:
setDataSourcein classorg.mybatis.spring.SqlSessionFactoryBean
-
setSqlSessionFactoryBuilder
public void setSqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder sqlSessionFactoryBuilder)
Sets theSqlSessionFactoryBuilderto use when creating theSqlSessionFactory. This is mainly meant for testing so that mock SqlSessionFactory classes can be injected. By default,SqlSessionFactoryBuildercreatesDefaultSqlSessionFactoryinstances.- Overrides:
setSqlSessionFactoryBuilderin classorg.mybatis.spring.SqlSessionFactoryBean
-
setTransactionFactory
public void setTransactionFactory(org.apache.ibatis.transaction.TransactionFactory transactionFactory)
Set the MyBatis TransactionFactory to use. Default isSpringManagedTransactionFactoryThe defaultSpringManagedTransactionFactoryshould 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:
setTransactionFactoryin classorg.mybatis.spring.SqlSessionFactoryBean- Parameters:
transactionFactory- the MyBatis TransactionFactory- See Also:
SpringManagedTransactionFactory
-
setEnvironment
public void setEnvironment(java.lang.String environment)
NOTE: This class overrides anyEnvironmentyou have set in the MyBatis config file. This is used only as a placeholder name. The default value isSqlSessionFactoryBean.class.getSimpleName().- Overrides:
setEnvironmentin classorg.mybatis.spring.SqlSessionFactoryBean- Parameters:
environment- the environment name
-
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Overrides:
afterPropertiesSetin classorg.mybatis.spring.SqlSessionFactoryBean- Throws:
java.lang.Exception
-
buildSqlSessionFactory
protected org.apache.ibatis.session.SqlSessionFactory buildSqlSessionFactory() throws java.io.IOExceptionBuild aSqlSessionFactoryinstance. The default implementation uses the standard MyBatisXMLConfigBuilderAPI to build aSqlSessionFactoryinstance based on an Reader.- Overrides:
buildSqlSessionFactoryin classorg.mybatis.spring.SqlSessionFactoryBean- Returns:
- SqlSessionFactory
- Throws:
java.io.IOException- if loading the config file failed
-
getObject
public org.apache.ibatis.session.SqlSessionFactory getObject() throws java.lang.Exception- Specified by:
getObjectin interfaceorg.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>- Overrides:
getObjectin classorg.mybatis.spring.SqlSessionFactoryBean- Throws:
java.lang.Exception
-
getObjectType
public java.lang.Class<? extends org.apache.ibatis.session.SqlSessionFactory> getObjectType()
- Specified by:
getObjectTypein interfaceorg.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>- Overrides:
getObjectTypein classorg.mybatis.spring.SqlSessionFactoryBean
-
isSingleton
public boolean isSingleton()
- Specified by:
isSingletonin interfaceorg.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>- Overrides:
isSingletonin classorg.mybatis.spring.SqlSessionFactoryBean
-
onApplicationEvent
public void onApplicationEvent(org.springframework.context.ApplicationEvent event)
- Specified by:
onApplicationEventin interfaceorg.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>- Overrides:
onApplicationEventin classorg.mybatis.spring.SqlSessionFactoryBean
-
-