1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.executor;
17
18 import java.sql.Connection;
19 import java.sql.SQLException;
20 import java.sql.Statement;
21 import java.util.Collections;
22 import java.util.List;
23
24 import org.apache.ibatis.executor.statement.StatementHandler;
25 import org.apache.ibatis.logging.Log;
26 import org.apache.ibatis.mapping.BoundSql;
27 import org.apache.ibatis.mapping.MappedStatement;
28 import org.apache.ibatis.session.Configuration;
29 import org.apache.ibatis.session.ResultHandler;
30 import org.apache.ibatis.session.RowBounds;
31 import org.apache.ibatis.transaction.Transaction;
32
33
34
35
36 public class SimpleExecutor extends BaseExecutor {
37
38 public SimpleExecutor(Configuration configuration, Transaction transaction) {
39 super(configuration, transaction);
40 }
41
42 @Override
43 public int doUpdate(MappedStatement ms, Object parameter) throws SQLException {
44 Statement stmt = null;
45 try {
46 Configuration configuration = ms.getConfiguration();
47 StatementHandler handler = configuration.newStatementHandler(this, ms, parameter, RowBounds.DEFAULT, null, null);
48 stmt = prepareStatement(handler, ms.getStatementLog());
49 return handler.update(stmt);
50 } finally {
51 closeStatement(stmt);
52 }
53 }
54
55 @Override
56 public <E> List<E> doQuery(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
57 Statement stmt = null;
58 try {
59 Configuration configuration = ms.getConfiguration();
60 StatementHandler handler = configuration.newStatementHandler(wrapper, ms, parameter, rowBounds, resultHandler, boundSql);
61 stmt = prepareStatement(handler, ms.getStatementLog());
62 return handler.<E>query(stmt, resultHandler);
63 } finally {
64 closeStatement(stmt);
65 }
66 }
67
68 @Override
69 public List<BatchResult> doFlushStatements(boolean isRollback) throws SQLException {
70 return Collections.emptyList();
71 }
72
73 private Statement prepareStatement(StatementHandler handler, Log statementLog) throws SQLException {
74 Statement stmt;
75 Connection connection = getConnection(statementLog);
76 stmt = handler.prepare(connection);
77 handler.parameterize(stmt);
78 return stmt;
79 }
80
81 }