Java Code Examples for org.apache.ibatis.plugin.Invocation#getTarget()

The following examples show how to use org.apache.ibatis.plugin.Invocation#getTarget() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PaginationInterceptor.java    From joyqueue with Apache License 2.0 6 votes vote down vote up
@Override
public Object intercept(Invocation invocation) throws Throwable {
    StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
    BoundSql boundSql = statementHandler.getBoundSql();
    if (log.isDebugEnabled()) {
        log.debug("raw SQL : " + boundSql.getSql());
    }
    if (boundSql.getSql() == null || boundSql.getSql().isEmpty() || boundSql.getSql().contains(" limit ")) {
        return invocation.proceed();
    }
    MetaObject metaStatementHandler = null;
    RowBounds rowBounds = (RowBounds) metaStatementHandler.getValue("delegate.rowBounds");
    if (rowBounds == null || rowBounds == RowBounds.DEFAULT) {
        return invocation.proceed();
    }
    String originalSql = (String) metaStatementHandler.getValue("delegate.boundSql.sql");
    metaStatementHandler.setValue("delegate.boundSql.sql",
            getLimitString(originalSql, rowBounds.getOffset(), rowBounds.getLimit()));
    metaStatementHandler.setValue("delegate.rowBounds.offset", RowBounds.NO_ROW_OFFSET);
    metaStatementHandler.setValue("delegate.rowBounds.limit", RowBounds.NO_ROW_LIMIT);
    if (log.isDebugEnabled()) {
        log.debug("pagination SQL : " + boundSql.getSql());
    }
    return invocation.proceed();
}
 
Example 2
Source File: PageResultInterceptor.java    From joyqueue with Apache License 2.0 6 votes vote down vote up
@Override
public Object intercept(Invocation invocation) throws Throwable {
    // 目标对象转换
    ResultSetHandler resultSetHandler = (ResultSetHandler) invocation.getTarget();

    // 获取MappedStatement,Configuration对象
    MetaObject metaObject =
            MetaObject.forObject(resultSetHandler, new DefaultObjectFactory(), new DefaultObjectWrapperFactory(), new DefaultReflectorFactory());
    MappedStatement mappedStatement = (MappedStatement) metaObject.getValue("mappedStatement");
    String statement = mappedStatement.getId();
    if (!isPageSql(statement,metaObject.getValue("boundSql.parameterObject"))) {
        return invocation.proceed();
    }

    // 获取分页参数
    QPageQuery pageQuery = (QPageQuery) metaObject.getValue("boundSql.parameterObject");

    List<PageResult> result = new ArrayList<PageResult>(1);
    PageResult page = new PageResult();
    page.setPagination(pageQuery.getPagination());
    page.setResult((List) invocation.proceed());
    result.add(page);

    return result;
}
 
Example 3
Source File: PageInterceptor.java    From dubbo-mock with Apache License 2.0 6 votes vote down vote up
/**
 * 拦截后要执行的方法
 */
@Override
public Object intercept(Invocation invocation) throws Throwable {
    Page<?> page = PageThreadLocal.getThreadLocalPage();
    if (page == null) {
        return invocation.proceed();
    }
    PageThreadLocal.removeThreadLocalPage();
    RoutingStatementHandler handler = (RoutingStatementHandler) invocation.getTarget();
    // 通过反射获取到当前RoutingStatementHandler对象的delegate属性
    StatementHandler delegate = (StatementHandler) ReflectUtil.getFieldValue(handler, "delegate");
    BoundSql boundSql = delegate.getBoundSql();
    MappedStatement mappedStatement = (MappedStatement) ReflectUtil.getFieldValue(delegate, "mappedStatement");
    // 获取当前要执行的Sql语句,也就是我们直接在Mapper映射语句中写的Sql语句
    String sql = boundSql.getSql();
    // 是否查询总页数和总数据 默认为TRUE
    if (page.getTotalFlag()) {
        // 给当前的page参数对象设置总记录数
        this.setTotalRecord(page, mappedStatement, boundSql, sql);
    }

    String pageSql = this.getPageSql(sql, page);
    // 利用反射设置当前BoundSql对应的sql属性为我们建立好的分页Sql语句
    ReflectUtil.setFieldValue(boundSql, "sql", pageSql);
    return invocation.proceed();
}
 
