|
@@ -54,6 +54,7 @@ import org.springframework.core.io.Resource;
|
|
import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
|
|
import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
|
|
|
|
|
|
import com.baomidou.mybatisplus.MybatisConfiguration;
|
|
import com.baomidou.mybatisplus.MybatisConfiguration;
|
|
|
|
+import com.baomidou.mybatisplus.MybatisMetaObjectHandler;
|
|
import com.baomidou.mybatisplus.MybatisXMLConfigBuilder;
|
|
import com.baomidou.mybatisplus.MybatisXMLConfigBuilder;
|
|
import com.baomidou.mybatisplus.MybatisXMLMapperBuilder;
|
|
import com.baomidou.mybatisplus.MybatisXMLMapperBuilder;
|
|
import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
|
|
import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
|
|
@@ -70,7 +71,8 @@ import com.baomidou.mybatisplus.toolkit.PackageHelper;
|
|
* @author hubin
|
|
* @author hubin
|
|
* @Date 2016-01-23
|
|
* @Date 2016-01-23
|
|
*/
|
|
*/
|
|
-public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFactory>, InitializingBean, ApplicationListener<ApplicationEvent> {
|
|
|
|
|
|
+public class MybatisSqlSessionFactoryBean
|
|
|
|
+ implements FactoryBean<SqlSessionFactory>, InitializingBean, ApplicationListener<ApplicationEvent> {
|
|
|
|
|
|
private static final Log LOGGER = LogFactory.getLog(MybatisSqlSessionFactoryBean.class);
|
|
private static final Log LOGGER = LogFactory.getLog(MybatisSqlSessionFactoryBean.class);
|
|
|
|
|
|
@@ -117,22 +119,27 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
|
|
private ObjectFactory objectFactory;
|
|
private ObjectFactory objectFactory;
|
|
|
|
|
|
private ObjectWrapperFactory objectWrapperFactory;
|
|
private ObjectWrapperFactory objectWrapperFactory;
|
|
-
|
|
|
|
- //TODO 注入数据库类型
|
|
|
|
|
|
+
|
|
|
|
+ // TODO 注入数据库类型
|
|
public void setDbType(String dbType) {
|
|
public void setDbType(String dbType) {
|
|
MybatisConfiguration.DB_TYPE = DBType.getDBType(dbType);
|
|
MybatisConfiguration.DB_TYPE = DBType.getDBType(dbType);
|
|
}
|
|
}
|
|
-
|
|
|
|
- //TODO 注入表字段使用下划线命名
|
|
|
|
|
|
+
|
|
|
|
+ // TODO 注入表字段使用下划线命名
|
|
public void setDbColumnUnderline(boolean dbColumnUnderline) {
|
|
public void setDbColumnUnderline(boolean dbColumnUnderline) {
|
|
MybatisConfiguration.DB_COLUMN_UNDERLINE = dbColumnUnderline;
|
|
MybatisConfiguration.DB_COLUMN_UNDERLINE = dbColumnUnderline;
|
|
}
|
|
}
|
|
|
|
|
|
- //TODO 注入 SQL注入器
|
|
|
|
|
|
+ // TODO 注入 SQL注入器
|
|
public void setSqlInjector(ISqlInjector sqlInjector) {
|
|
public void setSqlInjector(ISqlInjector sqlInjector) {
|
|
MybatisConfiguration.SQL_INJECTOR = sqlInjector;
|
|
MybatisConfiguration.SQL_INJECTOR = sqlInjector;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // TODO 注入 元对象字段填充控制器
|
|
|
|
+ public void setMetaObjectHandler(MybatisMetaObjectHandler metaObjectHandler) {
|
|
|
|
+ MybatisConfiguration.META_OBJECT_HANDLER = metaObjectHandler;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Sets the ObjectFactory.
|
|
* Sets the ObjectFactory.
|
|
*
|
|
*
|
|
@@ -432,7 +439,7 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
|
|
|
|
|
|
Configuration configuration;
|
|
Configuration configuration;
|
|
|
|
|
|
- //TODO 加载自定义 MybatisXmlConfigBuilder
|
|
|
|
|
|
+ // TODO 加载自定义 MybatisXmlConfigBuilder
|
|
MybatisXMLConfigBuilder xmlConfigBuilder = null;
|
|
MybatisXMLConfigBuilder xmlConfigBuilder = null;
|
|
if (this.configuration != null) {
|
|
if (this.configuration != null) {
|
|
configuration = this.configuration;
|
|
configuration = this.configuration;
|
|
@@ -450,7 +457,7 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
|
|
LOGGER.debug(
|
|
LOGGER.debug(
|
|
"Property `configuration` or 'configLocation' not specified, using default MyBatis Configuration");
|
|
"Property `configuration` or 'configLocation' not specified, using default MyBatis Configuration");
|
|
}
|
|
}
|
|
- //TODO 使用自定义配置
|
|
|
|
|
|
+ // TODO 使用自定义配置
|
|
configuration = new MybatisConfiguration();
|
|
configuration = new MybatisConfiguration();
|
|
configuration.setVariables(this.configurationProperties);
|
|
configuration.setVariables(this.configurationProperties);
|
|
}
|
|
}
|
|
@@ -468,7 +475,7 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
|
|
}
|
|
}
|
|
|
|
|
|
if (hasLength(this.typeAliasesPackage)) {
|
|
if (hasLength(this.typeAliasesPackage)) {
|
|
- //TODO
|
|
|
|
|
|
+ // TODO
|
|
String[] typeAliasPackageArray = null;
|
|
String[] typeAliasPackageArray = null;
|
|
if (typeAliasesPackage.contains("*")) {
|
|
if (typeAliasesPackage.contains("*")) {
|
|
typeAliasPackageArray = PackageHelper.convertTypeAliasesPackage(typeAliasesPackage);
|
|
typeAliasPackageArray = PackageHelper.convertTypeAliasesPackage(typeAliasesPackage);
|
|
@@ -566,9 +573,10 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
|
|
}
|
|
}
|
|
|
|
|
|
try {
|
|
try {
|
|
- //TODO
|
|
|
|
- MybatisXMLMapperBuilder xmlMapperBuilder = new MybatisXMLMapperBuilder(mapperLocation.getInputStream(),
|
|
|
|
- configuration, mapperLocation.toString(), configuration.getSqlFragments());
|
|
|
|
|
|
+ // TODO
|
|
|
|
+ MybatisXMLMapperBuilder xmlMapperBuilder = new MybatisXMLMapperBuilder(
|
|
|
|
+ mapperLocation.getInputStream(), configuration, mapperLocation.toString(),
|
|
|
|
+ configuration.getSqlFragments());
|
|
xmlMapperBuilder.parse();
|
|
xmlMapperBuilder.parse();
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
throw new NestedIOException("Failed to parse mapping resource: '" + mapperLocation + "'", e);
|
|
throw new NestedIOException("Failed to parse mapping resource: '" + mapperLocation + "'", e);
|