public class DefaultSqlSession implements SqlSession {
private Configuration configuration;
private Executor executor;
... ...
@Override
public List selectList(String statement) {
return this.selectList(statement, null);
}
@Override
public List selectList(String statement, Object parameter) {
return this.selectList(statement, parameter, RowBounds.DEFAULT); //其中RowBounds.DEFAULT为new RowBounds();
}
@Override
public List selectList(String statement, Object parameter, RowBounds rowBounds) {
try {
//MappedStatement是mybatis根据创建的映射对象
MappedStatement ms = configuration.getMappedStatement(statement);
return executor.query(ms, wrapCollection(parameter), rowBounds, Executor.NO_RESULT_HANDLER);
} catch (Exception e) {
throw ExceptionFactory.wrapException("Error querying database. Cause: " + e, e);
} finally {
ErrorContext.instance().reset();
}
}
... ...
}
/**
* 行数限制
*/
public class RowBounds {
public static final int NO_ROW_OFFSET = 0;
public static final int NO_ROW_LIMIT = Integer.MAX_VALUE;
public static final RowBounds DEFAULT = new RowBounds();
private int offset;
private int limit;
public RowBounds() {
this.offset = NO_ROW_OFFSET;
this.limit = NO_ROW_LIMIT;
}
public RowBounds(int offset, int limit) {
this.offset = offset;
this.limit = limit;
}
... ...
}
当我们启用缓存后查询执行器Executor为CachingExector:
public class CachingExecutor implements Executor {
private Executor delegate;
private TransactionalCacheManager tcm = new TransactionalCacheManager();
public CachingExecutor(Executor delegate) {
this.delegate = delegate;//这里的delegate为abstract class BaseExecutor implements Executor
delegate.setExecutorWrapper(this);
}
... ...
@Override
public List query(MappedStatement ms, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler) throws SQLException {
BoundSql boundSql = ms.getBoundSql(parameterObject);
CacheKey key = createCacheKey(ms, parameterObject, rowBounds, boundSql);
return query(ms, parameterObject, rowBounds, resultHandler, key, boundSql);
}
@Override
public List query(MappedStatement ms, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql)
throws SQLException {
Cache cache = ms.getCache();
if (cache != null) {
flushCacheIfRequired(ms);//如果中设置flushCache="true",则清除缓存
if (ms.isUseCache() && resultHandler == null) {
ensureNoOutParams(ms, parameterObject, boundSql);//确保查询不包括输出参数,因为缓存程序不支持输出参数
@SuppressWarnings("unchecked")
List list = (List) tcm.getObject(cache, key);//从缓存管理器中获取缓存(缓存管理器是对各区块缓存的统一管理工具)
if (list == null) { //如果从缓存中获取不到,则执行查询
list = delegate. query(ms, parameterObject, rowBounds, resultHandler, key, boundSql);
tcm.putObject(cache, key, list); //将查询到的结果放入缓存
}
return list;
}
}
return delegate. query(ms, parameterObject, rowBounds, resultHandler, key, boundSql);
}
... ...
}
public interface ResultSetHandler {
/**
* 处理结果集
*/
List handleResultSets(Statement stmt) throws SQLException;
... ...
}
public class DefaultResultSetHandler implements ResultSetHandler {
... ...
// nested resultmaps
private final Map nestedResultObjects = new HashMap();//嵌套结果缓存
private final Map ancestorObjects = new HashMap();//祖对象缓存,即最外层的对象缓存
private final Map ancestorColumnPrefix = new HashMap();
... ...
/**
* 处理所有的结果集(一次查询可能有多个语句,所以可能有多个结果集)
*/
@Override
public List
/**
* 结果映射
*/
public class ResultMap {
private String id; //结果映射ID
private Class> type; //映射结果类型
private List resultMappings; //所有内嵌的结果映射
private List idResultMappings; //所有内嵌的ID结果映射
private List constructorResultMappings; //所有构造映射
private List propertyResultMappings; //所有的属性映射
... ...
private ResultMap() {
}
... ...
}
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000000777c3290, pid=5632, tid=6656
#
# JRE version: Java(TM) SE Ru
Spring 中提供一些Aware相关de接口,BeanFactoryAware、 ApplicationContextAware、ResourceLoaderAware、ServletContextAware等等,其中最常用到de匙ApplicationContextAware.实现ApplicationContextAwaredeBean,在Bean被初始后,将会被注入 Applicati
在Java项目中,我们通常会自己写一个DateUtil类,处理日期和字符串的转换,如下所示:
public class DateUtil01 {
private SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public void format(Date d
问题描述:
在实现类中的某一或某几个Override方法发生编译错误如下:
Name clash: The method put(String) of type XXXServiceImpl has the same erasure as put(String) of type XXXService but does not override it
当去掉@Over