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

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

Introduction

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

Prototype

ResultSetType resultSetType

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

Click Source Link

Usage

From source file:SqlUtil.java

License:Open Source License

/**
 * countMappedStatement/*from  www  .  j a  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   ww  w.ja v  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 w ww.  j  ava2s . co  m
 * 
 * @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  ww  .  j av a2s  . com*/
 *
 * @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/*from w w  w  .  j ava2 s. 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(), 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  ww  w.  jav  a 2s  .co  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// w  w  w  .  java2  s.c  o  m
 *
 * @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  w w w.j  ava 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.github.abel533.mapper.MapperTemplate.java

License:Open Source License

/**
 * SelectKey - ?mysqlOracle?/*  ww w .ja  v  a 2s  . c  o m*/
 *
 * @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 = new NoKeyGenerator();
    Boolean executeBefore = getBEFORE();
    String IDENTITY = (column.getGenerator() == null || column.getGenerator().equals("")) ? getIDENTITY()
            : column.getGenerator();
    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(keyGenerator);
    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", int.class, 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);
    configuration.addKeyGenerator(keyId, new SelectKeyGenerator(keyStatement, executeBefore));
    //keyGenerator
    try {
        MetaObject msObject = forObject(ms);
        msObject.setValue("keyGenerator", configuration.getKeyGenerator(keyId));
    } catch (Exception e) {
        //ignore
    }
}

From source file:com.github.abel533.mapperhelper.MapperTemplate.java

License:Open Source License

/**
 * SelectKey - ?mysqlOracle?//www  .  ja  v a2 s .com
 *
 * @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
    }
}