Example 4
Source File: PageInterceptor.java    From ssm-demo with Apache License 2.0 5 votes vote down vote up
/**
 * 拦截后要执行的方法
 */
public Object intercept(Invocation invocation) throws Throwable {
	// 对于StatementHandler其实只有两个实现类,
	// 一个是RoutingStatementHandler,
	// 另一个是抽象类BaseStatementHandler,
	// BaseStatementHandler有三个子类,分别是SimpleStatementHandler,PreparedStatementHandler和CallableStatementHandler,
	// SimpleStatementHandler是用于处理Statement的,
	// PreparedStatementHandler是处理PreparedStatement的,
	// 而CallableStatementHandler是 处理CallableStatement的。
	// Mybatis在进行Sql语句处理的时候都是建立的RoutingStatementHandler,而在RoutingStatementHandler里面拥有一个StatementHandler类型的delegate属性,
	// RoutingStatementHandler会依据Statement的不同建立对应的BaseStatementHandler,
	// 即SimpleStatementHandler、PreparedStatementHandler或CallableStatementHandler,
	// 在RoutingStatementHandler里面所有StatementHandler接口方法的实现都是调用的delegate对应的方法。
	// 我们在PageInterceptor类上已经用@Signature标记了该Interceptor只拦截StatementHandler接口的prepare方法,
	// 又因为Mybatis只有在建立RoutingStatementHandler的时候是通过Interceptor的plugin方法进行包裹的,
	// 所以我们这里拦截到的目标对象肯定是RoutingStatementHandler对象。
	RoutingStatementHandler handler = (RoutingStatementHandler) invocation.getTarget();

	// 通过反射获取到当前RoutingStatementHandler对象的delegate属性
	StatementHandler delegate = (StatementHandler) ReflectUtil.getFieldValue(handler, "delegate");

	// 获取到当前StatementHandler的boundSql,这里不管是调用handler.getBoundSql()还是直接调用delegate.getBoundSql()结果是一样的,因为之前已经说过了
	// RoutingStatementHandler实现的所有StatementHandler接口方法里面都是调用的delegate对应的方法。
	BoundSql boundSql = delegate.getBoundSql();

	// 拿到当前绑定Sql的参数对象,就是我们在调用对应的Mapper映射语句时所传入的参数对象
	Object obj = boundSql.getParameterObject();

	// 这里我们简单的通过传入的是Page对象就认定它是需要进行分页操作的。
	if (obj instanceof Page<?>) {

		Page<?> page = (Page<?>) obj;

		// 通过反射获取delegate父类BaseStatementHandler的mappedStatement属性
		MappedStatement mappedStatement = (MappedStatement) ReflectUtil.getFieldValue(delegate, "mappedStatement");

		// 拦截到的prepare方法参数是一个Connection对象
		Connection connection = (Connection) invocation.getArgs()[0];

		// 获取当前要执行的Sql语句,也就是我们直接在Mapper映射语句中写的Sql语句
		String sql = boundSql.getSql();

		// 给当前的page参数对象设置总记录数
		this.setTotalRecord(page, mappedStatement, connection);

		// 获取分页Sql语句
		String pageSql = this.getPageSql(page, sql);

		// 利用反射设置当前BoundSql对应的sql属性为我们建立好的分页Sql语句
		ReflectUtil.setFieldValue(boundSql, "sql", pageSql);

	}

	return invocation.proceed();
}
 
