1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
package net.sf.infrared.aspects.jdbc.p6spy; |
23 |
|
|
24 |
|
import java.sql.Connection; |
25 |
|
import java.sql.ResultSet; |
26 |
|
import java.sql.SQLException; |
27 |
|
import java.sql.SQLWarning; |
28 |
|
import java.sql.Statement; |
29 |
|
|
30 |
|
import net.sf.infrared.agent.MonitorFactory; |
31 |
|
import net.sf.infrared.agent.StatisticsCollector; |
32 |
|
import net.sf.infrared.aspects.api.ApiContext; |
33 |
|
import net.sf.infrared.aspects.jdbc.SqlExecuteContext; |
34 |
|
import net.sf.infrared.base.model.ExecutionTimer; |
35 |
|
|
36 |
|
import com.p6spy.engine.spy.P6Connection; |
37 |
|
import com.p6spy.engine.spy.P6Statement; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
public class InfraREDP6Statement implements Statement { |
48 |
|
protected InfraREDP6Factory factory; |
49 |
|
|
50 |
|
protected P6Connection conn; |
51 |
|
|
52 |
|
protected Statement passThru; |
53 |
|
|
54 |
|
protected String query; |
55 |
|
|
56 |
|
protected P6Statement p6Statement; |
57 |
|
|
58 |
|
public InfraREDP6Statement(InfraREDP6Factory infraP6Factory, Statement statement, |
59 |
0 |
P6Connection conn) { |
60 |
0 |
this.factory = infraP6Factory; |
61 |
0 |
this.conn = conn; |
62 |
0 |
passThru = statement; |
63 |
0 |
} |
64 |
|
|
65 |
|
public ResultSet executeQuery(String sql) throws java.sql.SQLException { |
66 |
|
ResultSet resultSet; |
67 |
0 |
query = sql; |
68 |
|
|
69 |
0 |
if (factory.isJDBCMonitoringEnabled()) { |
70 |
0 |
SqlExecuteContext executeCtx = factory.getSqlContext(sql).getExecuteContext(); |
71 |
0 |
ExecutionTimer timer = new ExecutionTimer(executeCtx); |
72 |
|
|
73 |
0 |
StatisticsCollector col = MonitorFactory.getFacade().recordExecutionBegin(timer); |
74 |
|
try { |
75 |
0 |
resultSet = passThru.executeQuery(sql); |
76 |
|
} finally { |
77 |
0 |
MonitorFactory.getFacade().recordExecutionEnd(timer, col); |
78 |
0 |
} |
79 |
|
} else { |
80 |
0 |
resultSet = passThru.executeQuery(sql); |
81 |
|
} |
82 |
0 |
return factory.getResultSet(resultSet, getP6Statement(), query, query); |
83 |
|
} |
84 |
|
|
85 |
|
public int executeUpdate(String sql) throws java.sql.SQLException { |
86 |
0 |
query = sql; |
87 |
|
|
88 |
0 |
if (factory.isJDBCMonitoringEnabled()) { |
89 |
0 |
SqlExecuteContext executeCtx = factory.getSqlContext(sql).getExecuteContext(); |
90 |
0 |
ExecutionTimer timer = new ExecutionTimer(executeCtx); |
91 |
|
|
92 |
0 |
StatisticsCollector col = MonitorFactory.getFacade().recordExecutionBegin(timer); |
93 |
|
try { |
94 |
0 |
return passThru.executeUpdate(sql); |
95 |
|
} finally { |
96 |
0 |
MonitorFactory.getFacade().recordExecutionEnd(timer, col); |
97 |
|
} |
98 |
|
} else { |
99 |
0 |
return passThru.executeUpdate(sql); |
100 |
|
} |
101 |
|
} |
102 |
|
|
103 |
|
public void addBatch(String sql) throws java.sql.SQLException { |
104 |
0 |
query += "; " + sql; |
105 |
0 |
passThru.addBatch(sql); |
106 |
0 |
} |
107 |
|
|
108 |
|
public int[] executeBatch() throws java.sql.SQLException { |
109 |
0 |
if(query == null) { |
110 |
0 |
return passThru.executeBatch(); |
111 |
|
} |
112 |
0 |
if (factory.isJDBCMonitoringEnabled()) { |
113 |
0 |
SqlExecuteContext executeCtx = factory.getSqlContext(query).getExecuteContext(); |
114 |
0 |
ExecutionTimer timer = new ExecutionTimer(executeCtx); |
115 |
|
|
116 |
0 |
StatisticsCollector col = MonitorFactory.getFacade().recordExecutionBegin(timer); |
117 |
|
try { |
118 |
0 |
return passThru.executeBatch(); |
119 |
|
} finally { |
120 |
0 |
MonitorFactory.getFacade().recordExecutionEnd(timer, col); |
121 |
|
} |
122 |
|
} else { |
123 |
0 |
return passThru.executeBatch(); |
124 |
|
} |
125 |
|
} |
126 |
|
|
127 |
|
public int executeUpdate(String sql, class="keyword">int p1) throws java.sql.SQLException { |
128 |
0 |
if (factory.isJDBCMonitoringEnabled()) { |
129 |
0 |
SqlExecuteContext executeCtx = factory.getSqlContext(sql).getExecuteContext(); |
130 |
0 |
ExecutionTimer timer = new ExecutionTimer(executeCtx); |
131 |
|
|
132 |
0 |
StatisticsCollector col = MonitorFactory.getFacade().recordExecutionBegin(timer); |
133 |
|
try { |
134 |
0 |
return passThru.executeUpdate(sql, p1); |
135 |
|
} finally { |
136 |
0 |
MonitorFactory.getFacade().recordExecutionEnd(timer, col); |
137 |
|
} |
138 |
|
} else { |
139 |
0 |
return passThru.executeUpdate(sql, p1); |
140 |
|
} |
141 |
|
} |
142 |
|
|
143 |
|
public int executeUpdate(String sql, class="keyword">int p1[]) throws java.sql.SQLException { |
144 |
0 |
if (factory.isJDBCMonitoringEnabled()) { |
145 |
0 |
SqlExecuteContext executeCtx = factory.getSqlContext(sql).getExecuteContext(); |
146 |
0 |
ExecutionTimer timer = new ExecutionTimer(executeCtx); |
147 |
|
|
148 |
0 |
StatisticsCollector col = MonitorFactory.getFacade().recordExecutionBegin(timer); |
149 |
|
try { |
150 |
0 |
return passThru.executeUpdate(sql, p1); |
151 |
|
} finally { |
152 |
0 |
MonitorFactory.getFacade().recordExecutionEnd(timer, col); |
153 |
|
} |
154 |
|
} else { |
155 |
0 |
return passThru.executeUpdate(sql, p1); |
156 |
|
} |
157 |
|
} |
158 |
|
|
159 |
|
public int executeUpdate(String sql, String p1[]) throws java.sql.SQLException { |
160 |
0 |
if (factory.isJDBCMonitoringEnabled()) { |
161 |
0 |
SqlExecuteContext executeCtx = factory.getSqlContext(sql).getExecuteContext(); |
162 |
0 |
ExecutionTimer timer = new ExecutionTimer(executeCtx); |
163 |
|
|
164 |
0 |
StatisticsCollector col = MonitorFactory.getFacade().recordExecutionBegin(timer); |
165 |
|
try { |
166 |
0 |
return passThru.executeUpdate(sql, p1); |
167 |
|
} finally { |
168 |
0 |
MonitorFactory.getFacade().recordExecutionEnd(timer, col); |
169 |
|
} |
170 |
|
} else { |
171 |
0 |
return passThru.executeUpdate(sql, p1); |
172 |
|
} |
173 |
|
} |
174 |
|
|
175 |
|
public boolean execute(String sql, int p1) throws java.sql.SQLException { |
176 |
0 |
if (factory.isJDBCMonitoringEnabled()) { |
177 |
0 |
SqlExecuteContext executeCtx = factory.getExecuteContext(sql); |
178 |
0 |
ExecutionTimer timer = new ExecutionTimer(executeCtx); |
179 |
|
|
180 |
0 |
StatisticsCollector col = MonitorFactory.getFacade().recordExecutionBegin(timer); |
181 |
|
try { |
182 |
0 |
return passThru.execute(sql, p1); |
183 |
|
} finally { |
184 |
0 |
MonitorFactory.getFacade().recordExecutionEnd(timer, col); |
185 |
|
} |
186 |
|
} else { |
187 |
0 |
return passThru.execute(sql, p1); |
188 |
|
} |
189 |
|
} |
190 |
|
|
191 |
|
public boolean execute(String sql, int p1[]) throws java.sql.SQLException { |
192 |
0 |
if (factory.isJDBCMonitoringEnabled()) { |
193 |
0 |
SqlExecuteContext executeCtx = factory.getExecuteContext(sql); |
194 |
0 |
ExecutionTimer timer = new ExecutionTimer(executeCtx); |
195 |
|
|
196 |
0 |
StatisticsCollector col = MonitorFactory.getFacade().recordExecutionBegin(timer); |
197 |
|
try { |
198 |
0 |
return passThru.execute(sql, p1); |
199 |
|
} finally { |
200 |
0 |
MonitorFactory.getFacade().recordExecutionEnd(timer, col); |
201 |
|
} |
202 |
|
} else { |
203 |
0 |
return passThru.execute(sql, p1); |
204 |
|
} |
205 |
|
} |
206 |
|
|
207 |
|
public boolean execute(String sql, String p1[]) throws java.sql.SQLException { |
208 |
0 |
if (factory.isJDBCMonitoringEnabled()) { |
209 |
0 |
SqlExecuteContext executeCtx = factory.getExecuteContext(sql); |
210 |
0 |
ExecutionTimer timer = new ExecutionTimer(executeCtx); |
211 |
|
|
212 |
0 |
StatisticsCollector col = MonitorFactory.getFacade().recordExecutionBegin(timer); |
213 |
|
try { |
214 |
0 |
return passThru.execute(sql, p1); |
215 |
|
} finally { |
216 |
0 |
MonitorFactory.getFacade().recordExecutionEnd(timer, col); |
217 |
|
} |
218 |
|
} else { |
219 |
0 |
return passThru.execute(sql, p1); |
220 |
|
} |
221 |
|
} |
222 |
|
|
223 |
|
public void close() throws SQLException { |
224 |
0 |
if (factory.isJDBCMonitoringEnabled()) { |
225 |
0 |
final String methodName = "close"; |
226 |
0 |
ApiContext ctx = new ApiContext(Statement.class.getName(), methodName, "JDBC"); |
227 |
0 |
ExecutionTimer timer = new ExecutionTimer(ctx); |
228 |
0 |
StatisticsCollector col = MonitorFactory.getFacade().recordExecutionBegin(timer); |
229 |
|
try { |
230 |
0 |
passThru.close(); |
231 |
|
} finally { |
232 |
0 |
MonitorFactory.getFacade().recordExecutionEnd(timer, col); |
233 |
0 |
} |
234 |
|
} else { |
235 |
0 |
passThru.close(); |
236 |
|
} |
237 |
0 |
} |
238 |
|
|
239 |
|
public int getMaxFieldSize() throws SQLException { |
240 |
0 |
return passThru.getMaxFieldSize(); |
241 |
|
} |
242 |
|
|
243 |
|
public void setMaxFieldSize(int max) throws SQLException { |
244 |
0 |
passThru.setMaxFieldSize(max); |
245 |
0 |
} |
246 |
|
|
247 |
|
public int getMaxRows() throws SQLException { |
248 |
0 |
return passThru.getMaxRows(); |
249 |
|
} |
250 |
|
|
251 |
|
public void setMaxRows(int max) throws SQLException { |
252 |
0 |
passThru.setMaxRows(max); |
253 |
0 |
} |
254 |
|
|
255 |
|
public void setEscapeProcessing(boolean enable) throws SQLException { |
256 |
0 |
passThru.setEscapeProcessing(enable); |
257 |
0 |
} |
258 |
|
|
259 |
|
public int getQueryTimeout() throws SQLException { |
260 |
0 |
return passThru.getQueryTimeout(); |
261 |
|
} |
262 |
|
|
263 |
|
public void setQueryTimeout(int seconds) throws SQLException { |
264 |
0 |
passThru.setQueryTimeout(seconds); |
265 |
0 |
} |
266 |
|
|
267 |
|
public void cancel() throws SQLException { |
268 |
0 |
passThru.cancel(); |
269 |
0 |
} |
270 |
|
|
271 |
|
public SQLWarning getWarnings() throws SQLException { |
272 |
0 |
return passThru.getWarnings(); |
273 |
|
} |
274 |
|
|
275 |
|
public void clearWarnings() throws SQLException { |
276 |
0 |
passThru.clearWarnings(); |
277 |
0 |
} |
278 |
|
|
279 |
|
public void setCursorName(String name) throws SQLException { |
280 |
0 |
passThru.setCursorName(name); |
281 |
0 |
} |
282 |
|
|
283 |
|
public boolean execute(String sql) throws SQLException { |
284 |
0 |
if (factory.isJDBCMonitoringEnabled()) { |
285 |
0 |
SqlExecuteContext executeCtx = factory.getExecuteContext(sql); |
286 |
0 |
ExecutionTimer timer = new ExecutionTimer(executeCtx); |
287 |
|
|
288 |
0 |
StatisticsCollector col = MonitorFactory.getFacade().recordExecutionBegin(timer); |
289 |
|
try { |
290 |
0 |
return passThru.execute(sql); |
291 |
|
} finally { |
292 |
0 |
MonitorFactory.getFacade().recordExecutionEnd(timer, col); |
293 |
|
} |
294 |
|
} else { |
295 |
0 |
return passThru.execute(sql); |
296 |
|
} |
297 |
|
} |
298 |
|
|
299 |
|
public ResultSet getResultSet() throws SQLException { |
300 |
0 |
return factory.getResultSet(passThru.getResultSet(), getP6Statement(), query, query); |
301 |
|
} |
302 |
|
|
303 |
|
public int getUpdateCount() throws SQLException { |
304 |
0 |
return passThru.getUpdateCount(); |
305 |
|
} |
306 |
|
|
307 |
|
public boolean getMoreResults() throws SQLException { |
308 |
0 |
return passThru.getMoreResults(); |
309 |
|
} |
310 |
|
|
311 |
|
public void setFetchDirection(int direction) throws SQLException { |
312 |
0 |
passThru.setFetchDirection(direction); |
313 |
0 |
} |
314 |
|
|
315 |
|
public int getFetchDirection() throws SQLException { |
316 |
0 |
return passThru.getFetchDirection(); |
317 |
|
} |
318 |
|
|
319 |
|
public void setFetchSize(int rows) throws SQLException { |
320 |
0 |
passThru.setFetchSize(rows); |
321 |
0 |
} |
322 |
|
|
323 |
|
public int getFetchSize() throws SQLException { |
324 |
0 |
return passThru.getFetchSize(); |
325 |
|
} |
326 |
|
|
327 |
|
public int getResultSetConcurrency() throws SQLException { |
328 |
0 |
return passThru.getResultSetConcurrency(); |
329 |
|
} |
330 |
|
|
331 |
|
public int getResultSetType() throws SQLException { |
332 |
0 |
return passThru.getResultSetType(); |
333 |
|
} |
334 |
|
|
335 |
|
public void clearBatch() throws SQLException { |
336 |
0 |
passThru.clearBatch(); |
337 |
0 |
} |
338 |
|
|
339 |
|
public Connection getConnection() throws SQLException { |
340 |
0 |
return conn; |
341 |
|
} |
342 |
|
|
343 |
|
public boolean getMoreResults(int current) throws SQLException { |
344 |
0 |
return passThru.getMoreResults(current); |
345 |
|
} |
346 |
|
|
347 |
|
public ResultSet getGeneratedKeys() throws SQLException { |
348 |
0 |
return factory.getResultSet(passThru.getGeneratedKeys(), |
349 |
|
new P6Statement(factory, this, conn), "", query); |
350 |
|
} |
351 |
|
|
352 |
|
public int getResultSetHoldability() throws SQLException { |
353 |
0 |
return passThru.getResultSetHoldability(); |
354 |
|
} |
355 |
|
|
356 |
|
protected P6Statement getP6Statement() { |
357 |
0 |
if (p6Statement == null) { |
358 |
0 |
p6Statement = new P6Statement(factory, this, conn); |
359 |
|
} |
360 |
0 |
return p6Statement; |
361 |
|
} |
362 |
|
} |