Example usage for org.apache.ibatis.mapping MappedStatement.Builder resultMaps

List of usage examples for org.apache.ibatis.mapping MappedStatement.Builder resultMaps

Introduction

In this page you can find the example usage for org.apache.ibatis.mapping MappedStatement.Builder resultMaps.

Prototype

List resultMaps

To view the source code for org.apache.ibatis.mapping MappedStatement.Builder resultMaps.

Click Source Link

Usage

From source file:SqlUtil.java

License:Open Source License

/**
 * countMappedStatement//from  w  w w.ja va 2  s  .  c o m
 *
 * @param ms
 * @param newSqlSource
 * @param suffix
 * @return
 */
private MappedStatement newMappedStatement(MappedStatement ms, SqlSource newSqlSource, String suffix) {
    String id = ms.getId() + suffix;
    MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), id, newSqlSource,
            ms.getSqlCommandType());
    builder.resource(ms.getResource());
    builder.fetchSize(ms.getFetchSize());
    builder.statementType(ms.getStatementType());
    builder.keyGenerator(ms.getKeyGenerator());
    if (ms.getKeyProperties() != null && ms.getKeyProperties().length != 0) {
        StringBuilder keyProperties = new StringBuilder();
        for (String keyProperty : ms.getKeyProperties()) {
            keyProperties.append(keyProperty).append(",");
        }
        keyProperties.delete(keyProperties.length() - 1, keyProperties.length());
        builder.keyProperty(keyProperties.toString());
    }
    builder.timeout(ms.getTimeout());
    builder.parameterMap(ms.getParameterMap());
    if (suffix == SUFFIX_PAGE) {
        builder.resultMaps(ms.getResultMaps());
    } else {
        //countint
        List<ResultMap> resultMaps = new ArrayList<ResultMap>();
        ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), id, int.class, EMPTY_RESULTMAPPING)
                .build();
        resultMaps.add(resultMap);
        builder.resultMaps(resultMaps);
    }
    builder.resultSetType(ms.getResultSetType());
    builder.cache(ms.getCache());
    builder.flushCacheRequired(ms.isFlushCacheRequired());
    builder.useCache(ms.isUseCache());

    return builder.build();
}

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

License:Open Source License

/**
 * MappedStatement?????//from   w  ww  .  jav a 2s.  c  om
 *
 * @param ms
 * @param newSqlSource
 * @return
 */
private MappedStatement newMappedStatement(MappedStatement ms, SqlSource newSqlSource) {
    MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), ms.getId() + "_",
            newSqlSource, ms.getSqlCommandType());
    builder.resource(ms.getResource());
    builder.fetchSize(ms.getFetchSize());
    builder.statementType(ms.getStatementType());
    builder.keyGenerator(ms.getKeyGenerator());
    if (ms.getKeyProperties() != null && ms.getKeyProperties().length != 0) {
        StringBuffer keyProperties = new StringBuffer();
        for (String keyProperty : ms.getKeyProperties()) {
            keyProperties.append(keyProperty).append(",");
        }
        keyProperties.delete(keyProperties.length() - 1, keyProperties.length());
        builder.keyProperty(keyProperties.toString());
    }
    builder.timeout(ms.getTimeout());
    builder.parameterMap(ms.getParameterMap());
    //resultMaps?int??resultMap - ?
    List<ResultMap> resultMaps = new ArrayList<ResultMap>();
    ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), ms.getId(), int.class,
            EMPTY_RESULTMAPPING).build();
    resultMaps.add(resultMap);
    builder.resultMaps(resultMaps);
    builder.resultSetType(ms.getResultSetType());
    builder.cache(ms.getCache());
    builder.flushCacheRequired(ms.isFlushCacheRequired());
    builder.useCache(ms.isUseCache());

    return builder.build();
}

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

License:Open Source License

/**
 * SelectKey - ?mysqlOracle?//from   ww w.ja  va 2  s  . c om
 * 
 * @param ms
 * @param column
 */
