Example usage for org.apache.ibatis.scripting.xmltags MixedSqlNode MixedSqlNode

List of usage examples for org.apache.ibatis.scripting.xmltags MixedSqlNode MixedSqlNode

Introduction

In this page you can find the example usage for org.apache.ibatis.scripting.xmltags MixedSqlNode MixedSqlNode.

Prototype

public MixedSqlNode(List<SqlNode> contents) 

Source Link

Usage

From source file:SqlUtil.java

License:Open Source License

/**
 * ?sqlSource/*from   w ww. j  a  va 2  s  .c o  m*/
 *
 * @param ms
 * @param newSqlSource
 * @param suffix
 * @return
 */
private SqlSource getNewSqlSource(MappedStatement ms, BoundSqlSqlSource newSqlSource, String suffix) {
    //XMLLanguageDriver.javaXMLScriptBuilder.java???SqlSource
    //?sql
    if (isDynamic(ms)) {
        MetaObject msObject = forObject(ms);
        SqlNode sqlNode = (SqlNode) msObject.getValue("sqlSource.rootSqlNode");
        MixedSqlNode mixedSqlNode = null;
        if (sqlNode instanceof MixedSqlNode) {
            mixedSqlNode = (MixedSqlNode) sqlNode;
        } else {
            List<SqlNode> contents = new ArrayList<SqlNode>(1);
            contents.add(sqlNode);
            mixedSqlNode = new MixedSqlNode(contents);
        }
        return new MyDynamicSqlSource(ms.getConfiguration(), mixedSqlNode, suffix == SUFFIX_COUNT);
    }
    //??sql
    else if (suffix == SUFFIX_PAGE) {
        //sql
        return getPageSqlSource(ms.getConfiguration(), newSqlSource);
    }
    //??count-sql
    else {
        return getCountSqlSource(newSqlSource);
    }
}

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

License:Open Source License

/**
 * ?whereif/*from   w  ww  .  j ava2 s .com*/
 * 
 * @param entityClass
 * @return
 */
protected SqlNode getAllIfColumnNode(Class<?> entityClass) {
    // ?
    List<EntityHelper.EntityColumn> columnList = EntityHelper.getColumns(entityClass);
    List<SqlNode> ifNodes = new ArrayList<SqlNode>();
    boolean first = true;
    // ?<if test="property!=null">column = #{property}</if>
    for (EntityHelper.EntityColumn column : columnList) {
        ifNodes.add(getIfNotNull(column, getColumnEqualsProperty(column, first), mapperHelper.isNotEmpty()));
        first = false;
    }
    return new MixedSqlNode(ifNodes);
}

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

License:Open Source License

/**
 * create criteria from baseExample/*from   w w  w.  j a v  a  2s. c o m*/
 * 
 * @param sqlNodes
 * @param baseExample
 */
protected SqlNode createCriteria(MappedStatement ms) {

    List<SqlNode> ifSqlNodes = new ArrayList<SqlNode>();

    SqlNode noValueSqlNode = new TextSqlNode(" ${criterion.condition} ");
    ifSqlNodes.add(new IfSqlNode(noValueSqlNode, "criterion.noValue"));

    SqlNode singleValueSqlNode = new TextSqlNode(" ${criterion.condition} #{criterion.value} ");
    ifSqlNodes.add(new IfSqlNode(singleValueSqlNode, "criterion.singleValue"));

    SqlNode betweenValueSqlNode = new TextSqlNode(
            " ${criterion.condition} #{criterion.value} and #{criterion.secondValue} ");
    ifSqlNodes.add(new IfSqlNode(betweenValueSqlNode, "criterion.betweenValue"));

    List<SqlNode> listSqlNode = new ArrayList<SqlNode>();
    listSqlNode.add(new TextSqlNode(" ${criterion.condition} "));
    SqlNode listItemNode = new TextSqlNode(" #{listItem} ");
    SqlNode foreachSqlNode3 = new ForEachSqlNode(ms.getConfiguration(), listItemNode, "criterion.value", null,
            "listItem", " (", ") ", ",");
    listSqlNode.add(foreachSqlNode3);
    ifSqlNodes.add(new IfSqlNode(new MixedSqlNode(listSqlNode), "criterion.listValue"));

    SqlNode chooseSqlNode = new ChooseSqlNode(ifSqlNodes, null);
    SqlNode foreachSqlNode2 = new ForEachSqlNode(ms.getConfiguration(), chooseSqlNode, "criteria.criteria",
            null, "criterion", null, null, "AND");
    SqlNode trimSqlNode = new TrimSqlNode(ms.getConfiguration(), foreachSqlNode2, " (", "AND", ") ",
            (String) null);
    SqlNode iftestSqlNode = new IfSqlNode(trimSqlNode, "criteria.valid");
    SqlNode foreachSqlNode1 = new ForEachSqlNode(ms.getConfiguration(), iftestSqlNode, "oredCriteria", null,
            "criteria", null, null, "OR");

    return foreachSqlNode1;
}

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

