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.List;
22
23 import org.apache.ibatis.cursor.Cursor;
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,
57 BoundSql boundSql) throws SQLException {
58 Statement stmt = null;
59 try {
60 Configuration configuration = ms.getConfiguration();
61 StatementHandler handler = configuration.newStatementHandler(wrapper, ms, parameter, rowBounds, resultHandler,
62 boundSql);
63 stmt = prepareStatement(handler, ms.getStatementLog());
64 return handler.query(stmt, resultHandler);
65 } finally {
66 closeStatement(stmt);
67 }
68 }
69
70 @Override
71 protected <E> Cursor<E> doQueryCursor(MappedStatement ms, Object parameter, RowBounds rowBounds, BoundSql boundSql)
72 throws SQLException {
73 Configuration configuration = ms.getConfiguration();
74 StatementHandler handler = configuration.newStatementHandler(wrapper, ms, parameter, rowBounds, null, boundSql);
75 Statement stmt = prepareStatement(handler, ms.getStatementLog());
76 Cursor<E> cursor = handler.queryCursor(stmt);
77 stmt.closeOnCompletion();
78 return cursor;
79 }
80
81 @Override
82 public List<BatchResult> doFlushStatements(boolean isRollback) {
83 return List.of();
84 }
85
86 private Statement prepareStatement(StatementHandler handler, Log statementLog) throws SQLException {
87 Statement stmt;
88 Connection connection = getConnection(statementLog);
89 stmt = handler.prepare(connection, transaction.getTimeout());
90 handler.parameterize(stmt);
91 return stmt;
92 }
93
94 }