protected void newSelectKeyMappedStatement(MappedStatement ms, EntityHelper.EntityColumn column) {
    String keyId = ms.getId() + SelectKeyGenerator.SELECT_KEY_SUFFIX;
    if (ms.getConfiguration().hasKeyGenerator(keyId)) {
        return;
    }
    Class<?> entityClass = getSelectReturnType(ms);
    // defaults
    Configuration configuration = ms.getConfiguration();
    KeyGenerator keyGenerator = null;
    Boolean executeBefore = getBEFORE();
    String IDENTITY = (column.getGenerator() == null || column.getGenerator().equals("")) ? getIDENTITY()
            : column.getGenerator();
    if (IDENTITY.equalsIgnoreCase("JDBC")) {
        keyGenerator = new Jdbc3KeyGenerator();
    } else {
        SqlSource sqlSource = new RawSqlSource(configuration, IDENTITY, entityClass);

        MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, keyId, sqlSource,
                SqlCommandType.SELECT);
        statementBuilder.resource(ms.getResource());
        statementBuilder.fetchSize(null);
        statementBuilder.statementType(StatementType.STATEMENT);
        statementBuilder.keyGenerator(new NoKeyGenerator());
        statementBuilder.keyProperty(column.getProperty());
        statementBuilder.keyColumn(null);
        statementBuilder.databaseId(null);
        statementBuilder.lang(configuration.getDefaultScriptingLanuageInstance());
        statementBuilder.resultOrdered(false);
        statementBuilder.resulSets(null);
        statementBuilder.timeout(configuration.getDefaultStatementTimeout());

        List<ParameterMapping> parameterMappings = new ArrayList<ParameterMapping>();
        ParameterMap.Builder inlineParameterMapBuilder = new ParameterMap.Builder(configuration,
                statementBuilder.id() + "-Inline", entityClass, parameterMappings);
        statementBuilder.parameterMap(inlineParameterMapBuilder.build());

        List<ResultMap> resultMaps = new ArrayList<ResultMap>();
        ResultMap.Builder inlineResultMapBuilder = new ResultMap.Builder(configuration,
                statementBuilder.id() + "-Inline", column.getJavaType(), new ArrayList<ResultMapping>(), null);
        resultMaps.add(inlineResultMapBuilder.build());
        statementBuilder.resultMaps(resultMaps);
        statementBuilder.resultSetType(null);

        statementBuilder.flushCacheRequired(false);
        statementBuilder.useCache(false);
        statementBuilder.cache(null);

        MappedStatement statement = statementBuilder.build();
        configuration.addMappedStatement(statement);

        MappedStatement keyStatement = configuration.getMappedStatement(keyId, false);
        keyGenerator = new SelectKeyGenerator(keyStatement, executeBefore);
        configuration.addKeyGenerator(keyId, keyGenerator);
    }
    // keyGenerator
    try {
        MetaObject msObject = forObject(ms);
        msObject.setValue("keyGenerator", keyGenerator);
        msObject.setValue("keyProperties", new String[] { column.getProperty() });
    } catch (Exception e) {
        // ignore
    }
}

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

License:Open Source License

/**
 * countMappedStatement//  w  w  w . j a v a2s.  c  o  m
 *
 * @param ms
 * @param newSqlSource
 * @param suffix
 * @return
 */
private MappedStatement newMappedStatement(MappedStatement ms, SqlSource newSqlSource, String suffix) {
    String id = ms.getId() + suffix;
    MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), id, newSqlSource,
            ms.getSqlCommandType());
    builder.resource(ms.getResource());
    builder.fetchSize(ms.getFetchSize());
    builder.statementType(ms.getStatementType());
    builder.keyGenerator(ms.getKeyGenerator());
    if (ms.getKeyProperties() != null && ms.getKeyProperties().length != 0) {
        StringBuilder keyProperties = new StringBuilder();
        for (String keyProperty : ms.getKeyProperties()) {
            keyProperties.append(keyProperty).append(",");
        }
        keyProperties.delete(keyProperties.length() - 1, keyProperties.length());
        builder.keyProperty(keyProperties.toString());
    }
    builder.timeout(ms.getTimeout());
    builder.parameterMap(ms.getParameterMap());
    if (suffix == SUFFIX_PAGE) {
        builder.resultMaps(ms.getResultMaps());
    } else {
        // countint
        List<ResultMap> resultMaps = new ArrayList<ResultMap>();
        ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), id, int.class, EMPTY_RESULTMAPPING)
                .build();
        resultMaps.add(resultMap);
        builder.resultMaps(resultMaps);
    }
    builder.resultSetType(ms.getResultSetType());
    builder.cache(ms.getCache());
    builder.flushCacheRequired(ms.isFlushCacheRequired());
    builder.useCache(ms.isUseCache());

    return builder.build();
}

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

License:Open Source License

/**
 * countMappedStatement// ww  w . ja v  a 2 s.com
 *
 * @param ms
 * @return
 */
