Example usage for org.apache.ibatis.mapping BoundSql setAdditionalParameter

List of usage examples for org.apache.ibatis.mapping BoundSql setAdditionalParameter

Introduction

In this page you can find the example usage for org.apache.ibatis.mapping BoundSql setAdditionalParameter.

Prototype

public void setAdditionalParameter(String name, Object value) 

Source Link

Usage

From source file:com.github.pagehelper.util.ExecutorUtil.java

License:Open Source License

/**
 * /*www.j  ava  2s .c  o  m*/
 *
 * @param dialect
 * @param executor
 * @param ms
 * @param parameter
 * @param rowBounds
 * @param resultHandler
 * @param boundSql
 * @param cacheKey
 * @param <E>
 * @return
 * @throws SQLException
 */
public static <E> List<E> pageQuery(Dialect dialect, Executor executor, MappedStatement ms, Object parameter,
        RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql, CacheKey cacheKey)
        throws SQLException {
    //??
    if (dialect.beforePage(ms, parameter, rowBounds)) {
        //? key
        CacheKey pageKey = cacheKey;
        //??
        parameter = dialect.processParameterObject(ms, parameter, boundSql, pageKey);
        //? sql
        String pageSql = dialect.getPageSql(ms, boundSql, parameter, rowBounds, pageKey);
        BoundSql pageBoundSql = new BoundSql(ms.getConfiguration(), pageSql, boundSql.getParameterMappings(),
                parameter);

        Map<String, Object> additionalParameters = getAdditionalParameter(boundSql);
        //??
        for (String key : additionalParameters.keySet()) {
            pageBoundSql.setAdditionalParameter(key, additionalParameters.get(key));
        }
        //
        return executor.query(ms, parameter, RowBounds.DEFAULT, resultHandler, pageKey, pageBoundSql);
    } else {
        //??
        return executor.query(ms, parameter, RowBounds.DEFAULT, resultHandler, cacheKey, boundSql);
    }
}

From source file:com.icfcc.db.pagehelper.sqlsource.PageDynamicSqlSource.java

License:Open Source License

@Override
protected BoundSql getCountBoundSql(Object parameterObject) {
    DynamicContext context = new DynamicContext(configuration, parameterObject);
    rootSqlNode.apply(context);/*from w  w  w .  ja va  2 s  . c  o  m*/
    SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration);
    Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass();
    SqlSource sqlSource = sqlSourceParser.parse(context.getSql(), parameterType, context.getBindings());
    BoundSql boundSql = sqlSource.getBoundSql(parameterObject);
    sqlSource = new StaticSqlSource(configuration, parser.getCountSql(boundSql.getSql()),
            boundSql.getParameterMappings());
    boundSql = sqlSource.getBoundSql(parameterObject);
    //??
    for (Map.Entry<String, Object> entry : context.getBindings().entrySet()) {
        boundSql.setAdditionalParameter(entry.getKey(), entry.getValue());
    }
    return boundSql;
}

From source file:com.icfcc.db.pagehelper.sqlsource.PageDynamicSqlSource.java

License:Open Source License

@Override
protected BoundSql getPageBoundSql(Object parameterObject) {
    DynamicContext context;//from  www.  jav  a 2s  .  c om
    //??parameterObject???
    //??Map?KEY
    //bug#25:http://git.oschina.net/free/Mybatis_PageHelper/issues/25
    if (parameterObject != null && parameterObject instanceof Map
            && ((Map) parameterObject).containsKey(ORIGINAL_PARAMETER_OBJECT)) {
        context = new DynamicContext(configuration, ((Map) parameterObject).get(ORIGINAL_PARAMETER_OBJECT));
    } else {
        context = new DynamicContext(configuration, parameterObject);
    }
    rootSqlNode.apply(context);
    SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration);
    Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass();
    SqlSource sqlSource = sqlSourceParser.parse(context.getSql(), parameterType, context.getBindings());
    sqlSource = new OrderByStaticSqlSource((StaticSqlSource) sqlSource);
    BoundSql boundSql = sqlSource.getBoundSql(parameterObject);
    sqlSource = new StaticSqlSource(configuration, parser.getPageSql(boundSql.getSql()),
            parser.getPageParameterMapping(configuration, boundSql));
    boundSql = sqlSource.getBoundSql(parameterObject);
    //??
    for (Map.Entry<String, Object> entry : context.getBindings().entrySet()) {
        boundSql.setAdditionalParameter(entry.getKey(), entry.getValue());
    }
    return boundSql;
}

