Example usage for org.apache.ibatis.mapping MappedStatement isUseCache

List of usage examples for org.apache.ibatis.mapping MappedStatement isUseCache

Introduction

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

Prototype

public boolean isUseCache() 

Source Link

Usage

From source file:SqlUtil.java

License:Open Source License

/**
 * countMappedStatement// w w w  .  j  a  va2  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?????/* w  ww.  j  av a2s  .co m*/
 *
 * @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.utils.SqlUtil.java

License:Open Source License

/**
 * countMappedStatement// www  .ja  v a 2s . c om
 *
 * @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 .j av  a  2  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(), 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 w  w. j  a v a2s . 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  ww  . ja va 2s  .co  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  ww.  ja  v  a2  s .  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.ewcms.common.mybatis.plugin.PaginationQueryPlugin.java

License:Open Source License

/**
 * ?{@link MppedStatement}//from   ww  w.ja  va 2s .  c  om
 * 
 * @param statement 
 * @param boundSql 
 * @param rowBounds
 * @return
 */
private MappedStatement newMappedStatement(final MappedStatement statement, final BoundSql boundSql,
        final RowBounds rowBounds) {

    setPagination(boundSql, rowBounds);
    Builder builder = new MappedStatement.Builder(statement.getConfiguration(), statement.getId(),
            new SqlSource() {
                @Override
                public BoundSql getBoundSql(Object parameterObject) {
                    return boundSql;
                }
            }, statement.getSqlCommandType()).cache(statement.getCache()).databaseId(statement.getDatabaseId())
                    .fetchSize(statement.getFetchSize())
                    .keyColumn(arrayToCommaDelimitedString(statement.getKeyColumns()))
                    .keyGenerator(statement.getKeyGenerator())
                    .keyProperty(arrayToCommaDelimitedString(statement.getKeyProperties()))
                    .parameterMap(statement.getParameterMap()).resource(statement.getResource())
                    .resultMaps(statement.getResultMaps()).statementType(statement.getStatementType())
                    .timeout(statement.getTimeout()).useCache(statement.isUseCache());

    return builder.build();
}

From source file:com.funtl.framework.smoke.core.commons.persistence.interceptor.PaginationInterceptor.java

License:Apache License

private MappedStatement copyFromMappedStatement(MappedStatement ms, SqlSource newSqlSource) {
    MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), ms.getId(),
            newSqlSource, ms.getSqlCommandType());
    builder.resource(ms.getResource());//  w w w. j  a  va2  s .co  m
    builder.fetchSize(ms.getFetchSize());
    builder.statementType(ms.getStatementType());
    builder.keyGenerator(ms.getKeyGenerator());
    if (ms.getKeyProperties() != null) {
        for (String keyProperty : ms.getKeyProperties()) {
            builder.keyProperty(keyProperty);
        }
    }
    builder.timeout(ms.getTimeout());
    builder.parameterMap(ms.getParameterMap());
    builder.resultMaps(ms.getResultMaps());
    builder.cache(ms.getCache());
    builder.useCache(ms.isUseCache());
    return builder.build();
}

From source file:com.github.ibole.infrastructure.persistence.db.mybatis.pagination.PaginationInterceptor.java

License:Apache License

private Integer getCount(String sql, Executor executor, MappedStatement ms, RowBounds rowBounds,
        BoundSql boundSql, Object parameter, Dialect dialect) throws SQLException {
    Integer count = 0;//from  www.j ava  2s.  c o  m
    Cache cache = ms.getCache();
    if (cache != null && ms.isUseCache() && ms.getConfiguration().isCacheEnabled()) {
        CacheKey cacheKey = executor.createCacheKey(ms, parameter, rowBounds, boundSql);
        count = (Integer) cache.getObject(cacheKey);
        if (count == null) {
            count = SqlHelper.getCount(sql, ms, executor.getTransaction(), parameter, boundSql, dialect);
            cache.putObject(cacheKey, count);
        }
    } else {
        count = SqlHelper.getCount(sql, ms, executor.getTransaction(), parameter, boundSql, dialect);
    }
    return count;
}