KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > jdbc > JdbcStatement


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.jdbc;
6
7
8 import java.sql.BatchUpdateException JavaDoc;
9 import java.sql.Connection JavaDoc;
10 import java.sql.ResultSet JavaDoc;
11 import java.sql.SQLException JavaDoc;
12 import java.sql.SQLWarning JavaDoc;
13 import java.sql.Statement JavaDoc;
14
15 import org.h2.command.CommandInterface;
16 import org.h2.engine.SessionInterface;
17 import org.h2.message.Message;
18 import org.h2.message.TraceObject;
19 import org.h2.result.ResultInterface;
20 import org.h2.util.ObjectArray;
21
22 /**
23  * Represents a statement.
24  */

25 public class JdbcStatement extends TraceObject implements Statement JavaDoc {
26
27     protected JdbcConnection conn;
28     protected SessionInterface session;
29     protected JdbcResultSet resultSet;
30     protected int maxRows;
31     protected boolean escapeProcessing=true;
32     protected int queryTimeout;
33     protected boolean queryTimeoutSet;
34     protected int fetchSize;
35     protected boolean fetchSizeSet;
36     protected int updateCount;
37     private CommandInterface executingCommand;
38     private ObjectArray batchCommands;
39     protected int resultSetType;
40     protected boolean closedByResultSet;
41
42     /**
43      * Executes a query (select statement) and returns the result set.
44      * If another result set exists for this statement, this will be closed
45      * (even if this statement fails).
46      *
47      * @return the result set
48      */

49     public ResultSet JavaDoc executeQuery(String JavaDoc sql) throws SQLException JavaDoc {
50         try {
51             int id = getNextId(TraceObject.RESULT_SET);
52             if(debug()) {
53                 debugCodeAssign("ResultSet", TraceObject.RESULT_SET, id);
54                 debugCodeCall("executeQuery", sql);
55             }
56             checkClosed();
57             closeOld();
58             if(escapeProcessing) {
59                 sql=conn.translateSQL(sql);
60             }
61             CommandInterface command=conn.prepareCommand(sql);
62             ResultInterface result;
63             synchronized(session) {
64                 setExecutingStatement(command);
65                 try {
66                     boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
67                     result = command.executeQuery(maxRows, scrollable);
68                 } finally {
69                     setExecutingStatement(null);
70                 }
71             }
72             command.close();
73             resultSet = new JdbcResultSet(session, conn, this, result, id, closedByResultSet);
74             return resultSet;
75         } catch(Throwable JavaDoc e) {
76             throw logAndConvert(e);
77         }
78     }
79
80     /**
81      * Executes a statement (insert, update, delete, create, drop)
82      * and returns the update count.
83      * If another result set exists for this statement, this will be closed
84      * (even if this statement fails).
85      *
86      * If the statement is a create or drop and does not throw an exception,
87      * the current transaction (if any) is committed after executing the statement.
88      * If autocommit is on, this statement will be committed.
89      *
90      * @param sql the SQL statement
91      * @return the update count (number of row affected by an insert,
92      * update or delete, or 0 if no rows or the statement was a
93      * create, drop, commit or rollback)
94      * @throws SQLException if a database error occured or a
95      * select statement was executed
96      */

97     public int executeUpdate(String JavaDoc sql) throws SQLException JavaDoc {
98         try {
99             debugCodeCall("executeUpdate", sql);
100             checkClosed();
101             closeOld();
102             if(escapeProcessing) {
103                 sql = conn.translateSQL(sql);
104             }
105             CommandInterface command = conn.prepareCommand(sql);
106             synchronized(session) {
107                 setExecutingStatement(command);
108                 try {
109                     updateCount = command.executeUpdate();
110                 } finally {
111                     setExecutingStatement(null);
112                 }
113             }
114             command.close();
115             return updateCount;
116         } catch(Throwable JavaDoc e) {
117             throw logAndConvert(e);
118         }
119     }
120
121     /**
122      * Executes an arbitrary statement.
123      * If another result set exists for this statement, this will be closed
124      * (even if this statement fails).
125      *
126      * If the statement is a create or drop and does not throw an exception,
127      * the current transaction (if any) is committed after executing the statement.
128      * If autocommit is on, and the statement is not a select, this statement will be committed.
129      *
130      * @return true if a result set is available, false if not
131      */

132     public boolean execute(String JavaDoc sql) throws SQLException JavaDoc {
133         try {
134             int id = getNextId(TraceObject.RESULT_SET);
135             if(debug()) {
136                 debugCodeCall("execute", sql);
137             }
138             checkClosed();
139             closeOld();
140             if(escapeProcessing) {
141                 sql = conn.translateSQL(sql);
142             }
143             CommandInterface command=conn.prepareCommand(sql);
144             boolean returnsResultSet;
145             synchronized(session) {
146                 setExecutingStatement(command);
147                 try {
148                     if(command.isQuery()) {
149                         returnsResultSet = true;
150                         boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
151                         ResultInterface result = command.executeQuery(maxRows, scrollable);
152                         resultSet = new JdbcResultSet(session, conn, this, result, id, closedByResultSet);
153                     } else {
154                         returnsResultSet = false;
155                         updateCount = command.executeUpdate();
156                     }
157                 } finally {
158                     setExecutingStatement(null);
159                 }
160             }
161             command.close();
162             return returnsResultSet;
163         } catch(Throwable JavaDoc e) {
164             throw logAndConvert(e);
165         }
166     }
167
168     /**
169      * Returns the last result set produces by this statement.
170      *
171      * @return the result set
172      */

173     public ResultSet JavaDoc getResultSet() throws SQLException JavaDoc {
174         try {
175             checkClosed();
176             if(resultSet != null) {
177                 int id = resultSet.getTraceId();
178                 debugCodeAssign("ResultSet", TraceObject.RESULT_SET, id);
179             }
180             debugCodeCall("getResultSet");
181             return resultSet;
182         } catch(Throwable JavaDoc e) {
183             throw logAndConvert(e);
184         }
185     }
186
187     /**
188      * Returns the last update count of this statement.
189      *
190      * @return the update count (number of row affected by an insert,
191      * update or delete, or 0 if no rows or the statement was a
192      * create, drop, commit or rollback; -1 if the statement was a select).
193      * @throws SQLException if this object is closed or invalid
194      */

195     public int getUpdateCount() throws SQLException JavaDoc {
196         try {
197             debugCodeCall("getUpdateCount");
198             checkClosed();
199             return updateCount;
200         } catch(Throwable JavaDoc e) {
201             throw logAndConvert(e);
202         }
203     }
204
205     /**
206      * Closes this statement.
207      * All result sets that where created by this statement
208      * become invalid after calling this method.
209      */

210     public void close() throws SQLException JavaDoc {
211         try {
212             debugCodeCall("close");
213             closeOld();
214             if(conn != null) {
215                 conn = null;
216             }
217         } catch(Throwable JavaDoc e) {
218             throw logAndConvert(e);
219         }
220     }
221
222     /**
223      * Returns the connection that created this object.
224      *
225      * @return the connection
226      */

227     public Connection JavaDoc getConnection() throws SQLException JavaDoc {
228         try {
229             debugCodeCall("getConnection");
230             checkClosed();
231             return conn;
232         } catch(Throwable JavaDoc e) {
233             throw logAndConvert(e);
234         }
235     }
236
237     /**
238      * Gets the first warning reported by calls on this object.
239      * This driver does not support warnings, and will always return null.
240      *
241      * @return null
242      */

243     public SQLWarning JavaDoc getWarnings() throws SQLException JavaDoc {
244         try {
245             debugCodeCall("getWarnings");
246             checkClosed();
247             return null;
248         } catch(Throwable JavaDoc e) {
249             throw logAndConvert(e);
250         }
251     }
252
253     /**
254      * Clears all warnings. As this driver does not support warnings,
255      * this call is ignored.
256      */

257     public void clearWarnings() throws SQLException JavaDoc {
258         try {
259             debugCodeCall("clearWarnings");
260             checkClosed();
261         } catch(Throwable JavaDoc e) {
262             throw logAndConvert(e);
263         }
264     }
265
266     /**
267      * Moves to the next result set - however there is always only one result set.
268      * This call also closes the current result set (if there is one).
269      * Returns true if there is a next result set (that means - it always returns false).
270      *
271      * @return false
272      * @throws SQLException if this object is closed.
273      */

274     public boolean getMoreResults() throws SQLException JavaDoc {
275         try {
276             debugCodeCall("getMoreResults");
277             checkClosed();
278             closeOld();
279             return false;
280         } catch(Throwable JavaDoc e) {
281             throw logAndConvert(e);
282         }
283     }
284
285     /**
286      * Sets the name of the cursor. This call is ignored.
287      *
288      * @param name ignored
289      * @throws SQLException if this object is closed
290      */

291     public void setCursorName(String JavaDoc name) throws SQLException JavaDoc {
292         try {
293             debugCodeCall("setCursorName", name);
294             checkClosed();
295         } catch(Throwable JavaDoc e) {
296             throw logAndConvert(e);
297         }
298     }
299
300     /**
301      * Sets the fetch direction.
302      * This call is ignored by this driver.
303      *
304      * @param direction ignored
305      * @throws SQLException if this object is closed
306      */

307     public void setFetchDirection(int direction) throws SQLException JavaDoc {
308         try {
309             debugCodeCall("setFetchDirection", direction);
310             checkClosed();
311         } catch(Throwable JavaDoc e) {
312             throw logAndConvert(e);
313         }
314     }
315
316    /**
317      * Gets the fetch direction.
318      *
319      * @return FETCH_FORWARD
320      * @throws SQLException if this object is closed
321      */

322     public int getFetchDirection() throws SQLException JavaDoc {
323         try {
324             debugCodeCall("getFetchDirection");
325             checkClosed();
326             return ResultSet.FETCH_FORWARD;
327         } catch(Throwable JavaDoc e) {
328             throw logAndConvert(e);
329         }
330     }
331
332     /**
333      * Gets the maximum number of rows for a ResultSet.
334      *
335      * @return the number of rows where 0 means no limit
336      * @throws SQLException if this object is closed
337      */

338     public int getMaxRows() throws SQLException JavaDoc {
339         try {
340             debugCodeCall("getMaxRows");
341             checkClosed();
342             return maxRows;
343         } catch(Throwable JavaDoc e) {
344             throw logAndConvert(e);
345         }
346     }
347
348     /**
349      * Gets the maximum number of rows for a ResultSet.
350      *
351      * @param maxRows the number of rows where 0 means no limit
352      * @throws SQLException if this object is closed
353      */

354     public void setMaxRows(int maxRows) throws SQLException JavaDoc {
355         try {
356             debugCodeCall("setMaxRows", maxRows);
357             checkClosed();
358             if(maxRows < 0) {
359                 throw Message.getInvalidValueException(""+maxRows, "maxRows");
360             }
361             this.maxRows = maxRows;
362         } catch(Throwable JavaDoc e) {
363             throw logAndConvert(e);
364         }
365     }
366
367     /**
368      * Sets the number of rows suggested to read in one step.
369      * This value cannot be higher than the maximum rows (setMaxRows)
370      * set by the statement or prepared statement, otherwise an exception
371      * is throws.
372      *
373      * @param rows the number of rows
374      * @throws SQLException if this object is closed
375      */

376     public void setFetchSize(int rows) throws SQLException JavaDoc {
377         try {
378             debugCodeCall("setFetchSize", rows);
379             checkClosed();
380             if(rows<0 || (rows>0 && maxRows>0 && rows>maxRows)) {
381                 throw Message.getInvalidValueException(""+rows, "rows");
382             }
383             fetchSize=rows;
384             fetchSizeSet=true;
385         } catch(Throwable JavaDoc e) {
386             throw logAndConvert(e);
387         }
388     }
389
390     /**
391      * Gets the number of rows suggested to read in one step.
392      *
393      * @return the current fetch size
394      * @throws SQLException if this object is closed
395      */

396     public int getFetchSize() throws SQLException JavaDoc {
397         try {
398             debugCodeCall("getFetchSize");
399             checkClosed();
400             return fetchSize;
401         } catch(Throwable JavaDoc e) {
402             throw logAndConvert(e);
403         }
404     }
405
406     /**
407      * Gets the result set concurrency created by this object.
408      *
409      * @return ResultSet.CONCUR_UPDATABLE
410      * @throws SQLException if this object is closed
411      */

412     public int getResultSetConcurrency() throws SQLException JavaDoc {
413         try {
414             debugCodeCall("getResultSetConcurrency");
415             checkClosed();
416             return ResultSet.CONCUR_UPDATABLE;
417         } catch(Throwable JavaDoc e) {
418             throw logAndConvert(e);
419         }
420     }
421
422     /**
423      * Gets the result set type.
424      *
425      * @return the type
426      * @throws SQLException if this object is closed
427      */

428     public int getResultSetType() throws SQLException JavaDoc {
429         try {
430             debugCodeCall("getResultSetType");
431             checkClosed();
432             return resultSetType;
433         } catch(Throwable JavaDoc e) {
434             throw logAndConvert(e);
435         }
436     }
437
438     /**
439      * Gets the maximum number of bytes for a result set column.
440      *
441      * @return always 0 for no limit
442      * @throws SQLException if this object is closed
443      */

444     public int getMaxFieldSize() throws SQLException JavaDoc {
445         try {
446             debugCodeCall("getMaxFieldSize");
447             checkClosed();
448             return 0;
449         } catch(Throwable JavaDoc e) {
450             throw logAndConvert(e);
451         }
452     }
453
454     /**
455      * Sets the maximum number of bytes for a result set column.
456      * This method does currently do nothing for this driver.
457      *
458      * @param max the maximum size - ignored
459      * @throws SQLException if this object is closed
460      */

461     public void setMaxFieldSize(int max) throws SQLException JavaDoc {
462         try {
463             debugCodeCall("setMaxFieldSize", max);
464             checkClosed();
465         } catch(Throwable JavaDoc e) {
466             throw logAndConvert(e);
467         }
468     }
469
470     /**
471      * Enables or disables processing or JDBC escape syntax.
472      * See also Connection.nativeSQL.
473      *
474      * @param enable - true (default) or false (no conversion is attempted)
475      * @throws SQLException if this object is closed
476      */

477     public void setEscapeProcessing(boolean enable) throws SQLException JavaDoc {
478         try {
479             if(debug()) {
480                 debugCode("setEscapeProcessing("+enable+");");
481             }
482             checkClosed();
483             escapeProcessing=enable;
484         } catch(Throwable JavaDoc e) {
485             throw logAndConvert(e);
486         }
487     }
488
489     /**
490      * Cancels a currently running statement.
491      * This method must be called from within another
492      * thread than the execute method.
493      * This method is not supported in the server mode.
494      *
495      * @throws SQLException if this object is closed
496      */

497     public void cancel() throws SQLException JavaDoc {
498         try {
499             debugCodeCall("cancel");
500             checkClosed();
501             // executingCommand can be reset by another thread
502
CommandInterface c = executingCommand;
503             try {
504                 if(c != null) {
505                     c.cancel();
506                 }
507             } finally {
508                 setExecutingStatement(null);
509             }
510         } catch(Throwable JavaDoc e) {
511             throw logAndConvert(e);
512         }
513     }
514
515     /**
516      * Gets the current query timeout in seconds.
517      *
518      * @return the timeout in seconds
519      * @throws SQLException if this object is closed
520      */

521     public int getQueryTimeout() throws SQLException JavaDoc {
522         try {
523             debugCodeCall("getQueryTimeout");
524             checkClosed();
525             return queryTimeout;
526         } catch(Throwable JavaDoc e) {
527             throw logAndConvert(e);
528         }
529     }
530
531     /**
532      * Sets the current query timeout in seconds.
533      * This method will succeed, even if the functionality is not supported by the database.
534      *
535      * @param seconds the timeout in seconds -
536      * 0 means no timeout, values smaller 0 will throw an exception
537      * @throws SQLException if this object is closed
538      */

539     public void setQueryTimeout(int seconds) throws SQLException JavaDoc {
540         try {
541             debugCodeCall("setQueryTimeout", seconds);
542             checkClosed();
543             if(seconds<0) {
544                 throw Message.getInvalidValueException(""+seconds, "seconds");
545             }
546             queryTimeout=seconds;
547             queryTimeoutSet=true;
548         } catch(Throwable JavaDoc e) {
549             throw logAndConvert(e);
550         }
551     }
552
553     /**
554      * Adds a statement to the batch.
555      */

556     public void addBatch(String JavaDoc sql) throws SQLException JavaDoc {
557         try {
558             debugCodeCall("addBatch", sql);
559             checkClosed();
560             if(escapeProcessing) {
561                 sql = conn.translateSQL(sql);
562             }
563             if(batchCommands == null) {
564                 batchCommands = new ObjectArray();
565             }
566             batchCommands.add(sql);
567         } catch(Throwable JavaDoc e) {
568             throw logAndConvert(e);
569         }
570     }
571
572     /**
573      * Clears the batch.
574      */

575     public void clearBatch() throws SQLException JavaDoc {
576         try {
577             debugCodeCall("clearBatch");
578             checkClosed();
579             batchCommands = null;
580         } catch(Throwable JavaDoc e) {
581             throw logAndConvert(e);
582         }
583     }
584
585     /**
586      * Executes the batch.
587      *
588      * @return the array of updatecounts
589      */

590     public int[] executeBatch() throws SQLException JavaDoc {
591         try {
592             debugCodeCall("executeBatch");
593             checkClosed();
594             if(batchCommands == null) {
595                 // TODO batch: check what other database do if no commands are set
596
batchCommands = new ObjectArray();
597             }
598             int[] result = new int[batchCommands.size()];
599             boolean error = false;
600             for(int i=0; i<batchCommands.size(); i++) {
601                 String JavaDoc sql = (String JavaDoc) batchCommands.get(i);
602                 try {
603                     result[i] = executeUpdate(sql);
604                 } catch(SQLException JavaDoc e) {
605                     logAndConvert(e);
606 //#ifdef JDK14
607
result[i] = Statement.EXECUTE_FAILED;
608 //#endif
609
error = true;
610                 }
611             }
612             batchCommands = null;
613             if(error) {
614                 throw new BatchUpdateException JavaDoc(result);
615             }
616             return result;
617         } catch(Throwable JavaDoc e) {
618             throw logAndConvert(e);
619         }
620     }
621
622     /**
623      * Return a result set that contains the last generated autoincrement key for this connection.
624      *
625      * @return the result set with one row and one column containing the key
626      * @throws SQLException if this object is closed
627      */

628     public ResultSet JavaDoc getGeneratedKeys() throws SQLException JavaDoc {
629         try {
630             debugCodeCall("getGeneratedKeys");
631             checkClosed();
632             return conn.getGeneratedKeys(this);
633         } catch(Throwable JavaDoc e) {
634             throw logAndConvert(e);
635         }
636     }
637
638     /**
639      * THIS FEATURE IS NOT SUPPORTED.
640      * @throws SQLException Unsupported Feature (SQL State 0A000)
641      */

642     public boolean getMoreResults(int current) throws SQLException JavaDoc {
643         try {
644             debugCodeCall("getMoreResults");
645             throw Message.getUnsupportedException();
646         } catch(Throwable JavaDoc e) {
647             throw logAndConvert(e);
648         }
649     }
650
651     /**
652      * Executes a statement and returns the update count.
653      * This method just calls executeUpdate(String sql).
654      *
655      * @param sql the SQL statement
656      * @return the update count (number of row affected by an insert,
657      * update or delete, or 0 if no rows or the statement was a
658      * create, drop, commit or rollback)
659      * @throws SQLException if a database error occured or a
660      * select statement was executed
661      */

662     public int executeUpdate(String JavaDoc sql, int autoGeneratedKeys) throws SQLException JavaDoc {
663         try {
664             if(debug()) {
665                 debugCode("executeUpdate("+quote(sql)+", "+autoGeneratedKeys+");");
666             }
667             return executeUpdate(sql);
668         } catch(Throwable JavaDoc e) {
669             throw logAndConvert(e);
670         }
671     }
672
673     /**
674      * Executes a statement and returns the update count.
675      * This method just calls executeUpdate(String sql).
676      *
677      * @param sql the SQL statement
678      * @return the update count (number of row affected by an insert,
679      * update or delete, or 0 if no rows or the statement was a
680      * create, drop, commit or rollback)
681      * @throws SQLException if a database error occured or a
682      * select statement was executed
683      */

684     public int executeUpdate(String JavaDoc sql, int[] columnIndexes) throws SQLException JavaDoc {
685         try {
686             if(debug()) {
687                 debugCode("executeUpdate("+quote(sql)+", "+quoteIntArray(columnIndexes)+");");
688             }
689             return executeUpdate(sql);
690         } catch(Throwable JavaDoc e) {
691             throw logAndConvert(e);
692         }
693     }
694
695     /**
696      * Executes a statement and returns the update count.
697      * This method just calls executeUpdate(String sql).
698      *
699      * @param sql the SQL statement
700      * @return the update count (number of row affected by an insert,
701      * update or delete, or 0 if no rows or the statement was a
702      * create, drop, commit or rollback)
703      * @throws SQLException if a database error occured or a
704      * select statement was executed
705      */

706     public int executeUpdate(String JavaDoc sql, String JavaDoc[] columnNames) throws SQLException JavaDoc {
707         try {
708             if(debug()) {
709                 debugCode("executeUpdate("+quote(sql)+", "+quoteArray(columnNames)+");");
710             }
711             return executeUpdate(sql);
712         } catch(Throwable JavaDoc e) {
713             throw logAndConvert(e);
714         }
715     }
716
717     /**
718      * Executes a statement and returns the update count.
719      * This method just calls execute(String sql).
720      *
721      * @param sql the SQL statement
722      * @return the update count (number of row affected by an insert,
723      * update or delete, or 0 if no rows or the statement was a
724      * create, drop, commit or rollback)
725      * @throws SQLException if a database error occured or a
726      * select statement was executed
727      */

728     public boolean execute(String JavaDoc sql, int autoGeneratedKeys) throws SQLException JavaDoc {
729         try {
730             if(debug()) {
731                 debugCode("execute("+quote(sql)+", "+autoGeneratedKeys+");");
732             }
733             return execute(sql);
734         } catch(Throwable JavaDoc e) {
735             throw logAndConvert(e);
736         }
737     }
738
739     /**
740      * Executes a statement and returns the update count.
741      * This method just calls execute(String sql).
742      *
743      * @param sql the SQL statement
744      * @return the update count (number of row affected by an insert,
745      * update or delete, or 0 if no rows or the statement was a
746      * create, drop, commit or rollback)
747      * @throws SQLException if a database error occured or a
748      * select statement was executed
749      */

750     public boolean execute(String JavaDoc sql, int[] columnIndexes) throws SQLException JavaDoc {
751         try {
752             if(debug()) {
753                 debugCode("execute("+quote(sql)+", "+quoteIntArray(columnIndexes)+");");
754             }
755             return execute(sql);
756         } catch(Throwable JavaDoc e) {
757             throw logAndConvert(e);
758         }
759     }
760
761     /**
762      * Executes a statement and returns the update count.
763      * This method just calls execute(String sql).
764      *
765      * @param sql the SQL statement
766      * @return the update count (number of row affected by an insert,
767      * update or delete, or 0 if no rows or the statement was a
768      * create, drop, commit or rollback)
769      * @throws SQLException if a database error occured or a
770      * select statement was executed
771      */

772     public boolean execute(String JavaDoc sql, String JavaDoc[] columnNames) throws SQLException JavaDoc {
773         try {
774             if(debug()) {
775                 debugCode("execute("+quote(sql)+", "+quoteArray(columnNames)+");");
776             }
777             return execute(sql);
778         } catch(Throwable JavaDoc e) {
779             throw logAndConvert(e);
780         }
781     }
782
783     /**
784      * Gets the result set holdability.
785      *
786      * @return the holdability
787      */

788 //#ifdef JDK14
789
public int getResultSetHoldability() throws SQLException JavaDoc {
790         try {
791             debugCodeCall("getResultSetHoldability");
792             checkClosed();
793             return ResultSet.HOLD_CURSORS_OVER_COMMIT;
794         } catch(Throwable JavaDoc e) {
795             throw logAndConvert(e);
796         }
797     }
798 //#endif
799

800     // =============================================================
801

802     JdbcStatement(SessionInterface session, JdbcConnection conn, int resultSetType, int id, boolean closeWithResultSet) {
803         setTrace(session.getTrace(), TraceObject.STATEMENT, id);
804         this.session = session;
805         this.conn = conn;
806         this.resultSetType = resultSetType;
807         this.closedByResultSet = closeWithResultSet;
808     }
809
810     void checkClosed() throws SQLException JavaDoc {
811         if(conn == null) {
812             throw Message.getSQLException(Message.OBJECT_CLOSED);
813         }
814         conn.checkClosed();
815     }
816
817     void closeOld() throws SQLException JavaDoc {
818         try {
819             if(!closedByResultSet) {
820                 if(resultSet != null) {
821                     resultSet.closeInternal();
822                 }
823             }
824         } finally {
825             resultSet = null;
826             updateCount=-1;
827         }
828     }
829
830     protected void setExecutingStatement(CommandInterface c) {
831         conn.setExecutingStatement(c == null ? null : this);
832         executingCommand = c;
833     }
834
835     /**
836      * Returns whether this statement is closed.
837      *
838      * @return true if the statement is closed
839      */

840     public boolean isClosed() throws SQLException JavaDoc {
841         try {
842             debugCodeCall("isClosed");
843             return conn == null;
844         } catch(Throwable JavaDoc e) {
845             throw logAndConvert(e);
846         }
847     }
848
849     /**
850      * Return an object of this class if possible.
851      * @throws SQLException Unsupported Feature (SQL State 0A000)
852      */

853     //#ifdef JDK16
854
/*
855     public <T> T unwrap(Class<T> iface) throws SQLException {
856         throw Message.getUnsupportedException();
857     }
858 */

859     //#endif
860

861     /**
862      * Checks if unwrap can return an object of this class.
863      * @throws SQLException Unsupported Feature (SQL State 0A000)
864      */

865     //#ifdef JDK16
866
/*
867     public boolean isWrapperFor(Class<?> iface) throws SQLException {
868         throw Message.getUnsupportedException();
869     }
870 */

871     //#endif
872

873     /**
874      * Returns whether this object is poolable.
875      * @return false
876      */

877     public boolean isPoolable() throws SQLException JavaDoc {
878         debugCodeCall("isPoolable");
879         return false;
880     }
881
882     /**
883      * Requests that this object should be pooled or not.
884      * This call is ignored.
885      *
886      * @param poolable the requested value
887      */

888     public void setPoolable(boolean poolable) throws SQLException JavaDoc {
889         if(debug()) {
890             debugCode("setPoolable("+poolable+");");
891         }
892     }
893
894 // public void finalize() {
895
// if(!Database.RUN_FINALIZERS) {
896
// return;
897
// }
898
// closeOld();
899
// if(conn != null) {
900
// conn = null;
901
// }
902
// }
903

904 }
905
906
Popular Tags