|
@@ -38,6 +38,7 @@ import org.apache.ibatis.mapping.Environment;
|
|
|
import org.apache.ibatis.plugin.Interceptor;
|
|
|
import org.apache.ibatis.reflection.factory.ObjectFactory;
|
|
|
import org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory;
|
|
|
+import org.apache.ibatis.scripting.LanguageDriver;
|
|
|
import org.apache.ibatis.session.Configuration;
|
|
|
import org.apache.ibatis.session.SqlSessionFactory;
|
|
|
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
|
|
@@ -96,6 +97,7 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
|
|
|
|
|
|
private Resource configLocation;
|
|
|
|
|
|
+ // TODO 使用 MybatisConfiguration
|
|
|
private MybatisConfiguration configuration;
|
|
|
|
|
|
private Resource[] mapperLocations;
|
|
@@ -106,11 +108,13 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
|
|
|
|
|
|
private Properties configurationProperties;
|
|
|
|
|
|
+ // TODO 默认值改为 new MybatisSqlSessionFactoryBuilder();
|
|
|
private SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new MybatisSqlSessionFactoryBuilder();
|
|
|
|
|
|
private SqlSessionFactory sqlSessionFactory;
|
|
|
|
|
|
- //EnvironmentAware requires spring 3.1
|
|
|
+ // TODO 默认值改为 MybatisSqlSessionFactoryBean.class.getSimpleName();
|
|
|
+ // EnvironmentAware requires spring 3.1
|
|
|
private String environment = MybatisSqlSessionFactoryBean.class.getSimpleName();
|
|
|
|
|
|
private boolean failFast;
|
|
@@ -127,7 +131,11 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
|
|
|
|
|
|
private Class<?> typeAliasesSuperType;
|
|
|
|
|
|
- //issue #19. No default provider.
|
|
|
+ private LanguageDriver[] scriptingLanguageDrivers;
|
|
|
+
|
|
|
+ private Class<? extends LanguageDriver> defaultScriptingLanguageDriver;
|
|
|
+
|
|
|
+ // issue #19. No default provider.
|
|
|
private DatabaseIdProvider databaseIdProvider;
|
|
|
|
|
|
private Class<? extends VFS> vfs;
|
|
@@ -177,8 +185,7 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Sets the DatabaseIdProvider.
|
|
|
- * As of version 1.2.2 this variable is not initialized by default.
|
|
|
+ * Sets the DatabaseIdProvider. As of version 1.2.2 this variable is not initialized by default.
|
|
|
*
|
|
|
* @param databaseIdProvider a DatabaseIdProvider
|
|
|
* @since 1.1.0
|
|
@@ -229,14 +236,15 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
|
|
|
* @param plugins list of plugins
|
|
|
* @since 1.0.1
|
|
|
*/
|
|
|
- public void setPlugins(Interceptor[] plugins) {
|
|
|
+ public void setPlugins(Interceptor... plugins) {
|
|
|
this.plugins = plugins;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Packages to search for type aliases.
|
|
|
*
|
|
|
- * <p>Since 2.0.1, allow to specify a wildcard such as {@code com.example.*.model}.
|
|
|
+ * <p>
|
|
|
+ * Since 2.0.1, allow to specify a wildcard such as {@code com.example.*.model}.
|
|
|
*
|
|
|
* @param typeAliasesPackage package to scan for domain objects
|
|
|
* @since 1.0.1
|
|
@@ -246,8 +254,8 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Super class which domain objects have to extend to have a type alias created.
|
|
|
- * No effect if there is no package to scan configured.
|
|
|
+ * Super class which domain objects have to extend to have a type alias created. No effect if there is no package to
|
|
|
+ * scan configured.
|
|
|
*
|
|
|
* @param typeAliasesSuperType super class for domain objects
|
|
|
* @since 1.1.2
|
|
@@ -259,7 +267,8 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
|
|
|
/**
|
|
|
* Packages to search for type handlers.
|
|
|
*
|
|
|
- * <p>Since 2.0.1, allow to specify a wildcard such as {@code com.example.*.typehandler}.
|
|
|
+ * <p>
|
|
|
+ * Since 2.0.1, allow to specify a wildcard such as {@code com.example.*.typehandler}.
|
|
|
*
|
|
|
* @param typeHandlersPackage package to scan for type handlers
|
|
|
* @since 1.0.1
|
|
@@ -274,7 +283,7 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
|
|
|
* @param typeHandlers Type handler list
|
|
|
* @since 1.0.1
|
|
|
*/
|
|
|
- public void setTypeHandlers(TypeHandler<?>[] typeHandlers) {
|
|
|
+ public void setTypeHandlers(TypeHandler<?>... typeHandlers) {
|
|
|
this.typeHandlers = typeHandlers;
|
|
|
}
|
|
|
|
|
@@ -284,14 +293,13 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
|
|
|
* @param typeAliases Type aliases list
|
|
|
* @since 1.0.1
|
|
|
*/
|
|
|
- public void setTypeAliases(Class<?>[] typeAliases) {
|
|
|
+ public void setTypeAliases(Class<?>... typeAliases) {
|
|
|
this.typeAliases = typeAliases;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 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.
|
|
|
+ * 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.
|
|
|
*
|
|
|
* @param failFast enable failFast
|
|
|
* @since 1.0.1
|
|
@@ -322,23 +330,23 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Set locations of MyBatis mapper files that are going to be merged into the {@code SqlSessionFactory}
|
|
|
- * configuration at runtime.
|
|
|
+ * Set locations of MyBatis mapper files that are going to be merged into the {@code SqlSessionFactory} configuration
|
|
|
+ * at runtime.
|
|
|
* <p>
|
|
|
- * 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".
|
|
|
+ * 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".
|
|
|
*
|
|
|
* @param mapperLocations location of MyBatis mapper files
|
|
|
*/
|
|
|
- public void setMapperLocations(Resource[] mapperLocations) {
|
|
|
+ public void setMapperLocations(Resource... mapperLocations) {
|
|
|
this.mapperLocations = mapperLocations;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Set optional properties to be passed into the SqlSession configuration, as alternative to a
|
|
|
- * {@code <properties>} tag in the configuration xml file. This will be used to
|
|
|
- * resolve placeholders in the config file.
|
|
|
+ * {@code <properties>} tag in the configuration xml file. This will be used to resolve placeholders in the
|
|
|
+ * config file.
|
|
|
*
|
|
|
* @param sqlSessionFactoryProperties optional properties for the SqlSessionFactory
|
|
|
*/
|
|
@@ -347,18 +355,18 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Set the JDBC {@code DataSource} that this instance should manage transactions for. The {@code DataSource}
|
|
|
- * should match the one used by the {@code SqlSessionFactory}: for example, you could specify the same
|
|
|
- * JNDI DataSource for both.
|
|
|
+ * Set the JDBC {@code DataSource} that this instance should manage transactions for. The {@code DataSource} should
|
|
|
+ * match the one used by the {@code SqlSessionFactory}: for example, you could specify the same JNDI DataSource for
|
|
|
+ * both.
|
|
|
* <p>
|
|
|
- * A transactional JDBC {@code Connection} for this {@code DataSource} will be provided to application code
|
|
|
- * accessing this {@code DataSource} directly via {@code DataSourceUtils} or {@code DataSourceTransactionManager}.
|
|
|
+ * A transactional JDBC {@code Connection} for this {@code DataSource} will be provided to application code accessing
|
|
|
+ * this {@code DataSource} directly via {@code DataSourceUtils} or {@code DataSourceTransactionManager}.
|
|
|
* <p>
|
|
|
- * The {@code DataSource} specified here should be the target {@code DataSource} to manage transactions for, not
|
|
|
- * a {@code TransactionAwareDataSourceProxy}. Only data access code may work with
|
|
|
- * {@code TransactionAwareDataSourceProxy}, while the transaction manager needs to work on the
|
|
|
- * underlying target {@code DataSource}. If there's nevertheless a {@code TransactionAwareDataSourceProxy}
|
|
|
- * passed in, it will be unwrapped to extract its target {@code DataSource}.
|
|
|
+ * The {@code DataSource} specified here should be the target {@code DataSource} to manage transactions for, not a
|
|
|
+ * {@code TransactionAwareDataSourceProxy}. Only data access code may work with
|
|
|
+ * {@code TransactionAwareDataSourceProxy}, while the transaction manager needs to work on the underlying target
|
|
|
+ * {@code DataSource}. If there's nevertheless a {@code TransactionAwareDataSourceProxy} passed in, it will be
|
|
|
+ * unwrapped to extract its target {@code DataSource}.
|
|
|
*
|
|
|
* @param dataSource a JDBC {@code DataSource}
|
|
|
*/
|
|
@@ -643,14 +651,13 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private Set<Class<?>> scanClasses(String packagePatterns, Class<?> assignableType)
|
|
|
- throws IOException {
|
|
|
+ private Set<Class<?>> scanClasses(String packagePatterns, Class<?> assignableType) throws IOException {
|
|
|
Set<Class<?>> classes = new HashSet<>();
|
|
|
String[] packagePatternArray = tokenizeToStringArray(packagePatterns,
|
|
|
ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
|
|
|
for (String packagePattern : packagePatternArray) {
|
|
|
- Resource[] resources = RESOURCE_PATTERN_RESOLVER.getResources(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX +
|
|
|
- org.springframework.util.ClassUtils.convertClassNameToResourcePath(packagePattern) + "/**/*.class");
|
|
|
+ Resource[] resources = RESOURCE_PATTERN_RESOLVER.getResources(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
|
|
|
+ + ClassUtils.convertClassNameToResourcePath(packagePattern) + "/**/*.class");
|
|
|
for (Resource resource : resources) {
|
|
|
try {
|
|
|
ClassMetadata classMetadata = METADATA_READER_FACTORY.getMetadataReader(resource).getClassMetadata();
|