Example usage for org.apache.ibatis.executor.statement StatementHandler parameterize

List of usage examples for org.apache.ibatis.executor.statement StatementHandler parameterize

Introduction

In this page you can find the example usage for org.apache.ibatis.executor.statement StatementHandler parameterize.

Prototype

void parameterize(Statement statement) throws SQLException;

Source Link

Usage

From source file:com.luxoft.mybatis.splitter.ReusingBatchExecutor.java

License:Apache License

public int doUpdate(MappedStatement ms, Object parameterObject) throws SQLException {
    final Configuration configuration = ms.getConfiguration();
    final StatementHandler handler = configuration.newStatementHandler(this, ms, parameterObject,
            RowBounds.DEFAULT, null, null);
    final BoundSql boundSql = handler.getBoundSql();
    PreparedStatementKey key = new PreparedStatementKey(boundSql.getSql(), ms);
    StatementData statementData = statementsData.get(key);
    if (retainExecuteOrder && statementData != null && !key.equals(lastKey)) {
        statementData = null;//from w  w w.  j  a v a 2  s . c om
        executeUpTo(key, true);
    }
    if (statementData == null) {
        statementData = unusedStatementData.remove(key);
        if (statementData == null) {
            Connection connection = getConnection(ms.getStatementLog());
            Statement stmt = handler.prepare(connection);
            statementData = new StatementData(stmt);
        }
        statementsData.put(key, statementData);
    }
    lastKey = key;
    statementData.addParameterObject(parameterObject);
    handler.parameterize(statementData.getStatement());
    handler.batch(statementData.getStatement());
    return BATCH_UPDATE_RETURN_VALUE;
}

From source file:com.luxoft.mybatis.splitter.ReusingBatchExecutor.java

License:Apache License

public <E> List<E> doQuery(MappedStatement ms, Object parameterObject, RowBounds rowBounds,
        ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
    Statement stmt = null;//  www .  ja  va  2 s .c o  m
    try {
        flushStatements();
        Configuration configuration = ms.getConfiguration();
        StatementHandler handler = configuration.newStatementHandler(this, ms, parameterObject, rowBounds,
                resultHandler, boundSql);
        Connection connection = getConnection(ms.getStatementLog());
        stmt = handler.prepare(connection);
        handler.parameterize(stmt);
        return handler.<E>query(stmt, resultHandler);
    } finally {
        closeStatement(stmt);
    }
}