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

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

Introduction

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

Prototype

public List<ParameterMapping> getParameterMappings() 

Source Link

Usage

From source file:com.appleframework.orm.mybatis.pagehelper.parser.impl.AbstractParser.java

License:Open Source License

@SuppressWarnings({ "rawtypes", "unchecked" })
public static Map<String, Object> processParameter(MappedStatement ms, Object parameterObject,
        BoundSql boundSql) {
    Map<String, Object> paramMap = null;
    if (parameterObject == null) {
        paramMap = new HashMap<String, Object>();
    } else if (parameterObject instanceof Map) {
        //???Map//from   w  w  w. j a v a  2 s .c o m
        paramMap = new HashMap<String, Object>();
        paramMap.putAll((Map) parameterObject);
    } else {
        paramMap = new HashMap<String, Object>();
        //?sql??ParameterMapping?getter
        //TypeHandlerRegistry???
        boolean hasTypeHandler = ms.getConfiguration().getTypeHandlerRegistry()
                .hasTypeHandler(parameterObject.getClass());
        MetaObject metaObject = SystemMetaObject.forObject(parameterObject);
        //??MyProviderSqlSource?
        if (ms.getSqlSource() instanceof PageProviderSqlSource) {
            paramMap.put(PROVIDER_OBJECT, parameterObject);
        }
        if (!hasTypeHandler) {
            for (String name : metaObject.getGetterNames()) {
                paramMap.put(name, metaObject.getValue(name));
            }
        }
        //????
        if (boundSql.getParameterMappings() != null && boundSql.getParameterMappings().size() > 0) {
            for (ParameterMapping parameterMapping : boundSql.getParameterMappings()) {
                String name = parameterMapping.getProperty();
                if (!name.equals(PAGEPARAMETER_FIRST) && !name.equals(PAGEPARAMETER_SECOND)
                        && paramMap.get(name) == null) {
                    if (hasTypeHandler || parameterMapping.getJavaType().equals(parameterObject.getClass())) {
                        paramMap.put(name, parameterObject);
                        break;
                    }
                }
            }
        }
    }
    //?
    paramMap.put(ORIGINAL_PARAMETER_OBJECT, parameterObject);
    return paramMap;
}

From source file:com.appleframework.orm.mybatis.pagehelper.parser.impl.AbstractParser.java

License:Open Source License

public List<ParameterMapping> getPageParameterMapping(Configuration configuration, BoundSql boundSql) {
    List<ParameterMapping> newParameterMappings = new ArrayList<ParameterMapping>();
    if (boundSql != null && boundSql.getParameterMappings() != null) {
        newParameterMappings.addAll(boundSql.getParameterMappings());
    }/*from  ww  w . j  a va 2  s.c o m*/
    newParameterMappings
            .add(new ParameterMapping.Builder(configuration, PAGEPARAMETER_FIRST, Integer.class).build());
    newParameterMappings
            .add(new ParameterMapping.Builder(configuration, PAGEPARAMETER_SECOND, Integer.class).build());
    return newParameterMappings;
}

From source file:com.appleframework.orm.mybatis.pagehelper.parser.impl.InformixParser.java

License:Open Source License

@Override
public List<ParameterMapping> getPageParameterMapping(Configuration configuration, BoundSql boundSql) {
    List<ParameterMapping> newParameterMappings = new ArrayList<ParameterMapping>();
    newParameterMappings/*from w  w w.  j a  va2s .  com*/
            .add(new ParameterMapping.Builder(configuration, PAGEPARAMETER_FIRST, Integer.class).build());
    newParameterMappings
            .add(new ParameterMapping.Builder(configuration, PAGEPARAMETER_SECOND, Integer.class).build());
    if (boundSql.getParameterMappings() != null) {
        newParameterMappings.addAll(boundSql.getParameterMappings());
    }
    return newParameterMappings;
}

From source file:com.appleframework.orm.mybatis.pagehelper.parser.impl.SqlServerParser.java

