Example usage for org.apache.ibatis.plugin Invocation proceed

List of usage examples for org.apache.ibatis.plugin Invocation proceed

Introduction

In this page you can find the example usage for org.apache.ibatis.plugin Invocation proceed.

Prototype

public Object proceed() throws InvocationTargetException, IllegalAccessException 

Source Link

Usage

From source file:cn.com.bricks.mybatis.rbac.DynamicObscureInterceptor.java

@Override
public Object intercept(Invocation invocation) throws Throwable {
    //        ResultSetHandler resultSetHandler = (ResultSetHandler) invocation.getTarget();
    Object obj = invocation.proceed();
    if (obj != null) {
        ObscureCache obscureCache = ClientObscureFilterService.getObscureData();
        Map<String, Obscure> obsurecfg = obscureCache
                .getObscureConfigs(ClientRoleService.getCurrentUserRoles());
        // ???/* ww  w  . j  a  v  a2  s  .c o  m*/
        if (obsurecfg != null && !obsurecfg.isEmpty()) {
            // List
            if (obj instanceof List) {
                List results = (List) obj;
                for (Object ret : results) {
                    // TODO ?????
                    // ?
                    if (ret != null) {
                        // ????? ?
                        for (Map.Entry<String, Obscure> entry : obsurecfg.entrySet()) {
                            setObscureValue(ret, entry.getValue());
                        }
                    }
                }
            }
        }
    }
    return obj;
}

From source file:cn.com.bricks.mybatis.rbac.DynamicRbacInterceptor.java

@Override
public Object intercept(Invocation invocation) throws Throwable {
    StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
    MetaObject metaStatementHandler = MetaObject.forObject(statementHandler, DEFAULT_OBJECT_FACTORY,
            DEFAULT_OBJECT_WRAPPER_FACTORY, DEFAULT_REFLECTOR_FACTORY);
    MappedStatement mappedStatement = (MappedStatement) metaStatementHandler
            .getValue("delegate.mappedStatement");

    // ?sql//from  www.j  a v  a 2 s.  c o m
    BoundSql bsql = statementHandler.getBoundSql();
    // ?sql
    TextSqlNode sqlNode = new TextSqlNode(bsql.getSql());
    BoundSql nbsql = getBoundSql(mappedStatement.getConfiguration(), bsql.getParameterObject(), sqlNode);
    // ?sql?
    metaStatementHandler.setValue("delegate.boundSql.sql", nbsql.getSql());
    return invocation.proceed();
}

From source file:cn.myblog.uitl.MybatisPageHelper.PageHelper.java

License:Open Source License

@Override
public Object intercept(Invocation invocation) throws Throwable {
    final Object[] args = invocation.getArgs();
    RowBounds rowBounds = (RowBounds) args[2];
    if (localPage.get() == null && rowBounds == RowBounds.DEFAULT) {
        return invocation.proceed();
    } else {/*from   ww  w .  j av a 2s .c  o m*/
        //RowBounds-?Mybatis
        args[2] = RowBounds.DEFAULT;
        MappedStatement ms = (MappedStatement) args[0];
        Object parameterObject = args[1];
        BoundSql boundSql = ms.getBoundSql(parameterObject);

        //?
        Page page = localPage.get();
        //??
        localPage.remove();

        if (page == null) {
            if (offsetAsPageNum) {
                page = new Page(rowBounds.getOffset(), rowBounds.getLimit(),
                        rowBoundsWithCount ? Page.SQL_COUNT : Page.NO_SQL_COUNT);
            } else {
                page = new Page(rowBounds, rowBoundsWithCount ? Page.SQL_COUNT : Page.NO_SQL_COUNT);
            }
        }
        MappedStatement qs = newMappedStatement(ms, new BoundSqlSqlSource(boundSql));
        //?MappedStatement?qs?
        args[0] = qs;
        MetaObject msObject = SystemMetaObject.forObject(qs);
        String sql = (String) msObject.getValue("sqlSource.boundSql.sql");
        //?total??count
        if (page.getTotal() > Page.NO_SQL_COUNT) {
            //count - ?sql
            msObject.setValue("sqlSource.boundSql.sql", getCountSql(sql));
            //
            Object result = invocation.proceed();
            int totalCount = (Integer) ((List) result).get(0);
            page.setTotal(totalCount);
            int totalPage = totalCount / page.getPageSize() + ((totalCount % page.getPageSize() == 0) ? 0 : 1);
            page.setPages(totalPage);
            //sql - ?sql
            msObject.setValue("sqlSource.boundSql.sql", getPageSql(sql, page));
            //??
            msObject.setValue("resultMaps", ms.getResultMaps());
            //
            result = invocation.proceed();
            //?
            page.addAll((List) result);
            //
            return page;
        } else {
            //sql - ?sql
            msObject.setValue("sqlSource.boundSql.sql", getPageSql(sql, page));
            //??
            msObject.setValue("resultMaps", ms.getResultMaps());
            //
            Object result = invocation.proceed();
            //?
            page.addAll((List) result);
            //
            return page;
        }
    }
}

