KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > resource > adapter > jdbc > WrappedPreparedStatement


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.resource.adapter.jdbc;
23
24 import java.io.InputStream JavaDoc;
25 import java.io.Reader JavaDoc;
26 import java.math.BigDecimal JavaDoc;
27 import java.net.URL JavaDoc;
28 import java.sql.Array JavaDoc;
29 import java.sql.Blob JavaDoc;
30 import java.sql.Clob JavaDoc;
31 import java.sql.Date JavaDoc;
32 import java.sql.ParameterMetaData JavaDoc;
33 import java.sql.PreparedStatement JavaDoc;
34 import java.sql.Ref JavaDoc;
35 import java.sql.ResultSet JavaDoc;
36 import java.sql.ResultSetMetaData JavaDoc;
37 import java.sql.SQLException JavaDoc;
38 import java.sql.Statement JavaDoc;
39 import java.sql.Time JavaDoc;
40 import java.sql.Timestamp JavaDoc;
41 import java.util.Calendar JavaDoc;
42
43 /**
44  * A wrapper for a prepared statement.
45  *
46  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
47  * @author <a HREF="mailto:adrian@jboss.com">Adrian Brock</a>
48  * @version $Revision: 40746 $
49  */

50 public class WrappedPreparedStatement extends WrappedStatement implements PreparedStatement JavaDoc
51 {
52    private final PreparedStatement JavaDoc ps;
53
54    public WrappedPreparedStatement(final WrappedConnection lc, final PreparedStatement JavaDoc ps)
55    {
56       super(lc, ps);
57       this.ps = ps;
58    }
59
60    public Statement JavaDoc getUnderlyingStatement() throws SQLException JavaDoc
61    {
62       checkState();
63       if (ps instanceof CachedPreparedStatement)
64       {
65          return ((CachedPreparedStatement)ps).getUnderlyingPreparedStatement();
66       }
67       else
68       {
69          return ps;
70       }
71    }
72
73    public void setBoolean(int parameterIndex, boolean value) throws SQLException JavaDoc
74    {
75       checkState();
76       try
77       {
78          ps.setBoolean(parameterIndex, value);
79       }
80       catch (Throwable JavaDoc t)
81       {
82          throw checkException(t);
83       }
84    }
85
86    public void setByte(int parameterIndex, byte value) throws SQLException JavaDoc
87    {
88       checkState();
89       try
90       {
91          ps.setByte(parameterIndex, value);
92       }
93       catch (Throwable JavaDoc t)
94       {
95          throw checkException(t);
96       }
97    }
98
99    public void setShort(int parameterIndex, short value) throws SQLException JavaDoc
100    {
101       checkState();
102       try
103       {
104          ps.setShort(parameterIndex, value);
105       }
106       catch (Throwable JavaDoc t)
107       {
108          throw checkException(t);
109       }
110    }
111
112    public void setInt(int parameterIndex, int value) throws SQLException JavaDoc
113    {
114       checkState();
115       try
116       {
117          ps.setInt(parameterIndex, value);
118       }
119       catch (Throwable JavaDoc t)
120       {
121          throw checkException(t);
122       }
123    }
124
125    public void setLong(int parameterIndex, long value) throws SQLException JavaDoc
126    {
127       checkState();
128       try
129       {
130          ps.setLong(parameterIndex, value);
131       }
132       catch (Throwable JavaDoc t)
133       {
134          throw checkException(t);
135       }
136    }
137
138    public void setFloat(int parameterIndex, float value) throws SQLException JavaDoc
139    {
140       checkState();
141       try
142       {
143          ps.setFloat(parameterIndex, value);
144       }
145       catch (Throwable JavaDoc t)
146       {
147          throw checkException(t);
148       }
149    }
150
151    public void setDouble(int parameterIndex, double value) throws SQLException JavaDoc
152    {
153       checkState();
154       try
155       {
156          ps.setDouble(parameterIndex, value);
157       }
158       catch (Throwable JavaDoc t)
159       {
160          throw checkException(t);
161       }
162    }
163
164    public void setURL(int parameterIndex, URL JavaDoc value) throws SQLException JavaDoc
165    {
166       checkState();
167       try
168       {
169          ps.setURL(parameterIndex, value);
170       }
171       catch (Throwable JavaDoc t)
172       {
173          throw checkException(t);
174       }
175    }
176
177    public void setTime(int parameterIndex, Time JavaDoc value) throws SQLException JavaDoc
178    {
179       checkState();
180       try
181       {
182          ps.setTime(parameterIndex, value);
183       }
184       catch (Throwable JavaDoc t)
185       {
186          throw checkException(t);
187       }
188    }
189
190    public void setTime(int parameterIndex, Time JavaDoc value, Calendar JavaDoc calendar) throws SQLException JavaDoc
191    {
192       checkState();
193       try
194       {
195          ps.setTime(parameterIndex, value, calendar);
196       }
197       catch (Throwable JavaDoc t)
198       {
199          throw checkException(t);
200       }
201    }
202
203    public boolean execute() throws SQLException JavaDoc
204    {
205       checkTransaction();
206       try
207       {
208          checkConfiguredQueryTimeout();
209          return ps.execute();
210       }
211       catch (Throwable JavaDoc t)
212       {
213          throw checkException(t);
214       }
215    }
216
217    public ResultSetMetaData JavaDoc getMetaData() throws SQLException JavaDoc
218    {
219       checkState();
220       try
221       {
222          return ps.getMetaData();
223       }
224       catch (Throwable JavaDoc t)
225       {
226          throw checkException(t);
227       }
228    }
229
230    public ResultSet JavaDoc executeQuery() throws SQLException JavaDoc
231    {
232       checkTransaction();
233       try
234       {
235          checkConfiguredQueryTimeout();
236          ResultSet JavaDoc resultSet = ps.executeQuery();
237          return registerResultSet(resultSet);
238       }
239       catch (Throwable JavaDoc t)
240       {
241          throw checkException(t);
242       }
243    }
244
245    public int executeUpdate() throws SQLException JavaDoc
246    {
247       checkTransaction();
248       try
249       {
250          checkConfiguredQueryTimeout();
251          return ps.executeUpdate();
252       }
253       catch (Throwable JavaDoc t)
254       {
255          throw checkException(t);
256       }
257    }
258
259    public void addBatch() throws SQLException JavaDoc
260    {
261       checkState();
262       try
263       {
264          ps.addBatch();
265       }
266       catch (Throwable JavaDoc t)
267       {
268          throw checkException(t);
269       }
270    }
271
272    public void setNull(int parameterIndex, int sqlType) throws SQLException JavaDoc
273    {
274       checkState();
275       try
276       {
277          ps.setNull(parameterIndex, sqlType);
278       }
279       catch (Throwable JavaDoc t)
280       {
281          throw checkException(t);
282       }
283    }
284
285    public void setNull(int parameterIndex, int sqlType, String JavaDoc typeName) throws SQLException JavaDoc
286    {
287       checkState();
288       try
289       {
290          ps.setNull(parameterIndex, sqlType, typeName);
291       }
292       catch (Throwable JavaDoc t)
293       {
294          throw checkException(t);
295       }
296    }
297
298    public void setBigDecimal(int parameterIndex, BigDecimal JavaDoc value) throws SQLException JavaDoc
299    {
300       checkState();
301       try
302       {
303          ps.setBigDecimal(parameterIndex, value);
304       }
305       catch (Throwable JavaDoc t)
306       {
307          throw checkException(t);
308       }
309    }
310
311    public void setString(int parameterIndex, String JavaDoc value) throws SQLException JavaDoc
312    {
313       checkState();
314       try
315       {
316          ps.setString(parameterIndex, value);
317       }
318       catch (Throwable JavaDoc t)
319       {
320          throw checkException(t);
321       }
322    }
323
324    public void setBytes(int parameterIndex, byte[] value) throws SQLException JavaDoc
325    {
326       checkState();
327       try
328       {
329          ps.setBytes(parameterIndex, value);
330       }
331       catch (Throwable JavaDoc t)
332       {
333          throw checkException(t);
334       }
335    }
336
337    public void setDate(int parameterIndex, Date JavaDoc value) throws SQLException JavaDoc
338    {
339       checkState();
340       try
341       {
342          ps.setDate(parameterIndex, value);
343       }
344       catch (Throwable JavaDoc t)
345       {
346          throw checkException(t);
347       }
348    }
349
350    public void setDate(int parameterIndex, Date JavaDoc value, Calendar JavaDoc calendar) throws SQLException JavaDoc
351    {
352       checkState();
353       try
354       {
355          ps.setDate(parameterIndex, value, calendar);
356       }
357       catch (Throwable JavaDoc t)
358       {
359          throw checkException(t);
360       }
361    }
362
363    public void setTimestamp(int parameterIndex, Timestamp JavaDoc value) throws SQLException JavaDoc
364    {
365       checkState();
366       try
367       {
368          ps.setTimestamp(parameterIndex, value);
369       }
370       catch (Throwable JavaDoc t)
371       {
372          throw checkException(t);
373       }
374    }
375
376    public void setTimestamp(int parameterIndex, Timestamp JavaDoc value, Calendar JavaDoc calendar) throws SQLException JavaDoc
377    {
378       checkState();
379       try
380       {
381          ps.setTimestamp(parameterIndex, value, calendar);
382       }
383       catch (Throwable JavaDoc t)
384       {
385          throw checkException(t);
386       }
387    }
388
389    /**
390     * @deprecated
391     */

392    public void setAsciiStream(int parameterIndex, InputStream JavaDoc stream, int length) throws SQLException JavaDoc
393    {
394       checkState();
395       try
396       {
397          ps.setAsciiStream(parameterIndex, stream, length);
398       }
399       catch (Throwable JavaDoc t)
400       {
401          throw checkException(t);
402       }
403    }
404
405    /**
406     * @deprecated
407     */

408    public void setUnicodeStream(int parameterIndex, InputStream JavaDoc stream, int length) throws SQLException JavaDoc
409    {
410       checkState();
411       try
412       {
413          ps.setUnicodeStream(parameterIndex, stream, length);
414       }
415       catch (Throwable JavaDoc t)
416       {
417          throw checkException(t);
418       }
419    }
420
421    public void setBinaryStream(int parameterIndex, InputStream JavaDoc stream, int length) throws SQLException JavaDoc
422    {
423       checkState();
424       try
425       {
426          ps.setBinaryStream(parameterIndex, stream, length);
427       }
428       catch (Throwable JavaDoc t)
429       {
430          throw checkException(t);
431       }
432    }
433
434    public void clearParameters() throws SQLException JavaDoc
435    {
436       checkState();
437       try
438       {
439          ps.clearParameters();
440       }
441       catch (Throwable JavaDoc t)
442       {
443          throw checkException(t);
444       }
445    }
446
447    public void setObject(int parameterIndex, Object JavaDoc value, int sqlType, int scale) throws SQLException JavaDoc
448    {
449       checkState();
450       try
451       {
452          ps.setObject(parameterIndex, value, sqlType, scale);
453       }
454       catch (Throwable JavaDoc t)
455       {
456          throw checkException(t);
457       }
458    }
459
460    public void setObject(int parameterIndex, Object JavaDoc value, int sqlType) throws SQLException JavaDoc
461    {
462       checkState();
463       try
464       {
465          ps.setObject(parameterIndex, value, sqlType);
466       }
467       catch (Throwable JavaDoc t)
468       {
469          throw checkException(t);
470       }
471    }
472
473    public void setObject(int parameterIndex, Object JavaDoc value) throws SQLException JavaDoc
474    {
475       checkState();
476       try
477       {
478          ps.setObject(parameterIndex, value);
479       }
480       catch (Throwable JavaDoc t)
481       {
482          throw checkException(t);
483       }
484    }
485
486    public void setCharacterStream(int parameterIndex, Reader JavaDoc reader, int length) throws SQLException JavaDoc
487    {
488       checkState();
489       try
490       {
491          ps.setCharacterStream(parameterIndex, reader, length);
492       }
493       catch (Throwable JavaDoc t)
494       {
495          throw checkException(t);
496       }
497    }
498
499    public void setRef(int parameterIndex, Ref JavaDoc value) throws SQLException JavaDoc
500    {
501       checkState();
502       try
503       {
504          ps.setRef(parameterIndex, value);
505       }
506       catch (Throwable JavaDoc t)
507       {
508          throw checkException(t);
509       }
510    }
511
512    public void setBlob(int parameterIndex, Blob JavaDoc value) throws SQLException JavaDoc
513    {
514       checkState();
515       try
516       {
517          ps.setBlob(parameterIndex, value);
518       }
519       catch (Throwable JavaDoc t)
520       {
521          throw checkException(t);
522       }
523    }
524
525    public void setClob(int parameterIndex, Clob JavaDoc value) throws SQLException JavaDoc
526    {
527       checkState();
528       try
529       {
530          ps.setClob(parameterIndex, value);
531       }
532       catch (Throwable JavaDoc t)
533       {
534          throw checkException(t);
535       }
536    }
537
538    public void setArray(int parameterIndex, Array JavaDoc value) throws SQLException JavaDoc
539    {
540       checkState();
541       try
542       {
543          ps.setArray(parameterIndex, value);
544       }
545       catch (Throwable JavaDoc t)
546       {
547          throw checkException(t);
548       }
549    }
550
551    public ParameterMetaData JavaDoc getParameterMetaData() throws SQLException JavaDoc
552    {
553       checkState();
554       try
555       {
556          return ps.getParameterMetaData();
557       }
558       catch (Throwable JavaDoc t)
559       {
560          throw checkException(t);
561       }
562    }
563 }
564
Popular Tags