KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > dbcp > DelegatingCallableStatement


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.dbcp;
18
19 import java.net.URL JavaDoc;
20 import java.sql.CallableStatement JavaDoc;
21 import java.math.BigDecimal JavaDoc;
22 import java.sql.Date JavaDoc;
23 import java.sql.Time JavaDoc;
24 import java.sql.Timestamp JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.sql.Ref JavaDoc;
27 import java.sql.Blob JavaDoc;
28 import java.sql.Clob JavaDoc;
29 import java.sql.Array JavaDoc;
30 import java.util.Calendar JavaDoc;
31 import java.io.InputStream JavaDoc;
32 import java.io.Reader JavaDoc;
33 import java.sql.SQLException JavaDoc;
34
35 /**
36  * A base delegating implementation of {@link CallableStatement}.
37  * <p>
38  * All of the methods from the {@link CallableStatement} interface
39  * simply call the corresponding method on the "delegate"
40  * provided in my constructor.
41  * <p>
42  * Extends AbandonedTrace to implement Statement tracking and
43  * logging of code which created the Statement. Tracking the
44  * Statement ensures that the Connection which created it can
45  * close any open Statement's on Connection close.
46  *
47  * @author Glenn L. Nielsen
48  * @author James House
49  * @author Dirk Verbeeck
50  * @version $Revision: 1.19 $ $Date: 2004/03/06 13:35:31 $
51  */