Example 5
Source File: PreparePaginationInterceptor.java    From Shop-for-JavaWeb with MIT License 5 votes vote down vote up
@Override
    public Object intercept(Invocation ivk) throws Throwable {
        if (ivk.getTarget().getClass().isAssignableFrom(RoutingStatementHandler.class)) {
            final RoutingStatementHandler statementHandler = (RoutingStatementHandler) ivk.getTarget();
            final BaseStatementHandler delegate = (BaseStatementHandler) Reflections.getFieldValue(statementHandler, DELEGATE);
            final MappedStatement mappedStatement = (MappedStatement) Reflections.getFieldValue(delegate, MAPPED_STATEMENT);

//            //拦截需要分页的SQL
////            if (mappedStatement.getId().matches(_SQL_PATTERN)) { 
//            if (StringUtils.indexOfIgnoreCase(mappedStatement.getId(), _SQL_PATTERN) != -1) {
                BoundSql boundSql = delegate.getBoundSql();
                //分页SQL<select>中parameterType属性对应的实体参数,即Mapper接口中执行分页方法的参数,该参数不得为空
                Object parameterObject = boundSql.getParameterObject();
                if (parameterObject == null) {
                    log.error("参数未实例化");
                    throw new NullPointerException("parameterObject尚未实例化!");
                } else {
                    final Connection connection = (Connection) ivk.getArgs()[0];
                    final String sql = boundSql.getSql();
                    //记录统计
                    final int count = SQLHelper.getCount(sql, connection, mappedStatement, parameterObject, boundSql, log);
                    Page<Object> page = null;
                    page = convertParameter(parameterObject, page);
                    page.setCount(count);
                    String pagingSql = SQLHelper.generatePageSql(sql, page, DIALECT);
                    if (log.isDebugEnabled()) {
                        log.debug("PAGE SQL:" + pagingSql);
                    }
                    //将分页sql语句反射回BoundSql.
                    Reflections.setFieldValue(boundSql, "sql", pagingSql);
                }
                
                if (boundSql.getSql() == null || "".equals(boundSql.getSql())){
                    return null;
                }
                
            }
//        }
        return ivk.proceed();
    }
 
Example 6
Source File: PaginationInterceptor.java    From Mario with Apache License 2.0 5 votes vote down vote up
@Override
public Object intercept(Invocation invocation) throws Throwable {

    StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
    BoundSql boundSql = statementHandler.getBoundSql();

    String sql = boundSql.getSql();
    if (StringUtils.isBlank(sql)) {
        return invocation.proceed();
    }

    //select sql do 
    if (sql.matches(SQL_SELECT_REGEX) && !Pattern.matches(SQL_COUNT_REGEX, sql)) {
        Object obj = FieldUtils.readField(statementHandler, "delegate", true);
        // 反射获取 RowBounds 对象。
        RowBounds rowBounds = (RowBounds) FieldUtils.readField(obj, "rowBounds", true);

        // 分页参数存在且不为默认值时进行分页SQL构造
        if (rowBounds != null && rowBounds != RowBounds.DEFAULT) {
            FieldUtils.writeField(boundSql, "sql", newSql(sql, rowBounds), true);

            // 一定要还原否则将无法得到下一组数据(第一次的数据被缓存了)
            FieldUtils.writeField(rowBounds, "offset", RowBounds.NO_ROW_OFFSET, true);
            FieldUtils.writeField(rowBounds, "limit", RowBounds.NO_ROW_LIMIT, true);
        }
    }

    return invocation.proceed();
}
 
Example 7
Source File: QueryLoggingInterceptor.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * {@code StatementHandler}へのクエリ実行要求をインターセプトし、 SQLのロギング機構を起動します。
 * </p>
 */
@Override
public Object intercept(Invocation invocation) throws Throwable {
    QueryInformation queryInformation = new QueryInformation((StatementHandler)invocation.getTarget());
    Object result;
    queryLogger.log(queryInformation);
    result = invocation.proceed();
    return result;
}
 
Example 8
Source File: ExecutorInvocation.java    From sqlhelper with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ExecutorInvocation(Invocation invocation) {
    this.invocation = invocation;
    this.executor = (Executor) invocation.getTarget();
    parse();
}
 
