Package org.mybatis.guice
Class MyBatisModule
- java.lang.Object
-
- com.google.inject.AbstractModule
-
- org.mybatis.guice.MyBatisModule
-
- All Implemented Interfaces:
com.google.inject.Module
- Direct Known Subclasses:
MyBatisJtaModule
public abstract class MyBatisModule extends com.google.inject.AbstractModule
Easy to use helper Module that alleviates users to write the boilerplate google-guice bindings to create the SqlSessionFactory.
-
-
Field Summary
Fields Modifier and Type Field Description protected static com.google.inject.matcher.AbstractMatcher<Method>
DECLARED_BY_OBJECT
protected static com.google.inject.matcher.AbstractMatcher<Method>
SYNTHETIC
-
Constructor Summary
Constructors Constructor Description MyBatisModule()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected AliasBinder
addAlias(String alias)
Add a user defined binding.protected void
addInterceptorClass(Class<? extends org.apache.ibatis.plugin.Interceptor> interceptorClass)
Adds the user defined myBatis interceptor plugins type, letting google-guice creating it.protected void
addInterceptorsClasses(String packageName)
Adds the user defined MyBatis interceptors plugins types in the given package, letting google-guice creating them.protected void
addInterceptorsClasses(Collection<Class<? extends org.apache.ibatis.plugin.Interceptor>> interceptorsClasses)
Adds the user defined MyBatis interceptors plugins types, letting google-guice creating them.protected void
addMapperClass(Class<?> mapperClass)
Adds the user defined mapper classes.protected void
addMapperClasses(String packageName)
Adds the user defined mapper classes.protected void
addMapperClasses(String packageName, org.apache.ibatis.io.ResolverUtil.Test test)
Adds the user defined mapper classes.protected void
addMapperClasses(Collection<Class<?>> mapperClasses)
Adds the user defined mapper classes.protected void
addSimpleAlias(Class<?> type)
Adding simple aliases means that every specified class will be bound using the simple class name, i.e.protected void
addSimpleAliases(String packageName)
Adds all Classes in the given package as a simple alias.protected void
addSimpleAliases(String packageName, org.apache.ibatis.io.ResolverUtil.Test test)
Adds all Classes in the given package as a simple alias.protected void
addSimpleAliases(Collection<Class<?>> types)
Adding simple aliases means that every specified class will be bound using the simple class name, i.e.protected void
addTypeHandlerClass(Class<? extends org.apache.ibatis.type.TypeHandler<?>> handlerClass)
Adds the user defined MyBatis type handler, letting google-guice creating it.protected void
addTypeHandlerClasses(String packageName)
Adds the user defined MyBatis type handlers in the given package, letting google-guice creating it.protected void
addTypeHandlersClasses(Collection<Class<? extends org.apache.ibatis.type.TypeHandler<?>>> handlersClasses)
Adds the user defined MyBatis type handlers, letting google-guice creating it.protected void
aggressiveLazyLoading(boolean aggressiveLazyLoading)
Aggressive lazy loading.protected void
autoMappingBehavior(org.apache.ibatis.session.AutoMappingBehavior autoMappingBehavior)
Auto mapping behavior.protected void
bindConfigurationSetting(ConfigurationSetting configurationSetting)
protected <P extends javax.inject.Provider<? extends ConfigurationSetting>>
voidbindConfigurationSettingProvider(P configurationSettingProvider)
protected void
bindDatabaseIdProvider(Class<? extends org.apache.ibatis.mapping.DatabaseIdProvider> databaseIdProvider)
Bind database id provider.protected void
bindDatabaseIdProvider(org.apache.ibatis.mapping.DatabaseIdProvider databaseIdProvider)
Bind database id provider.protected void
bindDataSourceProvider(com.google.inject.Provider<DataSource> dataSourceProvider)
Bind data source provider.protected void
bindDataSourceProvider(javax.inject.Provider<DataSource> dataSourceProvider)
Bind data source provider.protected void
bindDataSourceProviderType(Class<? extends javax.inject.Provider<DataSource>> dataSourceProviderType)
Set the DataSource Provider type has to be bound.protected void
bindDefaultScriptingLanguageType(Class<? extends org.apache.ibatis.scripting.LanguageDriver> defaultScriptingLanguageType)
Sets the default LanguageDriver class.protected void
bindObjectFactoryType(Class<? extends org.apache.ibatis.reflection.factory.ObjectFactory> objectFactoryType)
Sets the ObjectFactory class.protected void
bindObjectWrapperFactoryType(Class<? extends org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory> objectWrapperFactoryType)
Sets the ObjectWrapperFactory class.protected void
bindTransactionFactory(com.google.inject.Provider<org.apache.ibatis.transaction.TransactionFactory> transactionFactoryProvider)
Bind transaction factory.protected void
bindTransactionFactory(javax.inject.Provider<org.apache.ibatis.transaction.TransactionFactory> transactionFactoryProvider)
Bind transaction factory.protected void
bindTransactionFactoryType(Class<? extends org.apache.ibatis.transaction.TransactionFactory> transactionFactoryType)
Set the TransactionFactory type has to be bound.protected void
bindTransactionInterceptors()
bind transactional interceptors.protected void
configure()
protected void
defaultStatementTimeout(Integer defaultStatementTimeout)
set default statement timeout.protected void
environmentId(String environmentId)
Set the MyBatis configuration environment id.protected void
executorType(org.apache.ibatis.session.ExecutorType executorType)
Executor type.protected void
failFast(boolean failFast)
Fail fast.protected ClassLoader
getResourceClassLoader()
Gets the resource class loader.protected <T> TypeHandlerBinder<T>
handleType(Class<T> type)
Add a user defined Type Handler letting google-guice creating it.protected abstract void
initialize()
Initialize.protected void
lazyLoadingEnabled(boolean lazyLoadingEnabled)
Lazy loading enabled.protected void
localCacheScope(org.apache.ibatis.session.LocalCacheScope localeCacheScope)
Configures the local cache scope setting.protected void
mapUnderscoreToCamelCase(boolean mapUnderscoreToCamelCase)
Maps underscores to camel case.protected void
multipleResultSetsEnabled(boolean multipleResultSetsEnabled)
Multiple result sets enabled.protected void
useCacheEnabled(boolean useCacheEnabled)
Use cache enabled.protected void
useColumnLabel(boolean useColumnLabel)
Use column label.protected void
useConfigurationProvider(Class<? extends javax.inject.Provider<? extends org.apache.ibatis.session.Configuration>> configurationProviderType)
Use configuration provider.protected void
useGeneratedKeys(boolean useGeneratedKeys)
Use generated keys.void
useJdbcDriverClassLoader(ClassLoader driverClassLoader)
Use jdbc driver class loader.void
useResourceClassLoader(ClassLoader resourceClassLoader)
Use resource class loader.protected void
useSqlSessionFactoryProvider(Class<? extends javax.inject.Provider<? extends org.apache.ibatis.session.SqlSessionFactory>> sqlSessionFactoryProvider)
Use sql session factory provider.-
Methods inherited from class com.google.inject.AbstractModule
addError, addError, addError, bind, bind, bind, bindConstant, binder, bindInterceptor, bindListener, bindListener, bindScope, configure, convertToTypes, currentStage, getMembersInjector, getMembersInjector, getProvider, getProvider, install, requestInjection, requestStaticInjection, requireBinding, requireBinding
-
-
-
-
Method Detail
-
environmentId
protected final void environmentId(String environmentId)
Set the MyBatis configuration environment id.- Parameters:
environmentId
- the MyBatis configuration environment id
-
lazyLoadingEnabled
protected final void lazyLoadingEnabled(boolean lazyLoadingEnabled)
Lazy loading enabled.- Parameters:
lazyLoadingEnabled
- the lazy loading enabled
-
aggressiveLazyLoading
protected final void aggressiveLazyLoading(boolean aggressiveLazyLoading)
Aggressive lazy loading.- Parameters:
aggressiveLazyLoading
- the aggressive lazy loading
-
multipleResultSetsEnabled
protected final void multipleResultSetsEnabled(boolean multipleResultSetsEnabled)
Multiple result sets enabled.- Parameters:
multipleResultSetsEnabled
- the multiple result sets enabled
-
useGeneratedKeys
protected final void useGeneratedKeys(boolean useGeneratedKeys)
Use generated keys.- Parameters:
useGeneratedKeys
- the use generated keys
-
useColumnLabel
protected final void useColumnLabel(boolean useColumnLabel)
Use column label.- Parameters:
useColumnLabel
- the use column label
-
useCacheEnabled
protected final void useCacheEnabled(boolean useCacheEnabled)
Use cache enabled.- Parameters:
useCacheEnabled
- the use cache enabled
-
useConfigurationProvider
protected final void useConfigurationProvider(Class<? extends javax.inject.Provider<? extends org.apache.ibatis.session.Configuration>> configurationProviderType)
Use configuration provider.- Parameters:
configurationProviderType
- provider for Configuration
-
useSqlSessionFactoryProvider
protected final void useSqlSessionFactoryProvider(Class<? extends javax.inject.Provider<? extends org.apache.ibatis.session.SqlSessionFactory>> sqlSessionFactoryProvider)
Use sql session factory provider.- Parameters:
sqlSessionFactoryProvider
- provider for SqlSessionFactory
-
failFast
protected final void failFast(boolean failFast)
Fail fast.- Parameters:
failFast
- the fail fast
-
mapUnderscoreToCamelCase
protected final void mapUnderscoreToCamelCase(boolean mapUnderscoreToCamelCase)
Maps underscores to camel case.- Parameters:
mapUnderscoreToCamelCase
- Toggles this settings value.
-
defaultStatementTimeout
protected final void defaultStatementTimeout(Integer defaultStatementTimeout)
set default statement timeout.- Parameters:
defaultStatementTimeout
- default statement timeout in seconds.
-
bindConfigurationSetting
protected final void bindConfigurationSetting(ConfigurationSetting configurationSetting)
-
bindConfigurationSettingProvider
protected final <P extends javax.inject.Provider<? extends ConfigurationSetting>> void bindConfigurationSettingProvider(P configurationSettingProvider)
-
executorType
protected final void executorType(org.apache.ibatis.session.ExecutorType executorType)
Executor type.- Parameters:
executorType
- the executor type
-
localCacheScope
protected final void localCacheScope(org.apache.ibatis.session.LocalCacheScope localeCacheScope)
Configures the local cache scope setting.- Parameters:
localeCacheScope
- The cache scope to use.- Since:
- 3.4
-
autoMappingBehavior
protected final void autoMappingBehavior(org.apache.ibatis.session.AutoMappingBehavior autoMappingBehavior)
Auto mapping behavior.- Parameters:
autoMappingBehavior
- the auto mapping behavior
-
bindDataSourceProviderType
protected final void bindDataSourceProviderType(Class<? extends javax.inject.Provider<DataSource>> dataSourceProviderType)
Set the DataSource Provider type has to be bound.- Parameters:
dataSourceProviderType
- the DataSource Provider type
-
bindDataSourceProvider
protected final void bindDataSourceProvider(javax.inject.Provider<DataSource> dataSourceProvider)
Bind data source provider.- Parameters:
dataSourceProvider
- the data source provider
-
bindDataSourceProvider
protected final void bindDataSourceProvider(com.google.inject.Provider<DataSource> dataSourceProvider)
Bind data source provider.- Parameters:
dataSourceProvider
- the data source provider
-
bindDatabaseIdProvider
protected final void bindDatabaseIdProvider(Class<? extends org.apache.ibatis.mapping.DatabaseIdProvider> databaseIdProvider)
Bind database id provider.- Parameters:
databaseIdProvider
- The DatabaseIdProvider class.
-
bindDatabaseIdProvider
protected final void bindDatabaseIdProvider(org.apache.ibatis.mapping.DatabaseIdProvider databaseIdProvider)
Bind database id provider.- Parameters:
databaseIdProvider
- The DatabaseIdProvider instance.
-
bindTransactionFactoryType
protected final void bindTransactionFactoryType(Class<? extends org.apache.ibatis.transaction.TransactionFactory> transactionFactoryType)
Set the TransactionFactory type has to be bound.- Parameters:
transactionFactoryType
- the TransactionFactory type
-
bindTransactionFactory
protected final void bindTransactionFactory(javax.inject.Provider<org.apache.ibatis.transaction.TransactionFactory> transactionFactoryProvider)
Bind transaction factory.- Parameters:
transactionFactoryProvider
- the transaction factory provider
-
bindTransactionFactory
protected final void bindTransactionFactory(com.google.inject.Provider<org.apache.ibatis.transaction.TransactionFactory> transactionFactoryProvider)
Bind transaction factory.- Parameters:
transactionFactoryProvider
- the transaction factory provider
-
bindObjectFactoryType
protected final void bindObjectFactoryType(Class<? extends org.apache.ibatis.reflection.factory.ObjectFactory> objectFactoryType)
Sets the ObjectFactory class.- Parameters:
objectFactoryType
- the ObjectFactory type
-
bindObjectWrapperFactoryType
protected final void bindObjectWrapperFactoryType(Class<? extends org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory> objectWrapperFactoryType)
Sets the ObjectWrapperFactory class.- Parameters:
objectWrapperFactoryType
- the ObjectFactory type
-
bindDefaultScriptingLanguageType
protected final void bindDefaultScriptingLanguageType(Class<? extends org.apache.ibatis.scripting.LanguageDriver> defaultScriptingLanguageType)
Sets the default LanguageDriver class.Due to current limitations in MyBatis, @Inject cannot be used in LanguageDriver class.
- Parameters:
defaultScriptingLanguageType
- the default LanguageDriver type
-
addAlias
protected final AliasBinder addAlias(String alias)
Add a user defined binding.- Parameters:
alias
- the string type alias- Returns:
- the alias binder
-
addSimpleAlias
protected final void addSimpleAlias(Class<?> type)
Adding simple aliases means that every specified class will be bound using the simple class name, i.e.com.acme.Foo
becomesFoo
.- Parameters:
type
- the specified types have to be bind
-
addSimpleAliases
protected final void addSimpleAliases(Collection<Class<?>> types)
Adding simple aliases means that every specified class will be bound using the simple class name, i.e.com.acme.Foo
becomesFoo
.- Parameters:
types
- the specified types have to be bind
-
addSimpleAliases
protected final void addSimpleAliases(String packageName, org.apache.ibatis.io.ResolverUtil.Test test)
Adds all Classes in the given package as a simple alias. Adding simple aliases means that every specified class will be bound using the simple class name, i.e.com.acme.Foo
becomesFoo
.- Parameters:
packageName
- the specified package to search for classes to alias.test
- a test to run against the objects found in the specified package
-
addSimpleAliases
protected final void addSimpleAliases(String packageName)
Adds all Classes in the given package as a simple alias. Adding simple aliases means that every specified class will be bound using the simple class name, i.e.com.acme.Foo
becomesFoo
.- Parameters:
packageName
- the specified package to search for classes to alias
-
handleType
protected final <T> TypeHandlerBinder<T> handleType(Class<T> type)
Add a user defined Type Handler letting google-guice creating it.- Type Parameters:
T
- the generic type- Parameters:
type
- the specified type has to be handled.- Returns:
- the type handler binder
-
addTypeHandlerClass
protected final void addTypeHandlerClass(Class<? extends org.apache.ibatis.type.TypeHandler<?>> handlerClass)
Adds the user defined MyBatis type handler, letting google-guice creating it.- Parameters:
handlerClass
- the handler type.
-
addTypeHandlersClasses
protected final void addTypeHandlersClasses(Collection<Class<? extends org.apache.ibatis.type.TypeHandler<?>>> handlersClasses)
Adds the user defined MyBatis type handlers, letting google-guice creating it.- Parameters:
handlersClasses
- the handler type.
-
addTypeHandlerClasses
protected final void addTypeHandlerClasses(String packageName)
Adds the user defined MyBatis type handlers in the given package, letting google-guice creating it.- Parameters:
packageName
- the package where looking for type handlers.
-
addInterceptorClass
protected final void addInterceptorClass(Class<? extends org.apache.ibatis.plugin.Interceptor> interceptorClass)
Adds the user defined myBatis interceptor plugins type, letting google-guice creating it.- Parameters:
interceptorClass
- The user defined MyBatis interceptor plugin type
-
addInterceptorsClasses
protected final void addInterceptorsClasses(Collection<Class<? extends org.apache.ibatis.plugin.Interceptor>> interceptorsClasses)
Adds the user defined MyBatis interceptors plugins types, letting google-guice creating them.- Parameters:
interceptorsClasses
- the user defined MyBatis Interceptors plugins types
-
addInterceptorsClasses
protected final void addInterceptorsClasses(String packageName)
Adds the user defined MyBatis interceptors plugins types in the given package, letting google-guice creating them.- Parameters:
packageName
- the package where looking for Interceptors plugins types.
-
addMapperClass
protected final void addMapperClass(Class<?> mapperClass)
Adds the user defined mapper classes.- Parameters:
mapperClass
- the user defined mapper classes.
-
addMapperClasses
protected final void addMapperClasses(Collection<Class<?>> mapperClasses)
Adds the user defined mapper classes.- Parameters:
mapperClasses
- the user defined mapper classes
-
addMapperClasses
protected final void addMapperClasses(String packageName)
Adds the user defined mapper classes.- Parameters:
packageName
- the specified package to search for mappers to add.
-
addMapperClasses
protected final void addMapperClasses(String packageName, org.apache.ibatis.io.ResolverUtil.Test test)
Adds the user defined mapper classes.- Parameters:
packageName
- the specified package to search for mappers to add.test
- a test to run against the objects found in the specified package.
-
configure
protected final void configure()
- Overrides:
configure
in classcom.google.inject.AbstractModule
-
bindTransactionInterceptors
protected void bindTransactionInterceptors()
bind transactional interceptors.
-
useResourceClassLoader
public void useResourceClassLoader(ClassLoader resourceClassLoader)
Use resource class loader.- Parameters:
resourceClassLoader
- the resource class loader- Since:
- 3.3
-
getResourceClassLoader
protected final ClassLoader getResourceClassLoader()
Gets the resource class loader.- Returns:
- the resource class loader
- Since:
- 3.3
-
useJdbcDriverClassLoader
public void useJdbcDriverClassLoader(ClassLoader driverClassLoader)
Use jdbc driver class loader.- Parameters:
driverClassLoader
- the driver class loader- Since:
- 3.3
-
initialize
protected abstract void initialize()
Initialize.
-
-