001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.resource.adapter.jdbc;
023:
024: import java.io.InputStream;
025: import java.io.Reader;
026: import java.math.BigDecimal;
027: import java.net.URL;
028: import java.sql.Array;
029: import java.sql.Blob;
030: import java.sql.Clob;
031: import java.sql.Date;
032: import java.sql.ParameterMetaData;
033: import java.sql.PreparedStatement;
034: import java.sql.Ref;
035: import java.sql.ResultSet;
036: import java.sql.ResultSetMetaData;
037: import java.sql.SQLException;
038: import java.sql.Statement;
039: import java.sql.Time;
040: import java.sql.Timestamp;
041: import java.util.Calendar;
042:
043: /**
044: * A wrapper for a prepared statement.
045: *
046: * @author <a href="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
047: * @author <a href="mailto:adrian@jboss.com">Adrian Brock</a>
048: * @version $Revision: 57189 $
049: */
050: public class WrappedPreparedStatement extends WrappedStatement
051: implements PreparedStatement {
052: private final PreparedStatement ps;
053:
054: public WrappedPreparedStatement(final WrappedConnection lc,
055: final PreparedStatement ps) {
056: super (lc, ps);
057: this .ps = ps;
058: }
059:
060: public Statement getUnderlyingStatement() throws SQLException {
061: checkState();
062: if (ps instanceof CachedPreparedStatement) {
063: return ((CachedPreparedStatement) ps)
064: .getUnderlyingPreparedStatement();
065: } else {
066: return ps;
067: }
068: }
069:
070: public void setBoolean(int parameterIndex, boolean value)
071: throws SQLException {
072: checkState();
073: try {
074: ps.setBoolean(parameterIndex, value);
075: } catch (Throwable t) {
076: throw checkException(t);
077: }
078: }
079:
080: public void setByte(int parameterIndex, byte value)
081: throws SQLException {
082: checkState();
083: try {
084: ps.setByte(parameterIndex, value);
085: } catch (Throwable t) {
086: throw checkException(t);
087: }
088: }
089:
090: public void setShort(int parameterIndex, short value)
091: throws SQLException {
092: checkState();
093: try {
094: ps.setShort(parameterIndex, value);
095: } catch (Throwable t) {
096: throw checkException(t);
097: }
098: }
099:
100: public void setInt(int parameterIndex, int value)
101: throws SQLException {
102: checkState();
103: try {
104: ps.setInt(parameterIndex, value);
105: } catch (Throwable t) {
106: throw checkException(t);
107: }
108: }
109:
110: public void setLong(int parameterIndex, long value)
111: throws SQLException {
112: checkState();
113: try {
114: ps.setLong(parameterIndex, value);
115: } catch (Throwable t) {
116: throw checkException(t);
117: }
118: }
119:
120: public void setFloat(int parameterIndex, float value)
121: throws SQLException {
122: checkState();
123: try {
124: ps.setFloat(parameterIndex, value);
125: } catch (Throwable t) {
126: throw checkException(t);
127: }
128: }
129:
130: public void setDouble(int parameterIndex, double value)
131: throws SQLException {
132: checkState();
133: try {
134: ps.setDouble(parameterIndex, value);
135: } catch (Throwable t) {
136: throw checkException(t);
137: }
138: }
139:
140: public void setURL(int parameterIndex, URL value)
141: throws SQLException {
142: checkState();
143: try {
144: ps.setURL(parameterIndex, value);
145: } catch (Throwable t) {
146: throw checkException(t);
147: }
148: }
149:
150: public void setTime(int parameterIndex, Time value)
151: throws SQLException {
152: checkState();
153: try {
154: ps.setTime(parameterIndex, value);
155: } catch (Throwable t) {
156: throw checkException(t);
157: }
158: }
159:
160: public void setTime(int parameterIndex, Time value,
161: Calendar calendar) throws SQLException {
162: checkState();
163: try {
164: ps.setTime(parameterIndex, value, calendar);
165: } catch (Throwable t) {
166: throw checkException(t);
167: }
168: }
169:
170: public boolean execute() throws SQLException {
171: checkTransaction();
172: try {
173: checkConfiguredQueryTimeout();
174: return ps.execute();
175: } catch (Throwable t) {
176: throw checkException(t);
177: }
178: }
179:
180: public ResultSetMetaData getMetaData() throws SQLException {
181: checkState();
182: try {
183: return ps.getMetaData();
184: } catch (Throwable t) {
185: throw checkException(t);
186: }
187: }
188:
189: public ResultSet executeQuery() throws SQLException {
190: checkTransaction();
191: try {
192: checkConfiguredQueryTimeout();
193: ResultSet resultSet = ps.executeQuery();
194: return registerResultSet(resultSet);
195: } catch (Throwable t) {
196: throw checkException(t);
197: }
198: }
199:
200: public int executeUpdate() throws SQLException {
201: checkTransaction();
202: try {
203: checkConfiguredQueryTimeout();
204: return ps.executeUpdate();
205: } catch (Throwable t) {
206: throw checkException(t);
207: }
208: }
209:
210: public void addBatch() throws SQLException {
211: checkState();
212: try {
213: ps.addBatch();
214: } catch (Throwable t) {
215: throw checkException(t);
216: }
217: }
218:
219: public void setNull(int parameterIndex, int sqlType)
220: throws SQLException {
221: checkState();
222: try {
223: ps.setNull(parameterIndex, sqlType);
224: } catch (Throwable t) {
225: throw checkException(t);
226: }
227: }
228:
229: public void setNull(int parameterIndex, int sqlType, String typeName)
230: throws SQLException {
231: checkState();
232: try {
233: ps.setNull(parameterIndex, sqlType, typeName);
234: } catch (Throwable t) {
235: throw checkException(t);
236: }
237: }
238:
239: public void setBigDecimal(int parameterIndex, BigDecimal value)
240: throws SQLException {
241: checkState();
242: try {
243: ps.setBigDecimal(parameterIndex, value);
244: } catch (Throwable t) {
245: throw checkException(t);
246: }
247: }
248:
249: public void setString(int parameterIndex, String value)
250: throws SQLException {
251: checkState();
252: try {
253: ps.setString(parameterIndex, value);
254: } catch (Throwable t) {
255: throw checkException(t);
256: }
257: }
258:
259: public void setBytes(int parameterIndex, byte[] value)
260: throws SQLException {
261: checkState();
262: try {
263: ps.setBytes(parameterIndex, value);
264: } catch (Throwable t) {
265: throw checkException(t);
266: }
267: }
268:
269: public void setDate(int parameterIndex, Date value)
270: throws SQLException {
271: checkState();
272: try {
273: ps.setDate(parameterIndex, value);
274: } catch (Throwable t) {
275: throw checkException(t);
276: }
277: }
278:
279: public void setDate(int parameterIndex, Date value,
280: Calendar calendar) throws SQLException {
281: checkState();
282: try {
283: ps.setDate(parameterIndex, value, calendar);
284: } catch (Throwable t) {
285: throw checkException(t);
286: }
287: }
288:
289: public void setTimestamp(int parameterIndex, Timestamp value)
290: throws SQLException {
291: checkState();
292: try {
293: ps.setTimestamp(parameterIndex, value);
294: } catch (Throwable t) {
295: throw checkException(t);
296: }
297: }
298:
299: public void setTimestamp(int parameterIndex, Timestamp value,
300: Calendar calendar) throws SQLException {
301: checkState();
302: try {
303: ps.setTimestamp(parameterIndex, value, calendar);
304: } catch (Throwable t) {
305: throw checkException(t);
306: }
307: }
308:
309: /**
310: * @deprecated
311: */
312: public void setAsciiStream(int parameterIndex, InputStream stream,
313: int length) throws SQLException {
314: checkState();
315: try {
316: ps.setAsciiStream(parameterIndex, stream, length);
317: } catch (Throwable t) {
318: throw checkException(t);
319: }
320: }
321:
322: /**
323: * @deprecated
324: */
325: public void setUnicodeStream(int parameterIndex,
326: InputStream stream, int length) throws SQLException {
327: checkState();
328: try {
329: ps.setUnicodeStream(parameterIndex, stream, length);
330: } catch (Throwable t) {
331: throw checkException(t);
332: }
333: }
334:
335: public void setBinaryStream(int parameterIndex, InputStream stream,
336: int length) throws SQLException {
337: checkState();
338: try {
339: ps.setBinaryStream(parameterIndex, stream, length);
340: } catch (Throwable t) {
341: throw checkException(t);
342: }
343: }
344:
345: public void clearParameters() throws SQLException {
346: checkState();
347: try {
348: ps.clearParameters();
349: } catch (Throwable t) {
350: throw checkException(t);
351: }
352: }
353:
354: public void setObject(int parameterIndex, Object value,
355: int sqlType, int scale) throws SQLException {
356: checkState();
357: try {
358: ps.setObject(parameterIndex, value, sqlType, scale);
359: } catch (Throwable t) {
360: throw checkException(t);
361: }
362: }
363:
364: public void setObject(int parameterIndex, Object value, int sqlType)
365: throws SQLException {
366: checkState();
367: try {
368: ps.setObject(parameterIndex, value, sqlType);
369: } catch (Throwable t) {
370: throw checkException(t);
371: }
372: }
373:
374: public void setObject(int parameterIndex, Object value)
375: throws SQLException {
376: checkState();
377: try {
378: ps.setObject(parameterIndex, value);
379: } catch (Throwable t) {
380: throw checkException(t);
381: }
382: }
383:
384: public void setCharacterStream(int parameterIndex, Reader reader,
385: int length) throws SQLException {
386: checkState();
387: try {
388: ps.setCharacterStream(parameterIndex, reader, length);
389: } catch (Throwable t) {
390: throw checkException(t);
391: }
392: }
393:
394: public void setRef(int parameterIndex, Ref value)
395: throws SQLException {
396: checkState();
397: try {
398: ps.setRef(parameterIndex, value);
399: } catch (Throwable t) {
400: throw checkException(t);
401: }
402: }
403:
404: public void setBlob(int parameterIndex, Blob value)
405: throws SQLException {
406: checkState();
407: try {
408: ps.setBlob(parameterIndex, value);
409: } catch (Throwable t) {
410: throw checkException(t);
411: }
412: }
413:
414: public void setClob(int parameterIndex, Clob value)
415: throws SQLException {
416: checkState();
417: try {
418: ps.setClob(parameterIndex, value);
419: } catch (Throwable t) {
420: throw checkException(t);
421: }
422: }
423:
424: public void setArray(int parameterIndex, Array value)
425: throws SQLException {
426: checkState();
427: try {
428: ps.setArray(parameterIndex, value);
429: } catch (Throwable t) {
430: throw checkException(t);
431: }
432: }
433:
434: public ParameterMetaData getParameterMetaData() throws SQLException {
435: checkState();
436: try {
437: return ps.getParameterMetaData();
438: } catch (Throwable t) {
439: throw checkException(t);
440: }
441: }
442: }
|