Example 9
Source File: PageStatementInterceptor.java    From joyqueue with Apache License 2.0 4 votes vote down vote up
@Override
public Object intercept(Invocation invocation) throws Throwable {
    StatementHandler handler = (StatementHandler) invocation.getTarget();

    // 获取MappedStatement,Configuration对象
    MetaObject metaObject =
            MetaObject.forObject(handler, new DefaultObjectFactory(), new DefaultObjectWrapperFactory(), new DefaultReflectorFactory());
    MappedStatement mappedStatement = (MappedStatement) metaObject.getValue("delegate.mappedStatement");
    String statement = mappedStatement.getId();
    if (!isPageSql(statement,metaObject.getValue("boundSql.parameterObject"))) {
        return invocation.proceed();
    }

    Configuration configuration = (Configuration) metaObject.getValue("delegate.configuration");
    Executor executor = (Executor) metaObject.getValue("delegate.executor");

    // 获取分页参数
    BoundSql boundSql = handler.getBoundSql();
    QPageQuery pageQuery = (QPageQuery) boundSql.getParameterObject();
    String countStatement = buildCountStatement(statement);
    List<Integer> counts = executor.query(configuration.
            getMappedStatement(countStatement), pageQuery, RowBounds.DEFAULT, null);

    int count = 0;
    if (counts != null && !counts.isEmpty()) {
        count = counts.get(0) == null ? 0 : counts.get(0);
    }

    if (pageQuery.getPagination() == null) {
        pageQuery.setPagination(new Pagination());
    }
    pageQuery.getPagination().setTotalRecord(count);

    String sql = boundSql.getSql();
    if (logger.isDebugEnabled()) {
        logger.debug("raw SQL : " + sql);
    }

    if (sql == null || sql.isEmpty() || sql.contains(" limit ")) {
        return invocation.proceed();
    }

    String originalSql = (String) metaObject.getValue("delegate.boundSql.sql");
    metaObject.setValue("delegate.boundSql.sql",
            getLimitString(originalSql, pageQuery.getPagination().getStart(),
                    pageQuery.getPagination().getSize()));
    metaObject.setValue("delegate.rowBounds.offset", RowBounds.NO_ROW_OFFSET);
    metaObject.setValue("delegate.rowBounds.limit", RowBounds.NO_ROW_LIMIT);

    if (logger.isDebugEnabled()) {
        logger.debug("pagination SQL : " + sql);
    }
    return invocation.proceed();
}
 
Example 10
Source File: ResultTypePlugin.java    From mybatis-jpa with Apache License 2.0 4 votes vote down vote up
@Override
public Object intercept(Invocation invocation) throws Throwable {
  if (invocation.getTarget() instanceof DefaultResultSetHandler) {
    DefaultResultSetHandler resultSetHandler = (DefaultResultSetHandler) invocation.getTarget();

    Object[] args = invocation.getArgs();
    Statement stmt = (Statement) args[0];

    MappedStatement mappedStatement = (MappedStatement) FieldReflectUtil
        .getFieldValue(resultSetHandler, "mappedStatement");

    List<ResultMap> resultMaps = mappedStatement.getResultMaps();

    if (resultMaps != null && !resultMaps.isEmpty()) {
      ResultMap resultMap = resultMaps.get(0);

      if (resultMap.getResultMappings() == null || resultMap.getResultMappings().isEmpty()) {
        if (resultMap.getType().isAnnotationPresent(Entity.class) || resultMap.getType()
            .isAnnotationPresent(Table.class)) {

          ResultMapParser parser = ResultMapParserHolder
              .getInstance(mappedStatement.getConfiguration());
          ResultMap newResultMap = parser
              .reloadResultMap(mappedStatement.getResource(), resultMap.getId(),
                  resultMap.getType());

          List<ResultMap> newResultMaps = new ArrayList<>();
          newResultMaps.add(newResultMap);

          FieldReflectUtil.setFieldValue(mappedStatement, "resultMaps", newResultMaps);

          // modify the resultMaps
          FieldReflectUtil.setFieldValue(resultSetHandler, "mappedStatement", mappedStatement);
        }
      }
    }

    // return resultSetHandler.handleResultSets(stmt);
  }
  return invocation.proceed();
}
 
