org.apache.ibatis.executor.Executor.createCacheKey()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(13.7k)|赞(0)|评价(0)|浏览(152)

本文整理了Java中org.apache.ibatis.executor.Executor.createCacheKey()方法的一些代码示例,展示了Executor.createCacheKey()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Executor.createCacheKey()方法的具体详情如下:
包路径:org.apache.ibatis.executor.Executor
类名称:Executor
方法名:createCacheKey

Executor.createCacheKey介绍

暂无

代码示例

代码示例来源:origin: pagehelper/Mybatis-PageHelper

/**
 * 执行手动设置的 count 查询,该查询支持的参数必须和被分页的方法相同
 *
 * @param executor
 * @param countMs
 * @param parameter
 * @param boundSql
 * @param resultHandler
 * @return
 * @throws SQLException
 */
public static Long executeManualCount(Executor executor, MappedStatement countMs,
                   Object parameter, BoundSql boundSql,
                   ResultHandler resultHandler) throws SQLException {
  CacheKey countKey = executor.createCacheKey(countMs, parameter, RowBounds.DEFAULT, boundSql);
  BoundSql countBoundSql = countMs.getBoundSql(parameter);
  Object countResultList = executor.query(countMs, parameter, RowBounds.DEFAULT, resultHandler, countKey, countBoundSql);
  Long count = ((Number) ((List) countResultList).get(0)).longValue();
  return count;
}

代码示例来源:origin: pagehelper/Mybatis-PageHelper

Map<String, Object> additionalParameters = getAdditionalParameter(boundSql);
CacheKey countKey = executor.createCacheKey(countMs, parameter, RowBounds.DEFAULT, boundSql);

代码示例来源:origin: pagehelper/Mybatis-PageHelper

