本文整理匯總了Java中org.apache.ibatis.mapping.MappedStatement.getCache方法的典型用法代碼示例。如果您正苦於以下問題:Java MappedStatement.getCache方法的具體用法?Java MappedStatement.getCache怎麽用?Java MappedStatement.getCache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.ibatis.mapping.MappedStatement
的用法示例。
在下文中一共展示了MappedStatement.getCache方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: intercept
import org.apache.ibatis.mapping.MappedStatement; //導入方法依賴的package包/類
public Object intercept(final Invocation invocation) throws Throwable {
final Executor executor = (Executor) invocation.getTarget();
final Object[] queryArgs = invocation.getArgs();
final MappedStatement ms = (MappedStatement)queryArgs[MAPPED_STATEMENT_INDEX];
final Object parameter = queryArgs[PARAMETER_INDEX];
final RowBounds rowBounds = (RowBounds)queryArgs[ROWBOUNDS_INDEX];
final PageBounds pageBounds = new PageBounds(rowBounds);
if(pageBounds.getOffset() == RowBounds.NO_ROW_OFFSET
&& pageBounds.getLimit() == RowBounds.NO_ROW_LIMIT
&& pageBounds.getOrders().isEmpty()){
return invocation.proceed();
}
final Dialect dialect;
try {
Class clazz = Class.forName(dialectClass);
Constructor constructor = clazz.getConstructor(MappedStatement.class, Object.class, PageBounds.class);
dialect = (Dialect)constructor.newInstance(new Object[]{ms, parameter, pageBounds});
} catch (Exception e) {
throw new ClassNotFoundException("Cannot create dialect instance: "+dialectClass,e);
}
final BoundSql boundSql = ms.getBoundSql(parameter);
queryArgs[MAPPED_STATEMENT_INDEX] = copyFromNewSql(ms,boundSql,dialect.getPageSQL(), dialect.getParameterMappings(), dialect.getParameterObject());
queryArgs[PARAMETER_INDEX] = dialect.getParameterObject();
queryArgs[ROWBOUNDS_INDEX] = new RowBounds(RowBounds.NO_ROW_OFFSET,RowBounds.NO_ROW_LIMIT);
Boolean async = pageBounds.getAsyncTotalCount() == null ? asyncTotalCount : pageBounds.getAsyncTotalCount();
Future<List> listFuture = call(new Callable<List>() {
public List call() throws Exception {
return (List)invocation.proceed();
}
}, async);
if(pageBounds.isContainsTotalCount()){
Callable<Paginator> countTask = new Callable() {
public Object call() throws Exception {
Integer count;
Cache cache = ms.getCache();
if(cache != null && ms.isUseCache() && ms.getConfiguration().isCacheEnabled()){
CacheKey cacheKey = executor.createCacheKey(ms,parameter,new PageBounds(),copyFromBoundSql(ms,boundSql,dialect.getCountSQL(), boundSql.getParameterMappings(), boundSql.getParameterObject()));
count = (Integer)cache.getObject(cacheKey);
if(count == null){
count = SQLHelp.getCount(ms,executor.getTransaction(),parameter,boundSql,dialect);
cache.putObject(cacheKey, count);
}
}else{
count = SQLHelp.getCount(ms,executor.getTransaction(),parameter,boundSql,dialect);
}
return new Paginator(pageBounds.getPage(), pageBounds.getLimit(), count);
}
};
Future<Paginator> countFutrue = call(countTask, async);
return new PageList(listFuture.get(),countFutrue.get());
}
return listFuture.get();
}