Example 11
Source File: SQLRouterInterceptor.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public Object intercept(Invocation invocation) throws Throwable {
	Object result = null;

	if (invocation.getTarget() instanceof RoutingStatementHandler) {
		RoutingStatementHandler statementHandler = (RoutingStatementHandler) invocation.getTarget();
		StatementHandler delegate = (StatementHandler) ReflectionUtil.getFieldValue(statementHandler, "delegate");
		BoundSql boundSql = delegate.getBoundSql();

		// 拦截到的prepare方法参数是一个Connection对象
		Connection connection = (Connection) invocation.getArgs()[0];
		String sql = boundSql.getSql();

		// 1、 如果前端有指定路由则,优先采用指定的路由
		if (RouterContext.containsKey(RouterConsts.ROUTER_KEY) && !hasAnnotation(sql)) {
			RouterInfo routerInfo = RouterContext.get(RouterConsts.ROUTER_KEY);
			sql = new StringBuilder(routerInfo.getSqlrouter()).append(sql).toString();

			// 利用反射设置当前BoundSql对应的sql属性为我们建立好的分页Sql语句
			ReflectionUtil.setFieldValue(boundSql, "sql", sql);
		}

		// 2、如果没有路由信息,对只读事物添加读取从库的路由
		if (!hasAnnotation(sql) && connection.isReadOnly()) {

			// 获取当前要执行的Sql语句,也就是我们直接在Mapper映射语句中写的Sql语句
			sql = msHint.genRouteInfo(MasterSlaveHint.SLAVE, sql);

			// 利用反射设置当前BoundSql对应的sql属性为我们建立好的分页Sql语句
			ReflectionUtil.setFieldValue(boundSql, "sql", sql);
		}

		result = invocation.proceed();

		// if (isDML(sql) &&
		// !RouterContext.containsKey(RouterConsts.ROUTER_KEY)) {
		// 如果更改执行的是DML语句,则设置后续的CRUD路由到master
		// String appName = PropertiesUtil.get("app.name");
		// //TODO这里可能需要针对应用来进行主从路由,存在一条链路路由到多个应用的不同DB中
		// RouterContext.put(RouterConsts.ROUTER_KEY,
		// msHint.getRouteMasterHint());
		// }

	} else {
		result = invocation.proceed();
	}

	return result;
}
 
Example 12
Source File: CacheHandler.java    From azeroth with Apache License 2.0 4 votes vote down vote up
@Override
public Object onInterceptor(Invocation invocation) throws Throwable {

    Object[] args = invocation.getArgs();
    MappedStatement mt = (MappedStatement) args[0];

    if (mt.getSqlCommandType().equals(SqlCommandType.SELECT)) {
        //按主键查询
        QueryMethodCache cacheInfo = getQueryMethodCache(mt.getId());
        if (cacheInfo == null) { return null; }
        final String cacheKey = genarateQueryCacheKey(cacheInfo.keyPattern, args[1]);

        Object cacheObject = null;
        boolean nullPlaceholder = false;
        //按主键查询以及标记非引用关系的缓存直接读取缓存
        if (cacheInfo.isSecondQueryById() == false) {
            //从缓存读取
            cacheObject = getCacheProvider().get(cacheKey);
            nullPlaceholder = nullValueCache && NULL_PLACEHOLDER.equals(cacheObject);
            if (nullPlaceholder) {
                logger.debug(
                        "_autocache_ method[{}] find NULL_PLACEHOLDER result from cacheKey:{}",
                        mt.getId(), cacheKey);
            } else if (cacheObject != null) {
                logger.debug("_autocache_ method[{}] find result from cacheKey:{}", mt.getId(),
                        cacheKey);
            }
        } else {
            //新根据缓存KEY找到与按ID缓存的KEY
            String refCacheKey = nullValueCache ? getCacheProvider().get(cacheKey)
                    : getCacheProvider().getStr(cacheKey);
            if (refCacheKey != null) {
                if (nullPlaceholder = (nullValueCache
                        && NULL_PLACEHOLDER.equals(refCacheKey))) {
                    cacheObject = NULL_PLACEHOLDER;
                } else {
                    cacheObject = getCacheProvider().get(refCacheKey);
                    if (cacheObject != null && logger.isDebugEnabled()) {
                        logger.debug(
                                "_autocache_ method[{}] find result from cacheKey:{} ,ref by:{}",
                                mt.getId(), refCacheKey, cacheKey);
                    }
                }
            }
        }

        if (nullPlaceholder) {
            cacheObject = new ArrayList<>();
        } else if (cacheObject != null && !(cacheObject instanceof Collection)) {
            cacheObject = new ArrayList<>(Arrays.asList(cacheObject));
        }

        return cacheObject;
        //非按主键删除的方法需求先行查询出来并删除主键缓存
    } else if (mt.getSqlCommandType().equals(SqlCommandType.DELETE)
            && !updateCacheMethods.containsKey(mt.getId())) {
        String mapperNameSpace = mt.getId().substring(0, mt.getId().lastIndexOf(SPLIT_PONIT));
        Executor executor = (Executor) invocation.getTarget();
        removeCacheByUpdateConditon(executor, mt, mapperNameSpace, args);
    }

    return null;

}
 
