org.mybatis.spring
Class SqlSessionFactoryBean

java.lang.Object  extended by org.mybatis.spring.SqlSessionFactoryBean
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 SqlSessionFactoryBean
extends Object
implements org.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>

FactoryBean that creates an MyBatis SqlSessionFactory. This is the usual way to set up a shared MyBatis SqlSessionFactory in a Spring application context; the SqlSessionFactory can then be passed to MyBatis-based DAOs via dependency injection. Either DataSourceTransactionManager or JtaTransactionManager can be used for transaction demarcation in combination with a SqlSessionFactory. JTA should be used for transactions which span multiple databases or when container managed transactions (CMT) are being used.

Version:
$Id: SqlSessionFactoryBean.java 4955 2012-03-18 09:16:58Z eduardo.macarron $
See Also:
setConfigLocation(org.springframework.core.io.Resource), setDataSource(javax.sql.DataSource)


Constructor Summary
SqlSessionFactoryBean()
           
 
Method Summary
 voidafterPropertiesSet()
          
protected  org.apache.ibatis.session.SqlSessionFactorybuildSqlSessionFactory()
          Build a SqlSessionFactory instance.
 org.apache.ibatis.mapping.DatabaseIdProvidergetDatabaseIdProvider()
          Sets the DatabaseIdProvider.
 org.apache.ibatis.session.SqlSessionFactorygetObject()
          
 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 MyBatis SqlSessionFactory config file.
 voidsetConfigurationProperties(Properties sqlSessionFactoryProperties)
          Set optional properties to be passed into the SqlSession configuration, as alternative to a &lt;properties&gt; tag in the configuration xml file.
 voidsetDatabaseIdProvider(org.apache.ibatis.mapping.DatabaseIdProvider databaseIdProvider)
          Gets the DatabaseIdProvider
 voidsetDataSource(DataSource dataSource)
          Set the JDBC DataSource that this instance should manage transactions for.
 voidsetEnvironment(String environment)
          NOTE: This class overrides any Environment you 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 the SqlSessionFactory configuration at runtime.
 voidsetPlugins(org.apache.ibatis.plugin.Interceptor[] plugins)
          Mybatis plugin list.
 voidsetSqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder sqlSessionFactoryBuilder)
          Sets the SqlSessionFactoryBuilder to use when creating the SqlSessionFactory.
 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.
 voidsetTypeHandlers(org.apache.ibatis.type.TypeHandler<?>[] typeHandlers)
          Set type handlers.
 voidsetTypeHandlersPackage(String typeHandlersPackage)
          Packages to search for type handlers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SqlSessionFactoryBean

public SqlSessionFactoryBean()
Method Detail

getDatabaseIdProvider

public org.apache.ibatis.mapping.DatabaseIdProvider getDatabaseIdProvider()
Sets the DatabaseIdProvider.

Returns:
Since:
1.1.0

setDatabaseIdProvider

public void setDatabaseIdProvider(org.apache.ibatis.mapping.DatabaseIdProvider databaseIdProvider)
Gets the DatabaseIdProvider

Parameters:
databaseIdProvider -
Since:
1.1.0

setPlugins

public void setPlugins(org.apache.ibatis.plugin.Interceptor[] plugins)
Mybatis plugin list.

Parameters:
plugins - list of plugins
Since:
1.0.1

setTypeAliasesPackage

public void setTypeAliasesPackage(String typeAliasesPackage)
Packages to search for type aliases.

Parameters:
typeAliasesPackage - package to scan for domain objects
Since:
1.0.1

setTypeHandlersPackage

public void setTypeHandlersPackage(String typeHandlersPackage)
Packages to search for type handlers.

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 with MappedTypes and optionally with MappedJdbcTypes

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 with Alias

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.

Parameters:
failFast - enable failFast
Since:
1.0.1

setConfigLocation

public void setConfigLocation(org.springframework.core.io.Resource configLocation)
Set the location of the MyBatis SqlSessionFactory config file. A typical value is "WEB-INF/mybatis-configuration.xml".


setMapperLocations

public 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. 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 &lt;properties&gt; 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 JDBC 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.


setSqlSessionFactoryBuilder

public void setSqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder sqlSessionFactoryBuilder)
Sets the 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.


setTransactionFactory

public void setTransactionFactory(org.apache.ibatis.transaction.TransactionFactory transactionFactory)
Set the MyBatis TransactionFactory to use. Default is 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.

Parameters:
transactionFactory - the MyBatis TransactionFactory
See Also:
SpringManagedTransactionFactory

setEnvironment

public void setEnvironment(String environment)
NOTE: This class overrides any Environment you have set in the MyBatis config file. This is used only as a placeholder name. The default value is SqlSessionFactoryBean.class.getSimpleName().

Parameters:
environment - the environment name

afterPropertiesSet

public void afterPropertiesSet()                        throws Exception

Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
Exception

buildSqlSessionFactory

protected org.apache.ibatis.session.SqlSessionFactory buildSqlSessionFactory()                                                                      throws IOException
Build a SqlSessionFactory instance. The default implementation uses the standard MyBatis XMLConfigBuilder API to build a SqlSessionFactory instance based on an Reader.

Returns:
SqlSessionFactory
Throws:
IOException - if loading the config file failed

getObject

public org.apache.ibatis.session.SqlSessionFactory getObject()                                                      throws Exception

Specified by:
getObject in interface org.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>
Throws:
Exception

getObjectType

public Class<? extends org.apache.ibatis.session.SqlSessionFactory> getObjectType()

Specified by:
getObjectType in interface org.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>

isSingleton

public boolean isSingleton()

Specified by:
isSingleton in interface org.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>

onApplicationEvent

public void onApplicationEvent(org.springframework.context.ApplicationEvent event)

Specified by:
onApplicationEvent in interface org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>


Copyright © 2010-2012
MyBatis.org. All Rights Reserved.


NOTHING
NOTHING
Add the Maven Dependecy to your project: maven dependecy for com.amazonaws : aws-java-sdk : 1.3.14