KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mysql > jdbc > jdbc2 > optional > CallableStatementWrapper


1 /*
2  Copyright (C) 2002-2004 MySQL AB
3
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of version 2 of the GNU General Public License as
6  published by the Free Software Foundation.
7
8  There are special exceptions to the terms and conditions of the GPL
9  as it is applied to this software. View the full text of the
10  exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
11  software distribution.
12
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22
23  */

24
25 package com.mysql.jdbc.jdbc2.optional;
26
27 import java.io.InputStream JavaDoc;
28 import java.io.Reader JavaDoc;
29 import java.math.BigDecimal JavaDoc;
30 import java.net.URL JavaDoc;
31 import java.sql.Array JavaDoc;
32 import java.sql.Blob JavaDoc;
33 import java.sql.CallableStatement JavaDoc;
34 import java.sql.Clob JavaDoc;
35 import java.sql.Date JavaDoc;
36 import java.sql.PreparedStatement JavaDoc;
37 import java.sql.Ref JavaDoc;
38 import java.sql.SQLException JavaDoc;
39 import java.sql.Time JavaDoc;
40 import java.sql.Timestamp JavaDoc;
41 import java.util.Calendar JavaDoc;
42 import java.util.Map JavaDoc;
43
44 import com.mysql.jdbc.SQLError;
45
46 /**
47  * Wraps callable statements created by pooled connections.
48  *
49  * @version $Id: CallableStatementWrapper.java,v 1.1.2.1 2005/05/13 18:58:38
50  * mmatthews Exp $
51  */