Example 13
Source File: OffsetLimitInterceptor.java    From AsuraFramework with Apache License 2.0 4 votes vote down vote up
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();
}
 
Example 14
Source File: PagePlugin.java    From cms with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
	public Object intercept(Invocation invocation) throws Throwable {

		if (invocation.getTarget() instanceof RoutingStatementHandler) {
			RoutingStatementHandler statementHandler = (RoutingStatementHandler) invocation.getTarget();
			BaseStatementHandler delegate = (BaseStatementHandler) ReflectHelper.getValueByFieldName(statementHandler,
					"delegate");
			MappedStatement mappedStatement = (MappedStatement) ReflectHelper.getValueByFieldName(delegate,
					"mappedStatement");

			if (mappedStatement.getId().matches(pageSqlId)) {
				BoundSql boundSql = delegate.getBoundSql();
				Object parameterObject = boundSql.getParameterObject();
				if (parameterObject == null) {
					throw new NullPointerException("parameterObject is null.");
				} else {
					Connection connection = (Connection) invocation.getArgs()[0];
					String sql = boundSql.getSql();
					String countSql="select count(0) from (" + sql + ") tmp_count ";
					/*if ("mysql".equals(dialect)) {
						
					} else if ("oracle".equals(dialect)) {
					}*/
					PreparedStatement countStmt = connection.prepareStatement(countSql);
					BoundSql countBS = new BoundSql(mappedStatement.getConfiguration(), countSql,
							boundSql.getParameterMappings(), parameterObject);
					setParameters(countStmt, mappedStatement, countBS, parameterObject);
					ResultSet rs = countStmt.executeQuery();
					int count = 0;
					if (rs.next()) {
						count = rs.getInt(1);
					}
					rs.close();
					countStmt.close();

					Page page = null;
					if (parameterObject instanceof Page) {
						page = (Page) parameterObject;
						page.setTotalResult(count);
					} else if (parameterObject instanceof Map) {
						Map<String, Object> map = (Map<String, Object>) parameterObject;
						page = (Page) map.get("page");
						if (page == null)
							page = new Page();
						page.setTotalResult(count);
					} else {
						Field pageField = ReflectHelper.getFieldByFieldName(parameterObject, "page");
						if (pageField != null) {
							page = (Page) ReflectHelper.getValueByFieldName(parameterObject, "page");
							if (page == null)
								page = new Page();
							page.setTotalResult(count);
							ReflectHelper.setValueByFieldName(parameterObject, "page", page);
						} else {
							throw new NoSuchFieldException(parameterObject.getClass().getName());
						}
					}
					String pageSql = generatePageSql(sql, page);
					ReflectHelper.setValueByFieldName(boundSql, "sql", pageSql);
				}
			}
		}

//		 Object result = invocation.proceed(); //执行请求方法,并将所得结果保存到result中
//		    if (result instanceof ArrayList) {
//		        ArrayList resultList = (ArrayList) result;
//		        for (int i = 0; i < resultList.size(); i++) {
//		            if (resultList.get(i) instanceof Map) {
//		                Map resultMap = (Map) resultList.get(i);
//		                resultMap.put("CERT_NO", "这个是加密结果"); //取出相应的字段进行加密
//		            }
//		        }
//		    }
		
		return invocation.proceed();
	}