当前位置: 首页>>代码示例>>Java>>正文


Java Executor.query方法代码示例

本文整理汇总了Java中org.apache.ibatis.executor.Executor.query方法的典型用法代码示例。如果您正苦于以下问题:Java Executor.query方法的具体用法?Java Executor.query怎么用?Java Executor.query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.ibatis.executor.Executor的用法示例。


在下文中一共展示了Executor.query方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: executeQueryCount

import org.apache.ibatis.executor.Executor; //导入方法依赖的package包/类
@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 = boundSql.getSql().replaceAll(";$", "");
    // count sql
    String countSql = PageSqlUtils.getCountSql(orignSql);

    BoundSql countBoundSql = new BoundSql(countMs.getConfiguration(), countSql,
            boundSql.getParameterMappings(), parameter);
    // 执行 count 查询
    Object countResultList = executor.query(countMs, parameter, RowBounds.DEFAULT,
            resultHandler, countKey, countBoundSql);
    Long count = (Long) ((List) countResultList).get(0);
    return count;
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:21,代码来源:PaginationHandler.java

示例2: executeQueryCount

import org.apache.ibatis.executor.Executor; //导入方法依赖的package包/类
@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 = boundSql.getSql().replaceAll(";$", "");
	// count sql
	String countSql = PageSqlUtils.getCountSql(orignSql);
	
	BoundSql countBoundSql = new BoundSql(countMs.getConfiguration(), countSql, boundSql.getParameterMappings(),
			parameter);
	// 执行 count 查询
	Object countResultList = executor.query(countMs, parameter, RowBounds.DEFAULT, resultHandler, countKey,
			countBoundSql);
	Long count = (Long) ((List) countResultList).get(0);
	return count;
}
 
开发者ID:vakinge,项目名称:jeesuite-libs,代码行数:19,代码来源:PaginationHandler.java

示例3: intercept

import org.apache.ibatis.executor.Executor; //导入方法依赖的package包/类
@Override
public Object intercept(Invocation invocation) throws Throwable {
       List<Sort> sortList = getSortList();
       if (sortList == null || sortList.size() == 0) {
           return invocation.proceed();
       }

       Executor executor = (Executor) invocation.getTarget();
       Object[] args = invocation.getArgs();
       MappedStatement ms = (MappedStatement) args[0];
       Object parameter = args[1];
       RowBounds rowBounds = (RowBounds) args[2];
       ResultHandler resultHandler = (ResultHandler) args[3];

       // 计算修改BoundSql
       BoundSql boundSql = ms.getBoundSql(parameter);
       MetaObject boundSqlHandler = MetaObject.forObject(boundSql, new DefaultObjectFactory(), new DefaultObjectWrapperFactory());
       Dialect dialect = DialectParser.parse(ms.getConfiguration());
       String sql = (String) boundSqlHandler.getValue("sql");
       sql = dialect.addSortString(sql, sortList);
       boundSqlHandler.setValue("sql", sql);

       // 继续执行原来的代码
       CacheKey key = executor.createCacheKey(ms, parameter, rowBounds, boundSql);
       return executor.query(ms, parameter, rowBounds, resultHandler, key, boundSql);
}
 
开发者ID:chanedi,项目名称:QuickProject,代码行数:27,代码来源:SortListInterceptor.java

示例4: executeAutoCount

import org.apache.ibatis.executor.Executor; //导入方法依赖的package包/类
/**
 * 执行自动生成的 count 查询
 *
 * @param executor
 * @param countMs
 * @param parameter
 * @param boundSql
 * @param rowBounds
 * @param resultHandler
 * @return
 * @throws IllegalAccessException
 * @throws SQLException
 */
