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