52 public class CallableStatementWrapper extends PreparedStatementWrapper
53         implements CallableStatement JavaDoc {
54
55     /**
56      * @param c
57      * @param conn
58      * @param toWrap
59      */

60     public CallableStatementWrapper(ConnectionWrapper c,
61             MysqlPooledConnection conn, CallableStatement JavaDoc toWrap) {
62         super(c, conn, toWrap);
63     }
64
65     /*
66      * (non-Javadoc)
67      *
68      * @see java.sql.CallableStatement#registerOutParameter(int, int)
69      */

70     public void registerOutParameter(int parameterIndex, int sqlType)
71             throws SQLException JavaDoc {
72         try {
73             if (this.wrappedStmt != null) {
74                 ((CallableStatement JavaDoc) this.wrappedStmt).registerOutParameter(
75                         parameterIndex, sqlType);
76             } else {
77                 throw new SQLException JavaDoc(
78                         "No operations allowed after statement closed",
79                         SQLError.SQL_STATE_GENERAL_ERROR);
80             }
81         } catch (SQLException JavaDoc sqlEx) {
82             checkAndFireConnectionError(sqlEx);
83         }
84     }
85
86     /*
87      * (non-Javadoc)
88      *
89      * @see java.sql.CallableStatement#registerOutParameter(int, int, int)
90      */

91     public void registerOutParameter(int parameterIndex, int sqlType, int scale)
92             throws SQLException JavaDoc {
93         try {
94             if (this.wrappedStmt != null) {
95                 ((CallableStatement JavaDoc) this.wrappedStmt).registerOutParameter(
96                         parameterIndex, sqlType, scale);
97             } else {
98                 throw new SQLException JavaDoc(
99                         "No operations allowed after statement closed",
100                         SQLError.SQL_STATE_GENERAL_ERROR);
101             }
102         } catch (SQLException JavaDoc sqlEx) {
103             checkAndFireConnectionError(sqlEx);
104         }
105     }
106
107     /*
108      * (non-Javadoc)
109      *
110      * @see java.sql.CallableStatement#wasNull()
111      */

112     public boolean wasNull() throws SQLException JavaDoc {
113         try {
114             if (this.wrappedStmt != null) {
115                 return ((CallableStatement JavaDoc) this.wrappedStmt).wasNull();
116             } else {
117                 throw new SQLException JavaDoc(
118                         "No operations allowed after statement closed",
119                         SQLError.SQL_STATE_GENERAL_ERROR);
120             }
121         } catch (SQLException JavaDoc sqlEx) {
122             checkAndFireConnectionError(sqlEx);
123         }
124
125         return false;
126     }
127
128     /*
129      * (non-Javadoc)
130      *
131      * @see java.sql.CallableStatement#getString(int)
132      */

133     public String JavaDoc getString(int parameterIndex) throws SQLException JavaDoc {
134         try {
135             if (this.wrappedStmt != null) {
136                 return ((CallableStatement JavaDoc) this.wrappedStmt)
137                         .getString(parameterIndex);
138             } else {
139                 throw new SQLException JavaDoc(
140                         "No operations allowed after statement closed",
141                         SQLError.SQL_STATE_GENERAL_ERROR);
142             }
143         } catch (SQLException JavaDoc sqlEx) {
144             checkAndFireConnectionError(sqlEx);
145         }
146         return null;
147     }
148
149     /*
150      * (non-Javadoc)
151      *
152      * @see java.sql.CallableStatement#getBoolean(int)
153      */

154     public boolean getBoolean(int parameterIndex) throws SQLException JavaDoc {
155         try {
156             if (this.wrappedStmt != null) {
157                 return ((CallableStatement JavaDoc) this.wrappedStmt)
158                         .getBoolean(parameterIndex);
159             } else {
160                 throw new SQLException JavaDoc(
161                         "No operations allowed after statement closed",
162                         SQLError.SQL_STATE_GENERAL_ERROR);
163             }
164         } catch (SQLException JavaDoc sqlEx) {
165             checkAndFireConnectionError(sqlEx);
166         }
167
168         return false;
169     }
170
171     /*
172      * (non-Javadoc)
173      *
174      * @see java.sql.CallableStatement#getByte(int)
175      */

176     public byte getByte(int parameterIndex) throws SQLException JavaDoc {
177         try {
178             if (this.wrappedStmt != null) {
179                 return ((CallableStatement JavaDoc) this.wrappedStmt)
180                         .getByte(parameterIndex);
181             } else {
182                 throw new SQLException JavaDoc(
183                         "No operations allowed after statement closed",
184                         SQLError.SQL_STATE_GENERAL_ERROR);
185             }
186         } catch (SQLException JavaDoc sqlEx) {
187             checkAndFireConnectionError(sqlEx);
188         }
189
190         return 0;
191     }
192
193     /*
194      * (non-Javadoc)
195      *
196      * @see java.sql.CallableStatement#getShort(int)
197      */

198     public short getShort(int parameterIndex) throws SQLException JavaDoc {
199         try {
200             if (this.wrappedStmt != null) {
201                 return ((CallableStatement JavaDoc) this.wrappedStmt)
202                         .getShort(parameterIndex);
203             } else {
204                 throw new SQLException JavaDoc(
205                         "No operations allowed after statement closed",
206                         SQLError.SQL_STATE_GENERAL_ERROR);
207             }
208         } catch (SQLException JavaDoc sqlEx) {
209             checkAndFireConnectionError(sqlEx);
210         }
211
212         return 0;
213     }
214
215     /*
216      * (non-Javadoc)
217      *
218      * @see java.sql.CallableStatement#getInt(int)
219      */

220     public int getInt(int parameterIndex) throws SQLException JavaDoc {
221         try {
222             if (this.wrappedStmt != null) {
223                 return ((CallableStatement JavaDoc) this.wrappedStmt)
224                         .getInt(parameterIndex);
225             } else {
226                 throw new SQLException JavaDoc(
227                         "No operations allowed after statement closed",
228                         SQLError.SQL_STATE_GENERAL_ERROR);
229             }
230         } catch (SQLException JavaDoc sqlEx) {
231             checkAndFireConnectionError(sqlEx);
232         }
233
234         return 0;
235     }
236
237     /*
238      * (non-Javadoc)
239      *
240      * @see java.sql.CallableStatement#getLong(int)
241      */

242     public long getLong(int parameterIndex) throws SQLException JavaDoc {
243         try {
244             if (this.wrappedStmt != null) {
245                 return ((CallableStatement JavaDoc) this.wrappedStmt)
246                         .getLong(parameterIndex);
247             } else {
248                 throw new SQLException JavaDoc(
249                         "No operations allowed after statement closed",
250                         SQLError.SQL_STATE_GENERAL_ERROR);
251             }
252         } catch (SQLException JavaDoc sqlEx) {
253             checkAndFireConnectionError(sqlEx);
254         }
255
256         return 0;
257     }
258
259     /*
260      * (non-Javadoc)
261      *
262      * @see java.sql.CallableStatement#getFloat(int)
263      */

264     public float getFloat(int parameterIndex) throws SQLException JavaDoc {
265         try {
266             if (this.wrappedStmt != null) {
267                 return ((CallableStatement JavaDoc) this.wrappedStmt)
268                         .getFloat(parameterIndex);
269             } else {
270                 throw new SQLException JavaDoc(
271                         "No operations allowed after statement closed",
272                         SQLError.SQL_STATE_GENERAL_ERROR);
273             }
274         } catch (SQLException JavaDoc sqlEx) {
275             checkAndFireConnectionError(sqlEx);
276         }
277
278         return 0;
279     }
280
281     /*
282      * (non-Javadoc)
283      *
284      * @see java.sql.CallableStatement#getDouble(int)
285      */

286     public double getDouble(int parameterIndex) throws SQLException JavaDoc {
287         try {
288             if (this.wrappedStmt != null) {
289                 return ((CallableStatement JavaDoc) this.wrappedStmt)
290                         .getDouble(parameterIndex);
291             } else {
292                 throw new SQLException JavaDoc(
293                         "No operations allowed after statement closed",
294                         SQLError.SQL_STATE_GENERAL_ERROR);
295             }
296         } catch (SQLException JavaDoc sqlEx) {
297             checkAndFireConnectionError(sqlEx);
298         }
299
300         return 0;
301     }
302
303     /*
304      * (non-Javadoc)
305      *
306      * @see java.sql.CallableStatement#getBigDecimal(int, int)
307      */

308     public BigDecimal JavaDoc getBigDecimal(int parameterIndex, int scale)
309             throws SQLException JavaDoc {
310         try {
311             if (this.wrappedStmt != null) {
312                 return ((CallableStatement JavaDoc) this.wrappedStmt).getBigDecimal(
313                         parameterIndex, scale);
314             } else {
315                 throw new SQLException JavaDoc(
316                         "No operations allowed after statement closed",
317                         SQLError.SQL_STATE_GENERAL_ERROR);
318             }
319         } catch (SQLException JavaDoc sqlEx) {
320             checkAndFireConnectionError(sqlEx);
321         }
322
323         return null;
324     }
325
326     /*
327      * (non-Javadoc)
328      *
329      * @see java.sql.CallableStatement#getBytes(int)
330      */

331     public byte[] getBytes(int parameterIndex) throws SQLException JavaDoc {
332         try {
333             if (this.wrappedStmt != null) {
334                 return ((CallableStatement JavaDoc) this.wrappedStmt)
335                         .getBytes(parameterIndex);
336             } else {
337                 throw new SQLException JavaDoc(
338                         "No operations allowed after statement closed",
339                         SQLError.SQL_STATE_GENERAL_ERROR);
340             }
341         } catch (SQLException JavaDoc sqlEx) {
342             checkAndFireConnectionError(sqlEx);
343         }
344
345         return null;
346     }
347
348     /*
349      * (non-Javadoc)
350      *
351      * @see java.sql.CallableStatement#getDate(int)
352      */

353     public Date JavaDoc getDate(int parameterIndex) throws SQLException JavaDoc {
354         try {
355             if (this.wrappedStmt != null) {
356                 return ((CallableStatement JavaDoc) this.wrappedStmt)
357                         .getDate(parameterIndex);
358             } else {
359                 throw new SQLException JavaDoc(
360                         "No operations allowed after statement closed",
361                         SQLError.SQL_STATE_GENERAL_ERROR);
362             }
363         } catch (SQLException JavaDoc sqlEx) {
364             checkAndFireConnectionError(sqlEx);
365         }
366
367         return null;
368     }
369
370     /*
371      * (non-Javadoc)
372      *
373      * @see java.sql.CallableStatement#getTime(int)
374      */

375     public Time JavaDoc getTime(int parameterIndex) throws SQLException JavaDoc {
376         try {
377             if (this.wrappedStmt != null) {
378                 return ((CallableStatement JavaDoc) this.wrappedStmt)
379                         .getTime(parameterIndex);
380             } else {
381                 throw new SQLException JavaDoc(
382                         "No operations allowed after statement closed",
383                         SQLError.SQL_STATE_GENERAL_ERROR);
384             }
385         } catch (SQLException JavaDoc sqlEx) {
386             checkAndFireConnectionError(sqlEx);
387         }
388
389         return null;
390     }
391
392     /*
393      * (non-Javadoc)
394      *
395      * @see java.sql.CallableStatement#getTimestamp(int)
396      */

397     public Timestamp JavaDoc getTimestamp(int parameterIndex) throws SQLException JavaDoc {
398         try {
399             if (this.wrappedStmt != null) {
400                 return ((CallableStatement JavaDoc) this.wrappedStmt)
401                         .getTimestamp(parameterIndex);
402             } else {
403                 throw new SQLException JavaDoc(
404                         "No operations allowed after statement closed",
405                         SQLError.SQL_STATE_GENERAL_ERROR);
406             }
407         } catch (SQLException JavaDoc sqlEx) {
408             checkAndFireConnectionError(sqlEx);
409         }
410
411         return null;
412     }
413
414     /*
415      * (non-Javadoc)
416      *
417      * @see java.sql.CallableStatement#getObject(int)
418      */

419     public Object JavaDoc getObject(int parameterIndex) throws SQLException JavaDoc {
420         try {
421             if (this.wrappedStmt != null) {
422                 return ((CallableStatement JavaDoc) this.wrappedStmt)
423                         .getObject(parameterIndex);
424             } else {
425                 throw new SQLException JavaDoc(
426                         "No operations allowed after statement closed",
427                         SQLError.SQL_STATE_GENERAL_ERROR);
428             }
429         } catch (SQLException JavaDoc sqlEx) {
430             checkAndFireConnectionError(sqlEx);
431         }
432
433         return null;
434     }
435
436     /*
437      * (non-Javadoc)
438      *
439      * @see java.sql.CallableStatement#getBigDecimal(int)
440      */

441     public BigDecimal JavaDoc getBigDecimal(int parameterIndex) throws SQLException JavaDoc {
442         try {
443             if (this.wrappedStmt != null) {
444                 return ((CallableStatement JavaDoc) this.wrappedStmt)
445                         .getBigDecimal(parameterIndex);
446             } else {
447                 throw new SQLException JavaDoc(
448                         "No operations allowed after statement closed",
449                         SQLError.SQL_STATE_GENERAL_ERROR);
450             }
451         } catch (SQLException JavaDoc sqlEx) {
452             checkAndFireConnectionError(sqlEx);
453         }
454
455         return null;
456     }
457
458     /*
459      * (non-Javadoc)
460      *
461      * @see java.sql.CallableStatement#getObject(int, java.util.Map)
462      */

463     public Object JavaDoc getObject(int parameterIndex, Map JavaDoc typeMap)
464             throws SQLException JavaDoc {
465         try {
466             if (this.wrappedStmt != null) {
467                 return ((CallableStatement JavaDoc) this.wrappedStmt).getObject(
468                         parameterIndex, typeMap);
469             } else {
470                 throw new SQLException JavaDoc(
471                         "No operations allowed after statement closed",
472                         SQLError.SQL_STATE_GENERAL_ERROR);
473             }
474         } catch (SQLException JavaDoc sqlEx) {
475             checkAndFireConnectionError(sqlEx);
476         }
477         return null;
478     }
479
480     /*
481      * (non-Javadoc)
482      *
483      * @see java.sql.CallableStatement#getRef(int)
484      */

485     public Ref JavaDoc getRef(int parameterIndex) throws SQLException JavaDoc {
486         try {
487             if (this.wrappedStmt != null) {
488                 return ((CallableStatement JavaDoc) this.wrappedStmt)
489                         .getRef(parameterIndex);
490             } else {
491                 throw new SQLException JavaDoc(
492                         "No operations allowed after statement closed",
493                         SQLError.SQL_STATE_GENERAL_ERROR);
494             }
495         } catch (SQLException JavaDoc sqlEx) {
496             checkAndFireConnectionError(sqlEx);
497         }
498
499         return null;
500     }
501
502     /*
503      * (non-Javadoc)
504      *
505      * @see java.sql.CallableStatement#getBlob(int)
506      */

507     public Blob JavaDoc getBlob(int parameterIndex) throws SQLException JavaDoc {
508         try {
509             if (this.wrappedStmt != null) {
510                 return ((CallableStatement JavaDoc) this.wrappedStmt)
511                         .getBlob(parameterIndex);
512             } else {
513                 throw new SQLException JavaDoc(
514                         "No operations allowed after statement closed",
515                         SQLError.SQL_STATE_GENERAL_ERROR);
516             }
517         } catch (SQLException JavaDoc sqlEx) {
518             checkAndFireConnectionError(sqlEx);
519         }
520
521         return null;
522     }
523
524     /*
525      * (non-Javadoc)
526      *
527      * @see java.sql.CallableStatement#getClob(int)
528      */

529     public Clob JavaDoc getClob(int parameterIndex) throws SQLException JavaDoc {
530         try {
531             if (this.wrappedStmt != null) {
532                 return ((CallableStatement JavaDoc) this.wrappedStmt)
533                         .getClob(parameterIndex);
534             } else {
535                 throw new SQLException JavaDoc(
536                         "No operations allowed after statement closed",
537                         SQLError.SQL_STATE_GENERAL_ERROR);
538             }
539         } catch (SQLException JavaDoc sqlEx) {
540             checkAndFireConnectionError(sqlEx);
541         }
542         return null;
543     }
544
545     /*
546      * (non-Javadoc)
547      *
548      * @see java.sql.CallableStatement#getArray(int)
549      */

550     public Array JavaDoc getArray(int parameterIndex) throws SQLException JavaDoc {
551         try {
552             if (this.wrappedStmt != null) {
553                 return ((CallableStatement JavaDoc) this.wrappedStmt)
554                         .getArray(parameterIndex);
555             } else {
556                 throw new SQLException JavaDoc(
557                         "No operations allowed after statement closed",
558                         SQLError.SQL_STATE_GENERAL_ERROR);
559             }
560         } catch (SQLException JavaDoc sqlEx) {
561             checkAndFireConnectionError(sqlEx);
562         }
563         return null;
564     }
565
566     /*
567      * (non-Javadoc)
568      *
569      * @see java.sql.CallableStatement#getDate(int, java.util.Calendar)
570      */

571     public Date JavaDoc getDate(int parameterIndex, Calendar JavaDoc cal) throws SQLException JavaDoc {
572         try {
573             if (this.wrappedStmt != null) {
574                 return ((CallableStatement JavaDoc) this.wrappedStmt).getDate(
575                         parameterIndex, cal);
576             } else {
577                 throw new SQLException JavaDoc(
578                         "No operations allowed after statement closed",
579                         SQLError.SQL_STATE_GENERAL_ERROR);
580             }
581         } catch (SQLException JavaDoc sqlEx) {
582             checkAndFireConnectionError(sqlEx);
583         }
584         return null;
585     }
586
587     /*
588      * (non-Javadoc)
589      *
590      * @see java.sql.CallableStatement#getTime(int, java.util.Calendar)
591      */

592     public Time JavaDoc getTime(int parameterIndex, Calendar JavaDoc cal) throws SQLException JavaDoc {
593         try {
594             if (this.wrappedStmt != null) {
595                 return ((CallableStatement JavaDoc) this.wrappedStmt).getTime(
596                         parameterIndex, cal);
597             } else {
598                 throw new SQLException JavaDoc(
599                         "No operations allowed after statement closed",
600                         SQLError.SQL_STATE_GENERAL_ERROR);
601             }
602         } catch (SQLException JavaDoc sqlEx) {
603             checkAndFireConnectionError(sqlEx);
604         }
605         return null;
606     }
607
608     /*
609      * (non-Javadoc)
610      *
611      * @see java.sql.CallableStatement#getTimestamp(int, java.util.Calendar)
612      */

613     public Timestamp JavaDoc getTimestamp(int parameterIndex, Calendar JavaDoc cal)
614             throws SQLException JavaDoc {
615         try {
616             if (this.wrappedStmt != null) {
617                 return ((CallableStatement JavaDoc) this.wrappedStmt).getTimestamp(
618                         parameterIndex, cal);
619             } else {
620                 throw new SQLException JavaDoc(
621                         "No operations allowed after statement closed",
622                         SQLError.SQL_STATE_GENERAL_ERROR);
623             }
624         } catch (SQLException JavaDoc sqlEx) {
625             checkAndFireConnectionError(sqlEx);
626         }
627         return null;
628     }
629
630     /*
631      * (non-Javadoc)
632      *
633      * @see java.sql.CallableStatement#registerOutParameter(int, int,
634      * java.lang.String)
635      */

636     public void registerOutParameter(int paramIndex, int sqlType,
637             String JavaDoc typeName) throws SQLException JavaDoc {
638         try {
639             if (this.wrappedStmt != null) {
640                 ((CallableStatement JavaDoc) this.wrappedStmt).registerOutParameter(
641                         paramIndex, sqlType, typeName);
642             } else {
643                 throw new SQLException JavaDoc(
644                         "No operations allowed after statement closed",
645                         SQLError.SQL_STATE_GENERAL_ERROR);
646             }
647         } catch (SQLException JavaDoc sqlEx) {
648             checkAndFireConnectionError(sqlEx);
649         }
650     }
651
652     /*
653      * (non-Javadoc)
654      *
655      * @see java.sql.CallableStatement#registerOutParameter(java.lang.String,
656      * int)
657      */

658     public void registerOutParameter(String JavaDoc parameterName, int sqlType)
659             throws SQLException JavaDoc {
660         try {
661             if (this.wrappedStmt != null) {
662                 ((CallableStatement JavaDoc) this.wrappedStmt).registerOutParameter(
663                         parameterName, sqlType);
664             } else {
665                 throw new SQLException JavaDoc(
666                         "No operations allowed after statement closed",
667                         SQLError.SQL_STATE_GENERAL_ERROR);
668             }
669         } catch (SQLException JavaDoc sqlEx) {
670             checkAndFireConnectionError(sqlEx);
671         }
672     }
673
674     /*
675      * (non-Javadoc)
676      *
677      * @see java.sql.CallableStatement#registerOutParameter(java.lang.String,
678      * int, int)
679      */

680     public void registerOutParameter(String JavaDoc parameterName, int sqlType,
681             int scale) throws SQLException JavaDoc {
682         try {
683             if (this.wrappedStmt != null) {
684                 ((CallableStatement JavaDoc) this.wrappedStmt).registerOutParameter(
685                         parameterName, sqlType, scale);
686             } else {
687                 throw new SQLException JavaDoc(
688                         "No operations allowed after statement closed",
689                         SQLError.SQL_STATE_GENERAL_ERROR);
690             }
691         } catch (SQLException JavaDoc sqlEx) {
692             checkAndFireConnectionError(sqlEx);
693         }
694     }
695
696     /*
697      * (non-Javadoc)
698      *
699      * @see java.sql.CallableStatement#registerOutParameter(java.lang.String,
700      * int, java.lang.String)
701      */

702     public void registerOutParameter(String JavaDoc parameterName, int sqlType,
703             String JavaDoc typeName) throws SQLException JavaDoc {
704         try {
705             if (this.wrappedStmt != null) {
706                 ((CallableStatement JavaDoc) this.wrappedStmt).registerOutParameter(
707                         parameterName, sqlType, typeName);
708             } else {
709                 throw new SQLException