001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.openjpa.lib.jdbc;
020:
021: import java.io.InputStream;
022: import java.io.Reader;
023: import java.math.BigDecimal;
024: import java.net.URL;
025: import java.sql.Array;
026: import java.sql.Blob;
027: import java.sql.CallableStatement;
028: import java.sql.Clob;
029: import java.sql.Connection;
030: import java.sql.Date;
031: import java.sql.ParameterMetaData;
032: import java.sql.Ref;
033: import java.sql.ResultSet;
034: import java.sql.ResultSetMetaData;
035: import java.sql.SQLException;
036: import java.sql.SQLWarning;
037: import java.sql.Time;
038: import java.sql.Timestamp;
039: import java.util.Calendar;
040: import java.util.Map;
041:
042: import org.apache.openjpa.lib.util.Closeable;
043:
044: /**
045: * {@link CallableStatement} that delegates to an internal statement.
046: *
047: * @author Abe White
048: */
049: public class DelegatingCallableStatement implements CallableStatement,
050: Closeable {
051:
052: private final CallableStatement _stmnt;
053: private final DelegatingCallableStatement _del;
054: private final Connection _conn;
055:
056: public DelegatingCallableStatement(CallableStatement stmnt,
057: Connection conn) {
058: _conn = conn;
059: _stmnt = stmnt;
060: if (_stmnt instanceof DelegatingCallableStatement)
061: _del = (DelegatingCallableStatement) _stmnt;
062: else
063: _del = null;
064: }
065:
066: private ResultSet wrapResult(boolean wrap, ResultSet rs) {
067: if (!wrap)
068: return rs;
069:
070: // never wrap null
071: if (rs == null)
072: return null;
073:
074: return new DelegatingResultSet(rs, this );
075: }
076:
077: /**
078: * Return the wrapped statement.
079: */
080: public CallableStatement getDelegate() {
081: return _stmnt;
082: }
083:
084: /**
085: * Return the base underlying data store statement.
086: */
087: public CallableStatement getInnermostDelegate() {
088: return (_del == null) ? _stmnt : _del.getInnermostDelegate();
089: }
090:
091: public int hashCode() {
092: return getInnermostDelegate().hashCode();
093: }
094:
095: public boolean equals(Object other) {
096: if (other == this )
097: return true;
098: if (other instanceof DelegatingCallableStatement)
099: other = ((DelegatingCallableStatement) other)
100: .getInnermostDelegate();
101: return getInnermostDelegate().equals(other);
102: }
103:
104: public String toString() {
105: StringBuffer buf = new StringBuffer("prepstmnt ")
106: .append(hashCode());
107: appendInfo(buf);
108: return buf.toString();
109: }
110:
111: protected void appendInfo(StringBuffer buf) {
112: if (_del != null)
113: _del.appendInfo(buf);
114: }
115:
116: public ResultSet executeQuery(String str) throws SQLException {
117: return executeQuery(true);
118: }
119:
120: /**
121: * Execute the query, with the option of not wrapping it in a
122: * {@link DelegatingResultSet}, which is the default.
123: */
124: protected ResultSet executeQuery(String sql, boolean wrap)
125: throws SQLException {
126: ResultSet rs;
127: if (_del != null)
128: rs = _del.executeQuery(sql, false);
129: else
130: rs = _stmnt.executeQuery(sql);
131:
132: return wrapResult(wrap, rs);
133: }
134:
135: public int executeUpdate(String str) throws SQLException {
136: return _stmnt.executeUpdate(str);
137: }
138:
139: public boolean execute(String str) throws SQLException {
140: return _stmnt.execute(str);
141: }
142:
143: public void close() throws SQLException {
144: _stmnt.close();
145: }
146:
147: public int getMaxFieldSize() throws SQLException {
148: return _stmnt.getMaxFieldSize();
149: }
150:
151: public void setMaxFieldSize(int i) throws SQLException {
152: _stmnt.setMaxFieldSize(i);
153: }
154:
155: public int getMaxRows() throws SQLException {
156: return _stmnt.getMaxRows();
157: }
158:
159: public void setMaxRows(int i) throws SQLException {
160: _stmnt.setMaxRows(i);
161: }
162:
163: public void setEscapeProcessing(boolean bool) throws SQLException {
164: _stmnt.setEscapeProcessing(bool);
165: }
166:
167: public int getQueryTimeout() throws SQLException {
168: return _stmnt.getQueryTimeout();
169: }
170:
171: public void setQueryTimeout(int i) throws SQLException {
172: _stmnt.setQueryTimeout(i);
173: }
174:
175: public void cancel() throws SQLException {
176: _stmnt.cancel();
177: }
178:
179: public SQLWarning getWarnings() throws SQLException {
180: return _stmnt.getWarnings();
181: }
182:
183: public void clearWarnings() throws SQLException {
184: _stmnt.clearWarnings();
185: }
186:
187: public void setCursorName(String str) throws SQLException {
188: _stmnt.setCursorName(str);
189: }
190:
191: public ResultSet getResultSet() throws SQLException {
192: return getResultSet(true);
193: }
194:
195: /**
196: * Get the last result set, with the option of not wrapping it in a
197: * {@link DelegatingResultSet}, which is the default.
198: */
199: protected ResultSet getResultSet(boolean wrap) throws SQLException {
200: ResultSet rs;
201: if (_del != null)
202: rs = _del.getResultSet(false);
203: else
204: rs = _stmnt.getResultSet();
205:
206: return wrapResult(wrap, rs);
207: }
208:
209: public int getUpdateCount() throws SQLException {
210: return _stmnt.getUpdateCount();
211: }
212:
213: public boolean getMoreResults() throws SQLException {
214: return _stmnt.getMoreResults();
215: }
216:
217: public void setFetchDirection(int i) throws SQLException {
218: _stmnt.setFetchDirection(i);
219: }
220:
221: public int getFetchDirection() throws SQLException {
222: return _stmnt.getFetchDirection();
223: }
224:
225: public void setFetchSize(int i) throws SQLException {
226: _stmnt.setFetchSize(i);
227: }
228:
229: public int getFetchSize() throws SQLException {
230: return _stmnt.getFetchSize();
231: }
232:
233: public int getResultSetConcurrency() throws SQLException {
234: return _stmnt.getResultSetConcurrency();
235: }
236:
237: public int getResultSetType() throws SQLException {
238: return _stmnt.getResultSetType();
239: }
240:
241: public void addBatch(String str) throws SQLException {
242: _stmnt.addBatch(str);
243: }
244:
245: public void clearBatch() throws SQLException {
246: _stmnt.clearBatch();
247: }
248:
249: public int[] executeBatch() throws SQLException {
250: return _stmnt.executeBatch();
251: }
252:
253: public Connection getConnection() throws SQLException {
254: return _conn;
255: }
256:
257: public ResultSet executeQuery() throws SQLException {
258: return executeQuery(true);
259: }
260:
261: /**
262: * Execute the query, with the option of not wrapping it in a
263: * {@link DelegatingResultSet}, which is the default.
264: */
265: protected ResultSet executeQuery(boolean wrap) throws SQLException {
266: ResultSet rs;
267: if (_del != null)
268: rs = _del.executeQuery(false);
269: else
270: rs = _stmnt.executeQuery();
271:
272: return wrapResult(wrap, rs);
273: }
274:
275: public int executeUpdate() throws SQLException {
276: return _stmnt.executeUpdate();
277: }
278:
279: public void setNull(int i1, int i2) throws SQLException {
280: _stmnt.setNull(i1, i2);
281: }
282:
283: public void setBoolean(int i, boolean b) throws SQLException {
284: _stmnt.setBoolean(i, b);
285: }
286:
287: public void setByte(int i, byte b) throws SQLException {
288: _stmnt.setByte(i, b);
289: }
290:
291: public void setShort(int i, short s) throws SQLException {
292: _stmnt.setShort(i, s);
293: }
294:
295: public void setInt(int i1, int i2) throws SQLException {
296: _stmnt.setInt(i1, i2);
297: }
298:
299: public void setLong(int i, long l) throws SQLException {
300: _stmnt.setLong(i, l);
301: }
302:
303: public void setFloat(int i, float f) throws SQLException {
304: _stmnt.setFloat(i, f);
305: }
306:
307: public void setDouble(int i, double d) throws SQLException {
308: _stmnt.setDouble(i, d);
309: }
310:
311: public void setBigDecimal(int i, BigDecimal bd) throws SQLException {
312: _stmnt.setBigDecimal(i, bd);
313: }
314:
315: public void setString(int i, String s) throws SQLException {
316: _stmnt.setString(i, s);
317: }
318:
319: public void setBytes(int i, byte[] b) throws SQLException {
320: _stmnt.setBytes(i, b);
321: }
322:
323: public void setDate(int i, Date d) throws SQLException {
324: _stmnt.setDate(i, d);
325: }
326:
327: public void setTime(int i, Time t) throws SQLException {
328: _stmnt.setTime(i, t);
329: }
330:
331: public void setTimestamp(int i, Timestamp t) throws SQLException {
332: _stmnt.setTimestamp(i, t);
333: }
334:
335: public void setAsciiStream(int i1, InputStream is, int i2)
336: throws SQLException {
337: _stmnt.setAsciiStream(i1, is, i2);
338: }
339:
340: public void setUnicodeStream(int i1, InputStream is, int i2)
341: throws SQLException {
342: _stmnt.setUnicodeStream(i1, is, i2);
343: }
344:
345: public void setBinaryStream(int i1, InputStream is, int i2)
346: throws SQLException {
347: _stmnt.setBinaryStream(i1, is, i2);
348: }
349:
350: public void clearParameters() throws SQLException {
351: _stmnt.clearParameters();
352: }
353:
354: public void setObject(int i1, Object o, int i2, int i3)
355: throws SQLException {
356: _stmnt.setObject(i1, o, i2, i3);
357: }
358:
359: public void setObject(int i1, Object o, int i2) throws SQLException {
360: _stmnt.setObject(i1, o, i2);
361: }
362:
363: public void setObject(int i, Object o) throws SQLException {
364: _stmnt.setObject(i, o);
365: }
366:
367: public boolean execute() throws SQLException {
368: return _stmnt.execute();
369: }
370:
371: public void addBatch() throws SQLException {
372: _stmnt.addBatch();
373: }
374:
375: public void setCharacterStream(int i1, Reader r, int i2)
376: throws SQLException {
377: _stmnt.setCharacterStream(i1, r, i2);
378: }
379:
380: public void setRef(int i, Ref r) throws SQLException {
381: _stmnt.setRef(i, r);
382: }
383:
384: public void setBlob(int i, Blob b) throws SQLException {
385: _stmnt.setBlob(i, b);
386: }
387:
388: public void setClob(int i, Clob c) throws SQLException {
389: _stmnt.setClob(i, c);
390: }
391:
392: public void setArray(int i, Array a) throws SQLException {
393: _stmnt.setArray(i, a);
394: }
395:
396: public ResultSetMetaData getMetaData() throws SQLException {
397: return _stmnt.getMetaData();
398: }
399:
400: public void setDate(int i, Date d, Calendar c) throws SQLException {
401: _stmnt.setDate(i, d, c);
402: }
403:
404: public void setTime(int i, Time t, Calendar c) throws SQLException {
405: _stmnt.setTime(i, t, c);
406: }
407:
408: public void setTimestamp(int i, Timestamp t, Calendar c)
409: throws SQLException {
410: _stmnt.setTimestamp(i, t, c);
411: }
412:
413: public void setNull(int i1, int i2, String s) throws SQLException {
414: _stmnt.setNull(i1, i2, s);
415: }
416:
417: // JDBC 3.0 (unsupported) methods follow; these are required to be able
418: // to compile against JDK 1.4
419:
420: public boolean getMoreResults(int i) throws SQLException {
421: throw new UnsupportedOperationException();
422: }
423:
424: public ResultSet getGeneratedKeys() throws SQLException {
425: throw new UnsupportedOperationException();
426: }
427:
428: public int executeUpdate(String s, int i) throws SQLException {
429: throw new UnsupportedOperationException();
430: }
431:
432: public int executeUpdate(String s, int[] ia) throws SQLException {
433: throw new UnsupportedOperationException();
434: }
435:
436: public int executeUpdate(String s, String[] sa) throws SQLException {
437: throw new UnsupportedOperationException();
438: }
439:
440: public boolean execute(String s, int i) throws SQLException {
441: throw new UnsupportedOperationException();
442: }
443:
444: public boolean execute(String s, int[] ia) throws SQLException {
445: throw new UnsupportedOperationException();
446: }
447:
448: public boolean execute(String s, String[] sa) throws SQLException {
449: throw new UnsupportedOperationException();
450: }
451:
452: public int getResultSetHoldability() throws SQLException {
453: throw new UnsupportedOperationException();
454: }
455:
456: public void setURL(int i, URL url) throws SQLException {
457: throw new UnsupportedOperationException();
458: }
459:
460: public ParameterMetaData getParameterMetaData() throws SQLException {
461: throw new UnsupportedOperationException();
462: }
463:
464: /////////////////////////////
465: // CallableStatement methods
466: /////////////////////////////
467:
468: public void registerOutParameter(int i1, int i2)
469: throws SQLException {
470: _stmnt.registerOutParameter(i1, i2);
471: }
472:
473: public void registerOutParameter(int i1, int i2, int i3)
474: throws SQLException {
475: _stmnt.registerOutParameter(i1, i2, i3);
476: }
477:
478: public boolean wasNull() throws SQLException {
479: return _stmnt.wasNull();
480: }
481:
482: public String getString(int i) throws SQLException {
483: return _stmnt.getString(i);
484: }
485:
486: public boolean getBoolean(int i) throws SQLException {
487: return _stmnt.getBoolean(i);
488: }
489:
490: public byte getByte(int i) throws SQLException {
491: return _stmnt.getByte(i);
492: }
493:
494: public short getShort(int i) throws SQLException {
495: return _stmnt.getShort(i);
496: }
497:
498: public int getInt(int i) throws SQLException {
499: return _stmnt.getInt(i);
500: }
501:
502: public long getLong(int i) throws SQLException {
503: return _stmnt.getLong(i);
504: }
505:
506: public float getFloat(int i) throws SQLException {
507: return _stmnt.getFloat(i);
508: }
509:
510: public double getDouble(int i) throws SQLException {
511: return _stmnt.getDouble(i);
512: }
513:
514: public BigDecimal getBigDecimal(int a, int b) throws SQLException {
515: return _stmnt.getBigDecimal(a, b);
516: }
517:
518: public byte[] getBytes(int i) throws SQLException {
519: return _stmnt.getBytes(i);
520: }
521:
522: public Date getDate(int i) throws SQLException {
523: return _stmnt.getDate(i);
524: }
525:
526: public Time getTime(int i) throws SQLException {
527: return _stmnt.getTime(i);
528: }
529:
530: public Timestamp getTimestamp(int i) throws SQLException {
531: return _stmnt.getTimestamp(i);
532: }
533:
534: public Object getObject(int i) throws SQLException {
535: return _stmnt.getObject(i);
536: }
537:
538: public BigDecimal getBigDecimal(int i) throws SQLException {
539: return _stmnt.getBigDecimal(i);
540: }
541:
542: public Object getObject(int i, Map m) throws SQLException {
543: return _stmnt.getObject(i, m);
544: }
545:
546: public Ref getRef(int i) throws SQLException {
547: return _stmnt.getRef(i);
548: }
549:
550: public Blob getBlob(int i) throws SQLException {
551: return _stmnt.getBlob(i);
552: }
553:
554: public Clob getClob(int i) throws SQLException {
555: return _stmnt.getClob(i);
556: }
557:
558: public Array getArray(int i) throws SQLException {
559: return _stmnt.getArray(i);
560: }
561:
562: public Date getDate(int i, Calendar c) throws SQLException {
563: return _stmnt.getDate(i, c);
564: }
565:
566: public Time getTime(int i, Calendar c) throws SQLException {
567: return _stmnt.getTime(i, c);
568: }
569:
570: public Timestamp getTimestamp(int i, Calendar c)
571: throws SQLException {
572: return _stmnt.getTimestamp(i, c);
573: }
574:
575: public void registerOutParameter(int i1, int i2, String s)
576: throws SQLException {
577: _stmnt.registerOutParameter(i1, i2, s);
578: }
579:
580: // JDBC 3.0 (unsupported) methods follow; these are required to be able
581: // to compile against JDK 1.4
582:
583: public void registerOutParameter(String s, int i)
584: throws SQLException {
585: throw new UnsupportedOperationException();
586: }
587:
588: public void registerOutParameter(String s, int i1, int i2)
589: throws SQLException {
590: throw new UnsupportedOperationException();
591: }
592:
593: public void registerOutParameter(String s1, int i, String s2)
594: throws SQLException {
595: throw new UnsupportedOperationException();
596: }
597:
598: public URL getURL(int i) throws SQLException {
599: throw new UnsupportedOperationException();
600: }
601:
602: public void setURL(String a, URL b) throws SQLException {
603: throw new UnsupportedOperationException();
604: }
605:
606: public URL getURL(String a) throws SQLException {
607: throw new UnsupportedOperationException();
608: }
609:
610: public void setNull(String a, int b) throws SQLException {
611: throw new UnsupportedOperationException();
612: }
613:
614: public void setBoolean(String a, boolean b) throws SQLException {
615: throw new UnsupportedOperationException();
616: }
617:
618: public void setByte(String a, byte b) throws SQLException {
619: throw new UnsupportedOperationException();
620: }
621:
622: public void setShort(String a, short b) throws SQLException {
623: throw new UnsupportedOperationException();
624: }
625:
626: public void setInt(String a, int b) throws SQLException {
627: throw new UnsupportedOperationException();
628: }
629:
630: public void setLong(String a, long b) throws SQLException {
631: throw new UnsupportedOperationException();
632: }
633:
634: public void setFloat(String a, float b) throws SQLException {
635: throw new UnsupportedOperationException();
636: }
637:
638: public void setDouble(String a, double b) throws SQLException {
639: throw new UnsupportedOperationException();
640: }
641:
642: public void setBigDecimal(String a, BigDecimal b)
643: throws SQLException {
644: throw new UnsupportedOperationException();
645: }
646:
647: public void setString(String a, String b) throws SQLException {
648: throw new UnsupportedOperationException();
649: }
650:
651: public void setBytes(String a, byte[] b) throws SQLException {
652: throw new UnsupportedOperationException();
653: }
654:
655: public void setDate(String a, Date b) throws SQLException {
656: throw new UnsupportedOperationException();
657: }
658:
659: public void setTime(String a, Time b) throws SQLException {
660: throw new UnsupportedOperationException();
661: }
662:
663: public void setTimestamp(String a, Timestamp b) throws SQLException {
664: throw new UnsupportedOperationException();
665: }
666:
667: public void setAsciiStream(String a, InputStream b, int c)
668: throws SQLException {
669: throw new UnsupportedOperationException();
670: }
671:
672: public void setBinaryStream(String a, InputStream b, int c)
673: throws SQLException {
674: throw new UnsupportedOperationException();
675: }
676:
677: public void setObject(String a, Object b, int c, int d)
678: throws SQLException {
679: throw new UnsupportedOperationException();
680: }
681:
682: public void setObject(String a, Object b, int c)
683: throws SQLException {
684: throw new UnsupportedOperationException();
685: }
686:
687: public void setObject(String a, Object b) throws SQLException {
688: throw new UnsupportedOperationException();
689: }
690:
691: public void setCharacterStream(String a, Reader b, int c)
692: throws SQLException {
693: throw new UnsupportedOperationException();
694: }
695:
696: public void setDate(String a, Date b, Calendar c)
697: throws SQLException {
698: throw new UnsupportedOperationException();
699: }
700:
701: public void setTime(String a, Time b, Calendar c)
702: throws SQLException {
703: throw new UnsupportedOperationException();
704: }
705:
706: public void setTimestamp(String a, Timestamp b, Calendar c)
707: throws SQLException {
708: throw new UnsupportedOperationException();
709: }
710:
711: public void setNull(String a, int b, String c) throws SQLException {
712: throw new UnsupportedOperationException();
713: }
714:
715: public String getString(String a) throws SQLException {
716: throw new UnsupportedOperationException();
717: }
718:
719: public boolean getBoolean(String a) throws SQLException {
720: throw new UnsupportedOperationException();
721: }
722:
723: public byte getByte(String a) throws SQLException {
724: throw new UnsupportedOperationException();
725: }
726:
727: public short getShort(String a) throws SQLException {
728: throw new UnsupportedOperationException();
729: }
730:
731: public int getInt(String a) throws SQLException {
732: throw new UnsupportedOperationException();
733: }
734:
735: public long getLong(String a) throws SQLException {
736: throw new UnsupportedOperationException();
737: }
738:
739: public float getFloat(String a) throws SQLException {
740: throw new UnsupportedOperationException();
741: }
742:
743: public double getDouble(String a) throws SQLException {
744: throw new UnsupportedOperationException();
745: }
746:
747: public byte[] getBytes(String a) throws SQLException {
748: throw new UnsupportedOperationException();
749: }
750:
751: public Date getDate(String a) throws SQLException {
752: throw new UnsupportedOperationException();
753: }
754:
755: public Time getTime(String a) throws SQLException {
756: throw new UnsupportedOperationException();
757: }
758:
759: public Timestamp getTimestamp(String a) throws SQLException {
760: throw new UnsupportedOperationException();
761: }
762:
763: public Object getObject(String a) throws SQLException {
764: throw new UnsupportedOperationException();
765: }
766:
767: public BigDecimal getBigDecimal(String a) throws SQLException {
768: throw new UnsupportedOperationException();
769: }
770:
771: public Object getObject(String a, Map b) throws SQLException {
772: throw new UnsupportedOperationException();
773: }
774:
775: public Ref getRef(String a) throws SQLException {
776: throw new UnsupportedOperationException();
777: }
778:
779: public Blob getBlob(String a) throws SQLException {
780: throw new UnsupportedOperationException();
781: }
782:
783: public Clob getClob(String a) throws SQLException {
784: throw new UnsupportedOperationException();
785: }
786:
787: public Array getArray(String a) throws SQLException {
788: throw new UnsupportedOperationException();
789: }
790:
791: public Date getDate(String a, Calendar b) throws SQLException {
792: throw new UnsupportedOperationException();
793: }
794:
795: public Time getTime(String a, Calendar b) throws SQLException {
796: throw new UnsupportedOperationException();
797: }
798:
799: public Timestamp getTimestamp(String a, Calendar b)
800: throws SQLException {
801: throw new UnsupportedOperationException();
802: }
803: }
|