源码阅读:
package org.apache.ibatis.mapping;
import org.apache.ibatis.cache.Cache;
import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator;
import org.apache.ibatis.executor.keygen.KeyGenerator;
import org.apache.ibatis.executor.keygen.NoKeyGenerator;
import org.apache.ibatis.session.Configuration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class MappedStatement {
private String resource;
private Configuration configuration;
private String id;
private Integer fetchSize;
private Integer timeout;
private StatementType statementType;
private ResultSetType resultSetType;
private SqlSource sqlSource;
private Cache cache;
private ParameterMap parameterMap;
private List<ResultMap> resultMaps;
private boolean flushCacheRequired;
private boolean useCache;
private SqlCommandType sqlCommandType;
private KeyGenerator keyGenerator;
private String keyProperty;
private boolean hasNestedResultMaps;
private MappedStatement() {
}
public static class Builder {
private MappedStatement mappedStatement = new MappedStatement();
public Builder(Configuration configuration, String id, SqlSource sqlSource,
SqlCommandType sqlCommandType) {
mappedStatement.configuration = configuration;
mappedStatement.id = id;
mappedStatement.sqlSource = sqlSource;
mappedStatement.statementType = StatementType.PREPARED;
mappedStatement.parameterMap = new ParameterMap.Builder(configuration,
"defaultParameterMap", Object.class, new ArrayList<ParameterMapping>()).build();
mappedStatement.resultMaps = new ArrayList<ResultMap>();
mappedStatement.timeout = configuration.getDefaultStatementTimeout();
mappedStatement.sqlCommandType = sqlCommandType;
mappedStatement.keyGenerator = configuration.isUseGeneratedKeys()
&& SqlCommandType.INSERT.equals(sqlCommandType) ? new Jdbc3KeyGenerator() : new NoKeyGenerator();
}
public Builder resource(String resource) {
mappedStatement.resource = resource;
return this;
}
public String id() {
return mappedStatement.id;
}
public Builder parameterMap(ParameterMap parameterMap) {
mappedStatement.parameterMap = parameterMap;
return this;
}
public Builder resultMaps(List<ResultMap> resultMaps) {
mappedStatement.resultMaps = resultMaps;
for (ResultMap resultMap : resultMaps) {
mappedStatement.hasNestedResultMaps = mappedStatement.hasNestedResultMaps || resultMap.hasNestedResultMaps();
}
return this;
}
public Builder fetchSize(Integer fetchSize) {
mappedStatement.fetchSize = fetchSize;
return this;
}
public Builder timeout(Integer timeout) {
mappedStatement.timeout = timeout;
return this;
}
public Builder statementType(StatementType statementType) {
mappedStatement.statementType = statementType;
return this;
}
public Builder resultSetType(ResultSetType resultSetType) {
mappedStatement.resultSetType = resultSetType;
return this;
}
public Builder cache(Cache cache) {
mappedStatement.cache = cache;
return this;
}
public Builder flushCacheRequired(boolean flushCacheRequired) {
mappedStatement.flushCacheRequired = flushCacheRequired;
return this;
}
public Builder useCache(boolean useCache) {
mappedStatement.useCache = useCache;
return this;
}
public Builder keyGenerator(KeyGenerator keyGenerator) {
mappedStatement.keyGenerator = keyGenerator;
return this;
}
public Builder keyProperty(String keyProperty) {
mappedStatement.keyProperty = keyProperty;
return this;
}
public MappedStatement build() {
assert mappedStatement.configuration != null;
assert mappedStatement.id != null;
assert mappedStatement.sqlSource != null;
mappedStatement.resultMaps = Collections.unmodifiableList(mappedStatement.resultMaps);
return mappedStatement;
}
}
public String getKeyProperty() {
return keyProperty;
}
public KeyGenerator getKeyGenerator() {
return keyGenerator;
}
public SqlCommandType getSqlCommandType() {
return sqlCommandType;
}
public String getResource() {
return resource;
}
public Configuration getConfiguration() {
return configuration;
}
public String getId() {
return id;
}
public boolean hasNestedResultMaps() {
return hasNestedResultMaps;
}
public Integer getFetchSize() {
return fetchSize;
}
public Integer getTimeout() {
return timeout;
}
public StatementType getStatementType() {
return statementType;
}
public ResultSetType getResultSetType() {
return resultSetType;
}
public SqlSource getSqlSource() {
return sqlSource;
}
public ParameterMap getParameterMap() {
return parameterMap;
}
public List<ResultMap> getResultMaps() {
return resultMaps;
}
public Cache getCache() {
return cache;
}
public boolean isFlushCacheRequired() {
return flushCacheRequired;
}
public boolean isUseCache() {
return useCache;
}
public BoundSql getBoundSql(Object parameterObject) {
BoundSql boundSql = sqlSource.getBoundSql(parameterObject);
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
if (parameterMappings == null || parameterMappings.size() <= 0) {
boundSql = new BoundSql(configuration, boundSql.getSql(), parameterMap.getParameterMappings(), parameterObject);
}
// check for nested result maps in parameter mappings (issue #30)
for (ParameterMapping pm : boundSql.getParameterMappings()) {
String rmId = pm.getResultMapId();
if (rmId != null) {
ResultMap rm = configuration.getResultMap(rmId);
if (rm != null) {
hasNestedResultMaps |= rm.hasNestedResultMaps();
}
}
}
return boundSql;
}
}
相关推荐
MyBatis源码分析.pdf
Mybatis源码分析主要分三部分: 1.使用案例讲解 2.Mybatis中用的所有设计模式讲解 3.源码分析
阿里巴巴P7架构师纯手工打造MyBatis源码——1小时解密底层源码.txt 需要更多往期录播资料可以联系我
5套完整springboot+mybatis源码下载只供学习之用,一套登录,一套权限,一套博客,一套.....
适合学习mybatis源码的各位同学,搜集不易,多多支持
一本小小的MyBatis源码分析书,内容详细介绍MyBatis源码!对于初中级java开发工程师是必备的!
阅读mybatis源码所记笔记。 基本: 1.数据源获取 2.mapper的sql语句获取 3.怎么去获得到的resultSet 重点: 1.orm是什么:体现于resultSet的数据库类型和java类型的转换 2.mybatis的一级缓存原理(简单的ifelse判断...
mybatis的源码分析视频,有详细的视频和文档。 视频地址亲测有效。失效了,请联系我。
mybatis源码包mybatis源码包mybatis源码包mybatis源码包
给大家分享一套课程,Java架构师之源码分析专题SpringBoot2.x、Spring5、SpringMVC、Mybatis源码分析,希望对大家学习有帮助。
Mybatis源码分析
mybatis核心源码mybatis核心源码mybatis核心源码mybatis核心源码mybatis核心源码mybatis核心源码mybatis核心源码mybatis核心源码mybatis核心源码mybatis核心源码mybatis核心源码mybatis核心源码mybatis核心源码...
mybatis中文文档和mybatis源码
MyBatis源码解析
刚开始学习mybatis的童鞋们注意了,查看mybatis源码,深入了解mybatis很有用哦
Spring整合Mybatis源码解析
mybatis源码阅读 配置 配置都在配置类 映射代理 映射器代理 3.3.1版本后ExecutorType为简单,重复使用批量插入可以正确返回生成主键 密钥生成器 useGeneratedKeys为true使用Jdbc3KeyGenerator selectKey节点使用...
mybatis源码
Spring boot Mybatis源码,只是单纯的分享给有需要的人使用,俗话说的好,万事开头难,当迈开了第一步,就相当于打开了一扇门,发现了新大陆,所以我们要持之以恒,才能取得成功,让我们一起努力,为心中最美好的...