License:Open Source License

/**
 * ??/*from  ww  w. ja va2 s. c om*/
 * 
 * @param entityClass
 * @return
 */
protected SqlNode getOrderByColumnNode(Class<?> entityClass) {
    // ??
    List<EntityHelper.EntityColumn> columnList = EntityHelper.getOrderByColumns(entityClass);
    boolean first = true;
    List<SqlNode> sqlNodes = new ArrayList<SqlNode>();
    for (EntityHelper.EntityColumn column : columnList) {
        SqlNode sqlNode = new StaticTextSqlNode(
                (first ? "" : ",  ") + column.getColumn() + " " + column.getOrderBy());
        sqlNodes.add(sqlNode);
        first = false;
    }
    return new MixedSqlNode(sqlNodes);
}

From source file:cn.org.awcp.core.utils.SqlUtil.java

License:Open Source License

/**
 * ?sqlSource/*from  w  w  w . j a v  a  2  s  . co  m*/
 *
 * @param ms
 * @param newSqlSource
 * @param suffix
 * @return
 */
private SqlSource getNewSqlSource(MappedStatement ms, BoundSqlSqlSource newSqlSource, String suffix) {
    // XMLLanguageDriver.javaXMLScriptBuilder.java???SqlSource
    // ?sql
    if (isDynamic(ms)) {
        MetaObject msObject = forObject(ms);
        SqlNode sqlNode = (SqlNode) msObject.getValue("sqlSource.rootSqlNode");
        MixedSqlNode mixedSqlNode = null;
        if (sqlNode instanceof MixedSqlNode) {
            mixedSqlNode = (MixedSqlNode) sqlNode;
        } else {
            List<SqlNode> contents = new ArrayList<SqlNode>(1);
            contents.add(sqlNode);
            mixedSqlNode = new MixedSqlNode(contents);
        }
        return new MyDynamicSqlSource(ms.getConfiguration(), mixedSqlNode, suffix == SUFFIX_COUNT);
    }
    // ??sql
    else if (suffix == SUFFIX_PAGE) {
        // sql
        return getPageSqlSource(ms.getConfiguration(), newSqlSource);
    }
    // ??count-sql
    else {
        return getCountSqlSource(newSqlSource);
    }
}

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

License:Open Source License

/**
 * ?sqlSource/*from  w  w w. j  a  v  a  2 s .c  o  m*/
 *
 * @param ms
 * @param sqlSource
 * @param parameterObject
 * @param suffix
 * @return
 */
