类 SqlSessionFactoryBean
- java.lang.Object
-
- xyz.xiezc.ioc.starter.orm.bean.SqlSessionFactoryBean
-
- 所有已实现的接口:
FactoryBean<org.apache.ibatis.session.SqlSessionFactory>
public class SqlSessionFactoryBean extends Object implements FactoryBean<org.apache.ibatis.session.SqlSessionFactory>
FactoryBeanthat creates an MyBatisSqlSessionFactory. This is the usual way to set up a shared MyBatisSqlSessionFactoryin a Spring application context; the SqlSessionFactory can then be passed to MyBatis-based DAOs via dependency injection.Either
DataSourceTransactionManagerorJtaTransactionManagercan be used for transaction demarcation in combination with aSqlSessionFactory. JTA should be used for transactions which span multiple databases or when container managed transactions (CMT) are being used.- 版本:
- $Id$
- 作者:
- Putthibong Boonbong, Hunter Presnall, Eduardo Macarron, Eddú Meléndez, Kazuki Shimizu
- 另请参阅:
setConfigLocation(cn.hutool.core.io.resource.Resource),setDataSource(javax.sql.DataSource)
-
-
构造器概要
构造器 构造器 说明 SqlSessionFactoryBean()
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidafterPropertiesSet()protected org.apache.ibatis.session.SqlSessionFactorybuildSqlSessionFactory()Build aSqlSessionFactoryinstance.org.apache.ibatis.cache.CachegetCache()org.apache.ibatis.mapping.DatabaseIdProvidergetDatabaseIdProvider()Gets the DatabaseIdProviderorg.apache.ibatis.session.SqlSessionFactorygetObject()ClassgetObjectType()Class<? extends org.apache.ibatis.io.VFS>getVfs()booleanisSingleton()voidsetCache(org.apache.ibatis.cache.Cache cache)voidsetConfigLocation(cn.hutool.core.io.resource.Resource configLocation)Set the location of the MyBatisSqlSessionFactoryconfig file.voidsetConfiguration(org.apache.ibatis.session.Configuration configuration)Set a customized MyBatis configuration.voidsetConfigurationProperties(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)Sets the DatabaseIdProvider.voidsetDataSource(DataSource dataSource)Set the JDBCDataSourcethat this instance should manage transactions for.voidsetDocumentMapperDefines(List<DocumentMapperDefine> documentMapperDefines)Set locations of MyBatis mapper files that are going to be merged into theSqlSessionFactoryconfiguration at runtime.voidsetEnvironment(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.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.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(Class<?>[] typeAliases)List of type aliases to register.voidsetTypeAliasesPackage(String typeAliasesPackage)Packages to search for type aliases.voidsetTypeAliasesSuperType(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(String typeHandlersPackage)Packages to search for type handlers.voidsetVfs(Class<? extends org.apache.ibatis.io.VFS> vfs)
-
-
-
方法详细资料
-
setObjectFactory
public void setObjectFactory(org.apache.ibatis.reflection.factory.ObjectFactory objectFactory)
Sets the ObjectFactory.- 参数:
objectFactory-- 从以下版本开始:
- 1.1.2
-
setObjectWrapperFactory
public void setObjectWrapperFactory(org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory objectWrapperFactory)
Sets the ObjectWrapperFactory.- 参数:
objectWrapperFactory-- 从以下版本开始:
- 1.1.2
-
getDatabaseIdProvider
public org.apache.ibatis.mapping.DatabaseIdProvider getDatabaseIdProvider()
Gets the DatabaseIdProvider- 返回:
- 从以下版本开始:
- 1.1.0
-
setDatabaseIdProvider
public void setDatabaseIdProvider(org.apache.ibatis.mapping.DatabaseIdProvider databaseIdProvider)
Sets the DatabaseIdProvider. As of version 1.2.2 this variable is not initialized by default.- 参数:
databaseIdProvider-- 从以下版本开始:
- 1.1.0
-
getVfs
public Class<? extends org.apache.ibatis.io.VFS> getVfs()
-
setVfs
public void setVfs(Class<? extends org.apache.ibatis.io.VFS> vfs)
-
getCache
public org.apache.ibatis.cache.Cache getCache()
-
setCache
public void setCache(org.apache.ibatis.cache.Cache cache)
-
setPlugins
public void setPlugins(org.apache.ibatis.plugin.Interceptor[] plugins)
Mybatis plugin list.- 参数:
plugins- list of plugins- 从以下版本开始:
- 1.0.1
-
setTypeAliasesPackage
public void setTypeAliasesPackage(String typeAliasesPackage)
Packages to search for type aliases.- 参数:
typeAliasesPackage- package to scan for domain objects- 从以下版本开始:
- 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.- 参数:
typeAliasesSuperType- super class for domain objects- 从以下版本开始:
- 1.1.2
-
setTypeHandlersPackage
public void setTypeHandlersPackage(String typeHandlersPackage)
Packages to search for type handlers.- 参数:
typeHandlersPackage- package to scan for type handlers- 从以下版本开始:
- 1.0.1
-
setTypeHandlers
public void setTypeHandlers(org.apache.ibatis.type.TypeHandler<?>[] typeHandlers)
Set type handlers. They must be annotated withMappedTypesand optionally withMappedJdbcTypes- 参数:
typeHandlers- Type handler list- 从以下版本开始:
- 1.0.1
-
setTypeAliases
public void setTypeAliases(Class<?>[] typeAliases)
List of type aliases to register. They can be annotated withAlias- 参数:
typeAliases- Type aliases list- 从以下版本开始:
- 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.- 参数:
failFast- enable failFast- 从以下版本开始:
- 1.0.1
-
setConfigLocation
public void setConfigLocation(cn.hutool.core.io.resource.Resource configLocation)
Set the location of the MyBatisSqlSessionFactoryconfig file. A typical value is "WEB-INF/mybatis-configuration.xml".
-
setConfiguration
public void setConfiguration(org.apache.ibatis.session.Configuration configuration)
Set a customized MyBatis configuration.- 参数:
configuration- MyBatis configuration- 从以下版本开始:
- 1.3.0
-
setDocumentMapperDefines
public void setDocumentMapperDefines(List<DocumentMapperDefine> documentMapperDefines)
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".
-
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.
-
setDataSource
public void setDataSource(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 JDBC
Connectionfor thisDataSourcewill be provided to application code accessing thisDataSourcedirectly viaDataSourceUtilsorDataSourceTransactionManager.The
DataSourcespecified 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.
-
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.
-
setTransactionFactory
public void setTransactionFactory(org.apache.ibatis.transaction.TransactionFactory transactionFactory)
Set the MyBatis TransactionFactory to use. Default isSpringManagedTransactionFactoryThe default
SpringManagedTransactionFactoryshould 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.- 参数:
transactionFactory- the MyBatis TransactionFactory- 另请参阅:
YaoManagedTransactionFactory
-
setEnvironment
public void setEnvironment(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().- 参数:
environment- the environment name
-
afterPropertiesSet
public void afterPropertiesSet()
-
buildSqlSessionFactory
protected org.apache.ibatis.session.SqlSessionFactory buildSqlSessionFactory()
Build aSqlSessionFactoryinstance.The default implementation uses the standard MyBatis
XMLConfigBuilderAPI to build aSqlSessionFactoryinstance based on an Reader. Since 1.3.0, it can be specified aConfigurationinstance directly(without config file).- 返回:
- SqlSessionFactory
- 抛出:
IOException- if loading the config file failed
-
getObject
public org.apache.ibatis.session.SqlSessionFactory getObject()
- 指定者:
getObject在接口中FactoryBean<org.apache.ibatis.session.SqlSessionFactory>
-
getObjectType
public Class getObjectType()
- 指定者:
getObjectType在接口中FactoryBean<org.apache.ibatis.session.SqlSessionFactory>
-
isSingleton
public boolean isSingleton()
- 指定者:
isSingleton在接口中FactoryBean<org.apache.ibatis.session.SqlSessionFactory>
-
-