From source file:cn.org.awcp.core.mybatis.mapper.MapperInterceptor.java

License:Open Source License

@Override
public Object intercept(Invocation invocation) throws Throwable {
    Object[] objects = invocation.getArgs();
    MappedStatement ms = (MappedStatement) objects[0];
    String msId = ms.getId();//from w w w  .  j  av  a2  s.  co m
    //??
    if (mapperHelper.isMapperMethod(msId)) {
        //????ProviderSqlSource??????
        if (ms.getSqlSource() instanceof ProviderSqlSource) {
            mapperHelper.setSqlSource(ms);
        }
    }
    Object result = invocation.proceed();
    return result;
}

From source file:cn.org.awcp.core.mybatis.page.PageHelper.java

License:Open Source License

/**
 * Mybatis/*w w w . j  av a  2 s.  co  m*/
 *
 * @param invocation ?
 * @return 
 * @throws Throwable 
 */
public Object intercept(Invocation invocation) throws Throwable {
    final Object[] args = invocation.getArgs();
    RowBounds rowBounds = (RowBounds) args[2];
    if (LOCAL_PAGE.get() == null && rowBounds == RowBounds.DEFAULT) {
        return invocation.proceed();
    } else {
        //RowBounds-?Mybatis
        args[2] = RowBounds.DEFAULT;
        MappedStatement ms = (MappedStatement) args[0];
        Object parameterObject = args[1];
        //?
        Page page = getPage(rowBounds);
        //pageSizeZero
        if (pageSizeZero && page.getPageSize() == 0) {
            //?
            Object result = invocation.proceed();
            //?
            page.addAll((List) result);
            //
            page.setPageNum(1);
            //?pageSize=total
            page.setPageSize(page.size());
            //??total
            page.setTotal(page.size());
            //?Page - ???
            return page;
        }
        //?total??count
        if (page.isCount()) {
            BoundSql boundSql = null;
            //???sql??boundSql
            if (!SQLUTIL.isDynamic(ms)) {
                boundSql = ms.getBoundSql(parameterObject);
            }
            //?MappedStatement?qs
            args[0] = SQLUTIL.getCountMappedStatement(ms, boundSql);
            //
            Object result = invocation.proceed();
            //
            page.setTotal((Integer) ((List) result).get(0));
            if (page.getTotal() == 0) {
                return page;
            }
        }
        //pageSize>0pageSize<=0???count
        if (page.getPageSize() > 0 && ((rowBounds == RowBounds.DEFAULT && page.getPageNum() > 0)
                || rowBounds != RowBounds.DEFAULT)) {
            BoundSql boundSql = null;
            //???sql??boundSql
            if (!SQLUTIL.isDynamic(ms)) {
                boundSql = ms.getBoundSql(parameterObject);
            }
            //?MappedStatement?qs
            args[0] = SQLUTIL.getPageMappedStatement(ms, boundSql);
            //?sqlboundSqlms?
            if (boundSql == null) {
                boundSql = ((MappedStatement) args[0]).getBoundSql(parameterObject);
            }
            //parameterObject?
            args[1] = SQLUTIL.setPageParameter(ms, parameterObject, boundSql, page);
            //
            Object result = invocation.proceed();
            //?
            page.addAll((List) result);
        }
        //
        return page;
    }
}

From source file:com.appleframework.orm.mybatis.pagehelper.SqlUtil.java

License:Open Source License

/**
 * Mybatis/*from   ww w  .  j  a v  a 2  s. c  o  m*/
 *
 * @param invocation ?
 * @return 
 * @throws Throwable 
 */
private Object _processPage(Invocation invocation) throws Throwable {
    final Object[] args = invocation.getArgs();
    Page page = null;
    //????Page
    if (supportMethodsArguments) {
        page = getPage(args);
    }
    //?
    RowBounds rowBounds = (RowBounds) args[2];
    //??page == null???
    if ((supportMethodsArguments && page == null)
            //???LocalPageRowBounds??
            || (!supportMethodsArguments && SqlUtil.getLocalPage() == null && rowBounds == RowBounds.DEFAULT)) {
        return invocation.proceed();
    } else {
        //???page==null??
        if (!supportMethodsArguments && page == null) {
            page = getPage(args);
        }
        return doProcessPage(invocation, page, args);
    }
}