@Override
public Object intercept(Invocation invocation) throws Throwable {
  Object[] args = invocation.getArgs();
  MappedStatement ms = (MappedStatement) args[0];
  Object parameter = args[1];
  RowBounds rowBounds = (RowBounds) args[2];
  ResultHandler resultHandler = (ResultHandler) args[3];
  Executor executor = (Executor) invocation.getTarget();
  CacheKey cacheKey;
  BoundSql boundSql;
  //由于逻辑关系,只会进入一次
  if(args.length == 4){
    //4 个参数时
    boundSql = ms.getBoundSql(parameter);
    cacheKey = executor.createCacheKey(ms, parameter, rowBounds, boundSql);
  } else {
    //6 个参数时
    cacheKey = (CacheKey) args[4];
    boundSql = (BoundSql) args[5];
  }
  //TODO 自己要进行的各种处理
  //注:下面的方法可以根据自己的逻辑调用多次,在分页插件中,count 和 page 各调用了一次
  return executor.query(ms, parameter, rowBounds, resultHandler, cacheKey, boundSql);
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Override
public CacheKey createCacheKey(MappedStatement ms, Object parameterObject, RowBounds rowBounds, BoundSql boundSql) {
 return delegate.createCacheKey(ms, parameterObject, rowBounds, boundSql);
}

代码示例来源:origin: org.mybatis/mybatis

@Override
public CacheKey createCacheKey(MappedStatement ms, Object parameterObject, RowBounds rowBounds, BoundSql boundSql) {
 return delegate.createCacheKey(ms, parameterObject, rowBounds, boundSql);
}

代码示例来源:origin: pagehelper/Mybatis-PageHelper

cacheKey = executor.createCacheKey(ms, parameter, rowBounds, boundSql);
} else {

代码示例来源:origin: ldlqdsdcn/eidea4

@Override
public CacheKey createCacheKey(MappedStatement ms, Object parameterObject,
                RowBounds rowBounds, BoundSql boundSql) {
  return executor.createCacheKey(ms, parameterObject, rowBounds, boundSql);
}

代码示例来源:origin: camunda/camunda-bpm-platform

private Object getNestedQueryConstructorValue(ResultSet rs, ResultMapping constructorMapping, String columnPrefix) throws SQLException {
 final String nestedQueryId = constructorMapping.getNestedQueryId();
 final MappedStatement nestedQuery = configuration.getMappedStatement(nestedQueryId);
 final Class<?> nestedQueryParameterType = nestedQuery.getParameterMap().getType();
 final Object nestedQueryParameterObject = prepareParameterForNestedQuery(rs, constructorMapping, nestedQueryParameterType, columnPrefix);
 Object value = null;
 if (nestedQueryParameterObject != null) {
  final BoundSql nestedBoundSql = nestedQuery.getBoundSql(nestedQueryParameterObject);
  final CacheKey key = executor.createCacheKey(nestedQuery, nestedQueryParameterObject, RowBounds.DEFAULT, nestedBoundSql);
  final Class<?> targetType = constructorMapping.getJavaType();
  final ResultLoader resultLoader = new ResultLoader(configuration, executor, nestedQuery, nestedQueryParameterObject, targetType, key, nestedBoundSql);
  value = resultLoader.loadResult();
 }
 return value;
}

代码示例来源:origin: org.mybatis/mybatis

private Object getNestedQueryConstructorValue(ResultSet rs, ResultMapping constructorMapping, String columnPrefix) throws SQLException {
 final String nestedQueryId = constructorMapping.getNestedQueryId();
 final MappedStatement nestedQuery = configuration.getMappedStatement(nestedQueryId);
 final Class<?> nestedQueryParameterType = nestedQuery.getParameterMap().getType();
 final Object nestedQueryParameterObject = prepareParameterForNestedQuery(rs, constructorMapping, nestedQueryParameterType, columnPrefix);
 Object value = null;
 if (nestedQueryParameterObject != null) {
  final BoundSql nestedBoundSql = nestedQuery.getBoundSql(nestedQueryParameterObject);
  final CacheKey key = executor.createCacheKey(nestedQuery, nestedQueryParameterObject, RowBounds.DEFAULT, nestedBoundSql);
  final Class<?> targetType = constructorMapping.getJavaType();
  final ResultLoader resultLoader = new ResultLoader(configuration, executor, nestedQuery, nestedQueryParameterObject, targetType, key, nestedBoundSql);
  value = resultLoader.loadResult();
 }
 return value;
}

代码示例来源:origin: org.apache.ibatis/ibatis-core

public CacheKey createCacheKey(MappedStatement ms, Object parameterObject, RowBounds rowBounds) {
 return delegate.createCacheKey(ms, parameterObject, rowBounds);
}

代码示例来源:origin: mybatis-book/book

CacheKey countKey = executor.createCacheKey(
    countMs, 
    parameterObject, 
CacheKey pageKey = executor.createCacheKey(
    ms, 
    parameterObject,

代码示例来源:origin: camunda/camunda-bpm-platform

private Object getNestedQueryMappingValue(ResultSet rs, MetaObject metaResultObject, ResultMapping propertyMapping, ResultLoaderMap lazyLoader, String columnPrefix)
  throws SQLException {
 final String nestedQueryId = propertyMapping.getNestedQueryId();
 final String property = propertyMapping.getProperty();
 final MappedStatement nestedQuery = configuration.getMappedStatement(nestedQueryId);
 final Class<?> nestedQueryParameterType = nestedQuery.getParameterMap().getType();
 final Object nestedQueryParameterObject = prepareParameterForNestedQuery(rs, propertyMapping, nestedQueryParameterType, columnPrefix);
 Object value = null;
 if (nestedQueryParameterObject != null) {
  final BoundSql nestedBoundSql = nestedQuery.getBoundSql(nestedQueryParameterObject);
  final CacheKey key = executor.createCacheKey(nestedQuery, nestedQueryParameterObject, RowBounds.DEFAULT, nestedBoundSql);
  final Class<?> targetType = propertyMapping.getJavaType();
  if (executor.isCached(nestedQuery, key)) {
   executor.deferLoad(nestedQuery, metaResultObject, property, key, targetType);
   value = DEFERED;
  } else {
   final ResultLoader resultLoader = new ResultLoader(configuration, executor, nestedQuery, nestedQueryParameterObject, targetType, key, nestedBoundSql);
   if (propertyMapping.isLazy()) {
    lazyLoader.addLoader(property, metaResultObject, resultLoader);
    value = DEFERED;
   } else {
    value = resultLoader.loadResult();
   }
  }
 }
 return value;
}

代码示例来源:origin: org.mybatis/mybatis

private Object getNestedQueryMappingValue(ResultSet rs, MetaObject metaResultObject, ResultMapping propertyMapping, ResultLoaderMap lazyLoader, String columnPrefix)
  throws SQLException {
 final String nestedQueryId = propertyMapping.getNestedQueryId();
 final String property = propertyMapping.getProperty();
 final MappedStatement nestedQuery = configuration.getMappedStatement(nestedQueryId);
 final Class<?> nestedQueryParameterType = nestedQuery.getParameterMap().getType();
 final Object nestedQueryParameterObject = prepareParameterForNestedQuery(rs, propertyMapping, nestedQueryParameterType, columnPrefix);
 Object value = null;
 if (nestedQueryParameterObject != null) {
  final BoundSql nestedBoundSql = nestedQuery.getBoundSql(nestedQueryParameterObject);
  final CacheKey key = executor.createCacheKey(nestedQuery, nestedQueryParameterObject, RowBounds.DEFAULT, nestedBoundSql);
  final Class<?> targetType = propertyMapping.getJavaType();
  if (executor.isCached(nestedQuery, key)) {
   executor.deferLoad(nestedQuery, metaResultObject, property, key, targetType);
   value = DEFERRED;
  } else {
   final ResultLoader resultLoader = new ResultLoader(configuration, executor, nestedQuery, nestedQueryParameterObject, targetType, key, nestedBoundSql);
   if (propertyMapping.isLazy()) {
    lazyLoader.addLoader(property, metaResultObject, resultLoader);
    value = DEFERRED;
   } else {
    value = resultLoader.loadResult();
   }
  }
 }
 return value;
}

代码示例来源:origin: com.github.pagehelper/pagehelper

/**
 * 执行手动设置的 count 查询,该查询支持的参数必须和被分页的方法相同
 *
 * @param executor
 * @param countMs
 * @param parameter
 * @param boundSql
 * @param resultHandler
 * @return
 * @throws SQLException
 */
public static Long executeManualCount(Executor executor, MappedStatement countMs,
                   Object parameter, BoundSql boundSql,
                   ResultHandler resultHandler) throws SQLException {
  CacheKey countKey = executor.createCacheKey(countMs, parameter, RowBounds.DEFAULT, boundSql);
  BoundSql countBoundSql = countMs.getBoundSql(parameter);
  Object countResultList = executor.query(countMs, parameter, RowBounds.DEFAULT, resultHandler, countKey, countBoundSql);
  Long count = ((Number) ((List) countResultList).get(0)).longValue();
  return count;
}

代码示例来源:origin: vakinge/jeesuite-libs

@SuppressWarnings("rawtypes")
private List executeQuery(Executor executor, MappedStatement ms,
    Object parameter, BoundSql boundSql,
    RowBounds rowBounds, ResultHandler resultHandler,PageParams pageParams) throws IllegalAccessException, SQLException {
  CacheKey countKey = executor.createCacheKey(ms, parameter, RowBounds.DEFAULT, boundSql);
  
  String orignSql = StringUtils.replace(boundSql.getSql(), ";$", StringUtils.EMPTY);
  
  String pageSql = PageSqlUtils.getLimitSQL(dbType,orignSql,pageParams);
  
  BoundSql countBoundSql = new BoundSql(ms.getConfiguration(), pageSql, boundSql.getParameterMappings(),
      parameter);
  
  List<?> resultList = executor.query(ms, parameter, RowBounds.DEFAULT, resultHandler, countKey,
      countBoundSql);
  return resultList;
}

代码示例来源:origin: com.github.tianjing/tgtools.web.develop

private Object query(Executor executor, MappedStatement ms , Object parameterObject, RowBounds rowBounds) throws Exception {
  BoundSql boundSql = ms.getBoundSql(parameterObject);
  //生成新的分页sql
  String sql =StringUtil.replace(Constants.SQLs.Page_GetPageData_SQL,"${sql}",boundSql.getSql());
  sql=StringUtil.replace(sql,"{currParge}",String.valueOf(rowBounds.getOffset()+1));
  sql=StringUtil.replace(sql,"{pargeSize}",String.valueOf(rowBounds.getLimit()));
  //将分页sql替换到 boundSql的sql,BoundSql无法直接new 因为有些成员无法获取 如 additionalParameters
  Field field= tgtools.util.ReflectionUtil.findField(BoundSql.class,"sql");
  field.setAccessible(true);
  field.set(boundSql,sql);
  CacheKey key = executor.createCacheKey(ms, parameterObject, rowBounds, boundSql);
  return executor.query(ms, parameterObject, rowBounds, null, key, boundSql);
}
@Override

代码示例来源:origin: vakinge/jeesuite-libs

@SuppressWarnings("rawtypes")
  private Long executeQueryCount(Executor executor, MappedStatement countMs,
      Object parameter, BoundSql boundSql,
      RowBounds rowBounds, ResultHandler resultHandler) throws IllegalAccessException, SQLException {
    CacheKey countKey = executor.createCacheKey(countMs, parameter, RowBounds.DEFAULT, boundSql);
    
    String orignSql = StringUtils.replace(boundSql.getSql(), ";$", StringUtils.EMPTY);
    // count sql
    String countSql = PageSqlUtils.getCountSql(orignSql);
    
    BoundSql countBoundSql = new BoundSql(countMs.getConfiguration(), countSql, boundSql.getParameterMappings(),
        parameter);
//        for (ParameterMapping parameterMapping : boundSql.getParameterMappings()) {
//            String propertyName = parameterMapping.getProperty();
//            if(boundSql.hasAdditionalParameter(propertyName)){
//                countBoundSql.setAdditionalParameter(propertyName, boundSql.getAdditionalParameter(propertyName));
//            }
//        }
    // 执行 count 查询
    Object countResultList = executor.query(countMs, parameter, RowBounds.DEFAULT, resultHandler, countKey,
        countBoundSql);
    Long count = (Long) ((List) countResultList).get(0);
    return count;
  }

代码示例来源:origin: org.apache.ibatis/ibatis-core

protected Object getNestedQueryMappingValue(ResultSet rs, MetaObject metaResultObject, ResultMapping propertyMapping, ResultLoaderMap lazyLoader) throws SQLException {
 final String nestedQueryId = propertyMapping.getNestedQueryId();
 final String property = propertyMapping.getProperty();
 final MappedStatement nestedQuery = configuration.getMappedStatement(nestedQueryId);
 final Class nestedQueryParameterType = nestedQuery.getParameterMap().getType();
 final Object nestedQueryParameterObject = prepareParameterForNestedQuery(rs, propertyMapping, nestedQueryParameterType);
 Object value = null;
 if (nestedQueryParameterObject != null) {
  final CacheKey key = executor.createCacheKey(nestedQuery, nestedQueryParameterObject, RowBounds.DEFAULT);
  if (executor.isCached(nestedQuery, key)) {
   executor.deferLoad(nestedQuery, metaResultObject, property, key);
  } else {
   final ResultLoader resultLoader = new ResultLoader(configuration, executor, nestedQuery, nestedQueryParameterObject, propertyMapping.getJavaType());
   if (configuration.isLazyLoadingEnabled()) {
    lazyLoader.addLoader(property, metaResultObject, resultLoader);
   } else {
    value = resultLoader.loadResult();
   }
  }
 }
 return value;
}

代码示例来源:origin: miemiedev/mybatis-paginator

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);
  }
};

代码示例来源:origin: com.github.miemiedev/mybatis-paginator

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);
  }
};

相关文章