001: /*
002: * Copyright (c) 1998-2005 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Sam
027: */
028:
029: package com.caucho.tools.profiler;
030:
031: import java.sql.Connection;
032: import java.sql.ResultSet;
033: import java.sql.SQLException;
034: import java.sql.SQLWarning;
035: import java.sql.Statement;
036:
037: public final class StatementWrapper implements Statement {
038: private final ProfilerPoint _parentProfilerPoint;
039: private final Statement _statement;
040:
041: private ProfilerPoint _profilerPoint;
042:
043: public StatementWrapper(ProfilerPoint profilerPoint,
044: Statement statement) {
045: _parentProfilerPoint = profilerPoint;
046: _profilerPoint = profilerPoint;
047: _statement = statement;
048: }
049:
050: private void setSql(String sql) {
051: _profilerPoint = _parentProfilerPoint.addProfilerPoint(sql);
052: }
053:
054: private ResultSet wrap(ResultSet resultSet) {
055: return new ResultSetWrapper(_profilerPoint, resultSet);
056: }
057:
058: public ResultSet executeQuery(String sql) throws SQLException {
059: setSql(sql);
060:
061: Profiler profiler = _profilerPoint.start();
062:
063: try {
064: return wrap(_statement.executeQuery(sql));
065: } finally {
066: profiler.finish();
067: }
068: }
069:
070: public int executeUpdate(String sql) throws SQLException {
071: setSql(sql);
072:
073: Profiler profiler = _profilerPoint.start();
074:
075: try {
076: return _statement.executeUpdate(sql);
077: } finally {
078: profiler.finish();
079: }
080: }
081:
082: public void close() throws SQLException {
083: Profiler profiler = _profilerPoint.start();
084:
085: try {
086: _statement.close();
087: } finally {
088: profiler.finish();
089: }
090: }
091:
092: public int getMaxFieldSize() throws SQLException {
093: Profiler profiler = _profilerPoint.start();
094:
095: try {
096: return _statement.getMaxFieldSize();
097: } finally {
098: profiler.finish();
099: }
100: }
101:
102: public void setMaxFieldSize(int max) throws SQLException {
103: Profiler profiler = _profilerPoint.start();
104:
105: try {
106: _statement.setMaxFieldSize(max);
107: } finally {
108: profiler.finish();
109: }
110: }
111:
112: public int getMaxRows() throws SQLException {
113: Profiler profiler = _profilerPoint.start();
114:
115: try {
116: return _statement.getMaxRows();
117: } finally {
118: profiler.finish();
119: }
120: }
121:
122: public void setMaxRows(int max) throws SQLException {
123: Profiler profiler = _profilerPoint.start();
124:
125: try {
126: _statement.setMaxRows(max);
127: } finally {
128: profiler.finish();
129: }
130: }
131:
132: public void setEscapeProcessing(boolean enable) throws SQLException {
133: Profiler profiler = _profilerPoint.start();
134:
135: try {
136: _statement.setEscapeProcessing(enable);
137: } finally {
138: profiler.finish();
139: }
140: }
141:
142: public int getQueryTimeout() throws SQLException {
143: Profiler profiler = _profilerPoint.start();
144:
145: try {
146: return _statement.getQueryTimeout();
147: } finally {
148: profiler.finish();
149: }
150: }
151:
152: public void setQueryTimeout(int seconds) throws SQLException {
153: Profiler profiler = _profilerPoint.start();
154:
155: try {
156: _statement.setQueryTimeout(seconds);
157: } finally {
158: profiler.finish();
159: }
160: }
161:
162: public void cancel() throws SQLException {
163: Profiler profiler = _profilerPoint.start();
164:
165: try {
166: _statement.cancel();
167: } finally {
168: profiler.finish();
169: }
170: }
171:
172: public SQLWarning getWarnings() throws SQLException {
173: Profiler profiler = _profilerPoint.start();
174:
175: try {
176: return _statement.getWarnings();
177: } finally {
178: profiler.finish();
179: }
180: }
181:
182: public void clearWarnings() throws SQLException {
183: Profiler profiler = _profilerPoint.start();
184:
185: try {
186: _statement.clearWarnings();
187: } finally {
188: profiler.finish();
189: }
190: }
191:
192: public void setCursorName(String name) throws SQLException {
193: Profiler profiler = _profilerPoint.start();
194:
195: try {
196: _statement.setCursorName(name);
197: } finally {
198: profiler.finish();
199: }
200: }
201:
202: public boolean execute(String sql) throws SQLException {
203: Profiler profiler = _profilerPoint.start();
204:
205: try {
206: return _statement.execute(sql);
207: } finally {
208: profiler.finish();
209: }
210: }
211:
212: public ResultSet getResultSet() throws SQLException {
213: return wrap(_statement.getResultSet());
214: }
215:
216: public int getUpdateCount() throws SQLException {
217: Profiler profiler = _profilerPoint.start();
218:
219: try {
220: return _statement.getUpdateCount();
221: } finally {
222: profiler.finish();
223: }
224: }
225:
226: public boolean getMoreResults() throws SQLException {
227: Profiler profiler = _profilerPoint.start();
228:
229: try {
230: return _statement.getMoreResults();
231: } finally {
232: profiler.finish();
233: }
234: }
235:
236: public void setFetchDirection(int direction) throws SQLException {
237: Profiler profiler = _profilerPoint.start();
238:
239: try {
240: _statement.setFetchDirection(direction);
241: } finally {
242: profiler.finish();
243: }
244: }
245:
246: public int getFetchDirection() throws SQLException {
247: Profiler profiler = _profilerPoint.start();
248:
249: try {
250: return _statement.getFetchDirection();
251: } finally {
252: profiler.finish();
253: }
254: }
255:
256: public void setFetchSize(int rows) throws SQLException {
257: Profiler profiler = _profilerPoint.start();
258:
259: try {
260: _statement.setFetchSize(rows);
261: } finally {
262: profiler.finish();
263: }
264: }
265:
266: public int getFetchSize() throws SQLException {
267: Profiler profiler = _profilerPoint.start();
268:
269: try {
270: return _statement.getFetchSize();
271: } finally {
272: profiler.finish();
273: }
274: }
275:
276: public int getResultSetConcurrency() throws SQLException {
277: Profiler profiler = _profilerPoint.start();
278:
279: try {
280: return _statement.getResultSetConcurrency();
281: } finally {
282: profiler.finish();
283: }
284: }
285:
286: public int getResultSetType() throws SQLException {
287: Profiler profiler = _profilerPoint.start();
288:
289: try {
290: return _statement.getResultSetType();
291: } finally {
292: profiler.finish();
293: }
294: }
295:
296: public void addBatch(String sql) throws SQLException {
297: Profiler profiler = _profilerPoint.start();
298:
299: try {
300: _statement.addBatch(sql);
301: } finally {
302: profiler.finish();
303: }
304: }
305:
306: public void clearBatch() throws SQLException {
307: Profiler profiler = _profilerPoint.start();
308:
309: try {
310: _statement.clearBatch();
311: } finally {
312: profiler.finish();
313: }
314: }
315:
316: public int[] executeBatch() throws SQLException {
317: Profiler profiler = _profilerPoint.start();
318:
319: try {
320: return _statement.executeBatch();
321: } finally {
322: profiler.finish();
323: }
324: }
325:
326: public Connection getConnection() throws SQLException {
327: Profiler profiler = _profilerPoint.start();
328:
329: try {
330: return _statement.getConnection();
331: } finally {
332: profiler.finish();
333: }
334: }
335:
336: public boolean getMoreResults(int current) throws SQLException {
337: Profiler profiler = _profilerPoint.start();
338:
339: try {
340: return _statement.getMoreResults(current);
341: } finally {
342: profiler.finish();
343: }
344: }
345:
346: public ResultSet getGeneratedKeys() throws SQLException {
347: return wrap(_statement.getGeneratedKeys());
348: }
349:
350: public int executeUpdate(String sql, int autoGeneratedKeys)
351: throws SQLException {
352: setSql(sql);
353:
354: Profiler profiler = _profilerPoint.start();
355:
356: try {
357: return _statement.executeUpdate(sql, autoGeneratedKeys);
358: } finally {
359: profiler.finish();
360: }
361: }
362:
363: public int executeUpdate(String sql, int[] columnIndexes)
364: throws SQLException {
365: setSql(sql);
366:
367: Profiler profiler = _profilerPoint.start();
368:
369: try {
370: return _statement.executeUpdate(sql, columnIndexes);
371: } finally {
372: profiler.finish();
373: }
374: }
375:
376: public int executeUpdate(String sql, String[] columnNames)
377: throws SQLException {
378: setSql(sql);
379:
380: Profiler profiler = _profilerPoint.start();
381:
382: try {
383: return _statement.executeUpdate(sql, columnNames);
384: } finally {
385: profiler.finish();
386: }
387: }
388:
389: public boolean execute(String sql, int autoGeneratedKeys)
390: throws SQLException {
391: setSql(sql);
392:
393: Profiler profiler = _profilerPoint.start();
394:
395: try {
396: return _statement.execute(sql, autoGeneratedKeys);
397: } finally {
398: profiler.finish();
399: }
400: }
401:
402: public boolean execute(String sql, int[] columnIndexes)
403: throws SQLException {
404: setSql(sql);
405:
406: Profiler profiler = _profilerPoint.start();
407:
408: try {
409: return _statement.execute(sql, columnIndexes);
410: } finally {
411: profiler.finish();
412: }
413: }
414:
415: public boolean execute(String sql, String[] columnNames)
416: throws SQLException {
417: setSql(sql);
418:
419: Profiler profiler = _profilerPoint.start();
420:
421: try {
422: return _statement.execute(sql, columnNames);
423: } finally {
424: profiler.finish();
425: }
426: }
427:
428: public int getResultSetHoldability() throws SQLException {
429: Profiler profiler = _profilerPoint.start();
430:
431: try {
432: return _statement.getResultSetHoldability();
433: } finally {
434: profiler.finish();
435: }
436: }
437:
438: public String toString() {
439: return "StatementWrapper[" + _profilerPoint.getName() + "]";
440: }
441:
442: public boolean isClosed() throws SQLException {
443: throw new UnsupportedOperationException("Not supported yet.");
444: }
445:
446: public void setPoolable(boolean poolable) throws SQLException {
447: throw new UnsupportedOperationException("Not supported yet.");
448: }
449:
450: public boolean isPoolable() throws SQLException {
451: throw new UnsupportedOperationException("Not supported yet.");
452: }
453:
454: public <T> T unwrap(Class<T> iface) throws SQLException {
455: throw new UnsupportedOperationException("Not supported yet.");
456: }
457:
458: public boolean isWrapperFor(Class<?> iface) throws SQLException {
459: throw new UnsupportedOperationException("Not supported yet.");
460: }
461: }
|