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.io.InputStream;
032: import java.io.Reader;
033: import java.math.BigDecimal;
034: import java.net.URL;
035: import java.sql.*;
036: import java.util.Calendar;
037:
038: public class PreparedStatementWrapper implements PreparedStatement {
039: private final PreparedStatement _preparedStatement;
040: private ProfilerPoint _profilerPoint;
041:
042: public PreparedStatementWrapper(ProfilerPoint profilerPoint,
043: PreparedStatement preparedStatement) {
044: _profilerPoint = profilerPoint;
045: _preparedStatement = preparedStatement;
046: }
047:
048: public ResultSet executeQuery() throws SQLException {
049: Profiler profiler = _profilerPoint.start();
050:
051: try {
052: return _preparedStatement.executeQuery();
053: } finally {
054: profiler.finish();
055: }
056: }
057:
058: public int executeUpdate() throws SQLException {
059: Profiler profiler = _profilerPoint.start();
060:
061: try {
062: return _preparedStatement.executeUpdate();
063: } finally {
064: profiler.finish();
065: }
066: }
067:
068: public void setNull(int parameterIndex, int sqlType)
069: throws SQLException {
070: Profiler profiler = _profilerPoint.start();
071:
072: try {
073: _preparedStatement.setNull(parameterIndex, sqlType);
074: } finally {
075: profiler.finish();
076: }
077: }
078:
079: public void setBoolean(int parameterIndex, boolean x)
080: throws SQLException {
081: Profiler profiler = _profilerPoint.start();
082:
083: try {
084: _preparedStatement.setBoolean(parameterIndex, x);
085: } finally {
086: profiler.finish();
087: }
088: }
089:
090: public void setByte(int parameterIndex, byte x) throws SQLException {
091: Profiler profiler = _profilerPoint.start();
092:
093: try {
094: _preparedStatement.setByte(parameterIndex, x);
095: } finally {
096: profiler.finish();
097: }
098: }
099:
100: public void setShort(int parameterIndex, short x)
101: throws SQLException {
102: Profiler profiler = _profilerPoint.start();
103:
104: try {
105: _preparedStatement.setShort(parameterIndex, x);
106: } finally {
107: profiler.finish();
108: }
109: }
110:
111: public void setInt(int parameterIndex, int x) throws SQLException {
112: Profiler profiler = _profilerPoint.start();
113:
114: try {
115: _preparedStatement.setInt(parameterIndex, x);
116: } finally {
117: profiler.finish();
118: }
119: }
120:
121: public void setLong(int parameterIndex, long x) throws SQLException {
122: Profiler profiler = _profilerPoint.start();
123:
124: try {
125: _preparedStatement.setLong(parameterIndex, x);
126: } finally {
127: profiler.finish();
128: }
129: }
130:
131: public void setFloat(int parameterIndex, float x)
132: throws SQLException {
133: Profiler profiler = _profilerPoint.start();
134:
135: try {
136: _preparedStatement.setFloat(parameterIndex, x);
137: } finally {
138: profiler.finish();
139: }
140: }
141:
142: public void setDouble(int parameterIndex, double x)
143: throws SQLException {
144: Profiler profiler = _profilerPoint.start();
145:
146: try {
147: _preparedStatement.setDouble(parameterIndex, x);
148: } finally {
149: profiler.finish();
150: }
151: }
152:
153: public void setBigDecimal(int parameterIndex, BigDecimal x)
154: throws SQLException {
155: Profiler profiler = _profilerPoint.start();
156:
157: try {
158: _preparedStatement.setBigDecimal(parameterIndex, x);
159: } finally {
160: profiler.finish();
161: }
162: }
163:
164: public void setString(int parameterIndex, String x)
165: throws SQLException {
166: Profiler profiler = _profilerPoint.start();
167:
168: try {
169: _preparedStatement.setString(parameterIndex, x);
170: } finally {
171: profiler.finish();
172: }
173: }
174:
175: public void setBytes(int parameterIndex, byte[] x)
176: throws SQLException {
177: Profiler profiler = _profilerPoint.start();
178:
179: try {
180: _preparedStatement.setBytes(parameterIndex, x);
181: } finally {
182: profiler.finish();
183: }
184: }
185:
186: public void setDate(int parameterIndex, Date x) throws SQLException {
187: Profiler profiler = _profilerPoint.start();
188:
189: try {
190: _preparedStatement.setDate(parameterIndex, x);
191: } finally {
192: profiler.finish();
193: }
194: }
195:
196: public void setTime(int parameterIndex, Time x) throws SQLException {
197: Profiler profiler = _profilerPoint.start();
198:
199: try {
200: _preparedStatement.setTime(parameterIndex, x);
201: } finally {
202: profiler.finish();
203: }
204: }
205:
206: public void setTimestamp(int parameterIndex, Timestamp x)
207: throws SQLException {
208: Profiler profiler = _profilerPoint.start();
209:
210: try {
211: _preparedStatement.setTimestamp(parameterIndex, x);
212: } finally {
213: profiler.finish();
214: }
215: }
216:
217: public void setAsciiStream(int parameterIndex, InputStream x,
218: int length) throws SQLException {
219: Profiler profiler = _profilerPoint.start();
220:
221: try {
222: _preparedStatement
223: .setAsciiStream(parameterIndex, x, length);
224: } finally {
225: profiler.finish();
226: }
227: }
228:
229: public void setUnicodeStream(int parameterIndex, InputStream x,
230: int length) throws SQLException {
231: Profiler profiler = _profilerPoint.start();
232:
233: try {
234: _preparedStatement.setUnicodeStream(parameterIndex, x,
235: length);
236: } finally {
237: profiler.finish();
238: }
239: }
240:
241: public void setBinaryStream(int parameterIndex, InputStream x,
242: int length) throws SQLException {
243: Profiler profiler = _profilerPoint.start();
244:
245: try {
246: _preparedStatement.setBinaryStream(parameterIndex, x,
247: length);
248: } finally {
249: profiler.finish();
250: }
251: }
252:
253: public void clearParameters() throws SQLException {
254: Profiler profiler = _profilerPoint.start();
255:
256: try {
257: _preparedStatement.clearParameters();
258: } finally {
259: profiler.finish();
260: }
261: }
262:
263: public void setObject(int parameterIndex, Object x,
264: int targetSqlType, int scale) throws SQLException {
265: Profiler profiler = _profilerPoint.start();
266:
267: try {
268: _preparedStatement.setObject(parameterIndex, x,
269: targetSqlType, scale);
270: } finally {
271: profiler.finish();
272: }
273: }
274:
275: public void setObject(int parameterIndex, Object x,
276: int targetSqlType) throws SQLException {
277: Profiler profiler = _profilerPoint.start();
278:
279: try {
280: _preparedStatement.setObject(parameterIndex, x,
281: targetSqlType);
282: } finally {
283: profiler.finish();
284: }
285: }
286:
287: public void setObject(int parameterIndex, Object x)
288: throws SQLException {
289: Profiler profiler = _profilerPoint.start();
290:
291: try {
292: _preparedStatement.setObject(parameterIndex, x);
293: } finally {
294: profiler.finish();
295: }
296: }
297:
298: public boolean execute() throws SQLException {
299: Profiler profiler = _profilerPoint.start();
300:
301: try {
302: return _preparedStatement.execute();
303: } finally {
304: profiler.finish();
305: }
306: }
307:
308: public void addBatch() throws SQLException {
309: Profiler profiler = _profilerPoint.start();
310:
311: try {
312: _preparedStatement.addBatch();
313: } finally {
314: profiler.finish();
315: }
316: }
317:
318: public void setCharacterStream(int parameterIndex, Reader reader,
319: int length) throws SQLException {
320: Profiler profiler = _profilerPoint.start();
321:
322: try {
323: _preparedStatement.setCharacterStream(parameterIndex,
324: reader, length);
325: } finally {
326: profiler.finish();
327: }
328: }
329:
330: public void setRef(int i, Ref x) throws SQLException {
331: Profiler profiler = _profilerPoint.start();
332:
333: try {
334: _preparedStatement.setRef(i, x);
335: } finally {
336: profiler.finish();
337: }
338: }
339:
340: public void setBlob(int i, Blob x) throws SQLException {
341: Profiler profiler = _profilerPoint.start();
342:
343: try {
344: _preparedStatement.setBlob(i, x);
345: } finally {
346: profiler.finish();
347: }
348: }
349:
350: public void setClob(int i, Clob x) throws SQLException {
351: Profiler profiler = _profilerPoint.start();
352:
353: try {
354: _preparedStatement.setClob(i, x);
355: } finally {
356: profiler.finish();
357: }
358: }
359:
360: public void setArray(int i, Array x) throws SQLException {
361: Profiler profiler = _profilerPoint.start();
362:
363: try {
364: _preparedStatement.setArray(i, x);
365: } finally {
366: profiler.finish();
367: }
368: }
369:
370: public ResultSetMetaData getMetaData() throws SQLException {
371: Profiler profiler = _profilerPoint.start();
372:
373: try {
374: return _preparedStatement.getMetaData();
375: } finally {
376: profiler.finish();
377: }
378: }
379:
380: public void setDate(int parameterIndex, Date x, Calendar cal)
381: throws SQLException {
382: Profiler profiler = _profilerPoint.start();
383:
384: try {
385: _preparedStatement.setDate(parameterIndex, x, cal);
386: } finally {
387: profiler.finish();
388: }
389: }
390:
391: public void setTime(int parameterIndex, Time x, Calendar cal)
392: throws SQLException {
393: Profiler profiler = _profilerPoint.start();
394:
395: try {
396: _preparedStatement.setTime(parameterIndex, x, cal);
397: } finally {
398: profiler.finish();
399: }
400: }
401:
402: public void setTimestamp(int parameterIndex, Timestamp x,
403: Calendar cal) throws SQLException {
404: Profiler profiler = _profilerPoint.start();
405:
406: try {
407: _preparedStatement.setTimestamp(parameterIndex, x, cal);
408: } finally {
409: profiler.finish();
410: }
411: }
412:
413: public void setNull(int paramIndex, int sqlType, String typeName)
414: throws SQLException {
415: Profiler profiler = _profilerPoint.start();
416:
417: try {
418: _preparedStatement.setNull(paramIndex, sqlType, typeName);
419: } finally {
420: profiler.finish();
421: }
422: }
423:
424: public void setURL(int parameterIndex, URL x) throws SQLException {
425: Profiler profiler = _profilerPoint.start();
426:
427: try {
428: _preparedStatement.setURL(parameterIndex, x);
429: } finally {
430: profiler.finish();
431: }
432: }
433:
434: public ParameterMetaData getParameterMetaData() throws SQLException {
435: Profiler profiler = _profilerPoint.start();
436:
437: try {
438: return _preparedStatement.getParameterMetaData();
439: } finally {
440: profiler.finish();
441: }
442: }
443:
444: public ResultSet executeQuery(String sql) throws SQLException {
445: Profiler profiler = _profilerPoint.start();
446:
447: try {
448: return _preparedStatement.executeQuery(sql);
449: } finally {
450: profiler.finish();
451: }
452: }
453:
454: public int executeUpdate(String sql) throws SQLException {
455: Profiler profiler = _profilerPoint.start();
456:
457: try {
458: return _preparedStatement.executeUpdate(sql);
459: } finally {
460: profiler.finish();
461: }
462: }
463:
464: public void close() throws SQLException {
465: Profiler profiler = _profilerPoint.start();
466:
467: try {
468: _preparedStatement.close();
469: } finally {
470: profiler.finish();
471: }
472: }
473:
474: public int getMaxFieldSize() throws SQLException {
475: Profiler profiler = _profilerPoint.start();
476:
477: try {
478: return _preparedStatement.getMaxFieldSize();
479: } finally {
480: profiler.finish();
481: }
482: }
483:
484: public void setMaxFieldSize(int max) throws SQLException {
485: Profiler profiler = _profilerPoint.start();
486:
487: try {
488: _preparedStatement.setMaxFieldSize(max);
489: } finally {
490: profiler.finish();
491: }
492: }
493:
494: public int getMaxRows() throws SQLException {
495: Profiler profiler = _profilerPoint.start();
496:
497: try {
498: return _preparedStatement.getMaxRows();
499: } finally {
500: profiler.finish();
501: }
502: }
503:
504: public void setMaxRows(int max) throws SQLException {
505: Profiler profiler = _profilerPoint.start();
506:
507: try {
508: _preparedStatement.setMaxRows(max);
509: } finally {
510: profiler.finish();
511: }
512: }
513:
514: public void setEscapeProcessing(boolean enable) throws SQLException {
515: Profiler profiler = _profilerPoint.start();
516:
517: try {
518: _preparedStatement.setEscapeProcessing(enable);
519: } finally {
520: profiler.finish();
521: }
522: }
523:
524: public int getQueryTimeout() throws SQLException {
525: Profiler profiler = _profilerPoint.start();
526:
527: try {
528: return _preparedStatement.getQueryTimeout();
529: } finally {
530: profiler.finish();
531: }
532: }
533:
534: public void setQueryTimeout(int seconds) throws SQLException {
535: Profiler profiler = _profilerPoint.start();
536:
537: try {
538: _preparedStatement.setQueryTimeout(seconds);
539: } finally {
540: profiler.finish();
541: }
542: }
543:
544: public void cancel() throws SQLException {
545: Profiler profiler = _profilerPoint.start();
546:
547: try {
548: _preparedStatement.cancel();
549: } finally {
550: profiler.finish();
551: }
552: }
553:
554: public SQLWarning getWarnings() throws SQLException {
555: Profiler profiler = _profilerPoint.start();
556:
557: try {
558: return _preparedStatement.getWarnings();
559: } finally {
560: profiler.finish();
561: }
562: }
563:
564: public void clearWarnings() throws SQLException {
565: Profiler profiler = _profilerPoint.start();
566:
567: try {
568: _preparedStatement.clearWarnings();
569: } finally {
570: profiler.finish();
571: }
572: }
573:
574: public void setCursorName(String name) throws SQLException {
575: Profiler profiler = _profilerPoint.start();
576:
577: try {
578: _preparedStatement.setCursorName(name);
579: } finally {
580: profiler.finish();
581: }
582: }
583:
584: public boolean execute(String sql) throws SQLException {
585: Profiler profiler = _profilerPoint.start();
586:
587: try {
588: return _preparedStatement.execute(sql);
589: } finally {
590: profiler.finish();
591: }
592: }
593:
594: public ResultSet getResultSet() throws SQLException {
595: Profiler profiler = _profilerPoint.start();
596:
597: try {
598: return _preparedStatement.getResultSet();
599: } finally {
600: profiler.finish();
601: }
602: }
603:
604: public int getUpdateCount() throws SQLException {
605: Profiler profiler = _profilerPoint.start();
606:
607: try {
608: return _preparedStatement.getUpdateCount();
609: } finally {
610: profiler.finish();
611: }
612: }
613:
614: public boolean getMoreResults() throws SQLException {
615: Profiler profiler = _profilerPoint.start();
616:
617: try {
618: return _preparedStatement.getMoreResults();
619: } finally {
620: profiler.finish();
621: }
622: }
623:
624: public void setFetchDirection(int direction) throws SQLException {
625: Profiler profiler = _profilerPoint.start();
626:
627: try {
628: _preparedStatement.setFetchDirection(direction);
629: } finally {
630: profiler.finish();
631: }
632: }
633:
634: public int getFetchDirection() throws SQLException {
635: Profiler profiler = _profilerPoint.start();
636:
637: try {
638: return _preparedStatement.getFetchDirection();
639: } finally {
640: profiler.finish();
641: }
642: }
643:
644: public void setFetchSize(int rows) throws SQLException {
645: Profiler profiler = _profilerPoint.start();
646:
647: try {
648: _preparedStatement.setFetchSize(rows);
649: } finally {
650: profiler.finish();
651: }
652: }
653:
654: public int getFetchSize() throws SQLException {
655: Profiler profiler = _profilerPoint.start();
656:
657: try {
658: return _preparedStatement.getFetchSize();
659: } finally {
660: profiler.finish();
661: }
662: }
663:
664: public int getResultSetConcurrency() throws SQLException {
665: Profiler profiler = _profilerPoint.start();
666:
667: try {
668: return _preparedStatement.getResultSetConcurrency();
669: } finally {
670: profiler.finish();
671: }
672: }
673:
674: public int getResultSetType() throws SQLException {
675: Profiler profiler = _profilerPoint.start();
676:
677: try {
678: return _preparedStatement.getResultSetType();
679: } finally {
680: profiler.finish();
681: }
682: }
683:
684: public void addBatch(String sql) throws SQLException {
685: Profiler profiler = _profilerPoint.start();
686:
687: try {
688: _preparedStatement.addBatch(sql);
689: } finally {
690: profiler.finish();
691: }
692: }
693:
694: public void clearBatch() throws SQLException {
695: Profiler profiler = _profilerPoint.start();
696:
697: try {
698: _preparedStatement.clearBatch();
699: } finally
700:
701: {
702: profiler.finish();
703: }
704: }
705:
706: public int[] executeBatch() throws SQLException {
707: Profiler profiler = _profilerPoint.start();
708:
709: try {
710: return _preparedStatement.executeBatch();
711: } finally {
712: profiler.finish();
713: }
714: }
715:
716: public Connection getConnection() throws SQLException {
717: Profiler profiler = _profilerPoint.start();
718:
719: try {
720: return _preparedStatement.getConnection();
721: } finally {
722: profiler.finish();
723: }
724: }
725:
726: public boolean getMoreResults(int current) throws SQLException {
727: Profiler profiler = _profilerPoint.start();
728:
729: try {
730: return _preparedStatement.getMoreResults(current);
731: } finally {
732: profiler.finish();
733: }
734: }
735:
736: public ResultSet getGeneratedKeys() throws SQLException {
737: Profiler profiler = _profilerPoint.start();
738:
739: try {
740: return _preparedStatement.getGeneratedKeys();
741: } finally {
742: profiler.finish();
743: }
744: }
745:
746: public int executeUpdate(String sql, int autoGeneratedKeys)
747: throws SQLException {
748: Profiler profiler = _profilerPoint.start();
749:
750: try {
751: return _preparedStatement.executeUpdate(sql,
752: autoGeneratedKeys);
753: } finally {
754: profiler.finish();
755: }
756: }
757:
758: public int executeUpdate(String sql, int[] columnIndexes)
759: throws SQLException {
760: Profiler profiler = _profilerPoint.start();
761:
762: try {
763: return _preparedStatement.executeUpdate(sql, columnIndexes);
764: } finally {
765: profiler.finish();
766: }
767: }
768:
769: public int executeUpdate(String sql, String[] columnNames)
770: throws SQLException {
771: Profiler profiler = _profilerPoint.start();
772:
773: try {
774: return _preparedStatement.executeUpdate(sql, columnNames);
775: } finally {
776: profiler.finish();
777: }
778: }
779:
780: public boolean execute(String sql, int autoGeneratedKeys)
781: throws SQLException {
782: Profiler profiler = _profilerPoint.start();
783:
784: try {
785: return _preparedStatement.execute(sql, autoGeneratedKeys);
786: } finally {
787: profiler.finish();
788: }
789: }
790:
791: public boolean execute(String sql, int[] columnIndexes)
792: throws SQLException {
793: Profiler profiler = _profilerPoint.start();
794:
795: try {
796: return _preparedStatement.execute(sql, columnIndexes);
797: } finally {
798: profiler.finish();
799: }
800: }
801:
802: public boolean execute(String sql, String[] columnNames)
803: throws SQLException {
804: Profiler profiler = _profilerPoint.start();
805:
806: try {
807: return _preparedStatement.execute(sql, columnNames);
808: } finally {
809: profiler.finish();
810: }
811: }
812:
813: public int getResultSetHoldability() throws SQLException {
814: Profiler profiler = _profilerPoint.start();
815:
816: try {
817: return _preparedStatement.getResultSetHoldability();
818: } finally {
819: profiler.finish();
820: }
821: }
822:
823: public String toString() {
824: return "PreparedStatementWrapper[" + _profilerPoint.getName()
825: + "]";
826: }
827:
828: public void setRowId(int parameterIndex, RowId x)
829: throws SQLException {
830: throw new UnsupportedOperationException("Not supported yet.");
831: }
832:
833: public void setNString(int parameterIndex, String value)
834: throws SQLException {
835: throw new UnsupportedOperationException("Not supported yet.");
836: }
837:
838: public void setNCharacterStream(int parameterIndex, Reader value,
839: long length) throws SQLException {
840: throw new UnsupportedOperationException("Not supported yet.");
841: }
842:
843: public void setNClob(int parameterIndex, NClob value)
844: throws SQLException {
845: throw new UnsupportedOperationException("Not supported yet.");
846: }
847:
848: public void setClob(int parameterIndex, Reader reader, long length)
849: throws SQLException {
850: throw new UnsupportedOperationException("Not supported yet.");
851: }
852:
853: public void setBlob(int parameterIndex, InputStream inputStream,
854: long length) throws SQLException {
855: throw new UnsupportedOperationException("Not supported yet.");
856: }
857:
858: public void setNClob(int parameterIndex, Reader reader, long length)
859: throws SQLException {
860: throw new UnsupportedOperationException("Not supported yet.");
861: }
862:
863: public void setSQLXML(int parameterIndex, SQLXML xmlObject)
864: throws SQLException {
865: throw new UnsupportedOperationException("Not supported yet.");
866: }
867:
868: public void setAsciiStream(int parameterIndex, InputStream x,
869: long length) throws SQLException {
870: throw new UnsupportedOperationException("Not supported yet.");
871: }
872:
873: public void setBinaryStream(int parameterIndex, InputStream x,
874: long length) throws SQLException {
875: throw new UnsupportedOperationException("Not supported yet.");
876: }
877:
878: public void setCharacterStream(int parameterIndex, Reader reader,
879: long length) throws SQLException {
880: throw new UnsupportedOperationException("Not supported yet.");
881: }
882:
883: public void setAsciiStream(int parameterIndex, InputStream x)
884: throws SQLException {
885: throw new UnsupportedOperationException("Not supported yet.");
886: }
887:
888: public void setBinaryStream(int parameterIndex, InputStream x)
889: throws SQLException {
890: throw new UnsupportedOperationException("Not supported yet.");
891: }
892:
893: public void setCharacterStream(int parameterIndex, Reader reader)
894: throws SQLException {
895: throw new UnsupportedOperationException("Not supported yet.");
896: }
897:
898: public void setNCharacterStream(int parameterIndex, Reader value)
899: throws SQLException {
900: throw new UnsupportedOperationException("Not supported yet.");
901: }
902:
903: public void setClob(int parameterIndex, Reader reader)
904: throws SQLException {
905: throw new UnsupportedOperationException("Not supported yet.");
906: }
907:
908: public void setBlob(int parameterIndex, InputStream inputStream)
909: throws SQLException {
910: throw new UnsupportedOperationException("Not supported yet.");
911: }
912:
913: public void setNClob(int parameterIndex, Reader reader)
914: throws SQLException {
915: throw new UnsupportedOperationException("Not supported yet.");
916: }
917:
918: public boolean isClosed() throws SQLException {
919: throw new UnsupportedOperationException("Not supported yet.");
920: }
921:
922: public void setPoolable(boolean poolable) throws SQLException {
923: throw new UnsupportedOperationException("Not supported yet.");
924: }
925:
926: public boolean isPoolable() throws SQLException {
927: throw new UnsupportedOperationException("Not supported yet.");
928: }
929:
930: public <T> T unwrap(Class<T> iface) throws SQLException {
931: throw new UnsupportedOperationException("Not supported yet.");
932: }
933:
934: public boolean isWrapperFor(Class<?> iface) throws SQLException {
935: throw new UnsupportedOperationException("Not supported yet.");
936: }
937: }
|