public static MappedStatement newCountMappedStatement(MappedStatement ms) {
    MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), ms.getId() + "_COUNT",
            ms.getSqlSource(), ms.getSqlCommandType());
    builder.resource(ms.getResource());
    builder.fetchSize(ms.getFetchSize());
    builder.statementType(ms.getStatementType());
    builder.keyGenerator(ms.getKeyGenerator());
    if (ms.getKeyProperties() != null && ms.getKeyProperties().length != 0) {
        StringBuilder keyProperties = new StringBuilder();
        for (String keyProperty : ms.getKeyProperties()) {
            keyProperties.append(keyProperty).append(",");
        }
        keyProperties.delete(keyProperties.length() - 1, keyProperties.length());
        builder.keyProperty(keyProperties.toString());
    }
    builder.timeout(ms.getTimeout());
    builder.parameterMap(ms.getParameterMap());
    //countint
    List<ResultMap> resultMaps = new ArrayList<ResultMap>();
    ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), ms.getId(), int.class,
            EMPTY_RESULTMAPPING).build();
    resultMaps.add(resultMap);
    builder.resultMaps(resultMaps);
    builder.resultSetType(ms.getResultSetType());
    builder.cache(ms.getCache());
    builder.flushCacheRequired(ms.isFlushCacheRequired());
    builder.useCache(ms.isUseCache());

    return builder.build();
}

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

License:Open Source License

/**
 * countMappedStatement//from   w  ww . j  a v  a  2s . c  o  m
 *
 * @param ms
 * @param sqlSource
 * @param suffix
 * @return
 */
private MappedStatement newMappedStatement(MappedStatement ms, SqlSource sqlSource, String suffix) {
    String id = ms.getId() + suffix;
    MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), id, sqlSource,
            ms.getSqlCommandType());
    builder.resource(ms.getResource());
    builder.fetchSize(ms.getFetchSize());
    builder.statementType(ms.getStatementType());
    builder.keyGenerator(ms.getKeyGenerator());
    if (ms.getKeyProperties() != null && ms.getKeyProperties().length != 0) {
        StringBuilder keyProperties = new StringBuilder();
        for (String keyProperty : ms.getKeyProperties()) {
            keyProperties.append(keyProperty).append(",");
        }
        keyProperties.delete(keyProperties.length() - 1, keyProperties.length());
        builder.keyProperty(keyProperties.toString());
    }
    builder.timeout(ms.getTimeout());
    builder.parameterMap(ms.getParameterMap());
    if (suffix == SUFFIX_PAGE) {
        builder.resultMaps(ms.getResultMaps());
    } else {
        //countint
        List<ResultMap> resultMaps = new ArrayList<ResultMap>();
        ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), id, int.class, EMPTY_RESULTMAPPING)
                .build();
        resultMaps.add(resultMap);
        builder.resultMaps(resultMaps);
    }
    builder.resultSetType(ms.getResultSetType());
    builder.cache(ms.getCache());
    builder.flushCacheRequired(ms.isFlushCacheRequired());
    builder.useCache(ms.isUseCache());

    return builder.build();
}

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

License:Open Source License

/**
 * countMappedStatement//from  w w w .  j av a2s .  c om
 *
 * @param ms
 * @return
 */
public static MappedStatement newCountMappedStatement(MappedStatement ms) {
    MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), ms.getId() + "_COUNT",
            ms.getSqlSource(), ms.getSqlCommandType());
    builder.resource(ms.getResource());
    builder.fetchSize(ms.getFetchSize());
    builder.statementType(ms.getStatementType());
    builder.keyGenerator(ms.getKeyGenerator());
    if (ms.getKeyProperties() != null && ms.getKeyProperties().length != 0) {
        StringBuilder keyProperties = new StringBuilder();
        for (String keyProperty : ms.getKeyProperties()) {
            keyProperties.append(keyProperty).append(",");
        }
        keyProperties.delete(keyProperties.length() - 1, keyProperties.length());
        builder.keyProperty(keyProperties.toString());
    }
    builder.timeout(ms.getTimeout());
    builder.parameterMap(ms.getParameterMap());
    //countint
    List<ResultMap> resultMaps = new ArrayList<ResultMap>();
    ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), ms.getId(), Long.class,
            EMPTY_RESULTMAPPING).build();
    resultMaps.add(resultMap);
    builder.resultMaps(resultMaps);
    builder.resultSetType(ms.getResultSetType());
    builder.cache(ms.getCache());
    builder.flushCacheRequired(ms.isFlushCacheRequired());
    builder.useCache(ms.isUseCache());

    return builder.build();
}

From source file:com.baidu.dpop.ctp.common.mybatis.page.SqlUtil.java

License:Open Source License

/**
 * countMappedStatement//from  www.  j a v a 2s  .c o m
 *
 * @param ms
 * @param sqlSource
 * @param suffix
 * @return
 */