private SqlSource getsqlSource(MappedStatement ms, SqlSource sqlSource, Object parameterObject, String suffix) {
    //1. XMLLanguageDriver.javaXMLScriptBuilder.java???SqlSource
    //2. ProviderSqlSource
    //3. RawSqlSource?
    //?sql
    if (isDynamic(ms)) {
        MetaObject msObject = forObject(ms);
        SqlNode sqlNode = (SqlNode) msObject.getValue("sqlSource.rootSqlNode");
        MixedSqlNode mixedSqlNode = null;
        if (sqlNode instanceof MixedSqlNode) {
            mixedSqlNode = (MixedSqlNode) sqlNode;
        } else {
            List<SqlNode> contents = new ArrayList<SqlNode>(1);
            contents.add(sqlNode);
            mixedSqlNode = new MixedSqlNode(contents);
        }
        return new MyDynamicSqlSource(ms.getConfiguration(), mixedSqlNode, suffix == SUFFIX_COUNT);
    } else if (sqlSource instanceof ProviderSqlSource) {
        return new MyProviderSqlSource(ms.getConfiguration(), (ProviderSqlSource) sqlSource,
                suffix == SUFFIX_COUNT);
    }
    //??sql
    else if (suffix == SUFFIX_PAGE) {
        //sql
        return getPageSqlSource(ms.getConfiguration(), sqlSource, parameterObject);
    }
    //??count-sql
    else {
        return getCountSqlSource(ms.getConfiguration(), sqlSource, parameterObject);
    }
}

From source file:com.cheyipai.platformservice.thirdparty.core.pager.PageHelper.java

License:Open Source License

/**
 * ?sqlSource//  ww  w .  ja v  a  2  s.  c  o m
 *
 * @param ms
 * @param newSqlSource
 * @param suffix
 * @return
 */
private SqlSource getNewSqlSource(MappedStatement ms, BoundSqlSqlSource newSqlSource, String suffix) {
    SqlSource sqlSource = ms.getSqlSource();
    //XMLLanguageDriver.javaXMLScriptBuilder.java???SqlSource
    if (sqlSource instanceof DynamicSqlSource) {
        MetaObject msObject = forObject(ms);
        List<SqlNode> contents = (List<SqlNode>) msObject.getValue(SQL_NODES);
        List<SqlNode> newSqlNodes = new ArrayList<SqlNode>(contents.size() + 2);
        //?
        if (suffix == SUFFIX_PAGE) {
            newSqlNodes.add(new TextSqlNode(getPageSqlBefore()));
            newSqlNodes.addAll(contents);
            newSqlNodes.add(new TextSqlNode(getPageSqlAfter()));
            return new MyDynamicSqlSource(ms.getConfiguration(), new MixedSqlNode(newSqlNodes));
        } else {
            newSqlNodes.add(new TextSqlNode(getCountSqlBefore()));
            newSqlNodes.addAll(contents);
            newSqlNodes.add(new TextSqlNode(getCountSqlAfter()));
            return new DynamicSqlSource(ms.getConfiguration(), new MixedSqlNode(newSqlNodes));
        }
    } else {
        //RawSqlSource
        //?
        if (suffix == SUFFIX_PAGE) {
            //sql
            MetaObject sqlObject = forObject(newSqlSource);
            sqlObject.setValue(BOUND_SQL, getPageSql((String) sqlObject.getValue(BOUND_SQL)));
            //?
            List<ParameterMapping> newParameterMappings = new ArrayList<ParameterMapping>();
            newParameterMappings.addAll(newSqlSource.getBoundSql().getParameterMappings());
            newParameterMappings
                    .add(new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_FIRST, Integer.class)
                            .build());
            newParameterMappings.add(
                    new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_SECOND, Integer.class)
                            .build());
            sqlObject.setValue("boundSql.parameterMappings", newParameterMappings);
        } else {
            //count sql
            MetaObject sqlObject = forObject(newSqlSource);
            sqlObject.setValue(BOUND_SQL, getCountSql((String) sqlObject.getValue(BOUND_SQL)));
        }
        return newSqlSource;
    }
}

From source file:com.dingding.utils.page.SqlUtil.java

License:Open Source License

/**
 * ?sqlSource/*from   www.j a  v a2 s. co  m*/
 *
 * @param ms
 * @param newSqlSource
 * @param suffix
 * @return
 */