private Long executeAutoCount(Executor executor, MappedStatement countMs,
                               Object parameter, BoundSql boundSql,
                               RowBounds rowBounds, ResultHandler resultHandler) throws IllegalAccessException, SQLException {
    Map<String, Object> additionalParameters = (Map<String, Object>) additionalParametersField.get(boundSql);
    //创建 count 查询的缓存 key
    CacheKey countKey = executor.createCacheKey(countMs, parameter, RowBounds.DEFAULT, boundSql);
    //调用方言获取 count sql
    String countSql = dialect.getCountSql(countMs, boundSql, parameter, rowBounds, countKey);
    //countKey.update(countSql);
    BoundSql countBoundSql = new BoundSql(countMs.getConfiguration(), countSql, boundSql.getParameterMappings(), parameter);
    //当使用动态 SQL 时,可能会产生临时的参数,这些参数需要手动设置到新的 BoundSql 中
    for (String key : additionalParameters.keySet()) {
        countBoundSql.setAdditionalParameter(key, additionalParameters.get(key));
    }
    //执行 count 查询
    Object countResultList = executor.query(countMs, parameter, RowBounds.DEFAULT, resultHandler, countKey, countBoundSql);
    Long count = (Long) ((List) countResultList).get(0);
    return count;
}
 
开发者ID:pagehelper,项目名称:Mybatis-PageHelper,代码行数:33,代码来源:PageInterceptor.java

示例5: selectList