From source file:com.appleframework.orm.mybatis.pagehelper.SqlUtil.java

License:Open Source License

/**
 * ??//  w ww . ja va2s . co m
 *
 * @param page
 * @param invocation
 * @return
 * @throws Throwable
 */
private Page doQueryOnly(Page page, Invocation invocation) throws Throwable {
    page.setCountSignal(null);
    //?
    Object result = invocation.proceed();
    //?
    page.addAll((List) result);
    //
    page.setPageNum(1);
    //?pageSize=total
    page.setPageSize(page.size());
    //??total
    page.setTotal(page.size());
    //?Page - ???
    return page;
}

From source file:com.appleframework.orm.mybatis.pagehelper.SqlUtil.java

License:Open Source License

/**
 * Mybatis//from   w  w  w.jav a  2  s . co  m
 *
 * @param invocation ?
 * @return 
 * @throws Throwable 
 */
private Page doProcessPage(Invocation invocation, Page page, Object[] args) throws Throwable {
    //?RowBounds?
    RowBounds rowBounds = (RowBounds) args[2];
    //?ms
    MappedStatement ms = (MappedStatement) args[0];
    //?PageSqlSource
    if (!isPageSqlSource(ms)) {
        processMappedStatement(ms);
    }
    //?parser????setThreadLocal???
    ((PageSqlSource) ms.getSqlSource()).setParser(parser);
    try {
        //RowBounds-?Mybatis
        args[2] = RowBounds.DEFAULT;
        //??  pageSizeZero
        if (isQueryOnly(page)) {
            return doQueryOnly(page, invocation);
        }

        //?total??count
        if (page.isCount()) {
            page.setCountSignal(Boolean.TRUE);
            //?MS
            args[0] = msCountMap.get(ms.getId());
            //
            Object result = invocation.proceed();
            //ms
            args[0] = ms;
            //
            page.setTotal((Integer) ((List) result).get(0));
            if (page.getTotal() == 0) {
                return page;
            }
        } else {
            page.setTotal(-1l);
        }
        //pageSize>0pageSize<=0???count
        if (page.getPageSize() > 0 && ((rowBounds == RowBounds.DEFAULT && page.getPageNum() > 0)
                || rowBounds != RowBounds.DEFAULT)) {
            //?MappedStatement?qs
            page.setCountSignal(null);
            BoundSql boundSql = ms.getBoundSql(args[1]);
            args[1] = parser.setPageParameter(ms, args[1], boundSql, page);
            page.setCountSignal(Boolean.FALSE);
            //
            Object result = invocation.proceed();
            //?
            page.addAll((List) result);
        }
    } finally {
        ((PageSqlSource) ms.getSqlSource()).removeParser();
    }

    //
    return page;
}

From source file:com.autonavi.tsp.workbackend.util.page.PageHelper.java

License:Open Source License

/**
 * Mybatis/*ww  w  .j a v a 2s  . c  o m*/
 *
 * @param invocation ?
 * @return 
 * @throws Throwable 
 */
public Object intercept(Invocation invocation) throws Throwable {
    final Object[] args = invocation.getArgs();
    RowBounds rowBounds = (RowBounds) args[2];
    if (LOCAL_PAGE.get() == null && rowBounds == RowBounds.DEFAULT) {
        return invocation.proceed();
    } else {
        //?ms
        MappedStatement ms = (MappedStatement) args[0];
        //RowBounds-?Mybatis
        args[2] = RowBounds.DEFAULT;
        //?
        Page page = getPage(rowBounds);
        //pageSizeZero
        if ((page.getPageSizeZero() != null && page.getPageSizeZero()) && page.getPageSize() == 0) {
            //?
            Object result = invocation.proceed();
            //?
            page.addAll((List) result);
            //
            page.setPageNum(1);
            //?pageSize=total
            page.setPageSize(page.size());
            //??total
            page.setTotal(page.size());
            //?Page - ???
            return page;
        }
        SqlSource sqlSource = ((MappedStatement) args[0]).getSqlSource();
        //?total??count
        if (page.isCount()) {
            //?MappedStatement?qs
            SQLUTIL.processCountMappedStatement(ms, sqlSource, args);
            //
            Object result = invocation.proceed();
            //
            page.setTotal((Integer) ((List) result).get(0));
            if (page.getTotal() == 0) {
                return page;
            }
        }
        //pageSize>0pageSize<=0???count
        if (page.getPageSize() > 0 && ((rowBounds == RowBounds.DEFAULT && page.getPageNum() > 0)
                || rowBounds != RowBounds.DEFAULT)) {
            //?MappedStatement?qs
            SQLUTIL.processPageMappedStatement(ms, sqlSource, page, args);
            //
            Object result = invocation.proceed();
            //?
            page.addAll((List) result);
        }
        //
        return page;
    }
}