private SqlSource getNewSqlSource(MappedStatement ms, BoundSqlSqlSource newSqlSource, String suffix) {
    SqlSource sqlSource = ms.getSqlSource();
    //XMLLanguageDriver.javaXMLScriptBuilder.java???SqlSource
    if (sqlSource instanceof DynamicSqlSource) {
        MetaObject msObject = forObject(ms);
        List<SqlNode> contents = (List<SqlNode>) msObject.getValue(SQL_NODES);
        List<SqlNode> newSqlNodes = new ArrayList<SqlNode>(contents.size() + 2);
        //?
        if (suffix == SUFFIX_PAGE) {
            newSqlNodes.add(new TextSqlNode(SQLPARSER.getPageSqlBefore()));
            newSqlNodes.addAll(contents);
            newSqlNodes.add(new TextSqlNode(SQLPARSER.getPageSqlAfter()));
            return new MyDynamicSqlSource(ms.getConfiguration(), new MixedSqlNode(newSqlNodes), false);
        } else {
            newSqlNodes.add(new TextSqlNode(SQLPARSER.getCountSqlBefore()));
            newSqlNodes.addAll(contents);
            newSqlNodes.add(new TextSqlNode(SQLPARSER.getCountSqlAfter()));
            return new MyDynamicSqlSource(ms.getConfiguration(), new MixedSqlNode(newSqlNodes), true);
        }
    } else {
        //RawSqlSource
        //?
        if (suffix == SUFFIX_PAGE) {
            //sql
            MetaObject sqlObject = forObject(newSqlSource);
            sqlObject.setValue(BOUND_SQL, SQLPARSER.getPageSql((String) sqlObject.getValue(BOUND_SQL)));
            //?
            List<ParameterMapping> newParameterMappings = new ArrayList<ParameterMapping>();
            newParameterMappings.addAll(newSqlSource.getBoundSql().getParameterMappings());
            newParameterMappings
                    .add(new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_FIRST, Integer.class)
                            .build());
            newParameterMappings.add(
                    new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_SECOND, Integer.class)
                            .build());
            sqlObject.setValue("boundSql.parameterMappings", newParameterMappings);
        } else {
            //count sql
            MetaObject sqlObject = forObject(newSqlSource);
            sqlObject.setValue(BOUND_SQL, SQLPARSER.getCountSql((String) sqlObject.getValue(BOUND_SQL)));
        }
        return newSqlSource;
    }
}

From source file:com.github.abel533.mapper.MapperProvider.java

License:Open Source License

/**
 * /*  w w  w .j  a v  a 2 s .  c o m*/
 *
 * @param ms
 * @return
 */
public SqlNode select(MappedStatement ms) {
    Class<?> entityClass = getSelectReturnType(ms);
    //
    setResultType(ms, entityClass);
    List<SqlNode> sqlNodes = new ArrayList<SqlNode>();
    //??sql:select column ... from table
    sqlNodes.add(new StaticTextSqlNode(
            "SELECT " + EntityHelper.getSelectColumns(entityClass) + " FROM " + tableName(entityClass)));
    //if<where>
    sqlNodes.add(new WhereSqlNode(ms.getConfiguration(), getAllIfColumnNode(entityClass)));
    return new MixedSqlNode(sqlNodes);
}

From source file:com.github.abel533.mapper.MapperProvider.java

License:Open Source License

/**
 * //from w  w w  .j a va 2 s  .c o m
 *
 * @param ms
 * @return
 */
public SqlNode selectCount(MappedStatement ms) {
    Class<?> entityClass = getSelectReturnType(ms);
    List<SqlNode> sqlNodes = new ArrayList<SqlNode>();
    //select count(*) from table
    sqlNodes.add(new StaticTextSqlNode("SELECT COUNT(*) FROM " + tableName(entityClass)));
    //?where,if?
    sqlNodes.add(new WhereSqlNode(ms.getConfiguration(), getAllIfColumnNode(entityClass)));
    return new MixedSqlNode(sqlNodes);
}