KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > tools > profiler > StatementWrapper


1 /*
2  * Copyright (c) 1998-2005 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Sam
27  */

28
29
30 package com.caucho.tools.profiler;
31
32 import java.sql.Connection JavaDoc;
33 import java.sql.ResultSet JavaDoc;
34 import java.sql.SQLException JavaDoc;
35 import java.sql.SQLWarning JavaDoc;
36 import java.sql.Statement JavaDoc;
37
38 public final class StatementWrapper
39   implements Statement JavaDoc
40 {
41   private final ProfilerPoint _parentProfilerPoint;
42   private final Statement JavaDoc _statement;
43
44   private ProfilerPoint _profilerPoint;
45
46   public StatementWrapper(ProfilerPoint profilerPoint, Statement JavaDoc statement)
47   {
48     _parentProfilerPoint = profilerPoint;
49     _profilerPoint = profilerPoint;
50     _statement = statement;
51   }
52
53   private void setSql(String JavaDoc sql)
54   {
55     _profilerPoint = _parentProfilerPoint.createProfilerPoint(sql);
56   }
57
58   private ResultSet JavaDoc wrap(ResultSet JavaDoc resultSet)
59   {
60     return new ResultSetWrapper(_profilerPoint, resultSet);
61   }
62
63   public ResultSet JavaDoc executeQuery(String JavaDoc sql)
64     throws SQLException JavaDoc
65   {
66     setSql(sql);
67
68     Profiler profiler = _profilerPoint.start();
69
70     try {
71       return wrap(_statement.executeQuery(sql));
72     }
73     finally {
74       profiler.finish();
75     }
76   }
77
78   public int executeUpdate(String JavaDoc sql)
79     throws SQLException JavaDoc
80   {
81     setSql(sql);
82
83     Profiler profiler = _profilerPoint.start();
84
85     try {
86       return _statement.executeUpdate(sql);
87     }
88     finally {
89       profiler.finish();
90     }
91   }
92
93   public void close()
94     throws SQLException JavaDoc
95   {
96     Profiler profiler = _profilerPoint.start();
97
98     try {
99       _statement.close();
100     }
101     finally {
102       profiler.finish();
103     }
104   }
105
106   public int getMaxFieldSize()
107     throws SQLException JavaDoc
108   {
109     Profiler profiler = _profilerPoint.start();
110
111     try {
112       return _statement.getMaxFieldSize();
113     }
114     finally {
115       profiler.finish();
116     }
117   }
118
119   public void setMaxFieldSize(int max)
120     throws SQLException JavaDoc
121   {
122     Profiler profiler = _profilerPoint.start();
123
124     try {
125       _statement.setMaxFieldSize(max);
126     }
127     finally {
128       profiler.finish();
129     }
130   }
131
132   public int getMaxRows()
133     throws SQLException JavaDoc
134   {
135     Profiler profiler = _profilerPoint.start();
136
137     try {
138       return _statement.getMaxRows();
139     }
140     finally {
141       profiler.finish();
142     }
143   }
144
145   public void setMaxRows(int max)
146     throws SQLException JavaDoc
147   {
148     Profiler profiler = _profilerPoint.start();
149
150     try {
151       _statement.setMaxRows(max);
152     }
153     finally {
154       profiler.finish();
155     }
156   }
157
158   public void setEscapeProcessing(boolean enable)
159     throws SQLException JavaDoc
160   {
161     Profiler profiler = _profilerPoint.start();
162
163     try {
164       _statement.setEscapeProcessing(enable);
165     }
166     finally {
167       profiler.finish();
168     }
169   }
170
171   public int getQueryTimeout()
172     throws SQLException JavaDoc
173   {
174     Profiler profiler = _profilerPoint.start();
175
176     try {
177       return _statement.getQueryTimeout();
178     }
179     finally {
180       profiler.finish();
181     }
182   }
183
184   public void setQueryTimeout(int seconds)
185     throws SQLException JavaDoc
186   {
187     Profiler profiler = _profilerPoint.start();
188
189     try {
190       _statement.setQueryTimeout(seconds);
191     }
192     finally {
193       profiler.finish();
194     }
195   }
196
197   public void cancel()
198     throws SQLException JavaDoc
199   {
200     Profiler profiler = _profilerPoint.start();
201
202     try {
203       _statement.cancel();
204     }
205     finally {
206       profiler.finish();
207     }
208   }
209
210   public SQLWarning JavaDoc getWarnings()
211     throws SQLException JavaDoc
212   {
213     Profiler profiler = _profilerPoint.start();
214
215     try {
216       return _statement.getWarnings();
217     }
218     finally {
219       profiler.finish();
220     }
221   }
222
223   public void clearWarnings()
224     throws SQLException JavaDoc
225   {
226     Profiler profiler = _profilerPoint.start();
227
228     try {
229       _statement.clearWarnings();
230     }
231     finally {
232       profiler.finish();
233     }
234   }
235
236   public void setCursorName(String JavaDoc name)
237     throws SQLException JavaDoc
238   {
239     Profiler profiler = _profilerPoint.start();
240
241     try {
242       _statement.setCursorName(name);
243     }
244     finally {
245       profiler.finish();
246     }
247   }
248
249   public boolean execute(String JavaDoc sql)
250     throws SQLException JavaDoc
251   {
252     Profiler profiler = _profilerPoint.start();
253
254     try {
255       return _statement.execute(sql);
256     }
257     finally {
258       profiler.finish();
259     }
260   }
261
262   public ResultSet JavaDoc getResultSet()
263     throws SQLException JavaDoc
264   {
265     return wrap(_statement.getResultSet());
266   }
267
268   public int getUpdateCount()
269     throws SQLException JavaDoc
270   {
271     Profiler profiler = _profilerPoint.start();
272
273     try {
274       return _statement.getUpdateCount();
275     }
276     finally {
277       profiler.finish();
278     }
279   }
280
281   public boolean getMoreResults()
282     throws SQLException JavaDoc
283   {
284     Profiler profiler = _profilerPoint.start();
285
286     try {
287       return _statement.getMoreResults();
288     }
289     finally {
290       profiler.finish();
291     }
292   }
293
294   public void setFetchDirection(int direction)
295     throws SQLException JavaDoc
296   {
297     Profiler profiler = _profilerPoint.start();
298
299     try {
300       _statement.setFetchDirection(direction);
301     }
302     finally {
303       profiler.finish();
304     }
305   }
306
307   public int getFetchDirection()
308     throws SQLException JavaDoc
309   {
310     Profiler profiler = _profilerPoint.start();
311
312     try {
313       return _statement.getFetchDirection();
314     }
315     finally {
316       profiler.finish();
317     }
318   }
319
320   public void setFetchSize(int rows)
321     throws SQLException JavaDoc
322   {
323     Profiler profiler = _profilerPoint.start();
324
325     try {
326       _statement.setFetchSize(rows);
327     }
328     finally {
329       profiler.finish();
330     }
331   }
332
333   public int getFetchSize()
334     throws SQLException JavaDoc
335   {
336     Profiler profiler = _profilerPoint.start();
337
338     try {
339       return _statement.getFetchSize();
340     }
341     finally {
342       profiler.finish();
343     }
344   }
345
346   public int getResultSetConcurrency()
347     throws SQLException JavaDoc
348   {
349     Profiler profiler = _profilerPoint.start();
350
351     try {
352       return _statement.getResultSetConcurrency();
353     }
354     finally {
355       profiler.finish();
356     }
357   }
358
359   public int getResultSetType()
360     throws SQLException JavaDoc
361   {
362     Profiler profiler = _profilerPoint.start();
363
364     try {
365       return _statement.getResultSetType();
366     }
367     finally {
368       profiler.finish();
369     }
370   }
371
372   public void addBatch(String JavaDoc sql)
373     throws SQLException JavaDoc
374   {
375     Profiler profiler = _profilerPoint.start();
376
377     try {
378       _statement.addBatch(sql);
379     }
380     finally {
381       profiler.finish();
382     }
383   }
384
385   public void clearBatch()
386     throws SQLException JavaDoc
387   {
388     Profiler profiler = _profilerPoint.start();
389
390     try {
391       _statement.clearBatch();
392     }
393     finally {
394       profiler.finish();
395     }
396   }
397
398   public int[] executeBatch()
399     throws SQLException JavaDoc
400   {
401     Profiler profiler = _profilerPoint.start();
402
403     try {
404       return _statement.executeBatch();
405     }
406     finally {
407       profiler.finish();
408     }
409   }
410
411   public Connection JavaDoc getConnection()
412     throws SQLException JavaDoc
413   {
414     Profiler profiler = _profilerPoint.start();
415
416     try {
417       return _statement.getConnection();
418     }
419     finally {
420       profiler.finish();
421     }
422   }
423
424   public boolean getMoreResults(int current)
425     throws SQLException JavaDoc
426   {
427     Profiler profiler = _profilerPoint.start();
428
429     try {
430       return _statement.getMoreResults(current);
431     }
432     finally {
433       profiler.finish();
434     }
435   }
436
437   public ResultSet JavaDoc getGeneratedKeys()
438     throws SQLException JavaDoc
439   {
440     return wrap(_statement.getGeneratedKeys());
441   }
442
443   public int executeUpdate(String JavaDoc sql, int autoGeneratedKeys)
444     throws SQLException JavaDoc
445   {
446     setSql(sql);
447
448     Profiler profiler = _profilerPoint.start();
449
450     try {
451       return _statement.executeUpdate(sql, autoGeneratedKeys);
452     }
453     finally {
454       profiler.finish();
455     }
456   }
457
458   public int executeUpdate(String JavaDoc sql, int[] columnIndexes)
459     throws SQLException JavaDoc
460   {
461     setSql(sql);
462
463     Profiler profiler = _profilerPoint.start();
464
465     try {
466       return _statement.executeUpdate(sql, columnIndexes);
467     }
468     finally {
469       profiler.finish();
470     }
471   }
472
473   public int executeUpdate(String JavaDoc sql, String JavaDoc[] columnNames)
474     throws SQLException JavaDoc
475   {
476     setSql(sql);
477
478     Profiler profiler = _profilerPoint.start();
479
480     try {
481       return _statement.executeUpdate(sql, columnNames);
482     }
483     finally {
484       profiler.finish();
485     }
486   }
487
488   public boolean execute(String JavaDoc sql, int autoGeneratedKeys)
489     throws SQLException JavaDoc
490   {
491     setSql(sql);
492
493     Profiler profiler = _profilerPoint.start();
494
495     try {
496       return _statement.execute(sql, autoGeneratedKeys);
497     }
498     finally {
499       profiler.finish();
500     }
501   }
502
503   public boolean execute(String JavaDoc sql, int[] columnIndexes)
504     throws SQLException JavaDoc
505   {
506     setSql(sql);
507
508     Profiler profiler = _profilerPoint.start();
509
510     try {
511       return _statement.execute(sql, columnIndexes);
512     }
513     finally {
514       profiler.finish();
515     }
516   }
517
518   public boolean execute(String JavaDoc sql, String JavaDoc[] columnNames)
519     throws SQLException JavaDoc
520   {
521     setSql(sql);
522
523     Profiler profiler = _profilerPoint.start();
524
525     try {
526       return _statement.execute(sql, columnNames);
527     }
528     finally {
529       profiler.finish();
530     }
531   }
532
533   public int getResultSetHoldability()
534     throws SQLException JavaDoc
535   {
536     Profiler profiler = _profilerPoint.start();
537
538     try {
539       return _statement.getResultSetHoldability();
540     }
541     finally {
542       profiler.finish();
543     }
544   }
545
546   public String JavaDoc toString()
547   {
548     return "StatementWrapper[" + _profilerPoint.getName() + "]";
549   }
550 }
551
Popular Tags