001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.commons.dbcp;
019:
020: import java.net.URL;
021: import java.sql.CallableStatement;
022: import java.math.BigDecimal;
023: import java.sql.Date;
024: import java.sql.Time;
025: import java.sql.Timestamp;
026: import java.util.Map;
027: import java.sql.Ref;
028: import java.sql.Blob;
029: import java.sql.Clob;
030: import java.sql.Array;
031: import java.util.Calendar;
032: import java.io.InputStream;
033: import java.io.Reader;
034: import java.sql.SQLException;
035:
036: /**
037: * A base delegating implementation of {@link CallableStatement}.
038: * <p>
039: * All of the methods from the {@link CallableStatement} interface
040: * simply call the corresponding method on the "delegate"
041: * provided in my constructor.
042: * <p>
043: * Extends AbandonedTrace to implement Statement tracking and
044: * logging of code which created the Statement. Tracking the
045: * Statement ensures that the Connection which created it can
046: * close any open Statement's on Connection close.
047: *
048: * @author Glenn L. Nielsen
049: * @author James House
050: * @author Dirk Verbeeck
051: * @version $Revision: 491655 $ $Date: 2007-01-01 15:05:30 -0700 (Mon, 01 Jan 2007) $
052: */
053: public class DelegatingCallableStatement extends
054: DelegatingPreparedStatement implements CallableStatement {
055:
056: /** My delegate. */
057: protected CallableStatement _stmt = null;
058:
059: /**
060: * Create a wrapper for the Statement which traces this
061: * Statement to the Connection which created it and the
062: * code which created it.
063: *
064: * @param c the {@link DelegatingConnection} that created this statement
065: * @param s the {@link CallableStatement} to delegate all calls to
066: */
067: public DelegatingCallableStatement(DelegatingConnection c,
068: CallableStatement s) {
069: super (c, s);
070: _stmt = s;
071: }
072:
073: public boolean equals(Object obj) {
074: CallableStatement delegate = (CallableStatement) getInnermostDelegate();
075: if (delegate == null) {
076: return false;
077: }
078: if (obj instanceof DelegatingCallableStatement) {
079: DelegatingCallableStatement s = (DelegatingCallableStatement) obj;
080: return delegate.equals(s.getInnermostDelegate());
081: } else {
082: return delegate.equals(obj);
083: }
084: }
085:
086: /** Sets my delegate. */
087: public void setDelegate(CallableStatement s) {
088: super .setDelegate(s);
089: _stmt = s;
090: }
091:
092: public void registerOutParameter(int parameterIndex, int sqlType)
093: throws SQLException {
094: checkOpen();
095: try {
096: _stmt.registerOutParameter(parameterIndex, sqlType);
097: } catch (SQLException e) {
098: handleException(e);
099: }
100: }
101:
102: public void registerOutParameter(int parameterIndex, int sqlType,
103: int scale) throws SQLException {
104: checkOpen();
105: try {
106: _stmt.registerOutParameter(parameterIndex, sqlType, scale);
107: } catch (SQLException e) {
108: handleException(e);
109: }
110: }
111:
112: public boolean wasNull() throws SQLException {
113: checkOpen();
114: try {
115: return _stmt.wasNull();
116: } catch (SQLException e) {
117: handleException(e);
118: return false;
119: }
120: }
121:
122: public String getString(int parameterIndex) throws SQLException {
123: checkOpen();
124: try {
125: return _stmt.getString(parameterIndex);
126: } catch (SQLException e) {
127: handleException(e);
128: return null;
129: }
130: }
131:
132: public boolean getBoolean(int parameterIndex) throws SQLException {
133: checkOpen();
134: try {
135: return _stmt.getBoolean(parameterIndex);
136: } catch (SQLException e) {
137: handleException(e);
138: return false;
139: }
140: }
141:
142: public byte getByte(int parameterIndex) throws SQLException {
143: checkOpen();
144: try {
145: return _stmt.getByte(parameterIndex);
146: } catch (SQLException e) {
147: handleException(e);
148: return 0;
149: }
150: }
151:
152: public short getShort(int parameterIndex) throws SQLException {
153: checkOpen();
154: try {
155: return _stmt.getShort(parameterIndex);
156: } catch (SQLException e) {
157: handleException(e);
158: return 0;
159: }
160: }
161:
162: public int getInt(int parameterIndex) throws SQLException {
163: checkOpen();
164: try {
165: return _stmt.getInt(parameterIndex);
166: } catch (SQLException e) {
167: handleException(e);
168: return 0;
169: }
170: }
171:
172: public long getLong(int parameterIndex) throws SQLException {
173: checkOpen();
174: try {
175: return _stmt.getLong(parameterIndex);
176: } catch (SQLException e) {
177: handleException(e);
178: return 0;
179: }
180: }
181:
182: public float getFloat(int parameterIndex) throws SQLException {
183: checkOpen();
184: try {
185: return _stmt.getFloat(parameterIndex);
186: } catch (SQLException e) {
187: handleException(e);
188: return 0;
189: }
190: }
191:
192: public double getDouble(int parameterIndex) throws SQLException {
193: checkOpen();
194: try {
195: return _stmt.getDouble(parameterIndex);
196: } catch (SQLException e) {
197: handleException(e);
198: return 0;
199: }
200: }
201:
202: /** @deprecated */
203: public BigDecimal getBigDecimal(int parameterIndex, int scale)
204: throws SQLException {
205: checkOpen();
206: try {
207: return _stmt.getBigDecimal(parameterIndex, scale);
208: } catch (SQLException e) {
209: handleException(e);
210: return null;
211: }
212: }
213:
214: public byte[] getBytes(int parameterIndex) throws SQLException {
215: checkOpen();
216: try {
217: return _stmt.getBytes(parameterIndex);
218: } catch (SQLException e) {
219: handleException(e);
220: return null;
221: }
222: }
223:
224: public Date getDate(int parameterIndex) throws SQLException {
225: checkOpen();
226: try {
227: return _stmt.getDate(parameterIndex);
228: } catch (SQLException e) {
229: handleException(e);
230: return null;
231: }
232: }
233:
234: public Time getTime(int parameterIndex) throws SQLException {
235: checkOpen();
236: try {
237: return _stmt.getTime(parameterIndex);
238: } catch (SQLException e) {
239: handleException(e);
240: return null;
241: }
242: }
243:
244: public Timestamp getTimestamp(int parameterIndex)
245: throws SQLException {
246: checkOpen();
247: try {
248: return _stmt.getTimestamp(parameterIndex);
249: } catch (SQLException e) {
250: handleException(e);
251: return null;
252: }
253: }
254:
255: public Object getObject(int parameterIndex) throws SQLException {
256: checkOpen();
257: try {
258: return _stmt.getObject(parameterIndex);
259: } catch (SQLException e) {
260: handleException(e);
261: return null;
262: }
263: }
264:
265: public BigDecimal getBigDecimal(int parameterIndex)
266: throws SQLException {
267: checkOpen();
268: try {
269: return _stmt.getBigDecimal(parameterIndex);
270: } catch (SQLException e) {
271: handleException(e);
272: return null;
273: }
274: }
275:
276: public Object getObject(int i, Map map) throws SQLException {
277: checkOpen();
278: try {
279: return _stmt.getObject(i, map);
280: } catch (SQLException e) {
281: handleException(e);
282: return null;
283: }
284: }
285:
286: public Ref getRef(int i) throws SQLException {
287: checkOpen();
288: try {
289: return _stmt.getRef(i);
290: } catch (SQLException e) {
291: handleException(e);
292: return null;
293: }
294: }
295:
296: public Blob getBlob(int i) throws SQLException {
297: checkOpen();
298: try {
299: return _stmt.getBlob(i);
300: } catch (SQLException e) {
301: handleException(e);
302: return null;
303: }
304: }
305:
306: public Clob getClob(int i) throws SQLException {
307: checkOpen();
308: try {
309: return _stmt.getClob(i);
310: } catch (SQLException e) {
311: handleException(e);
312: return null;
313: }
314: }
315:
316: public Array getArray(int i) throws SQLException {
317: checkOpen();
318: try {
319: return _stmt.getArray(i);
320: } catch (SQLException e) {
321: handleException(e);
322: return null;
323: }
324: }
325:
326: public Date getDate(int parameterIndex, Calendar cal)
327: throws SQLException {
328: checkOpen();
329: try {
330: return _stmt.getDate(parameterIndex, cal);
331: } catch (SQLException e) {
332: handleException(e);
333: return null;
334: }
335: }
336:
337: public Time getTime(int parameterIndex, Calendar cal)
338: throws SQLException {
339: checkOpen();
340: try {
341: return _stmt.getTime(parameterIndex, cal);
342: } catch (SQLException e) {
343: handleException(e);
344: return null;
345: }
346: }
347:
348: public Timestamp getTimestamp(int parameterIndex, Calendar cal)
349: throws SQLException {
350: checkOpen();
351: try {
352: return _stmt.getTimestamp(parameterIndex, cal);
353: } catch (SQLException e) {
354: handleException(e);
355: return null;
356: }
357: }
358:
359: public void registerOutParameter(int paramIndex, int sqlType,
360: String typeName) throws SQLException {
361: checkOpen();
362: try {
363: _stmt.registerOutParameter(paramIndex, sqlType, typeName);
364: } catch (SQLException e) {
365: handleException(e);
366: }
367: }
368:
369: // ------------------- JDBC 3.0 -----------------------------------------
370: // Will be commented by the build process on a JDBC 2.0 system
371:
372: /* JDBC_3_ANT_KEY_BEGIN */
373:
374: public void registerOutParameter(String parameterName, int sqlType)
375: throws SQLException {
376: checkOpen();
377: try {
378: _stmt.registerOutParameter(parameterName, sqlType);
379: } catch (SQLException e) {
380: handleException(e);
381: }
382: }
383:
384: public void registerOutParameter(String parameterName, int sqlType,
385: int scale) throws SQLException {
386: checkOpen();
387: try {
388: _stmt.registerOutParameter(parameterName, sqlType, scale);
389: } catch (SQLException e) {
390: handleException(e);
391: }
392: }
393:
394: public void registerOutParameter(String parameterName, int sqlType,
395: String typeName) throws SQLException {
396: checkOpen();
397: try {
398: _stmt
399: .registerOutParameter(parameterName, sqlType,
400: typeName);
401: } catch (SQLException e) {
402: handleException(e);
403: }
404: }
405:
406: public URL getURL(int parameterIndex) throws SQLException {
407: checkOpen();
408: try {
409: return _stmt.getURL(parameterIndex);
410: } catch (SQLException e) {
411: handleException(e);
412: return null;
413: }
414: }
415:
416: public void setURL(String parameterName, URL val)
417: throws SQLException {
418: checkOpen();
419: try {
420: _stmt.setURL(parameterName, val);
421: } catch (SQLException e) {
422: handleException(e);
423: }
424: }
425:
426: public void setNull(String parameterName, int sqlType)
427: throws SQLException {
428: checkOpen();
429: try {
430: _stmt.setNull(parameterName, sqlType);
431: } catch (SQLException e) {
432: handleException(e);
433: }
434: }
435:
436: public void setBoolean(String parameterName, boolean x)
437: throws SQLException {
438: checkOpen();
439: try {
440: _stmt.setBoolean(parameterName, x);
441: } catch (SQLException e) {
442: handleException(e);
443: }
444: }
445:
446: public void setByte(String parameterName, byte x)
447: throws SQLException {
448: checkOpen();
449: try {
450: _stmt.setByte(parameterName, x);
451: } catch (SQLException e) {
452: handleException(e);
453: }
454: }
455:
456: public void setShort(String parameterName, short x)
457: throws SQLException {
458: checkOpen();
459: try {
460: _stmt.setShort(parameterName, x);
461: } catch (SQLException e) {
462: handleException(e);
463: }
464: }
465:
466: public void setInt(String parameterName, int x) throws SQLException {
467: checkOpen();
468: try {
469: _stmt.setInt(parameterName, x);
470: } catch (SQLException e) {
471: handleException(e);
472: }
473: }
474:
475: public void setLong(String parameterName, long x)
476: throws SQLException {
477: checkOpen();
478: try {
479: _stmt.setLong(parameterName, x);
480: } catch (SQLException e) {
481: handleException(e);
482: }
483: }
484:
485: public void setFloat(String parameterName, float x)
486: throws SQLException {
487: checkOpen();
488: try {
489: _stmt.setFloat(parameterName, x);
490: } catch (SQLException e) {
491: handleException(e);
492: }
493: }
494:
495: public void setDouble(String parameterName, double x)
496: throws SQLException {
497: checkOpen();
498: try {
499: _stmt.setDouble(parameterName, x);
500: } catch (SQLException e) {
501: handleException(e);
502: }
503: }
504:
505: public void setBigDecimal(String parameterName, BigDecimal x)
506: throws SQLException {
507: checkOpen();
508: try {
509: _stmt.setBigDecimal(parameterName, x);
510: } catch (SQLException e) {
511: handleException(e);
512: }
513: }
514:
515: public void setString(String parameterName, String x)
516: throws SQLException {
517: checkOpen();
518: try {
519: _stmt.setString(parameterName, x);
520: } catch (SQLException e) {
521: handleException(e);
522: }
523: }
524:
525: public void setBytes(String parameterName, byte[] x)
526: throws SQLException {
527: checkOpen();
528: try {
529: _stmt.setBytes(parameterName, x);
530: } catch (SQLException e) {
531: handleException(e);
532: }
533: }
534:
535: public void setDate(String parameterName, Date x)
536: throws SQLException {
537: checkOpen();
538: try {
539: _stmt.setDate(parameterName, x);
540: } catch (SQLException e) {
541: handleException(e);
542: }
543: }
544:
545: public void setTime(String parameterName, Time x)
546: throws SQLException {
547: checkOpen();
548: try {
549: _stmt.setTime(parameterName, x);
550: } catch (SQLException e) {
551: handleException(e);
552: }
553: }
554:
555: public void setTimestamp(String parameterName, Timestamp x)
556: throws SQLException {
557: checkOpen();
558: try {
559: _stmt.setTimestamp(parameterName, x);
560: } catch (SQLException e) {
561: handleException(e);
562: }
563: }
564:
565: public void setAsciiStream(String parameterName, InputStream x,
566: int length) throws SQLException {
567: checkOpen();
568: try {
569: _stmt.setAsciiStream(parameterName, x, length);
570: } catch (SQLException e) {
571: handleException(e);
572: }
573: }
574:
575: public void setBinaryStream(String parameterName, InputStream x,
576: int length) throws SQLException {
577: checkOpen();
578: try {
579: _stmt.setBinaryStream(parameterName, x, length);
580: } catch (SQLException e) {
581: handleException(e);
582: }
583: }
584:
585: public void setObject(String parameterName, Object x,
586: int targetSqlType, int scale) throws SQLException {
587: checkOpen();
588: try {
589: _stmt.setObject(parameterName, x, targetSqlType, scale);
590: } catch (SQLException e) {
591: handleException(e);
592: }
593: }
594:
595: public void setObject(String parameterName, Object x,
596: int targetSqlType) throws SQLException {
597: checkOpen();
598: try {
599: _stmt.setObject(parameterName, x, targetSqlType);
600: } catch (SQLException e) {
601: handleException(e);
602: }
603: }
604:
605: public void setObject(String parameterName, Object x)
606: throws SQLException {
607: checkOpen();
608: try {
609: _stmt.setObject(parameterName, x);
610: } catch (SQLException e) {
611: handleException(e);
612: }
613: }
614:
615: public void setCharacterStream(String parameterName, Reader reader,
616: int length) throws SQLException {
617: checkOpen();
618: _stmt.setCharacterStream(parameterName, reader, length);
619: }
620:
621: public void setDate(String parameterName, Date x, Calendar cal)
622: throws SQLException {
623: checkOpen();
624: try {
625: _stmt.setDate(parameterName, x, cal);
626: } catch (SQLException e) {
627: handleException(e);
628: }
629: }
630:
631: public void setTime(String parameterName, Time x, Calendar cal)
632: throws SQLException {
633: checkOpen();
634: try {
635: _stmt.setTime(parameterName, x, cal);
636: } catch (SQLException e) {
637: handleException(e);
638: }
639: }
640:
641: public void setTimestamp(String parameterName, Timestamp x,
642: Calendar cal) throws SQLException {
643: checkOpen();
644: try {
645: _stmt.setTimestamp(parameterName, x, cal);
646: } catch (SQLException e) {
647: handleException(e);
648: }
649: }
650:
651: public void setNull(String parameterName, int sqlType,
652: String typeName) throws SQLException {
653: checkOpen();
654: try {
655: _stmt.setNull(parameterName, sqlType, typeName);
656: } catch (SQLException e) {
657: handleException(e);
658: }
659: }
660:
661: public String getString(String parameterName) throws SQLException {
662: checkOpen();
663: try {
664: return _stmt.getString(parameterName);
665: } catch (SQLException e) {
666: handleException(e);
667: return null;
668: }
669: }
670:
671: public boolean getBoolean(String parameterName) throws SQLException {
672: checkOpen();
673: try {
674: return _stmt.getBoolean(parameterName);
675: } catch (SQLException e) {
676: handleException(e);
677: return false;
678: }
679: }
680:
681: public byte getByte(String parameterName) throws SQLException {
682: checkOpen();
683: try {
684: return _stmt.getByte(parameterName);
685: } catch (SQLException e) {
686: handleException(e);
687: return 0;
688: }
689: }
690:
691: public short getShort(String parameterName) throws SQLException {
692: checkOpen();
693: try {
694: return _stmt.getShort(parameterName);
695: } catch (SQLException e) {
696: handleException(e);
697: return 0;
698: }
699: }
700:
701: public int getInt(String parameterName) throws SQLException {
702: checkOpen();
703: try {
704: return _stmt.getInt(parameterName);
705: } catch (SQLException e) {
706: handleException(e);
707: return 0;
708: }
709: }
710:
711: public long getLong(String parameterName) throws SQLException {
712: checkOpen();
713: try {
714: return _stmt.getLong(parameterName);
715: } catch (SQLException e) {
716: handleException(e);
717: return 0;
718: }
719: }
720:
721: public float getFloat(String parameterName) throws SQLException {
722: checkOpen();
723: try {
724: return _stmt.getFloat(parameterName);
725: } catch (SQLException e) {
726: handleException(e);
727: return 0;
728: }
729: }
730:
731: public double getDouble(String parameterName) throws SQLException {
732: checkOpen();
733: try {
734: return _stmt.getDouble(parameterName);
735: } catch (SQLException e) {
736: handleException(e);
737: return 0;
738: }
739: }
740:
741: public byte[] getBytes(String parameterName) throws SQLException {
742: checkOpen();
743: try {
744: return _stmt.getBytes(parameterName);
745: } catch (SQLException e) {
746: handleException(e);
747: return null;
748: }
749: }
750:
751: public Date getDate(String parameterName) throws SQLException {
752: checkOpen();
753: try {
754: return _stmt.getDate(parameterName);
755: } catch (SQLException e) {
756: handleException(e);
757: return null;
758: }
759: }
760:
761: public Time getTime(String parameterName) throws SQLException {
762: checkOpen();
763: try {
764: return _stmt.getTime(parameterName);
765: } catch (SQLException e) {
766: handleException(e);
767: return null;
768: }
769: }
770:
771: public Timestamp getTimestamp(String parameterName)
772: throws SQLException {
773: checkOpen();
774: try {
775: return _stmt.getTimestamp(parameterName);
776: } catch (SQLException e) {
777: handleException(e);
778: return null;
779: }
780: }
781:
782: public Object getObject(String parameterName) throws SQLException {
783: checkOpen();
784: try {
785: return _stmt.getObject(parameterName);
786: } catch (SQLException e) {
787: handleException(e);
788: return null;
789: }
790: }
791:
792: public BigDecimal getBigDecimal(String parameterName)
793: throws SQLException {
794: checkOpen();
795: try {
796: return _stmt.getBigDecimal(parameterName);
797: } catch (SQLException e) {
798: handleException(e);
799: return null;
800: }
801: }
802:
803: public Object getObject(String parameterName, Map map)
804: throws SQLException {
805: checkOpen();
806: try {
807: return _stmt.getObject(parameterName, map);
808: } catch (SQLException e) {
809: handleException(e);
810: return null;
811: }
812: }
813:
814: public Ref getRef(String parameterName) throws SQLException {
815: checkOpen();
816: try {
817: return _stmt.getRef(parameterName);
818: } catch (SQLException e) {
819: handleException(e);
820: return null;
821: }
822: }
823:
824: public Blob getBlob(String parameterName) throws SQLException {
825: checkOpen();
826: try {
827: return _stmt.getBlob(parameterName);
828: } catch (SQLException e) {
829: handleException(e);
830: return null;
831: }
832: }
833:
834: public Clob getClob(String parameterName) throws SQLException {
835: checkOpen();
836: try {
837: return _stmt.getClob(parameterName);
838: } catch (SQLException e) {
839: handleException(e);
840: return null;
841: }
842: }
843:
844: public Array getArray(String parameterName) throws SQLException {
845: checkOpen();
846: try {
847: return _stmt.getArray(parameterName);
848: } catch (SQLException e) {
849: handleException(e);
850: return null;
851: }
852: }
853:
854: public Date getDate(String parameterName, Calendar cal)
855: throws SQLException {
856: checkOpen();
857: try {
858: return _stmt.getDate(parameterName, cal);
859: } catch (SQLException e) {
860: handleException(e);
861: return null;
862: }
863: }
864:
865: public Time getTime(String parameterName, Calendar cal)
866: throws SQLException {
867: checkOpen();
868: try {
869: return _stmt.getTime(parameterName, cal);
870: } catch (SQLException e) {
871: handleException(e);
872: return null;
873: }
874: }
875:
876: public Timestamp getTimestamp(String parameterName, Calendar cal)
877: throws SQLException {
878: checkOpen();
879: try {
880: return _stmt.getTimestamp(parameterName, cal);
881: } catch (SQLException e) {
882: handleException(e);
883: return null;
884: }
885: }
886:
887: public URL getURL(String parameterName) throws SQLException {
888: checkOpen();
889: try {
890: return _stmt.getURL(parameterName);
891: } catch (SQLException e) {
892: handleException(e);
893: return null;
894: }
895: }
896:
897: /* JDBC_3_ANT_KEY_END */
898: }
|