Search in sources :

Example 6 with StatementHandler

use of org.apache.ibatis.executor.statement.StatementHandler in project mybatis-3 by mybatis.

the class SimpleExecutor method doUpdate.

@Override
public int doUpdate(MappedStatement ms, Object parameter) throws SQLException {
    Statement stmt = null;
    try {
        Configuration configuration = ms.getConfiguration();
        StatementHandler handler = configuration.newStatementHandler(this, ms, parameter, RowBounds.DEFAULT, null, null);
        stmt = prepareStatement(handler, ms.getStatementLog());
        return handler.update(stmt);
    } finally {
        closeStatement(stmt);
    }
}
Also used : Configuration(org.apache.ibatis.session.Configuration) MappedStatement(org.apache.ibatis.mapping.MappedStatement) Statement(java.sql.Statement) StatementHandler(org.apache.ibatis.executor.statement.StatementHandler)

Example 7 with StatementHandler

use of org.apache.ibatis.executor.statement.StatementHandler in project mybatis-3 by mybatis.

the class BatchExecutor method doUpdate.

@Override
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();
    final String sql = boundSql.getSql();
    final Statement stmt;
    if (sql.equals(currentSql) && ms.equals(currentStatement)) {
        int last = statementList.size() - 1;
        stmt = statementList.get(last);
        applyTransactionTimeout(stmt);
        //fix Issues 322
        handler.parameterize(stmt);
        BatchResult batchResult = batchResultList.get(last);
        batchResult.addParameterObject(parameterObject);
    } else {
        Connection connection = getConnection(ms.getStatementLog());
        stmt = handler.prepare(connection, transaction.getTimeout());
        //fix Issues 322
        handler.parameterize(stmt);
        currentSql = sql;
        currentStatement = ms;
        statementList.add(stmt);
        batchResultList.add(new BatchResult(ms, sql, parameterObject));
    }
    // handler.parameterize(stmt);
    handler.batch(stmt);
    return BATCH_UPDATE_RETURN_VALUE;
}
Also used : Configuration(org.apache.ibatis.session.Configuration) BoundSql(org.apache.ibatis.mapping.BoundSql) MappedStatement(org.apache.ibatis.mapping.MappedStatement) Statement(java.sql.Statement) StatementHandler(org.apache.ibatis.executor.statement.StatementHandler) Connection(java.sql.Connection)

Example 8 with StatementHandler

use of org.apache.ibatis.executor.statement.StatementHandler in project mybatis-3 by mybatis.

the class BatchExecutor method doQuery.

@Override
public <E> List<E> doQuery(MappedStatement ms, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
    Statement stmt = null;
    try {
        flushStatements();
        Configuration configuration = ms.getConfiguration();
        StatementHandler handler = configuration.newStatementHandler(wrapper, ms, parameterObject, rowBounds, resultHandler, boundSql);
        Connection connection = getConnection(ms.getStatementLog());
        stmt = handler.prepare(connection, transaction.getTimeout());
        handler.parameterize(stmt);
        return handler.<E>query(stmt, resultHandler);
    } finally {
        closeStatement(stmt);
    }
}
Also used : Configuration(org.apache.ibatis.session.Configuration) MappedStatement(org.apache.ibatis.mapping.MappedStatement) Statement(java.sql.Statement) StatementHandler(org.apache.ibatis.executor.statement.StatementHandler) Connection(java.sql.Connection)

Example 9 with StatementHandler

use of org.apache.ibatis.executor.statement.StatementHandler in project mybatis-3 by mybatis.

the class BatchExecutor method doQueryCursor.

@Override
protected <E> Cursor<E> doQueryCursor(MappedStatement ms, Object parameter, RowBounds rowBounds, BoundSql boundSql) throws SQLException {
    flushStatements();
    Configuration configuration = ms.getConfiguration();
    StatementHandler handler = configuration.newStatementHandler(wrapper, ms, parameter, rowBounds, null, boundSql);
    Connection connection = getConnection(ms.getStatementLog());
    Statement stmt = handler.prepare(connection, transaction.getTimeout());
    handler.parameterize(stmt);
    return handler.<E>queryCursor(stmt);
}
Also used : Configuration(org.apache.ibatis.session.Configuration) MappedStatement(org.apache.ibatis.mapping.MappedStatement) Statement(java.sql.Statement) StatementHandler(org.apache.ibatis.executor.statement.StatementHandler) Connection(java.sql.Connection)

Example 10 with StatementHandler

use of org.apache.ibatis.executor.statement.StatementHandler in project mybatis-3 by mybatis.

the class SimpleExecutor method doQuery.

@Override
public <E> List<E> doQuery(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
    Statement stmt = null;
    try {
        Configuration configuration = ms.getConfiguration();
        StatementHandler handler = configuration.newStatementHandler(wrapper, ms, parameter, rowBounds, resultHandler, boundSql);
        stmt = prepareStatement(handler, ms.getStatementLog());
        return handler.<E>query(stmt, resultHandler);
    } finally {
        closeStatement(stmt);
    }
}
Also used : Configuration(org.apache.ibatis.session.Configuration) MappedStatement(org.apache.ibatis.mapping.MappedStatement) Statement(java.sql.Statement) StatementHandler(org.apache.ibatis.executor.statement.StatementHandler)

Aggregations

StatementHandler (org.apache.ibatis.executor.statement.StatementHandler)10 Statement (java.sql.Statement)9 MappedStatement (org.apache.ibatis.mapping.MappedStatement)9 Configuration (org.apache.ibatis.session.Configuration)9 Connection (java.sql.Connection)3 RoutingStatementHandler (org.apache.ibatis.executor.statement.RoutingStatementHandler)1 BoundSql (org.apache.ibatis.mapping.BoundSql)1