52 public class DelegatingCallableStatement extends DelegatingPreparedStatement
53         implements CallableStatement JavaDoc {
54
55     /** My delegate. */
56     protected CallableStatement JavaDoc _stmt = null;
57
58     /**
59      * Create a wrapper for the Statement which traces this
60      * Statement to the Connection which created it and the
61      * code which created it.
62      *
63      * @param cs the {@link CallableStatement} to delegate all calls to.
64      */

65     public DelegatingCallableStatement(DelegatingConnection c,
66                                        CallableStatement JavaDoc s) {
67         super(c, s);
68         _stmt = s;
69     }
70
71     public boolean equals(Object JavaDoc obj) {
72         CallableStatement JavaDoc delegate = (CallableStatement JavaDoc) getInnermostDelegate();
73         if (delegate == null) {
74             return false;
75         }
76         if (obj instanceof DelegatingCallableStatement) {
77             DelegatingCallableStatement s = (DelegatingCallableStatement) obj;
78             return delegate.equals(s.getInnermostDelegate());
79         }
80         else {
81             return delegate.equals(obj);
82         }
83     }
84
85     /** Sets my delegate. */
86     public void setDelegate(CallableStatement JavaDoc s) {
87         super.setDelegate(s);
88         _stmt = s;
89     }
90
91     public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException JavaDoc
92     { checkOpen(); try { _stmt.registerOutParameter( parameterIndex, sqlType); } catch (SQLException JavaDoc e) { handleException(e); } }
93
94     public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException JavaDoc
95     { checkOpen(); try { _stmt.registerOutParameter( parameterIndex, sqlType, scale); } catch (SQLException JavaDoc e) { handleException(e); } }
96
97     public boolean wasNull() throws SQLException JavaDoc
98     { checkOpen(); try { return _stmt.wasNull(); } catch (SQLException JavaDoc e) { handleException(e); return false; } }
99
100     public String JavaDoc getString(int parameterIndex) throws SQLException JavaDoc
101     { checkOpen(); try { return _stmt.getString( parameterIndex); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
102
103     public boolean getBoolean(int parameterIndex) throws SQLException JavaDoc
104     { checkOpen(); try { return _stmt.getBoolean( parameterIndex); } catch (SQLException JavaDoc e) { handleException(e); return false; } }
105
106     public byte getByte(int parameterIndex) throws SQLException JavaDoc
107     { checkOpen(); try { return _stmt.getByte( parameterIndex); } catch (SQLException JavaDoc e) { handleException(e); return 0; } }
108
109     public short getShort(int parameterIndex) throws SQLException JavaDoc
110     { checkOpen(); try { return _stmt.getShort( parameterIndex); } catch (SQLException JavaDoc e) { handleException(e); return 0; } }
111
112     public int getInt(int parameterIndex) throws SQLException JavaDoc
113     { checkOpen(); try { return _stmt.getInt( parameterIndex); } catch (SQLException JavaDoc e) { handleException(e); return 0; } }
114
115     public long getLong(int parameterIndex) throws SQLException JavaDoc
116     { checkOpen(); try { return _stmt.getLong( parameterIndex); } catch (SQLException JavaDoc e) { handleException(e); return 0; } }
117
118     public float getFloat(int parameterIndex) throws SQLException JavaDoc
119     { checkOpen(); try { return _stmt.getFloat( parameterIndex); } catch (SQLException JavaDoc e) { handleException(e); return 0; } }
120
121     public double getDouble(int parameterIndex) throws SQLException JavaDoc
122     { checkOpen(); try { return _stmt.getDouble( parameterIndex); } catch (SQLException JavaDoc e) { handleException(e); return 0; } }
123
124     /** @deprecated */
125     public BigDecimal JavaDoc getBigDecimal(int parameterIndex, int scale) throws SQLException JavaDoc
126     { checkOpen(); try { return _stmt.getBigDecimal( parameterIndex, scale); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
127
128     public byte[] getBytes(int parameterIndex) throws SQLException JavaDoc
129     { checkOpen(); try { return _stmt.getBytes( parameterIndex); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
130
131     public Date JavaDoc getDate(int parameterIndex) throws SQLException JavaDoc
132     { checkOpen(); try { return _stmt.getDate( parameterIndex); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
133
134     public Time JavaDoc getTime(int parameterIndex) throws SQLException JavaDoc
135     { checkOpen(); try { return _stmt.getTime( parameterIndex); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
136
137     public Timestamp JavaDoc getTimestamp(int parameterIndex) throws SQLException JavaDoc
138     { checkOpen(); try { return _stmt.getTimestamp( parameterIndex); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
139
140     public Object JavaDoc getObject(int parameterIndex) throws SQLException JavaDoc
141     { checkOpen(); try { return _stmt.getObject( parameterIndex); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
142
143     public BigDecimal JavaDoc getBigDecimal(int parameterIndex) throws SQLException JavaDoc
144     { checkOpen(); try { return _stmt.getBigDecimal( parameterIndex); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
145
146     public Object JavaDoc getObject(int i, Map JavaDoc map) throws SQLException JavaDoc
147     { checkOpen(); try { return _stmt.getObject( i, map); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
148
149     public Ref JavaDoc getRef(int i) throws SQLException JavaDoc
150     { checkOpen(); try { return _stmt.getRef( i); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
151
152     public Blob JavaDoc getBlob(int i) throws SQLException JavaDoc
153     { checkOpen(); try { return _stmt.getBlob( i); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
154
155     public Clob JavaDoc getClob(int i) throws SQLException JavaDoc
156     { checkOpen(); try { return _stmt.getClob( i); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
157
158     public Array JavaDoc getArray(int i) throws SQLException JavaDoc
159     { checkOpen(); try { return _stmt.getArray( i); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
160
161     public Date JavaDoc getDate(int parameterIndex, Calendar JavaDoc cal) throws SQLException JavaDoc
162     { checkOpen(); try { return _stmt.getDate( parameterIndex, cal); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
163
164     public Time JavaDoc getTime(int parameterIndex, Calendar JavaDoc cal) throws SQLException JavaDoc
165     { checkOpen(); try { return _stmt.getTime( parameterIndex, cal); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
166
167     public Timestamp JavaDoc getTimestamp(int parameterIndex, Calendar JavaDoc cal) throws SQLException JavaDoc
168     { checkOpen(); try { return _stmt.getTimestamp( parameterIndex, cal); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
169
170     public void registerOutParameter(int paramIndex, int sqlType, String JavaDoc typeName) throws SQLException JavaDoc
171     { checkOpen(); try { _stmt.registerOutParameter( paramIndex, sqlType, typeName); } catch (SQLException JavaDoc e) { handleException(e); } }
172
173     // ------------------- JDBC 3.0 -----------------------------------------
174
// Will be commented by the build process on a JDBC 2.0 system
175

176 /* JDBC_3_ANT_KEY_BEGIN */
177
178     public void registerOutParameter(String JavaDoc parameterName, int sqlType) throws SQLException JavaDoc
179     { checkOpen(); try { _stmt.registerOutParameter(parameterName, sqlType); } catch (SQLException JavaDoc e) { handleException(e); } }
180
181     public void registerOutParameter(String JavaDoc parameterName, int sqlType, int scale) throws SQLException JavaDoc
182     { checkOpen(); try { _stmt.registerOutParameter(parameterName, sqlType, scale); } catch (SQLException JavaDoc e) { handleException(e); } }
183
184     public void registerOutParameter(String JavaDoc parameterName, int sqlType, String JavaDoc typeName) throws SQLException JavaDoc
185     { checkOpen(); try { _stmt.registerOutParameter(parameterName, sqlType, typeName); } catch (SQLException JavaDoc e) { handleException(e); } }
186
187     public URL JavaDoc getURL(int parameterIndex) throws SQLException JavaDoc
188     { checkOpen(); try { return _stmt.getURL(parameterIndex); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
189
190     public void setURL(String JavaDoc parameterName, URL JavaDoc val) throws SQLException JavaDoc
191     { checkOpen(); try { _stmt.setURL(parameterName, val); } catch (SQLException JavaDoc e) { handleException(e); } }
192
193     public void setNull(String JavaDoc parameterName, int sqlType) throws SQLException JavaDoc
194     { checkOpen(); try { _stmt.setNull(parameterName, sqlType); } catch (SQLException JavaDoc e) { handleException(e); } }
195
196     public void setBoolean(String JavaDoc parameterName, boolean x) throws SQLException JavaDoc
197     { checkOpen(); try { _stmt.setBoolean(parameterName, x); } catch (SQLException JavaDoc e) { handleException(e); } }
198
199     public void setByte(String JavaDoc parameterName, byte x) throws SQLException JavaDoc
200     { checkOpen(); try { _stmt.setByte(parameterName, x); } catch (SQLException JavaDoc e) { handleException(e); } }
201
202     public void setShort(String JavaDoc parameterName, short x) throws SQLException JavaDoc
203     { checkOpen(); try { _stmt.setShort(parameterName, x); } catch (SQLException JavaDoc e) { handleException(e); } }
204
205     public void setInt(String JavaDoc parameterName, int x) throws SQLException JavaDoc
206     { checkOpen(); try { _stmt.setInt(parameterName, x); } catch (SQLException JavaDoc e) { handleException(e); } }
207
208     public void setLong(String JavaDoc parameterName, long x) throws SQLException JavaDoc
209     { checkOpen(); try { _stmt.setLong(parameterName, x); } catch (SQLException JavaDoc e) { handleException(e); } }
210
211     public void setFloat(String JavaDoc parameterName, float x) throws SQLException JavaDoc
212     { checkOpen(); try { _stmt.setFloat(parameterName, x); } catch (SQLException JavaDoc e) { handleException(e); } }
213
214     public void setDouble(String JavaDoc parameterName, double x) throws SQLException JavaDoc
215     { checkOpen(); try { _stmt.setDouble(parameterName, x); } catch (SQLException JavaDoc e) { handleException(e); } }
216
217     public void setBigDecimal(String JavaDoc parameterName, BigDecimal JavaDoc x) throws SQLException JavaDoc
218     { checkOpen(); try { _stmt.setBigDecimal(parameterName, x); } catch (SQLException JavaDoc e) { handleException(e); } }
219
220     public void setString(String JavaDoc parameterName, String JavaDoc x) throws SQLException JavaDoc
221     { checkOpen(); try { _stmt.setString(parameterName, x); } catch (SQLException JavaDoc e) { handleException(e); } }
222
223     public void setBytes(String JavaDoc parameterName, byte [] x) throws SQLException JavaDoc
224     { checkOpen(); try { _stmt.setBytes(parameterName, x); } catch (SQLException JavaDoc e) { handleException(e); } }
225
226     public void setDate(String JavaDoc parameterName, Date JavaDoc x) throws SQLException JavaDoc
227     { checkOpen(); try { _stmt.setDate(parameterName, x); } catch (SQLException JavaDoc e) { handleException(e); } }
228
229     public void setTime(String JavaDoc parameterName, Time JavaDoc x) throws SQLException JavaDoc
230     { checkOpen(); try { _stmt.setTime(parameterName, x); } catch (SQLException JavaDoc e) { handleException(e); } }
231
232     public void setTimestamp(String JavaDoc parameterName, Timestamp JavaDoc x) throws SQLException JavaDoc
233     { checkOpen(); try { _stmt.setTimestamp(parameterName, x); } catch (SQLException JavaDoc e) { handleException(e); } }
234
235     public void setAsciiStream(String JavaDoc parameterName, InputStream JavaDoc x, int length) throws SQLException JavaDoc
236     { checkOpen(); try { _stmt.setAsciiStream(parameterName, x, length); } catch (SQLException JavaDoc e) { handleException(e); } }
237
238     public void setBinaryStream(String JavaDoc parameterName, InputStream JavaDoc x, int length) throws SQLException JavaDoc
239     { checkOpen(); try { _stmt.setBinaryStream(parameterName, x, length); } catch (SQLException JavaDoc e) { handleException(e); } }
240
241     public void setObject(String JavaDoc parameterName, Object JavaDoc x, int targetSqlType, int scale) throws SQLException JavaDoc
242     { checkOpen(); try { _stmt.setObject(parameterName, x, targetSqlType, scale); } catch (SQLException JavaDoc e) { handleException(e); } }
243
244     public void setObject(String JavaDoc parameterName, Object JavaDoc x, int targetSqlType) throws SQLException JavaDoc
245     { checkOpen(); try { _stmt.setObject(parameterName, x, targetSqlType); } catch (SQLException JavaDoc e) { handleException(e); } }
246
247     public void setObject(String JavaDoc parameterName, Object JavaDoc x) throws SQLException JavaDoc
248     { checkOpen(); try { _stmt.setObject(parameterName, x); } catch (SQLException JavaDoc e) { handleException(e); } }
249
250     public void setCharacterStream(String JavaDoc parameterName, Reader JavaDoc reader, int length) throws SQLException JavaDoc
251     { checkOpen(); _stmt.setCharacterStream(parameterName, reader, length); }
252
253     public void setDate(String JavaDoc parameterName, Date JavaDoc x, Calendar JavaDoc cal) throws SQLException JavaDoc
254     { checkOpen(); try { _stmt.setDate(parameterName, x, cal); } catch (SQLException JavaDoc e) { handleException(e); } }
255
256     public void setTime(String JavaDoc parameterName, Time JavaDoc x, Calendar JavaDoc cal) throws SQLException JavaDoc
257     { checkOpen(); try { _stmt.setTime(parameterName, x, cal); } catch (SQLException JavaDoc e) { handleException(e); } }
258
259     public void setTimestamp(String JavaDoc parameterName, Timestamp JavaDoc x, Calendar JavaDoc cal) throws SQLException JavaDoc
260     { checkOpen(); try { _stmt.setTimestamp(parameterName, x, cal); } catch (SQLException JavaDoc e) { handleException(e); } }
261
262     public void setNull(String JavaDoc parameterName, int sqlType, String JavaDoc typeName) throws SQLException JavaDoc
263     { checkOpen(); try { _stmt.setNull(parameterName, sqlType, typeName); } catch (SQLException JavaDoc e) { handleException(e); } }
264
265     public String JavaDoc getString(String JavaDoc parameterName) throws SQLException JavaDoc
266     { checkOpen(); try { return _stmt.getString(parameterName); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
267
268     public boolean getBoolean(String JavaDoc parameterName) throws SQLException JavaDoc
269     { checkOpen(); try { return _stmt.getBoolean(parameterName); } catch (SQLException JavaDoc e) { handleException(e); return false; } }
270
271     public byte getByte(String JavaDoc parameterName) throws SQLException JavaDoc
272     { checkOpen(); try { return _stmt.getByte(parameterName); } catch (SQLException JavaDoc e) { handleException(e); return 0; } }
273
274     public short getShort(String JavaDoc parameterName) throws SQLException JavaDoc
275     { checkOpen(); try { return _stmt.getShort(parameterName); } catch (SQLException JavaDoc e) { handleException(e); return 0; } }
276
277     public int getInt(String JavaDoc parameterName) throws SQLException JavaDoc
278     { checkOpen(); try { return _stmt.getInt(parameterName); } catch (SQLException JavaDoc e) { handleException(e); return 0; } }
279
280     public long getLong(String JavaDoc parameterName) throws SQLException JavaDoc
281     { checkOpen(); try { return _stmt.getLong(parameterName); } catch (SQLException JavaDoc e) { handleException(e); return 0; } }
282
283     public float getFloat(String JavaDoc parameterName) throws SQLException JavaDoc
284     { checkOpen(); try { return _stmt.getFloat(parameterName); } catch (SQLException JavaDoc e) { handleException(e); return 0; } }
285
286     public double getDouble(String JavaDoc parameterName) throws SQLException JavaDoc
287     { checkOpen(); try { return _stmt.getDouble(parameterName); } catch (SQLException JavaDoc e) { handleException(e); return 0; } }
288
289     public byte[] getBytes(String JavaDoc parameterName) throws SQLException JavaDoc
290     { checkOpen(); try { return _stmt.getBytes(parameterName); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
291
292     public Date JavaDoc getDate(String JavaDoc parameterName) throws SQLException JavaDoc
293     { checkOpen(); try { return _stmt.getDate(parameterName); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
294
295     public Time JavaDoc getTime(String JavaDoc parameterName) throws SQLException JavaDoc
296     { checkOpen(); try { return _stmt.getTime(parameterName); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
297
298     public Timestamp JavaDoc getTimestamp(String JavaDoc parameterName) throws SQLException JavaDoc
299     { checkOpen(); try { return _stmt.getTimestamp(parameterName); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
300
301     public Object JavaDoc getObject(String JavaDoc parameterName) throws SQLException JavaDoc
302     { checkOpen(); try { return _stmt.getObject(parameterName); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
303
304     public BigDecimal JavaDoc getBigDecimal(String JavaDoc parameterName) throws SQLException JavaDoc
305     { checkOpen(); try { return _stmt.getBigDecimal(parameterName); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
306
307     public Object JavaDoc getObject(String JavaDoc parameterName, Map JavaDoc map) throws SQLException JavaDoc
308     { checkOpen(); try { return _stmt.getObject(parameterName, map); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
309
310     public Ref JavaDoc getRef(String JavaDoc parameterName) throws SQLException JavaDoc
311     { checkOpen(); try { return _stmt.getRef(parameterName); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
312
313     public Blob JavaDoc getBlob(String JavaDoc parameterName) throws SQLException JavaDoc
314     { checkOpen(); try { return _stmt.getBlob(parameterName); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
315
316     public Clob JavaDoc getClob(String JavaDoc parameterName) throws SQLException JavaDoc
317     { checkOpen(); try { return _stmt.getClob(parameterName); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
318
319     public Array JavaDoc getArray(String JavaDoc parameterName) throws SQLException JavaDoc
320     { checkOpen(); try { return _stmt.getArray(parameterName); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
321
322     public Date JavaDoc getDate(String JavaDoc parameterName, Calendar JavaDoc cal) throws SQLException JavaDoc
323     { checkOpen(); try { return _stmt.getDate(parameterName, cal); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
324
325     public Time JavaDoc getTime(String JavaDoc parameterName, Calendar JavaDoc cal) throws SQLException JavaDoc
326     { checkOpen(); try { return _stmt.getTime(parameterName, cal); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
327
328     public Timestamp JavaDoc getTimestamp(String JavaDoc parameterName, Calendar JavaDoc cal) throws SQLException JavaDoc
329     { checkOpen(); try { return _stmt.getTimestamp(parameterName, cal); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
330
331     public URL JavaDoc getURL(String JavaDoc parameterName) throws SQLException JavaDoc
332     { checkOpen(); try { return _stmt.getURL(parameterName); } catch (SQLException JavaDoc e) { handleException(e); return null; } }
333
334 /* JDBC_3_ANT_KEY_END */
335 }
Popular Tags