From source file:com.linju.framework.pager.sqlsource.PageDynamicSqlSource.java

License:Open Source License

public BoundSql getBoundSql(Object parameterObject) {
    DynamicContext context;/*from   w w w .  j  ava 2s.c om*/
    //??parameterObject???
    //??Map?KEY
    //bug#25:http://git.oschina.net/free/Mybatis_PageHelper/issues/25
    if (parameterObject != null && parameterObject instanceof Map
            && ((Map) parameterObject).containsKey(ORIGINAL_PARAMETER_OBJECT)) {
        context = new DynamicContext(configuration, ((Map) parameterObject).get(ORIGINAL_PARAMETER_OBJECT));
    } else {
        context = new DynamicContext(configuration, parameterObject);
    }
    rootSqlNode.apply(context);
    SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration);
    Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass();
    SqlSource sqlSource = sqlSourceParser.parse(context.getSql(), parameterType, context.getBindings());
    if (count) {
        sqlSource = msUtils.getStaticCountSqlSource(configuration, sqlSource, parameterObject);
    } else {
        sqlSource = msUtils.getStaticPageSqlSource(configuration, sqlSource, parameterObject);
    }
    BoundSql boundSql = sqlSource.getBoundSql(parameterObject);
    //??
    for (Map.Entry<String, Object> entry : context.getBindings().entrySet()) {
        boundSql.setAdditionalParameter(entry.getKey(), entry.getValue());
    }
    return boundSql;
}

From source file:com.luxoft.mybatis.splitter.SwitchingSqlSource.java

License:Apache License

@Override
public BoundSql getBoundSql(Object parameterObject) {
    BoundSql subBoundSql = new BoundSql(configuration, sql, parameterMappings, parameterObject);
    for (ParameterMapping parameterMapping : subBoundSql.getParameterMappings()) {
        String property = new PropertyTokenizer(parameterMapping.getProperty()).getName();
        if (parentBoundSql.hasAdditionalParameter(property)) {
            subBoundSql.setAdditionalParameter(property, parentBoundSql.getAdditionalParameter(property));
        }//from   ww  w  . j a  v a 2 s. c  o m
    }
    return subBoundSql;
}

From source file:com.sinotopia.mybatis.pagehelper.PageInterceptor.java

License:Open Source License

@Override
public Object intercept(Invocation invocation) throws Throwable {
    try {//from  w w w . ja  v a 2s. co  m
        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];
        }
        List resultList;
        //????
        if (!dialect.skip(ms, parameter, rowBounds)) {
            //?????
            String msId = ms.getId();
            Configuration configuration = ms.getConfiguration();
            Map<String, Object> additionalParameters = (Map<String, Object>) additionalParametersField
                    .get(boundSql);
            //?? count 
            if (dialect.beforeCount(ms, parameter, rowBounds)) {
                String countMsId = msId + countSuffix;
                Long count;
                //? count 
                MappedStatement countMs = getExistedMappedStatement(configuration, countMsId);
                if (countMs != null) {
                    count = executeManualCount(executor, countMs, parameter, boundSql, resultHandler);
                } else {
                    countMs = msCountMap.get(countMsId);
                    //
                    if (countMs == null) {
                        //?? ms  Long  ms
                        countMs = MSUtils.newCountMappedStatement(ms, countMsId);
                        msCountMap.put(countMsId, countMs);
                    }
                    count = executeAutoCount(executor, countMs, parameter, boundSql, rowBounds, resultHandler);
                }
                //?
                // true false 
                if (!dialect.afterCount(count, parameter, rowBounds)) {
                    // 0 
                    return dialect.afterPage(new ArrayList(), parameter, rowBounds);
                }
            }
            //??
            if (dialect.beforePage(ms, parameter, rowBounds)) {
                //? key
                CacheKey pageKey = cacheKey;
                //??
                parameter = dialect.processParameterObject(ms, parameter, boundSql, pageKey);
                //? sql
                String pageSql = dialect.getPageSql(ms, boundSql, parameter, rowBounds, pageKey);
                BoundSql pageBoundSql = new BoundSql(configuration, pageSql, boundSql.getParameterMappings(),
                        parameter);
                //??
                for (String key : additionalParameters.keySet()) {
                    pageBoundSql.setAdditionalParameter(key, additionalParameters.get(key));
                }
                //
                resultList = executor.query(ms, parameter, RowBounds.DEFAULT, resultHandler, pageKey,
                        pageBoundSql);
            } else {
                //??
                resultList = executor.query(ms, parameter, RowBounds.DEFAULT, resultHandler, cacheKey,
                        boundSql);
            }
        } else {
            //rowBounds??????
            resultList = executor.query(ms, parameter, rowBounds, resultHandler, cacheKey, boundSql);
        }
        return dialect.afterPage(resultList, parameter, rowBounds);
    } finally {
        dialect.afterAll();
    }
}

