001: /*
002: * @(#) SmartPreparedStatement 1.0 02/08/01
003: */
004:
005: package org.smartlib.pool.core;
006:
007: import java.sql.*;
008: import java.math.BigDecimal;
009: import java.util.Calendar;
010: import java.net.URL;
011:
012: /**
013: * This class encapsulates a SmartPreparedStatement.
014: * Dont expect me to document this class, if you want refer Sun's Documentation.
015: *
016: * @author Sachin Shekar Shetty
017: * @version 1.0, 02/08/01
018: */
019:
020: public class SmartPreparedStatement extends SmartStatement implements
021: PreparedStatement, Close {
022:
023: private PreparedStatement pstmt;
024: private SmartConnection sConn;
025: private boolean isClosed;
026: Debugger debug = new Debugger(
027: "org.smartlib.pool.core.SmartPreparedStatement", true);
028:
029: // default access
030: SmartPreparedStatement(PreparedStatement pstmt,
031: SmartConnection sConn) {
032:
033: super (pstmt, sConn);
034: this .pstmt = pstmt;
035: this .sConn = sConn;
036:
037: }
038:
039: private void preProcess() throws SQLException {
040:
041: if (isClosed())
042: throw new SQLException("Prepared Statement already closed");
043: sConn.setLastAccessedTime();
044:
045: }
046:
047: public ResultSet executeQuery() throws SQLException {
048:
049: preProcess();
050: return pstmt.executeQuery();
051:
052: }
053:
054: public int executeUpdate() throws SQLException {
055:
056: preProcess();
057: return pstmt.executeUpdate();
058:
059: }
060:
061: public void setNull(int parameterIndex, int sqlType)
062: throws SQLException {
063:
064: preProcess();
065: pstmt.setNull(parameterIndex, sqlType);
066:
067: }
068:
069: public void setBoolean(int parameterIndex, boolean x)
070: throws SQLException {
071:
072: preProcess();
073: pstmt.setBoolean(parameterIndex, x);
074:
075: }
076:
077: public void setByte(int parameterIndex, byte x) throws SQLException {
078:
079: preProcess();
080: pstmt.setByte(parameterIndex, x);
081:
082: }
083:
084: public void setShort(int parameterIndex, short x)
085: throws SQLException {
086:
087: preProcess();
088: pstmt.setShort(parameterIndex, x);
089:
090: }
091:
092: public void setInt(int parameterIndex, int x) throws SQLException {
093:
094: preProcess();
095: pstmt.setInt(parameterIndex, x);
096:
097: }
098:
099: public void setLong(int parameterIndex, long x) throws SQLException {
100:
101: preProcess();
102: pstmt.setLong(parameterIndex, x);
103:
104: }
105:
106: public void setFloat(int parameterIndex, float x)
107: throws SQLException {
108:
109: preProcess();
110: pstmt.setFloat(parameterIndex, x);
111:
112: }
113:
114: public void setDouble(int parameterIndex, double x)
115: throws SQLException {
116:
117: preProcess();
118: pstmt.setDouble(parameterIndex, x);
119:
120: }
121:
122: public void setBigDecimal(int parameterIndex, BigDecimal x)
123: throws SQLException {
124:
125: preProcess();
126: pstmt.setBigDecimal(parameterIndex, x);
127:
128: }
129:
130: public void setString(int parameterIndex, String x)
131: throws SQLException {
132:
133: preProcess();
134: pstmt.setString(parameterIndex, x);
135:
136: }
137:
138: public void setBytes(int parameterIndex, byte x[])
139: throws SQLException {
140:
141: preProcess();
142: pstmt.setBytes(parameterIndex, x);
143:
144: }
145:
146: public void setDate(int parameterIndex, java.sql.Date x)
147: throws SQLException {
148:
149: preProcess();
150: pstmt.setDate(parameterIndex, x);
151:
152: }
153:
154: public void setTime(int parameterIndex, java.sql.Time x)
155: throws SQLException {
156:
157: preProcess();
158: pstmt.setTime(parameterIndex, x);
159:
160: }
161:
162: public void setTimestamp(int parameterIndex, java.sql.Timestamp x)
163: throws SQLException {
164:
165: preProcess();
166: pstmt.setTimestamp(parameterIndex, x);
167:
168: }
169:
170: public void setAsciiStream(int parameterIndex,
171: java.io.InputStream x, int length) throws SQLException {
172:
173: preProcess();
174: pstmt.setAsciiStream(parameterIndex, x, length);
175:
176: }
177:
178: public void setUnicodeStream(int parameterIndex,
179: java.io.InputStream x, int length) throws SQLException {
180:
181: preProcess();
182: pstmt.setUnicodeStream(parameterIndex, x, length);
183:
184: }
185:
186: public void setBinaryStream(int parameterIndex,
187: java.io.InputStream x, int length) throws SQLException {
188:
189: preProcess();
190: pstmt.setBinaryStream(parameterIndex, x, length);
191:
192: }
193:
194: public void clearParameters() throws SQLException {
195:
196: preProcess();
197: pstmt.clearParameters();
198:
199: }
200:
201: public void setObject(int parameterIndex, Object x,
202: int targetSqlType, int scale) throws SQLException {
203:
204: preProcess();
205: pstmt.setObject(parameterIndex, x, targetSqlType, scale);
206:
207: }
208:
209: public void setObject(int parameterIndex, Object x,
210: int targetSqlType) throws SQLException {
211:
212: preProcess();
213: pstmt.setObject(parameterIndex, x, targetSqlType);
214:
215: }
216:
217: public void setObject(int parameterIndex, Object x)
218: throws SQLException {
219:
220: preProcess();
221: pstmt.setObject(parameterIndex, x);
222:
223: }
224:
225: public boolean execute() throws SQLException {
226:
227: preProcess();
228: return pstmt.execute();
229:
230: }
231:
232: public void addBatch() throws SQLException {
233:
234: preProcess();
235: pstmt.addBatch();
236:
237: }
238:
239: public void setCharacterStream(int parameterIndex,
240: java.io.Reader reader, int length) throws SQLException {
241:
242: preProcess();
243: pstmt.setCharacterStream(parameterIndex, reader, length);
244:
245: }
246:
247: public void setRef(int i, Ref x) throws SQLException {
248:
249: preProcess();
250: pstmt.setRef(i, x);
251:
252: }
253:
254: public void setBlob(int i, Blob x) throws SQLException {
255:
256: preProcess();
257: pstmt.setBlob(i, x);
258:
259: }
260:
261: public void setClob(int i, Clob x) throws SQLException {
262:
263: preProcess();
264: pstmt.setClob(i, x);
265:
266: }
267:
268: public void setArray(int i, Array x) throws SQLException {
269:
270: preProcess();
271: pstmt.setArray(i, x);
272:
273: }
274:
275: public ResultSetMetaData getMetaData() throws SQLException {
276:
277: preProcess();
278: return pstmt.getMetaData();
279:
280: }
281:
282: public void setDate(int parameterIndex, java.sql.Date x,
283: Calendar cal) throws SQLException {
284:
285: preProcess();
286: pstmt.setDate(parameterIndex, x, cal);
287:
288: }
289:
290: public void setTime(int parameterIndex, java.sql.Time x,
291: Calendar cal) throws SQLException {
292:
293: preProcess();
294: pstmt.setTime(parameterIndex, x, cal);
295:
296: }
297:
298: public void setTimestamp(int parameterIndex, java.sql.Timestamp x,
299: Calendar cal) throws SQLException {
300:
301: preProcess();
302: pstmt.setTimestamp(parameterIndex, x, cal);
303:
304: }
305:
306: public void setNull(int paramIndex, int sqlType, String typeName)
307: throws SQLException {
308:
309: preProcess();
310: pstmt.setNull(paramIndex, sqlType, typeName);
311:
312: }
313:
314: public void setURL(int parameterIndex, URL x) throws SQLException {
315: //To change body of implemented methods use File | Settings | File Templates.
316: }
317:
318: public ParameterMetaData getParameterMetaData() throws SQLException {
319: return null; //To change body of implemented methods use File | Settings | File Templates.
320: }
321:
322: public Connection getConnection() throws SQLException {
323:
324: preProcess();
325: return pstmt.getConnection();
326:
327: }
328:
329: public int[] executeBatch() throws SQLException {
330:
331: preProcess();
332: return pstmt.executeBatch();
333:
334: }
335:
336: public void clearBatch() throws SQLException {
337:
338: preProcess();
339: pstmt.clearBatch();
340:
341: }
342:
343: public void addBatch(String sql) throws SQLException {
344:
345: preProcess();
346: pstmt.addBatch(sql);
347:
348: }
349:
350: public ResultSet executeQuery(String sql) throws SQLException {
351:
352: preProcess();
353: return pstmt.executeQuery(sql);
354:
355: }
356:
357: public int executeUpdate(String sql) throws SQLException {
358:
359: preProcess();
360: return pstmt.executeUpdate(sql);
361:
362: }
363:
364: public void close() throws SQLException {
365:
366: debug.print("PreparedStatement Closed for:" + sConn.getOwner());
367: if (isClosed)
368: throw new SQLException("PreparedStatement already closed");
369: pstmt.close();
370: isClosed = true;
371:
372: }
373:
374: public boolean isClosed() throws SQLException {
375:
376: return isClosed;
377:
378: }
379:
380: public int getMaxFieldSize() throws SQLException {
381:
382: preProcess();
383: return pstmt.getMaxFieldSize();
384:
385: }
386:
387: public void setMaxFieldSize(int max) throws SQLException {
388:
389: preProcess();
390: pstmt.setMaxFieldSize(max);
391:
392: }
393:
394: public int getMaxRows() throws SQLException {
395:
396: preProcess();
397: return pstmt.getMaxRows();
398:
399: }
400:
401: public void setMaxRows(int max) throws SQLException {
402:
403: preProcess();
404: pstmt.setMaxRows(max);
405:
406: }
407:
408: public void setEscapeProcessing(boolean enable) throws SQLException {
409:
410: preProcess();
411: pstmt.setEscapeProcessing(enable);
412:
413: }
414:
415: public int getQueryTimeout() throws SQLException {
416:
417: preProcess();
418: return pstmt.getQueryTimeout();
419:
420: }
421:
422: public void setQueryTimeout(int seconds) throws SQLException {
423:
424: preProcess();
425: pstmt.setQueryTimeout(seconds);
426:
427: }
428:
429: public void cancel() throws SQLException {
430:
431: preProcess();
432: pstmt.cancel();
433:
434: }
435:
436: public SQLWarning getWarnings() throws SQLException {
437:
438: preProcess();
439: return pstmt.getWarnings();
440:
441: }
442:
443: public void clearWarnings() throws SQLException {
444:
445: preProcess();
446: pstmt.clearWarnings();
447:
448: }
449:
450: public void setCursorName(String name) throws SQLException {
451:
452: preProcess();
453: pstmt.setCursorName(name);
454:
455: }
456:
457: public boolean execute(String sql) throws SQLException {
458:
459: preProcess();
460: return pstmt.execute(sql);
461:
462: }
463:
464: public ResultSet getResultSet() throws SQLException {
465:
466: preProcess();
467: return pstmt.getResultSet();
468:
469: }
470:
471: public int getUpdateCount() throws SQLException {
472:
473: preProcess();
474: return pstmt.getUpdateCount();
475:
476: }
477:
478: public boolean getMoreResults() throws SQLException {
479:
480: preProcess();
481: return pstmt.getMoreResults();
482:
483: }
484:
485: public void setFetchDirection(int direction) throws SQLException {
486:
487: preProcess();
488: pstmt.setFetchDirection(direction);
489:
490: }
491:
492: public int getFetchDirection() throws SQLException {
493:
494: preProcess();
495: return pstmt.getFetchDirection();
496:
497: }
498:
499: public void setFetchSize(int rows) throws SQLException {
500:
501: preProcess();
502: pstmt.setFetchSize(rows);
503:
504: }
505:
506: public int getFetchSize() throws SQLException {
507:
508: preProcess();
509: return pstmt.getFetchSize();
510:
511: }
512:
513: public int getResultSetConcurrency() throws SQLException {
514:
515: preProcess();
516: return pstmt.getResultSetConcurrency();
517:
518: }
519:
520: public int getResultSetType() throws SQLException {
521:
522: preProcess();
523: return pstmt.getResultSetType();
524:
525: }
526:
527: public String toString() {
528:
529: return pstmt.toString();
530:
531: }
532:
533: }
|