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

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

Introduction

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

Prototype

public String getDatabaseId() 

Source Link

Usage

From source file:com.ewcms.common.mybatis.plugin.PaginationQueryPlugin.java

License:Open Source License

/**
 * ?{@link MppedStatement}//w  ww. jav  a  2 s .  c o  m
 * 
 * @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.luxoft.mybatis.splitter.UpdateSplitterPlugin.java

License:Apache License

@Override
public Object intercept(Invocation invocation) throws Throwable {
    MappedStatement ms = (MappedStatement) invocation.getArgs()[0];
    Object parameterObject = invocation.getArgs()[1];
    final Configuration configuration = ms.getConfiguration();
    final StatementHandler handler = configuration.newStatementHandler((Executor) invocation.getTarget(), ms,
            parameterObject, RowBounds.DEFAULT, null, null);
    final BoundSql boundSql = handler.getBoundSql();
    final String sql = boundSql.getSql();
    List<String> splitted = splitter.split(sql);
    int rc = 0;/*from  www  .  j a  v  a2 s  . co m*/
    List<ParameterMapping> fullParameterMappings = new ArrayList<ParameterMapping>(
            boundSql.getParameterMappings());
    for (String sqlPart : splitted) {
        if (skipEmptyStatements && sqlPart.length() == 0) {
            continue;
        }
        int numParams = 0;
        for (int index = sqlPart.indexOf('?'); index >= 0; index = sqlPart.indexOf('?', index + 1)) {
            numParams++;
        }
        MappedStatement subStatement = subStatements.get(ms);
        if (subStatement == null) {
            subStatement = new MappedStatement.Builder(ms.getConfiguration(), ms.getId(),
                    new SwitchingSqlSource(configuration), ms.getSqlCommandType()).cache(ms.getCache())
                            .databaseId(ms.getDatabaseId()).fetchSize(ms.getFetchSize())
                            .timeout(ms.getTimeout()).flushCacheRequired(ms.isFlushCacheRequired())
                            .useCache(ms.isUseCache()).build();
            subStatements.put(ms, subStatement);
        }
        List<ParameterMapping> subParameterMappings = fullParameterMappings.subList(0, numParams);
        ((SwitchingSqlSource) subStatement.getSqlSource()).switchParams(sqlPart, boundSql,
                new ArrayList<ParameterMapping>(subParameterMappings));
        subParameterMappings.clear();
        int subRc = (Integer) invocation.getMethod().invoke(invocation.getTarget(), subStatement,
                parameterObject);
        if (rc >= 0) {
            rc = subRc < 0 ? subRc : rc + subRc;
        }
    }
    return rc;
}

From source file:com.yimidida.shards.plugin.PaginationInterceptor.java

License:Open Source License

private MappedStatement buildMappedStatement(MappedStatement ms, BoundSql boundSql, String sql) {
    Builder builder = new MappedStatement.Builder(ms.getConfiguration(), ms.getId(),
            new BoundSqlSqlSource(ms, boundSql, sql), ms.getSqlCommandType());

    builder.resource(ms.getResource());//from  ww w  . ja  v  a2 s  .co m
    builder.parameterMap(ms.getParameterMap());
    builder.resultMaps(ms.getResultMaps());
    builder.fetchSize(ms.getFetchSize());
    builder.timeout(ms.getTimeout());
    builder.statementType(ms.getStatementType());
    builder.resultSetType(ms.getResultSetType());
    builder.cache(ms.getCache());
    builder.flushCacheRequired(ms.isFlushCacheRequired());
    builder.useCache(ms.isUseCache());
    builder.keyGenerator(ms.getKeyGenerator());
    builder.keyProperty(delimitedArraytoString(ms.getKeyProperties()));
    builder.keyColumn(delimitedArraytoString(ms.getKeyColumns()));
    builder.databaseId(ms.getDatabaseId());

    return builder.build();
}