001: // jTDS JDBC Driver for Microsoft SQL Server and Sybase
002: // Copyright (C) 2004 The jTDS Project
003: //
004: // This library is free software; you can redistribute it and/or
005: // modify it under the terms of the GNU Lesser General Public
006: // License as published by the Free Software Foundation; either
007: // version 2.1 of the License, or (at your option) any later version.
008: //
009: // This library is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: // Lesser General Public License for more details.
013: //
014: // You should have received a copy of the GNU Lesser General Public
015: // License along with this library; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: //
018: package net.sourceforge.jtds.jdbcx.proxy;
019:
020: import java.math.BigDecimal;
021: import java.sql.*;
022: import java.util.Calendar;
023:
024: import net.sourceforge.jtds.jdbc.*;
025:
026: /**
027: * This class would be better implemented as a java.lang.reflect.Proxy. However, this
028: * feature was not added until 1.3 and reflection performance was not improved until 1.4.
029: * Since the driver still needs to be compatible with 1.2 and 1.3 this class is used
030: * to delegate the calls to a prepared statement with minimal overhead.
031: *
032: * @version $Id: PreparedStatementProxy.java,v 1.3 2004/08/24 17:45:08 bheineman Exp $
033: */
034: public class PreparedStatementProxy extends StatementProxy implements
035: PreparedStatement {
036: private JtdsPreparedStatement _preparedStatement;
037:
038: PreparedStatementProxy(ConnectionProxy connection,
039: JtdsPreparedStatement preparedStatement) {
040: super (connection, preparedStatement);
041:
042: _preparedStatement = preparedStatement;
043: }
044:
045: /**
046: * Delgates calls to the prepared statement; SQLExceptions thrown from the
047: * prepared statement will cause an event to be fired on the connection
048: * pool listeners.
049: *
050: * @throws SQLException if an error occurs
051: */
052: public ResultSet executeQuery() throws SQLException {
053: validateConnection();
054:
055: try {
056: return _preparedStatement.executeQuery();
057: } catch (SQLException sqlException) {
058: processSQLException(sqlException);
059: }
060:
061: return null;
062: }
063:
064: /**
065: * Delgates calls to the prepared statement; SQLExceptions thrown from the
066: * prepared statement will cause an event to be fired on the connection
067: * pool listeners.
068: *
069: * @throws SQLException if an error occurs
070: */
071: public int executeUpdate() throws SQLException {
072: validateConnection();
073:
074: try {
075: return _preparedStatement.executeUpdate();
076: } catch (SQLException sqlException) {
077: processSQLException(sqlException);
078: }
079:
080: return Integer.MIN_VALUE;
081: }
082:
083: /**
084: * Delgates calls to the prepared statement; SQLExceptions thrown from the
085: * prepared statement will cause an event to be fired on the connection
086: * pool listeners.
087: *
088: * @throws SQLException if an error occurs
089: */
090: public void setNull(int parameterIndex, int sqlType)
091: throws SQLException {
092: validateConnection();
093:
094: try {
095: _preparedStatement.setNull(parameterIndex, sqlType);
096: } catch (SQLException sqlException) {
097: processSQLException(sqlException);
098: }
099: }
100:
101: /**
102: * Delgates calls to the prepared statement; SQLExceptions thrown from the
103: * prepared statement will cause an event to be fired on the connection
104: * pool listeners.
105: *
106: * @throws SQLException if an error occurs
107: */
108: public void setBoolean(int parameterIndex, boolean x)
109: throws SQLException {
110: validateConnection();
111:
112: try {
113: _preparedStatement.setBoolean(parameterIndex, x);
114: } catch (SQLException sqlException) {
115: processSQLException(sqlException);
116: }
117: }
118:
119: /**
120: * Delgates calls to the prepared statement; SQLExceptions thrown from the
121: * prepared statement will cause an event to be fired on the connection
122: * pool listeners.
123: *
124: * @throws SQLException if an error occurs
125: */
126: public void setByte(int parameterIndex, byte x) throws SQLException {
127: validateConnection();
128:
129: try {
130: _preparedStatement.setByte(parameterIndex, x);
131: } catch (SQLException sqlException) {
132: processSQLException(sqlException);
133: }
134: }
135:
136: /**
137: * Delgates calls to the prepared statement; SQLExceptions thrown from the
138: * prepared statement will cause an event to be fired on the connection
139: * pool listeners.
140: *
141: * @throws SQLException if an error occurs
142: */
143: public void setShort(int parameterIndex, short x)
144: throws SQLException {
145: validateConnection();
146:
147: try {
148: _preparedStatement.setShort(parameterIndex, x);
149: } catch (SQLException sqlException) {
150: processSQLException(sqlException);
151: }
152: }
153:
154: /**
155: * Delgates calls to the prepared statement; SQLExceptions thrown from the
156: * prepared statement will cause an event to be fired on the connection
157: * pool listeners.
158: *
159: * @throws SQLException if an error occurs
160: */
161: public void setInt(int parameterIndex, int x) throws SQLException {
162: validateConnection();
163:
164: try {
165: _preparedStatement.setInt(parameterIndex, x);
166: } catch (SQLException sqlException) {
167: processSQLException(sqlException);
168: }
169: }
170:
171: /**
172: * Delgates calls to the prepared statement; SQLExceptions thrown from the
173: * prepared statement will cause an event to be fired on the connection
174: * pool listeners.
175: *
176: * @throws SQLException if an error occurs
177: */
178: public void setLong(int parameterIndex, long x) throws SQLException {
179: validateConnection();
180:
181: try {
182: _preparedStatement.setLong(parameterIndex, x);
183: } catch (SQLException sqlException) {
184: processSQLException(sqlException);
185: }
186: }
187:
188: /**
189: * Delgates calls to the prepared statement; SQLExceptions thrown from the
190: * prepared statement will cause an event to be fired on the connection
191: * pool listeners.
192: *
193: * @throws SQLException if an error occurs
194: */
195: public void setFloat(int parameterIndex, float x)
196: throws SQLException {
197: validateConnection();
198:
199: try {
200: _preparedStatement.setFloat(parameterIndex, x);
201: } catch (SQLException sqlException) {
202: processSQLException(sqlException);
203: }
204: }
205:
206: /**
207: * Delgates calls to the prepared statement; SQLExceptions thrown from the
208: * prepared statement will cause an event to be fired on the connection
209: * pool listeners.
210: *
211: * @throws SQLException if an error occurs
212: */
213: public void setDouble(int parameterIndex, double x)
214: throws SQLException {
215: validateConnection();
216:
217: try {
218: _preparedStatement.setDouble(parameterIndex, x);
219: } catch (SQLException sqlException) {
220: processSQLException(sqlException);
221: }
222: }
223:
224: /**
225: * Delgates calls to the prepared statement; SQLExceptions thrown from the
226: * prepared statement will cause an event to be fired on the connection
227: * pool listeners.
228: *
229: * @throws SQLException if an error occurs
230: */
231: public void setBigDecimal(int parameterIndex, BigDecimal x)
232: throws SQLException {
233: validateConnection();
234:
235: try {
236: _preparedStatement.setBigDecimal(parameterIndex, x);
237: } catch (SQLException sqlException) {
238: processSQLException(sqlException);
239: }
240: }
241:
242: /**
243: * Delgates calls to the prepared statement; SQLExceptions thrown from the
244: * prepared statement will cause an event to be fired on the connection
245: * pool listeners.
246: *
247: * @throws SQLException if an error occurs
248: */
249: public void setString(int parameterIndex, String x)
250: throws SQLException {
251: validateConnection();
252:
253: try {
254: _preparedStatement.setString(parameterIndex, x);
255: } catch (SQLException sqlException) {
256: processSQLException(sqlException);
257: }
258: }
259:
260: /**
261: * Delgates calls to the prepared statement; SQLExceptions thrown from the
262: * prepared statement will cause an event to be fired on the connection
263: * pool listeners.
264: *
265: * @throws SQLException if an error occurs
266: */
267: public void setBytes(int parameterIndex, byte[] x)
268: throws SQLException {
269: validateConnection();
270:
271: try {
272: _preparedStatement.setBytes(parameterIndex, x);
273: } catch (SQLException sqlException) {
274: processSQLException(sqlException);
275: }
276: }
277:
278: /**
279: * Delgates calls to the prepared statement; SQLExceptions thrown from the
280: * prepared statement will cause an event to be fired on the connection
281: * pool listeners.
282: *
283: * @throws SQLException if an error occurs
284: */
285: public void setDate(int parameterIndex, java.sql.Date x)
286: throws SQLException {
287: validateConnection();
288:
289: try {
290: _preparedStatement.setDate(parameterIndex, x);
291: } catch (SQLException sqlException) {
292: processSQLException(sqlException);
293: }
294: }
295:
296: /**
297: * Delgates calls to the prepared statement; SQLExceptions thrown from the
298: * prepared statement will cause an event to be fired on the connection
299: * pool listeners.
300: *
301: * @throws SQLException if an error occurs
302: */
303: public void setTime(int parameterIndex, java.sql.Time x)
304: throws SQLException {
305: validateConnection();
306:
307: try {
308: _preparedStatement.setTime(parameterIndex, x);
309: } catch (SQLException sqlException) {
310: processSQLException(sqlException);
311: }
312: }
313:
314: /**
315: * Delgates calls to the prepared statement; SQLExceptions thrown from the
316: * prepared statement will cause an event to be fired on the connection
317: * pool listeners.
318: *
319: * @throws SQLException if an error occurs
320: */
321: public void setTimestamp(int parameterIndex, java.sql.Timestamp x)
322: throws SQLException {
323: validateConnection();
324:
325: try {
326: _preparedStatement.setTimestamp(parameterIndex, x);
327: } catch (SQLException sqlException) {
328: processSQLException(sqlException);
329: }
330: }
331:
332: /**
333: * Delgates calls to the prepared statement; SQLExceptions thrown from the
334: * prepared statement will cause an event to be fired on the connection
335: * pool listeners.
336: *
337: * @throws SQLException if an error occurs
338: */
339: public void setAsciiStream(int parameterIndex,
340: java.io.InputStream x, int length) throws SQLException {
341: validateConnection();
342:
343: try {
344: _preparedStatement
345: .setAsciiStream(parameterIndex, x, length);
346: } catch (SQLException sqlException) {
347: processSQLException(sqlException);
348: }
349: }
350:
351: /**
352: * Delgates calls to the prepared statement; SQLExceptions thrown from the
353: * prepared statement will cause an event to be fired on the connection
354: * pool listeners.
355: *
356: * @throws SQLException if an error occurs
357: */
358: public void setUnicodeStream(int parameterIndex,
359: java.io.InputStream x, int length) throws SQLException {
360: validateConnection();
361:
362: try {
363: _preparedStatement.setUnicodeStream(parameterIndex, x,
364: length);
365: } catch (SQLException sqlException) {
366: processSQLException(sqlException);
367: }
368: }
369:
370: /**
371: * Delgates calls to the prepared statement; SQLExceptions thrown from the
372: * prepared statement will cause an event to be fired on the connection
373: * pool listeners.
374: *
375: * @throws SQLException if an error occurs
376: */
377: public void setBinaryStream(int parameterIndex,
378: java.io.InputStream x, int length) throws SQLException {
379: validateConnection();
380:
381: try {
382: _preparedStatement.setBinaryStream(parameterIndex, x,
383: length);
384: } catch (SQLException sqlException) {
385: processSQLException(sqlException);
386: }
387: }
388:
389: /**
390: * Delgates calls to the prepared statement; SQLExceptions thrown from the
391: * prepared statement will cause an event to be fired on the connection
392: * pool listeners.
393: *
394: * @throws SQLException if an error occurs
395: */
396: public void clearParameters() throws SQLException {
397: validateConnection();
398:
399: try {
400: _preparedStatement.clearParameters();
401: } catch (SQLException sqlException) {
402: processSQLException(sqlException);
403: }
404: }
405:
406: /**
407: * Delgates calls to the prepared statement; SQLExceptions thrown from the
408: * prepared statement will cause an event to be fired on the connection
409: * pool listeners.
410: *
411: * @throws SQLException if an error occurs
412: */
413: public void setObject(int parameterIndex, Object x,
414: int targetSqlType, int scale) throws SQLException {
415: validateConnection();
416:
417: try {
418: _preparedStatement.setObject(parameterIndex, x,
419: targetSqlType, scale);
420: } catch (SQLException sqlException) {
421: processSQLException(sqlException);
422: }
423: }
424:
425: /**
426: * Delgates calls to the prepared statement; SQLExceptions thrown from the
427: * prepared statement will cause an event to be fired on the connection
428: * pool listeners.
429: *
430: * @throws SQLException if an error occurs
431: */
432: public void setObject(int parameterIndex, Object x,
433: int targetSqlType) throws SQLException {
434: validateConnection();
435:
436: try {
437: _preparedStatement.setObject(parameterIndex, x,
438: targetSqlType);
439: } catch (SQLException sqlException) {
440: processSQLException(sqlException);
441: }
442: }
443:
444: /**
445: * Delgates calls to the prepared statement; SQLExceptions thrown from the
446: * prepared statement will cause an event to be fired on the connection
447: * pool listeners.
448: *
449: * @throws SQLException if an error occurs
450: */
451: public void setObject(int parameterIndex, Object x)
452: throws SQLException {
453: validateConnection();
454:
455: try {
456: _preparedStatement.setObject(parameterIndex, x);
457: } catch (SQLException sqlException) {
458: processSQLException(sqlException);
459: }
460: }
461:
462: /**
463: * Delgates calls to the prepared statement; SQLExceptions thrown from the
464: * prepared statement will cause an event to be fired on the connection
465: * pool listeners.
466: *
467: * @throws SQLException if an error occurs
468: */
469: public boolean execute() throws SQLException {
470: validateConnection();
471:
472: try {
473: return _preparedStatement.execute();
474: } catch (SQLException sqlException) {
475: processSQLException(sqlException);
476: }
477:
478: return false;
479: }
480:
481: /**
482: * Delgates calls to the prepared statement; SQLExceptions thrown from the
483: * prepared statement will cause an event to be fired on the connection
484: * pool listeners.
485: *
486: * @throws SQLException if an error occurs
487: */
488: public void addBatch() throws SQLException {
489: validateConnection();
490:
491: try {
492: _preparedStatement.addBatch();
493: } catch (SQLException sqlException) {
494: processSQLException(sqlException);
495: }
496: }
497:
498: /**
499: * Delgates calls to the prepared statement; SQLExceptions thrown from the
500: * prepared statement will cause an event to be fired on the connection
501: * pool listeners.
502: *
503: * @throws SQLException if an error occurs
504: */
505: public void setCharacterStream(int parameterIndex,
506: java.io.Reader x, int length) throws SQLException {
507: validateConnection();
508:
509: try {
510: _preparedStatement.setCharacterStream(parameterIndex, x,
511: length);
512: } catch (SQLException sqlException) {
513: processSQLException(sqlException);
514: }
515: }
516:
517: /**
518: * Delgates calls to the prepared statement; SQLExceptions thrown from the
519: * prepared statement will cause an event to be fired on the connection
520: * pool listeners.
521: *
522: * @throws SQLException if an error occurs
523: */
524: public void setRef(int parameterIndex, Ref x) throws SQLException {
525: validateConnection();
526:
527: try {
528: _preparedStatement.setRef(parameterIndex, x);
529: } catch (SQLException sqlException) {
530: processSQLException(sqlException);
531: }
532: }
533:
534: /**
535: * Delgates calls to the prepared statement; SQLExceptions thrown from the
536: * prepared statement will cause an event to be fired on the connection
537: * pool listeners.
538: *
539: * @throws SQLException if an error occurs
540: */
541: public void setBlob(int parameterIndex, Blob x) throws SQLException {
542: validateConnection();
543:
544: try {
545: _preparedStatement.setBlob(parameterIndex, x);
546: } catch (SQLException sqlException) {
547: processSQLException(sqlException);
548: }
549: }
550:
551: /**
552: * Delgates calls to the prepared statement; SQLExceptions thrown from the
553: * prepared statement will cause an event to be fired on the connection
554: * pool listeners.
555: *
556: * @throws SQLException if an error occurs
557: */
558: public void setClob(int parameterIndex, Clob x) throws SQLException {
559: validateConnection();
560:
561: try {
562: _preparedStatement.setClob(parameterIndex, x);
563: } catch (SQLException sqlException) {
564: processSQLException(sqlException);
565: }
566: }
567:
568: /**
569: * Delgates calls to the prepared statement; SQLExceptions thrown from the
570: * prepared statement will cause an event to be fired on the connection
571: * pool listeners.
572: *
573: * @throws SQLException if an error occurs
574: */
575: public void setArray(int parameterIndex, Array x)
576: throws SQLException {
577: validateConnection();
578:
579: try {
580: _preparedStatement.setArray(parameterIndex, x);
581: } catch (SQLException sqlException) {
582: processSQLException(sqlException);
583: }
584: }
585:
586: /**
587: * Delgates calls to the prepared statement; SQLExceptions thrown from the
588: * prepared statement will cause an event to be fired on the connection
589: * pool listeners.
590: *
591: * @throws SQLException if an error occurs
592: */
593: public ResultSetMetaData getMetaData() throws SQLException {
594: validateConnection();
595:
596: try {
597: return _preparedStatement.getMetaData();
598: } catch (SQLException sqlException) {
599: processSQLException(sqlException);
600: }
601:
602: return null;
603: }
604:
605: /**
606: * Delgates calls to the prepared statement; SQLExceptions thrown from the
607: * prepared statement will cause an event to be fired on the connection
608: * pool listeners.
609: *
610: * @throws SQLException if an error occurs
611: */
612: public void setDate(int parameterIndex, java.sql.Date x,
613: Calendar cal) throws SQLException {
614: validateConnection();
615:
616: try {
617: _preparedStatement.setDate(parameterIndex, x, cal);
618: } catch (SQLException sqlException) {
619: processSQLException(sqlException);
620: }
621: }
622:
623: /**
624: * Delgates calls to the prepared statement; SQLExceptions thrown from the
625: * prepared statement will cause an event to be fired on the connection
626: * pool listeners.
627: *
628: * @throws SQLException if an error occurs
629: */
630: public void setTime(int parameterIndex, java.sql.Time x,
631: Calendar cal) throws SQLException {
632: validateConnection();
633:
634: try {
635: _preparedStatement.setTime(parameterIndex, x, cal);
636: } catch (SQLException sqlException) {
637: processSQLException(sqlException);
638: }
639: }
640:
641: /**
642: * Delgates calls to the prepared statement; SQLExceptions thrown from the
643: * prepared statement will cause an event to be fired on the connection
644: * pool listeners.
645: *
646: * @throws SQLException if an error occurs
647: */
648: public void setTimestamp(int parameterIndex, java.sql.Timestamp x,
649: Calendar cal) throws SQLException {
650: validateConnection();
651:
652: try {
653: _preparedStatement.setTimestamp(parameterIndex, x, cal);
654: } catch (SQLException sqlException) {
655: processSQLException(sqlException);
656: }
657: }
658:
659: /**
660: * Delgates calls to the prepared statement; SQLExceptions thrown from the
661: * prepared statement will cause an event to be fired on the connection
662: * pool listeners.
663: *
664: * @throws SQLException if an error occurs
665: */
666: public void setNull(int parameterIndex, int sqlType, String typeName)
667: throws SQLException {
668: validateConnection();
669:
670: try {
671: _preparedStatement.setNull(parameterIndex, sqlType,
672: typeName);
673: } catch (SQLException sqlException) {
674: processSQLException(sqlException);
675: }
676: }
677:
678: /**
679: * Delgates calls to the prepared statement; SQLExceptions thrown from the
680: * prepared statement will cause an event to be fired on the connection
681: * pool listeners.
682: *
683: * @throws SQLException if an error occurs
684: */
685: public void setURL(int parameterIndex, java.net.URL x)
686: throws SQLException {
687: validateConnection();
688:
689: try {
690: _preparedStatement.setURL(parameterIndex, x);
691: } catch (SQLException sqlException) {
692: processSQLException(sqlException);
693: }
694: }
695:
696: /**
697: * Delgates calls to the prepared statement; SQLExceptions thrown from the
698: * prepared statement will cause an event to be fired on the connection
699: * pool listeners.
700: *
701: * @throws SQLException if an error occurs
702: */
703: public ParameterMetaData getParameterMetaData() throws SQLException {
704: validateConnection();
705:
706: try {
707: return _preparedStatement.getParameterMetaData();
708: } catch (SQLException sqlException) {
709: processSQLException(sqlException);
710: }
711:
712: return null;
713: }
714: }
|