1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.dbutils;
18
19 import java.lang.reflect.InvocationHandler;
20 import java.lang.reflect.Proxy;
21 import java.sql.CallableStatement;
22 import java.sql.Connection;
23 import java.sql.Driver;
24 import java.sql.PreparedStatement;
25 import java.sql.ResultSet;
26 import java.sql.ResultSetMetaData;
27 import java.sql.Statement;
28
29
30
31
32
33
34
35
36
37 public class ProxyFactory {
38
39
40
41
42 private static final Class[] callableStatementClass =
43 new Class[] { CallableStatement.class };
44
45
46
47
48 private static final Class[] connectionClass =
49 new Class[] { Connection.class };
50
51
52
53
54 private static final Class[] driverClass = new Class[] { Driver.class };
55
56
57
58
59 private static final ProxyFactory instance = new ProxyFactory();
60
61
62
63
64 private static final Class[] metaClass =
65 new Class[] { ResultSetMetaData.class };
66
67
68
69
70 private static final Class[] preparedStatementClass =
71 new Class[] { PreparedStatement.class };
72
73
74
75
76 private static final Class[] resultSetClass =
77 new Class[] { ResultSet.class };
78
79
80
81
82 private static final Class[] statementClass =
83 new Class[] { Statement.class };
84
85
86
87
88
89
90 public static ProxyFactory instance() {
91 return instance;
92 }
93
94
95
96
97 protected ProxyFactory() {
98 super();
99 }
100
101
102
103
104
105
106 public CallableStatement createCallableStatement(InvocationHandler handler) {
107 return (CallableStatement) Proxy.newProxyInstance(
108 handler.getClass().getClassLoader(),
109 callableStatementClass,
110 handler);
111 }
112
113
114
115
116
117
118 public Connection createConnection(InvocationHandler handler) {
119 return (Connection) Proxy.newProxyInstance(
120 handler.getClass().getClassLoader(),
121 connectionClass,
122 handler);
123 }
124
125
126
127
128
129
130 public Driver createDriver(InvocationHandler handler) {
131 return (Driver) Proxy.newProxyInstance(
132 handler.getClass().getClassLoader(),
133 driverClass,
134 handler);
135 }
136
137
138
139
140
141
142 public PreparedStatement createPreparedStatement(InvocationHandler handler) {
143 return (PreparedStatement) Proxy.newProxyInstance(
144 handler.getClass().getClassLoader(),
145 preparedStatementClass,
146 handler);
147 }
148
149
150
151
152
153
154 public ResultSet createResultSet(InvocationHandler handler) {
155 return (ResultSet) Proxy.newProxyInstance(
156 handler.getClass().getClassLoader(),
157 resultSetClass,
158 handler);
159 }
160
161
162
163
164
165
166 public ResultSetMetaData createResultSetMetaData(InvocationHandler handler) {
167 return (ResultSetMetaData) Proxy.newProxyInstance(
168 handler.getClass().getClassLoader(),
169 metaClass,
170 handler);
171 }
172
173
174
175
176
177
178 public Statement createStatement(InvocationHandler handler) {
179 return (Statement) Proxy.newProxyInstance(
180 handler.getClass().getClassLoader(),
181 statementClass,
182 handler);
183 }
184
185 }