From source file:com.badminton.interceptors.mySqlHelper.pagehelper.util.SqlUtil.java

License:Open Source License

/**
 * /*w  w  w . j a v  a 2 s  .  c o  m*/
 *
 * @param invocation
 * @return
 * @throws Throwable
 */
public Object doIntercept(Invocation invocation) throws Throwable {
    //??
    Object[] args = invocation.getArgs();
    MappedStatement ms = (MappedStatement) args[0];
    Object parameterObject = args[1];
    RowBounds rowBounds = (RowBounds) args[2];
    List resultList;
    if (autoDialect) {
        lock.lock();
        try {
            if (autoDialect) {
                autoDialect = false;
                this.dialect = getDialect(ms);
            }
        } finally {
            lock.unlock();
        }
    }
    Dialect runtimeDialect = dialect;
    if (autoRuntimeDialect) {
        runtimeDialect = getDialect(ms);
    }
    //????
    if (!runtimeDialect.skip(ms, parameterObject, rowBounds)) {
        ResultHandler resultHandler = (ResultHandler) args[3];
        //?
        Executor executor = (Executor) invocation.getTarget();
        BoundSql boundSql = ms.getBoundSql(parameterObject);
        //?????
        Map<String, Object> additionalParameters = (Map<String, Object>) additionalParametersField
                .get(boundSql);
        //?? count 
        if (runtimeDialect.beforeCount(ms, parameterObject, rowBounds)) {
            // count  key
            CacheKey countKey = executor.createCacheKey(ms, parameterObject, RowBounds.DEFAULT, boundSql);
            countKey.update("_Count");
            MappedStatement countMs = msCountMap.get(countKey);
            if (countMs == null) {
                //?? ms  Long  ms
                countMs = MSUtils.newCountMappedStatement(ms);
                msCountMap.put(countKey, countMs);
            }
            //? count sql
            String countSql = runtimeDialect.getCountSql(ms, boundSql, parameterObject, rowBounds, countKey);
            BoundSql countBoundSql = new BoundSql(ms.getConfiguration(), countSql,
                    boundSql.getParameterMappings(), parameterObject);
            //? SQL ???? BoundSql 
            for (String key : additionalParameters.keySet()) {
                countBoundSql.setAdditionalParameter(key, additionalParameters.get(key));
            }
            // count 
            Object countResultList = executor.query(countMs, parameterObject, RowBounds.DEFAULT, resultHandler,
                    countKey, countBoundSql);
            Long count = (Long) ((List) countResultList).get(0);
            //?
            runtimeDialect.afterCount(count, parameterObject, rowBounds);
            if (count == 0L) {
                // 0 
                return runtimeDialect.afterPage(new ArrayList(), parameterObject, rowBounds);
            }
        }
        //??
        if (runtimeDialect.beforePage(ms, parameterObject, rowBounds)) {
            //? key
            CacheKey pageKey = executor.createCacheKey(ms, parameterObject, rowBounds, boundSql);
            //??
            parameterObject = runtimeDialect.processParameterObject(ms, parameterObject, boundSql, pageKey);
            //? sql
            String pageSql = runtimeDialect.getPageSql(ms, boundSql, parameterObject, rowBounds, pageKey);
            BoundSql pageBoundSql = new BoundSql(ms.getConfiguration(), pageSql,
                    boundSql.getParameterMappings(), parameterObject);
            //??
            for (String key : additionalParameters.keySet()) {
                pageBoundSql.setAdditionalParameter(key, additionalParameters.get(key));
            }
            //
            resultList = executor.query(ms, parameterObject, RowBounds.DEFAULT, resultHandler, pageKey,
                    pageBoundSql);
        } else {
            resultList = new ArrayList();
        }
    } else {
        args[2] = RowBounds.DEFAULT;
        resultList = (List) invocation.proceed();
    }
    //
    return runtimeDialect.afterPage(resultList, parameterObject, rowBounds);
}