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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected final AliasBinder
Add a user defined binding.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.protected final void
addInterceptorsClasses
(String packageName) Adds the user defined MyBatis interceptors plugins types in the given package, letting google-guice creating them.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.protected final void
addMapperClass
(Class<?> mapperClass) Adds the user defined mapper classes.protected final void
addMapperClasses
(String packageName) Adds the user defined mapper classes.protected final void
addMapperClasses
(String packageName, org.apache.ibatis.io.ResolverUtil.Test test) Adds the user defined mapper classes.protected final void
addMapperClasses
(Collection<Class<?>> mapperClasses) Adds the user defined mapper classes.protected final void
addSimpleAlias
(Class<?> type) Adding simple aliases means that every specified class will be bound using the simple class name, i.e.protected final void
addSimpleAliases
(String packageName) Adds all Classes in the given package as a simple alias.protected final void
addSimpleAliases
(String packageName, org.apache.ibatis.io.ResolverUtil.Test test) Adds all Classes in the given package as a simple alias.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.protected final void
addTypeHandlerClass
(Class<? extends org.apache.ibatis.type.TypeHandler<?>> handlerClass) Adds the user defined MyBatis type handler, letting google-guice creating it.protected final void
addTypeHandlerClasses
(String packageName) Adds the user defined MyBatis type handlers in the given package, letting google-guice creating it.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.protected final void
aggressiveLazyLoading
(boolean aggressiveLazyLoading) Aggressive lazy loading.protected final void
autoMappingBehavior
(org.apache.ibatis.session.AutoMappingBehavior autoMappingBehavior) Auto mapping behavior.protected final void
bindConfigurationSetting
(ConfigurationSetting configurationSetting) protected final <P extends jakarta.inject.Provider<? extends ConfigurationSetting>>
voidbindConfigurationSettingProvider
(P configurationSettingProvider) protected final void
bindDatabaseIdProvider
(Class<? extends org.apache.ibatis.mapping.DatabaseIdProvider> databaseIdProvider) Bind database id provider.protected final void
bindDatabaseIdProvider
(org.apache.ibatis.mapping.DatabaseIdProvider databaseIdProvider) Bind database id provider.protected final void
bindDataSourceProvider
(com.google.inject.Provider<DataSource> dataSourceProvider) Bind data source provider.protected final void
bindDataSourceProvider
(jakarta.inject.Provider<DataSource> dataSourceProvider) Bind data source provider.protected final void
bindDataSourceProviderType
(Class<? extends jakarta.inject.Provider<DataSource>> dataSourceProviderType) Set the DataSource Provider type has to be bound.protected final void
bindDefaultScriptingLanguageType
(Class<? extends org.apache.ibatis.scripting.LanguageDriver> defaultScriptingLanguageType) Sets the default LanguageDriver class.protected final void
bindObjectFactoryType
(Class<? extends org.apache.ibatis.reflection.factory.ObjectFactory> objectFactoryType) Sets the ObjectFactory class.protected final void
bindObjectWrapperFactoryType
(Class<? extends org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory> objectWrapperFactoryType) Sets the ObjectWrapperFactory class.protected final void
bindTransactionFactory
(com.google.inject.Provider<org.apache.ibatis.transaction.TransactionFactory> transactionFactoryProvider) Bind transaction factory.protected final void
bindTransactionFactory
(jakarta.inject.Provider<org.apache.ibatis.transaction.TransactionFactory> transactionFactoryProvider) Bind transaction factory.protected final void
bindTransactionFactoryType
(Class<? extends org.apache.ibatis.transaction.TransactionFactory> transactionFactoryType) Set the TransactionFactory type has to be bound.protected void
bind transactional interceptors.protected final void
protected final void
defaultStatementTimeout
(Integer defaultStatementTimeout) set default statement timeout.protected final void
environmentId
(String environmentId) Set the MyBatis configuration environment id.protected final void
executorType
(org.apache.ibatis.session.ExecutorType executorType) Executor type.protected final void
failFast
(boolean failFast) Fail fast.getClasses
(String packageName) Return a set of all classes contained in the given package.getClasses
(org.apache.ibatis.io.ResolverUtil.Test test, String packageName) Return a set of all classes contained in the given package that match with the given test requirement.protected final ClassLoader
Gets the resource class loader.protected final <T> TypeHandlerBinder
<T> handleType
(Class<T> type) Add a user defined Type Handler letting google-guice creating it.protected abstract void
Initialize.protected final void
lazyLoadingEnabled
(boolean lazyLoadingEnabled) Lazy loading enabled.protected final void
localCacheScope
(org.apache.ibatis.session.LocalCacheScope localeCacheScope) Configures the local cache scope setting.protected final void
mapUnderscoreToCamelCase
(boolean mapUnderscoreToCamelCase) Maps underscores to camel case.protected final void
multipleResultSetsEnabled
(boolean multipleResultSetsEnabled) Multiple result sets enabled.protected final void
useCacheEnabled
(boolean useCacheEnabled) Use cache enabled.protected final void
useColumnLabel
(boolean useColumnLabel) Use column label.protected final void
useConfigurationProvider
(Class<? extends jakarta.inject.Provider<? extends org.apache.ibatis.session.Configuration>> configurationProviderType) Use configuration provider.protected final 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 final void
useSqlSessionFactoryProvider
(Class<? extends jakarta.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, requestInjection, requestStaticInjection, requireBinding, requireBinding
-
Field Details
-
DECLARED_BY_OBJECT
-
SYNTHETIC
-
-
Constructor Details
-
MyBatisModule
public MyBatisModule()
-
-
Method Details
-
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 jakarta.inject.Provider<? extends org.apache.ibatis.session.Configuration>> configurationProviderType) Use configuration provider.- Parameters:
configurationProviderType
- provider for Configuration
-
useSqlSessionFactoryProvider
protected final void useSqlSessionFactoryProvider(Class<? extends jakarta.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
set default statement timeout.- Parameters:
defaultStatementTimeout
- default statement timeout in seconds.
-
bindConfigurationSetting
-
bindConfigurationSettingProvider
protected final <P extends jakarta.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 jakarta.inject.Provider<DataSource>> dataSourceProviderType) Set the DataSource Provider type has to be bound.- Parameters:
dataSourceProviderType
- the DataSource Provider type
-
bindDataSourceProvider
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(jakarta.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
Add a user defined binding.- Parameters:
alias
- the string type alias- Returns:
- the alias binder
-
addSimpleAlias
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
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
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
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
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
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
Adds the user defined mapper classes.- Parameters:
mapperClass
- the user defined mapper classes.
-
addMapperClasses
Adds the user defined mapper classes.- Parameters:
mapperClasses
- the user defined mapper classes
-
addMapperClasses
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.
-
getClasses
Return a set of all classes contained in the given package.- Parameters:
packageName
- the package has to be analyzed.- Returns:
- a set of all classes contained in the given package.
-
getClasses
protected static Set<Class<?>> getClasses(org.apache.ibatis.io.ResolverUtil.Test test, String packageName) Return a set of all classes contained in the given package that match with the given test requirement.- Parameters:
test
- the class filter on the given package.packageName
- the package has to be analyzed.- Returns:
- a set of all classes contained in the given package.
-
configure
protected final void configure()- Overrides:
configure
in classcom.google.inject.AbstractModule
-
bindTransactionInterceptors
protected void bindTransactionInterceptors()bind transactional interceptors. -
useResourceClassLoader
Use resource class loader.- Parameters:
resourceClassLoader
- the resource class loader- Since:
- 3.3
-
getResourceClassLoader
Gets the resource class loader.- Returns:
- the resource class loader
- Since:
- 3.3
-
useJdbcDriverClassLoader
Use jdbc driver class loader.- Parameters:
driverClassLoader
- the driver class loader- Since:
- 3.3
-
initialize
protected abstract void initialize()Initialize.
-