1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.executor.statement;
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.Executor;
25 import org.apache.ibatis.executor.ExecutorException;
26 import org.apache.ibatis.executor.parameter.ParameterHandler;
27 import org.apache.ibatis.mapping.BoundSql;
28 import org.apache.ibatis.mapping.MappedStatement;
29 import org.apache.ibatis.session.ResultHandler;
30 import org.apache.ibatis.session.RowBounds;
31
32
33
34
35 public class RoutingStatementHandler implements StatementHandler {
36
37 private final StatementHandler delegate;
38
39 public RoutingStatementHandler(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
40
41 switch (ms.getStatementType()) {
42 case STATEMENT:
43 delegate = new SimpleStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
44 break;
45 case PREPARED:
46 delegate = new PreparedStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
47 break;
48 case CALLABLE:
49 delegate = new CallableStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
50 break;
51 default:
52 throw new ExecutorException("Unknown statement type: " + ms.getStatementType());
53 }
54
55 }
56
57 @Override
58 public Statement prepare(Connection connection, Integer transactionTimeout) throws SQLException {
59 return delegate.prepare(connection, transactionTimeout);
60 }
61
62 @Override
63 public void parameterize(Statement statement) throws SQLException {
64 delegate.parameterize(statement);
65 }
66
67 @Override
68 public void batch(Statement statement) throws SQLException {
69 delegate.batch(statement);
70 }
71
72 @Override
73 public int update(Statement statement) throws SQLException {
74 return delegate.update(statement);
75 }
76
77 @Override
78 public <E> List<E> query(Statement statement, ResultHandler resultHandler) throws SQLException {
79 return delegate.query(statement, resultHandler);
80 }
81
82 @Override
83 public <E> Cursor<E> queryCursor(Statement statement) throws SQLException {
84 return delegate.queryCursor(statement);
85 }
86
87 @Override
88 public BoundSql getBoundSql() {
89 return delegate.getBoundSql();
90 }
91
92 @Override
93 public ParameterHandler getParameterHandler() {
94 return delegate.getParameterHandler();
95 }
96 }