import org.apache.ibatis.executor.Executor; //导入方法依赖的package包/类
private <E> List<E> selectList() throws SQLException {
  Executor localExecutor = executor;
  if (Thread.currentThread().getId() != this.creatorThreadId || localExecutor.isClosed()) {
    localExecutor = newExecutor();
  }
  try {
    return localExecutor.<E> query(mappedStatement, parameterObject, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER, cacheKey, boundSql);
  } finally {
    if (localExecutor != executor) {
      localExecutor.close(false);
    }
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:14,代码来源:ResultLoader.java

示例6: selectList

import org.apache.ibatis.executor.Executor; //导入方法依赖的package包/类
private <E> List<E> selectList() throws SQLException {
  Executor localExecutor = executor;
  //如果executor已经被关闭了,则创建一个新的
  if (Thread.currentThread().getId() != this.creatorThreadId || localExecutor.isClosed()) {
    localExecutor = newExecutor();
  }
  try {
    //又调回Executor.query去了,比较巧妙
    return localExecutor.<E> query(mappedStatement, parameterObject, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER, cacheKey, boundSql);
  } finally {
    if (localExecutor != executor) {
      localExecutor.close(false);
    }
  }
}
 
开发者ID:shurun19851206,项目名称:mybaties,代码行数:16,代码来源:ResultLoader.java

示例7: removeCacheByUpdateConditon

import org.apache.ibatis.executor.Executor; //导入方法依赖的package包/类
/**
 * 按更新的查询条件更新缓存
 * @param executor
 * @param mt
 * @param mapperNameSpace
 * @param args
 */
private void removeCacheByUpdateConditon(Executor executor, MappedStatement mt,
                                         String mapperNameSpace, Object[] args) {
    try {
        Object parameterObject = args[1];
        EntityInfo entityInfo = MybatisMapperParser.getEntityInfoByMapper(mapperNameSpace);
        MappedStatement statement = getQueryIdsMappedStatementForUpdateCache(mt, entityInfo);
        if (statement == null) { return; }

        String querySql = statement.getSqlSource().getBoundSql(parameterObject).getSql();

        List<?> idsResult = null;
        if (PARSE_SQL_ERROR_DEFAULT.equals(querySql)) {
            BoundSql boundSql = mt.getBoundSql(parameterObject);
            querySql = "select " + entityInfo.getIdColumn() + " from "
                    + entityInfo.getTableName() + " WHERE "
                    + boundSql.getSql().split(WHERE_REGEX)[1];
            BoundSql queryBoundSql = new BoundSql(statement.getConfiguration(), querySql,
                    boundSql.getParameterMappings(), parameterObject);

            idsResult = executor.query(statement, parameterObject, RowBounds.DEFAULT,
                    new DefaultResultHandler(), null, queryBoundSql);
        } else {
            idsResult = executor.query(statement, parameterObject, RowBounds.DEFAULT, null);
        }

        if (idsResult != null && !idsResult.isEmpty()) {
            for (Object id : idsResult) {
                String cacheKey = entityInfo.getEntityClass().getSimpleName() + ID_CACHEKEY_JOIN
                        + id.toString();
                getCacheProvider().remove(cacheKey);
            }
            if (logger.isDebugEnabled()) {
                logger.debug(
                        "_autocache_ update Method[{}] executed,remove ralate cache {}.id:[{}]",
                        mt.getId(), entityInfo.getEntityClass().getSimpleName(), idsResult);
            }
        }
    } catch (Exception e) {
        logger.error("_autocache_ update Method[{}] remove ralate cache error", e);
    }
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:49,代码来源:CacheHandler.java

示例8: removeCacheByUpdateConditon

import org.apache.ibatis.executor.Executor; //导入方法依赖的package包/类
/**
 * 按更新的查询条件更新缓存
 * @param executor
 * @param mt
 * @param mapperNameSpace
 * @param args
 */
private void removeCacheByUpdateConditon(Executor executor, MappedStatement mt, String mapperNameSpace,
		Object[] args) {
	try {					
		Object parameterObject = args[1];
		if(parameterObject != null && parameterObject.getClass().getName().equals(TK_MAPPER_EXAMPLE_CLASS_NAME)){
			//清除group下所有缓存
			removeCacheByGroup(mt.getId(), mapperNameSpace,true);
			logger.warn("[tk.mybatis.mapper.entity.Example] Not recommended for use with [@Cache],may be caching cleanup failure",TK_MAPPER_EXAMPLE_CLASS_NAME,mapperNameSpace);
			return;
		}
		EntityInfo entityInfo = MybatisMapperParser.getEntityInfoByMapper(mapperNameSpace);
		MappedStatement statement = getQueryIdsMappedStatementForUpdateCache(mt,entityInfo);
		if(statement == null)return ;
		
		String querySql = statement.getSqlSource().getBoundSql(parameterObject).getSql();
		
		List<?> idsResult = null;
		if(PARSE_SQL_ERROR_DEFAULT.equals(querySql)){
			BoundSql boundSql = mt.getBoundSql(parameterObject);
			querySql = "select "+entityInfo.getIdColumn()+" from "+entityInfo.getTableName()+" WHERE " + boundSql.getSql().split(WHERE_REGEX)[1];
			BoundSql queryBoundSql = new BoundSql(statement.getConfiguration(), querySql, boundSql.getParameterMappings(), parameterObject);
             
			idsResult = executor.query(statement, parameterObject, RowBounds.DEFAULT, new DefaultResultHandler(),null,queryBoundSql);
		}else{
			idsResult = executor.query(statement, parameterObject, RowBounds.DEFAULT, null);
		}
		
		if(idsResult != null && !idsResult.isEmpty()){
			for (Object id : idsResult) {							
				String cacheKey = entityInfo.getEntityClass().getSimpleName() + ID_CACHEKEY_JOIN + id.toString();
				getCacheProvider().remove(cacheKey);
			}
			if(logger.isDebugEnabled())logger.debug("_autocache_ update Method[{}] executed,remove ralate cache {}.id:[{}]",mt.getId(),entityInfo.getEntityClass().getSimpleName(),idsResult);
		}
	} catch (Exception e) {
		//清除group下所有缓存
		removeCacheByGroup(mt.getId(), mapperNameSpace,true);
		logger.error("_autocache_ removecache_by_update [{}] error,force clean all group cache",mt.getId());
	}
}
 
开发者ID:vakinge,项目名称:jeesuite-libs,代码行数:48,代码来源:CacheHandler.java

示例9: executeManualCount

import org.apache.ibatis.executor.Executor; //导入方法依赖的package包/类
/**
 * 执行手动设置的 count 查询,该查询支持的参数必须和被分页的方法相同
 *
 * @param executor
 * @param countMs
 * @param parameter
 * @param boundSql
 * @param resultHandler
 * @return
 * @throws IllegalAccessException
 * @throws SQLException
 */
private Long executeManualCount(Executor executor, MappedStatement countMs,
                               Object parameter, BoundSql boundSql,
                               ResultHandler resultHandler) throws IllegalAccessException, 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;
}
 
开发者ID:pagehelper,项目名称:Mybatis-PageHelper,代码行数:22,代码来源:PageInterceptor.java


注:本文中的org.apache.ibatis.executor.Executor.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。