private MappedStatement newMappedStatement(MappedStatement ms, SqlSource sqlSource, String suffix) {
    String id = ms.getId() + suffix;
    MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), id, sqlSource,
            ms.getSqlCommandType());

    builder.resource(ms.getResource());
    builder.fetchSize(ms.getFetchSize());
    builder.statementType(ms.getStatementType());
    builder.keyGenerator(ms.getKeyGenerator());

    if (ms.getKeyProperties() != null && ms.getKeyProperties().length != 0) {
        StringBuilder keyProperties = new StringBuilder();
        for (String keyProperty : ms.getKeyProperties()) {
            keyProperties.append(keyProperty).append(",");
        }
        keyProperties.delete(keyProperties.length() - 1, keyProperties.length());
        builder.keyProperty(keyProperties.toString());
    }
    builder.timeout(ms.getTimeout());
    builder.parameterMap(ms.getParameterMap());
    if (suffix.equals(SUFFIX_PAGE)) {
        builder.resultMaps(ms.getResultMaps());
    } else {
        //countint
        List<ResultMap> resultMaps = new ArrayList<ResultMap>();
        ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), id, int.class, EMPTY_RESULTMAPPING)
                .build();
        resultMaps.add(resultMap);
        builder.resultMaps(resultMaps);
    }
    builder.resultSetType(ms.getResultSetType());
    builder.cache(ms.getCache());
    builder.flushCacheRequired(ms.isFlushCacheRequired());
    builder.useCache(ms.isUseCache());

    return builder.build();
}

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

License:Apache License

/**
 * <p>/*from   w  w w.j a v a2 s .c  o m*/
 * ? SQL
 * </p>
 *
 * @param configuration
 * @param mappedStatement
 * @param boundSql
 * @param connection
 * @param parameter
 * @return
 * @throws Exception
 */
protected void sqlExplain(Configuration configuration, MappedStatement mappedStatement, BoundSql boundSql,
        Connection connection, Object parameter) {
    StringBuilder explain = new StringBuilder("EXPLAIN ");
    explain.append(boundSql.getSql());
    String sqlExplain = explain.toString();
    StaticSqlSource sqlsource = new StaticSqlSource(configuration, sqlExplain, boundSql.getParameterMappings());
    MappedStatement.Builder builder = new MappedStatement.Builder(configuration, "explain_sql", sqlsource,
            SqlCommandType.SELECT);
    builder.resultMaps(mappedStatement.getResultMaps()).resultSetType(mappedStatement.getResultSetType())
            .statementType(mappedStatement.getStatementType());
    MappedStatement query_statement = builder.build();
    DefaultParameterHandler handler = new DefaultParameterHandler(query_statement, parameter, boundSql);
    try (PreparedStatement stmt = connection.prepareStatement(sqlExplain)) {
        handler.setParameters(stmt);
        try (ResultSet rs = stmt.executeQuery()) {
            while (rs.next()) {
                if (!"Using where".equals(rs.getString("Extra"))) {
                    if (this.isStopProceed()) {
                        throw new MybatisPlusException(
                                "Error: Full table operation is prohibited. SQL: " + boundSql.getSql());
                    }
                    break;
                }
            }
        }

    } catch (Exception e) {
        throw new MybatisPlusException(e);
    }
}

From source file:com.bsb.cms.commons.page.interceptor.PaginationInterceptor.java

License:Open Source License

/**
 * ?MappedStatement/* w  w w.jav  a  2s  .  co  m*/
 */
private MappedStatement copyFromMappedStatement(MappedStatement ms, SqlSource newSqlSource) {
    MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), ms.getId(),
            newSqlSource, ms.getSqlCommandType());
    builder.resource(ms.getResource());
    builder.fetchSize(ms.getFetchSize());
    builder.statementType(ms.getStatementType());
    builder.keyGenerator(ms.getKeyGenerator());
    String[] keyProperties = ms.getKeyProperties();
    String keyProperty = "";
    if ((keyProperties != null) && (keyProperties.length > 0))
        for (String kp : keyProperties)
            keyProperty = keyProperty + "," + kp;

    if (StringUtils.isNotEmpty(keyProperty))
        keyProperty = keyProperty.substring(1);
    builder.keyProperty(keyProperty);
    builder.timeout(ms.getTimeout());
    builder.parameterMap(ms.getParameterMap());
    builder.resultMaps(ms.getResultMaps());
    builder.cache(ms.getCache());
    MappedStatement newMs = builder.build();
    return newMs;
}