License:Open Source License

@Override
public List<ParameterMapping> getPageParameterMapping(Configuration configuration, BoundSql boundSql) {
    return boundSql.getParameterMappings();
}

From source file:com.appleframework.orm.mybatis.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 ww.j a 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, localParser.get().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.appleframework.orm.mybatis.pagehelper.sqlsource.PageProviderSqlSource.java

License:Open Source License

@Override
protected BoundSql getCountBoundSql(Object parameterObject) {
    BoundSql boundSql;
    SqlSource sqlSource = createSqlSource(parameterObject);
    boundSql = sqlSource.getBoundSql(parameterObject);
    return new BoundSql(configuration, localParser.get().getCountSql(boundSql.getSql()),
            boundSql.getParameterMappings(), parameterObject);
}

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

License:Open Source License

/**
 * ?/*from  w ww.  j a v a2s .  c o m*/
 *
 * @param configuration
 * @param boundSql
 * @return
 */
private List<ParameterMapping> getPageParameterMapping(Configuration configuration, BoundSql boundSql) {
    List<ParameterMapping> newParameterMappings = new ArrayList<ParameterMapping>();
    newParameterMappings.addAll(boundSql.getParameterMappings());
    newParameterMappings
            .add(new ParameterMapping.Builder(configuration, PAGEPARAMETER_FIRST, Integer.class).build());
    newParameterMappings
            .add(new ParameterMapping.Builder(configuration, PAGEPARAMETER_SECOND, Integer.class).build());
    return newParameterMappings;
}

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

License:Open Source License

/**
 * ?countsqlSource/*  w  ww .jav a2 s.c  om*/
 *
 * @param sqlSource
 * @return
 */
private SqlSource getCountSqlSource(Configuration configuration, SqlSource sqlSource, Object parameterObject) {
    BoundSql boundSql = sqlSource.getBoundSql(parameterObject);
    return new StaticSqlSource(configuration, sqlParser.getCountSql(boundSql.getSql()),
            boundSql.getParameterMappings());
}

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

License:Open Source License

/**
 * //from  w w w.  j  a  v a  2s.  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);
}

From source file:com.baomidou.mybatisplus.plugins.OptimisticLockerInterceptor.java

License:Apache License

@SuppressWarnings("unchecked")
private void changSql(MappedStatement ms, BoundSql boundSql, Object parameterObject, LockerCache lockerCache)
        throws Exception {
    Field versionField = lockerCache.field;
    String versionColumn = lockerCache.column;
    final Object versionValue = versionField.get(parameterObject);
    if (versionValue != null) {// ???version,?
        Configuration configuration = ms.getConfiguration();
        // //from   w  w  w  . j  av  a2s.c  om
        lockerCache.versionHandler.plusVersion(parameterObject, versionField, versionValue);
        // ?where?,?
        Update jsqlSql = (Update) CCJSqlParserUtil.parse(boundSql.getSql());
        BinaryExpression expression = (BinaryExpression) jsqlSql.getWhere();
        if (expression != null && !expression.toString().contains(versionColumn)) {
            EqualsTo equalsTo = new EqualsTo();
            equalsTo.setLeftExpression(new Column(versionColumn));
            equalsTo.setRightExpression(RIGHT_EXPRESSION);
            jsqlSql.setWhere(new AndExpression(equalsTo, expression));
            List<ParameterMapping> parameterMappings = new LinkedList<>(boundSql.getParameterMappings());
            parameterMappings.add(jsqlSql.getExpressions().size(), getVersionMappingInstance(configuration));
            MetaObject boundSqlMeta = configuration.newMetaObject(boundSql);
            boundSqlMeta.setValue("sql", jsqlSql.toString());
            boundSqlMeta.setValue("parameterMappings", parameterMappings);
        }
        // ?
        boundSql.setAdditionalParameter("originVersionValue", versionValue);
    }
}