use of indi.mybatis.flying.models.Sortable in project mybatis.flying by limeng32.
the class EnhancedCachingInterceptor method createCacheKey.
private CacheKey createCacheKey(MappedStatement mappedStatement, Object parameter, RowBounds rowBounds, BoundSql boundSql, Executor executor) {
MetaObject metaObject = MetaObject.forObject(parameter, DEFAULT_OBJECT_FACTORY, DEFAULT_OBJECT_WRAPPER_FACTORY, DEFAULT_REFLECTOR_FACTORY);
/* 当需要分页查询时,将page参数里的当前页和每页数加到cachekey里 */
if (metaObject.getOriginalObject() instanceof Conditionable) {
CacheKey cacheKey = new CacheKey();
cacheKey.update(mappedStatement.getId());
cacheKey.update(rowBounds.getOffset());
cacheKey.update(rowBounds.getLimit());
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
cacheKey.update(boundSql.getSql());
if (parameterMappings.size() > 0 && parameter != null) {
TypeHandlerRegistry typeHandlerRegistry = mappedStatement.getConfiguration().getTypeHandlerRegistry();
if (typeHandlerRegistry.hasTypeHandler(parameter.getClass())) {
cacheKey.update(parameter);
} else {
for (ParameterMapping parameterMapping : parameterMappings) {
String propertyName = parameterMapping.getProperty();
if (metaObject.hasGetter(propertyName)) {
cacheKey.update(metaObject.getValue(propertyName));
} else if (boundSql.hasAdditionalParameter(propertyName)) {
cacheKey.update(boundSql.getAdditionalParameter(propertyName));
}
}
}
}
Sortable sorter = ((Conditionable) metaObject.getOriginalObject()).getSorter();
if (sorter != null) {
cacheKey.update(sorter.toSql());
}
Limitable limiter = ((Conditionable) metaObject.getOriginalObject()).getLimiter();
if (limiter != null) {
cacheKey.update(limiter.getPageNo());
cacheKey.update(limiter.getPageSize());
}
return cacheKey;
} else {
return executor.createCacheKey(mappedStatement, parameter, rowBounds, boundSql);
}
}
Aggregations