From source file:com.sinotopia.mybatis.pagehelper.PageInterceptor.java

License:Open Source License

/**
 * ? count //from   w w w .j av a 2  s .  c o  m
 *
 * @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;
}

From source file:org.fire.platform.common.page.sqlsource.PageDynamicSqlSource.java

License:Open Source License

@SuppressWarnings("rawtypes")
public BoundSql getBoundSql(Object parameterObject) {
    DynamicContext context;//w  w  w. j  a v a 2s  .c  o  m
    //??parameterObject???
    //??Map?KEY
    //bug#25:http://git.oschina.net/free/Mybatis_PageHelper/issues/25
    if (parameterObject != null && parameterObject instanceof Map
            && ((Map) parameterObject).containsKey(ORIGINAL_PARAMETER_OBJECT)) {
        context = new DynamicContext(configuration, ((Map) parameterObject).get(ORIGINAL_PARAMETER_OBJECT));
    } else {
        context = new DynamicContext(configuration, parameterObject);
    }
    rootSqlNode.apply(context);
    SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration);
    Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass();
    SqlSource sqlSource = sqlSourceParser.parse(context.getSql(), parameterType, context.getBindings());
    if (count) {
        sqlSource = msUtils.getStaticCountSqlSource(configuration, sqlSource, parameterObject);
    } else {
        sqlSource = msUtils.getStaticPageSqlSource(configuration, sqlSource, parameterObject);
    }
    BoundSql boundSql = sqlSource.getBoundSql(parameterObject);
    //??
    for (Map.Entry<String, Object> entry : context.getBindings().entrySet()) {
        boundSql.setAdditionalParameter(entry.getKey(), entry.getValue());
    }
    return boundSql;
}

From source file:org.mybatis.scripting.velocity.SQLScriptSource.java

License:Apache License

@Override
public BoundSql getBoundSql(Object parameterObject) {

    final Map<String, Object> context = new HashMap<String, Object>();
    final ParameterMappingCollector pmc = new ParameterMappingCollector(parameterMappingSources, context,
            configuration);/*from   ww w .j  av a2 s  . c  o m*/

    context.put(DATABASE_ID_KEY, configuration.getDatabaseId());
    context.put(PARAMETER_OBJECT_KEY, parameterObject);
    context.put(MAPPING_COLLECTOR_KEY, pmc);

    final String sql = VelocityFacade.apply(compiledScript, context);
    BoundSql boundSql = new BoundSql(configuration, sql, pmc.getParameterMappings(), parameterObject);
    for (Map.Entry<String, Object> entry : context.entrySet()) {
        boundSql.setAdditionalParameter(entry.getKey(), entry.getValue());
    }

    return boundSql;

}

From source file:org.solmix.datax.mybatis.page.PageInterceptor.java

License:Open Source License

private BoundSql copyFromBoundSql(MappedStatement ms, BoundSql boundSql, String sql, Object parameterObject) {
    BoundSql newBoundSql = new BoundSql(ms.getConfiguration(), sql, boundSql.getParameterMappings(),
            parameterObject);// www  .j  a va 2 s  .  co m
    for (ParameterMapping mapping : boundSql.getParameterMappings()) {
        String prop = mapping.getProperty();
        if (boundSql.hasAdditionalParameter(prop)) {
            newBoundSql.setAdditionalParameter(prop, boundSql.getAdditionalParameter(prop));
        }
    }
    return newBoundSql;
}